decidim-admin 0.10.1 → 0.11.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of decidim-admin might be problematic. Click here for more details.

Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/assets/config/decidim_admin_manifest.js +1 -0
  4. data/app/assets/javascripts/decidim/admin/application.js.es6 +13 -5
  5. data/app/assets/javascripts/decidim/admin/auto_buttons_by_position.component.js.es6 +42 -0
  6. data/app/assets/javascripts/decidim/admin/auto_label_by_position.component.js.es6 +33 -0
  7. data/app/assets/javascripts/decidim/admin/dynamic_fields.component.js.es6 +163 -0
  8. data/app/assets/javascripts/decidim/admin/field_dependent_inputs.component.js.es6 +39 -0
  9. data/app/assets/javascripts/decidim/admin/managed_users.js.es6 +12 -0
  10. data/app/assets/javascripts/decidim/admin/sort_list.component.js.es6 +1 -1
  11. data/app/assets/javascripts/decidim/admin/subform_toggler.component.js.es6 +35 -0
  12. data/app/assets/javascripts/decidim/admin/tab_focus.js.es6 +4 -4
  13. data/app/assets/stylesheets/decidim/admin/application.scss.erb +1 -1
  14. data/app/assets/stylesheets/decidim/admin/extra/_dropdown_inverted.scss +7 -5
  15. data/app/assets/stylesheets/decidim/admin/modules/_agenda.scss +34 -0
  16. data/app/assets/stylesheets/decidim/admin/modules/_buttons.scss +5 -0
  17. data/app/assets/stylesheets/decidim/admin/modules/_cards.scss +15 -0
  18. data/app/assets/stylesheets/decidim/admin/modules/_forms.scss +4 -0
  19. data/app/assets/stylesheets/decidim/admin/modules/_modules.scss +1 -0
  20. data/app/assets/stylesheets/decidim/admin/modules/_typography.scss +8 -0
  21. data/app/assets/stylesheets/decidim/admin/utils/_flex.scss +2 -2
  22. data/app/assets/stylesheets/decidim/admin/utils/_helpers.scss +28 -0
  23. data/app/assets/stylesheets/decidim/admin/utils/_mixins.scss +44 -0
  24. data/app/commands/decidim/admin/create_area.rb +3 -1
  25. data/app/commands/decidim/admin/{create_feature.rb → create_component.rb} +11 -11
  26. data/app/commands/decidim/admin/create_oauth_application.rb +36 -0
  27. data/app/commands/decidim/admin/create_participatory_space_private_user.rb +85 -0
  28. data/app/commands/decidim/admin/destroy_area.rb +42 -0
  29. data/app/commands/decidim/admin/{destroy_feature.rb → destroy_component.rb} +11 -11
  30. data/app/commands/decidim/admin/destroy_oauth_application.rb +39 -0
  31. data/app/commands/decidim/admin/{impersonate_managed_user.rb → impersonate_user.rb} +19 -13
  32. data/app/commands/decidim/admin/publish_component.rb +51 -0
  33. data/app/commands/decidim/admin/{unpublish_feature.rb → unpublish_component.rb} +12 -12
  34. data/app/commands/decidim/admin/update_area.rb +5 -1
  35. data/app/commands/decidim/admin/update_component.rb +62 -0
  36. data/app/commands/decidim/admin/{update_feature_permissions.rb → update_component_permissions.rb} +10 -10
  37. data/app/commands/decidim/admin/update_oauth_application.rb +39 -0
  38. data/app/controllers/decidim/admin/application_controller.rb +1 -1
  39. data/app/controllers/decidim/admin/areas_controller.rb +6 -4
  40. data/app/controllers/decidim/admin/{feature_permissions_controller.rb → component_permissions_controller.rb} +12 -12
  41. data/app/controllers/decidim/admin/{features → components}/base_controller.rb +9 -9
  42. data/app/controllers/decidim/admin/components_controller.rb +142 -0
  43. data/app/controllers/decidim/admin/concerns/has_private_users.rb +102 -0
  44. data/app/controllers/decidim/admin/dashboard_controller.rb +1 -1
  45. data/app/controllers/decidim/admin/exports_controller.rb +6 -6
  46. data/app/controllers/decidim/admin/impersonatable_users_controller.rb +29 -0
  47. data/app/controllers/decidim/admin/impersonations_controller.rb +122 -0
  48. data/app/controllers/decidim/admin/logs_controller.rb +1 -1
  49. data/app/controllers/decidim/admin/managed_users/impersonation_logs_controller.rb +25 -0
  50. data/app/controllers/decidim/admin/managed_users/promotions_controller.rb +3 -5
  51. data/app/controllers/decidim/admin/newsletters_controller.rb +1 -1
  52. data/app/controllers/decidim/admin/oauth_applications_controller.rb +90 -0
  53. data/app/controllers/decidim/admin/officializations_controller.rb +4 -3
  54. data/app/events/decidim/component_published_event.rb +6 -0
  55. data/app/forms/decidim/admin/{feature_form.rb → component_form.rb} +3 -3
  56. data/app/forms/decidim/admin/impersonate_user_form.rb +26 -0
  57. data/app/forms/decidim/admin/oauth_application_form.rb +32 -0
  58. data/app/forms/decidim/admin/organization_appearance_form.rb +6 -1
  59. data/app/forms/decidim/admin/organization_form.rb +1 -1
  60. data/app/forms/decidim/admin/participatory_space_private_user_form.rb +18 -0
  61. data/app/forms/decidim/admin/permissions_form.rb +1 -1
  62. data/app/helpers/decidim/admin/attributes_display_helper.rb +10 -3
  63. data/app/helpers/decidim/admin/bulk_actions_helper.rb +36 -0
  64. data/app/helpers/decidim/admin/exports_helper.rb +10 -10
  65. data/app/helpers/decidim/admin/settings_helper.rb +1 -1
  66. data/app/models/decidim/admin/abilities/admin_ability.rb +12 -9
  67. data/app/models/decidim/admin/abilities/participatory_process_admin_ability.rb +2 -2
  68. data/app/models/decidim/admin/abilities/user_manager_ability.rb +7 -6
  69. data/app/queries/decidim/admin/user_filter.rb +59 -0
  70. data/app/views/decidim/admin/area_types/edit.html.erb +1 -1
  71. data/app/views/decidim/admin/area_types/index.html.erb +2 -2
  72. data/app/views/decidim/admin/area_types/new.html.erb +1 -1
  73. data/app/views/decidim/admin/areas/edit.html.erb +1 -1
  74. data/app/views/decidim/admin/areas/index.html.erb +2 -2
  75. data/app/views/decidim/admin/areas/new.html.erb +1 -1
  76. data/app/views/decidim/admin/attachment_collections/edit.html.erb +1 -1
  77. data/app/views/decidim/admin/attachment_collections/index.html.erb +2 -2
  78. data/app/views/decidim/admin/attachment_collections/new.html.erb +1 -1
  79. data/app/views/decidim/admin/attachment_collections/show.html.erb +2 -3
  80. data/app/views/decidim/admin/attachments/edit.html.erb +1 -1
  81. data/app/views/decidim/admin/attachments/index.html.erb +1 -1
  82. data/app/views/decidim/admin/attachments/new.html.erb +1 -1
  83. data/app/views/decidim/admin/attachments/show.html.erb +2 -3
  84. data/app/views/decidim/admin/bulk_actions/_recategorize.html.erb +1 -1
  85. data/app/views/decidim/admin/categories/edit.html.erb +1 -1
  86. data/app/views/decidim/admin/categories/index.html.erb +2 -2
  87. data/app/views/decidim/admin/categories/new.html.erb +1 -1
  88. data/app/views/decidim/admin/categories/show.html.erb +2 -3
  89. data/app/views/decidim/admin/{feature_permissions → component_permissions}/edit.html.erb +3 -3
  90. data/app/views/decidim/admin/components/_component.html.erb +37 -0
  91. data/app/views/decidim/admin/{features → components}/_form.html.erb +6 -6
  92. data/app/views/decidim/admin/{features → components}/_settings_fields.html.erb +2 -2
  93. data/app/views/decidim/admin/components/edit.html.erb +7 -0
  94. data/app/views/decidim/admin/{features → components}/index.html.erb +6 -6
  95. data/app/views/decidim/admin/components/new.html.erb +8 -0
  96. data/app/views/decidim/admin/devise/mailers/reset_password_instructions.html.erb +1 -1
  97. data/app/views/decidim/admin/exports/_dropdown.html.erb +3 -3
  98. data/app/views/decidim/admin/impersonatable_users/index.html.erb +84 -0
  99. data/app/views/decidim/admin/impersonations/_form.html.erb +40 -0
  100. data/app/views/decidim/admin/impersonations/_handler_form.html.erb +5 -0
  101. data/app/views/decidim/admin/impersonations/new.html.erb +23 -0
  102. data/app/views/decidim/admin/managed_users/{impersonations → impersonation_logs}/index.html.erb +2 -0
  103. data/app/views/decidim/admin/managed_users/promotions/new.html.erb +4 -4
  104. data/app/views/decidim/admin/moderations/index.html.erb +2 -2
  105. data/app/views/decidim/admin/newsletters/_form.html.erb +1 -1
  106. data/app/views/decidim/admin/newsletters/edit.html.erb +1 -1
  107. data/app/views/decidim/admin/newsletters/index.html.erb +1 -1
  108. data/app/views/decidim/admin/newsletters/new.html.erb +1 -1
  109. data/app/views/decidim/admin/newsletters/show.html.erb +1 -1
  110. data/app/views/decidim/admin/oauth_applications/_form.html.erb +19 -0
  111. data/app/views/decidim/admin/oauth_applications/edit.html.erb +13 -0
  112. data/app/views/decidim/admin/oauth_applications/index.html.erb +38 -0
  113. data/app/views/decidim/admin/oauth_applications/new.html.erb +13 -0
  114. data/app/views/decidim/admin/oauth_applications/show.html.erb +27 -0
  115. data/app/views/decidim/admin/officializations/index.html.erb +2 -2
  116. data/app/views/decidim/admin/officializations/new.html.erb +2 -2
  117. data/app/views/decidim/admin/organization/_form.html.erb +1 -1
  118. data/app/views/decidim/admin/organization/edit.html.erb +1 -2
  119. data/app/views/decidim/admin/organization_appearance/edit.html.erb +1 -2
  120. data/app/views/decidim/admin/participatory_space_private_users/_form.html.erb +18 -0
  121. data/app/views/decidim/admin/participatory_space_private_users/index.html.erb +59 -0
  122. data/app/views/decidim/admin/participatory_space_private_users/new.html.erb +7 -0
  123. data/app/views/decidim/admin/scope_types/edit.html.erb +1 -1
  124. data/app/views/decidim/admin/scope_types/index.html.erb +2 -2
  125. data/app/views/decidim/admin/scope_types/new.html.erb +1 -1
  126. data/app/views/decidim/admin/scopes/edit.html.erb +1 -1
  127. data/app/views/decidim/admin/scopes/index.html.erb +3 -3
  128. data/app/views/decidim/admin/scopes/new.html.erb +1 -1
  129. data/app/views/decidim/admin/static_pages/edit.html.erb +1 -1
  130. data/app/views/decidim/admin/static_pages/index.html.erb +3 -3
  131. data/app/views/decidim/admin/static_pages/new.html.erb +1 -1
  132. data/app/views/decidim/admin/static_pages/show.html.erb +2 -3
  133. data/app/views/decidim/admin/user_groups/index.html.erb +3 -3
  134. data/app/views/decidim/admin/users/_form.html.erb +3 -3
  135. data/app/views/decidim/admin/users/index.html.erb +2 -2
  136. data/app/views/decidim/admin/users/new.html.erb +1 -1
  137. data/app/views/layouts/decidim/admin/_application.html.erb +9 -9
  138. data/app/views/layouts/decidim/admin/_header.html.erb +3 -4
  139. data/app/views/layouts/decidim/admin/_template_top.html.erb +1 -1
  140. data/app/views/layouts/decidim/admin/_title_bar.html.erb +1 -1
  141. data/app/views/layouts/decidim/admin/login.html.erb +1 -1
  142. data/app/views/layouts/decidim/admin/pages.html.erb +1 -1
  143. data/app/views/layouts/decidim/admin/users.html.erb +5 -3
  144. data/config/locales/ca.yml +119 -50
  145. data/config/locales/en.yml +119 -50
  146. data/config/locales/es.yml +120 -51
  147. data/config/locales/eu.yml +122 -53
  148. data/config/locales/fi.yml +121 -52
  149. data/config/locales/fr.yml +159 -90
  150. data/config/locales/gl.yml +119 -50
  151. data/config/locales/it.yml +120 -51
  152. data/config/locales/nl.yml +207 -138
  153. data/config/locales/pl.yml +119 -50
  154. data/config/locales/pt-BR.yml +120 -51
  155. data/config/locales/pt.yml +120 -51
  156. data/config/locales/ru.yml +7 -51
  157. data/config/locales/sv.yml +120 -51
  158. data/config/locales/uk.yml +7 -52
  159. data/config/routes.rb +6 -2
  160. data/db/migrate/20180413233318_add_reason_to_decidim_impersonation_logs.rb +7 -0
  161. data/lib/decidim/admin/components.rb +11 -0
  162. data/lib/decidim/admin/engine.rb +12 -3
  163. data/lib/decidim/admin/test/forms/attachment_collection_form_examples.rb +9 -9
  164. data/lib/decidim/admin/test/forms/attachment_form_examples.rb +1 -1
  165. data/lib/decidim/admin/test/forms/category_form_examples.rb +11 -11
  166. data/lib/decidim/admin/test/{manage_feature_permissions_examples.rb → manage_component_permissions_examples.rb} +9 -9
  167. data/lib/decidim/admin/test/manage_moderations_examples.rb +2 -2
  168. data/lib/decidim/admin/test.rb +1 -1
  169. data/lib/decidim/admin/version.rb +1 -1
  170. data/lib/decidim/admin.rb +1 -1
  171. metadata +66 -43
  172. data/app/commands/decidim/admin/create_managed_user.rb +0 -69
  173. data/app/commands/decidim/admin/publish_feature.rb +0 -51
  174. data/app/commands/decidim/admin/update_feature.rb +0 -62
  175. data/app/controllers/decidim/admin/features_controller.rb +0 -142
  176. data/app/controllers/decidim/admin/managed_users/impersonations_controller.rb +0 -78
  177. data/app/controllers/decidim/admin/managed_users_controller.rb +0 -83
  178. data/app/events/decidim/feature_published_event.rb +0 -6
  179. data/app/forms/decidim/admin/impersonate_managed_user_form.rb +0 -20
  180. data/app/forms/decidim/admin/managed_user_form.rb +0 -24
  181. data/app/queries/decidim/admin/users_officialization.rb +0 -56
  182. data/app/views/decidim/admin/features/_feature.html.erb +0 -37
  183. data/app/views/decidim/admin/features/edit.html.erb +0 -7
  184. data/app/views/decidim/admin/features/new.html.erb +0 -8
  185. data/app/views/decidim/admin/managed_users/_form.html.erb +0 -12
  186. data/app/views/decidim/admin/managed_users/impersonations/_form.html.erb +0 -10
  187. data/app/views/decidim/admin/managed_users/impersonations/new.html.erb +0 -15
  188. data/app/views/decidim/admin/managed_users/index.html.erb +0 -44
  189. data/app/views/decidim/admin/managed_users/new.html.erb +0 -47
  190. data/lib/decidim/admin/features.rb +0 -11
@@ -29,7 +29,9 @@ module Decidim
29
29
  attr_reader :form
30
30
 
31
31
  def create_area
32
- Area.create!(
32
+ Decidim.traceability.create!(
33
+ Area,
34
+ form.current_user,
33
35
  name: form.name,
34
36
  organization: form.organization,
35
37
  area_type: form.area_type
@@ -2,29 +2,29 @@
2
2
 
3
3
  module Decidim
4
4
  module Admin
5
- # This command gets called when a feature is created from the admin panel.
6
- class CreateFeature < Rectify::Command
5
+ # This command gets called when a component is created from the admin panel.
6
+ class CreateComponent < Rectify::Command
7
7
  attr_reader :form, :manifest, :participatory_space
8
8
 
9
9
  # Public: Initializes the command.
10
10
  #
11
- # manifest - The feature's manifest to create a feature from.
12
- # form - The form from which the data in this feature comes from.
13
- # participatory_space - The participatory space that will hold this feature.
11
+ # manifest - The component's manifest to create a component from.
12
+ # form - The form from which the data in this component comes from.
13
+ # participatory_space - The participatory space that will hold this component.
14
14
  def initialize(manifest, form, participatory_space)
15
15
  @manifest = manifest
16
16
  @form = form
17
17
  @participatory_space = participatory_space
18
18
  end
19
19
 
20
- # Public: Creates the Feature.
20
+ # Public: Creates the Component.
21
21
  #
22
22
  # Broadcasts :ok if created, :invalid otherwise.
23
23
  def call
24
24
  return broadcast(:invalid) if form.invalid?
25
25
 
26
26
  transaction do
27
- create_feature
27
+ create_component
28
28
  run_hooks
29
29
  end
30
30
 
@@ -33,9 +33,9 @@ module Decidim
33
33
 
34
34
  private
35
35
 
36
- def create_feature
37
- @feature = Decidim.traceability.create!(
38
- Feature,
36
+ def create_component
37
+ @component = Decidim.traceability.create!(
38
+ Component,
39
39
  form.current_user,
40
40
  manifest_name: manifest.name,
41
41
  name: form.name,
@@ -48,7 +48,7 @@ module Decidim
48
48
  end
49
49
 
50
50
  def run_hooks
51
- manifest.run_hooks(:create, @feature)
51
+ manifest.run_hooks(:create, @component)
52
52
  end
53
53
  end
54
54
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # Creates an OAuthApplication.
6
+ class CreateOAuthApplication < Rectify::Command
7
+ # Initializes the command.
8
+ #
9
+ # form - The source fo data for this OAuthApplication.
10
+ def initialize(form)
11
+ @form = form
12
+ end
13
+
14
+ def call
15
+ return broadcast(:invalid) unless @form.valid?
16
+
17
+ @application = Decidim.traceability.create!(
18
+ OAuthApplication,
19
+ @form.current_user,
20
+ name: @form.name,
21
+ organization_name: @form.organization_name,
22
+ organization_url: @form.organization_url,
23
+ organization_logo: @form.organization_logo,
24
+ redirect_uri: @form.redirect_uri,
25
+ scopes: "public",
26
+ organization: @form.current_organization
27
+ )
28
+
29
+ broadcast(:ok, @application)
30
+ rescue ActiveRecord::RecordInvalid
31
+ @form.errors.add(:organization_logo, @application.errors[:organization_logo]) if @application.errors.include? :organization_logo
32
+ broadcast(:invalid)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic when creating a new participatory space
6
+ # private user in the system.
7
+ class CreateParticipatorySpacePrivateUser < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # form - A form object with the params.
11
+ # private_user_to - The private_user_to that will hold the
12
+ # user role
13
+ def initialize(form, current_user, private_user_to)
14
+ @form = form
15
+ @current_user = current_user
16
+ @private_user_to = private_user_to
17
+ end
18
+
19
+ # Executes the command. Broadcasts these events:
20
+ #
21
+ # - :ok when everything is valid.
22
+ # - :invalid if the form wasn't valid and we couldn't proceed.
23
+ #
24
+ # Returns nothing.
25
+ def call
26
+ return broadcast(:invalid) if form.invalid?
27
+
28
+ ActiveRecord::Base.transaction do
29
+ @user ||= existing_user || new_user
30
+ create_private_user
31
+ end
32
+
33
+ broadcast(:ok)
34
+ rescue ActiveRecord::RecordInvalid
35
+ form.errors.add(:email, :taken)
36
+ broadcast(:invalid)
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :form, :private_user_to, :current_user, :user
42
+
43
+ def create_private_user
44
+ Decidim::ParticipatorySpacePrivateUser.find_or_create_by!(
45
+ user: user,
46
+ privatable_to: @private_user_to
47
+ )
48
+ end
49
+
50
+ def existing_user
51
+ return @existing_user if defined?(@existing_user)
52
+
53
+ @existing_user = User.find_by(
54
+ email: form.email,
55
+ organization: private_user_to.organization
56
+ )
57
+
58
+ InviteUserAgain.call(@existing_user, invitation_instructions) if @existing_user && !@existing_user.invitation_accepted?
59
+
60
+ @existing_user
61
+ end
62
+
63
+ def new_user
64
+ @new_user ||= InviteUser.call(user_form) do
65
+ on(:ok) do |user|
66
+ return user
67
+ end
68
+ end
69
+ end
70
+
71
+ def user_form
72
+ OpenStruct.new(name: form.name,
73
+ email: form.email.downcase,
74
+ organization: private_user_to.organization,
75
+ admin: false,
76
+ invited_by: current_user,
77
+ invitation_instructions: invitation_instructions)
78
+ end
79
+
80
+ def invitation_instructions
81
+ "invite_private_user"
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic to destroy an area.
6
+ class DestroyArea < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # area - The area to destroy
10
+ # current_user - the user performing the action
11
+ def initialize(area, current_user)
12
+ @area = area
13
+ @current_user = current_user
14
+ end
15
+
16
+ # Executes the command. Broadcasts these events:
17
+ #
18
+ # - :ok when everything is valid.
19
+ # - :invalid if the form wasn't valid and we couldn't proceed.
20
+ #
21
+ # Returns nothing.
22
+ def call
23
+ destroy_area
24
+ broadcast(:ok)
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :current_user
30
+
31
+ def destroy_area
32
+ Decidim.traceability.perform_action!(
33
+ "delete",
34
+ @area,
35
+ current_user
36
+ ) do
37
+ @area.destroy!
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -2,14 +2,14 @@
2
2
 
3
3
  module Decidim
4
4
  module Admin
5
- # This command deals with destroying a Feature from the admin panel.
6
- class DestroyFeature < Rectify::Command
5
+ # This command deals with destroying a Component from the admin panel.
6
+ class DestroyComponent < Rectify::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
- # feature - The Feature to be destroyed.
9
+ # component - The Component to be destroyed.
10
10
  # current_user - the user performing the action
11
- def initialize(feature, current_user)
12
- @feature = feature
11
+ def initialize(component, current_user)
12
+ @component = component
13
13
  @current_user = current_user
14
14
  end
15
15
 
@@ -18,7 +18,7 @@ module Decidim
18
18
  # Broadcasts :ok if it got destroyed, raises an exception otherwise.
19
19
  def call
20
20
  begin
21
- destroy_feature
21
+ destroy_component
22
22
  rescue StandardError
23
23
  return broadcast(:invalid)
24
24
  end
@@ -27,16 +27,16 @@ module Decidim
27
27
 
28
28
  private
29
29
 
30
- def destroy_feature
30
+ def destroy_component
31
31
  transaction do
32
32
  run_before_hooks
33
33
 
34
34
  Decidim.traceability.perform_action!(
35
35
  "delete",
36
- @feature,
36
+ @component,
37
37
  @current_user
38
38
  ) do
39
- @feature.destroy!
39
+ @component.destroy!
40
40
  end
41
41
 
42
42
  run_hooks
@@ -44,11 +44,11 @@ module Decidim
44
44
  end
45
45
 
46
46
  def run_before_hooks
47
- @feature.manifest.run_hooks(:before_destroy, @feature)
47
+ @component.manifest.run_hooks(:before_destroy, @component)
48
48
  end
49
49
 
50
50
  def run_hooks
51
- @feature.manifest.run_hooks(:destroy, @feature)
51
+ @component.manifest.run_hooks(:destroy, @component)
52
52
  end
53
53
  end
54
54
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This command deals with destroying an application from the admin panel.
6
+ class DestroyOAuthApplication < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # application - The OAuthApplication to be destroyed.
10
+ # user - The user that destroys the application.
11
+ def initialize(application, current_user)
12
+ @application = application
13
+ @current_user = current_user
14
+ end
15
+
16
+ # Public: Executes the command.
17
+ #
18
+ # Broadcasts :ok if it got destroyed
19
+ def call
20
+ destroy_application
21
+ broadcast(:ok)
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :application, :current_user
27
+
28
+ def destroy_application
29
+ Decidim.traceability.perform_action!(
30
+ "delete",
31
+ application,
32
+ current_user
33
+ ) do
34
+ application.destroy!
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -3,14 +3,13 @@
3
3
  module Decidim
4
4
  module Admin
5
5
  # A command with all the business logic to impersonate a managed user.
6
- class ImpersonateManagedUser < Rectify::Command
6
+ class ImpersonateUser < Rectify::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - The form with the authorization info
10
10
  # user - The user to impersonate
11
- def initialize(form, user)
11
+ def initialize(form)
12
12
  @form = form
13
- @user = user
14
13
  end
15
14
 
16
15
  # Executes the command. Broadcasts these events:
@@ -20,9 +19,16 @@ module Decidim
20
19
  #
21
20
  # Returns nothing.
22
21
  def call
23
- return broadcast(:invalid) unless user.managed? && authorization_valid?
22
+ return broadcast(:invalid) unless form.valid?
23
+
24
+ transaction do
25
+ user.save! unless user.persisted?
26
+
27
+ create_authorization
28
+
29
+ create_impersonation_log
30
+ end
24
31
 
25
- create_impersonation_log
26
32
  enqueue_expire_job
27
33
 
28
34
  broadcast(:ok)
@@ -30,21 +36,21 @@ module Decidim
30
36
 
31
37
  private
32
38
 
33
- attr_reader :user, :form
39
+ attr_reader :form
34
40
 
35
- def authorization_valid?
36
- return false unless form.valid?
37
- Decidim::Authorization.where(
38
- user: user,
39
- name: form.authorization.handler_name,
40
- unique_id: form.authorization.unique_id
41
- ).any?
41
+ def user
42
+ form.user
43
+ end
44
+
45
+ def create_authorization
46
+ Authorization.create_or_update_from(form.authorization)
42
47
  end
43
48
 
44
49
  def create_impersonation_log
45
50
  Decidim::ImpersonationLog.create!(
46
51
  admin: form.current_user,
47
52
  user: user,
53
+ reason: form.reason,
48
54
  started_at: Time.current
49
55
  )
50
56
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This command gets called when a component is published from the admin panel.
6
+ class PublishComponent < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # component - The component to publish.
10
+ # current_user - the user performing the action
11
+ def initialize(component, current_user)
12
+ @component = component
13
+ @current_user = current_user
14
+ end
15
+
16
+ # Public: Publishes the Component.
17
+ #
18
+ # Broadcasts :ok if published, :invalid otherwise.
19
+ def call
20
+ publish_component
21
+ publish_event
22
+
23
+ broadcast(:ok)
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :component, :current_user
29
+
30
+ def publish_component
31
+ Decidim.traceability.perform_action!(
32
+ :publish,
33
+ component,
34
+ current_user
35
+ ) do
36
+ component.publish!
37
+ component
38
+ end
39
+ end
40
+
41
+ def publish_event
42
+ Decidim::EventsManager.publish(
43
+ event: "decidim.events.components.component_published",
44
+ event_class: Decidim::ComponentPublishedEvent,
45
+ resource: component,
46
+ recipient_ids: component.participatory_space.followers.pluck(:id)
47
+ )
48
+ end
49
+ end
50
+ end
51
+ end
@@ -2,38 +2,38 @@
2
2
 
3
3
  module Decidim
4
4
  module Admin
5
- # This command gets called when a feature is unpublished from the admin panel.
6
- class UnpublishFeature < Rectify::Command
5
+ # This command gets called when a component is unpublished from the admin panel.
6
+ class UnpublishComponent < Rectify::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
- # feature - The feature to unpublish.
9
+ # component - The component to unpublish.
10
10
  # current_user - the user performing the action
11
- def initialize(feature, current_user)
12
- @feature = feature
11
+ def initialize(component, current_user)
12
+ @component = component
13
13
  @current_user = current_user
14
14
  end
15
15
 
16
- # Public: Unpublishes the Feature.
16
+ # Public: Unpublishes the Component.
17
17
  #
18
18
  # Broadcasts :ok if unpublished, :invalid otherwise.
19
19
  def call
20
- unpublish_feature
20
+ unpublish_component
21
21
 
22
22
  broadcast(:ok)
23
23
  end
24
24
 
25
25
  private
26
26
 
27
- attr_reader :feature, :current_user
27
+ attr_reader :component, :current_user
28
28
 
29
- def unpublish_feature
29
+ def unpublish_component
30
30
  Decidim.traceability.perform_action!(
31
31
  :unpublish,
32
- feature,
32
+ component,
33
33
  current_user
34
34
  ) do
35
- feature.unpublish!
36
- feature
35
+ component.unpublish!
36
+ component
37
37
  end
38
38
  end
39
39
  end
@@ -31,7 +31,11 @@ module Decidim
31
31
  attr_reader :form
32
32
 
33
33
  def update_area
34
- @area.update!(attributes)
34
+ Decidim.traceability.update!(
35
+ @area,
36
+ form.current_user,
37
+ attributes
38
+ )
35
39
  end
36
40
 
37
41
  def attributes
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # This command gets called when a component is created from the admin panel.
6
+ class UpdateComponent < Rectify::Command
7
+ attr_reader :form, :component, :previous_settings
8
+
9
+ # Public: Initializes the command.
10
+ #
11
+ # form - The form from which the data in this component comes from.
12
+ # component - The component to update.
13
+ def initialize(form, component)
14
+ @manifest = component.manifest
15
+ @form = form
16
+ @component = component
17
+ end
18
+
19
+ # Public: Creates the Component.
20
+ #
21
+ # Broadcasts :ok if created, :invalid otherwise.
22
+ def call
23
+ return broadcast(:invalid) if form.invalid?
24
+
25
+ transaction do
26
+ update_component
27
+ run_hooks
28
+ end
29
+
30
+ broadcast(:ok, settings_changed?, previous_settings, current_settings)
31
+ end
32
+
33
+ private
34
+
35
+ def update_component
36
+ @previous_settings = @component.attributes["settings"].dup
37
+
38
+ @component.name = form.name
39
+ @component.settings = form.settings
40
+ @component.default_step_settings = form.default_step_settings
41
+ @component.step_settings = form.step_settings
42
+ @component.weight = form.weight
43
+
44
+ @settings_changed = @component.settings_changed?
45
+
46
+ @component.save!
47
+ end
48
+
49
+ def run_hooks
50
+ @manifest.run_hooks(:update, @component)
51
+ end
52
+
53
+ def settings_changed?
54
+ @settings_changed
55
+ end
56
+
57
+ def current_settings
58
+ @component.attributes["settings"]
59
+ end
60
+ end
61
+ end
62
+ end
@@ -2,21 +2,21 @@
2
2
 
3
3
  module Decidim
4
4
  module Admin
5
- # This command gets called when permissions for a feature are updated
5
+ # This command gets called when permissions for a component are updated
6
6
  # in the admin panel.
7
- class UpdateFeaturePermissions < Rectify::Command
8
- attr_reader :form, :feature
7
+ class UpdateComponentPermissions < Rectify::Command
8
+ attr_reader :form, :component
9
9
 
10
10
  # Public: Initializes the command.
11
11
  #
12
- # form - The form from which the data in this feature comes from.
13
- # feature - The feature to update.
14
- def initialize(form, feature)
12
+ # form - The form from which the data in this component comes from.
13
+ # component - The component to update.
14
+ def initialize(form, component)
15
15
  @form = form
16
- @feature = feature
16
+ @component = component
17
17
  end
18
18
 
19
- # Public: Sets the permissions for a feature.
19
+ # Public: Sets the permissions for a component.
20
20
  #
21
21
  # Broadcasts :ok if created, :invalid otherwise.
22
22
  def call
@@ -42,13 +42,13 @@ module Decidim
42
42
  result.update(key => serialized)
43
43
  end
44
44
 
45
- @feature.update!(
45
+ @component.update!(
46
46
  permissions: permissions
47
47
  )
48
48
  end
49
49
 
50
50
  def run_hooks
51
- @feature.manifest.run_hooks(:permission_update, @feature)
51
+ @component.manifest.run_hooks(:permission_update, @component)
52
52
  end
53
53
  end
54
54
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # Updates the OAuth application given form data.
6
+ class UpdateOAuthApplication < Rectify::Command
7
+ # Initializes the command.
8
+ #
9
+ # application - The OAuthApplication to update.
10
+ # form - The form object containing the data to update.
11
+ # user - The user that updates the application.
12
+ def initialize(application, form, user)
13
+ @application = application
14
+ @form = form
15
+ @user = user
16
+ end
17
+
18
+ def call
19
+ return broadcast(:invalid) unless @form.valid?
20
+ return broadcast(:invalid) unless @user.organization == @application.organization
21
+
22
+ @application = Decidim.traceability.update!(
23
+ @application,
24
+ @user,
25
+ name: @form.name,
26
+ organization_name: @form.organization_name,
27
+ organization_url: @form.organization_url,
28
+ organization_logo: @form.organization_logo,
29
+ redirect_uri: @form.redirect_uri
30
+ )
31
+
32
+ broadcast(:ok, @application)
33
+ rescue ActiveRecord::RecordInvalid
34
+ @form.errors.add(:organization_logo, @application.errors[:organization_logo]) if @application.errors.include? :organization_logo
35
+ broadcast(:invalid)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -21,7 +21,7 @@ module Decidim
21
21
  helper Decidim::ScopesHelper
22
22
  helper Decidim::TranslationsHelper
23
23
  helper Decidim::LanguageChooserHelper
24
- helper Decidim::FeaturePathHelper
24
+ helper Decidim::ComponentPathHelper
25
25
 
26
26
  protect_from_forgery with: :exception, prepend: true
27
27