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
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decidim
|
4
|
-
module Initiatives
|
5
|
-
module Abilities
|
6
|
-
module Admin
|
7
|
-
# Defines the abilities related to user able to administer components for an initiative.
|
8
|
-
# Intended to be used with `cancancan`.
|
9
|
-
class ComponentsAbility
|
10
|
-
include CanCan::Ability
|
11
|
-
|
12
|
-
attr_reader :user, :context
|
13
|
-
|
14
|
-
def initialize(user, context)
|
15
|
-
return if user&.admin?
|
16
|
-
|
17
|
-
@user = user
|
18
|
-
@context = context
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decidim
|
4
|
-
module Initiatives
|
5
|
-
module Abilities
|
6
|
-
module Admin
|
7
|
-
# Defines the abilities related to user able to administer initiatives.
|
8
|
-
# Intended to be used with `cancancan`.
|
9
|
-
class InitiativeAdminAbility
|
10
|
-
include CanCan::Ability
|
11
|
-
|
12
|
-
attr_reader :user, :context
|
13
|
-
|
14
|
-
def initialize(user, context)
|
15
|
-
return unless user&.admin?
|
16
|
-
|
17
|
-
@user = user
|
18
|
-
@context = context
|
19
|
-
|
20
|
-
define_admin_abilities
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def define_admin_abilities
|
26
|
-
can :preview, Initiative
|
27
|
-
|
28
|
-
can :manage, Initiative
|
29
|
-
can :send_to_technical_validation, Initiative
|
30
|
-
cannot :show, Initiative
|
31
|
-
can :show, Initiative if Decidim::Initiatives.print_enabled
|
32
|
-
|
33
|
-
cannot :publish, Initiative
|
34
|
-
can :publish, Initiative, &:validating?
|
35
|
-
|
36
|
-
cannot :unpublish, Initiative
|
37
|
-
can :unpublish, Initiative, &:published?
|
38
|
-
|
39
|
-
cannot :discard, Initiative
|
40
|
-
can :discard, Initiative, &:validating?
|
41
|
-
|
42
|
-
cannot :accept, Initiative
|
43
|
-
can :accept, Initiative do |initiative|
|
44
|
-
initiative.published? &&
|
45
|
-
initiative.signature_end_time < Time.zone.today &&
|
46
|
-
initiative.percentage >= 100
|
47
|
-
end
|
48
|
-
|
49
|
-
cannot :reject, Initiative
|
50
|
-
can :reject, Initiative do |initiative|
|
51
|
-
initiative.published? &&
|
52
|
-
initiative.signature_end_time < Time.zone.today &&
|
53
|
-
initiative.percentage < 100
|
54
|
-
end
|
55
|
-
|
56
|
-
cannot :export_votes, Initiative
|
57
|
-
can :export_votes, Initiative do |initiative|
|
58
|
-
initiative.offline? || initiative.any?
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decidim
|
4
|
-
module Initiatives
|
5
|
-
module Abilities
|
6
|
-
module Admin
|
7
|
-
# Defines the abilities related to user able to administer initiative types.
|
8
|
-
# Intended to be used with `cancancan`.
|
9
|
-
class InitiativeTypeAbility
|
10
|
-
include CanCan::Ability
|
11
|
-
|
12
|
-
attr_reader :user, :context
|
13
|
-
|
14
|
-
def initialize(user, context)
|
15
|
-
return unless user&.admin?
|
16
|
-
|
17
|
-
@user = user
|
18
|
-
@context = context
|
19
|
-
|
20
|
-
can :manage, InitiativesType
|
21
|
-
cannot :destroy, InitiativesType
|
22
|
-
can :destroy, InitiativesType do |initiative_type|
|
23
|
-
result = true
|
24
|
-
|
25
|
-
initiative_type.scopes.each do |s|
|
26
|
-
result &&= s.initiatives.empty?
|
27
|
-
end
|
28
|
-
|
29
|
-
result
|
30
|
-
end
|
31
|
-
|
32
|
-
can :manage, Decidim::InitiativesTypeScope
|
33
|
-
cannot :destroy, Decidim::InitiativesTypeScope
|
34
|
-
can :destroy, Decidim::InitiativesTypeScope do |scope|
|
35
|
-
scope.initiatives.empty?
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decidim
|
4
|
-
module Initiatives
|
5
|
-
module Abilities
|
6
|
-
module Admin
|
7
|
-
# Defines the abilities related to plain users able to administer initiatives.
|
8
|
-
# Intended to be used with `cancancan`.
|
9
|
-
class InitiativeUserAbility
|
10
|
-
include CanCan::Ability
|
11
|
-
|
12
|
-
attr_reader :user, :context
|
13
|
-
|
14
|
-
def initialize(user, context)
|
15
|
-
return unless user
|
16
|
-
return if user&.admin?
|
17
|
-
|
18
|
-
@user = user
|
19
|
-
@context = context
|
20
|
-
|
21
|
-
grant_dashboard_access
|
22
|
-
grant_initiative_permissions
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def grant_dashboard_access
|
28
|
-
can :read, :admin_dashboard if has_initiatives?(user)
|
29
|
-
end
|
30
|
-
|
31
|
-
def grant_initiative_permissions
|
32
|
-
can :list, Decidim::Initiative if has_initiatives?(user)
|
33
|
-
|
34
|
-
can :preview, Initiative do |initiative|
|
35
|
-
initiative.has_authorship? user
|
36
|
-
end
|
37
|
-
|
38
|
-
can :read, Initiative do |initiative|
|
39
|
-
initiative.has_authorship?(user) &&
|
40
|
-
Decidim::Initiatives.print_enabled
|
41
|
-
end
|
42
|
-
|
43
|
-
can :edit, Decidim::Initiative do |initiative|
|
44
|
-
initiative.has_authorship?(user)
|
45
|
-
end
|
46
|
-
|
47
|
-
can :update, Decidim::Initiative do |initiative|
|
48
|
-
initiative.has_authorship?(user) && initiative.created?
|
49
|
-
end
|
50
|
-
|
51
|
-
can :send_to_technical_validation, Initiative do |initiative|
|
52
|
-
initiative.has_authorship?(user) &&
|
53
|
-
initiative.created? && (
|
54
|
-
!initiative.decidim_user_group_id.nil? ||
|
55
|
-
initiative.committee_members.approved.count >= Decidim::Initiatives.minimum_committee_members
|
56
|
-
)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def has_initiatives?(user)
|
61
|
-
initiatives = InitiativesCreated.by(user) | InitiativesPromoted.by(user)
|
62
|
-
initiatives.any?
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decidim
|
4
|
-
module Initiatives
|
5
|
-
module Abilities
|
6
|
-
# Defines the abilities related to initiatives for a logged in user.
|
7
|
-
# Intended to be used with `cancancan`.
|
8
|
-
class CurrentUserAbility
|
9
|
-
include CanCan::Ability
|
10
|
-
|
11
|
-
attr_reader :user, :context
|
12
|
-
|
13
|
-
def initialize(user, context)
|
14
|
-
return unless user
|
15
|
-
|
16
|
-
@user = user
|
17
|
-
@context = context
|
18
|
-
|
19
|
-
can :create, Initiative if creation_enabled?
|
20
|
-
can :read, Initiative do |initiative|
|
21
|
-
initiative.published? || initiative.has_authorship?(user) || user&.admin?
|
22
|
-
end
|
23
|
-
|
24
|
-
can :read, :admin_dashboard if has_initiatives?
|
25
|
-
|
26
|
-
define_membership_management_abilities
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def creation_enabled?
|
32
|
-
Decidim::Initiatives.creation_enabled && (
|
33
|
-
Decidim::Initiatives.do_not_require_authorization ||
|
34
|
-
UserAuthorizations.for(user).any? ||
|
35
|
-
user.user_groups.verified.any?
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
def define_membership_management_abilities
|
40
|
-
can :request_membership, Initiative do |initiative|
|
41
|
-
!initiative.published? &&
|
42
|
-
!initiative.has_authorship?(user) &&
|
43
|
-
(
|
44
|
-
Decidim::Initiatives.do_not_require_authorization ||
|
45
|
-
UserAuthorizations.for(user).any? ||
|
46
|
-
user.user_groups.verified.any?
|
47
|
-
)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def has_initiatives?
|
52
|
-
initiatives = InitiativesCreated.by(user) | InitiativesPromoted.by(user)
|
53
|
-
initiatives.any?
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decidim
|
4
|
-
module Initiatives
|
5
|
-
module Abilities
|
6
|
-
# Defines the base abilities related to initiatives for any user. Guest
|
7
|
-
# users will use these too. Intended to be used with `cancancan`.
|
8
|
-
class EveryoneAbility < Decidim::Abilities::EveryoneAbility
|
9
|
-
def initialize(user, context)
|
10
|
-
super(user, context)
|
11
|
-
|
12
|
-
can :read, Initiative do |initiative|
|
13
|
-
initiative.published? || initiative.rejected? || initiative.accepted?
|
14
|
-
end
|
15
|
-
|
16
|
-
can :search, InitiativesType
|
17
|
-
can :search, InitiativesTypeScope
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decidim
|
4
|
-
module Initiatives
|
5
|
-
module Abilities
|
6
|
-
# Defines the abilities for non logged users..
|
7
|
-
# Intended to be used with `cancancan`.
|
8
|
-
class NonLoggedUserAbility
|
9
|
-
include CanCan::Ability
|
10
|
-
|
11
|
-
attr_reader :context
|
12
|
-
|
13
|
-
def initialize(user, context)
|
14
|
-
return if user
|
15
|
-
|
16
|
-
@context = context
|
17
|
-
|
18
|
-
can :create, Initiative if creation_enabled?
|
19
|
-
can :vote, Initiative
|
20
|
-
can :request_membership, Initiative do |initiative|
|
21
|
-
!initiative.published?
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def creation_enabled?
|
28
|
-
Decidim::Initiatives.creation_enabled
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decidim
|
4
|
-
module Initiatives
|
5
|
-
module Abilities
|
6
|
-
# Defines the abilities related to votes.
|
7
|
-
# Intended to be used with `cancancan`.
|
8
|
-
class VoteAbility
|
9
|
-
include CanCan::Ability
|
10
|
-
|
11
|
-
attr_reader :user, :context
|
12
|
-
|
13
|
-
def initialize(user, context)
|
14
|
-
return unless user
|
15
|
-
|
16
|
-
@user = user
|
17
|
-
@context = context
|
18
|
-
|
19
|
-
can :vote, Initiative do |initiative|
|
20
|
-
can_vote?(initiative)
|
21
|
-
end
|
22
|
-
|
23
|
-
can :unvote, Initiative do |initiative|
|
24
|
-
can_unvote?(initiative)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def decidim_user_group_id
|
31
|
-
context[:params]&.try(:[], "group_id")
|
32
|
-
end
|
33
|
-
|
34
|
-
def can_vote?(initiative)
|
35
|
-
initiative.votes_enabled? &&
|
36
|
-
initiative.organization&.id == user.organization&.id &&
|
37
|
-
initiative.votes.where(decidim_author_id: user.id, decidim_user_group_id: decidim_user_group_id).empty? &&
|
38
|
-
(can_user_support?(initiative) || user.user_groups.verified.any?)
|
39
|
-
end
|
40
|
-
|
41
|
-
def can_unvote?(initiative)
|
42
|
-
initiative.votes_enabled? &&
|
43
|
-
initiative.organization&.id == user.organization&.id &&
|
44
|
-
initiative.votes.where(decidim_author_id: user.id, decidim_user_group_id: decidim_user_group_id).any? &&
|
45
|
-
(can_user_support?(initiative) || user.user_groups.verified.any?)
|
46
|
-
end
|
47
|
-
|
48
|
-
def can_user_support?(initiative)
|
49
|
-
!initiative.offline? && (
|
50
|
-
Decidim::Initiatives.do_not_require_authorization ||
|
51
|
-
UserAuthorizations.for(user).any?
|
52
|
-
)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,6 +0,0 @@
|
|
1
|
-
<div id="initiative-<%= initiative.id %>-supports-count" class="card__support__data">
|
2
|
-
<% unless initiative.supports_count.zero? %>
|
3
|
-
<span class="card__support__number"><%= initiative.supports_count %></span>
|
4
|
-
<span><%= t(".count", count: initiative.supports_count) %></span>
|
5
|
-
<% end %>
|
6
|
-
</div>
|