decidim-assemblies 0.19.0 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/images/decidim/assemblies/assembly.svg +1 -3
- data/app/assets/javascripts/decidim/assemblies/orgchart.js.es6 +698 -0
- data/app/cells/decidim/assemblies/assembly_m/footer.erb +2 -2
- data/app/cells/decidim/assemblies/assembly_m_cell.rb +5 -5
- data/app/cells/decidim/assemblies/assembly_member/show.erb +4 -4
- data/app/cells/decidim/assemblies/content_blocks/highlighted_assemblies/show.erb +10 -11
- data/app/cells/decidim/assemblies/content_blocks/highlighted_assemblies_cell.rb +1 -0
- data/app/commands/decidim/assemblies/admin/create_assemblies_type.rb +45 -0
- data/app/commands/decidim/assemblies/admin/create_assembly.rb +1 -2
- data/app/commands/decidim/assemblies/admin/create_assembly_admin.rb +2 -1
- data/app/commands/decidim/assemblies/admin/create_assembly_member.rb +12 -3
- data/app/commands/decidim/assemblies/admin/destroy_assemblies_type.rb +45 -0
- data/app/commands/decidim/assemblies/admin/notify_role_assigned_to_assembly.rb +22 -0
- data/app/commands/decidim/assemblies/admin/update_assemblies_setting.rb +46 -0
- data/app/commands/decidim/assemblies/admin/update_assemblies_type.rb +46 -0
- data/app/commands/decidim/assemblies/admin/update_assembly.rb +1 -2
- data/app/commands/decidim/assemblies/admin/update_assembly_admin.rb +2 -1
- data/app/controllers/concerns/decidim/assemblies/admin/filterable.rb +30 -0
- data/app/controllers/decidim/assemblies/admin/assemblies_controller.rb +8 -29
- data/app/controllers/decidim/assemblies/admin/assemblies_settings_controller.rb +49 -0
- data/app/controllers/decidim/assemblies/admin/assemblies_types_controller.rb +107 -0
- data/app/controllers/decidim/assemblies/assemblies_controller.rb +6 -2
- data/app/events/decidim/assemblies/create_assembly_member_event.rb +17 -0
- data/app/events/decidim/role_assigned_to_assembly_event.rb +28 -0
- data/app/forms/decidim/assemblies/admin/assemblies_setting_form.rb +14 -0
- data/app/forms/decidim/assemblies/admin/assemblies_type_form.rb +17 -0
- data/app/forms/decidim/assemblies/admin/assembly_form.rb +32 -13
- data/app/helpers/decidim/assemblies/admin/assemblies_helper.rb +6 -0
- data/app/helpers/decidim/assemblies/assemblies_helper.rb +6 -3
- data/app/helpers/decidim/assemblies/filter_assemblies_helper.rb +10 -7
- data/app/models/decidim/assemblies_setting.rb +17 -0
- data/app/models/decidim/assemblies_type.rb +24 -0
- data/app/models/decidim/assembly.rb +25 -2
- data/app/models/decidim/assembly_user_role.rb +1 -1
- data/app/permissions/decidim/assemblies/permissions.rb +55 -1
- data/app/presenters/decidim/assemblies/admin_log/assemblies_setting_presenter.rb +27 -0
- data/app/presenters/decidim/assemblies/admin_log/assemblies_type_presenter.rb +43 -0
- data/app/presenters/decidim/assemblies/admin_log/assembly_presenter.rb +1 -2
- data/app/presenters/decidim/assemblies/assembly_stats_presenter.rb +1 -1
- data/app/presenters/decidim/log/value_types/assembly_type_presenter.rb +29 -0
- data/app/queries/decidim/assemblies/filtered_assemblies.rb +2 -2
- data/app/queries/decidim/assemblies/parent_assemblies_for_select.rb +42 -0
- data/app/services/decidim/assemblies/assembly_search.rb +3 -3
- data/app/types/decidim/assemblies/assemblies_type_type.rb +17 -0
- data/app/types/decidim/assemblies/assembly_member_type.rb +29 -0
- data/app/types/decidim/assemblies/assembly_type.rb +67 -0
- data/app/views/decidim/assemblies/_filter_by_type.html.erb +11 -7
- data/app/views/decidim/assemblies/admin/assemblies/_form.html.erb +2 -6
- data/app/views/decidim/assemblies/admin/assemblies/index.html.erb +8 -4
- data/app/views/decidim/assemblies/admin/assemblies_settings/_form.html.erb +10 -0
- data/app/views/decidim/assemblies/admin/assemblies_settings/edit.html.erb +6 -0
- data/app/views/decidim/assemblies/admin/assemblies_types/_form.html.erb +11 -0
- data/app/views/decidim/assemblies/admin/assemblies_types/edit.html.erb +6 -0
- data/app/views/decidim/assemblies/admin/assemblies_types/index.html.erb +43 -0
- data/app/views/decidim/assemblies/admin/assemblies_types/new.html.erb +7 -0
- data/app/views/decidim/assemblies/admin/assembly_members/index.html.erb +30 -30
- data/app/views/decidim/assemblies/assemblies/_parent_assemblies.html.erb +2 -2
- data/app/views/decidim/assemblies/assemblies/_promoted_assembly.html.erb +3 -3
- data/app/views/decidim/assemblies/assemblies/index.html.erb +11 -8
- data/app/views/decidim/assemblies/assemblies/show.html.erb +10 -13
- data/app/views/decidim/assemblies/assembly_members/index.html.erb +1 -1
- data/app/views/layouts/decidim/admin/assemblies.html.erb +22 -0
- data/app/views/layouts/decidim/admin/assembly.html.erb +2 -2
- data/config/locales/ar.yml +60 -27
- data/config/locales/bg-BG.yml +7 -0
- data/config/locales/ca.yml +79 -1
- data/config/locales/cs.yml +125 -47
- data/config/locales/da-DK.yml +1 -0
- data/config/locales/de.yml +80 -0
- data/config/locales/el-GR.yml +1 -0
- data/config/locales/el.yml +456 -0
- data/config/locales/en.yml +78 -0
- data/config/locales/es-MX.yml +79 -0
- data/config/locales/es-PY.yml +79 -0
- data/config/locales/es.yml +78 -0
- data/config/locales/et-EE.yml +1 -0
- data/config/locales/eu.yml +11 -0
- data/config/locales/fi-plain.yml +78 -0
- data/config/locales/fi.yml +81 -3
- data/config/locales/fr-CA.yml +456 -0
- data/config/locales/fr.yml +78 -0
- data/config/locales/ga-IE.yml +1 -0
- data/config/locales/gl.yml +11 -0
- data/config/locales/hr-HR.yml +1 -0
- data/config/locales/hu.yml +67 -2
- data/config/locales/id-ID.yml +11 -0
- data/config/locales/is-IS.yml +263 -0
- data/config/locales/it.yml +181 -102
- data/config/locales/ja-JP.yml +452 -0
- data/config/locales/lt-LT.yml +1 -0
- data/config/locales/lv-LV.yml +454 -0
- data/config/locales/mt-MT.yml +1 -0
- data/config/locales/nl.yml +86 -8
- data/config/locales/no.yml +451 -0
- data/config/locales/pl.yml +222 -142
- data/config/locales/pt-BR.yml +12 -1
- data/config/locales/pt.yml +198 -118
- data/config/locales/ro-RO.yml +422 -0
- data/config/locales/ru.yml +11 -0
- data/config/locales/sk-SK.yml +168 -0
- data/config/locales/sk.yml +172 -0
- data/config/locales/sl.yml +132 -0
- data/config/locales/sr-CS.yml +73 -0
- data/config/locales/sv.yml +167 -88
- data/config/locales/tr-TR.yml +11 -0
- data/config/locales/uk.yml +11 -0
- data/db/migrate/20200108113855_create_decidim_assembly_types.rb +19 -0
- data/db/migrate/20200108123050_migrate_decidim_assembly_types.rb +83 -0
- data/db/migrate/20200320105906_index_foreign_keys_in_decidim_assemblies.rb +7 -0
- data/db/migrate/20200320105907_index_foreign_keys_in_decidim_assembly_user_roles.rb +7 -0
- data/db/migrate/20200416132109_remove_legacy_decidim_assembly_type.rb +8 -0
- data/db/migrate/20200430202456_create_decidim_assemblies_settings.rb +10 -0
- data/db/seeds/city.jpeg +0 -0
- data/db/seeds/city2.jpeg +0 -0
- data/lib/decidim/assemblies/admin_engine.rb +3 -0
- data/lib/decidim/assemblies/engine.rb +7 -0
- data/lib/decidim/assemblies/participatory_space.rb +11 -3
- data/lib/decidim/assemblies/query_extensions.rb +40 -0
- data/lib/decidim/assemblies/test/factories.rb +29 -2
- data/lib/decidim/assemblies/version.rb +1 -1
- metadata +62 -10
- data/app/views/decidim/assemblies/assembly_widgets/show.html.erb +0 -11
@@ -6,15 +6,13 @@ module Decidim
|
|
6
6
|
# Controller that allows managing assemblies.
|
7
7
|
#
|
8
8
|
class AssembliesController < Decidim::Assemblies::Admin::ApplicationController
|
9
|
-
include Decidim::
|
10
|
-
helper_method :current_assembly, :parent_assembly, :
|
9
|
+
include Decidim::Assemblies::Admin::Filterable
|
10
|
+
helper_method :current_assembly, :parent_assembly, :current_participatory_space
|
11
11
|
layout "decidim/admin/assemblies"
|
12
12
|
|
13
|
-
before_action :set_all_assemblies, except: [:index]
|
14
|
-
|
15
13
|
def index
|
16
14
|
enforce_permission_to :read, :assembly_list
|
17
|
-
@assemblies =
|
15
|
+
@assemblies = filtered_collection
|
18
16
|
end
|
19
17
|
|
20
18
|
def new
|
@@ -30,7 +28,7 @@ module Decidim
|
|
30
28
|
CreateAssembly.call(@form) do
|
31
29
|
on(:ok) do |assembly|
|
32
30
|
flash[:notice] = I18n.t("assemblies.create.success", scope: "decidim.admin")
|
33
|
-
redirect_to assemblies_path(
|
31
|
+
redirect_to assemblies_path(q: { parent_id_eq: assembly.parent_id })
|
34
32
|
end
|
35
33
|
|
36
34
|
on(:invalid) do
|
@@ -72,39 +70,20 @@ module Decidim
|
|
72
70
|
|
73
71
|
private
|
74
72
|
|
75
|
-
def organization_assemblies
|
76
|
-
@organization_assemblies ||= OrganizationAssemblies.new(current_user.organization).query
|
77
|
-
end
|
78
|
-
|
79
|
-
def query
|
80
|
-
organization_assemblies
|
81
|
-
.where(parent_id: params[:parent_id])
|
82
|
-
.ransack(params[:q])
|
83
|
-
end
|
84
|
-
|
85
73
|
def collection
|
86
|
-
@collection ||=
|
87
|
-
end
|
88
|
-
|
89
|
-
def set_all_assemblies
|
90
|
-
@all_assemblies = organization_assemblies
|
74
|
+
@collection ||= OrganizationAssemblies.new(current_user.organization).query
|
91
75
|
end
|
92
76
|
|
93
77
|
def current_assembly
|
94
|
-
|
95
|
-
|
96
|
-
scope.where(id: params[:slug])
|
78
|
+
@current_assembly ||= collection.where(slug: params[:slug]).or(
|
79
|
+
collection.where(id: params[:slug])
|
97
80
|
).first
|
98
81
|
end
|
99
82
|
|
100
83
|
alias current_participatory_space current_assembly
|
101
84
|
|
102
85
|
def parent_assembly
|
103
|
-
@parent_assembly ||=
|
104
|
-
end
|
105
|
-
|
106
|
-
def parent_assemblies
|
107
|
-
@parent_assemblies ||= organization_assemblies.where(parent_id: nil)
|
86
|
+
@parent_assembly ||= collection.find_by(id: ransack_params[:parent_id_eq])
|
108
87
|
end
|
109
88
|
|
110
89
|
def assembly_params
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
module Admin
|
6
|
+
# Controller used to manage the assemblies settings for the current
|
7
|
+
# organization.
|
8
|
+
class AssembliesSettingsController < Decidim::Assemblies::Admin::ApplicationController
|
9
|
+
layout "decidim/admin/assemblies"
|
10
|
+
|
11
|
+
# GET /admin/assemblies_settings/edit
|
12
|
+
def edit
|
13
|
+
enforce_permission_to :edit, :assemblies_setting, assemblies_settings: current_assemblies_settings
|
14
|
+
@form = assemblies_settings_form.from_model(current_assemblies_settings)
|
15
|
+
end
|
16
|
+
|
17
|
+
# PUT /admin/assemblies_settings/:id
|
18
|
+
def update
|
19
|
+
enforce_permission_to :update, :assemblies_setting, assemblies_settings: current_assemblies_settings
|
20
|
+
|
21
|
+
@form = assemblies_settings_form
|
22
|
+
.from_params(params, assemblies_settings: current_assemblies_settings)
|
23
|
+
|
24
|
+
UpdateAssembliesSetting.call(current_assemblies_settings, @form) do
|
25
|
+
on(:ok) do
|
26
|
+
flash[:notice] = I18n.t("assemblies_settings.update.success", scope: "decidim.admin")
|
27
|
+
redirect_to edit_assemblies_settings_path
|
28
|
+
end
|
29
|
+
|
30
|
+
on(:invalid) do
|
31
|
+
flash.now[:alert] = I18n.t("assemblies_settings.update.error", scope: "decidim.admin")
|
32
|
+
render :edit
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def current_assemblies_settings
|
40
|
+
@current_assemblies_settings ||= Decidim::AssembliesSetting.find_or_create_by!(decidim_organization_id: current_organization.id)
|
41
|
+
end
|
42
|
+
|
43
|
+
def assemblies_settings_form
|
44
|
+
form(Decidim::Assemblies::Admin::AssembliesSettingForm)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
module Admin
|
6
|
+
# Controller used to manage the available assemblies types for the current
|
7
|
+
# organization.
|
8
|
+
# As this substitues former i18n simple hash we need to keep these i18n keys for migrations
|
9
|
+
# and rollbakcs. So let i18n-tasks know about:
|
10
|
+
# i18n-tasks-use t('decidim.assemblies.assembly_types.government')
|
11
|
+
# i18n-tasks-use t('decidim.assemblies.assembly_types.commission')
|
12
|
+
# i18n-tasks-use t('decidim.assemblies.assembly_types.consultative_advisory')
|
13
|
+
# i18n-tasks-use t('decidim.assemblies.assembly_types.executive')
|
14
|
+
# i18n-tasks-use t('decidim.assemblies.assembly_types.others')
|
15
|
+
# i18n-tasks-use t('decidim.assemblies.assembly_types.participatory')
|
16
|
+
# i18n-tasks-use t('decidim.assemblies.assembly_types.working_group')
|
17
|
+
# This comment (and the i18n keys) may be removed in future versions
|
18
|
+
class AssembliesTypesController < Decidim::Assemblies::Admin::ApplicationController
|
19
|
+
helper_method :available_assemblies_types, :current_assembly_type
|
20
|
+
layout "decidim/admin/assemblies"
|
21
|
+
|
22
|
+
# GET /admin/assemblies_types
|
23
|
+
def index
|
24
|
+
enforce_permission_to :index, :assembly_type
|
25
|
+
end
|
26
|
+
|
27
|
+
# GET /admin/assemblies_types/new
|
28
|
+
def new
|
29
|
+
enforce_permission_to :create, :assembly_type
|
30
|
+
@form = assembly_type_form.instance
|
31
|
+
end
|
32
|
+
|
33
|
+
# POST /admin/assemblies_types
|
34
|
+
def create
|
35
|
+
enforce_permission_to :create, :assembly_type
|
36
|
+
@form = assembly_type_form.from_params(params)
|
37
|
+
|
38
|
+
CreateAssembliesType.call(@form) do
|
39
|
+
on(:ok) do |_assembly_type|
|
40
|
+
flash[:notice] = I18n.t("assemblies_types.create.success", scope: "decidim.admin")
|
41
|
+
redirect_to assemblies_types_path
|
42
|
+
end
|
43
|
+
|
44
|
+
on(:invalid) do
|
45
|
+
flash.now[:alert] = I18n.t("assemblies_types.create.error", scope: "decidim.admin")
|
46
|
+
render :new
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# GET /admin/assemblies_types/:id/edit
|
52
|
+
def edit
|
53
|
+
enforce_permission_to :edit, :assembly_type, assembly_type: current_assembly_type
|
54
|
+
@form = assembly_type_form
|
55
|
+
.from_model(current_assembly_type,
|
56
|
+
assembly_type: current_assembly_type)
|
57
|
+
end
|
58
|
+
|
59
|
+
# PUT /admin/assemblies_types/:id
|
60
|
+
def update
|
61
|
+
enforce_permission_to :update, :assembly_type, assembly_type: current_assembly_type
|
62
|
+
|
63
|
+
@form = assembly_type_form
|
64
|
+
.from_params(params, assembly_type: current_assembly_type)
|
65
|
+
|
66
|
+
UpdateAssembliesType.call(current_assembly_type, @form) do
|
67
|
+
on(:ok) do
|
68
|
+
flash[:notice] = I18n.t("assemblies_types.update.success", scope: "decidim.admin")
|
69
|
+
redirect_to assemblies_types_path
|
70
|
+
end
|
71
|
+
|
72
|
+
on(:invalid) do
|
73
|
+
flash.now[:alert] = I18n.t("assemblies_types.update.error", scope: "decidim.admin")
|
74
|
+
render :edit
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# DELETE /admin/assemblies_types/:id
|
80
|
+
def destroy
|
81
|
+
enforce_permission_to :destroy, :assembly_type, assembly_type: current_assembly_type
|
82
|
+
|
83
|
+
DestroyAssembliesType.call(current_assembly_type, current_user) do
|
84
|
+
on(:ok) do
|
85
|
+
flash[:notice] = I18n.t("assemblies_types.destroy.success", scope: "decidim.admin")
|
86
|
+
redirect_to assemblies_types_path
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def available_assemblies_types
|
94
|
+
@available_assemblies_types ||= AssembliesType.where(organization: current_organization)
|
95
|
+
end
|
96
|
+
|
97
|
+
def current_assembly_type
|
98
|
+
@current_assembly_type ||= AssembliesType.find(params[:id])
|
99
|
+
end
|
100
|
+
|
101
|
+
def assembly_type_form
|
102
|
+
form(Decidim::Assemblies::Admin::AssembliesTypeForm)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -8,7 +8,7 @@ module Decidim
|
|
8
8
|
participatory_space_layout only: :show
|
9
9
|
include FilterResource
|
10
10
|
|
11
|
-
helper_method :parent_assemblies, :promoted_assemblies, :stats, :assembly_participatory_processes
|
11
|
+
helper_method :parent_assemblies, :promoted_assemblies, :stats, :assembly_participatory_processes, :current_assemblies_settings
|
12
12
|
|
13
13
|
def index
|
14
14
|
enforce_permission_to :list, :assembly
|
@@ -56,7 +56,7 @@ module Decidim
|
|
56
56
|
{
|
57
57
|
scope_id: nil,
|
58
58
|
area_id: nil,
|
59
|
-
|
59
|
+
type_id: nil
|
60
60
|
}
|
61
61
|
end
|
62
62
|
|
@@ -87,6 +87,10 @@ module Decidim
|
|
87
87
|
def assembly_participatory_processes
|
88
88
|
@assembly_participatory_processes ||= @current_participatory_space.linked_participatory_space_resources(:participatory_processes, "included_participatory_processes")
|
89
89
|
end
|
90
|
+
|
91
|
+
def current_assemblies_settings
|
92
|
+
@current_assemblies_settings ||= Decidim::AssembliesSetting.find_or_create_by(decidim_organization_id: current_organization.id)
|
93
|
+
end
|
90
94
|
end
|
91
95
|
end
|
92
96
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
class CreateAssemblyMemberEvent < Decidim::Events::SimpleEvent
|
6
|
+
i18n_attributes :resource_name
|
7
|
+
|
8
|
+
def resource_name
|
9
|
+
@resource_name ||= translated_attribute(assembly.title)
|
10
|
+
end
|
11
|
+
|
12
|
+
def assembly
|
13
|
+
@assembly ||= resource
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen-string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
class RoleAssignedToAssemblyEvent < Decidim::Events::SimpleEvent
|
5
|
+
include Decidim::Events::NotificationEvent
|
6
|
+
include Decidim::Events::AuthorEvent
|
7
|
+
|
8
|
+
def notification_title
|
9
|
+
I18n.t("notification_title", i18n_options).html_safe
|
10
|
+
end
|
11
|
+
|
12
|
+
def i18n_role
|
13
|
+
I18n.t(extra["role"], "decidim.admin.models.assembly_user_role.roles", default: extra["role"])
|
14
|
+
end
|
15
|
+
|
16
|
+
def i18n_options
|
17
|
+
{
|
18
|
+
resource_path: resource_path,
|
19
|
+
resource_title: resource_title,
|
20
|
+
resource_url: resource_url,
|
21
|
+
scope: event_name,
|
22
|
+
participatory_space_title: participatory_space_title,
|
23
|
+
participatory_space_url: participatory_space_url,
|
24
|
+
role: i18n_role
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
module Admin
|
6
|
+
# A form object used to create assembly setting from the admin dashboard.
|
7
|
+
class AssembliesSettingForm < Form
|
8
|
+
mimic :assemblies_setting
|
9
|
+
|
10
|
+
attribute :enable_organization_chart, Boolean
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
module Admin
|
6
|
+
# A form object used to create assembly type from the admin dashboard.
|
7
|
+
class AssembliesTypeForm < Form
|
8
|
+
include TranslatableAttributes
|
9
|
+
|
10
|
+
mimic :assemblies_type
|
11
|
+
|
12
|
+
translatable_attribute :title, String
|
13
|
+
validates :title, translatable_presence: true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -9,12 +9,10 @@ module Decidim
|
|
9
9
|
class AssemblyForm < Form
|
10
10
|
include TranslatableAttributes
|
11
11
|
|
12
|
-
ASSEMBLY_TYPES = %w(government executive consultative_advisory participatory working_group commission others).freeze
|
13
12
|
CREATED_BY = %w(city_council public others).freeze
|
14
13
|
|
15
14
|
mimic :assembly
|
16
15
|
|
17
|
-
translatable_attribute :assembly_type_other, String
|
18
16
|
translatable_attribute :composition, String
|
19
17
|
translatable_attribute :closing_date_reason, String
|
20
18
|
translatable_attribute :created_by_other, String
|
@@ -32,7 +30,6 @@ module Decidim
|
|
32
30
|
translatable_attribute :target, String
|
33
31
|
translatable_attribute :title, String
|
34
32
|
|
35
|
-
attribute :assembly_type, String
|
36
33
|
attribute :created_by, String
|
37
34
|
attribute :facebook_handler, String
|
38
35
|
attribute :github_handler, String
|
@@ -42,6 +39,7 @@ module Decidim
|
|
42
39
|
attribute :twitter_handler, String
|
43
40
|
attribute :youtube_handler, String
|
44
41
|
|
42
|
+
attribute :decidim_assemblies_type_id, Integer
|
45
43
|
attribute :area_id, Integer
|
46
44
|
attribute :parent_id, Integer
|
47
45
|
attribute :participatory_processes_ids, Array[Integer]
|
@@ -64,13 +62,16 @@ module Decidim
|
|
64
62
|
attribute :remove_hero_image
|
65
63
|
|
66
64
|
validates :area, presence: true, if: proc { |object| object.area_id.present? }
|
67
|
-
|
65
|
+
|
66
|
+
validates :parent, presence: true, if: ->(form) { form.parent.present? }
|
67
|
+
validate :ensure_parent_cannot_be_child, if: ->(form) { form.parent.present? }
|
68
|
+
|
68
69
|
validates :scope, presence: true, if: proc { |object| object.scope_id.present? }
|
69
70
|
validates :slug, presence: true, format: { with: Decidim::Assembly.slug_format }
|
70
71
|
|
71
72
|
validate :slug_uniqueness
|
73
|
+
validate :same_type_organization, if: ->(form) { form.decidim_assemblies_type_id }
|
72
74
|
|
73
|
-
validates :assembly_type_other, translatable_presence: true, if: ->(form) { form.assembly_type == "others" }
|
74
75
|
validates :created_by_other, translatable_presence: true, if: ->(form) { form.created_by == "others" }
|
75
76
|
validates :title, :subtitle, :description, :short_description, translatable_presence: true
|
76
77
|
|
@@ -81,6 +82,13 @@ module Decidim
|
|
81
82
|
file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } },
|
82
83
|
file_content_type: { allow: ["image/jpeg", "image/png"] }
|
83
84
|
|
85
|
+
def ensure_parent_cannot_be_child
|
86
|
+
return if id.blank?
|
87
|
+
|
88
|
+
available_assemblies = Decidim::Assemblies::ParentAssembliesForSelect.for(current_organization, Assembly.find(id))
|
89
|
+
errors.add(:parent, :invalid) unless available_assemblies.include? parent
|
90
|
+
end
|
91
|
+
|
84
92
|
def map_model(model)
|
85
93
|
self.scope_id = model.decidim_scope_id
|
86
94
|
end
|
@@ -94,12 +102,8 @@ module Decidim
|
|
94
102
|
end
|
95
103
|
|
96
104
|
def assembly_types_for_select
|
97
|
-
|
98
|
-
|
99
|
-
I18n.t("assembly_types.#{type}", scope: "decidim.assemblies"),
|
100
|
-
type
|
101
|
-
]
|
102
|
-
end
|
105
|
+
@assembly_types_for_select ||= organization_assembly_types
|
106
|
+
&.map { |type| [translated_attribute(type.title), type.id] }
|
103
107
|
end
|
104
108
|
|
105
109
|
def created_by_for_select
|
@@ -117,12 +121,20 @@ module Decidim
|
|
117
121
|
|
118
122
|
def processes_for_select
|
119
123
|
@processes_for_select ||= organization_participatory_processes
|
120
|
-
|
121
|
-
|
124
|
+
&.map { |pp| [translated_attribute(pp.title), pp.id] }
|
125
|
+
&.sort_by { |arr| arr[0] }
|
126
|
+
end
|
127
|
+
|
128
|
+
def assembly_type
|
129
|
+
AssembliesType.find_by(id: decidim_assemblies_type_id)
|
122
130
|
end
|
123
131
|
|
124
132
|
private
|
125
133
|
|
134
|
+
def organization_assembly_types
|
135
|
+
AssembliesType.where(organization: current_organization)
|
136
|
+
end
|
137
|
+
|
126
138
|
def organization_participatory_processes
|
127
139
|
Decidim.find_participatory_space_manifest(:participatory_processes)
|
128
140
|
.participatory_spaces.call(current_organization)
|
@@ -140,6 +152,13 @@ module Decidim
|
|
140
152
|
|
141
153
|
errors.add(:slug, :taken)
|
142
154
|
end
|
155
|
+
|
156
|
+
def same_type_organization
|
157
|
+
return unless assembly_type
|
158
|
+
return if assembly_type.organization == current_organization
|
159
|
+
|
160
|
+
errors.add(:assembly_type, :invalid)
|
161
|
+
end
|
143
162
|
end
|
144
163
|
end
|
145
164
|
end
|