Skip to content

Commit

Permalink
Refactor: The controller is responsible for the before-destory behavi…
Browse files Browse the repository at this point in the history
…our. If this is used in more that one place, it can be refactored to an operation.
  • Loading branch information
CloCkWeRX committed Dec 5, 2016
1 parent 861b7f6 commit aae213f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def confirm
# DELETE /admin/users/1.xml AJAX
#----------------------------------------------------------------------------
def destroy
flash[:warning] = t(:msg_cant_delete_user, @user.full_name) unless @user.destroy
unless @user.check_if_current_user && @user.destroy
flash[:warning] = t(:msg_cant_delete_user, @user.full_name)
end

respond_with(@user)
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/users/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ def check_if_needs_approval
self.suspended_at = Time.now if Setting.user_signup == :needs_approval && !admin
end

private

# Prevent current user from deleting herself.
#----------------------------------------------------------------------------
def check_if_current_user
User.current_user.nil? || User.current_user != self
end

private

# Prevent deleting a user unless she has no artifacts left.
#----------------------------------------------------------------------------
def check_if_has_related_assets
Expand Down

0 comments on commit aae213f

Please sign in to comment.