Sha256: b9beef425fdc8c643d71cdd6c2d667009e6f3c3f14786242850797e2981905c6

Contents?: true

Size: 942 Bytes

Versions: 25

Compression:

Stored size: 942 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command to remove the admin privilege to an user.
    class RemoveAdmin < Decidim::Command
      # Public: Initializes the command.
      #
      # user - the user that will no longer be an admin
      # current_user - the user that performs the action
      def initialize(user, current_user)
        @user = user
        @current_user = current_user
      end

      def call
        return broadcast(:invalid) unless user

        Decidim.traceability.perform_action!(
          "remove_from_admin",
          user,
          current_user,
          extra: {
            invited_user_role: user_role
          }
        ) do
          user.update!(admin: false, roles: [])
        end

        broadcast(:ok)
      end

      private

      attr_reader :user, :current_user

      def user_role
        user.admin? ? :admin : user.roles.last
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-admin-0.27.2 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.27.1 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.27.0 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.27.0.rc2 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.27.0.rc1 app/commands/decidim/admin/remove_admin.rb