Class: Decidim::DecidimAwesome::Admin::CreateAwesomeAuthorizationMembers
- Inherits:
-
Command
- Object
- Command
- Command
- Decidim::DecidimAwesome::Admin::CreateAwesomeAuthorizationMembers
- Defined in:
- app/commands/decidim/decidim_awesome/admin/create_awesome_authorization_members.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ CreateAwesomeAuthorizationMembers
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ CreateAwesomeAuthorizationMembers
Public: Initializes the command.
form - The form object containing the authorization group and emails.
10 11 12 |
# File 'app/commands/decidim/decidim_awesome/admin/create_awesome_authorization_members.rb', line 10 def initialize(form) @form = form end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
- :ok when all members were added or already existed.
- :invalid if some members could not be created.
Returns nothing.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/commands/decidim/decidim_awesome/admin/create_awesome_authorization_members.rb', line 20 def call .members.destroy_all if form.remove_previous_members previous_members_count = .members.count .members.insert_all( # rubocop:disable Rails/SkipsModelValidations form.data.map { |email| { email: email.strip.downcase } }, unique_by: :index_auth_members_group_email ) created_count = .members.count - previous_members_count if created_count.zero? && form.remove_previous_members.blank? return broadcast(:invalid, I18n.t("decidim.decidim_awesome.admin.awesome_authorization_users.update.empty")) end broadcast(:ok, created_count) rescue StandardError => e broadcast(:invalid, e.) end |