decidim-department_admin 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/decorators/decidim/admin/department_filter_decorator.rb +54 -0
- data/app/decorators/decidim/ransackable_attributes_decorator.rb +15 -2
- data/config/i18n-tasks.yml +3 -0
- data/config/locales/ca.yml +3 -0
- data/config/locales/cs.yml +3 -0
- data/config/locales/en.yml +3 -0
- data/config/locales/es.yml +3 -0
- data/lib/decidim/department_admin/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7bfc0e1e141af5d70b51165898413ce1db47ffb16f51e43248e4ad1d417225da
|
|
4
|
+
data.tar.gz: e5c0937519cf8dada53ad2f81718e901271927887dca00e1973cbe237bccfdc6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9c84db0de327fd63cf9741a32112abcc84d69258b658eb7e7c84b5545a34018802ba2d3e61a0ea1ac54212c62a1023f85ff4fb979c088ef75c37a4dc56467c62
|
|
7
|
+
data.tar.gz: c33d72bcdedd66cd715f28114ef811ab1c7b5f4f09b7fd3bc84036485fc8c09c2a6ba9647bff9dd46177cce4903643a1a6731165971f5f98f04a50751d4b3efa
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim::Admin::DepartmentFilterDecorator
|
|
4
|
+
#
|
|
5
|
+
# This decorator adds a "Department" option to the "Filter" dropdown of the
|
|
6
|
+
# participatory processes and assemblies admin lists.
|
|
7
|
+
#
|
|
8
|
+
# The departments are queried on every request, so the options follow the
|
|
9
|
+
# departments created, renamed or removed. Organization admins get all the
|
|
10
|
+
# departments of the organization, department admins only their own ones.
|
|
11
|
+
#
|
|
12
|
+
FILTER = :decidim_department_admin_department_id_eq
|
|
13
|
+
|
|
14
|
+
def self.decorate
|
|
15
|
+
[
|
|
16
|
+
Decidim::ParticipatoryProcesses::Admin::ParticipatoryProcessesController,
|
|
17
|
+
Decidim::Assemblies::Admin::AssembliesController,
|
|
18
|
+
].each do |controller|
|
|
19
|
+
controller.prepend(self)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def filters
|
|
26
|
+
return super if filterable_departments.empty?
|
|
27
|
+
|
|
28
|
+
super + [FILTER]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def filters_with_values
|
|
32
|
+
return super if filterable_departments.empty?
|
|
33
|
+
|
|
34
|
+
super.merge(FILTER => filterable_departments.map(&:id))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def dynamically_translated_filters
|
|
38
|
+
super + [FILTER]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def translated_decidim_department_admin_department_id_eq(id)
|
|
42
|
+
translated_attribute(filterable_departments.find { |department| department.id == id.to_i }&.name)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def filterable_departments
|
|
46
|
+
@filterable_departments ||= begin
|
|
47
|
+
departments = Decidim::DepartmentAdmin::Department.where(organization: current_organization)
|
|
48
|
+
departments = departments.where(id: current_user.departments) unless current_user.admin?
|
|
49
|
+
departments.sort_by { |department| I18n.transliterate(translated_attribute(department.name).to_s).downcase }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
Decidim::Admin::DepartmentFilterDecorator.decorate
|
|
@@ -5,7 +5,11 @@ module Decidim::RansackableAttributesDecorator
|
|
|
5
5
|
# Decidim only allows organization admins to filter and sort by admin attributes (private_space,
|
|
6
6
|
# published_at, process group...). Department admins need them too in the admin spaces lists.
|
|
7
7
|
#
|
|
8
|
+
# It also allows organization admins and department admins to filter processes and assemblies
|
|
9
|
+
# by department, used by the "Department" option of the admin lists "Filter" dropdown.
|
|
10
|
+
#
|
|
8
11
|
ADMIN_AUTH_OBJECT = Object.new.tap { |auth_object| auth_object.define_singleton_method(:admin?) { true } }.freeze
|
|
12
|
+
DEPARTMENT_ATTRIBUTE = "decidim_department_admin_department_id"
|
|
9
13
|
|
|
10
14
|
def self.decorate
|
|
11
15
|
models = [Decidim::ParticipatoryProcess, Decidim::Assembly]
|
|
@@ -16,9 +20,18 @@ module Decidim::RansackableAttributesDecorator
|
|
|
16
20
|
end
|
|
17
21
|
|
|
18
22
|
def ransackable_attributes(auth_object = nil)
|
|
19
|
-
|
|
23
|
+
attributes = auth_object.try(:department_admin?) ? super(ADMIN_AUTH_OBJECT) : super
|
|
24
|
+
return attributes unless filterable_by_department?(auth_object)
|
|
25
|
+
|
|
26
|
+
attributes + [DEPARTMENT_ATTRIBUTE]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def filterable_by_department?(auth_object)
|
|
32
|
+
return false unless [Decidim::ParticipatoryProcess, Decidim::Assembly].include?(self)
|
|
20
33
|
|
|
21
|
-
|
|
34
|
+
auth_object.try(:admin?) || auth_object.try(:department_admin?)
|
|
22
35
|
end
|
|
23
36
|
end
|
|
24
37
|
|
data/config/i18n-tasks.yml
CHANGED
|
@@ -103,6 +103,7 @@ ignore_unused:
|
|
|
103
103
|
- 'activemodel.attributes.conference.decidim_department_admin_department_id'
|
|
104
104
|
- 'activemodel.attributes.participatory_process.decidim_department_admin_department_id'
|
|
105
105
|
- 'activerecord.models.decidim/department_admin/*'
|
|
106
|
+
- 'decidim.admin.filters.decidim_department_admin_department_id_eq.label'
|
|
106
107
|
- 'decidim.admin.models.assembly.fields.assembly_role'
|
|
107
108
|
- 'decidim.admin.models.assembly.fields.department'
|
|
108
109
|
- 'decidim.admin.models.assembly.fields.department_role'
|
|
@@ -112,7 +113,9 @@ ignore_unused:
|
|
|
112
113
|
- 'decidim.admin.models.participatory_process.fields.department'
|
|
113
114
|
- 'decidim.admin.models.participatory_process.fields.department_role'
|
|
114
115
|
- 'decidim.admin.models.participatory_process.fields.process_role'
|
|
116
|
+
- 'decidim.admin.models.user.fields.roles.assembly_admin'
|
|
115
117
|
- 'decidim.admin.models.user.fields.roles.department_admin'
|
|
118
|
+
- 'decidim.admin.models.user.fields.roles.process_admin'
|
|
116
119
|
- 'decidim.admin.shared.filters.filter.all'
|
|
117
120
|
- 'decidim.admin.shared.filters.filter_by'
|
|
118
121
|
- 'decidim.admin.users.form.area'
|
data/config/locales/ca.yml
CHANGED
data/config/locales/cs.yml
CHANGED
data/config/locales/en.yml
CHANGED
data/config/locales/es.yml
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: decidim-department_admin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oliver Valls
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-12-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: decidim-admin
|
|
@@ -55,6 +55,7 @@ files:
|
|
|
55
55
|
- app/controllers/decidim/department_admin/admin/application_controller.rb
|
|
56
56
|
- app/controllers/decidim/department_admin/admin/departments_controller.rb
|
|
57
57
|
- app/controllers/decidim/department_admin/application_controller.rb
|
|
58
|
+
- app/decorators/decidim/admin/department_filter_decorator.rb
|
|
58
59
|
- app/decorators/decidim/admin/newsletters_controller_decorator.rb
|
|
59
60
|
- app/decorators/decidim/admin/newsletters_helper_decorator.rb
|
|
60
61
|
- app/decorators/decidim/admin/users_controller_decorator.rb
|