decidim-admin 0.4.4 → 0.5.0

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 (99) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/admin/application.js.es6 +3 -0
  3. data/app/assets/javascripts/decidim/admin/participatory_processes.js.es6 +12 -0
  4. data/app/assets/javascripts/decidim/admin/scopes.js.es6 +20 -0
  5. data/app/assets/javascripts/decidim/admin/select2.js.es6 +8 -0
  6. data/app/assets/stylesheets/decidim/admin/_decidim.scss +2 -0
  7. data/app/assets/stylesheets/decidim/admin/extra/_categories.scss +1 -1
  8. data/app/assets/stylesheets/decidim/admin/extra/_login.scss +1 -1
  9. data/app/assets/stylesheets/decidim/admin/extra/_sort.scss +1 -1
  10. data/app/assets/stylesheets/decidim/admin/modules/_buttons.scss +3 -0
  11. data/app/assets/stylesheets/decidim/admin/modules/_callouts.scss +0 -1
  12. data/app/assets/stylesheets/decidim/admin/modules/_cards.scss +47 -0
  13. data/app/assets/stylesheets/decidim/admin/modules/_secondary-nav.scss +2 -2
  14. data/app/assets/stylesheets/decidim/admin/modules/_typography.scss +1 -1
  15. data/app/assets/stylesheets/decidim/admin/plugins/_select2.scss +27 -0
  16. data/app/assets/stylesheets/decidim/admin/utils/_toggle-expand.scss +1 -1
  17. data/app/commands/decidim/admin/close_session_managed_user.rb +44 -0
  18. data/app/commands/decidim/admin/create_feature.rb +2 -1
  19. data/app/commands/decidim/admin/create_managed_user.rb +61 -0
  20. data/app/commands/decidim/admin/create_scope.rb +7 -2
  21. data/app/commands/decidim/admin/create_scope_type.rb +40 -0
  22. data/app/commands/decidim/admin/impersonate_managed_user.rb +61 -0
  23. data/app/commands/decidim/admin/promote_managed_user.rb +56 -0
  24. data/app/commands/decidim/admin/update_participatory_process.rb +3 -1
  25. data/app/commands/decidim/admin/update_scope.rb +4 -1
  26. data/app/commands/decidim/admin/update_scope_type.rb +45 -0
  27. data/app/controllers/decidim/admin/application_controller.rb +2 -1
  28. data/app/controllers/decidim/admin/categories_controller.rb +3 -3
  29. data/app/controllers/decidim/admin/exports_controller.rb +1 -1
  30. data/app/controllers/decidim/admin/managed_users/impersonations_controller.rb +78 -0
  31. data/app/controllers/decidim/admin/managed_users/promotions_controller.rb +43 -0
  32. data/app/controllers/decidim/admin/managed_users_controller.rb +69 -0
  33. data/app/controllers/decidim/admin/moderations_controller.rb +4 -4
  34. data/app/controllers/decidim/admin/newsletters_controller.rb +1 -1
  35. data/app/controllers/decidim/admin/participatory_processes_controller.rb +0 -5
  36. data/app/controllers/decidim/admin/scope_types_controller.rb +79 -0
  37. data/app/controllers/decidim/admin/scopes_controller.rb +22 -7
  38. data/app/controllers/decidim/admin/user_groups_controller.rb +1 -1
  39. data/app/controllers/decidim/admin/users_controller.rb +1 -2
  40. data/app/forms/decidim/admin/impersonate_managed_user_form.rb +20 -0
  41. data/app/forms/decidim/admin/managed_user_form.rb +35 -0
  42. data/app/forms/decidim/admin/managed_user_promotion_form.rb +13 -0
  43. data/app/forms/decidim/admin/participatory_process_form.rb +2 -0
  44. data/app/forms/decidim/admin/scope_form.rb +17 -6
  45. data/app/forms/decidim/admin/scope_type_form.rb +21 -0
  46. data/app/helpers/decidim/admin/scopes_helper.rb +46 -0
  47. data/app/helpers/decidim/admin/settings_helper.rb +12 -1
  48. data/app/jobs/decidim/admin/expire_impersonation_job.rb +16 -0
  49. data/app/models/decidim/admin/abilities/admin_ability.rb +17 -0
  50. data/app/models/decidim/admin/abilities/user_manager_ability.rb +30 -0
  51. data/app/views/decidim/admin/categories/_form.html.erb +1 -1
  52. data/app/views/decidim/admin/categories/edit.html.erb +1 -1
  53. data/app/views/decidim/admin/categories/index.html.erb +7 -7
  54. data/app/views/decidim/admin/categories/new.html.erb +1 -1
  55. data/app/views/decidim/admin/features/_form.html.erb +6 -3
  56. data/app/views/decidim/admin/features/_settings_fields.html.erb +2 -1
  57. data/app/views/decidim/admin/managed_users/_form.html.erb +12 -0
  58. data/app/views/decidim/admin/managed_users/impersonations/_form.html.erb +10 -0
  59. data/app/views/decidim/admin/managed_users/impersonations/index.html.erb +34 -0
  60. data/app/views/decidim/admin/managed_users/impersonations/new.html.erb +15 -0
  61. data/app/views/decidim/admin/managed_users/index.html.erb +44 -0
  62. data/app/views/decidim/admin/managed_users/new.html.erb +47 -0
  63. data/app/views/decidim/admin/managed_users/promotions/_form.html.erb +3 -0
  64. data/app/views/decidim/admin/managed_users/promotions/new.html.erb +21 -0
  65. data/app/views/decidim/admin/moderations/index.html.erb +4 -4
  66. data/app/views/decidim/admin/participatory_process_copies/_form.html.erb +1 -1
  67. data/app/views/decidim/admin/participatory_process_user_roles/edit.html.erb +1 -1
  68. data/app/views/decidim/admin/participatory_processes/_form.html.erb +13 -8
  69. data/app/views/decidim/admin/participatory_processes/index.html.erb +1 -1
  70. data/app/views/decidim/admin/scope_types/_form.html.erb +7 -0
  71. data/app/views/decidim/admin/scope_types/edit.html.erb +13 -0
  72. data/app/views/decidim/admin/scope_types/index.html.erb +40 -0
  73. data/app/views/decidim/admin/scope_types/new.html.erb +13 -0
  74. data/app/views/decidim/admin/scopes/_form.html.erb +12 -2
  75. data/app/views/decidim/admin/scopes/index.html.erb +19 -7
  76. data/app/views/decidim/admin/scopes/new.html.erb +1 -1
  77. data/app/views/decidim/admin/users/_form.html.erb +4 -0
  78. data/app/views/decidim/admin/users/index.html.erb +2 -0
  79. data/app/views/layouts/decidim/admin/newsletters.erb +1 -1
  80. data/app/views/layouts/decidim/admin/pages.html.erb +1 -1
  81. data/app/views/layouts/decidim/admin/participatory_process.html.erb +4 -4
  82. data/app/views/layouts/decidim/admin/participatory_process_groups.html.erb +1 -1
  83. data/app/views/layouts/decidim/admin/settings.html.erb +4 -1
  84. data/app/views/layouts/decidim/admin/users.html.erb +8 -3
  85. data/config/i18n-tasks.yml +2 -1
  86. data/config/locales/ca.yml +80 -3
  87. data/config/locales/en.yml +82 -2
  88. data/config/locales/es.yml +80 -3
  89. data/config/locales/eu.yml +44 -7
  90. data/config/locales/fi.yml +0 -7
  91. data/config/locales/fr.yml +21 -6
  92. data/config/locales/it.yml +0 -10
  93. data/config/locales/nl.yml +1 -1
  94. data/config/locales/pl.yml +7 -0
  95. data/config/routes.rb +24 -11
  96. data/lib/decidim/admin/engine.rb +6 -3
  97. data/lib/decidim/admin/test/manage_attachments_examples.rb +77 -79
  98. metadata +56 -9
  99. data/app/views/decidim/admin/participatory_processes/show.html.erb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c0d4b42e8b84fba4a3a14ccad8d9c70eed4f10d
4
- data.tar.gz: af8756ad81565a4344864c15991586ec9dfcaf07
3
+ metadata.gz: 516f2d4eb6dd6d58c1f0be4f006e82b9a861dfa2
4
+ data.tar.gz: 6efae3c2a6f0ad25183ce8b83614a4e60c3dbc30
5
5
  SHA512:
6
- metadata.gz: b8fa320e0f63c0fcbf30e1f93e6f10955e53aa38c33f18f37b9acbee05f67e583ee91f9d9b2542d90f59178175e5f7eb80930c2c26c7e763091f9fdc9162cbe1
7
- data.tar.gz: b76ae9721bf791470141d73c29c720c37791843156c8d9bc26cf536d5c48486e3be3208b3a64e8a956780b7f2e3c4d7cd9898e079dd9c1397dd86908b6e976da
6
+ metadata.gz: b527b5374e8b45bd49ba6ecbbee30178fe2d05af25ab7b9e19ec44a9cc3b8ebe0f1908c4d7b73402ec7d4f814cd500e9746ca98a9f2a28d79656dd49b002d316
7
+ data.tar.gz: 558e8cb6200ff1e907163b9e3d1922994cb4437a5ae937006cb2acd44f80c0199f9ac24901a68a170b1ffa15d5133be4190a2d0d9c8f4412ecabb0b229e79016
@@ -8,6 +8,9 @@
8
8
  // = require foundation-datepicker
9
9
  // = require form_datepicker
10
10
  // = require moment.min
11
+ // = require ./select2
12
+ // = require ./scopes
13
+ // = require ./participatory_processes
11
14
  // = require_self
12
15
 
13
16
  window.Decidim = window.Decidim || {};
@@ -0,0 +1,12 @@
1
+ $(() => {
2
+ const $participatoryProcessScopeEnabled = $('#participatory_process_scopes_enabled');
3
+ const $participatoryProcessScopeId = $("#participatory_process_scope_id");
4
+
5
+ if ($('.edit_participatory_process').length > 0) {
6
+ $participatoryProcessScopeEnabled.on('change', (event) => {
7
+ const checked = event.target.checked;
8
+ $participatoryProcessScopeId.attr("disabled", !checked);
9
+ })
10
+ $participatoryProcessScopeId.attr("disabled", !$participatoryProcessScopeEnabled.prop('checked'));
11
+ }
12
+ });
@@ -0,0 +1,20 @@
1
+ $(() => {
2
+ const selectedLang = $("html").attr('lang') || 'en';
3
+ $(".select2").each(function(index, select) {
4
+ let $element = $(select);
5
+ let options = {
6
+ language: selectedLang,
7
+ multiple: $element.attr("multiple")==="multiple",
8
+ width: "100%",
9
+ allowClear: true
10
+ };
11
+ if ($element.data("remote-path")) {
12
+ options.ajax = {
13
+ url: $element.data("remote-path"),
14
+ delay: 250,
15
+ cache: true
16
+ };
17
+ }
18
+ $element.select2(options);
19
+ });
20
+ });
@@ -0,0 +1,8 @@
1
+ // = require select2
2
+ // = require select2_locale_es
3
+ // = require select2_locale_eu
4
+ // = require select2_locale_ca
5
+ // = require select2_locale_fi
6
+ // = require select2_locale_fr
7
+ // = require select2_locale_it
8
+ // = require select2_locale_nl
@@ -10,6 +10,8 @@
10
10
  @import "foundation";
11
11
  @include foundation-everything();
12
12
 
13
+ @import "select2";
14
+ @import "plugins/select2";
13
15
  @import "plugins/foundation-datepicker";
14
16
 
15
17
  @import "modules/modules";
@@ -2,4 +2,4 @@
2
2
  td:first-child{
3
3
  padding-left: 20px
4
4
  }
5
- }
5
+ }
@@ -33,4 +33,4 @@ body.login{
33
33
  padding: $global-padding;
34
34
  }
35
35
  }
36
- }
36
+ }
@@ -9,4 +9,4 @@
9
9
 
10
10
  .icon--move {
11
11
  vertical-align: middle;
12
- }
12
+ }
@@ -23,6 +23,9 @@
23
23
  @include breakpoint(mediumlarge){
24
24
  float: right;
25
25
  }
26
+ &:not(:first-child){
27
+ margin-right: 1rem;
28
+ }
26
29
  }
27
30
 
28
31
 
@@ -23,7 +23,6 @@
23
23
  }
24
24
  }
25
25
 
26
-
27
26
  .has-process-title .callout-wrapper{
28
27
  @include breakpoint(large){
29
28
  padding-top: $process-title-height;
@@ -1,3 +1,5 @@
1
+ $card-padding-small: 1rem;
2
+
1
3
  .card-title{
2
4
  @include smallcaps;
3
5
  font-size: 1rem;
@@ -27,3 +29,48 @@
27
29
  display: block;
28
30
  }
29
31
  }
32
+
33
+ .card--list__item{
34
+ display: flex;
35
+ align-items: center;
36
+ padding-left: $card-padding-small;
37
+ .card--list--mini &{
38
+ padding-left: $card-padding-small;
39
+ }
40
+ @include breakpoint(medium){
41
+ padding-left: $card-padding;
42
+ }
43
+ }
44
+
45
+ .card--list__icon{
46
+ display: none;
47
+ fill: $anchor-color;
48
+ @include breakpoint(medium){
49
+ margin-right: 1rem;
50
+ display: block;
51
+ width: 30px;
52
+ height: 30px;
53
+ flex-shrink: 0;
54
+ }
55
+ }
56
+
57
+ .card--list__text{
58
+ flex-grow: 1;
59
+ flex-shrink: 1;
60
+ display: inline-flex;
61
+ overflow: hidden;
62
+ align-items: center;
63
+ padding: 1rem 1rem 1rem 0;
64
+ .card--list--mini &{
65
+ padding: .5rem .5rem .5rem 0;
66
+ }
67
+ .author{
68
+ margin-top: .3rem;
69
+ margin-right: 1rem;
70
+ }
71
+ }
72
+
73
+ .card--list__heading{
74
+ margin-bottom: 0;
75
+ display: block;
76
+ }
@@ -74,13 +74,13 @@ $process-title-height: 3rem;
74
74
  }
75
75
 
76
76
 
77
- .process-title{
77
+ .process-title {
78
78
  @include breakpoint(large){
79
79
  margin-bottom: $process-title-height;
80
80
  }
81
81
  }
82
82
 
83
- .process-title-content{
83
+ .process-title-content {
84
84
  @include breakpoint(large){
85
85
  position: absolute;
86
86
  left: 120px;
@@ -16,4 +16,4 @@
16
16
 
17
17
  .text-info{
18
18
  color: $secondary;
19
- }
19
+ }
@@ -0,0 +1,27 @@
1
+ .select2-container {
2
+ width: 100%;
3
+ &.select2 {
4
+ margin-bottom: 1.5rem;
5
+ }
6
+ .select2-dropdown {
7
+ box-shadow: inset 0 -1px 2px rgba(26, 24, 29, 0.1);
8
+ border-color: #eee;
9
+ }
10
+ .select2-selection {
11
+ box-shadow: inset 0 1px 2px rgba(26, 24, 29, 0.1);
12
+ border-color: #eee;
13
+ }
14
+ .select2-selection--single {
15
+ margin-top: 5px;
16
+ height: 48px;
17
+ .select2-selection__rendered {
18
+ line-height: 46px;
19
+ padding-right: 23px;
20
+ font-weight: normal;
21
+ }
22
+ .select2-selection__arrow {
23
+ height: 54px;
24
+ right: 4px;
25
+ }
26
+ }
27
+ }
@@ -5,4 +5,4 @@
5
5
  &.is-expanded{
6
6
  display: block;
7
7
  }
8
- }
8
+ }
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic to close a current impersonation session.
6
+ class CloseSessionManagedUser < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # user - The user impersonated.
10
+ # current_user - The current user doing the impersonation.
11
+ def initialize(user, current_user)
12
+ @user = user
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 impersonation is not valid.
20
+ #
21
+ # Returns nothing.
22
+ def call
23
+ return broadcast(:invalid) unless impersonation_log.present?
24
+
25
+ close_session
26
+
27
+ broadcast(:ok)
28
+ end
29
+
30
+ attr_reader :current_user, :user
31
+
32
+ private
33
+
34
+ def impersonation_log
35
+ @impersonation_log ||= Decidim::ImpersonationLog.where(admin: current_user, user: user).active.first
36
+ end
37
+
38
+ def close_session
39
+ impersonation_log.ended_at = Time.current
40
+ impersonation_log.save!
41
+ end
42
+ end
43
+ end
44
+ end
@@ -38,7 +38,8 @@ module Decidim
38
38
  manifest_name: manifest.name,
39
39
  name: form.name,
40
40
  participatory_process: participatory_process,
41
- settings: @form.settings,
41
+ settings: form.settings,
42
+ default_step_settings: form.default_step_settings,
42
43
  step_settings: form.step_settings
43
44
  )
44
45
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic to create a new managed user in the
6
+ # admin panel.
7
+ class CreateManagedUser < Rectify::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # form - A form object with the params.
11
+ def initialize(form)
12
+ @form = form
13
+ end
14
+
15
+ # Executes the command. Broadcasts these events:
16
+ #
17
+ # - :ok when everything is valid.
18
+ # - :invalid if the form wasn't valid and we couldn't proceed.
19
+ #
20
+ # Returns nothing.
21
+ def call
22
+ return broadcast(:invalid) if form.invalid?
23
+
24
+ transaction do
25
+ create_managed_user
26
+ raise ActiveRecord::Rollback unless authorized_user?
27
+ end
28
+
29
+ broadcast(:ok)
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :form, :user
35
+
36
+ def create_managed_user
37
+ @user = Decidim::User.create!(
38
+ name: form.name,
39
+ organization: form.current_organization,
40
+ admin: false,
41
+ managed: true,
42
+ comments_notifications: true,
43
+ replies_notifications: true,
44
+ tos_agreement: true
45
+ )
46
+ end
47
+
48
+ def authorized_user?
49
+ form.authorization.user = @user
50
+ AuthorizeUser.call(form.authorization) do
51
+ on(:ok) do
52
+ return true
53
+ end
54
+ on(:invalid) do
55
+ return false
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -7,8 +7,10 @@ module Decidim
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
10
- def initialize(form)
10
+ # parent_scope - A parent scope for the scope to be created
11
+ def initialize(form, parent_scope = nil)
11
12
  @form = form
13
+ @parent_scope = parent_scope
12
14
  end
13
15
 
14
16
  # Executes the command. Broadcasts these events:
@@ -31,7 +33,10 @@ module Decidim
31
33
  def create_scope
32
34
  Scope.create!(
33
35
  name: form.name,
34
- organization: form.organization
36
+ organization: form.organization,
37
+ code: form.code,
38
+ scope_type: form.scope_type,
39
+ parent: @parent_scope
35
40
  )
36
41
  end
37
42
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic when creating a scope type.
6
+ class CreateScopeType < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # form - A form object with the params.
10
+ def initialize(form)
11
+ @form = form
12
+ end
13
+
14
+ # Executes the command. Broadcasts these events:
15
+ #
16
+ # - :ok when everything is valid.
17
+ # - :invalid if the form wasn't valid and we couldn't proceed.
18
+ #
19
+ # Returns nothing.
20
+ def call
21
+ return broadcast(:invalid) if form.invalid?
22
+
23
+ create_scope_type
24
+ broadcast(:ok)
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :form
30
+
31
+ def create_scope_type
32
+ ScopeType.create!(
33
+ name: form.name,
34
+ organization: form.organization,
35
+ plural: form.plural
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Admin
5
+ # A command with all the business logic to impersonate a managed user.
6
+ class ImpersonateManagedUser < Rectify::Command
7
+ # Public: Initializes the command.
8
+ #
9
+ # form - The form with the authorization info
10
+ # user - The user to impersonate
11
+ # current_user - The current user doing the impersonation.
12
+ def initialize(form, user, current_user)
13
+ @form = form
14
+ @user = user
15
+ @current_user = current_user
16
+ end
17
+
18
+ # Executes the command. Broadcasts these events:
19
+ #
20
+ # - :ok when everything is valid.
21
+ # - :invalid if the impersonation is not valid.
22
+ #
23
+ # Returns nothing.
24
+ def call
25
+ return broadcast(:invalid) if !user.managed? || !authorization_valid?
26
+
27
+ create_impersonation_log
28
+ enque_expire_job
29
+
30
+ broadcast(:ok)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :current_user, :user, :form
36
+
37
+ def authorization_valid?
38
+ return false unless form.valid?
39
+ Decidim::Authorization.where(
40
+ user: user,
41
+ name: form.authorization.handler_name,
42
+ unique_id: form.authorization.unique_id
43
+ ).any?
44
+ end
45
+
46
+ def create_impersonation_log
47
+ Decidim::ImpersonationLog.create!(
48
+ admin: current_user,
49
+ user: user,
50
+ started_at: Time.current
51
+ )
52
+ end
53
+
54
+ def enque_expire_job
55
+ Decidim::Admin::ExpireImpersonationJob
56
+ .set(wait: Decidim::ImpersonationLog::SESSION_TIME_IN_MINUTES.minutes)
57
+ .perform_later(user, current_user)
58
+ end
59
+ end
60
+ end
61
+ end