Sha256: d8a32bdda0cd134cbaa635443487d7904f0f64ed2a5ae99ed0362c449f1617f1
Contents?: true
Size: 1.29 KB
Versions: 12
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true module Decidim # A command with all the business logic to reject a join request to a user # group. class RejectUserGroupJoinRequest < Decidim::Command # Public: Initializes the command. # # membership - the UserGroupMembership to be accepted. def initialize(membership) @membership = membership 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) unless membership return broadcast(:invalid) if membership.role.to_s != "requested" transaction do send_notification reject_membership end broadcast(:ok, @user_group) end private attr_reader :membership def reject_membership membership.destroy! end def send_notification Decidim::EventsManager.publish( event: "decidim.events.groups.join_request_rejected", event_class: JoinRequestRejectedEvent, resource: membership.user_group, affected_users: [membership.user], extra: { user_group_name: membership.user_group.name, user_group_nickname: membership.user_group.nickname } ) end end end
Version data entries
12 entries across 12 versions & 1 rubygems