Sha256: 4c0ca8c18bd995ea1722d0256a8350282355884cccfa97ef0c1bceaa7ff7e4f1

Contents?: true

Size: 985 Bytes

Versions: 12

Compression:

Stored size: 985 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # A command with all the business logic to reject an invitation to belong to a
  # group.
  class RejectGroupInvitation < Decidim::Command
    # Public: Initializes the command.
    #
    # user_group - the UserGroup where the user has been invited
    # user - the User that has been invited
    def initialize(user_group, user)
      @user_group = user_group
      @user = user
    end

    # Executes the command. Broadcasts these events:
    #
    # - :ok when everything is valid.
    # - :invalid if we couldn't proceed.
    #
    # Returns nothing.
    def call
      return broadcast(:invalid) if membership.blank?

      reject_invitation

      broadcast(:ok)
    end

    private

    attr_reader :user_group, :user

    def reject_invitation
      membership.destroy!
    end

    def membership
      @membership ||= Decidim::UserGroupMembership.find_by(user: user, user_group: user_group, role: :invited)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/commands/decidim/reject_group_invitation.rb
decidim-core-0.27.8 app/commands/decidim/reject_group_invitation.rb
decidim-core-0.27.7 app/commands/decidim/reject_group_invitation.rb
decidim-core-0.27.6 app/commands/decidim/reject_group_invitation.rb
decidim-core-0.27.5 app/commands/decidim/reject_group_invitation.rb
decidim-core-0.27.4 app/commands/decidim/reject_group_invitation.rb
decidim-core-0.27.3 app/commands/decidim/reject_group_invitation.rb
decidim-core-0.27.2 app/commands/decidim/reject_group_invitation.rb
decidim-core-0.27.1 app/commands/decidim/reject_group_invitation.rb
decidim-core-0.27.0 app/commands/decidim/reject_group_invitation.rb
decidim-core-0.27.0.rc2 app/commands/decidim/reject_group_invitation.rb
decidim-core-0.27.0.rc1 app/commands/decidim/reject_group_invitation.rb