decidim-department_admin 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-AGPLv3.txt +661 -0
  3. data/README.md +132 -0
  4. data/Rakefile +9 -0
  5. data/app/controllers/decidim/department_admin/admin/application_controller.rb +15 -0
  6. data/app/controllers/decidim/department_admin/application_controller.rb +13 -0
  7. data/app/decorators/decidim/admin/newsletters_controller_decorator.rb +30 -0
  8. data/app/decorators/decidim/admin/users_controller_decorator.rb +128 -0
  9. data/app/decorators/decidim/area_decorator.rb +44 -0
  10. data/app/decorators/decidim/assemblies/admin/assemblies_controller_decorator.rb +25 -0
  11. data/app/decorators/decidim/assemblies/admin/assemblies_helper_decorator.rb +24 -0
  12. data/app/decorators/decidim/assemblies/create_assembly_decorator.rb +19 -0
  13. data/app/decorators/decidim/assemblies/parent_assemblies_for_select_decorator.rb +38 -0
  14. data/app/decorators/decidim/assemblies/permissions_decorator.rb +22 -0
  15. data/app/decorators/decidim/assemblies/update_assembly_decorator.rb +19 -0
  16. data/app/decorators/decidim/assemblies_decorator.rb +21 -0
  17. data/app/decorators/decidim/assemblies_with_user_role_decorator.rb +27 -0
  18. data/app/decorators/decidim/conference_form_decorator.rb +23 -0
  19. data/app/decorators/decidim/conferences/admin/conferences_controller_decorator.rb +27 -0
  20. data/app/decorators/decidim/conferences/create_conference_decorator.rb +52 -0
  21. data/app/decorators/decidim/conferences/permissions_decorator.rb +24 -0
  22. data/app/decorators/decidim/conferences/update_conference_decorator.rb +21 -0
  23. data/app/decorators/decidim/conferences_decorator.rb +27 -0
  24. data/app/decorators/decidim/conferences_with_user_role_decorator.rb +29 -0
  25. data/app/decorators/decidim/decidim_form_helper_decorator.rb +23 -0
  26. data/app/decorators/decidim/invite_user_decorator.rb +56 -0
  27. data/app/decorators/decidim/invite_user_form_decorator.rb +45 -0
  28. data/app/decorators/decidim/newsletter_decorator.rb +20 -0
  29. data/app/decorators/decidim/newsletters_helper_decorator.rb +44 -0
  30. data/app/decorators/decidim/participatory_process_decorator.rb +21 -0
  31. data/app/decorators/decidim/participatory_process_group_decorator.rb +17 -0
  32. data/app/decorators/decidim/participatory_processes/admin/participatory_processes_controller_decorator.rb +25 -0
  33. data/app/decorators/decidim/participatory_processes/create_participatory_process_decorator.rb +19 -0
  34. data/app/decorators/decidim/participatory_processes/permissions_decorator.rb +22 -0
  35. data/app/decorators/decidim/participatory_processes/update_participatory_process_decorator.rb +19 -0
  36. data/app/decorators/decidim/participatory_processes_with_user_role_decorator.rb +27 -0
  37. data/app/decorators/decidim/user_decorator.rb +59 -0
  38. data/app/decorators/lib/decidim/participatory_space_resourceable_decorator.rb +33 -0
  39. data/app/helpers/decidim/admin/user_roles_helper.rb +25 -0
  40. data/app/helpers/decidim/department_admin/application_helper.rb +54 -0
  41. data/app/models/decidim/participatory_space_role_config/department_admin.rb +8 -0
  42. data/app/overrides/decidim/admin/shared/add_radio_buttons_to_filters.rb +6 -0
  43. data/app/packs/entrypoints/decidim_department_admin.js +4 -0
  44. data/app/packs/entrypoints/decidim_department_admin.scss +1 -0
  45. data/app/packs/images/decidim/department_admin/icon.svg +1 -0
  46. data/app/packs/stylesheets/decidim/admin/department_admin.scss +7 -0
  47. data/app/permissions/decidim/assemblies/participatory_space_permissions.rb +14 -0
  48. data/app/permissions/decidim/conferences/participatory_space_permissions.rb +17 -0
  49. data/app/permissions/decidim/department_admin/permissions.rb +240 -0
  50. data/app/permissions/decidim/participatory_processes/participatory_space_permissions.rb +14 -0
  51. data/app/queries/decidim/admin/user_admin_by_space_name_filter.rb +67 -0
  52. data/app/queries/decidim/admin/user_admin_filter.rb +50 -0
  53. data/app/views/decidim/admin/users/_filters.html.erb +32 -0
  54. data/app/views/decidim/admin/users/_form.html.erb +36 -0
  55. data/app/views/decidim/admin/users/index.html.erb +91 -0
  56. data/app/views/decidim/admin/users/show.html.erb +98 -0
  57. data/app/views/decidim/assemblies/admin/assemblies/index.html.erb +139 -0
  58. data/app/views/decidim/conferences/admin/conferences/_form.html.erb +134 -0
  59. data/app/views/decidim/conferences/admin/conferences/index.html.erb +78 -0
  60. data/app/views/decidim/participatory_processes/admin/participatory_processes/index.html.erb +117 -0
  61. data/config/assets.rb +27 -0
  62. data/config/i18n-tasks.yml +148 -0
  63. data/config/initializers/user_roles.rb +4 -0
  64. data/config/locales/ca.yml +61 -0
  65. data/config/locales/cs.yml +46 -0
  66. data/config/locales/en.yml +61 -0
  67. data/config/locales/es.yml +61 -0
  68. data/db/migrate/20190328130102_create_department_admin_areas.rb +10 -0
  69. data/db/migrate/20210420143021_add_area_to_conferences.rb +7 -0
  70. data/lib/decidim/department_admin/admin.rb +10 -0
  71. data/lib/decidim/department_admin/admin_engine.rb +27 -0
  72. data/lib/decidim/department_admin/engine.rb +136 -0
  73. data/lib/decidim/department_admin/test/factories.rb +17 -0
  74. data/lib/decidim/department_admin/version.rb +11 -0
  75. data/lib/decidim/department_admin.rb +15 -0
  76. metadata +189 -0
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "decidim/core"
5
+
6
+ module Decidim
7
+ module DepartmentAdmin
8
+ # This is the engine that runs on the public interface of department_admin.
9
+ class Engine < ::Rails::Engine
10
+ isolate_namespace Decidim::DepartmentAdmin
11
+
12
+ # make decorators autoload in development env
13
+ config.autoload_paths << File.join(
14
+ Decidim::DepartmentAdmin::Engine.root, "app", "decorators", "{**}"
15
+ )
16
+
17
+ routes do
18
+ # Add engine routes here
19
+ # resources :department_admin
20
+ # root to: "department_admin#index"
21
+ end
22
+
23
+ initializer "department_admin.webpacker.assets_path" do
24
+ Decidim.register_assets_path File.expand_path("app/packs", root)
25
+ end
26
+
27
+ # rubocop: disable Lint/ConstantDefinitionInBlock
28
+ initializer "department_admin.permissions_registry" do
29
+ # activate Decidim LayoutHelper for the overriden views
30
+ ::Decidim::Admin::ApplicationController.helper ::Decidim::LayoutHelper
31
+ ::Decidim::ApplicationController.helper ::Decidim::LayoutHelper
32
+
33
+ # avoid webpacker to crash when executing before Decidim is loaded
34
+ next unless Rails.env.test? || defined? DecidimController
35
+
36
+ # **
37
+ # Modify decidim-admin permissions registry
38
+ # **
39
+ artifact = ::Decidim::Admin::ApplicationController
40
+ AdminApplicationControllerPermissions = Class.new(::Decidim::DepartmentAdmin::Permissions)
41
+ register_new_permissions_for(artifact, AdminApplicationControllerPermissions)
42
+
43
+ # **
44
+ # Modify decidim-particypatory_processes permissions registry
45
+ # **
46
+
47
+ # force the concern to be included so that registry is initialized
48
+ # we choose some random class already including it
49
+ require "decidim/participatory_processes/admin/categories_controller"
50
+ artifact = ::Decidim::ParticipatoryProcesses::Admin::Concerns::ParticipatoryProcessAdmin
51
+ ParticipatoryProcessesAdminConcernPermissions = Class.new(::Decidim::DepartmentAdmin::Permissions)
52
+ register_new_permissions_for(artifact, ParticipatoryProcessesAdminConcernPermissions)
53
+
54
+ artifact = Decidim::ParticipatoryProcesses::Admin::ApplicationController
55
+ ParticipatoryProcessesAdminApplicationControllerPermissions = Class.new(::Decidim::DepartmentAdmin::Permissions)
56
+ register_new_permissions_for(artifact, ParticipatoryProcessesAdminApplicationControllerPermissions)
57
+
58
+ # public views produce problems with Devise's current_user
59
+ # require 'decidim/participatory_processes/application_controller'
60
+ # artifact= 'Decidim::ParticipatoryProcesses::ApplicationController'
61
+ # chain= ::Decidim.permissions_registry.chain_for(artifact)
62
+ # chain << ::Decidim::DepartmentAdmin::Permissions
63
+
64
+ # **
65
+ # Modify decidim-assemblies permissions registry
66
+ # **
67
+ require "decidim/assemblies/admin/assembly_copies_controller"
68
+ require "decidim/assemblies/admin/components_controller"
69
+ artifact = ::Decidim::Assemblies::Admin::Concerns::AssemblyAdmin
70
+ AssembliesAdminConcernPermissions = Class.new(::Decidim::DepartmentAdmin::Permissions)
71
+ register_new_permissions_for(artifact, AssembliesAdminConcernPermissions)
72
+
73
+ artifact = Decidim::Assemblies::Admin::ApplicationController
74
+ AssembliesAdminApplicationControllerPermissions = Class.new(::Decidim::DepartmentAdmin::Permissions)
75
+ register_new_permissions_for(artifact, AssembliesAdminApplicationControllerPermissions)
76
+
77
+ if Decidim::DepartmentAdmin.conferences_defined?
78
+ # **
79
+ # Modify decidim-conferences permissions registry
80
+ # **
81
+ require "decidim/conferences/admin/conference_copies_controller"
82
+ require "decidim/conferences/admin/components_controller"
83
+ artifact = ::Decidim::Conferences::Admin::Concerns::ConferenceAdmin
84
+ ConferencesAdminConcernPermissions = Class.new(::Decidim::DepartmentAdmin::Permissions)
85
+ register_new_permissions_for(artifact, ConferencesAdminConcernPermissions)
86
+
87
+ artifact = Decidim::Conferences::Admin::ApplicationController
88
+ ConferencesAdminApplicationControllerPermissions = Class.new(::Decidim::DepartmentAdmin::Permissions)
89
+ register_new_permissions_for(artifact, ConferencesAdminApplicationControllerPermissions)
90
+ end
91
+ end
92
+ # rubocop: enable Lint/ConstantDefinitionInBlock
93
+
94
+ # make decorators available to applications that use this Engine
95
+ config.to_prepare do
96
+ decorators = "#{Decidim::DepartmentAdmin::Engine.root}/app/decorators"
97
+ Dir.glob("#{decorators}/**/*_decorator.rb").each do |decorator|
98
+ require_dependency(decorator)
99
+ end
100
+ end
101
+
102
+ config.after_initialize do
103
+ require "decidim/participatory_processes/participatory_space"
104
+ # override participatory_processes space manifest permissions with DepartmentAdmin's one
105
+ manifest = Decidim.find_participatory_space_manifest(:participatory_processes)
106
+ manifest.permissions_class_name = "Decidim::ParticipatoryProcesses::ParticipatorySpacePermissions"
107
+ # override assemblies space manifest permissions with DepartmentAdmin's one
108
+ manifest = Decidim.find_participatory_space_manifest(:assemblies)
109
+ manifest.permissions_class_name = "Decidim::Assemblies::ParticipatorySpacePermissions"
110
+ if Decidim::DepartmentAdmin.conferences_defined?
111
+ # override conferences space manifest permissions with DepartmentAdmin's one
112
+ manifest = Decidim.find_participatory_space_manifest(:conferences)
113
+ manifest.permissions_class_name = "Decidim::Conferences::ParticipatorySpacePermissions"
114
+ end
115
+ end
116
+
117
+ #------------------------------------------------------
118
+
119
+ private
120
+
121
+ #------------------------------------------------------
122
+
123
+ # Modifies the permissions registry for the given +artifact+ with +new_permissions_class+.
124
+ # NOTE: Previous permissions are cleared and setted to the +new_permissions_class+ for delegation.
125
+ def register_new_permissions_for(artifact, new_permissions_class)
126
+ chain = ::Decidim.permissions_registry.chain_for(artifact)
127
+ # configure old chain, in case new permissions has to delegate
128
+ new_permissions_class.delegate_chain = chain.dup
129
+ # re-set the permissions classes to DepartmentAdmin::Permissions' subclass
130
+ chain.clear
131
+ chain << new_permissions_class
132
+ Rails.logger.info("Registered new permissions for #{artifact} to: #{::Decidim.permissions_registry.chain_for(artifact)}")
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/core/test/factories"
4
+
5
+ FactoryBot.define do
6
+ factory :department_admin, parent: :user do
7
+ roles { ["department_admin"] }
8
+ admin_terms_accepted_at { Time.zone.now }
9
+ transient do
10
+ area { nil }
11
+ end
12
+
13
+ after(:build) do |user, evaluator|
14
+ user.areas << evaluator.area if evaluator.area.present?
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This holds the decidim-module-department_admin version.
5
+ module DepartmentAdmin
6
+ # see CHANGELOG.md
7
+ def self.version
8
+ "0.8.0"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/department_admin/admin"
4
+ require "decidim/department_admin/engine"
5
+ require "decidim/department_admin/admin_engine"
6
+
7
+ module Decidim
8
+ # This namespace holds the logic of the `DepartmentAdmin` module. This module
9
+ # allows users to create department_admin in a participatory space.
10
+ module DepartmentAdmin
11
+ def self.conferences_defined?
12
+ defined?(Decidim::Conferences::QueryExtensions)
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decidim-department_admin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: ruby
6
+ authors:
7
+ - Oliver Valls
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: decidim-admin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.28.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.28.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: decidim-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.28.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.28.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: decidim
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.28.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.28.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: decidim-conferences
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.28.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.28.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: decidim-dev
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.28.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.28.0
83
+ description: This Dedicim's module produces a new "department admin" role which restricts
84
+ the permissions of an Admin into participatory spaces of a given Area.
85
+ email:
86
+ - oliver.vh@coditramuntana.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - LICENSE-AGPLv3.txt
92
+ - README.md
93
+ - Rakefile
94
+ - app/controllers/decidim/department_admin/admin/application_controller.rb
95
+ - app/controllers/decidim/department_admin/application_controller.rb
96
+ - app/decorators/decidim/admin/newsletters_controller_decorator.rb
97
+ - app/decorators/decidim/admin/users_controller_decorator.rb
98
+ - app/decorators/decidim/area_decorator.rb
99
+ - app/decorators/decidim/assemblies/admin/assemblies_controller_decorator.rb
100
+ - app/decorators/decidim/assemblies/admin/assemblies_helper_decorator.rb
101
+ - app/decorators/decidim/assemblies/create_assembly_decorator.rb
102
+ - app/decorators/decidim/assemblies/parent_assemblies_for_select_decorator.rb
103
+ - app/decorators/decidim/assemblies/permissions_decorator.rb
104
+ - app/decorators/decidim/assemblies/update_assembly_decorator.rb
105
+ - app/decorators/decidim/assemblies_decorator.rb
106
+ - app/decorators/decidim/assemblies_with_user_role_decorator.rb
107
+ - app/decorators/decidim/conference_form_decorator.rb
108
+ - app/decorators/decidim/conferences/admin/conferences_controller_decorator.rb
109
+ - app/decorators/decidim/conferences/create_conference_decorator.rb
110
+ - app/decorators/decidim/conferences/permissions_decorator.rb
111
+ - app/decorators/decidim/conferences/update_conference_decorator.rb
112
+ - app/decorators/decidim/conferences_decorator.rb
113
+ - app/decorators/decidim/conferences_with_user_role_decorator.rb
114
+ - app/decorators/decidim/decidim_form_helper_decorator.rb
115
+ - app/decorators/decidim/invite_user_decorator.rb
116
+ - app/decorators/decidim/invite_user_form_decorator.rb
117
+ - app/decorators/decidim/newsletter_decorator.rb
118
+ - app/decorators/decidim/newsletters_helper_decorator.rb
119
+ - app/decorators/decidim/participatory_process_decorator.rb
120
+ - app/decorators/decidim/participatory_process_group_decorator.rb
121
+ - app/decorators/decidim/participatory_processes/admin/participatory_processes_controller_decorator.rb
122
+ - app/decorators/decidim/participatory_processes/create_participatory_process_decorator.rb
123
+ - app/decorators/decidim/participatory_processes/permissions_decorator.rb
124
+ - app/decorators/decidim/participatory_processes/update_participatory_process_decorator.rb
125
+ - app/decorators/decidim/participatory_processes_with_user_role_decorator.rb
126
+ - app/decorators/decidim/user_decorator.rb
127
+ - app/decorators/lib/decidim/participatory_space_resourceable_decorator.rb
128
+ - app/helpers/decidim/admin/user_roles_helper.rb
129
+ - app/helpers/decidim/department_admin/application_helper.rb
130
+ - app/models/decidim/participatory_space_role_config/department_admin.rb
131
+ - app/overrides/decidim/admin/shared/add_radio_buttons_to_filters.rb
132
+ - app/packs/entrypoints/decidim_department_admin.js
133
+ - app/packs/entrypoints/decidim_department_admin.scss
134
+ - app/packs/images/decidim/department_admin/icon.svg
135
+ - app/packs/stylesheets/decidim/admin/department_admin.scss
136
+ - app/permissions/decidim/assemblies/participatory_space_permissions.rb
137
+ - app/permissions/decidim/conferences/participatory_space_permissions.rb
138
+ - app/permissions/decidim/department_admin/permissions.rb
139
+ - app/permissions/decidim/participatory_processes/participatory_space_permissions.rb
140
+ - app/queries/decidim/admin/user_admin_by_space_name_filter.rb
141
+ - app/queries/decidim/admin/user_admin_filter.rb
142
+ - app/views/decidim/admin/users/_filters.html.erb
143
+ - app/views/decidim/admin/users/_form.html.erb
144
+ - app/views/decidim/admin/users/index.html.erb
145
+ - app/views/decidim/admin/users/show.html.erb
146
+ - app/views/decidim/assemblies/admin/assemblies/index.html.erb
147
+ - app/views/decidim/conferences/admin/conferences/_form.html.erb
148
+ - app/views/decidim/conferences/admin/conferences/index.html.erb
149
+ - app/views/decidim/participatory_processes/admin/participatory_processes/index.html.erb
150
+ - config/assets.rb
151
+ - config/i18n-tasks.yml
152
+ - config/initializers/user_roles.rb
153
+ - config/locales/ca.yml
154
+ - config/locales/cs.yml
155
+ - config/locales/en.yml
156
+ - config/locales/es.yml
157
+ - db/migrate/20190328130102_create_department_admin_areas.rb
158
+ - db/migrate/20210420143021_add_area_to_conferences.rb
159
+ - lib/decidim/department_admin.rb
160
+ - lib/decidim/department_admin/admin.rb
161
+ - lib/decidim/department_admin/admin_engine.rb
162
+ - lib/decidim/department_admin/engine.rb
163
+ - lib/decidim/department_admin/test/factories.rb
164
+ - lib/decidim/department_admin/version.rb
165
+ homepage: https://github.com/decidim/decidim-module-department_admin
166
+ licenses:
167
+ - AGPL-3.0
168
+ metadata:
169
+ rubygems_mfa_required: 'true'
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: 3.1.1
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubygems_version: 3.3.7
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: A decidim department_admin module
189
+ test_files: []