Sha256: d7a6c071c5aa03bb0a1464972434ed7dca4cb965c802bee5882bb5fab921393c

Contents?: true

Size: 942 Bytes

Versions: 39

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 < Rectify::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

39 entries across 39 versions & 1 rubygems

Version Path
decidim-admin-0.26.10 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.26.9 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.26.8 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.26.7 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.26.5 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.26.4 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.26.3 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.26.2 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.26.1 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.26.0 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.26.0.rc2 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.26.0.rc1 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.25.2 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.25.1 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.25.0 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.25.0.rc4 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.25.0.rc3 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.25.0.rc2 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.25.0.rc1 app/commands/decidim/admin/remove_admin.rb
decidim-admin-0.24.3 app/commands/decidim/admin/remove_admin.rb