decidim-core 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/decidim/extras/_add_comments.scss +9 -0
  3. data/app/assets/stylesheets/decidim/extras/_label-required.scss +3 -0
  4. data/app/assets/stylesheets/decidim/extras/_reference.scss +3 -0
  5. data/app/assets/stylesheets/decidim/extras/_social_icons_mini.scss +10 -0
  6. data/app/commands/decidim/invite_user.rb +1 -1
  7. data/app/commands/decidim/update_account.rb +2 -6
  8. data/app/constraints/decidim/current_feature.rb +11 -18
  9. data/app/constraints/decidim/current_participatory_process.rb +35 -0
  10. data/app/controllers/concerns/decidim/devise_controllers.rb +1 -0
  11. data/app/controllers/concerns/decidim/locale_switcher.rb +2 -2
  12. data/app/controllers/concerns/decidim/needs_authorization.rb +1 -2
  13. data/app/controllers/concerns/decidim/needs_organization.rb +1 -2
  14. data/app/controllers/concerns/decidim/needs_participatory_process.rb +19 -10
  15. data/app/controllers/decidim/account_controller.rb +13 -9
  16. data/app/controllers/decidim/application_controller.rb +3 -8
  17. data/app/controllers/decidim/devise/registrations_controller.rb +0 -1
  18. data/app/controllers/decidim/devise/sessions_controller.rb +0 -1
  19. data/app/controllers/decidim/errors_controller.rb +15 -0
  20. data/app/controllers/decidim/features/base_controller.rb +1 -0
  21. data/app/controllers/decidim/participatory_process_groups_controller.rb +6 -2
  22. data/app/controllers/decidim/participatory_process_steps_controller.rb +1 -0
  23. data/app/controllers/decidim/participatory_processes_controller.rb +3 -3
  24. data/app/helpers/decidim/application_helper.rb +3 -0
  25. data/app/helpers/decidim/feature_path_helper.rb +35 -0
  26. data/app/helpers/decidim/feature_reference_helper.rb +4 -2
  27. data/app/helpers/decidim/icon_helper.rb +20 -0
  28. data/app/helpers/decidim/menu_helper.rb +1 -1
  29. data/app/helpers/decidim/participatory_process_helper.rb +0 -14
  30. data/app/models/decidim/feature.rb +9 -1
  31. data/app/models/decidim/static_page.rb +1 -0
  32. data/app/models/decidim/user.rb +2 -0
  33. data/app/queries/decidim/highlighted_participatory_processes.rb +1 -1
  34. data/app/views/decidim/account/show.html.erb +1 -3
  35. data/app/views/decidim/devise/shared/_omniauth_buttons.html.erb +1 -1
  36. data/app/views/decidim/devise/shared/_omniauth_buttons_mini.html.erb +20 -0
  37. data/app/views/{pages/500.html.erb → decidim/errors/internal_server_error.html.erb} +0 -0
  38. data/app/views/{pages/404.html.erb → decidim/errors/not_found.html.erb} +1 -1
  39. data/app/views/decidim/shared/_login_modal.html.erb +4 -0
  40. data/app/views/decidim/shared/_share_modal.html.erb +1 -1
  41. data/app/views/layouts/decidim/_process_header.html.erb +2 -2
  42. data/config/i18n-tasks.yml +2 -0
  43. data/config/initializers/invisible_captcha.rb +2 -2
  44. data/config/locales/ca.yml +14 -8
  45. data/config/locales/en.yml +13 -7
  46. data/config/locales/es.yml +13 -7
  47. data/config/locales/eu.yml +0 -7
  48. data/config/locales/fi.yml +0 -7
  49. data/config/locales/fr.yml +4 -11
  50. data/config/locales/it.yml +0 -7
  51. data/config/locales/nl.yml +0 -7
  52. data/config/routes.rb +2 -8
  53. data/db/migrate/20160817115213_devise_create_decidim_users.rb +6 -6
  54. data/db/migrate/20160920140207_devise_invitable_add_to_decidim_users.rb +9 -9
  55. data/db/seeds.rb +2 -2
  56. data/lib/decidim/core.rb +25 -1
  57. data/lib/decidim/core/engine.rb +0 -1
  58. data/lib/decidim/core/test.rb +1 -0
  59. data/lib/decidim/core/test/factories.rb +11 -6
  60. data/lib/decidim/core/test/shared_examples/comments_examples.rb +69 -66
  61. data/lib/decidim/core/test/shared_examples/errors.rb +21 -0
  62. data/lib/decidim/core/test/shared_examples/has_reference.rb +18 -2
  63. data/lib/decidim/core/test/shared_examples/manage_moderations_examples.rb +2 -2
  64. data/lib/decidim/core/version.rb +1 -1
  65. data/lib/decidim/devise_failure_app.rb +1 -1
  66. data/lib/decidim/form_builder.rb +89 -5
  67. data/lib/decidim/has_reference.rb +3 -15
  68. data/lib/decidim/notifiable.rb +22 -0
  69. data/lib/devise/models/decidim_validatable.rb +4 -4
  70. metadata +41 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8eba11b2c48395aa9194428d085bede3ceddc066
4
- data.tar.gz: 64377d579d64f932000db763f1eddb834b827569
3
+ metadata.gz: 8f13f38a692e1e440b837466cfef145041b4731a
4
+ data.tar.gz: 23544d83481adcedf009ee8696d6d3369b900fd3
5
5
  SHA512:
6
- metadata.gz: 68ef82ba758d77eac53a22010784d39af4ee4ca28a732596609a3f5d203d4bb45c7c4a5ea1377945340f125e9aae743a6dfc59a89a7105e6843e70eec06e316c
7
- data.tar.gz: '0485336b9f027af626642657de541ad421e6c6c160699ec7d669a30d655fea485c221a6efcc2b6cca47bd2ebf65ae0c0de985a723738f560b5f29eab2e6d70a3'
6
+ metadata.gz: 6dcf4943c0d07fd5293b1b3a2114b98bfcda43ac5980b9904f26050310d2a2ae9b673ba20cb07ac33696fcdabce843d6b0b0b51bcb9e952078ae716ff88748ff
7
+ data.tar.gz: 47108ee568bbdd48e9a7d2f1ea6f0161edb7c5d76d27d20faa02166ca5dbcdad3036b1f96d7b549de9b9a0171132bce460f2452898d252228685ba9b8e22fc3b
@@ -0,0 +1,9 @@
1
+ .add-comment {
2
+ .remaining-character-count {
3
+ border: 0;
4
+ color: $body-font-color;
5
+ padding: 0.85em 1em;
6
+ vertical-align: middle;
7
+ display: inline-block;
8
+ }
9
+ }
@@ -0,0 +1,3 @@
1
+ .label-required {
2
+ margin-left: 5px;
3
+ }
@@ -0,0 +1,3 @@
1
+ .reference--text-left {
2
+ text-align: left;
3
+ }
@@ -0,0 +1,10 @@
1
+ .button--social--mini {
2
+ padding: 0;
3
+ display: inline-block;
4
+ min-width: 0;
5
+ .button--social__icon {
6
+ border: 0;
7
+ padding: 0.85em 0;
8
+ margin-right: 0;
9
+ }
10
+ }
@@ -36,7 +36,7 @@ module Decidim
36
36
  end
37
37
 
38
38
  def invite_user
39
- @user = Decidim::User.create(
39
+ @user = Decidim::User.new(
40
40
  name: form.name,
41
41
  email: form.email.downcase,
42
42
  organization: form.organization,
@@ -21,7 +21,6 @@ module Decidim
21
21
 
22
22
  if @user.valid?
23
23
  @user.save!
24
- @form.remove_avatar = false
25
24
  broadcast(:ok, @user.unconfirmed_email.present?)
26
25
  else
27
26
  if @user.errors.has_key? :avatar
@@ -39,11 +38,8 @@ module Decidim
39
38
  end
40
39
 
41
40
  def update_avatar
42
- if @form.avatar
43
- @user.avatar = @form.avatar
44
- elsif @form.remove_avatar
45
- @user.remove_avatar = true
46
- end
41
+ @user.avatar = @form.avatar
42
+ @user.remove_avatar = @form.remove_avatar
47
43
  end
48
44
 
49
45
  def update_password
@@ -11,36 +11,29 @@ module Decidim
11
11
  @manifest = manifest
12
12
  end
13
13
 
14
- # Public: Injects the current feature into the environment.
14
+ # Public: Matches the request against a feature and injects it into the
15
+ # environment.
15
16
  #
16
- # request - The request that holds the current feature relevant
17
- # information.
17
+ # request - The request that holds the current feature relevant information.
18
18
  #
19
- # Returns nothing.
19
+ # Returns a true if the request matched, false otherwise
20
20
  def matches?(request)
21
21
  env = request.env
22
- params = request.params
23
22
 
24
- organization = env["decidim.current_organization"]
23
+ return false unless CurrentParticipatoryProcess.new.matches?(request)
25
24
 
26
- @participatory_process = request.env["decidim.current_participatory_process"] ||
27
- organization.participatory_processes.find_by_id(params["participatory_process_id"])
25
+ @participatory_process = env["decidim.current_participatory_process"]
28
26
 
29
- env["decidim.current_participatory_process"] ||= @participatory_process
30
-
31
- feature = detect_current_feature(params)
32
-
33
- return false unless feature
34
-
35
- env["decidim.current_feature"] ||= feature
36
- true
27
+ current_feature(env, request.params) ? true : false
37
28
  end
38
29
 
39
30
  private
40
31
 
41
- def detect_current_feature(params)
42
- return nil unless params["feature_id"]
32
+ def current_feature(env, params)
33
+ env["decidim.current_feature"] ||= detect_current_feature(params)
34
+ end
43
35
 
36
+ def detect_current_feature(params)
44
37
  @participatory_process.features.find do |feature|
45
38
  params["feature_id"] == feature.id.to_s && feature.manifest_name == @manifest.name.to_s
46
39
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class infers the current participatory process we're scoped to by
5
+ # looking at the request parameters and the organization in the request
6
+ # environment, and injects it into the environment.
7
+ class CurrentParticipatoryProcess
8
+ # Public: Matches the request against a participatory process and injects it
9
+ # into the environment.
10
+ #
11
+ # request - The request that holds the participatory process relevant
12
+ # information.
13
+ #
14
+ # Returns a true if the request matched, false otherwise
15
+ def matches?(request)
16
+ env = request.env
17
+
18
+ @organization = env["decidim.current_organization"]
19
+ return false unless @organization
20
+
21
+ current_participatory_process(env, request.params) ? true : false
22
+ end
23
+
24
+ private
25
+
26
+ def current_participatory_process(env, params)
27
+ env["decidim.current_participatory_process"] ||=
28
+ detect_current_participatory_process(params)
29
+ end
30
+
31
+ def detect_current_participatory_process(params)
32
+ @organization.participatory_processes.find_by_id(params["participatory_process_id"])
33
+ end
34
+ end
35
+ end
@@ -22,6 +22,7 @@ module Decidim
22
22
  helper Decidim::ReplaceButtonsHelper
23
23
  helper Decidim::LayoutHelper
24
24
  helper Decidim::MenuHelper
25
+ helper Decidim::OmniauthHelper
25
26
 
26
27
  layout "layouts/decidim/application"
27
28
  end
@@ -46,14 +46,14 @@ module Decidim
46
46
  #
47
47
  # Returns an Array of Strings.
48
48
  def available_locales
49
- @available_locales ||= current_organization.available_locales.map(&:to_s)
49
+ @available_locales ||= current_organization.available_locales
50
50
  end
51
51
 
52
52
  # The default locale of this organization.
53
53
  #
54
54
  # Returns a String with the default locale.
55
55
  def default_locale
56
- @default_locale ||= current_organization.default_locale
56
+ @default_locale ||= (current_organization || Decidim).public_send(:default_locale)
57
57
  end
58
58
  end
59
59
  end
@@ -30,8 +30,7 @@ module Decidim
30
30
  current_settings: try(:current_settings),
31
31
  feature_settings: try(:feature_settings),
32
32
  current_organization: try(:current_organization),
33
- current_feature: try(:current_feature),
34
- current_participatory_process: try(:current_participatory_process)
33
+ current_feature: try(:current_feature)
35
34
  }
36
35
  end
37
36
 
@@ -22,9 +22,8 @@ module Decidim
22
22
 
23
23
  private
24
24
 
25
- # Raises a 404 if no organization is present.
26
25
  def verify_organization
27
- raise ActionController::RoutingError, "Not Found" unless current_organization
26
+ redirect_to decidim_system.root_path unless current_organization
28
27
  end
29
28
  end
30
29
  end
@@ -1,19 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/concern"
4
-
5
3
  module Decidim
6
4
  # This module, when injected into a controller, ensures there's a
7
5
  # Participatory Process available and deducts it from the context.
8
6
  module NeedsParticipatoryProcess
9
- extend ActiveSupport::Concern
7
+ def self.enhance_controller(instance_or_module)
8
+ instance_or_module.class_eval do
9
+ helper_method :current_participatory_process
10
+ end
11
+ end
10
12
 
11
- include NeedsOrganization
13
+ def self.extended(base)
14
+ base.extend NeedsOrganization, InstanceMethods
12
15
 
13
- included do
14
- after_action :verify_participatory_process
15
- helper_method :current_participatory_process
16
+ enhance_controller(base)
17
+ end
18
+
19
+ def self.included(base)
20
+ base.include NeedsOrganization, InstanceMethods
21
+
22
+ enhance_controller(base)
23
+ end
16
24
 
25
+ module InstanceMethods
17
26
  # Public: Finds the current Participatory Process given this controller's
18
27
  # context.
19
28
  #
@@ -24,13 +33,13 @@ module Decidim
24
33
 
25
34
  private
26
35
 
27
- def verify_participatory_process
28
- raise ActionController::RoutingError, "Participatory process not found." unless current_participatory_process
36
+ def ability_context
37
+ super.merge(current_participatory_process: current_participatory_process)
29
38
  end
30
39
 
31
40
  def detect_participatory_process
32
41
  request.env["current_participatory_process"] ||
33
- current_organization.participatory_processes.find_by(id: params[:participatory_process_id] || params[:id])
42
+ current_organization.participatory_processes.find(params[:participatory_process_id] || params[:id])
34
43
  end
35
44
  end
36
45
  end
@@ -15,25 +15,25 @@ module Decidim
15
15
 
16
16
  def update
17
17
  authorize! :update, current_user
18
- @account = form(AccountForm).from_params(params)
18
+ @account = form(AccountForm).from_params(account_params)
19
19
 
20
20
  UpdateAccount.call(current_user, @account) do
21
21
  on(:ok) do |email_is_unconfirmed|
22
- flash.now[:notice] = if email_is_unconfirmed
23
- t("account.update.success_with_email_confirmation", scope: "decidim")
24
- else
25
- t("account.update.success", scope: "decidim")
26
- end
22
+ flash[:notice] = if email_is_unconfirmed
23
+ t("account.update.success_with_email_confirmation", scope: "decidim")
24
+ else
25
+ t("account.update.success", scope: "decidim")
26
+ end
27
27
 
28
28
  bypass_sign_in(current_user)
29
+ redirect_to account_path
29
30
  end
30
31
 
31
32
  on(:invalid) do
32
- flash.now[:alert] = t("account.update.error", scope: "decidim")
33
+ flash[:alert] = t("account.update.error", scope: "decidim")
34
+ render action: :show
33
35
  end
34
36
  end
35
-
36
- render action: :show
37
37
  end
38
38
 
39
39
  def delete
@@ -64,5 +64,9 @@ module Decidim
64
64
  def authorizations
65
65
  @authorizations ||= current_user.authorizations
66
66
  end
67
+
68
+ def account_params
69
+ { avatar: current_user.avatar }.merge(params[:user].to_unsafe_h)
70
+ end
67
71
  end
68
72
  end
@@ -3,8 +3,8 @@
3
3
  module Decidim
4
4
  # The main application controller that inherits from Rails.
5
5
  class ApplicationController < ::DecidimController
6
- include Decidim::NeedsOrganization
7
- include Decidim::LocaleSwitcher
6
+ include NeedsOrganization
7
+ include LocaleSwitcher
8
8
  include NeedsAuthorization
9
9
  include PayloadInfo
10
10
 
@@ -16,6 +16,7 @@ module Decidim
16
16
  helper Decidim::CookiesHelper
17
17
  helper Decidim::AriaSelectedLinkToHelper
18
18
  helper Decidim::MenuHelper
19
+ helper Decidim::FeaturePathHelper
19
20
 
20
21
  # Saves the location before loading each page so we can return to the
21
22
  # right page. If we're on a devise page, we don't want to store that as the
@@ -28,8 +29,6 @@ module Decidim
28
29
 
29
30
  layout "layouts/decidim/application"
30
31
 
31
- rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_404
32
-
33
32
  private
34
33
 
35
34
  def store_current_location
@@ -46,9 +45,5 @@ module Decidim
46
45
  def add_vary_header
47
46
  response.headers["Vary"] = "Accept"
48
47
  end
49
-
50
- def redirect_to_404
51
- raise ActionController::RoutingError, "Not Found"
52
- end
53
48
  end
54
49
  end
@@ -8,7 +8,6 @@ module Decidim
8
8
  include FormFactory
9
9
  include Decidim::DeviseControllers
10
10
 
11
- helper Decidim::OmniauthHelper
12
11
  helper_method :terms_and_conditions_page
13
12
 
14
13
  before_action :configure_permitted_parameters
@@ -5,7 +5,6 @@ module Decidim
5
5
  # Custom Devise SessionsController to avoid namespace problems.
6
6
  class SessionsController < ::Devise::SessionsController
7
7
  include Decidim::DeviseControllers
8
- helper Decidim::OmniauthHelper
9
8
 
10
9
  def after_sign_in_path_for(user)
11
10
  return first_login_authorizations_path if first_login_and_not_authorized?(user) &&
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ class ErrorsController < ApplicationController
5
+ skip_authorization_check
6
+
7
+ def not_found
8
+ render status: :not_found
9
+ end
10
+
11
+ def internal_server_error
12
+ render status: :internal_server_error
13
+ end
14
+ end
15
+ end
@@ -16,6 +16,7 @@ module Decidim
16
16
  helper Decidim::FeatureReferenceHelper
17
17
  helper Decidim::TranslationsHelper
18
18
  helper Decidim::ParticipatoryProcessHelper
19
+ helper Decidim::IconHelper
19
20
  helper Decidim::ResourceHelper
20
21
  helper Decidim::OrganizationScopesHelper
21
22
  helper Decidim::ActionAuthorizationHelper
@@ -6,6 +6,8 @@ module Decidim
6
6
  class ParticipatoryProcessGroupsController < ApplicationController
7
7
  helper_method :participatory_processes, :group, :collection
8
8
 
9
+ before_action :set_group
10
+
9
11
  def show
10
12
  authorize! :read, ParticipatoryProcessGroup
11
13
  end
@@ -17,8 +19,10 @@ module Decidim
17
19
  end
18
20
  alias collection participatory_processes
19
21
 
20
- def group
21
- Decidim::ParticipatoryProcessGroup.find(params[:id])
22
+ def set_group
23
+ @group = Decidim::ParticipatoryProcessGroup.find(params[:id])
22
24
  end
25
+
26
+ attr_reader :group
23
27
  end
24
28
  end
@@ -11,6 +11,7 @@ module Decidim
11
11
  include NeedsParticipatoryProcess
12
12
 
13
13
  helper Decidim::ParticipatoryProcessHelper
14
+ helper Decidim::IconHelper
14
15
 
15
16
  def index
16
17
  authorize! :read, ParticipatoryProcess
@@ -6,15 +6,15 @@ module Decidim
6
6
  # A controller that holds the logic to show ParticipatoryProcesses in a
7
7
  # public layout.
8
8
  class ParticipatoryProcessesController < ApplicationController
9
- include NeedsParticipatoryProcess
10
-
11
9
  layout "layouts/decidim/participatory_process", only: [:show]
12
10
 
13
- skip_after_action :verify_participatory_process, only: [:index]
11
+ before_action -> { extend(NeedsParticipatoryProcess) }, only: [:show]
14
12
 
15
13
  helper Decidim::AttachmentsHelper
16
14
  helper Decidim::ParticipatoryProcessHelper
15
+ helper Decidim::IconHelper
17
16
  helper Decidim::WidgetUrlsHelper
17
+
18
18
  helper_method :collection, :promoted_participatory_processes, :participatory_processes
19
19
 
20
20
  def index