decidim-department_admin 0.8.0 → 0.12.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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -10
  3. data/app/commands/decidim/department_admin/admin/create_department.rb +15 -0
  4. data/app/commands/decidim/department_admin/admin/destroy_department.rb +24 -0
  5. data/app/commands/decidim/department_admin/admin/update_department.rb +11 -0
  6. data/app/controllers/decidim/department_admin/admin/departments_controller.rb +92 -0
  7. data/app/decorators/decidim/admin/newsletters_controller_decorator.rb +5 -5
  8. data/app/decorators/decidim/{newsletters_helper_decorator.rb → admin/newsletters_helper_decorator.rb} +5 -6
  9. data/app/decorators/decidim/admin/users_controller_decorator.rb +10 -10
  10. data/app/decorators/decidim/assemblies/admin/assemblies_controller_decorator.rb +1 -1
  11. data/app/decorators/decidim/assemblies/admin/assemblies_helper_decorator.rb +11 -6
  12. data/app/decorators/decidim/assemblies/admin/assembly_form_decorator.rb +11 -0
  13. data/app/decorators/decidim/assemblies/assembly_presenter_decorator.rb +15 -0
  14. data/app/decorators/decidim/assemblies/content_blocks/metadata_cell_decorator.rb +15 -0
  15. data/app/decorators/decidim/assemblies/create_assembly_decorator.rb +18 -6
  16. data/app/decorators/decidim/assemblies/parent_assemblies_for_select_decorator.rb +2 -2
  17. data/app/decorators/decidim/assemblies/permissions_decorator.rb +1 -1
  18. data/app/decorators/decidim/assemblies/update_assembly_decorator.rb +14 -7
  19. data/app/decorators/decidim/assemblies_decorator.rb +5 -0
  20. data/app/decorators/decidim/assemblies_with_user_role_decorator.rb +4 -4
  21. data/app/decorators/decidim/conference_form_decorator.rb +6 -6
  22. data/app/decorators/decidim/conferences/conference_presenter_decorator.rb +17 -0
  23. data/app/decorators/decidim/conferences/create_conference_decorator.rb +4 -40
  24. data/app/decorators/decidim/conferences/duplicate_conference_decorator.rb +21 -0
  25. data/app/decorators/decidim/conferences/permissions_decorator.rb +1 -1
  26. data/app/decorators/decidim/conferences/update_conference_decorator.rb +5 -9
  27. data/app/decorators/decidim/conferences_decorator.rb +3 -3
  28. data/app/decorators/decidim/conferences_with_user_role_decorator.rb +3 -7
  29. data/app/decorators/decidim/decidim_form_helper_decorator.rb +10 -0
  30. data/app/decorators/decidim/invite_user_decorator.rb +10 -10
  31. data/app/decorators/decidim/invite_user_form_decorator.rb +10 -8
  32. data/app/decorators/decidim/newsletter_decorator.rb +8 -7
  33. data/app/decorators/decidim/organization_decorator.rb +13 -0
  34. data/app/decorators/decidim/participatory_process_decorator.rb +5 -0
  35. data/app/decorators/decidim/participatory_processes/admin/participatory_process_form_decorator.rb +11 -0
  36. data/app/decorators/decidim/participatory_processes/admin/participatory_processes_controller_decorator.rb +3 -3
  37. data/app/decorators/decidim/participatory_processes/content_blocks/metadata_cell_decorator.rb +19 -0
  38. data/app/decorators/decidim/participatory_processes/create_participatory_process_decorator.rb +19 -6
  39. data/app/decorators/decidim/participatory_processes/participatory_process_presenter_decorator.rb +15 -0
  40. data/app/decorators/decidim/participatory_processes/permissions_decorator.rb +1 -1
  41. data/app/decorators/decidim/participatory_processes/update_participatory_process_decorator.rb +14 -6
  42. data/app/decorators/decidim/participatory_processes_with_user_role_decorator.rb +4 -4
  43. data/app/decorators/decidim/ransackable_attributes_decorator.rb +25 -0
  44. data/app/decorators/decidim/user_decorator.rb +7 -0
  45. data/app/decorators/lib/decidim/participatory_space_resourceable_decorator.rb +22 -24
  46. data/app/forms/decidim/department_admin/admin/department_form.rb +19 -0
  47. data/app/models/decidim/department_admin/department.rb +57 -0
  48. data/app/overrides/decidim/admin/shared/add_radio_buttons_to_filters.rb +9 -2
  49. data/app/overrides/decidim/admin/users/add_department_to_form.rb +25 -0
  50. data/app/overrides/decidim/assemblies/admin/assemblies/add_department_columns_to_assemblies_thead.rb +18 -0
  51. data/app/overrides/decidim/assemblies/admin/assemblies/add_department_columns_to_assembly_row.rb +18 -0
  52. data/app/overrides/decidim/assemblies/admin/assemblies/add_department_to_form.rb +30 -0
  53. data/app/overrides/decidim/conferences/admin/conferences/add_department_columns_to_conference_row.rb +18 -0
  54. data/app/overrides/decidim/conferences/admin/conferences/add_department_columns_to_conferences_thead.rb +12 -0
  55. data/app/overrides/decidim/conferences/admin/conferences/add_department_to_form.rb +27 -0
  56. data/app/overrides/decidim/participatory_processes/admin/participatory_processes/add_department_columns_to_process_row.rb +18 -0
  57. data/app/overrides/decidim/participatory_processes/admin/participatory_processes/add_department_columns_to_processes_thead.rb +18 -0
  58. data/app/overrides/decidim/participatory_processes/admin/participatory_processes/add_department_to_form.rb +30 -0
  59. data/app/permissions/decidim/department_admin/permissions.rb +90 -42
  60. data/app/presenters/decidim/department_admin/department_presenter.rb +16 -0
  61. data/app/views/decidim/admin/users/_role_filter.html.erb +18 -0
  62. data/app/views/decidim/admin/users/_search_mode_filter.html.erb +13 -0
  63. data/app/views/decidim/admin/users/index.html.erb +73 -43
  64. data/app/views/decidim/department_admin/admin/departments/_form.html.erb +9 -0
  65. data/app/views/decidim/department_admin/admin/departments/edit.html.erb +16 -0
  66. data/app/views/decidim/department_admin/admin/departments/index.html.erb +48 -0
  67. data/app/views/decidim/department_admin/admin/departments/new.html.erb +16 -0
  68. data/config/i18n-tasks.yml +27 -16
  69. data/config/locales/ca.yml +62 -1
  70. data/config/locales/cs.yml +59 -0
  71. data/config/locales/en.yml +62 -1
  72. data/config/locales/es.yml +62 -1
  73. data/db/migrate/20260506100001_create_decidim_department_admin_departments.rb +13 -0
  74. data/db/migrate/20260506100002_create_decidim_department_admin_user_departments.rb +16 -0
  75. data/db/migrate/20260506100003_add_decidim_department_admin_department_id_to_participatory_processes.rb +8 -0
  76. data/db/migrate/20260506100004_add_decidim_department_admin_department_id_to_assemblies.rb +8 -0
  77. data/db/migrate/20260515000001_migrate_department_admin_areas_to_departments.rb +66 -0
  78. data/db/migrate/20260909000001_add_decidim_department_admin_department_id_to_conferences.rb +10 -0
  79. data/db/migrate/20260909000002_migrate_department_admin_conference_areas_to_departments.rb +43 -0
  80. data/lib/decidim/department_admin/admin_engine.rb +21 -7
  81. data/lib/decidim/department_admin/engine.rb +68 -65
  82. data/lib/decidim/department_admin/test/factories.rb +7 -0
  83. data/lib/decidim/department_admin/version.rb +3 -1
  84. metadata +49 -58
  85. data/app/decorators/decidim/area_decorator.rb +0 -44
  86. data/app/views/decidim/admin/users/_filters.html.erb +0 -32
  87. data/app/views/decidim/admin/users/_form.html.erb +0 -36
  88. data/app/views/decidim/assemblies/admin/assemblies/index.html.erb +0 -139
  89. data/app/views/decidim/conferences/admin/conferences/_form.html.erb +0 -134
  90. data/app/views/decidim/conferences/admin/conferences/index.html.erb +0 -78
  91. data/app/views/decidim/participatory_processes/admin/participatory_processes/index.html.erb +0 -117
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63c5991ddf1ec9fea6f3e90c122341f19d02f97d832fbc7bb3635bfdec5f4091
4
- data.tar.gz: f750ada6b119dfd390332c15768a16b48ea6a37536f764cbaeb8962ded46a1ed
3
+ metadata.gz: 24d58aa034491220887e6b920b097bd26427a969805e56ecb74e37b5ec6d13ec
4
+ data.tar.gz: c1331f69cd2018ff0b85b1b42a3409fcb5a731687df6c6d432b5a096a3821055
5
5
  SHA512:
6
- metadata.gz: 00574e78d6877feeade71f8c9e70e77f3f49d91b44f378f73db50349c7e1408a0a1f820972fa8b784f44ed2c089345485ec357b54d0749a3113ab2bd88da039a
7
- data.tar.gz: 895bc003e2ad3af6b377c8671054bff0238bb9f32f3d79dce170b982a5b3d0a2b471c352c938a7acfbdba04ff1686552140ee6a8c7e88035b67841f026abffdc
6
+ metadata.gz: 345e363c55dc2c3eac6aa960f222cda930d5d367d9ee7eb9cedbbff7698b32c46da114ac63970c571f614d7c96f3159f8f83ffea9a9be2a3685d7f2d7396e57b
7
+ data.tar.gz: 25c51dc6716ae06b9703d41231aab7a46758311d59e6e9ade5242939d169c33f99286444dd532ff02fc5482c5b663b9d6616e3facd64408ae91458b7d8947403
data/README.md CHANGED
@@ -7,7 +7,7 @@ The module currently only affects the following participatory spaces and admin b
7
7
  - Participatory Processes: administer processes with the same area as the user's one.
8
8
  - Assemblies: administer assemblies with the same area as the user's one.
9
9
  - Newsletters: send newsletters to participants in the spaces with the same area as user's one.
10
- - Conferences: administer conferences with the same area as the user's one.
10
+ - Conferences: administer all conferences, with the same permissions as an admin. Conferences can be assigned to a department, but this is only used to classify them and does not restrict access.
11
11
 
12
12
  ## Usage
13
13
 
@@ -55,6 +55,8 @@ Beware that this module overrides many core features of Decidim. Thus, modified
55
55
 
56
56
  Most of the times the overrides and modifications will be found in `app/decorators`.
57
57
 
58
+ Changes to Decidim views are done with [Deface](https://github.com/spree/deface) overrides in `app/overrides`, instead of copying the whole view. For example, the department select in the spaces forms and the department columns in the admin lists of processes, assemblies and conferences.
59
+
58
60
  ## How it works
59
61
  Although some other artifacts exist, the key places to search for in this module are 3:
60
62
  - lib/decidim/department_admin/engine.rb
@@ -81,16 +83,9 @@ All decorator artifacts are extensions or modifications to the standard Decidim
81
83
 
82
84
  #### Temporal fix: added & in case role_name check.
83
85
 
84
- Currently, in the file:
85
- - lib/decidim/participatory_space_resourceable.rb
86
- we have overridden `user_role_config_for` method, in role_name case check.
87
-
88
- The reason for this, is that this method is called from `user_role_config` in `Decidim::Admin::UserRolesHelper` file, with second param `role_name` that can be nil as it is called as `role&.role`.
89
- This happens only when logged in user is Departmental Admin type and this can be possible because this module is only available in this repo.
90
- So, to avoid error when role_name passed is nil, we override this param check with a simple `role_name&.to_sym`
86
+ `app/decorators/lib/decidim/participatory_space_resourceable_decorator.rb` overrides `user_role_config_for` to use `role_name&.to_sym`.
91
87
 
92
- In next versions, this issue will be patched in `decidim/decidim`, so this override could be removed:
93
- - lib/decidim/participatory_space_resourceable.rb
88
+ `Decidim::Admin::UserRolesHelper#user_role_config` calls this method with `role&.role`, which is `nil` when the logged in user is a department admin without a role in the space. Decidim still calls `role_name.to_sym` (checked in 0.31), so the override is needed until this is fixed upstream.
94
89
 
95
90
  ### Run tests
96
91
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DepartmentAdmin
5
+ module Admin
6
+ class CreateDepartment < Decidim::Commands::CreateResource
7
+ fetch_form_attributes :name, :organization
8
+
9
+ protected
10
+
11
+ def resource_class = Decidim::DepartmentAdmin::Department
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DepartmentAdmin
5
+ module Admin
6
+ class DestroyDepartment < Decidim::Commands::DestroyResource
7
+ # Executes the command. Broadcasts these events:
8
+ #
9
+ # - :ok when everything is valid.
10
+ # - :invalid if the form was not valid and we could not proceed.
11
+ #
12
+ # Returns nothing.
13
+ def call
14
+ return broadcast(:has_department_admins) if resource.users.any?
15
+
16
+ destroy_resource
17
+ broadcast(:ok)
18
+ rescue ActiveRecord::RecordNotDestroyed
19
+ broadcast(:has_spaces)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DepartmentAdmin
5
+ module Admin
6
+ class UpdateDepartment < Decidim::Commands::UpdateResource
7
+ fetch_form_attributes :name
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module DepartmentAdmin
5
+ module Admin
6
+ class DepartmentsController < Decidim::Admin::ApplicationController
7
+ layout "decidim/admin/settings"
8
+
9
+ add_breadcrumb_item_from_menu :admin_settings_menu
10
+
11
+ helper_method :department, :organization_departments
12
+
13
+ def index
14
+ enforce_permission_to :read, :department
15
+ @departments = organization_departments
16
+ end
17
+
18
+ def new
19
+ enforce_permission_to :create, :department
20
+ @form = form(DepartmentForm).instance
21
+ end
22
+
23
+ def edit
24
+ enforce_permission_to :update, :department, department: department
25
+ @form = form(DepartmentForm).from_model(department)
26
+ end
27
+
28
+ def create
29
+ enforce_permission_to :create, :department
30
+ @form = form(DepartmentForm).from_params(params)
31
+
32
+ CreateDepartment.call(@form) do
33
+ on(:ok) do
34
+ flash[:notice] = I18n.t("departments.create.success", scope: "decidim.department_admin.admin")
35
+ redirect_to decidim_admin_department_admin.departments_path
36
+ end
37
+
38
+ on(:invalid) do
39
+ flash.now[:alert] = I18n.t("departments.create.error", scope: "decidim.department_admin.admin")
40
+ render :new
41
+ end
42
+ end
43
+ end
44
+
45
+ def update
46
+ enforce_permission_to :update, :department, department: department
47
+ @form = form(DepartmentForm).from_params(params)
48
+
49
+ UpdateDepartment.call(@form, department) do
50
+ on(:ok) do
51
+ flash[:notice] = I18n.t("departments.update.success", scope: "decidim.department_admin.admin")
52
+ redirect_to decidim_admin_department_admin.departments_path
53
+ end
54
+
55
+ on(:invalid) do
56
+ flash.now[:alert] = I18n.t("departments.update.error", scope: "decidim.department_admin.admin")
57
+ render :edit
58
+ end
59
+ end
60
+ end
61
+
62
+ def destroy
63
+ enforce_permission_to :destroy, :department, department: department
64
+
65
+ DestroyDepartment.call(department, current_user) do
66
+ on(:ok) do
67
+ flash[:notice] = I18n.t("departments.destroy.success", scope: "decidim.department_admin.admin")
68
+ redirect_to decidim_admin_department_admin.departments_path
69
+ end
70
+
71
+ on(:has_department_admins) do
72
+ flash[:alert] = I18n.t("departments.destroy.has_department_admins", scope: "decidim.department_admin.admin")
73
+ redirect_to decidim_admin_department_admin.departments_path
74
+ end
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def organization_departments
81
+ Decidim::DepartmentAdmin::Department.where(organization: current_organization)
82
+ end
83
+
84
+ def department
85
+ return @department if defined?(@department)
86
+
87
+ @department = organization_departments.find_by(id: params[:id])
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -3,7 +3,7 @@
3
3
  require_dependency "decidim/admin/newsletters_controller"
4
4
 
5
5
  module Decidim::Admin::NewslettersControllerDecorator
6
- # Sort Admins by role and area
6
+ # Sort Admins by role and department
7
7
  def self.decorate
8
8
  ::Decidim::Admin::NewslettersController.class_eval do
9
9
  alias_method :original_collection, :collection
@@ -14,14 +14,14 @@ module Decidim::Admin::NewslettersControllerDecorator
14
14
  return original_collection unless current_user.department_admin?
15
15
 
16
16
  @collection ||= Decidim::Newsletter.where(organization: current_organization)
17
- .joins(author: :areas)
18
- .where(department_admin_areas: { decidim_area_id: current_user_areas.pluck(:id) })
17
+ .joins(author: :departments)
18
+ .where(decidim_department_admin_departments: { id: current_user_departments.pluck(:id) })
19
19
  end
20
20
 
21
- def current_user_areas
21
+ def current_user_departments
22
22
  return unless current_user.department_admin?
23
23
 
24
- current_user.areas
24
+ current_user.departments
25
25
  end
26
26
  end
27
27
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Decidim::NewslettersHelperDecorator
3
+ module Decidim::Admin::NewslettersHelperDecorator
4
4
  # rubocop: disable Metrics/CyclomaticComplexity
5
5
  # rubocop: disable Metrics/PerceivedComplexity
6
6
  def self.decorate
@@ -21,10 +21,9 @@ module Decidim::NewslettersHelperDecorator
21
21
  @spaces_user_can_admin ||= {}
22
22
  Decidim.participatory_space_manifests.each do |manifest|
23
23
  organization_participatory_space(manifest.name)&.each do |space|
24
- next unless space.respond_to?(:decidim_area_id)
25
- next if space.decidim_area_id.blank?
26
- next unless current_user.areas.any?
27
- next unless space.decidim_area_id == current_user.areas.first.id
24
+ next unless space.respond_to?(:department)
25
+ next if space.department.blank?
26
+ next unless current_user.departments.include?(space.department)
28
27
 
29
28
  @spaces_user_can_admin[manifest.name] ||= []
30
29
  space_as_option_for_select_data = space_as_option_for_select(space)
@@ -41,4 +40,4 @@ module Decidim::NewslettersHelperDecorator
41
40
  # rubocop: enable Metrics/PerceivedComplexity
42
41
  end
43
42
 
44
- Decidim::NewslettersHelperDecorator.decorate
43
+ Decidim::Admin::NewslettersHelperDecorator.decorate
@@ -8,7 +8,7 @@ module Decidim::Admin::UsersControllerDecorator
8
8
  # rubocop: disable Metrics/CyclomaticComplexity
9
9
  # rubocop: disable Metrics/PerceivedComplexity
10
10
  def self.decorate
11
- # Sort Admins by role and area
11
+ # Sort Admins by role and department
12
12
  ::Decidim::Admin::UsersController.class_eval do
13
13
  alias_method :original_collection, :collection
14
14
 
@@ -32,9 +32,9 @@ module Decidim::Admin::UsersControllerDecorator
32
32
  ::Decidim::Admin::UserAdminFilter.for(original_collection, @search_text, @role, current_organization)
33
33
  end
34
34
  if current_user.department_admin?
35
- filtered.joins(:areas)
35
+ filtered.joins(:departments)
36
36
  .where("'department_admin' = ANY(roles)")
37
- .where("decidim_areas.id": current_user.areas.pluck(:id))
37
+ .where("decidim_department_admin_departments.id": current_user.departments.pluck(:id))
38
38
  else
39
39
  filtered
40
40
  end
@@ -45,7 +45,7 @@ module Decidim::Admin::UsersControllerDecorator
45
45
  def filtered_collection
46
46
  @filtered_collection ||= begin
47
47
  users = @by_process_name ? collection : query.result
48
- sorted_users = users.uniq.sort { |u_1, u_2| "#{u_1.active_role}||#{u_1.areas.first&.name}" <=> "#{u_2.active_role}||#{u_2.areas.first&.name}" }
48
+ sorted_users = users.uniq.sort { |u_1, u_2| "#{u_1.active_role}||#{u_1.departments.first&.name}" <=> "#{u_2.active_role}||#{u_2.departments.first&.name}" }
49
49
  paginate(Kaminari.paginate_array(sorted_users))
50
50
  end
51
51
  end
@@ -65,15 +65,15 @@ module Decidim::Admin::UsersControllerDecorator
65
65
 
66
66
  @spaces.push("title" => process_title,
67
67
  "type" => type,
68
- "area" => process.area.nil? ? "" : process.area&.name&.[](locale),
68
+ "area" => process.department.nil? ? "" : process.department.name[locale],
69
69
  "created_at" => process.created_at,
70
70
  "private" => process.private_space?,
71
71
  "published" => process.published?)
72
72
  end
73
73
 
74
74
  @user.assemblies.each do |assembly|
75
- area_name = if assembly.area && assembly.area.name
76
- assembly.area.name[locale]
75
+ area_name = if assembly.department && assembly.department.name
76
+ assembly.department.name[locale]
77
77
  else
78
78
  ""
79
79
  end
@@ -91,7 +91,7 @@ module Decidim::Admin::UsersControllerDecorator
91
91
 
92
92
  if Decidim::DepartmentAdmin.conferences_defined?
93
93
  @user.conferences.each do |conference|
94
- area_name = conference.area&.name.try(:[], locale) || ""
94
+ area_name = conference.department&.name.try(:[], locale) || ""
95
95
 
96
96
  conference_title = conference.title[locale]
97
97
  conference_title = conference.title["ca"] if conference_title.blank?
@@ -106,9 +106,9 @@ module Decidim::Admin::UsersControllerDecorator
106
106
  end
107
107
 
108
108
  # rubocop: disable Style/NestedTernaryOperator
109
- if (params[:sort_column] == "published" || params[:sort_column] == "private") && params[:sort_order] == "asc"
109
+ if %w(published private).include?(params[:sort_column]) && params[:sort_order] == "asc"
110
110
  @spaces.sort! { |x, y| x[params[:sort_column]] ? 0 : (1 <=> y[params[:sort_column]] ? 0 : 1) }
111
- elsif (params[:sort_column] == "published" || params[:sort_column] == "private") && params[:sort_order] == "desc"
111
+ elsif %w(published private).include?(params[:sort_column]) && params[:sort_order] == "desc"
112
112
  @spaces.sort! { |x, y| y[params[:sort_column]] ? 0 : 1 <=> x[params[:sort_column]] ? 0 : 1 }
113
113
  elsif params[:sort_column] && params[:sort_order] && params[:sort_order] == "asc"
114
114
  @spaces.sort! { |x, y| x[params[:sort_column]] <=> y[params[:sort_column]] }
@@ -13,7 +13,7 @@ module Decidim::Assemblies::Admin::AssembliesControllerDecorator
13
13
 
14
14
  def collection
15
15
  if current_user.department_admin?
16
- ::Decidim::Assemblies::AssembliesWithUserRole.for(current_user)
16
+ ::Decidim::Assemblies::AssembliesWithUserRole.for(current_user).order(weight: :asc)
17
17
  else
18
18
  original_organization_assemblies
19
19
  end
@@ -6,15 +6,20 @@ module Decidim::Assemblies::Admin::AssembliesHelperDecorator
6
6
  #
7
7
  def self.decorate
8
8
  Decidim::Assemblies::Admin::AssembliesHelper.class_eval do
9
- alias_method :parent_assemblies_for_select_original, :parent_assemblies_for_select
9
+ alias_method :parent_assemblies_options_original, :parent_assemblies_options
10
10
 
11
- # Public: A collection of Assemblies that can be selected as parent
12
- # assemblies for another assembly; to be used in forms.
13
- def parent_assemblies_for_select
11
+ # Public: select options representing a collection of Assemblies that
12
+ # can be selected as parent assemblies for another assembly; to be used in forms.
13
+ def parent_assemblies_options
14
14
  if current_user.department_admin?
15
- @parent_assemblies_for_select ||= Decidim::Assemblies::ParentAssembliesForSelect.for(current_organization, current_assembly, current_user)
15
+ options = []
16
+ root_assemblies ||= Decidim::Assemblies::ParentAssembliesForSelect.for(current_organization, current_assembly, current_user)
17
+
18
+ root_assemblies.each do |assembly|
19
+ build_assembly_options(assembly, options)
20
+ end
16
21
  else
17
- parent_assemblies_for_select_original
22
+ parent_assemblies_options_original
18
23
  end
19
24
  end
20
25
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim::Assemblies::Admin::AssemblyFormDecorator
4
+ def self.decorate
5
+ Decidim::Assemblies::Admin::AssemblyForm.class_eval do
6
+ attribute :decidim_department_admin_department_id, Integer
7
+ end
8
+ end
9
+ end
10
+
11
+ Decidim::Assemblies::Admin::AssemblyFormDecorator.decorate
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim::Assemblies::AssemblyPresenterDecorator
4
+ def self.decorate
5
+ Decidim::Assemblies::AssemblyPresenter.class_eval do
6
+ def department_name
7
+ return if assembly.decidim_department_admin_department_id.blank?
8
+
9
+ Decidim::DepartmentAdmin::DepartmentPresenter.new(assembly.department).translated_name
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ Decidim::Assemblies::AssemblyPresenterDecorator.decorate
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim::Assemblies::ContentBlocks::MetadataCellDecorator
4
+ def metadata_items
5
+ items = super
6
+ items << "department_name" if resource.decidim_department_admin_department_id.present? && items.exclude?("department_name")
7
+ items
8
+ end
9
+
10
+ def self.decorate
11
+ Decidim::Assemblies::ContentBlocks::MetadataCell.prepend(self)
12
+ end
13
+ end
14
+
15
+ Decidim::Assemblies::ContentBlocks::MetadataCellDecorator.decorate
@@ -1,16 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Decidim::Assemblies::CreateAssemblyDecorator
4
- # Intercepts the `call` method and forces the Area of the user if it is a
5
- # department_admin user.
4
+ # Forces the Department of the user if it is a department_admin user.
6
5
  def self.decorate
7
6
  Decidim::Assemblies::Admin::CreateAssembly.class_eval do
8
- alias_method :original_call, :call
7
+ fetch_form_attributes :title, :subtitle, :weight, :slug, :description, :short_description,
8
+ :promoted, :taxonomizations, :parent, :announcement, :organization,
9
+ :private_space, :developer_group, :local_area, :target, :participatory_scope,
10
+ :participatory_structure, :meta_scope, :purpose_of_action,
11
+ :composition, :creation_date, :created_by, :created_by_other,
12
+ :duration, :included_at, :closing_date, :closing_date_reason, :internal_organisation,
13
+ :is_transparent, :special_features, :twitter_handler, :facebook_handler,
14
+ :instagram_handler, :youtube_handler, :github_handler, :decidim_department_admin_department_id
15
+ alias_method :run_after_hooks_original, :run_after_hooks
16
+
17
+ def run_after_hooks
18
+ run_after_hooks_original
9
19
 
10
- def call
11
20
  author = form.current_user
12
- form.area_id = author.areas.first.id if author.department_admin?
13
- original_call
21
+ if author.department_admin?
22
+ resource.update(decidim_department_admin_department_id: author.departments.first.id)
23
+ elsif form.try(:decidim_department_admin_department_id).present?
24
+ resource.update(decidim_department_admin_department_id: form.decidim_department_admin_department_id)
25
+ end
14
26
  end
15
27
  end
16
28
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Decidim::Assemblies::ParentAssembliesForSelectDecorator
4
4
  # This decorator adds current_user as an argument to be able to check
5
- # it's department in the query and filter the assemblies by area.
5
+ # its department in the query and filter the assemblies by department.
6
6
  def self.decorate
7
7
  Decidim::Assemblies::ParentAssembliesForSelect.class_eval do
8
8
  # Syntactic sugar to initialize the class and return the queried objects.
@@ -22,7 +22,7 @@ module Decidim::Assemblies::ParentAssembliesForSelectDecorator
22
22
  # Returns an ActiveRecord::Relation.
23
23
  def query
24
24
  available_assemblies = if @current_user.present? && @current_user.department_admin?
25
- Decidim::Assembly.where(area: @current_user.areas).where.not(id: @assembly)
25
+ Decidim::Assembly.where(department: @current_user.departments).where.not(id: @assembly)
26
26
  else
27
27
  Decidim::Assembly.where(organization: @organization).where.not(id: @assembly)
28
28
  end
@@ -10,7 +10,7 @@ module Decidim::Assemblies::PermissionsDecorator
10
10
 
11
11
  # rubocop: disable Lint/UnusedMethodArgument
12
12
  def has_manageable_assemblies?(role: :any)
13
- return unless user
13
+ return false unless user
14
14
 
15
15
  user.department_admin? || original_has_manageable_assemblies?
16
16
  end
@@ -1,16 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Decidim::Assemblies::UpdateAssemblyDecorator
4
- # Intercepts the `call` method and forces the Area of the user if it is a
5
- # department_admin user.
4
+ # Forces the Department of the user if it is a department_admin user.
6
5
  def self.decorate
7
6
  Decidim::Assemblies::Admin::UpdateAssembly.class_eval do
8
- alias_method :original_call, :call
9
-
10
- def call
7
+ fetch_form_attributes :title, :subtitle, :slug, :promoted, :description, :short_description,
8
+ :taxonomizations, :parent, :private_space, :developer_group, :local_area,
9
+ :target, :participatory_scope, :participatory_structure, :meta_scope,
10
+ :purpose_of_action, :composition, :creation_date, :created_by,
11
+ :created_by_other, :duration, :included_at, :closing_date, :closing_date_reason,
12
+ :internal_organisation, :is_transparent, :special_features, :twitter_handler, :announcement,
13
+ :facebook_handler, :instagram_handler, :youtube_handler, :github_handler, :weight, :decidim_department_admin_department_id
14
+ def run_before_hooks
11
15
  author = form.current_user
12
- form.area_id = author.areas.first.id if author.department_admin?
13
- original_call
16
+ if author.department_admin?
17
+ form.decidim_department_admin_department_id = author.departments.first.id
18
+ elsif form.try(:decidim_department_admin_department_id).blank?
19
+ form.decidim_department_admin_department_id = resource.decidim_department_admin_department_id
20
+ end
14
21
  end
15
22
  end
16
23
  end
@@ -14,6 +14,11 @@ module Decidim::AssembliesDecorator
14
14
  foreign_key: :decidim_assembly_id,
15
15
  association_foreign_key: :decidim_user_id,
16
16
  validate: false
17
+
18
+ belongs_to :department,
19
+ class_name: "Decidim::DepartmentAdmin::Department",
20
+ foreign_key: :decidim_department_admin_department_id,
21
+ optional: true
17
22
  end
18
23
  end
19
24
  end
@@ -9,13 +9,13 @@ module Decidim::AssembliesWithUserRoleDecorator
9
9
  Decidim::Assemblies::AssembliesWithUserRole.class_eval do
10
10
  private
11
11
 
12
- alias_method :assembly_ids_by_assemblies_user_table, :assembly_ids
12
+ alias_method :assembly_ids_original, :assembly_ids
13
13
 
14
14
  def assembly_ids
15
- ids = [assembly_ids_by_assemblies_user_table]
16
- if user&.department_admin?
15
+ ids = [assembly_ids_original]
16
+ if user&.department_admin? && role == :any
17
17
  ids << ::Decidim::Assembly
18
- .where("decidim_area_id" => user.areas.pluck(:id)).pluck(:id)
18
+ .where(decidim_department_admin_department_id: user.departments.pluck(:id)).pluck(:id)
19
19
  end
20
20
 
21
21
  ::Decidim::Assembly.where(id: ids.flatten.uniq)
@@ -2,19 +2,19 @@
2
2
 
3
3
  module Decidim::ConferenceFormDecorator
4
4
  #
5
- # This decorator adds the attribute area_id to the ConferenceForm and
6
- # extends it with utility methods for the view and command.
5
+ # This decorator adds the attribute decidim_department_admin_department_id to
6
+ # the ConferenceForm and extends it with utility methods for the view and command.
7
7
  #
8
8
  def self.decorate
9
9
  return unless Decidim::DepartmentAdmin.conferences_defined?
10
10
 
11
11
  Decidim::Conferences::Admin::ConferenceForm.class_eval do
12
- attribute :area_id, Integer
12
+ attribute :decidim_department_admin_department_id, Integer
13
13
 
14
- validates :area, presence: true, if: proc { |object| object.area_id.present? }
14
+ validates :department, presence: true, if: proc { |object| object.decidim_department_admin_department_id.present? }
15
15
 
16
- def area
17
- @area ||= current_organization.areas.find_by(id: area_id)
16
+ def department
17
+ @department ||= Decidim::DepartmentAdmin::Department.find_by(id: decidim_department_admin_department_id)
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim::Conferences::ConferencePresenterDecorator
4
+ def self.decorate
5
+ return unless Decidim::DepartmentAdmin.conferences_defined?
6
+
7
+ Decidim::Conferences::ConferencePresenter.class_eval do
8
+ def department_name
9
+ return if conference.decidim_department_admin_department_id.blank?
10
+
11
+ Decidim::DepartmentAdmin::DepartmentPresenter.new(conference.department).translated_name
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ Decidim::Conferences::ConferencePresenterDecorator.decorate
@@ -1,50 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Intercepts the `call` method and forces the Area of the user if it is a
4
- # department_admin user.
5
3
  module Decidim::Conferences::CreateConferenceDecorator
6
4
  def self.decorate
7
5
  return unless Decidim::DepartmentAdmin.conferences_defined?
8
6
 
9
7
  Decidim::Conferences::Admin::CreateConference.class_eval do
10
- alias_method :original_call, :call
11
-
12
- def call
13
- author = form.current_user
14
- form.area_id = author.areas.first.id if author.department_admin?
15
- original_call
16
- end
17
-
18
- private
19
-
20
- def conference
21
- @conference ||= Decidim.traceability.create(
22
- Decidim::Conference,
23
- form.current_user,
24
- organization: form.current_organization,
25
- title: form.title,
26
- slogan: form.slogan,
27
- slug: form.slug,
28
- hashtag: form.hashtag,
29
- weight: form.weight,
30
- description: form.description,
31
- short_description: form.short_description,
32
- objectives: form.objectives,
33
- location: form.location,
34
- scopes_enabled: form.scopes_enabled,
35
- scope: form.scope,
36
- start_date: form.start_date,
37
- end_date: form.end_date,
38
- hero_image: form.hero_image,
39
- banner_image: form.banner_image,
40
- promoted: form.promoted,
41
- show_statistics: form.show_statistics,
42
- registrations_enabled: form.registrations_enabled,
43
- available_slots: form.available_slots || 0,
44
- registration_terms: form.registration_terms,
45
- area: form.area
46
- )
47
- end
8
+ fetch_form_attributes :organization, :title, :slogan, :slug, :weight, :description,
9
+ :short_description, :objectives, :location, :taxonomizations, :start_date, :end_date,
10
+ :promoted, :show_statistics, :registrations_enabled, :available_slots, :registration_terms,
11
+ :decidim_department_admin_department_id
48
12
  end
49
13
  end
50
14
  end