decidim-initiatives 0.11.2 → 0.12.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/app/assets/config/decidim_initiatives_manifest.css +4 -0
- data/app/assets/config/decidim_initiatives_manifest.js +0 -2
- data/app/assets/stylesheet/decidim/initiatives/{application.css.scss → initiatives.scss} +0 -1
- data/app/cells/decidim/initiatives/initiative_cell.rb +19 -0
- data/app/cells/decidim/initiatives/initiative_m/author.erb +10 -0
- data/app/cells/decidim/initiatives/initiative_m/footer.erb +28 -0
- data/app/cells/decidim/initiatives/initiative_m/tags.erb +9 -0
- data/app/cells/decidim/initiatives/initiative_m_cell.rb +45 -0
- data/app/commands/decidim/initiatives/vote_initiative.rb +22 -0
- data/app/controllers/concerns/decidim/initiatives/admin/initiative_admin.rb +0 -4
- data/app/controllers/concerns/decidim/initiatives/needs_initiative.rb +18 -23
- data/app/controllers/decidim/initiatives/admin/application_controller.rb +13 -0
- data/app/controllers/decidim/initiatives/admin/committee_requests_controller.rb +4 -4
- data/app/controllers/decidim/initiatives/admin/initiative_attachments_controller.rb +1 -1
- data/app/controllers/decidim/initiatives/admin/initiatives_controller.rb +11 -11
- data/app/controllers/decidim/initiatives/admin/initiatives_type_scopes_controller.rb +5 -5
- data/app/controllers/decidim/initiatives/admin/initiatives_types_controller.rb +7 -7
- data/app/controllers/decidim/initiatives/application_controller.rb +30 -0
- data/app/controllers/decidim/initiatives/committee_requests_controller.rb +4 -5
- data/app/controllers/decidim/initiatives/create_initiative_controller.rb +3 -3
- data/app/controllers/decidim/initiatives/initiative_types_controller.rb +2 -2
- data/app/controllers/decidim/initiatives/initiative_votes_controller.rb +3 -17
- data/app/controllers/decidim/initiatives/initiatives_controller.rb +3 -7
- data/app/controllers/decidim/initiatives/initiatives_type_scopes_controller.rb +2 -2
- data/app/events/decidim/initiatives/endorse_initiative_event.rb +4 -45
- data/app/events/decidim/initiatives/milestone_completed_event.rb +17 -0
- data/app/models/decidim/initiative.rb +5 -4
- data/app/models/decidim/initiatives_committee_member.rb +1 -0
- data/app/permissions/decidim/initiatives/admin/permissions.rb +188 -0
- data/app/permissions/decidim/initiatives/permissions.rb +139 -0
- data/app/presenters/decidim/initiative_presenter.rb +16 -0
- data/app/views/decidim/initiatives/_initiative.html.erb +1 -35
- data/app/views/decidim/initiatives/admin/committee_requests/index.html.erb +2 -3
- data/app/views/decidim/initiatives/admin/initiatives/_form.html.erb +3 -3
- data/app/views/decidim/initiatives/admin/initiatives/edit.html.erb +8 -8
- data/app/views/decidim/initiatives/admin/initiatives/index.html.erb +4 -4
- data/app/views/decidim/initiatives/admin/initiatives_type_scopes/edit.html.erb +1 -1
- data/app/views/decidim/initiatives/admin/initiatives_types/_form.html.erb +0 -2
- data/app/views/decidim/initiatives/admin/initiatives_types/_initiative_type_scopes.html.erb +2 -2
- data/app/views/decidim/initiatives/admin/initiatives_types/edit.html.erb +1 -1
- data/app/views/decidim/initiatives/admin/initiatives_types/index.html.erb +2 -2
- data/app/views/decidim/initiatives/committee_requests/new.html.erb +3 -5
- data/app/views/decidim/initiatives/initiatives/_index_header.html.erb +2 -2
- data/app/views/decidim/initiatives/initiatives/_vote_button.html.erb +17 -15
- data/app/views/decidim/initiatives/initiatives/_vote_cabin.html.erb +1 -1
- data/app/views/decidim/initiatives/initiatives/index.html.erb +0 -1
- data/app/views/decidim/initiatives/initiatives/show.html.erb +0 -1
- data/app/views/decidim/initiatives/initiatives/signature_identities.html.erb +15 -13
- data/app/views/layouts/decidim/admin/initiative.html.erb +9 -6
- data/app/views/layouts/decidim/admin/initiatives.html.erb +11 -3
- data/app/views/layouts/decidim/initiative_creation.html.erb +0 -1
- data/config/locales/ca.yml +31 -11
- data/config/locales/en.yml +32 -11
- data/config/locales/es.yml +33 -12
- data/config/locales/eu.yml +32 -11
- data/config/locales/fi.yml +32 -11
- data/config/locales/fr.yml +32 -11
- data/config/locales/gl.yml +32 -11
- data/config/locales/it.yml +32 -11
- data/config/locales/nl.yml +32 -11
- data/config/locales/pl.yml +42 -13
- data/config/locales/pt-BR.yml +32 -11
- data/config/locales/pt.yml +32 -11
- data/config/locales/sv.yml +32 -11
- data/config/locales/uk.yml +43 -14
- data/db/migrate/20171109132011_enable_pg_trgm_extension_for_initiatives.rb +18 -0
- data/lib/decidim/initiatives/admin_engine.rb +1 -15
- data/lib/decidim/initiatives/engine.rb +6 -11
- data/lib/decidim/initiatives/participatory_space.rb +12 -4
- data/lib/decidim/initiatives/test/factories.rb +17 -1
- data/lib/decidim/initiatives/version.rb +1 -1
- metadata +27 -29
- data/app/controllers/concerns/decidim/initiatives/action_authorization.rb +0 -38
- data/app/models/decidim/initiatives/abilities/admin/attachments_ability.rb +0 -55
- data/app/models/decidim/initiatives/abilities/admin/committee_admin_ability.rb +0 -36
- data/app/models/decidim/initiatives/abilities/admin/committee_user_ability.rb +0 -50
- data/app/models/decidim/initiatives/abilities/admin/components_ability.rb +0 -24
- data/app/models/decidim/initiatives/abilities/admin/initiative_admin_ability.rb +0 -65
- data/app/models/decidim/initiatives/abilities/admin/initiative_type_ability.rb +0 -42
- data/app/models/decidim/initiatives/abilities/admin/initiative_user_ability.rb +0 -68
- data/app/models/decidim/initiatives/abilities/current_user_ability.rb +0 -58
- data/app/models/decidim/initiatives/abilities/everyone_ability.rb +0 -22
- data/app/models/decidim/initiatives/abilities/non_logged_user_ability.rb +0 -33
- data/app/models/decidim/initiatives/abilities/vote_ability.rb +0 -57
- data/app/views/decidim/initiatives/initiatives/_supports_count.html.erb +0 -6
- data/db/migrate/20171109132011_enable_pg_extensions.rb +0 -9
@@ -9,13 +9,13 @@ module Decidim
|
|
9
9
|
|
10
10
|
# GET /admin/initiatives_types/:initiatives_type_id/initiatives_type_scopes/new
|
11
11
|
def new
|
12
|
-
|
12
|
+
enforce_permission_to :create, :initiative_type_scope
|
13
13
|
@form = initiative_type_scope_form.instance
|
14
14
|
end
|
15
15
|
|
16
16
|
# POST /admin/initiatives_types/:initiatives_type_id/initiatives_type_scopes
|
17
17
|
def create
|
18
|
-
|
18
|
+
enforce_permission_to :create, :initiative_type_scope
|
19
19
|
@form = initiative_type_scope_form
|
20
20
|
.from_params(params, type_id: params[:initiatives_type_id])
|
21
21
|
|
@@ -34,13 +34,13 @@ module Decidim
|
|
34
34
|
|
35
35
|
# GET /admin/initiatives_types/:initiatives_type_id/initiatives_type_scopes/:id/edit
|
36
36
|
def edit
|
37
|
-
|
37
|
+
enforce_permission_to :edit, :initiative_type_scope, initiative_type_scope: current_initiative_type_scope
|
38
38
|
@form = initiative_type_scope_form.from_model(current_initiative_type_scope)
|
39
39
|
end
|
40
40
|
|
41
41
|
# PUT /admin/initiatives_types/:initiatives_type_id/initiatives_type_scopes/:id
|
42
42
|
def update
|
43
|
-
|
43
|
+
enforce_permission_to :update, :initiative_type_scope, initiative_type_scope: current_initiative_type_scope
|
44
44
|
@form = initiative_type_scope_form.from_params(params)
|
45
45
|
|
46
46
|
UpdateInitiativeTypeScope.call(current_initiative_type_scope, @form) do
|
@@ -58,7 +58,7 @@ module Decidim
|
|
58
58
|
|
59
59
|
# DELETE /admin/initiatives_types/:initiatives_type_id/initiatives_type_scopes/:id
|
60
60
|
def destroy
|
61
|
-
|
61
|
+
enforce_permission_to :destroy, :initiative_type_scope, initiative_type_scope: current_initiative_type_scope
|
62
62
|
current_initiative_type_scope.destroy!
|
63
63
|
|
64
64
|
redirect_to edit_initiatives_type_path(current_initiative_type_scope.type), flash: {
|
@@ -7,25 +7,25 @@ module Decidim
|
|
7
7
|
module Admin
|
8
8
|
# Controller used to manage the available initiative types for the current
|
9
9
|
# organization.
|
10
|
-
class InitiativesTypesController < ApplicationController
|
10
|
+
class InitiativesTypesController < Decidim::Initiatives::Admin::ApplicationController
|
11
11
|
helper_method :current_initiative_type
|
12
12
|
|
13
13
|
# GET /admin/initiatives_types
|
14
14
|
def index
|
15
|
-
|
15
|
+
enforce_permission_to :index, :initiative_type
|
16
16
|
|
17
17
|
@initiatives_types = InitiativeTypes.for(current_organization)
|
18
18
|
end
|
19
19
|
|
20
20
|
# GET /admin/initiatives_types/new
|
21
21
|
def new
|
22
|
-
|
22
|
+
enforce_permission_to :create, :initiative_type
|
23
23
|
@form = initiative_type_form.instance
|
24
24
|
end
|
25
25
|
|
26
26
|
# POST /admin/initiatives_types
|
27
27
|
def create
|
28
|
-
|
28
|
+
enforce_permission_to :create, :initiative_type
|
29
29
|
@form = initiative_type_form.from_params(params)
|
30
30
|
|
31
31
|
CreateInitiativeType.call(@form) do
|
@@ -43,7 +43,7 @@ module Decidim
|
|
43
43
|
|
44
44
|
# GET /admin/initiatives_types/:id/edit
|
45
45
|
def edit
|
46
|
-
|
46
|
+
enforce_permission_to :edit, :initiative_type, initiative_type: current_initiative_type
|
47
47
|
@form = initiative_type_form
|
48
48
|
.from_model(current_initiative_type,
|
49
49
|
initiative_type: current_initiative_type)
|
@@ -51,7 +51,7 @@ module Decidim
|
|
51
51
|
|
52
52
|
# PUT /admin/initiatives_types/:id
|
53
53
|
def update
|
54
|
-
|
54
|
+
enforce_permission_to :update, :initiative_type, initiative_type: current_initiative_type
|
55
55
|
|
56
56
|
@form = initiative_type_form
|
57
57
|
.from_params(params, initiative_type: current_initiative_type)
|
@@ -71,7 +71,7 @@ module Decidim
|
|
71
71
|
|
72
72
|
# DELETE /admin/initiatives_types/:id
|
73
73
|
def destroy
|
74
|
-
|
74
|
+
enforce_permission_to :destroy, :initiative_type, initiative_type: current_initiative_type
|
75
75
|
current_initiative_type.destroy!
|
76
76
|
|
77
77
|
redirect_to initiatives_types_path, flash: {
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Initiatives
|
5
|
+
# The main admin application controller for initiatives
|
6
|
+
class ApplicationController < Decidim::ApplicationController
|
7
|
+
layout "decidim/admin/initiatives"
|
8
|
+
|
9
|
+
include NeedsPermission
|
10
|
+
|
11
|
+
def permissions_context
|
12
|
+
super.merge(
|
13
|
+
current_participatory_space: try(:current_participatory_space)
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def permission_class_chain
|
18
|
+
[
|
19
|
+
Decidim::Initiatives::Permissions,
|
20
|
+
Decidim::Admin::Permissions,
|
21
|
+
Decidim::Permissions
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
def permission_scope
|
26
|
+
:public
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -3,22 +3,21 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Initiatives
|
5
5
|
# Controller in charge of managing committee membership
|
6
|
-
class CommitteeRequestsController < Decidim::ApplicationController
|
6
|
+
class CommitteeRequestsController < Decidim::Initiatives::ApplicationController
|
7
7
|
include Decidim::Initiatives::NeedsInitiative
|
8
8
|
|
9
|
-
helper Decidim::ActionAuthorizationHelper
|
10
9
|
helper InitiativeHelper
|
11
10
|
|
12
|
-
|
11
|
+
layout "layouts/decidim/application"
|
13
12
|
|
14
13
|
# GET /initiatives/:initiative_id/committee_requests/new
|
15
14
|
def new
|
16
|
-
|
15
|
+
enforce_permission_to :request_membership, :initiative, initiative: current_initiative
|
17
16
|
end
|
18
17
|
|
19
18
|
# GET /initiatives/:initiative_id/committee_requests/spawn
|
20
19
|
def spawn
|
21
|
-
|
20
|
+
enforce_permission_to :request_membership, :initiative, initiative: current_initiative
|
22
21
|
|
23
22
|
SpawnCommitteeRequest.call(current_initiative, current_user) do
|
24
23
|
on(:ok) do
|
@@ -5,7 +5,7 @@ module Decidim
|
|
5
5
|
require "wicked"
|
6
6
|
|
7
7
|
# Controller in charge of managing the create initiative wizard.
|
8
|
-
class CreateInitiativeController < Decidim::ApplicationController
|
8
|
+
class CreateInitiativeController < Decidim::Initiatives::ApplicationController
|
9
9
|
layout "layouts/decidim/initiative_creation"
|
10
10
|
|
11
11
|
include Wicked::Wizard
|
@@ -28,12 +28,12 @@ module Decidim
|
|
28
28
|
:finish
|
29
29
|
|
30
30
|
def show
|
31
|
-
|
31
|
+
enforce_permission_to :create, :initiative
|
32
32
|
send("#{step}_step", initiative: session[:initiative])
|
33
33
|
end
|
34
34
|
|
35
35
|
def update
|
36
|
-
|
36
|
+
enforce_permission_to :create, :initiative
|
37
37
|
send("#{step}_step", params)
|
38
38
|
end
|
39
39
|
|
@@ -3,10 +3,10 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Initiatives
|
5
5
|
# Exposes the initiative type text search so users can choose a type writing its name.
|
6
|
-
class InitiativeTypesController < Decidim::ApplicationController
|
6
|
+
class InitiativeTypesController < Decidim::Initiatives::ApplicationController
|
7
7
|
# GET /initiative_types/search
|
8
8
|
def search
|
9
|
-
|
9
|
+
enforce_permission_to :search, :initiative_type
|
10
10
|
|
11
11
|
types = FreetextInitiativeTypes.for(current_organization, I18n.locale, params[:term])
|
12
12
|
render json: { results: types.map { |type| { id: type.id.to_s, text: type.title[I18n.locale.to_s] } } }
|
@@ -3,18 +3,16 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Initiatives
|
5
5
|
# Exposes the initiative vote resource so users can vote initiatives.
|
6
|
-
class InitiativeVotesController < Decidim::ApplicationController
|
6
|
+
class InitiativeVotesController < Decidim::Initiatives::ApplicationController
|
7
7
|
include Decidim::Initiatives::NeedsInitiative
|
8
8
|
|
9
9
|
before_action :authenticate_user!
|
10
10
|
|
11
|
-
helper Decidim::ActionAuthorizationHelper
|
12
11
|
helper InitiativeHelper
|
13
|
-
include Decidim::Initiatives::ActionAuthorization
|
14
12
|
|
15
13
|
# POST /initiatives/:initiative_id/initiative_vote
|
16
14
|
def create
|
17
|
-
|
15
|
+
enforce_permission_to :vote, :initiative, initiative: current_initiative, group_id: params[:group_id]
|
18
16
|
VoteInitiative.call(current_initiative, current_user, params[:group_id]) do
|
19
17
|
on(:ok) do
|
20
18
|
current_initiative.reload
|
@@ -31,7 +29,7 @@ module Decidim
|
|
31
29
|
|
32
30
|
# DELETE /initiatives/:initiative_id/initiative_vote
|
33
31
|
def destroy
|
34
|
-
|
32
|
+
enforce_permission_to :unvote, :initiative, initiative: current_initiative, group_id: params[:group_id]
|
35
33
|
UnvoteInitiative.call(current_initiative, current_user, params[:group_id]) do
|
36
34
|
on(:ok) do
|
37
35
|
current_initiative.reload
|
@@ -39,18 +37,6 @@ module Decidim
|
|
39
37
|
end
|
40
38
|
end
|
41
39
|
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def ability_context
|
46
|
-
{
|
47
|
-
current_settings: try(:current_settings),
|
48
|
-
component_settings: try(:component_settings),
|
49
|
-
current_organization: try(:current_organization),
|
50
|
-
current_component: try(:current_component),
|
51
|
-
params: try(:params)
|
52
|
-
}
|
53
|
-
end
|
54
40
|
end
|
55
41
|
end
|
56
42
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Initiatives
|
5
5
|
# This controller contains the logic regarding citizen initiatives
|
6
|
-
class InitiativesController < Decidim::ApplicationController
|
6
|
+
class InitiativesController < Decidim::Initiatives::ApplicationController
|
7
7
|
include ParticipatorySpaceContext
|
8
8
|
participatory_space_layout only: [:show]
|
9
9
|
|
@@ -11,7 +11,6 @@ module Decidim
|
|
11
11
|
helper Decidim::AttachmentsHelper
|
12
12
|
helper Decidim::FiltersHelper
|
13
13
|
helper Decidim::OrdersHelper
|
14
|
-
helper Decidim::ActionAuthorizationHelper
|
15
14
|
helper Decidim::ResourceHelper
|
16
15
|
helper Decidim::IconHelper
|
17
16
|
helper Decidim::Comments::CommentsHelper
|
@@ -20,7 +19,6 @@ module Decidim
|
|
20
19
|
helper InitiativeHelper
|
21
20
|
include InitiativeSlug
|
22
21
|
|
23
|
-
include Decidim::Initiatives::ActionAuthorization
|
24
22
|
include FilterResource
|
25
23
|
include Paginable
|
26
24
|
include Orderable
|
@@ -29,16 +27,14 @@ module Decidim
|
|
29
27
|
|
30
28
|
helper_method :collection, :initiatives, :filter, :stats
|
31
29
|
|
32
|
-
skip_authorization_check only: :signature_identities
|
33
|
-
|
34
30
|
# GET /initiatives
|
35
31
|
def index
|
36
|
-
|
32
|
+
enforce_permission_to :list, :initiative
|
37
33
|
end
|
38
34
|
|
39
35
|
# GET /initiatives/:id
|
40
36
|
def show
|
41
|
-
|
37
|
+
enforce_permission_to :read, :initiative, initiative: current_initiative
|
42
38
|
end
|
43
39
|
|
44
40
|
# GET /initiatives/:id/signature_identities
|
@@ -3,12 +3,12 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Initiatives
|
5
5
|
# Exposes the initiative type text search so users can choose a type writing its name.
|
6
|
-
class InitiativesTypeScopesController < Decidim::ApplicationController
|
6
|
+
class InitiativesTypeScopesController < Decidim::Initiatives::ApplicationController
|
7
7
|
helper_method :scoped_types
|
8
8
|
|
9
9
|
# GET /initiative_type_scopes/search
|
10
10
|
def search
|
11
|
-
|
11
|
+
enforce_permission_to :search, :initiative_type_scope
|
12
12
|
render layout: false
|
13
13
|
end
|
14
14
|
|
@@ -2,52 +2,11 @@
|
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
module Initiatives
|
5
|
-
class EndorseInitiativeEvent < Decidim::Events::
|
6
|
-
include Decidim::Events::
|
7
|
-
include Decidim::Events::NotificationEvent
|
5
|
+
class EndorseInitiativeEvent < Decidim::Events::SimpleEvent
|
6
|
+
include Decidim::Events::AuthorEvent
|
8
7
|
|
9
|
-
def
|
10
|
-
|
11
|
-
"decidim.initiatives.events.endorse_initiative_event.email_subject",
|
12
|
-
resource_title: resource_title,
|
13
|
-
author_nickname: author.nickname,
|
14
|
-
author_name: author.name
|
15
|
-
)
|
16
|
-
end
|
17
|
-
|
18
|
-
def email_intro
|
19
|
-
I18n.t(
|
20
|
-
"decidim.initiatives.events.endorse_initiative_event.email_intro",
|
21
|
-
resource_title: resource_title,
|
22
|
-
author_nickname: author.nickname,
|
23
|
-
author_name: author.name
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
def email_outro
|
28
|
-
I18n.t(
|
29
|
-
"decidim.initiatives.events.endorse_initiative_event.email_outro",
|
30
|
-
resource_title: resource_title,
|
31
|
-
author_nickname: author.nickname,
|
32
|
-
author_name: author.name
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
def notification_title
|
37
|
-
I18n.t(
|
38
|
-
"decidim.initiatives.events.endorse_initiative_event.notification_title",
|
39
|
-
resource_title: resource_title,
|
40
|
-
resource_path: resource_path,
|
41
|
-
author_nickname: author.nickname,
|
42
|
-
author_name: author.name,
|
43
|
-
author_path: author.profile_path
|
44
|
-
).html_safe
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def author
|
50
|
-
@author ||= Decidim::UserPresenter.new(resource.author)
|
8
|
+
def i18n_scope
|
9
|
+
"decidim.initiatives.events.endorse_initiative_event"
|
51
10
|
end
|
52
11
|
end
|
53
12
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen-string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Initiatives
|
5
|
+
class MilestoneCompletedEvent < Decidim::Events::SimpleEvent
|
6
|
+
i18n_attributes :percentage
|
7
|
+
|
8
|
+
def percentage
|
9
|
+
extra[:percentage]
|
10
|
+
end
|
11
|
+
|
12
|
+
def participatory_space
|
13
|
+
resource
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -15,6 +15,7 @@ module Decidim
|
|
15
15
|
include Decidim::Traceable
|
16
16
|
include Decidim::Loggable
|
17
17
|
include Decidim::Initiatives::InitiativeSlug
|
18
|
+
include Decidim::Resourceable
|
18
19
|
|
19
20
|
belongs_to :organization,
|
20
21
|
foreign_key: "decidim_organization_id",
|
@@ -78,12 +79,12 @@ module Decidim
|
|
78
79
|
scope :public_spaces, -> { published }
|
79
80
|
|
80
81
|
scope :order_by_most_recent, -> { order(created_at: :desc) }
|
81
|
-
scope :order_by_supports, -> { order("initiative_votes_count + coalesce(offline_votes, 0) desc") }
|
82
|
+
scope :order_by_supports, -> { order(Arel.sql("initiative_votes_count + coalesce(offline_votes, 0) desc")) }
|
82
83
|
scope :order_by_most_commented, lambda {
|
83
84
|
select("decidim_initiatives.*")
|
84
85
|
.left_joins(:comments)
|
85
86
|
.group("decidim_initiatives.id")
|
86
|
-
.order("count(decidim_comments_comments.id) desc")
|
87
|
+
.order(Arel.sql("count(decidim_comments_comments.id) desc"))
|
87
88
|
}
|
88
89
|
|
89
90
|
after_save :notify_state_change
|
@@ -92,7 +93,7 @@ module Decidim
|
|
92
93
|
def self.order_randomly(seed)
|
93
94
|
transaction do
|
94
95
|
connection.execute("SELECT setseed(#{connection.quote(seed)})")
|
95
|
-
select('"decidim_initiatives".*, RANDOM()').order("RANDOM()").load
|
96
|
+
select('"decidim_initiatives".*, RANDOM()').order(Arel.sql("RANDOM()")).load
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
@@ -223,7 +224,7 @@ module Decidim
|
|
223
224
|
|
224
225
|
def supports_count
|
225
226
|
face_to_face_votes = offline_votes.nil? || online? ? 0 : offline_votes
|
226
|
-
digital_votes = offline? ? 0 : initiative_votes_count
|
227
|
+
digital_votes = offline? ? 0 : (initiative_votes_count + initiative_supports_count)
|
227
228
|
digital_votes + face_to_face_votes
|
228
229
|
end
|
229
230
|
|
@@ -0,0 +1,188 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Initiatives
|
5
|
+
module Admin
|
6
|
+
class Permissions < Decidim::DefaultPermissions
|
7
|
+
def permissions
|
8
|
+
# The public part needs to be implemented yet
|
9
|
+
return permission_action if permission_action.scope != :admin
|
10
|
+
return permission_action unless user
|
11
|
+
|
12
|
+
user_can_enter_space_area?
|
13
|
+
|
14
|
+
return permission_action if initiative && !initiative.is_a?(Decidim::Initiative)
|
15
|
+
|
16
|
+
user_can_read_participatory_space?
|
17
|
+
|
18
|
+
if !user.admin? && initiative&.has_authorship?(user)
|
19
|
+
initiative_committee_action?
|
20
|
+
initiative_user_action?
|
21
|
+
attachment_action?
|
22
|
+
|
23
|
+
return permission_action
|
24
|
+
end
|
25
|
+
|
26
|
+
if !user.admin? && has_initiatives?
|
27
|
+
read_initiative_list_action?
|
28
|
+
|
29
|
+
return permission_action
|
30
|
+
end
|
31
|
+
|
32
|
+
return permission_action unless user.admin?
|
33
|
+
|
34
|
+
initiative_type_action?
|
35
|
+
initiative_type_scope_action?
|
36
|
+
initiative_committee_action?
|
37
|
+
initiative_admin_user_action?
|
38
|
+
allow! if permission_action.subject == :attachment
|
39
|
+
|
40
|
+
permission_action
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def initiative
|
46
|
+
@initiative ||= context.fetch(:initiative, nil) || context.fetch(:current_participatory_space, nil)
|
47
|
+
end
|
48
|
+
|
49
|
+
def user_can_read_participatory_space?
|
50
|
+
return unless permission_action.action == :read &&
|
51
|
+
permission_action.subject == :participatory_space
|
52
|
+
|
53
|
+
toggle_allow(user.admin? || initiative.has_authorship?(user))
|
54
|
+
end
|
55
|
+
|
56
|
+
def user_can_enter_space_area?
|
57
|
+
return unless permission_action.action == :enter &&
|
58
|
+
permission_action.subject == :space_area &&
|
59
|
+
context.fetch(:space_name, nil) == :initiatives
|
60
|
+
|
61
|
+
toggle_allow(user.admin? || has_initiatives?)
|
62
|
+
end
|
63
|
+
|
64
|
+
def has_initiatives?
|
65
|
+
(InitiativesCreated.by(user) | InitiativesPromoted.by(user)).any?
|
66
|
+
end
|
67
|
+
|
68
|
+
def attachment_action?
|
69
|
+
return unless permission_action.subject == :attachment
|
70
|
+
|
71
|
+
attachment = context.fetch(:attachment, nil)
|
72
|
+
attached = attachment&.attached_to
|
73
|
+
|
74
|
+
case permission_action.action
|
75
|
+
when :update, :destroy
|
76
|
+
toggle_allow(attached && attached.is_a?(Decidim::Initiative))
|
77
|
+
when :read, :create
|
78
|
+
allow!
|
79
|
+
else
|
80
|
+
disallow!
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def initiative_type_action?
|
85
|
+
return unless permission_action.subject == :initiative_type
|
86
|
+
|
87
|
+
initiative_type = context.fetch(:initiative_type, nil)
|
88
|
+
|
89
|
+
case permission_action.action
|
90
|
+
when :destroy
|
91
|
+
scopes_are_empty = initiative_type && initiative_type.scopes.all? { |scope| scope.initiatives.empty? }
|
92
|
+
toggle_allow(scopes_are_empty)
|
93
|
+
else
|
94
|
+
allow!
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def initiative_type_scope_action?
|
99
|
+
return unless permission_action.subject == :initiative_type_scope
|
100
|
+
|
101
|
+
initiative_type_scope = context.fetch(:initiative_type_scope, nil)
|
102
|
+
|
103
|
+
case permission_action.action
|
104
|
+
when :destroy
|
105
|
+
scopes_is_empty = initiative_type_scope && initiative_type_scope.initiatives.empty?
|
106
|
+
toggle_allow(scopes_is_empty)
|
107
|
+
else
|
108
|
+
allow!
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def initiative_committee_action?
|
113
|
+
return unless permission_action.subject == :initiative_committee_member
|
114
|
+
|
115
|
+
request = context.fetch(:request, nil)
|
116
|
+
|
117
|
+
case permission_action.action
|
118
|
+
when :index
|
119
|
+
allow!
|
120
|
+
when :approve
|
121
|
+
toggle_allow(!request&.accepted?)
|
122
|
+
when :revoke
|
123
|
+
toggle_allow(!request&.rejected?)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def initiative_admin_user_action?
|
128
|
+
return unless permission_action.subject == :initiative
|
129
|
+
|
130
|
+
case permission_action.action
|
131
|
+
when :read
|
132
|
+
toggle_allow(Decidim::Initiatives.print_enabled)
|
133
|
+
when :publish
|
134
|
+
toggle_allow(initiative.validating?)
|
135
|
+
when :unpublish
|
136
|
+
toggle_allow(initiative.published?)
|
137
|
+
when :discard
|
138
|
+
toggle_allow(initiative.validating?)
|
139
|
+
when :export_votes
|
140
|
+
toggle_allow(initiative.offline? || initiative.any?)
|
141
|
+
when :accept
|
142
|
+
allowed = initiative.published? &&
|
143
|
+
initiative.signature_end_time < Time.zone.today &&
|
144
|
+
initiative.percentage >= 100
|
145
|
+
toggle_allow(allowed)
|
146
|
+
when :reject
|
147
|
+
allowed = initiative.published? &&
|
148
|
+
initiative.signature_end_time < Time.zone.today &&
|
149
|
+
initiative.percentage < 100
|
150
|
+
toggle_allow(allowed)
|
151
|
+
else
|
152
|
+
allow!
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def read_initiative_list_action?
|
157
|
+
return unless permission_action.subject == :initiative &&
|
158
|
+
permission_action.action == :list
|
159
|
+
allow!
|
160
|
+
end
|
161
|
+
|
162
|
+
def initiative_user_action?
|
163
|
+
return unless permission_action.subject == :initiative
|
164
|
+
|
165
|
+
case permission_action.action
|
166
|
+
when :read
|
167
|
+
toggle_allow(Decidim::Initiatives.print_enabled)
|
168
|
+
when :preview, :edit
|
169
|
+
allow!
|
170
|
+
when :update
|
171
|
+
toggle_allow(initiative.created?)
|
172
|
+
when :send_to_technical_validation
|
173
|
+
allowed = initiative.created? && (
|
174
|
+
!initiative.decidim_user_group_id.nil? ||
|
175
|
+
initiative.committee_members.approved.count >= Decidim::Initiatives.minimum_committee_members
|
176
|
+
)
|
177
|
+
|
178
|
+
toggle_allow(allowed)
|
179
|
+
when :manage_membership
|
180
|
+
allow!
|
181
|
+
else
|
182
|
+
disallow!
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|