decidim-core 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/config/decidim_core_manifest.js +2 -0
- data/app/assets/javascripts/decidim/map.js.es6.erb +95 -0
- data/app/assets/stylesheets/decidim/map.css +3 -0
- data/app/assets/stylesheets/decidim/modules/_layout.scss +2 -4
- data/app/assets/stylesheets/decidim/modules/_margins.scss +3 -2
- data/app/assets/stylesheets/decidim/modules/_process-header.scss +15 -2
- data/app/assets/stylesheets/decidim/modules/_process-phase.scss +4 -1
- data/app/assets/stylesheets/decidim/utils/_settings.scss +3 -3
- data/app/commands/decidim/create_report.rb +90 -0
- data/app/controllers/concerns/decidim/devise_controllers.rb +26 -0
- data/app/controllers/concerns/decidim/payload_info.rb +23 -0
- data/app/controllers/concerns/decidim/user_profile.rb +2 -1
- data/app/controllers/decidim/application_controller.rb +25 -1
- data/app/controllers/decidim/authorizations_controller.rb +10 -2
- data/app/controllers/decidim/cookie_policy_controller.rb +5 -0
- data/app/controllers/decidim/devise/confirmations_controller.rb +1 -9
- data/app/controllers/decidim/devise/invitations_controller.rb +1 -9
- data/app/controllers/decidim/devise/omniauth_registrations_controller.rb +1 -10
- data/app/controllers/decidim/devise/passwords_controller.rb +1 -9
- data/app/controllers/decidim/devise/registrations_controller.rb +2 -15
- data/app/controllers/decidim/devise/sessions_controller.rb +9 -15
- data/{lib → app/controllers}/decidim/features/base_controller.rb +5 -1
- data/app/controllers/decidim/participatory_process_groups_controller.rb +22 -0
- data/app/controllers/decidim/participatory_process_steps_controller.rb +2 -0
- data/app/controllers/decidim/participatory_processes_controller.rb +14 -3
- data/app/controllers/decidim/reports_controller.rb +33 -0
- data/app/controllers/decidim/static_map_controller.rb +18 -0
- data/app/forms/decidim/report_form.rb +12 -0
- data/app/helpers/decidim/application_helper.rb +0 -2
- data/app/helpers/decidim/feature_reference_helper.rb +22 -0
- data/app/helpers/decidim/map_helper.rb +41 -0
- data/app/helpers/decidim/organization_scopes_helper.rb +41 -0
- data/app/helpers/decidim/replace_buttons_helper.rb +42 -0
- data/app/helpers/decidim/resource_helper.rb +2 -1
- data/app/helpers/decidim/translations_helper.rb +1 -1
- data/app/mailers/decidim/reported_mailer.rb +35 -0
- data/app/middleware/decidim/current_organization.rb +29 -3
- data/app/models/decidim/abilities/everyone.rb +1 -0
- data/app/models/decidim/moderation.rb +13 -0
- data/app/models/decidim/newsletter.rb +1 -0
- data/app/models/decidim/organization.rb +2 -0
- data/app/models/decidim/participatory_process.rb +11 -0
- data/app/models/decidim/participatory_process_group.rb +15 -0
- data/app/models/decidim/participatory_process_step.rb +1 -1
- data/app/models/decidim/report.rb +23 -0
- data/app/services/decidim/public_processes.rb +42 -0
- data/app/services/decidim/resource_search.rb +17 -1
- data/app/services/decidim/static_map_generator.rb +49 -0
- data/app/uploaders/decidim/application_uploader.rb +4 -1
- data/app/uploaders/decidim/official_image_footer_uploader.rb +2 -2
- data/app/uploaders/decidim/official_image_header_uploader.rb +1 -1
- data/app/validators/geocoding_validator.rb +22 -0
- data/app/views/decidim/authorizations/new.html.erb +1 -1
- data/app/views/decidim/participatory_process_groups/_participatory_process_group.html.erb +22 -0
- data/app/views/decidim/participatory_process_groups/show.html.erb +11 -0
- data/app/views/decidim/participatory_processes/index.html.erb +1 -1
- data/app/views/decidim/participatory_processes/show.html.erb +18 -5
- data/app/views/decidim/reported_mailer/hide.html.erb +5 -0
- data/app/views/decidim/reported_mailer/report.html.erb +5 -0
- data/app/views/decidim/shared/_address_details.html.erb +9 -0
- data/app/views/decidim/shared/_flag_modal.html.erb +20 -0
- data/app/views/decidim/shared/_share_modal.html.erb +5 -5
- data/app/views/decidim/shared/_static_map.html.erb +17 -0
- data/app/views/devise/mailer/invite_collaborator.html.erb +17 -0
- data/app/views/devise/mailer/invite_collaborator.text.erb +15 -0
- data/app/views/layouts/decidim/_application.html.erb +5 -12
- data/app/views/layouts/decidim/{_social_meta.html.erb → _head.html.erb} +13 -0
- data/app/views/layouts/decidim/_head_extra.html.erb +7 -0
- data/app/views/layouts/decidim/_process_header.html.erb +15 -9
- data/app/views/layouts/decidim/_process_header_steps.html.erb +3 -3
- data/app/views/layouts/decidim/{_header.html.erb → _wrapper.html.erb} +47 -10
- data/app/views/pages/home/_highlighted_processes.html.erb +2 -2
- data/config/i18n-tasks.yml +3 -0
- data/config/locales/ca.yml +40 -1
- data/config/locales/en.yml +40 -1
- data/config/locales/es.yml +40 -1
- data/config/locales/eu.yml +235 -1
- data/config/locales/fi.yml +375 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20170215115407_add_organization_custom_reference.rb +11 -0
- data/db/migrate/20170220110740_remove_steps_short_description.rb +21 -0
- data/db/migrate/20170221094835_add_scopes_to_processes.rb +6 -0
- data/db/migrate/20170228142440_add_participatory_process_groups.rb +15 -0
- data/db/migrate/20170306144354_add_secondary_hosts_to_organizations.rb +5 -0
- data/db/migrate/20170307084957_create_reports.rb +15 -0
- data/db/migrate/20170308091316_create_moderations.rb +12 -0
- data/db/migrate/20170313095436_add_available_authorizations_to_organization.rb +10 -0
- data/db/seeds.rb +20 -10
- data/lib/decidim/core.rb +12 -1
- data/lib/decidim/core/api.rb +1 -0
- data/lib/decidim/core/api/decidim_type.rb +12 -0
- data/lib/decidim/core/api/process_step_type.rb +0 -6
- data/lib/decidim/core/api/user_type.rb +4 -0
- data/lib/decidim/core/engine.rb +27 -0
- data/lib/decidim/core/test.rb +5 -0
- data/lib/decidim/core/test/factories.rb +52 -3
- data/lib/decidim/core/test/shared_examples/comments_examples.rb +215 -0
- data/lib/decidim/core/test/shared_examples/has_reference.rb +30 -0
- data/lib/decidim/core/test/shared_examples/manage_moderations_examples.rb +75 -0
- data/lib/decidim/core/test/shared_examples/reportable.rb +44 -0
- data/lib/decidim/core/test/shared_examples/reports_examples.rb +64 -0
- data/lib/decidim/core/version.rb +2 -2
- data/lib/decidim/has_reference.rb +50 -0
- data/lib/decidim/query_extensions.rb +4 -0
- data/lib/decidim/reportable.rb +46 -0
- data/vendor/assets/javascripts/leaflet-svg-icon.js +179 -0
- data/vendor/assets/javascripts/leaflet-tilelayer-here.js +166 -0
- data/vendor/assets/javascripts/leaflet.js +9 -0
- data/vendor/assets/javascripts/leaflet.markercluster.js +7 -0
- data/vendor/assets/javascripts/quill.min.js +8 -8
- data/vendor/assets/javascripts/quill.min.js.map +1 -1
- data/vendor/assets/stylesheets/MarkerCluster.Default.css +60 -0
- data/vendor/assets/stylesheets/MarkerCluster.css +14 -0
- data/vendor/assets/stylesheets/leaflet.css +624 -0
- data/vendor/assets/stylesheets/quill.bubble.css +75 -4
- data/vendor/assets/stylesheets/quill.core.css +21 -2
- data/vendor/assets/stylesheets/quill.snow.css +29 -3
- metadata +107 -27
- data/app/views/layouts/decidim/_footer.html.erb +0 -36
- data/app/views/layouts/decidim/_meta.html.erb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3eff907b57b0cab03cceeb32b458e2cfd59e7dc6
|
4
|
+
data.tar.gz: 133dc98f767565fc733b02f8733c057855cd7d9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: beb54c792c2e01aa0f08ebe85be2ad2b2b2888b2b102e008b1499e1a769279076bc650b7d14189bde0fd00d59d4d28734876271a81d02ea69c9b5e6746f70218
|
7
|
+
data.tar.gz: a45d55c72e259bae57b7ba19a2293259a8ca8a9199f3b5c02f906d37e06e6ad7a879ee20cafef940175dc7740aaf37667897e6c1ff9b121d9c4faacd8a9d3e61
|
@@ -0,0 +1,95 @@
|
|
1
|
+
// = require leaflet
|
2
|
+
// = require leaflet-tilelayer-here
|
3
|
+
// = require leaflet-svg-icon
|
4
|
+
// = require leaflet.markercluster
|
5
|
+
// = require jquery-tmpl
|
6
|
+
// = require_self
|
7
|
+
|
8
|
+
L.DivIcon.SVGIcon.DecidimIcon = L.DivIcon.SVGIcon.extend({
|
9
|
+
options: {
|
10
|
+
fillColor: '#ef604d',
|
11
|
+
opacity: 0
|
12
|
+
},
|
13
|
+
_createPathDescription: function() {
|
14
|
+
return 'M14 1.17a11.685 11.685 0 0 0-11.685 11.685c0 11.25 10.23 20.61 10.665 21a1.5 1.5 0 0 0 2.025 0c0.435-.435 10.665-9.81 10.665-21A11.685 11.685 0 0 0 14 1.17Zm0 17.415A5.085 5.085 0 1 1 19.085 13.5 5.085 5.085 0 0 1 14 18.585Z';
|
15
|
+
},
|
16
|
+
_createCircle: function() {
|
17
|
+
return ""
|
18
|
+
}
|
19
|
+
});
|
20
|
+
|
21
|
+
const popupTemplateId = 'marker-popup';
|
22
|
+
$.template(popupTemplateId, $(`#${popupTemplateId}`).html());
|
23
|
+
|
24
|
+
const addMarkers = (markersData, markerClusters, map) => {
|
25
|
+
const bounds = new L.LatLngBounds(markersData.map((markerData) => [markerData.latitude, markerData.longitude]));
|
26
|
+
|
27
|
+
markersData.forEach((markerData) => {
|
28
|
+
let marker = L.marker([markerData.latitude, markerData.longitude], {
|
29
|
+
icon: new L.DivIcon.SVGIcon.DecidimIcon()
|
30
|
+
});
|
31
|
+
let node = document.createElement('div');
|
32
|
+
|
33
|
+
$.tmpl(popupTemplateId, markerData).appendTo(node);
|
34
|
+
|
35
|
+
marker.bindPopup(node, {
|
36
|
+
maxwidth: 640,
|
37
|
+
minWidth: 500,
|
38
|
+
keepInView: true,
|
39
|
+
className: 'map-info'
|
40
|
+
}).openPopup();
|
41
|
+
|
42
|
+
markerClusters.addLayer(marker);
|
43
|
+
});
|
44
|
+
|
45
|
+
map.addLayer(markerClusters);
|
46
|
+
map.fitBounds(bounds, { padding: [100, 100] });
|
47
|
+
};
|
48
|
+
|
49
|
+
const loadMap = (mapId, markersData) => {
|
50
|
+
let markerClusters = L.markerClusterGroup();
|
51
|
+
const { hereAppId, hereAppCode } = window.Decidim.mapConfiguration;
|
52
|
+
|
53
|
+
if (window.Decidim.currentMap) {
|
54
|
+
window.Decidim.currentMap.remove();
|
55
|
+
window.Decidim.currentMap = null;
|
56
|
+
}
|
57
|
+
|
58
|
+
const map = L.map(mapId);
|
59
|
+
|
60
|
+
L.tileLayer.here({
|
61
|
+
appId: hereAppId,
|
62
|
+
appCode: hereAppCode
|
63
|
+
}).addTo(map);
|
64
|
+
|
65
|
+
if (markersData.length > 0) {
|
66
|
+
addMarkers(markersData, markerClusters, map);
|
67
|
+
} else {
|
68
|
+
map.fitWorld();
|
69
|
+
}
|
70
|
+
|
71
|
+
map.scrollWheelZoom.disable();
|
72
|
+
|
73
|
+
return map;
|
74
|
+
};
|
75
|
+
|
76
|
+
window.Decidim = window.Decidim || {};
|
77
|
+
|
78
|
+
window.Decidim.loadMap = loadMap;
|
79
|
+
window.Decidim.currentMap = null;
|
80
|
+
window.Decidim.mapConfiguration = {};
|
81
|
+
|
82
|
+
$(() => {
|
83
|
+
const mapId = 'map';
|
84
|
+
const $map = $(`#${mapId}`);
|
85
|
+
|
86
|
+
const markersData = $map.data('markers-data');
|
87
|
+
const hereAppId = $map.data('here-app-id');
|
88
|
+
const hereAppCode = $map.data('here-app-code');
|
89
|
+
|
90
|
+
window.Decidim.mapConfiguration = { hereAppId, hereAppCode };
|
91
|
+
|
92
|
+
if ($map.length > 0) {
|
93
|
+
window.Decidim.currentMap = loadMap(mapId, markersData);
|
94
|
+
}
|
95
|
+
});
|
@@ -1,12 +1,13 @@
|
|
1
1
|
$margin-s: 1rem;
|
2
|
+
$margin-sm: 2rem;
|
2
3
|
$margin-m: 3rem;
|
3
4
|
$margin-l: 5rem;
|
4
5
|
|
5
6
|
//Sections
|
6
7
|
.section{
|
7
|
-
margin-bottom: $margin-
|
8
|
+
margin-bottom: $margin-sm;
|
8
9
|
@include breakpoint(large){
|
9
|
-
margin-bottom: $margin-
|
10
|
+
margin-bottom: $margin-m;
|
10
11
|
}
|
11
12
|
}
|
12
13
|
|
@@ -1,5 +1,8 @@
|
|
1
1
|
.process-header{
|
2
|
-
margin-bottom:
|
2
|
+
margin-bottom: $margin-sm;
|
3
|
+
@include breakpoint(medium){
|
4
|
+
margin-bottom: $margin-m;
|
5
|
+
}
|
3
6
|
.heading2{
|
4
7
|
font-weight: bold;
|
5
8
|
}
|
@@ -34,7 +37,10 @@
|
|
34
37
|
}
|
35
38
|
|
36
39
|
.process-header__info{
|
37
|
-
padding:
|
40
|
+
padding: 1rem 1.5rem 1rem 1rem;
|
41
|
+
@include breakpoint(medium){
|
42
|
+
padding: 2rem 1.5rem 2rem 1rem;
|
43
|
+
}
|
38
44
|
@include breakpoint(mediumlarge){
|
39
45
|
padding-left: 2rem;
|
40
46
|
}
|
@@ -59,6 +65,13 @@
|
|
59
65
|
}
|
60
66
|
}
|
61
67
|
|
68
|
+
.process-header__phase--simple{
|
69
|
+
padding: .5rem 1rem;
|
70
|
+
@include breakpoint (medium){
|
71
|
+
padding: 2rem 1rem;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
62
75
|
.process-header__hashtag{
|
63
76
|
font-weight: 600;
|
64
77
|
&::after{
|
@@ -118,9 +118,9 @@ $header-margin-bottom: 0.5rem;
|
|
118
118
|
$header-styles: (
|
119
119
|
'small': (
|
120
120
|
'h1': ('font-size': 40),
|
121
|
-
'h2': ('font-size':
|
122
|
-
'h3': ('font-size':
|
123
|
-
'h4': ('font-size':
|
121
|
+
'h2': ('font-size': 26),
|
122
|
+
'h3': ('font-size': 24),
|
123
|
+
'h4': ('font-size': 22),
|
124
124
|
'h5': ('font-size': 20),
|
125
125
|
'h6': ('font-size': 16)
|
126
126
|
),
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
# A command with all the business logic when a user creates a report.
|
4
|
+
class CreateReport < Rectify::Command
|
5
|
+
# Public: Initializes the command.
|
6
|
+
#
|
7
|
+
# form - A form object with the params.
|
8
|
+
# reportable - The resource being reported
|
9
|
+
# current_user - The current user.
|
10
|
+
def initialize(form, reportable, current_user)
|
11
|
+
@form = form
|
12
|
+
@reportable = reportable
|
13
|
+
@current_user = current_user
|
14
|
+
end
|
15
|
+
|
16
|
+
# Executes the command. Broadcasts these events:
|
17
|
+
#
|
18
|
+
# - :ok when everything is valid, together with the report.
|
19
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
20
|
+
#
|
21
|
+
# Returns nothing.
|
22
|
+
def call
|
23
|
+
return broadcast(:invalid) if form.invalid?
|
24
|
+
|
25
|
+
transaction do
|
26
|
+
find_or_create_moderation!
|
27
|
+
create_report!
|
28
|
+
update_report_count!
|
29
|
+
end
|
30
|
+
|
31
|
+
send_report_notification_to_admins
|
32
|
+
|
33
|
+
if hideable?
|
34
|
+
hide!
|
35
|
+
send_hide_notification_to_admins
|
36
|
+
end
|
37
|
+
|
38
|
+
broadcast(:ok, report)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_reader :form, :report
|
44
|
+
|
45
|
+
def find_or_create_moderation!
|
46
|
+
@moderation = Moderation.find_or_create_by!(reportable: @reportable, participatory_process: participatory_process)
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_report!
|
50
|
+
@report = Report.create!(
|
51
|
+
moderation: @moderation,
|
52
|
+
user: @current_user,
|
53
|
+
reason: form.reason,
|
54
|
+
details: form.details
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def update_report_count!
|
59
|
+
@moderation.update_attributes!(report_count: @moderation.report_count + 1)
|
60
|
+
end
|
61
|
+
|
62
|
+
def participatory_process_admins
|
63
|
+
@participatory_process_admins ||= Decidim::Admin::ProcessAdmins.for(participatory_process)
|
64
|
+
end
|
65
|
+
|
66
|
+
def send_report_notification_to_admins
|
67
|
+
participatory_process_admins.each do |admin|
|
68
|
+
ReportedMailer.report(admin, @report).deliver_later
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def hideable?
|
73
|
+
!@reportable.hidden? && @moderation.report_count >= Decidim.max_reports_before_hiding
|
74
|
+
end
|
75
|
+
|
76
|
+
def hide!
|
77
|
+
Decidim::Admin::HideResource.new(@reportable).call
|
78
|
+
end
|
79
|
+
|
80
|
+
def send_hide_notification_to_admins
|
81
|
+
participatory_process_admins.each do |admin|
|
82
|
+
ReportedMailer.hide(admin, @report).deliver_later
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def participatory_process
|
87
|
+
@participatory_process ||= @reportable.feature.participatory_process
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "active_support/concern"
|
3
|
+
|
4
|
+
module Decidim
|
5
|
+
# This concern groups methods and helpers needed by Devise controllers.
|
6
|
+
module DeviseControllers
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
include Decidim::NeedsOrganization
|
11
|
+
include Decidim::LocaleSwitcher
|
12
|
+
|
13
|
+
include NeedsAuthorization
|
14
|
+
skip_authorization_check
|
15
|
+
|
16
|
+
helper Decidim::TranslationsHelper
|
17
|
+
helper Decidim::MetaTagsHelper
|
18
|
+
helper Decidim::DecidimFormHelper
|
19
|
+
helper Decidim::LanguageChooserHelper
|
20
|
+
helper Decidim::CookiesHelper
|
21
|
+
helper Decidim::ReplaceButtonsHelper
|
22
|
+
|
23
|
+
layout "layouts/decidim/application"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module PayloadInfo
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
def append_info_to_payload(payload)
|
11
|
+
super
|
12
|
+
payload[:user_id] = try(:current_user).try(:id)
|
13
|
+
payload[:organization_id] = try(:current_organization).try(:id)
|
14
|
+
payload[:app] = try(:current_organization).try(:name)
|
15
|
+
payload[:remote_ip] = request.remote_ip
|
16
|
+
payload[:referer] = request.referer.to_s
|
17
|
+
payload[:request_id] = request.uuid
|
18
|
+
payload[:user_agent] = request.user_agent
|
19
|
+
payload[:xhr] = request.xhr? ? 'true' : 'false'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -13,6 +13,7 @@ module Decidim
|
|
13
13
|
delegate :user_groups, to: :current_user, prefix: false
|
14
14
|
|
15
15
|
included do
|
16
|
+
helper Decidim::UserProfileHelper
|
16
17
|
layout "layouts/decidim/user_profile"
|
17
18
|
|
18
19
|
helper_method :available_authorization_handlers,
|
@@ -25,7 +26,7 @@ module Decidim
|
|
25
26
|
# Public: Available authorization handlers in order to conditionally
|
26
27
|
# show the menu element.
|
27
28
|
def available_authorization_handlers
|
28
|
-
|
29
|
+
current_organization.available_authorizations.map(&:constantize)
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
@@ -1,19 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Decidim
|
3
3
|
# The main application controller that inherits from Rails.
|
4
|
-
class ApplicationController <
|
4
|
+
class ApplicationController < ::DecidimController
|
5
5
|
include Decidim::NeedsOrganization
|
6
6
|
include Decidim::LocaleSwitcher
|
7
7
|
include NeedsAuthorization
|
8
|
+
include PayloadInfo
|
9
|
+
|
8
10
|
helper Decidim::MetaTagsHelper
|
9
11
|
helper Decidim::DecidimFormHelper
|
10
12
|
helper Decidim::LanguageChooserHelper
|
13
|
+
helper Decidim::ReplaceButtonsHelper
|
14
|
+
helper Decidim::TranslationsHelper
|
15
|
+
helper Decidim::CookiesHelper
|
16
|
+
helper Decidim::AriaSelectedLinkToHelper
|
17
|
+
|
18
|
+
# Saves the location before loading each page so we can return to the
|
19
|
+
# right page. If we're on a devise page, we don't want to store that as the
|
20
|
+
# place to return to (for example, we don't want to return to the sign in page
|
21
|
+
# after signing in), which is what the :unless prevents
|
22
|
+
before_action :store_current_location, unless: :devise_controller?
|
11
23
|
|
12
24
|
protect_from_forgery with: :exception, prepend: true
|
13
25
|
after_action :add_vary_header
|
14
26
|
|
15
27
|
layout "layouts/decidim/application"
|
16
28
|
|
29
|
+
rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_404
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def store_current_location
|
34
|
+
store_location_for(:user, request.url)
|
35
|
+
end
|
36
|
+
|
17
37
|
def user_not_authorized_path
|
18
38
|
decidim.root_path
|
19
39
|
end
|
@@ -24,5 +44,9 @@ module Decidim
|
|
24
44
|
def add_vary_header
|
25
45
|
response.headers["Vary"] = "Accept"
|
26
46
|
end
|
47
|
+
|
48
|
+
def redirect_to_404
|
49
|
+
raise ActionController::RoutingError, "Not Found"
|
50
|
+
end
|
27
51
|
end
|
28
52
|
end
|
@@ -5,13 +5,15 @@ module Decidim
|
|
5
5
|
# This controller allows users to create and destroy their authorizations. It
|
6
6
|
# shouldn't be necessary to expand it to add new authorization schemes.
|
7
7
|
class AuthorizationsController < ApplicationController
|
8
|
-
helper_method :handler, :handlers
|
8
|
+
helper_method :handler, :handlers, :stored_location
|
9
9
|
before_action :valid_handler, only: [:new, :create]
|
10
10
|
|
11
11
|
include Decidim::UserProfile
|
12
12
|
helper Decidim::DecidimFormHelper
|
13
|
+
helper Decidim::AuthorizationFormHelper
|
13
14
|
|
14
15
|
layout "layouts/decidim/user_profile", only: [:index]
|
16
|
+
skip_before_action :store_current_location
|
15
17
|
|
16
18
|
def new; end
|
17
19
|
|
@@ -33,7 +35,7 @@ module Decidim
|
|
33
35
|
AuthorizeUser.call(handler) do
|
34
36
|
on(:ok) do
|
35
37
|
flash[:notice] = t("authorizations.create.success", scope: "decidim")
|
36
|
-
redirect_to params[:redirect_url] || authorizations_path
|
38
|
+
redirect_to params[:redirect_url] || stored_location_for(current_user) || authorizations_path
|
37
39
|
end
|
38
40
|
|
39
41
|
on(:invalid) do
|
@@ -53,6 +55,12 @@ module Decidim
|
|
53
55
|
|
54
56
|
protected
|
55
57
|
|
58
|
+
def stored_location
|
59
|
+
location = stored_location_for(current_user)
|
60
|
+
store_location_for(current_user, location)
|
61
|
+
location || participatory_processes_path
|
62
|
+
end
|
63
|
+
|
56
64
|
def handler_params
|
57
65
|
(params[:authorization_handler] || {}).merge(user: current_user)
|
58
66
|
end
|