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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24d58aa034491220887e6b920b097bd26427a969805e56ecb74e37b5ec6d13ec
4
- data.tar.gz: c1331f69cd2018ff0b85b1b42a3409fcb5a731687df6c6d432b5a096a3821055
3
+ metadata.gz: 7bfc0e1e141af5d70b51165898413ce1db47ffb16f51e43248e4ad1d417225da
4
+ data.tar.gz: e5c0937519cf8dada53ad2f81718e901271927887dca00e1973cbe237bccfdc6
5
5
  SHA512:
6
- metadata.gz: 345e363c55dc2c3eac6aa960f222cda930d5d367d9ee7eb9cedbbff7698b32c46da114ac63970c571f614d7c96f3159f8f83ffea9a9be2a3685d7f2d7396e57b
7
- data.tar.gz: 25c51dc6716ae06b9703d41231aab7a46758311d59e6e9ade5242939d169c33f99286444dd532ff02fc5482c5b663b9d6616e3facd64408ae91458b7d8947403
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
- return super unless auth_object.try(:department_admin?)
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
- super(ADMIN_AUTH_OBJECT)
34
+ auth_object.try(:admin?) || auth_object.try(:department_admin?)
22
35
  end
23
36
  end
24
37
 
@@ -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'
@@ -15,6 +15,9 @@ ca:
15
15
  other: Departaments
16
16
  decidim:
17
17
  admin:
18
+ filters:
19
+ decidim_department_admin_department_id_eq:
20
+ label: Departament
18
21
  models:
19
22
  assembly:
20
23
  fields:
@@ -13,6 +13,9 @@ cs:
13
13
  other: Oddělení
14
14
  decidim:
15
15
  admin:
16
+ filters:
17
+ decidim_department_admin_department_id_eq:
18
+ label: Oddělení
16
19
  models:
17
20
  assembly:
18
21
  fields:
@@ -15,6 +15,9 @@ en:
15
15
  other: Departments
16
16
  decidim:
17
17
  admin:
18
+ filters:
19
+ decidim_department_admin_department_id_eq:
20
+ label: Department
18
21
  models:
19
22
  assembly:
20
23
  fields:
@@ -15,6 +15,9 @@ es:
15
15
  other: Departamentos
16
16
  decidim:
17
17
  admin:
18
+ filters:
19
+ decidim_department_admin_department_id_eq:
20
+ label: Departamento
18
21
  models:
19
22
  assembly:
20
23
  fields:
@@ -5,7 +5,7 @@ module Decidim
5
5
  module DepartmentAdmin
6
6
  # see CHANGELOG.md
7
7
  def self.version
8
- "0.12.0"
8
+ "0.13.0"
9
9
  end
10
10
 
11
11
  DECIDIM_VER = "~> 0.31.0"
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.12.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-23 00:00:00.000000000 Z
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