Sha256: 656937ef10605752502a6879beb0e852d2adfa00537ab78a8771e77cdc7e3982
Contents?: true
Size: 1.22 KB
Versions: 2
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module Decidim # A command with all the business logic to unendorse a resource, both as a user or as a user_group. class UnendorseResource < Rectify::Command # Public: Initializes the command. # # resource - A Decidim::Endorsable object. # current_user - The current user. # current_group- (optional) The current_group that is unendorsing the Resource. def initialize(resource, current_user, current_group = nil) @resource = resource @current_user = current_user @current_group = current_group end # Executes the command. Broadcasts these events: # # - :ok when everything is valid, together with the resource. # - :invalid if the form wasn't valid and we couldn't proceed. # # Returns nothing. def call destroy_resource_endorsement broadcast(:ok, @resource) end private def destroy_resource_endorsement query = if @current_group.present? @resource.endorsements.where(decidim_user_group_id: @current_group&.id) else @resource.endorsements.where(author: @current_user, decidim_user_group_id: 0) end query.destroy_all end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
decidim-core-0.26.10 | app/commands/decidim/unendorse_resource.rb |
decidim-core-0.26.9 | app/commands/decidim/unendorse_resource.rb |