DEV: Prefer create! over create when not checking return value.

We don't want stuff to silently fail.
This commit is contained in:
Guo Xiang Tan 2020-06-02 10:33:30 +08:00
parent 2a0a689442
commit c21e3bbd1b
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20

View File

@ -116,14 +116,14 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f
def add_to_private_topics_if_invited
topic_ids = Topic.where(archetype: Archetype::private_message).includes(:invites).where(invites: { email: invite.email }).pluck(:id)
topic_ids.each do |id|
TopicAllowedUser.create(user_id: invited_user.id, topic_id: id) unless TopicAllowedUser.exists?(user_id: invited_user.id, topic_id: id)
TopicAllowedUser.create!(user_id: invited_user.id, topic_id: id) unless TopicAllowedUser.exists?(user_id: invited_user.id, topic_id: id)
end
end
def add_user_to_groups
new_group_ids = invite.groups.pluck(:id) - invited_user.group_users.pluck(:group_id)
new_group_ids.each do |id|
invited_user.group_users.create(group_id: id)
invited_user.group_users.create!(group_id: id)
DiscourseEvent.trigger(:user_added_to_group, invited_user, Group.find_by(id: id), automatic: false)
end
end
@ -147,7 +147,7 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f
def notify_invitee
if inviter = invite.invited_by
inviter.notifications.create(notification_type: Notification.types[:invitee_accepted],
inviter.notifications.create!(notification_type: Notification.types[:invitee_accepted],
data: { display_username: invited_user.username }.to_json)
end
end