Sha256: 44aada30772e950aecdab38c18c1b645da2aa7ad75a595d7f0a1ca4b6c2e6b9f

Contents?: true

Size: 1.87 KB

Versions: 11

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Admin
      class Permissions < Decidim::DefaultPermissions
        def permissions
          # The public part needs to be implemented yet
          return permission_action if permission_action.scope != :admin

          if create_permission_action?
            # There's no special condition to create proposal notes, only
            # users with access to the admin section can do it.
            allow! if permission_action.subject == :proposal_note

            # Proposals can only be created from the admin when the
            # corresponding setting is enabled.
            toggle_allow(admin_creation_is_enabled?) if permission_action.subject == :proposal

            # Proposals can only be answered from the admin when the
            # corresponding setting is enabled.
            toggle_allow(admin_proposal_answering_is_enabled?) if permission_action.subject == :proposal_answer
          end

          # Every user allowed by the space can update the category of the proposal
          allow! if permission_action.subject == :proposal_category && permission_action.action == :update

          # Every user allowed by the space can import proposals from another_component
          allow! if permission_action.subject == :proposals && permission_action.action == :import

          permission_action
        end

        private

        def admin_creation_is_enabled?
          current_settings.try(:creation_enabled?) &&
            component_settings.try(:official_proposals_enabled)
        end

        def admin_proposal_answering_is_enabled?
          current_settings.try(:proposal_answering_enabled) &&
            component_settings.try(:proposal_answering_enabled)
        end

        def create_permission_action?
          permission_action.action == :create
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
decidim-proposals-0.14.4 app/permissions/decidim/proposals/admin/permissions.rb
decidim-proposals-0.14.3 app/permissions/decidim/proposals/admin/permissions.rb
decidim-proposals-0.14.2 app/permissions/decidim/proposals/admin/permissions.rb
decidim-proposals-0.14.1 app/permissions/decidim/proposals/admin/permissions.rb
decidim-proposals-0.13.1 app/permissions/decidim/proposals/admin/permissions.rb
decidim-proposals-0.12.2 app/permissions/decidim/proposals/admin/permissions.rb
decidim-proposals-0.13.0 app/permissions/decidim/proposals/admin/permissions.rb
decidim-proposals-0.12.1 app/permissions/decidim/proposals/admin/permissions.rb
decidim-proposals-0.13.0.pre1 app/permissions/decidim/proposals/admin/permissions.rb
decidim-proposals-0.12.0 app/permissions/decidim/proposals/admin/permissions.rb
decidim-proposals-0.12.0.pre app/permissions/decidim/proposals/admin/permissions.rb