Andy/misc/small adjustments (#208)

* Fix bad user_id error handling

* Remove spam user from index and remove old path
This commit is contained in:
Andy Zhao 2018-04-13 22:09:02 -04:00 committed by Ben Halpern
parent 936a724ead
commit 12adea7b83
2 changed files with 8 additions and 6 deletions

View file

@ -49,7 +49,9 @@ class Internal::UsersController < Internal::ApplicationController
comment.destroy!
end
user.articles.each &:destroy!
user.remove_from_index!
user.save!
user.update!(old_username: nil)
rescue => e
flash[:error] = e.message
end

View file

@ -14,20 +14,20 @@ class UserRoleService
end
def update_tag_moderators(user_ids, tag)
users = user_ids.map { |id| User.find(id) }
users = user_ids.map do |id|
User.find(id)
rescue
tag.errors[:moderator_ids] << ": user id #{id} was not found"
end
return false if !tag.errors[:moderator_ids].blank?
# Andy: Don't have to worry about comparing old and new values.
tag.tag_moderator_ids.each do |id|
User.find(id).remove_role(:tag_moderator, tag)
puts "removed #{id}"
end
users.each do |user|
user.add_role(:tag_moderator, tag)
puts "added #{user.id}"
end
return true
rescue ActiveRecord::RecordNotFound
tag.errors[:moderator_ids] << ": user #{id} was not found"
return false
end
private