decidim-assemblies 0.6.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 (86) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +34 -0
  3. data/Rakefile +3 -0
  4. data/app/assets/config/admin/decidim_assemblies_manifest.js +1 -0
  5. data/app/assets/config/decidim_assemblies_manifest.js +1 -0
  6. data/app/assets/images/decidim/assemblies/assembly.svg +6 -0
  7. data/app/assets/javascripts/decidim/assemblies/admin/assemblies.js.es6 +12 -0
  8. data/app/commands/decidim/assemblies/admin/copy_assembly.rb +88 -0
  9. data/app/commands/decidim/assemblies/admin/create_assembly.rb +68 -0
  10. data/app/commands/decidim/assemblies/admin/publish_assembly.rb +34 -0
  11. data/app/commands/decidim/assemblies/admin/unpublish_assembly.rb +34 -0
  12. data/app/commands/decidim/assemblies/admin/update_assembly.rb +73 -0
  13. data/app/constraints/decidim/assemblies/current_assembly.rb +37 -0
  14. data/app/constraints/decidim/assemblies/current_feature.rb +28 -0
  15. data/app/controllers/concerns/decidim/assemblies/admin/assembly_context.rb +21 -0
  16. data/app/controllers/concerns/decidim/assemblies/assembly_context.rb +25 -0
  17. data/app/controllers/concerns/decidim/assemblies/needs_assembly.rb +50 -0
  18. data/app/controllers/decidim/assemblies/admin/application_controller.rb +11 -0
  19. data/app/controllers/decidim/assemblies/admin/assemblies_controller.rb +100 -0
  20. data/app/controllers/decidim/assemblies/admin/assembly_attachments_controller.rb +27 -0
  21. data/app/controllers/decidim/assemblies/admin/assembly_copies_controller.rb +35 -0
  22. data/app/controllers/decidim/assemblies/admin/assembly_publications_controller.rb +45 -0
  23. data/app/controllers/decidim/assemblies/admin/categories_controller.rb +13 -0
  24. data/app/controllers/decidim/assemblies/admin/concerns/assembly_admin.rb +26 -0
  25. data/app/controllers/decidim/assemblies/admin/exports_controller.rb +14 -0
  26. data/app/controllers/decidim/assemblies/admin/feature_permissions_controller.rb +14 -0
  27. data/app/controllers/decidim/assemblies/admin/features_controller.rb +14 -0
  28. data/app/controllers/decidim/assemblies/admin/moderations_controller.rb +12 -0
  29. data/app/controllers/decidim/assemblies/assemblies_controller.rb +43 -0
  30. data/app/controllers/decidim/assemblies/assembly_widgets_controller.rb +21 -0
  31. data/app/controllers/decidim/assemblies/categories_controller.rb +13 -0
  32. data/app/forms/decidim/assemblies/admin/assembly_copy_form.rb +34 -0
  33. data/app/forms/decidim/assemblies/admin/assembly_form.rb +63 -0
  34. data/app/models/decidim/assemblies/abilities/admin/admin_ability.rb +18 -0
  35. data/app/models/decidim/assemblies/abilities/admin_ability.rb +16 -0
  36. data/app/models/decidim/assemblies/abilities/everyone_ability.rb +17 -0
  37. data/app/models/decidim/assembly.rb +45 -0
  38. data/app/presenters/decidim/assemblies/assembly_stats_presenter.rb +52 -0
  39. data/app/queries/decidim/assemblies/admin/admin_users.rb +39 -0
  40. data/app/queries/decidim/assemblies/organization_assemblies.rb +16 -0
  41. data/app/queries/decidim/assemblies/organization_prioritized_assemblies.rb +20 -0
  42. data/app/queries/decidim/assemblies/organization_published_assemblies.rb +19 -0
  43. data/app/queries/decidim/assemblies/prioritized_assemblies.rb +13 -0
  44. data/app/queries/decidim/assemblies/promoted_assemblies.rb +12 -0
  45. data/app/queries/decidim/assemblies/published_assemblies.rb +12 -0
  46. data/app/views/decidim/assemblies/_assembly.html.erb +22 -0
  47. data/app/views/decidim/assemblies/_order_by_assemblies.html.erb +3 -0
  48. data/app/views/decidim/assemblies/admin/assemblies/_form.html.erb +89 -0
  49. data/app/views/decidim/assemblies/admin/assemblies/edit.html.erb +19 -0
  50. data/app/views/decidim/assemblies/admin/assemblies/index.html.erb +66 -0
  51. data/app/views/decidim/assemblies/admin/assemblies/new.html.erb +11 -0
  52. data/app/views/decidim/assemblies/admin/assembly_copies/_form.html.erb +34 -0
  53. data/app/views/decidim/assemblies/admin/assembly_copies/new.html.erb +7 -0
  54. data/app/views/decidim/assemblies/assemblies/_no_assemblies_yet.html.erb +3 -0
  55. data/app/views/decidim/assemblies/assemblies/_promoted_assembly.html.erb +27 -0
  56. data/app/views/decidim/assemblies/assemblies/_statistics.html.erb +10 -0
  57. data/app/views/decidim/assemblies/assemblies/index.html.erb +17 -0
  58. data/app/views/decidim/assemblies/assemblies/show.html.erb +74 -0
  59. data/app/views/decidim/assemblies/assembly_widgets/show.html.erb +11 -0
  60. data/app/views/layouts/decidim/_assembly_header.html.erb +64 -0
  61. data/app/views/layouts/decidim/admin/assemblies.html.erb +14 -0
  62. data/app/views/layouts/decidim/admin/assembly.html.erb +54 -0
  63. data/app/views/layouts/decidim/assembly.html.erb +30 -0
  64. data/config/locales/ca.yml +128 -0
  65. data/config/locales/en.yml +128 -0
  66. data/config/locales/es.yml +128 -0
  67. data/config/locales/eu.yml +127 -0
  68. data/config/locales/fi.yml +127 -0
  69. data/config/locales/fr.yml +127 -0
  70. data/config/locales/it.yml +127 -0
  71. data/config/locales/nl.yml +127 -0
  72. data/config/locales/pl.yml +128 -0
  73. data/config/locales/uk.yml +129 -0
  74. data/db/migrate/20170727190859_add_assemblies.rb +37 -0
  75. data/db/migrate/20170822153055_add_scopes_enabled_to_assemblies.rb +7 -0
  76. data/db/seeds/Exampledocument.pdf +0 -0
  77. data/db/seeds/city.jpeg +0 -0
  78. data/db/seeds/city2.jpeg +0 -0
  79. data/db/seeds/homepage_image.jpg +0 -0
  80. data/lib/decidim/assemblies.rb +12 -0
  81. data/lib/decidim/assemblies/admin.rb +10 -0
  82. data/lib/decidim/assemblies/admin_engine.rb +79 -0
  83. data/lib/decidim/assemblies/engine.rb +53 -0
  84. data/lib/decidim/assemblies/participatory_space.rb +69 -0
  85. data/lib/decidim/assemblies/test/factories.rb +41 -0
  86. metadata +188 -0
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # This module, when injected into a controller, ensures there's a
7
+ # Assembly available and deducts it from the context.
8
+ module AssemblyContext
9
+ def self.extended(base)
10
+ base.class_eval do
11
+ include Concerns::AssemblyAdmin
12
+
13
+ delegate :active_step, to: :current_assembly, prefix: false
14
+
15
+ alias_method :current_assembly, :current_participatory_space
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ # This module, when injected into a controller, ensures there's a
6
+ # Assembly available and deducts it from the context.
7
+ module AssemblyContext
8
+ def self.extended(base)
9
+ base.class_eval do
10
+ include NeedsAssembly
11
+
12
+ layout "layouts/decidim/assembly"
13
+
14
+ before_action do
15
+ authorize! :read, current_assembly
16
+ end
17
+ end
18
+ end
19
+
20
+ def ability_context
21
+ super.merge(current_assembly: current_assembly)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ # This module, when injected into a controller, ensures there's a
6
+ # Assembly available and deducts it from the context.
7
+ module NeedsAssembly
8
+ def self.enhance_controller(instance_or_module)
9
+ instance_or_module.class_eval do
10
+ helper_method :current_assembly
11
+ end
12
+ end
13
+
14
+ def self.extended(base)
15
+ base.extend Decidim::NeedsOrganization, InstanceMethods
16
+
17
+ enhance_controller(base)
18
+ end
19
+
20
+ def self.included(base)
21
+ base.include Decidim::NeedsOrganization, InstanceMethods
22
+
23
+ enhance_controller(base)
24
+ end
25
+
26
+ module InstanceMethods
27
+ # Public: Finds the current Assembly given this controller's
28
+ # context.
29
+ #
30
+ # Returns the current Assembly.
31
+ def current_assembly
32
+ @current_assembly ||= detect_assembly
33
+ end
34
+
35
+ alias current_participatory_space current_assembly
36
+
37
+ private
38
+
39
+ def ability_context
40
+ super.merge(current_assembly: current_assembly)
41
+ end
42
+
43
+ def detect_assembly
44
+ request.env["current_assembly"] ||
45
+ OrganizationAssemblies.new(current_organization).query.find(params[:assembly_id] || params[:id])
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # The main admin application controller for assemblies
7
+ class ApplicationController < Decidim::Admin::ApplicationController
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # Controller that allows managing assemblies.
7
+ #
8
+ class AssembliesController < Decidim::Admin::ApplicationController
9
+ helper_method :current_assembly
10
+
11
+ layout "decidim/admin/assemblies"
12
+
13
+ def index
14
+ authorize! :index, Decidim::Assembly
15
+ @assemblies = collection
16
+ end
17
+
18
+ def new
19
+ authorize! :new, Decidim::Assembly
20
+ @form = form(AssemblyForm).instance
21
+ end
22
+
23
+ def create
24
+ authorize! :new, Decidim::Assembly
25
+ @form = form(AssemblyForm).from_params(params)
26
+
27
+ CreateAssembly.call(@form) do
28
+ on(:ok) do
29
+ flash[:notice] = I18n.t("assemblies.create.success", scope: "decidim.admin")
30
+ redirect_to assemblies_path
31
+ end
32
+
33
+ on(:invalid) do
34
+ flash.now[:alert] = I18n.t("assemblies.create.error", scope: "decidim.admin")
35
+ render :new
36
+ end
37
+ end
38
+ end
39
+
40
+ def edit
41
+ authorize! :update, current_assembly
42
+ @form = form(AssemblyForm).from_model(current_assembly)
43
+ render layout: "decidim/admin/assembly"
44
+ end
45
+
46
+ def update
47
+ authorize! :update, current_assembly
48
+ @form = form(AssemblyForm).from_params(assembly_params)
49
+
50
+ UpdateAssembly.call(current_assembly, @form) do
51
+ on(:ok) do |assembly|
52
+ flash[:notice] = I18n.t("assemblies.update.success", scope: "decidim.admin")
53
+ redirect_to edit_assembly_path(assembly)
54
+ end
55
+
56
+ on(:invalid) do
57
+ flash.now[:alert] = I18n.t("assemblies.update.error", scope: "decidim.admin")
58
+ render :edit, layout: "decidim/admin/assembly"
59
+ end
60
+ end
61
+ end
62
+
63
+ def destroy
64
+ authorize! :destroy, current_assembly
65
+ current_assembly.destroy!
66
+
67
+ flash[:notice] = I18n.t("assemblies.destroy.success", scope: "decidim.admin")
68
+
69
+ redirect_to assemblies_path
70
+ end
71
+
72
+ def copy
73
+ authorize! :create, Decidim::Assembly
74
+ end
75
+
76
+ private
77
+
78
+ def current_assembly
79
+ @current_assembly ||= collection.find(params[:id]) if params[:id]
80
+ end
81
+
82
+ def collection
83
+ @collection ||= OrganizationAssemblies.new(current_user.organization).query
84
+ end
85
+
86
+ def ability_context
87
+ super.merge(current_assembly: current_assembly)
88
+ end
89
+
90
+ def assembly_params
91
+ {
92
+ id: params[:id],
93
+ hero_image: current_assembly.hero_image,
94
+ banner_image: current_assembly.banner_image
95
+ }.merge(params[:assembly].to_unsafe_h)
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # Controller that allows managing all the attachments for a participatory
7
+ # assembly.
8
+ #
9
+ class AssemblyAttachmentsController < Decidim::Admin::ApplicationController
10
+ include Concerns::AssemblyAdmin
11
+ include Decidim::Admin::Concerns::HasAttachments
12
+
13
+ def after_destroy_path
14
+ assembly_attachments_path(current_assembly.id)
15
+ end
16
+
17
+ def attached_to
18
+ current_assembly
19
+ end
20
+
21
+ def authorization_object
22
+ @attachment || Attachment
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # Controller that allows managing assemblies.
7
+ #
8
+ class AssemblyCopiesController < Decidim::Admin::ApplicationController
9
+ include Concerns::AssemblyAdmin
10
+
11
+ def new
12
+ authorize! :new, Decidim::Assembly
13
+ @form = form(AssemblyCopyForm).from_model(current_assembly)
14
+ end
15
+
16
+ def create
17
+ authorize! :create, Decidim::Assembly
18
+ @form = form(AssemblyCopyForm).from_params(params)
19
+
20
+ CopyAssembly.call(@form, current_assembly) do
21
+ on(:ok) do
22
+ flash[:notice] = I18n.t("assemblies_copies.create.success", scope: "decidim.admin")
23
+ redirect_to assemblies_path
24
+ end
25
+
26
+ on(:invalid) do
27
+ flash.now[:alert] = I18n.t("assemblies_copies.create.error", scope: "decidim.admin")
28
+ render :new
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # Controller that allows managing assembly publications.
7
+ #
8
+ class AssemblyPublicationsController < Decidim::Admin::ApplicationController
9
+ include Concerns::AssemblyAdmin
10
+
11
+ def create
12
+ authorize! :publish, current_assembly
13
+
14
+ PublishAssembly.call(current_assembly) do
15
+ on(:ok) do
16
+ flash[:notice] = I18n.t("assembly_publications.create.success", scope: "decidim.admin")
17
+ end
18
+
19
+ on(:invalid) do
20
+ flash.now[:alert] = I18n.t("assembly_publications.create.error", scope: "decidim.admin")
21
+ end
22
+
23
+ redirect_back(fallback_location: assemblies_path)
24
+ end
25
+ end
26
+
27
+ def destroy
28
+ authorize! :publish, current_assembly
29
+
30
+ UnpublishAssembly.call(current_assembly) do
31
+ on(:ok) do
32
+ flash[:notice] = I18n.t("assembly_publications.destroy.success", scope: "decidim.admin")
33
+ end
34
+
35
+ on(:invalid) do
36
+ flash.now[:alert] = I18n.t("assembly_publications.destroy.error", scope: "decidim.admin")
37
+ end
38
+
39
+ redirect_back(fallback_location: assemblies_path)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # Controller that allows managing categories for assemblies.
7
+ #
8
+ class CategoriesController < Decidim::Admin::CategoriesController
9
+ include Concerns::AssemblyAdmin
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ module Assemblies
7
+ module Admin
8
+ module Concerns
9
+ # This concern is meant to be included in all controllers that are scoped
10
+ # into an assembly's admin panel. It will override the layout so it shows
11
+ # the sidebar, preload the assembly, etc.
12
+ module AssemblyAdmin
13
+ extend ActiveSupport::Concern
14
+
15
+ included do
16
+ include NeedsAssembly
17
+
18
+ layout "decidim/admin/assembly"
19
+
20
+ alias_method :current_participatory_space, :current_assembly
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # This controller allows exporting things.
7
+ # It is targeted for customizations for exporting things that lives under
8
+ # an assembly.
9
+ class ExportsController < Decidim::Admin::ExportsController
10
+ include Concerns::AssemblyAdmin
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # Controller that allows managing the Assembly' Feature
7
+ # permissions in the admin panel.
8
+ #
9
+ class FeaturePermissionsController < Decidim::Admin::FeaturePermissionsController
10
+ include Concerns::AssemblyAdmin
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # Controller that allows managing the Assembly' Features in the
7
+ # admin panel.
8
+ #
9
+ class FeaturesController < Decidim::Admin::FeaturesController
10
+ include Concerns::AssemblyAdmin
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ module Admin
6
+ # This controller allows admins to manage moderations in an assembly.
7
+ class ModerationsController < Decidim::Admin::ModerationsController
8
+ include Concerns::AssemblyAdmin
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Assemblies
5
+ # A controller that holds the logic to show Assemblies in a
6
+ # public layout.
7
+ class AssembliesController < Decidim::ApplicationController
8
+ layout "layouts/decidim/assembly", only: [:show]
9
+
10
+ before_action -> { extend NeedsAssembly }, only: [:show]
11
+
12
+ helper Decidim::AttachmentsHelper
13
+ helper Decidim::IconHelper
14
+ helper Decidim::WidgetUrlsHelper
15
+
16
+ helper_method :collection, :promoted_assemblies, :assemblies, :stats
17
+
18
+ def index
19
+ authorize! :read, Assembly
20
+ end
21
+
22
+ def show
23
+ authorize! :read, current_assembly
24
+ end
25
+
26
+ private
27
+
28
+ def assemblies
29
+ @assemblies ||= OrganizationPrioritizedAssemblies.new(current_organization)
30
+ end
31
+
32
+ alias collection assemblies
33
+
34
+ def promoted_assemblies
35
+ @promoted_assemblies ||= assemblies | PromotedAssemblies.new
36
+ end
37
+
38
+ def stats
39
+ @stats ||= AssemblyStatsPresenter.new(assembly: current_assembly)
40
+ end
41
+ end
42
+ end
43
+ end