decidim-admin 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of decidim-admin might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/javascripts/decidim/admin/application.js.es6 +3 -2
- data/app/assets/javascripts/decidim/admin/tab_focus.js.es6 +1 -1
- data/app/assets/stylesheets/decidim/admin/_foundation_and_overrides.scss +1 -1
- data/app/commands/decidim/admin/{create_participatory_process_attachment.rb → create_attachment.rb} +6 -7
- data/app/commands/decidim/admin/create_participatory_process.rb +12 -3
- data/app/commands/decidim/admin/{update_participatory_process_attachment.rb → update_attachment.rb} +7 -6
- data/app/commands/decidim/admin/update_feature.rb +2 -1
- data/app/commands/decidim/admin/update_organization.rb +1 -0
- data/app/commands/decidim/admin/update_participatory_process.rb +16 -4
- data/app/constraints/decidim/admin/organization_dashboard_constraint.rb +1 -1
- data/app/controllers/decidim/admin/application_controller.rb +2 -2
- data/app/controllers/decidim/admin/concerns/has_attachments.rb +116 -0
- data/app/controllers/decidim/admin/participatory_process_attachments_controller.rb +5 -67
- data/app/controllers/decidim/admin/users_controller.rb +5 -5
- data/app/forms/decidim/admin/{participatory_process_attachment_form.rb → attachment_form.rb} +2 -2
- data/app/forms/decidim/admin/feature_form.rb +1 -0
- data/app/forms/decidim/admin/organization_form.rb +1 -0
- data/app/forms/decidim/admin/participatory_process_form.rb +8 -1
- data/app/helpers/decidim/admin/application_helper.rb +1 -0
- data/app/helpers/decidim/admin/feature_settings_helper.rb +29 -0
- data/app/models/decidim/admin/abilities/admin_user.rb +4 -4
- data/app/models/decidim/admin/abilities/base.rb +3 -3
- data/app/models/decidim/admin/abilities/participatory_process_admin.rb +15 -7
- data/app/views/decidim/admin/{participatory_process_attachments → attachments}/_form.html.erb +0 -0
- data/app/views/decidim/admin/attachments/edit.html.erb +9 -0
- data/app/views/decidim/admin/attachments/index.html.erb +37 -0
- data/app/views/decidim/admin/attachments/new.html.erb +9 -0
- data/app/views/decidim/admin/attachments/show.html.erb +25 -0
- data/app/views/decidim/admin/features/_form.html.erb +1 -0
- data/app/views/decidim/admin/features/_settings_fields.html.erb +6 -3
- data/app/views/decidim/admin/organization/_form.html.erb +4 -0
- data/app/views/decidim/admin/participatory_processes/_form.html.erb +16 -0
- data/app/views/decidim/admin/participatory_processes/show.html.erb +11 -1
- data/app/views/layouts/decidim/admin/_header.html.erb +2 -2
- data/app/views/layouts/decidim/admin/_sidebar.html.erb +1 -1
- data/app/views/layouts/decidim/admin/participatory_process.html.erb +2 -2
- data/config/locales/ca.yml +29 -27
- data/config/locales/en.yml +29 -27
- data/config/locales/es.yml +29 -27
- data/config/routes.rb +1 -1
- data/db/migrate/20170128112958_change_user_groups_verified_to_timestamp.rb +9 -0
- data/lib/decidim/admin/engine.rb +2 -2
- data/lib/decidim/admin/test/manage_attachments_examples.rb +103 -0
- metadata +18 -35
- data/app/helpers/decidim/admin/aria_selected_link_to_helper.rb +0 -28
- data/app/views/decidim/admin/participatory_process_attachments/edit.html.erb +0 -9
- data/app/views/decidim/admin/participatory_process_attachments/index.html.erb +0 -37
- data/app/views/decidim/admin/participatory_process_attachments/new.html.erb +0 -9
- data/app/views/decidim/admin/participatory_process_attachments/show.html.erb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a558feb308b27b688f8588f74871422a59d3efbc
|
4
|
+
data.tar.gz: 3300ce4311639a5a14bf6e8fd1c94e1776a5148e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70b3749d2b3fbbaeaa6318b93613d6661f65bd9187b4d1bccab8b872747ff7d0d7ef3c96ea0c5183038671a1d953655773b451e24d531eb1ba9f99cd23b369bf
|
7
|
+
data.tar.gz: 17f6d2bf2e8966b973a877f83644b8e42e7991782ef242a734a93391c4fda67c1f9f9ae7b56643c9af222742385dbc5bc3b031631962840e7af93cbc8e2f0883
|
@@ -3,7 +3,6 @@
|
|
3
3
|
// = require jquery
|
4
4
|
// = require jquery_ujs
|
5
5
|
// = require foundation
|
6
|
-
// = require turbolinks
|
7
6
|
// = require html.sortable
|
8
7
|
// = require ./sort_steps
|
9
8
|
// = require ./tab_focus
|
@@ -15,4 +14,6 @@ const pageLoad = () => {
|
|
15
14
|
sortSteps();
|
16
15
|
};
|
17
16
|
|
18
|
-
$(
|
17
|
+
$(() => {
|
18
|
+
pageLoad();
|
19
|
+
});
|
@@ -3,7 +3,7 @@
|
|
3
3
|
/**
|
4
4
|
* When switching tabs in i18n fields, autofocus on the input to save clicks #212
|
5
5
|
*/
|
6
|
-
$(
|
6
|
+
$(() => {
|
7
7
|
// Event launched by foundation
|
8
8
|
$('[data-tabs]').on('change.zf.tabs', (event) => {
|
9
9
|
const $container = $(event.target).next('.tabs-content .tabs-panel.is-active');
|
@@ -27,7 +27,7 @@
|
|
27
27
|
@include foundation-drilldown-menu;
|
28
28
|
@include foundation-dropdown;
|
29
29
|
@include foundation-dropdown-menu;
|
30
|
-
@include foundation-
|
30
|
+
@include foundation-responsive-embed;
|
31
31
|
@include foundation-label;
|
32
32
|
@include foundation-media-object;
|
33
33
|
@include foundation-menu;
|
data/app/commands/decidim/admin/{create_participatory_process_attachment.rb → create_attachment.rb}
RENAMED
@@ -3,15 +3,14 @@ module Decidim
|
|
3
3
|
module Admin
|
4
4
|
# A command with all the business logic to add an attachment to a
|
5
5
|
# participatory process.
|
6
|
-
class
|
6
|
+
class CreateAttachment < Rectify::Command
|
7
7
|
# Public: Initializes the command.
|
8
8
|
#
|
9
9
|
# form - A form object with the params.
|
10
|
-
#
|
11
|
-
|
12
|
-
def initialize(form, participatory_process)
|
10
|
+
# attached_to - The ActiveRecord::Base that will hold the attachment
|
11
|
+
def initialize(form, attached_to)
|
13
12
|
@form = form
|
14
|
-
@
|
13
|
+
@attached_to = attached_to
|
15
14
|
end
|
16
15
|
|
17
16
|
# Executes the command. Broadcasts these events:
|
@@ -32,11 +31,11 @@ module Decidim
|
|
32
31
|
attr_reader :form
|
33
32
|
|
34
33
|
def create_attachment
|
35
|
-
|
34
|
+
Attachment.create!(
|
36
35
|
title: form.title,
|
37
36
|
description: form.description,
|
38
37
|
file: form.file,
|
39
|
-
|
38
|
+
attached_to: @attached_to
|
40
39
|
)
|
41
40
|
end
|
42
41
|
end
|
@@ -19,9 +19,15 @@ module Decidim
|
|
19
19
|
# Returns nothing.
|
20
20
|
def call
|
21
21
|
return broadcast(:invalid) if form.invalid?
|
22
|
-
|
23
22
|
process = create_participatory_process
|
24
|
-
|
23
|
+
|
24
|
+
if process.persisted?
|
25
|
+
broadcast(:ok, process)
|
26
|
+
else
|
27
|
+
form.errors.add(:hero_image, process.errors[:hero_image]) if process.errors.include? :hero_image
|
28
|
+
form.errors.add(:banner_image, process.errors[:banner_image]) if process.errors.include? :banner_image
|
29
|
+
broadcast(:invalid)
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
private
|
@@ -30,7 +36,7 @@ module Decidim
|
|
30
36
|
|
31
37
|
def create_participatory_process
|
32
38
|
transaction do
|
33
|
-
process = ParticipatoryProcess.
|
39
|
+
process = ParticipatoryProcess.new(
|
34
40
|
title: form.title,
|
35
41
|
subtitle: form.subtitle,
|
36
42
|
slug: form.slug,
|
@@ -43,6 +49,9 @@ module Decidim
|
|
43
49
|
organization: form.current_organization
|
44
50
|
)
|
45
51
|
|
52
|
+
return process unless process.valid?
|
53
|
+
process.save!
|
54
|
+
|
46
55
|
process.steps.create!(
|
47
56
|
title: TranslationsHelper.multi_translation(
|
48
57
|
"decidim.admin.participatory_process_steps.default_title",
|
data/app/commands/decidim/admin/{update_participatory_process_attachment.rb → update_attachment.rb}
RENAMED
@@ -3,14 +3,15 @@ module Decidim
|
|
3
3
|
module Admin
|
4
4
|
# A command with all the business logic to update an attachment from a
|
5
5
|
# participatory process.
|
6
|
-
class
|
7
|
-
attr_reader :
|
6
|
+
class UpdateAttachment < Rectify::Command
|
7
|
+
attr_reader :attachment
|
8
|
+
|
8
9
|
# Public: Initializes the command.
|
9
10
|
#
|
10
|
-
#
|
11
|
+
# attachment - the Attachment to update
|
11
12
|
# form - A form object with the params.
|
12
|
-
def initialize(
|
13
|
-
@
|
13
|
+
def initialize(attachment, form)
|
14
|
+
@attachment = attachment
|
14
15
|
@form = form
|
15
16
|
end
|
16
17
|
|
@@ -32,7 +33,7 @@ module Decidim
|
|
32
33
|
attr_reader :form
|
33
34
|
|
34
35
|
def update_attachment
|
35
|
-
|
36
|
+
attachment.update_attributes!(attributes)
|
36
37
|
end
|
37
38
|
|
38
39
|
def attributes
|
@@ -42,6 +42,7 @@ module Decidim
|
|
42
42
|
welcome_text: form.welcome_text,
|
43
43
|
homepage_image: form.homepage_image || organization.homepage_image,
|
44
44
|
logo: form.logo || organization.logo,
|
45
|
+
favicon: form.favicon || organization.favicon,
|
45
46
|
default_locale: form.default_locale,
|
46
47
|
show_statistics: form.show_statistics
|
47
48
|
}
|
@@ -21,17 +21,25 @@ module Decidim
|
|
21
21
|
# Returns nothing.
|
22
22
|
def call
|
23
23
|
return broadcast(:invalid) if form.invalid?
|
24
|
-
|
25
24
|
update_participatory_process
|
26
|
-
|
25
|
+
|
26
|
+
if @participatory_process.valid?
|
27
|
+
broadcast(:ok, @participatory_process)
|
28
|
+
else
|
29
|
+
form.errors.add(:hero_image, @participatory_process.errors[:hero_image]) if @participatory_process.errors.include? :hero_image
|
30
|
+
form.errors.add(:banner_image, @participatory_process.errors[:banner_image]) if @participatory_process.errors.include? :banner_image
|
31
|
+
broadcast(:invalid)
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
35
|
+
|
29
36
|
private
|
30
37
|
|
31
38
|
attr_reader :form
|
32
39
|
|
33
40
|
def update_participatory_process
|
34
|
-
@participatory_process.
|
41
|
+
@participatory_process.assign_attributes(attributes)
|
42
|
+
@participatory_process.save! if @participatory_process.valid?
|
35
43
|
end
|
36
44
|
|
37
45
|
def attributes
|
@@ -44,7 +52,11 @@ module Decidim
|
|
44
52
|
banner_image: form.banner_image,
|
45
53
|
promoted: form.promoted,
|
46
54
|
description: form.description,
|
47
|
-
short_description: form.short_description
|
55
|
+
short_description: form.short_description,
|
56
|
+
domain: form.domain,
|
57
|
+
scope: form.scope,
|
58
|
+
developer_group: form.developer_group,
|
59
|
+
end_date: form.end_date
|
48
60
|
}.compact
|
49
61
|
end
|
50
62
|
end
|
@@ -16,8 +16,8 @@ module Decidim
|
|
16
16
|
|
17
17
|
# Overwrites `cancancan`'s method to point to the correct ability class,
|
18
18
|
# since the gem expects the ability class to be in the root namespace.
|
19
|
-
def
|
20
|
-
|
19
|
+
def current_ability_klass
|
20
|
+
Decidim::Admin::Abilities::Base
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
module Concerns
|
5
|
+
# Attachments can be related to any class in Decidim, in order to
|
6
|
+
# manage the attachments for a given type, you should create a new
|
7
|
+
# controller and include this concern.
|
8
|
+
#
|
9
|
+
# The only requirement is to define a `attached_to` method that
|
10
|
+
# returns an instance of the model to attach the attachment to.
|
11
|
+
module HasAttachments
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
helper_method :attached_to, :authorization_object
|
16
|
+
|
17
|
+
def index
|
18
|
+
authorize! :read, authorization_object
|
19
|
+
|
20
|
+
render template: "decidim/admin/attachments/index"
|
21
|
+
end
|
22
|
+
|
23
|
+
def new
|
24
|
+
authorize! :create, authorization_object
|
25
|
+
@form = form(AttachmentForm).instance
|
26
|
+
render template: "decidim/admin/attachments/new"
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
authorize! :create, authorization_object
|
31
|
+
@form = form(AttachmentForm).from_params(params)
|
32
|
+
|
33
|
+
CreateAttachment.call(@form, attached_to) do
|
34
|
+
on(:ok) do
|
35
|
+
flash[:notice] = I18n.t("attachments.create.success", scope: "decidim.admin")
|
36
|
+
redirect_to action: :index
|
37
|
+
end
|
38
|
+
|
39
|
+
on(:invalid) do
|
40
|
+
flash.now[:alert] = I18n.t("attachments.create.error", scope: "decidim.admin")
|
41
|
+
render template: "decidim/admin/attachments/new"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def edit
|
47
|
+
@attachment = collection.find(params[:id])
|
48
|
+
authorize! :update, authorization_object
|
49
|
+
@form = form(AttachmentForm).from_model(@attachment)
|
50
|
+
render template: "decidim/admin/attachments/edit"
|
51
|
+
end
|
52
|
+
|
53
|
+
def update
|
54
|
+
@attachment = collection.find(params[:id])
|
55
|
+
authorize! :update, authorization_object
|
56
|
+
@form = form(AttachmentForm).from_params(params)
|
57
|
+
|
58
|
+
UpdateAttachment.call(@attachment, @form) do
|
59
|
+
on(:ok) do
|
60
|
+
flash[:notice] = I18n.t("attachments.update.success", scope: "decidim.admin")
|
61
|
+
redirect_to action: :index
|
62
|
+
end
|
63
|
+
|
64
|
+
on(:invalid) do
|
65
|
+
flash.now[:alert] = I18n.t("attachments.update.error", scope: "decidim.admin")
|
66
|
+
render template: "decidim/admin/attachments/edit"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def show
|
72
|
+
@attachment = collection.find(params[:id])
|
73
|
+
authorize! :read, authorization_object
|
74
|
+
render template: "decidim/admin/attachments/show"
|
75
|
+
end
|
76
|
+
|
77
|
+
def destroy
|
78
|
+
@attachment = collection.find(params[:id])
|
79
|
+
authorize! :destroy, authorization_object
|
80
|
+
@attachment.destroy!
|
81
|
+
|
82
|
+
flash[:notice] = I18n.t("attachments.destroy.success", scope: "decidim.admin")
|
83
|
+
|
84
|
+
redirect_to after_destroy_path
|
85
|
+
end
|
86
|
+
|
87
|
+
# Public: Returns a String or Object that will be passed to `redirect_to` after
|
88
|
+
# destroying an attachment. By default it redirects to the attached_to.
|
89
|
+
#
|
90
|
+
# It can be redefined at controller level if you need to redirect elsewhere.
|
91
|
+
def after_destroy_path
|
92
|
+
attached_to
|
93
|
+
end
|
94
|
+
|
95
|
+
# Public: The only method to be implemented at the controller. You need to
|
96
|
+
# return the object where the attachment will be attached to.
|
97
|
+
def attached_to
|
98
|
+
raise NotImplementedError
|
99
|
+
end
|
100
|
+
|
101
|
+
# Public: The Class or Object to be used with the authorization layer to
|
102
|
+
# verify the user can manage the attachments
|
103
|
+
#
|
104
|
+
# By default is the same as the attached_to.
|
105
|
+
def authorization_object
|
106
|
+
attached_to
|
107
|
+
end
|
108
|
+
|
109
|
+
def collection
|
110
|
+
@collection ||= attached_to.attachments
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -8,76 +8,14 @@ module Decidim
|
|
8
8
|
#
|
9
9
|
class ParticipatoryProcessAttachmentsController < ApplicationController
|
10
10
|
include Concerns::ParticipatoryProcessAdmin
|
11
|
+
include Concerns::HasAttachments
|
11
12
|
|
12
|
-
def
|
13
|
-
|
13
|
+
def attached_to
|
14
|
+
participatory_process
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
-
|
18
|
-
@form = form(ParticipatoryProcessAttachmentForm).instance
|
19
|
-
end
|
20
|
-
|
21
|
-
def create
|
22
|
-
authorize! :create, ParticipatoryProcessAttachment
|
23
|
-
@form = form(ParticipatoryProcessAttachmentForm).from_params(params)
|
24
|
-
|
25
|
-
CreateParticipatoryProcessAttachment.call(@form, participatory_process) do
|
26
|
-
on(:ok) do
|
27
|
-
flash[:notice] = I18n.t("participatory_process_attachments.create.success", scope: "decidim.admin")
|
28
|
-
redirect_to participatory_process_attachments_path(participatory_process)
|
29
|
-
end
|
30
|
-
|
31
|
-
on(:invalid) do
|
32
|
-
flash.now[:alert] = I18n.t("participatory_process_attachments.create.error", scope: "decidim.admin")
|
33
|
-
render :new
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def edit
|
39
|
-
@participatory_process_attachment = collection.find(params[:id])
|
40
|
-
authorize! :update, @participatory_process_attachment
|
41
|
-
@form = form(ParticipatoryProcessAttachmentForm).from_model(@participatory_process_attachment)
|
42
|
-
end
|
43
|
-
|
44
|
-
def update
|
45
|
-
@participatory_process_attachment = collection.find(params[:id])
|
46
|
-
authorize! :update, @participatory_process_attachment
|
47
|
-
@form = form(ParticipatoryProcessAttachmentForm).from_params(params)
|
48
|
-
|
49
|
-
UpdateParticipatoryProcessAttachment.call(@participatory_process_attachment, @form) do
|
50
|
-
on(:ok) do
|
51
|
-
flash[:notice] = I18n.t("participatory_process_attachments.update.success", scope: "decidim.admin")
|
52
|
-
redirect_to participatory_process_attachments_path(participatory_process)
|
53
|
-
end
|
54
|
-
|
55
|
-
on(:invalid) do
|
56
|
-
flash.now[:alert] = I18n.t("participatory_process_attachments.update.error", scope: "decidim.admin")
|
57
|
-
render :edit
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def show
|
63
|
-
@participatory_process_attachment = collection.find(params[:id])
|
64
|
-
authorize! :read, @participatory_process_attachment
|
65
|
-
end
|
66
|
-
|
67
|
-
def destroy
|
68
|
-
@participatory_process_attachment = collection.find(params[:id])
|
69
|
-
authorize! :destroy, @participatory_process_attachment
|
70
|
-
@participatory_process_attachment.destroy!
|
71
|
-
|
72
|
-
flash[:notice] = I18n.t("participatory_process_attachments.destroy.success", scope: "decidim.admin")
|
73
|
-
|
74
|
-
redirect_to participatory_process_attachments_path(@participatory_process_attachment.participatory_process)
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def collection
|
80
|
-
@collection ||= participatory_process.attachments
|
17
|
+
def authorization_object
|
18
|
+
@attachment || Attachment
|
81
19
|
end
|
82
20
|
end
|
83
21
|
end
|
@@ -7,17 +7,17 @@ module Decidim
|
|
7
7
|
#
|
8
8
|
class UsersController < Admin::ApplicationController
|
9
9
|
def index
|
10
|
-
authorize! :index,
|
10
|
+
authorize! :index, :admin_users
|
11
11
|
@users = collection
|
12
12
|
end
|
13
13
|
|
14
14
|
def new
|
15
|
-
authorize! :new,
|
15
|
+
authorize! :new, :admin_users
|
16
16
|
@form = form(InviteAdminForm).instance
|
17
17
|
end
|
18
18
|
|
19
19
|
def create
|
20
|
-
authorize! :new,
|
20
|
+
authorize! :new, :admin_users
|
21
21
|
|
22
22
|
default_params = {
|
23
23
|
organization: current_organization,
|
@@ -42,7 +42,7 @@ module Decidim
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def resend_invitation
|
45
|
-
authorize! :invite,
|
45
|
+
authorize! :invite, :admin_users
|
46
46
|
|
47
47
|
InviteUserAgain.call(user, "invite_admin") do
|
48
48
|
on(:ok) do
|
@@ -58,7 +58,7 @@ module Decidim
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def destroy
|
61
|
-
authorize! :destroy,
|
61
|
+
authorize! :destroy, :admin_users
|
62
62
|
|
63
63
|
RemoveUserRole.call(user, "admin") do
|
64
64
|
on(:ok) do
|
data/app/forms/decidim/admin/{participatory_process_attachment_form.rb → attachment_form.rb}
RENAMED
@@ -3,14 +3,14 @@ module Decidim
|
|
3
3
|
module Admin
|
4
4
|
# A form object used to create attachments in a participatory process.
|
5
5
|
#
|
6
|
-
class
|
6
|
+
class AttachmentForm < Form
|
7
7
|
include TranslatableAttributes
|
8
8
|
|
9
9
|
attribute :file
|
10
10
|
translatable_attribute :title, String
|
11
11
|
translatable_attribute :description, String
|
12
12
|
|
13
|
-
mimic :
|
13
|
+
mimic :attachment
|
14
14
|
|
15
15
|
validates :file, presence: true, unless: :persisted?
|
16
16
|
validates :title, :description, translatable_presence: true
|
@@ -11,9 +11,13 @@ module Decidim
|
|
11
11
|
translatable_attribute :subtitle, String
|
12
12
|
translatable_attribute :description, String
|
13
13
|
translatable_attribute :short_description, String
|
14
|
+
translatable_attribute :domain, String
|
15
|
+
translatable_attribute :scope, String
|
14
16
|
|
15
17
|
mimic :participatory_process
|
16
18
|
|
19
|
+
attribute :end_date, Date
|
20
|
+
attribute :developer_group, String
|
17
21
|
attribute :slug, String
|
18
22
|
attribute :hashtag, String
|
19
23
|
attribute :promoted, Boolean
|
@@ -25,7 +29,10 @@ module Decidim
|
|
25
29
|
|
26
30
|
validate :slug, :slug_uniqueness
|
27
31
|
|
28
|
-
|
32
|
+
validates :hero_image, file_size: { less_than_or_equal_to: lambda { |_record| Decidim.maximum_attachment_size } }, file_content_type: { allow: ['image/jpeg', 'image/png'] }
|
33
|
+
validates :banner_image, file_size: { less_than_or_equal_to:lambda { |_record| Decidim.maximum_attachment_size } }, file_content_type: { allow: ['image/jpeg', 'image/png'] }
|
34
|
+
|
35
|
+
private
|
29
36
|
|
30
37
|
def slug_uniqueness
|
31
38
|
return unless current_organization.participatory_processes.where(slug: slug).where.not(id: id).any?
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Decidim
|
3
|
+
module Admin
|
4
|
+
# This class contains helpers needed in order for feature settings to
|
5
|
+
# properly render.
|
6
|
+
module FeatureSettingsHelper
|
7
|
+
TYPES = {
|
8
|
+
boolean: :check_box,
|
9
|
+
integer: :number_field,
|
10
|
+
string: :text_field,
|
11
|
+
text: :text_area
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
# Public: Renders a form field that matches a settings attribute's
|
15
|
+
# type.
|
16
|
+
#
|
17
|
+
# form - The form in which to render the field.
|
18
|
+
# attribute - The FeatureSettings::Attribute instance with the
|
19
|
+
# description of the attribute.
|
20
|
+
# name - The name of the field.
|
21
|
+
# options - Extra options to be passed to the field helper.
|
22
|
+
#
|
23
|
+
# Returns a rendered form field.
|
24
|
+
def settings_attribute_input(form, attribute, name, options = {})
|
25
|
+
form.send(TYPES[attribute.type.to_sym], name, options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -7,9 +7,8 @@ module Decidim
|
|
7
7
|
class AdminUser
|
8
8
|
include CanCan::Ability
|
9
9
|
|
10
|
-
def initialize(user)
|
11
|
-
return unless user
|
12
|
-
return unless user.role?(:admin)
|
10
|
+
def initialize(user, _context)
|
11
|
+
return unless user && user.role?(:admin)
|
13
12
|
|
14
13
|
can :manage, ParticipatoryProcess
|
15
14
|
can :manage, ParticipatoryProcessStep
|
@@ -25,7 +24,8 @@ module Decidim
|
|
25
24
|
|
26
25
|
can :manage, Feature
|
27
26
|
can :read, :admin_dashboard
|
28
|
-
can :manage,
|
27
|
+
can :manage, :admin_users
|
28
|
+
can :manage, Attachment
|
29
29
|
can :manage, Scope
|
30
30
|
can [:create, :index, :new, :read, :invite], User
|
31
31
|
can [:destroy], [User] do |user_to_destroy|
|
@@ -9,9 +9,9 @@ module Decidim
|
|
9
9
|
class Base
|
10
10
|
include CanCan::Ability
|
11
11
|
|
12
|
-
def initialize(user)
|
13
|
-
merge ::Decidim::Ability.new(user)
|
14
|
-
merge ParticipatoryProcessAdmin.new(user)
|
12
|
+
def initialize(user, context)
|
13
|
+
merge ::Decidim::Ability.new(user, context)
|
14
|
+
merge ParticipatoryProcessAdmin.new(user, context)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -11,12 +11,14 @@ module Decidim
|
|
11
11
|
class ParticipatoryProcessAdmin
|
12
12
|
include CanCan::Ability
|
13
13
|
|
14
|
-
def initialize(user)
|
15
|
-
|
16
|
-
participatory_processes = ManageableParticipatoryProcessesForUser.for(user)
|
17
|
-
return unless participatory_processes.any?
|
14
|
+
def initialize(user, _context)
|
15
|
+
@user = user
|
18
16
|
|
19
|
-
|
17
|
+
return unless user && !user.role?(:admin)
|
18
|
+
|
19
|
+
can :read, :admin_dashboard do
|
20
|
+
participatory_processes.any?
|
21
|
+
end
|
20
22
|
|
21
23
|
can :manage, ParticipatoryProcess do |process|
|
22
24
|
participatory_processes.include?(process)
|
@@ -25,12 +27,14 @@ module Decidim
|
|
25
27
|
cannot :create, ParticipatoryProcess
|
26
28
|
cannot :destroy, ParticipatoryProcess
|
27
29
|
|
30
|
+
cannot :manage, :admin_users
|
31
|
+
|
28
32
|
can :manage, ParticipatoryProcessUserRole do |role|
|
29
33
|
role.user != user
|
30
34
|
end
|
31
35
|
|
32
|
-
can :manage,
|
33
|
-
participatory_processes.include?(
|
36
|
+
can :manage, Attachment do |attachment|
|
37
|
+
participatory_processes.include?(attachment.attached_to)
|
34
38
|
end
|
35
39
|
|
36
40
|
can :manage, ParticipatoryProcessStep do |step|
|
@@ -45,6 +49,10 @@ module Decidim
|
|
45
49
|
participatory_processes.include?(category.participatory_process)
|
46
50
|
end
|
47
51
|
end
|
52
|
+
|
53
|
+
def participatory_processes
|
54
|
+
@participatory_processes ||= ManageableParticipatoryProcessesForUser.for(@user)
|
55
|
+
end
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
data/app/views/decidim/admin/{participatory_process_attachments → attachments}/_form.html.erb
RENAMED
File without changes
|