Class: Decidim::Admin::PromoteManagedUser
- Inherits:
-
Command
- Object
- Command
- Decidim::Admin::PromoteManagedUser
- Defined in:
- decidim-admin/app/commands/decidim/admin/promote_managed_user.rb
Overview
A command with all the business logic to promote a managed user.
Managed users can be promoted to standard users. It means they will be invited to the application and will lose the managed flag so the user cannot be impersonated anymore.
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#promoted_by ⇒ Object
readonly
Returns the value of attribute promoted_by.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form, user, promoted_by) ⇒ PromoteManagedUser
constructor
Public: Initializes the command.
Constructor Details
#initialize(form, user, promoted_by) ⇒ PromoteManagedUser
Public: Initializes the command.
form - A form object with the params. user - The user to promote promoted_by - The user performing the operation
16 17 18 19 20 |
# File 'decidim-admin/app/commands/decidim/admin/promote_managed_user.rb', line 16 def initialize(form, user, promoted_by) @form = form @user = user @promoted_by = promoted_by end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
38 39 40 |
# File 'decidim-admin/app/commands/decidim/admin/promote_managed_user.rb', line 38 def form @form end |
#promoted_by ⇒ Object (readonly)
Returns the value of attribute promoted_by.
38 39 40 |
# File 'decidim-admin/app/commands/decidim/admin/promote_managed_user.rb', line 38 def promoted_by @promoted_by end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
38 39 40 |
# File 'decidim-admin/app/commands/decidim/admin/promote_managed_user.rb', line 38 def user @user end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if the form wasn't valid and we couldn't proceed.
Returns nothing.
28 29 30 31 32 33 34 35 36 |
# File 'decidim-admin/app/commands/decidim/admin/promote_managed_user.rb', line 28 def call return broadcast(:invalid) if form.invalid? || !user.managed? || email_already_exists? promote_user invite_user create_action_log broadcast(:ok) end |