decidim-assemblies 0.8.4 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/app/assets/javascripts/decidim/assemblies/admin/assemblies.js.es6 +11 -9
- data/app/commands/decidim/assemblies/admin/create_assembly_admin.rb +93 -0
- data/app/commands/decidim/assemblies/admin/update_assembly_admin.rb +42 -0
- data/app/controllers/decidim/assemblies/admin/assemblies_controller.rb +2 -4
- data/app/controllers/decidim/assemblies/admin/assembly_user_roles_controller.rb +99 -0
- data/app/forms/decidim/assemblies/admin/assembly_user_role_form.rb +30 -0
- data/app/models/decidim/assemblies/abilities/admin/admin_ability.rb +1 -0
- data/app/models/decidim/assemblies/abilities/admin/assembly_admin_ability.rb +54 -0
- data/app/models/decidim/assemblies/abilities/admin/assembly_collaborator_ability.rb +25 -0
- data/app/models/decidim/assemblies/abilities/admin/assembly_moderator_ability.rb +33 -0
- data/app/models/decidim/assemblies/abilities/admin/assembly_role_ability.rb +65 -0
- data/app/models/decidim/assemblies/abilities/assembly_admin_ability.rb +15 -0
- data/app/models/decidim/assemblies/abilities/assembly_collaborator_ability.rb +15 -0
- data/app/models/decidim/assemblies/abilities/assembly_moderator_ability.rb +15 -0
- data/app/models/decidim/assemblies/abilities/assembly_role_ability.rb +51 -0
- data/app/models/decidim/assembly.rb +1 -0
- data/app/models/decidim/assembly_user_role.rb +22 -0
- data/app/queries/decidim/assemblies/assemblies_with_user_role.rb +48 -0
- data/app/views/decidim/assemblies/admin/assemblies/_form.html.erb +1 -1
- data/app/views/decidim/assemblies/admin/assembly_user_roles/_form.html.erb +22 -0
- data/app/views/decidim/assemblies/admin/assembly_user_roles/edit.html.erb +7 -0
- data/app/views/decidim/assemblies/admin/assembly_user_roles/index.html.erb +65 -0
- data/app/views/decidim/assemblies/admin/assembly_user_roles/new.html.erb +7 -0
- data/app/views/decidim/assemblies/assemblies/show.html.erb +5 -0
- data/app/views/layouts/decidim/admin/assembly.html.erb +19 -14
- data/config/locales/ca.yml +28 -1
- data/config/locales/en.yml +28 -0
- data/config/locales/es.yml +32 -5
- data/config/locales/eu.yml +28 -0
- data/config/locales/fi.yml +66 -38
- data/config/locales/fr.yml +28 -0
- data/config/locales/gl.yml +165 -0
- data/config/locales/it.yml +30 -2
- data/config/locales/nl.yml +28 -0
- data/config/locales/pl.yml +28 -0
- data/config/locales/pt-BR.yml +165 -0
- data/config/locales/pt.yml +48 -20
- data/config/locales/sv.yml +165 -0
- data/db/migrate/20180109105917_add_assembly_user_roles.rb +17 -0
- data/lib/decidim/assemblies/admin_engine.rb +11 -2
- data/lib/decidim/assemblies/engine.rb +9 -0
- data/lib/decidim/assemblies/participatory_space.rb +7 -2
- data/lib/decidim/assemblies/test/factories.rb +36 -0
- data/lib/decidim/assemblies/version.rb +1 -1
- metadata +34 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 239b54948da6dacd5224932fd59660b9593c5f47658af0ece3f2e77cac509574
|
4
|
+
data.tar.gz: f781b393aeaf19a7a5d5646c6fbb98fd450c79449ff054d0bb7d639490703ef7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ca312550fe3293500f448d66eca8c343192cf4e6f416f5e8e22c2fc8e106f3b7cb7ac4f444db1b5e29a413dede542e54754b06258ee8d124ce17061a11a26f3
|
7
|
+
data.tar.gz: 3a2eaf20e4de03122cf94a3a1b71d8e8058bf1acbcff54c01f973aa6f0a947e0142260e3d7bcbcf481925911728c70f7405fbc56faf716f22afc237ee17d95b3
|
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
$(() => {
|
2
|
-
|
3
|
-
|
2
|
+
((exports) => {
|
3
|
+
const $assemblyScopeEnabled = $('#assembly_scopes_enabled');
|
4
|
+
const $assemblyScopeId = $("#assembly_scope_id");
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
if ($('.edit_assembly, .new_assembly').length > 0) {
|
7
|
+
$assemblyScopeEnabled.on('change', (event) => {
|
8
|
+
const checked = event.target.checked;
|
9
|
+
exports.theDataPicker.enabled($assemblyScopeId, checked);
|
10
|
+
})
|
11
|
+
exports.theDataPicker.enabled($assemblyScopeId, $assemblyScopeEnabled.prop('checked'));
|
12
|
+
}
|
13
|
+
})(window);
|
12
14
|
});
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when creating a new participatory
|
7
|
+
# process admin in the system.
|
8
|
+
class CreateAssemblyAdmin < Rectify::Command
|
9
|
+
# Public: Initializes the command.
|
10
|
+
#
|
11
|
+
# form - A form object with the params.
|
12
|
+
# assembly - The Assembly that will hold the
|
13
|
+
# user role
|
14
|
+
def initialize(form, current_user, assembly)
|
15
|
+
@form = form
|
16
|
+
@current_user = current_user
|
17
|
+
@assembly = assembly
|
18
|
+
end
|
19
|
+
|
20
|
+
# Executes the command. Broadcasts these events:
|
21
|
+
#
|
22
|
+
# - :ok when everything is valid.
|
23
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
24
|
+
#
|
25
|
+
# Returns nothing.
|
26
|
+
def call
|
27
|
+
return broadcast(:invalid) if form.invalid?
|
28
|
+
|
29
|
+
ActiveRecord::Base.transaction do
|
30
|
+
create_or_invite_user
|
31
|
+
create_role
|
32
|
+
end
|
33
|
+
|
34
|
+
broadcast(:ok)
|
35
|
+
rescue ActiveRecord::RecordInvalid
|
36
|
+
form.errors.add(:email, :taken)
|
37
|
+
broadcast(:invalid)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
attr_reader :form, :assembly, :current_user, :user
|
43
|
+
|
44
|
+
def create_role
|
45
|
+
Decidim::AssemblyUserRole.find_or_create_by!(
|
46
|
+
role: form.role.to_sym,
|
47
|
+
user: user,
|
48
|
+
assembly: @assembly
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_or_invite_user
|
53
|
+
@user ||= existing_user || new_user
|
54
|
+
end
|
55
|
+
|
56
|
+
def existing_user
|
57
|
+
return @existing_user if defined?(@existing_user)
|
58
|
+
|
59
|
+
@existing_user = User.where(
|
60
|
+
email: form.email,
|
61
|
+
organization: assembly.organization
|
62
|
+
).first
|
63
|
+
|
64
|
+
InviteUserAgain.call(@existing_user, invitation_instructions) if @existing_user && !@existing_user.invitation_accepted?
|
65
|
+
|
66
|
+
@existing_user
|
67
|
+
end
|
68
|
+
|
69
|
+
def new_user
|
70
|
+
@new_user ||= InviteUser.call(user_form) do
|
71
|
+
on(:ok) do |user|
|
72
|
+
return user
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def user_form
|
78
|
+
OpenStruct.new(name: form.name,
|
79
|
+
email: form.email.downcase,
|
80
|
+
organization: assembly.organization,
|
81
|
+
admin: false,
|
82
|
+
invited_by: current_user,
|
83
|
+
invitation_instructions: invitation_instructions)
|
84
|
+
end
|
85
|
+
|
86
|
+
def invitation_instructions
|
87
|
+
return "invite_admin" if form.role == "admin"
|
88
|
+
"invite_collaborator"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when updated a participatory
|
7
|
+
# process admin in the system.
|
8
|
+
class UpdateAssemblyAdmin < Rectify::Command
|
9
|
+
# Public: Initializes the command.
|
10
|
+
#
|
11
|
+
# form - A form object with the params.
|
12
|
+
# user_role - The AssemblyUSerRole to update
|
13
|
+
def initialize(form, user_role)
|
14
|
+
@form = form
|
15
|
+
@user_role = user_role
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
25
|
+
return broadcast(:invalid) if form.invalid?
|
26
|
+
return broadcast(:invalid) unless user_role
|
27
|
+
|
28
|
+
update_role!
|
29
|
+
broadcast(:ok)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :form, :user_role
|
35
|
+
|
36
|
+
def update_role!
|
37
|
+
user_role.update_attributes!(role: form.role)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -6,7 +6,7 @@ module Decidim
|
|
6
6
|
# Controller that allows managing assemblies.
|
7
7
|
#
|
8
8
|
class AssembliesController < Decidim::Admin::ApplicationController
|
9
|
-
helper_method :current_assembly
|
9
|
+
helper_method :current_assembly, :current_participatory_space
|
10
10
|
layout "decidim/admin/assemblies"
|
11
11
|
|
12
12
|
def index
|
@@ -83,9 +83,7 @@ module Decidim
|
|
83
83
|
).first
|
84
84
|
end
|
85
85
|
|
86
|
-
|
87
|
-
current_assembly
|
88
|
-
end
|
86
|
+
alias current_participatory_space current_assembly
|
89
87
|
|
90
88
|
def collection
|
91
89
|
@collection ||= OrganizationAssemblies.new(current_user.organization).query
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
module Admin
|
6
|
+
# Controller that allows managing assembly user roles.
|
7
|
+
#
|
8
|
+
class AssemblyUserRolesController < Decidim::Assemblies::Admin::ApplicationController
|
9
|
+
include Concerns::AssemblyAdmin
|
10
|
+
|
11
|
+
def index
|
12
|
+
authorize! :read, Decidim::AssemblyUserRole
|
13
|
+
@assembly_user_roles = collection
|
14
|
+
end
|
15
|
+
|
16
|
+
def new
|
17
|
+
authorize! :create, Decidim::AssemblyUserRole
|
18
|
+
@form = form(AssemblyUserRoleForm).instance
|
19
|
+
end
|
20
|
+
|
21
|
+
def create
|
22
|
+
authorize! :create, Decidim::AssemblyUserRole
|
23
|
+
@form = form(AssemblyUserRoleForm).from_params(params)
|
24
|
+
|
25
|
+
CreateAssemblyAdmin.call(@form, current_user, current_assembly) do
|
26
|
+
on(:ok) do
|
27
|
+
flash[:notice] = I18n.t("assembly_user_roles.create.success", scope: "decidim.admin")
|
28
|
+
end
|
29
|
+
|
30
|
+
on(:invalid) do
|
31
|
+
flash[:alert] = I18n.t("assembly_user_roles.create.error", scope: "decidim.admin")
|
32
|
+
end
|
33
|
+
redirect_to assembly_user_roles_path(current_assembly)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def edit
|
38
|
+
@user_role = collection.find(params[:id])
|
39
|
+
authorize! :update, @user_role
|
40
|
+
@form = form(AssemblyUserRoleForm).from_model(@user_role.user)
|
41
|
+
end
|
42
|
+
|
43
|
+
def update
|
44
|
+
@user_role = collection.find(params[:id])
|
45
|
+
authorize! :update, @user_role
|
46
|
+
@form = form(AssemblyUserRoleForm).from_params(params)
|
47
|
+
|
48
|
+
UpdateAssemblyAdmin.call(@form, @user_role) do
|
49
|
+
on(:ok) do
|
50
|
+
flash[:notice] = I18n.t("assembly_user_roles.update.success", scope: "decidim.admin")
|
51
|
+
redirect_to assembly_user_roles_path(current_assembly)
|
52
|
+
end
|
53
|
+
|
54
|
+
on(:invalid) do
|
55
|
+
flash.now[:alert] = I18n.t("assembly_user_roles.update.error", scope: "decidim.admin")
|
56
|
+
render :edit
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def destroy
|
62
|
+
@assembly_user_role = collection.find(params[:id])
|
63
|
+
authorize! :destroy, @assembly_user_role
|
64
|
+
@assembly_user_role.destroy!
|
65
|
+
|
66
|
+
flash[:notice] = I18n.t("assembly_user_roles.destroy.success", scope: "decidim.admin")
|
67
|
+
|
68
|
+
redirect_to assembly_user_roles_path(@assembly_user_role.assembly)
|
69
|
+
end
|
70
|
+
|
71
|
+
def resend_invitation
|
72
|
+
@user_role = collection.find(params[:id])
|
73
|
+
authorize! :invite, @user_role
|
74
|
+
|
75
|
+
InviteUserAgain.call(@user_role.user, "invite_admin") do
|
76
|
+
on(:ok) do
|
77
|
+
flash[:notice] = I18n.t("users.resend_invitation.success", scope: "decidim.admin")
|
78
|
+
end
|
79
|
+
|
80
|
+
on(:invalid) do
|
81
|
+
flash[:alert] = I18n.t("users.resend_invitation.error", scope: "decidim.admin")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
redirect_to assembly_user_roles_path(current_assembly)
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def collection
|
91
|
+
@collection ||= Decidim::AssemblyUserRole
|
92
|
+
.includes(:user)
|
93
|
+
.where(assembly: current_assembly)
|
94
|
+
.order(:role, "decidim_users.name")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
module Admin
|
6
|
+
# A form object used to create assembly user roles from the admin dashboard.
|
7
|
+
#
|
8
|
+
class AssemblyUserRoleForm < Form
|
9
|
+
mimic :assembly_user_role
|
10
|
+
|
11
|
+
attribute :name, String
|
12
|
+
attribute :email, String
|
13
|
+
attribute :role, String
|
14
|
+
|
15
|
+
validates :email, :role, presence: true
|
16
|
+
validates :name, presence: true
|
17
|
+
validates :role, inclusion: { in: Decidim::AssemblyUserRole::ROLES }
|
18
|
+
|
19
|
+
def roles
|
20
|
+
Decidim::AssemblyUserRole::ROLES.map do |role|
|
21
|
+
[
|
22
|
+
I18n.t(role, scope: "decidim.admin.models.assembly_user_role.roles"),
|
23
|
+
role
|
24
|
+
]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
module Abilities
|
6
|
+
module Admin
|
7
|
+
# Defines the abilities for an assembly admin user. Intended to be used
|
8
|
+
# with `cancancan`.
|
9
|
+
class AssemblyAdminAbility < Decidim::Assemblies::Abilities::Admin::AssemblyRoleAbility
|
10
|
+
def define_abilities
|
11
|
+
super
|
12
|
+
|
13
|
+
can :manage, Assembly do |assembly|
|
14
|
+
can_manage_assembly?(assembly)
|
15
|
+
end
|
16
|
+
|
17
|
+
cannot :create, Assembly
|
18
|
+
cannot :destroy, Assembly
|
19
|
+
end
|
20
|
+
|
21
|
+
def role
|
22
|
+
:admin
|
23
|
+
end
|
24
|
+
|
25
|
+
def define_assembly_abilities
|
26
|
+
can :manage, Feature do |feature|
|
27
|
+
can_manage_assembly?(feature.participatory_space)
|
28
|
+
end
|
29
|
+
|
30
|
+
can :manage, Category do |category|
|
31
|
+
can_manage_assembly?(category.participatory_space)
|
32
|
+
end
|
33
|
+
|
34
|
+
can :manage, Attachment do |attachment|
|
35
|
+
attachment.attached_to.is_a?(Decidim::Assembly) && can_manage_assembly?(attachment.attached_to)
|
36
|
+
end
|
37
|
+
|
38
|
+
can :manage, AssemblyUserRole do |role|
|
39
|
+
can_manage_assembly?(role.assembly) && role.user != @user
|
40
|
+
end
|
41
|
+
|
42
|
+
can :manage, Moderation do |moderation|
|
43
|
+
can_manage_assembly?(moderation.participatory_space)
|
44
|
+
end
|
45
|
+
|
46
|
+
can [:unreport, :hide], Reportable do |reportable|
|
47
|
+
can_manage_assembly?(reportable.feature.participatory_space)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
module Abilities
|
6
|
+
module Admin
|
7
|
+
# Defines the abilities for an assembly collaborator user. Intended to be used
|
8
|
+
# with `cancancan`.
|
9
|
+
class AssemblyCollaboratorAbility < Decidim::Assemblies::Abilities::Admin::AssemblyRoleAbility
|
10
|
+
def define_abilities
|
11
|
+
super
|
12
|
+
|
13
|
+
can [:read, :preview], Assembly do |assembly|
|
14
|
+
can_manage_assembly?(assembly)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def role
|
19
|
+
:collaborator
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Assemblies
|
5
|
+
module Abilities
|
6
|
+
module Admin
|
7
|
+
# Defines the abilities for an assembly moderator user. Intended to be used
|
8
|
+
# with `cancancan`.
|
9
|
+
class AssemblyModeratorAbility < Decidim::Assemblies::Abilities::Admin::AssemblyRoleAbility
|
10
|
+
def define_abilities
|
11
|
+
super
|
12
|
+
|
13
|
+
can [:index, :read], Assembly do |assembly|
|
14
|
+
can_manage_assembly?(assembly)
|
15
|
+
end
|
16
|
+
|
17
|
+
can :manage, Moderation do |moderation|
|
18
|
+
can_manage_assembly?(moderation.participatory_space)
|
19
|
+
end
|
20
|
+
|
21
|
+
can [:unreport, :hide], Reportable do |reportable|
|
22
|
+
can_manage_assembly?(reportable.feature.participatory_space)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def role
|
27
|
+
:moderator
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|