Sha256: a5bd5dfdf996579fe2f7e99b50db3d425abfb60c0630fcb43353c29c4d36d74b

Contents?: true

Size: 875 Bytes

Versions: 8

Compression:

Stored size: 875 Bytes

Contents

# frozen_string_literal: true
module Decidim
  module Comments
    module Abilities
      # Defines the abilities related to comments for a logged in process admin user.
      # Intended to be used with `cancancan`.
      class ProcessAdminUser
        include CanCan::Ability

        attr_reader :user, :context

        def initialize(user, context)
          return unless user && !user.role?(:admin)

          @user = user
          @context = context

          can :manage, Comment do |comment|
            participatory_processes.include?(comment.feature.participatory_process)
          end
          can :unreport, Comment
          can :hide, Comment
        end

        private

        def participatory_processes
          @participatory_processes ||= Decidim::Admin::ManageableParticipatoryProcessesForUser.for(@user)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
decidim-comments-0.1.0 app/models/decidim/comments/abilities/process_admin_user.rb
decidim-0.1.0 decidim-comments/app/models/decidim/comments/abilities/process_admin_user.rb
decidim-comments-0.0.8.1 app/models/decidim/comments/abilities/process_admin_user.rb
decidim-0.0.8.1 decidim-comments/app/models/decidim/comments/abilities/process_admin_user.rb
decidim-comments-0.0.7 app/models/decidim/comments/abilities/process_admin_user.rb
decidim-0.0.7 decidim-comments/app/models/decidim/comments/abilities/process_admin_user.rb
decidim-comments-0.0.6 app/models/decidim/comments/abilities/process_admin_user.rb
decidim-0.0.6 decidim-comments/app/models/decidim/comments/abilities/process_admin_user.rb