Skip to content

Commit

Permalink
Refactor: The controller is responsible for the before-creation behav…
Browse files Browse the repository at this point in the history
…iour. 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 78d041f commit 1f11488
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def create
params[:user][:email].try(:strip!)
params[:user][:password_confirmation] = nil if params[:user][:password_confirmation].blank?
@user = User.new(user_params)
@user.check_if_needs_approval
@user.save_without_session_maintenance

respond_with(@user)
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 @@ -39,7 +39,6 @@
#

class User < ActiveRecord::Base
before_create :check_if_needs_approval
before_destroy :check_if_current_user, :check_if_has_related_assets

has_one :avatar, as: :entity, dependent: :destroy # Personal avatar.
Expand Down Expand Up @@ -143,14 +142,15 @@ def to_xml(_options = nil)
[name].to_xml
end

private

# Suspend newly created user if signup requires an approval.
#----------------------------------------------------------------------------
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
Expand Down

0 comments on commit 1f11488

Please sign in to comment.