Sha256: 33cdde1a09ae38eb3f049e06caa3e81b35c5be2ab39a6dc8fdc6d2a87f631143
Contents?: true
Size: 1.69 KB
Versions: 2
Compression:
Stored size: 1.69 KB
Contents
# frozen_string_literal: true require "active_support/concern" module Decidim module Admin module GlobalModerationContext extend ActiveSupport::Concern included do # Private: Overwrites the method from the parent controller so that the # permission system does not overwrite permissions. def permission_resource :global_moderation end # Private: Finds the participatory spaces the current user is admin to. # This is only used for users that are "participatoy space admins", not # organization-wide admins. This method will later be used to find out # what moderations can the current user manage. # # Returns an Array. def spaces_user_is_admin_to @spaces_user_is_admin_to ||= Decidim.participatory_space_manifests.flat_map do |manifest| Decidim .find_participatory_space_manifest(manifest.name) .participatory_spaces .call(current_organization)&.select do |space| space.moderators.exists?(id: current_user.id) end end end # Private: finds the moderations the current user can manage, taking into # account whether the user is an organization-wide admin or a # "participatory space admin". # # Returns an `ActiveRecord::Relation` def moderations_for_user @moderations_for_user ||= if current_user.admin? Decidim::Moderation.all else Decidim::Moderation.where(participatory_space: spaces_user_is_admin_to) end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
decidim-admin-0.24.0.rc2 | app/controllers/concerns/decidim/admin/global_moderation_context.rb |
decidim-admin-0.24.0.rc1 | app/controllers/concerns/decidim/admin/global_moderation_context.rb |