-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f676906
commit 7f79eb9
Showing
4 changed files
with
87 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Templates | ||
module Admin | ||
# this is here due a bug in Decidim 0.28 when they introduced proposal answer templates | ||
# they didn't take into account that valuators can answer proposals | ||
class Permissions < Decidim::DefaultPermissions | ||
def permissions | ||
return permission_action if permission_action.scope != :admin | ||
return permission_action unless user | ||
return permission_action if context[:current_organization] != user.organization | ||
|
||
if user_has_a_role? && (permission_action.subject == :template && permission_action.action == :read) | ||
allow! | ||
else | ||
return permission_action unless user.admin? | ||
|
||
case permission_action.subject | ||
when :template | ||
allow! if [:read, :create, :update, :destroy, :copy].include? permission_action.action | ||
when :templates | ||
allow! if permission_action.action == :index | ||
when :questionnaire | ||
allow! | ||
end | ||
end | ||
|
||
permission_action | ||
end | ||
|
||
private | ||
|
||
def participatory_space | ||
@participatory_space ||= context[:proposal].try(:participatory_space) | ||
end | ||
|
||
def user_roles | ||
@user_roles ||= participatory_space.try(:user_roles) | ||
end | ||
|
||
def user_has_a_role? | ||
return unless user_roles | ||
|
||
user_roles.exists?(user:) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters