decidim-system 0.19.1 → 0.23.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-system might be problematic. Click here for more details.

Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/system/application.js.es6 +3 -1
  3. data/app/assets/stylesheets/decidim/system/_forms.scss +36 -0
  4. data/app/assets/stylesheets/decidim/system/_foundation_and_overrides.scss +1 -0
  5. data/app/assets/stylesheets/decidim/system/_sidebar.scss +0 -2
  6. data/app/assets/stylesheets/decidim/system/application.scss +1 -0
  7. data/app/commands/decidim/system/create_default_content_blocks.rb +1 -1
  8. data/app/commands/decidim/system/create_oauth_application.rb +37 -0
  9. data/app/commands/decidim/system/destroy_oauth_application.rb +39 -0
  10. data/app/commands/decidim/system/register_organization.rb +3 -1
  11. data/app/commands/decidim/system/update_oauth_application.rb +39 -0
  12. data/app/commands/decidim/system/update_organization.rb +5 -0
  13. data/app/controllers/decidim/system/oauth_applications_controller.rb +84 -0
  14. data/app/controllers/decidim/system/organizations_controller.rb +9 -1
  15. data/app/forms/decidim/system/file_upload_settings_form.rb +70 -0
  16. data/app/forms/decidim/system/oauth_application_form.rb +35 -0
  17. data/app/forms/decidim/system/update_organization_form.rb +33 -0
  18. data/app/views/decidim/system/devise/shared/_links.html.erb +1 -1
  19. data/app/views/decidim/system/oauth_applications/_form.html.erb +26 -0
  20. data/app/views/decidim/system/oauth_applications/edit.html.erb +13 -0
  21. data/app/views/decidim/system/oauth_applications/index.html.erb +41 -0
  22. data/app/views/decidim/system/oauth_applications/new.html.erb +13 -0
  23. data/app/views/decidim/system/oauth_applications/show.html.erb +27 -0
  24. data/app/views/decidim/system/organizations/_file_upload_settings.erb +56 -0
  25. data/app/views/decidim/system/organizations/_omniauth_provider.html.erb +23 -0
  26. data/app/views/decidim/system/organizations/_omniauth_settings.html.erb +11 -0
  27. data/app/views/decidim/system/organizations/_smtp_settings.html.erb +5 -1
  28. data/app/views/decidim/system/organizations/edit.html.erb +2 -0
  29. data/app/views/decidim/system/organizations/new.html.erb +2 -0
  30. data/app/views/layouts/decidim/system/_header.html.erb +1 -0
  31. data/app/views/layouts/decidim/system/_js_configuration.html.erb +9 -0
  32. data/app/views/layouts/decidim/system/application.html.erb +2 -0
  33. data/config/locales/am-ET.yml +1 -0
  34. data/config/locales/ar.yml +11 -0
  35. data/config/locales/bg-BG.yml +8 -0
  36. data/config/locales/bg.yml +8 -0
  37. data/config/locales/ca.yml +97 -0
  38. data/config/locales/cs.yml +98 -1
  39. data/config/locales/da-DK.yml +1 -0
  40. data/config/locales/da.yml +1 -0
  41. data/config/locales/de.yml +52 -0
  42. data/config/locales/el-GR.yml +1 -0
  43. data/config/locales/el.yml +98 -0
  44. data/config/locales/en.yml +97 -0
  45. data/config/locales/eo.yml +1 -0
  46. data/config/locales/es-MX.yml +97 -0
  47. data/config/locales/es-PY.yml +97 -0
  48. data/config/locales/es.yml +97 -0
  49. data/config/locales/et-EE.yml +1 -0
  50. data/config/locales/et.yml +1 -0
  51. data/config/locales/fi-plain.yml +97 -0
  52. data/config/locales/fi.yml +97 -0
  53. data/config/locales/fr-CA.yml +173 -0
  54. data/config/locales/fr.yml +97 -0
  55. data/config/locales/ga-IE.yml +1 -0
  56. data/config/locales/hr-HR.yml +1 -0
  57. data/config/locales/hr.yml +1 -0
  58. data/config/locales/hu.yml +18 -0
  59. data/config/locales/is-IS.yml +55 -0
  60. data/config/locales/is.yml +55 -0
  61. data/config/locales/it.yml +23 -1
  62. data/config/locales/ja-JP.yml +101 -0
  63. data/config/locales/ja.yml +173 -0
  64. data/config/locales/ko-KR.yml +1 -0
  65. data/config/locales/ko.yml +1 -0
  66. data/config/locales/lt-LT.yml +1 -0
  67. data/config/locales/lt.yml +1 -0
  68. data/config/locales/lv.yml +98 -0
  69. data/config/locales/mt-MT.yml +1 -0
  70. data/config/locales/mt.yml +1 -0
  71. data/config/locales/nl.yml +22 -0
  72. data/config/locales/no.yml +60 -3
  73. data/config/locales/om-ET.yml +1 -0
  74. data/config/locales/pl.yml +86 -21
  75. data/config/locales/pt-BR.yml +1 -1
  76. data/config/locales/pt.yml +47 -24
  77. data/config/locales/ro-RO.yml +98 -0
  78. data/config/locales/sk-SK.yml +90 -0
  79. data/config/locales/sk.yml +95 -0
  80. data/config/locales/sl.yml +51 -0
  81. data/config/locales/so-SO.yml +1 -0
  82. data/config/locales/sr-CS.yml +26 -0
  83. data/config/locales/sv.yml +64 -0
  84. data/config/locales/ti-ER.yml +1 -0
  85. data/config/locales/vi-VN.yml +1 -0
  86. data/config/locales/vi.yml +1 -0
  87. data/config/locales/zh-CN.yml +173 -0
  88. data/config/locales/zh-TW.yml +1 -0
  89. data/config/routes.rb +2 -0
  90. data/lib/decidim/system/engine.rb +5 -0
  91. data/lib/decidim/system/test/factories.rb +11 -0
  92. data/lib/decidim/system/version.rb +1 -1
  93. metadata +65 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 441f74bf9e266efc84367e6f448c90674dc636f8a27486af0d73f7016bce6dfe
4
- data.tar.gz: 7f8f565f3cec64fc28377c077fe29f5ad9e9899c9b8d2d9b9d1cb2246e3a1189
3
+ metadata.gz: 5faf98a3152e536e389d9fb86ae7e604b2bc56bada412fdb799fa4371544839e
4
+ data.tar.gz: 3a94d7d2a997d7996ac5869cdc589770b2925eaf409f4c5c8029eeea616a1fb2
5
5
  SHA512:
6
- metadata.gz: 4be3847813af41392dc4796c29968e099ff7150fa0bc92c400ee30fe216172264974a31f71f156db030def8b5884cf4a861d8e7c13f28ea345314bbe6cbdbf64
7
- data.tar.gz: 479d45242016df2e19fce5ee09ac65c50eb16b01565ef4108cfa02423ac8d050b8d9ec68b0dbd812f7b64564c6405654d90bea68256de8f11e00810b6b56bdbf
6
+ metadata.gz: 76c65b21024ee256684a009fe7791662f1099165baaa2c35ca68c8e1bc9ef8a6ad284a5f6b432fd3a07eea2e46f5cec0adf29c84ae05ae09bec27a32d467bd97
7
+ data.tar.gz: 417789586417f17361ba78e29fe554c7c121d8a178aba6cdb5470ff3bfaa9440fa52757f2d71f9ee9263e8b498477d0b7808c52a543b60b8d8676fd3686ce178
@@ -1,8 +1,10 @@
1
- // = require jquery
1
+ // = require jquery3
2
2
  // = require foundation
3
3
  // = require rails-ujs
4
4
  // = require decidim/editor
5
+ // = require decidim/input_tags
5
6
  // = require_self
7
+ // = require decidim/configuration
6
8
 
7
9
  $(() => {
8
10
  $(document).foundation();
@@ -0,0 +1,36 @@
1
+ @import "tagsinput";
2
+
3
+ $tag-padding: .25rem;
4
+ $tag-margin: .2rem;
5
+
6
+ .input__tag{
7
+ background-color: rgba($medium-gray, .5);
8
+ border-radius: $input-radius;
9
+ padding: $tag-padding;
10
+ display: inline-block;
11
+ cursor: pointer;
12
+ -webkit-user-select: none;
13
+ -moz-user-select: none;
14
+ -ms-user-select: none;
15
+ user-select: none;
16
+ }
17
+
18
+ // Override defaults
19
+ .bootstrap-tagsinput{
20
+ margin-bottom: $form-spacing;
21
+
22
+ // Use foundation precalculated methods to get accurate form css properties
23
+ $height: ($input-font-size * unitless-calc($input-line-height)) + (get-side($input-padding, 'top') + get-side($input-padding, 'bottom'));
24
+ $tag-line-height: rem-calc(22);
25
+ $span-height: ($input-font-size * unitless-calc($tag-line-height)) + (get-side($tag-padding, 'top') + get-side($tag-padding, 'bottom')) - rem-calc(1);
26
+
27
+ width: 100%;
28
+ min-height: $height;
29
+ padding-bottom: $tag-margin / 4;
30
+
31
+ .tag{
32
+ color: inherit;
33
+ margin-right: 0; // fix whitespace
34
+ margin-bottom: $tag-margin;
35
+ }
36
+ }
@@ -2,6 +2,7 @@
2
2
 
3
3
  @import "settings";
4
4
  @import "foundation";
5
+ @import "foundation-overrides/components/button-group";
5
6
 
6
7
  // If you'd like to include motion-ui the foundation-rails gem comes prepackaged with it, uncomment the 3 @imports, if you are not using the gem you need to install the motion-ui sass package.
7
8
  //
@@ -1,5 +1,4 @@
1
1
  @mixin menu-title{
2
- text-transform: uppercase;
3
2
  letter-spacing: 5px;
4
3
  }
5
4
 
@@ -48,7 +47,6 @@
48
47
  }
49
48
 
50
49
  li{
51
- text-transform: uppercase;
52
50
  font-weight: bold;
53
51
  font-size: .9em;
54
52
  border-left: 2px solid transparent;
@@ -4,6 +4,7 @@
4
4
  @import "sidebar";
5
5
  @import "tables";
6
6
  @import "actions";
7
+ @import "forms";
7
8
  @import "decidim/editor";
8
9
  @import "decidim/utils/fontface";
9
10
 
@@ -24,7 +24,7 @@ module Decidim
24
24
  Decidim::ContentBlock.create(
25
25
  decidim_organization_id: organization.id,
26
26
  weight: weight,
27
- scope: :homepage,
27
+ scope_name: :homepage,
28
28
  manifest_name: manifest.name,
29
29
  published_at: Time.current
30
30
  )
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module System
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
+ organization: @form.current_organization,
21
+ name: @form.name,
22
+ decidim_organization_id: @form.decidim_organization_id,
23
+ organization_name: @form.organization_name,
24
+ organization_url: @form.organization_url,
25
+ organization_logo: @form.organization_logo,
26
+ redirect_uri: @form.redirect_uri,
27
+ scopes: "public"
28
+ )
29
+
30
+ broadcast(:ok, @application)
31
+ rescue ActiveRecord::RecordInvalid
32
+ @form.errors.add(:organization_logo, @application.errors[:organization_logo]) if @application.errors.include? :organization_logo
33
+ broadcast(:invalid)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module System
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
@@ -57,8 +57,10 @@ module Decidim
57
57
  badges_enabled: true,
58
58
  user_groups_enabled: true,
59
59
  default_locale: form.default_locale,
60
+ omniauth_settings: form.encrypted_omniauth_settings,
60
61
  smtp_settings: form.encrypted_smtp_settings,
61
- send_welcome_notification: true
62
+ send_welcome_notification: true,
63
+ file_upload_settings: form.file_upload_settings.final
62
64
  )
63
65
  end
64
66
 
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module System
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
+
21
+ @application = Decidim.traceability.update!(
22
+ @application,
23
+ @user,
24
+ name: @form.name,
25
+ decidim_organization_id: @form.decidim_organization_id,
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
@@ -27,6 +27,9 @@ module Decidim
27
27
  save_organization
28
28
  end
29
29
 
30
+ # Ensure the runtime settings are updated
31
+ OrganizationSettings.reload(organization)
32
+
30
33
  broadcast(:ok)
31
34
  rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
32
35
  broadcast(:invalid)
@@ -47,7 +50,9 @@ module Decidim
47
50
  organization.force_users_to_authenticate_before_access_organization = form.force_users_to_authenticate_before_access_organization
48
51
  organization.available_authorizations = form.clean_available_authorizations
49
52
  organization.users_registration_mode = form.users_registration_mode
53
+ organization.omniauth_settings = form.encrypted_omniauth_settings
50
54
  organization.smtp_settings = form.encrypted_smtp_settings
55
+ organization.file_upload_settings = form.file_upload_settings.final
51
56
 
52
57
  organization.save!
53
58
  end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module System
5
+ # Controller that allows managing OAuth applications at the admin panel.
6
+ #
7
+ class OAuthApplicationsController < Decidim::System::ApplicationController
8
+ helper Decidim::Admin::AttributesDisplayHelper
9
+
10
+ def index
11
+ @oauth_applications = collection.page(params[:page]).per(15)
12
+ end
13
+
14
+ def show
15
+ @oauth_application = collection.find(params[:id])
16
+ end
17
+
18
+ def new
19
+ @form = form(OAuthApplicationForm).instance
20
+ end
21
+
22
+ def create
23
+ @form = form(OAuthApplicationForm).from_params(params)
24
+
25
+ CreateOAuthApplication.call(@form) do
26
+ on(:ok) do
27
+ flash[:notice] = I18n.t("oauth_applications.create.success", scope: "decidim.system")
28
+ redirect_to action: :index
29
+ end
30
+
31
+ on(:invalid) do
32
+ flash.now[:alert] = I18n.t("oauth_applications.create.error", scope: "decidim.system")
33
+ render :new
34
+ end
35
+ end
36
+ end
37
+
38
+ def edit
39
+ @oauth_application = collection.find(params[:id])
40
+ @form = form(OAuthApplicationForm).from_model(@oauth_application)
41
+ end
42
+
43
+ def update
44
+ @oauth_application = collection.find(params[:id])
45
+ @form = form(OAuthApplicationForm).from_params({ organization_logo: @oauth_application.organization_logo }.merge(params.to_unsafe_h))
46
+
47
+ UpdateOAuthApplication.call(@oauth_application, @form, current_user) do
48
+ on(:ok) do |_application|
49
+ flash[:notice] = I18n.t("oauth_applications.update.success", scope: "decidim.system")
50
+ redirect_to action: :index
51
+ end
52
+
53
+ on(:invalid) do |application|
54
+ @oauth_application = application
55
+ flash.now[:error] = I18n.t("oauth_applications.update.error", scope: "decidim.system")
56
+ render action: :edit
57
+ end
58
+ end
59
+ end
60
+
61
+ def destroy
62
+ @oauth_application = collection.find(params[:id])
63
+
64
+ DestroyOAuthApplication.call(@oauth_application, current_user) do
65
+ on(:ok) do
66
+ flash[:notice] = I18n.t("oauth_applications.destroy.success", scope: "decidim.system")
67
+ redirect_to action: :index
68
+ end
69
+
70
+ on(:invalid) do
71
+ flash.now[:error] = I18n.t("oauth_applications.destroy.error", scope: "decidim.system")
72
+ redirect_to :back
73
+ end
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ def collection
80
+ @collection ||= Decidim::OAuthApplication.all.includes([:organization])
81
+ end
82
+ end
83
+ end
84
+ end
@@ -5,10 +5,12 @@ module Decidim
5
5
  # Controller to manage Organizations (tenants).
6
6
  #
7
7
  class OrganizationsController < Decidim::System::ApplicationController
8
- helper_method :current_organization
8
+ helper_method :current_organization, :provider_enabled?
9
+ helper Decidim::OmniauthHelper
9
10
 
10
11
  def new
11
12
  @form = form(RegisterOrganizationForm).instance
13
+ @form.file_upload_settings = form(FileUploadSettingsForm).from_model({})
12
14
  end
13
15
 
14
16
  def create
@@ -56,12 +58,18 @@ module Decidim
56
58
  end
57
59
  end
58
60
 
61
+ private
62
+
59
63
  # The current organization for the request.
60
64
  #
61
65
  # Returns an Organization.
62
66
  def current_organization
63
67
  @organization
64
68
  end
69
+
70
+ def provider_enabled?(provider)
71
+ Rails.application.secrets.dig(:omniauth, provider, :enabled)
72
+ end
65
73
  end
66
74
  end
67
75
  end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module System
5
+ # A form object used to update organization file upload settings from the
6
+ # system dashboard.
7
+ #
8
+ class FileUploadSettingsForm < Form
9
+ include JsonbAttributes
10
+
11
+ mimic :organization_file_uploads
12
+
13
+ attribute :allowed_file_extensions, Hash[Symbol => String]
14
+ attribute :allowed_content_types, Hash[Symbol => String]
15
+ attribute :maximum_file_size, Hash[Symbol => Float]
16
+
17
+ def map_model(settings_hash)
18
+ settings_hash = begin
19
+ if settings_hash.is_a?(Hash)
20
+ default_settings.deep_merge(settings_hash.deep_stringify_keys)
21
+ else
22
+ default_settings
23
+ end
24
+ end
25
+
26
+ attribute_set.each do |attr|
27
+ key = attr.name.to_s
28
+ next unless settings_hash.has_key?(key)
29
+
30
+ # For the view, the array values need to be in comma separated format
31
+ # in order for them to work correctly with the tags inputs.
32
+ value = Rectify::FormAttribute.new(attr).value_from(
33
+ settings_hash[key]
34
+ )
35
+ value.each do |k, v|
36
+ value[k] = v.join(",") if v.is_a?(Array)
37
+ end
38
+
39
+ self[key] = value
40
+ end
41
+ end
42
+
43
+ # This turns the attributes passed from the view into the final
44
+ # configuration array. Due to the UI component used for the array values,
45
+ # those values need to be handled as a single comma separated string in
46
+ # the view layer. Before we save those attributes, they need to be
47
+ # converted into arrays which is what this method does.
48
+ def final
49
+ csv_attributes = [:allowed_file_extensions, :allowed_content_types]
50
+ attributes.tap do |attr|
51
+ csv_attributes.each do |key|
52
+ attr[key] = csv_array_setting(attr[key])
53
+ end
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def default_settings
60
+ Decidim::OrganizationSettings.default(:upload)
61
+ end
62
+
63
+ def csv_array_setting(original)
64
+ original.map do |key, value|
65
+ [key, value.split(",")]
66
+ end.to_h
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module System
5
+ # The form that validates the data to construct a valid OAuthApplication.
6
+ class OAuthApplicationForm < Decidim::Form
7
+ include Decidim::HasUploadValidations
8
+
9
+ mimic :oauth_application
10
+
11
+ attribute :name, String
12
+ attribute :decidim_organization_id, Integer
13
+ attribute :organization_name, String
14
+ attribute :organization_url, String
15
+ attribute :organization_logo
16
+ attribute :redirect_uri, String
17
+
18
+ validates :name, :redirect_uri, :decidim_organization_id, :organization_name, :organization_url, :organization_logo, presence: true
19
+ validates :organization_logo, passthru: { to: Decidim::OAuthApplication }
20
+ validate :redirect_uri_is_ssl
21
+
22
+ alias organization current_organization
23
+
24
+ private
25
+
26
+ def redirect_uri_is_ssl
27
+ return if redirect_uri.blank?
28
+
29
+ uri = URI.parse(redirect_uri)
30
+
31
+ errors.add(:redirect_uri, :must_be_ssl) if uri.host != "localhost" && uri.scheme != "https"
32
+ end
33
+ end
34
+ end
35
+ end