mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 01:35:34 +08:00
Put permissions helper methods inside utility module.
This commit is contained in:
parent
b8b9707c06
commit
1904099954
2 changed files with 22 additions and 17 deletions
|
@ -175,7 +175,7 @@ Canaid::Permissions.register_for(Comment) do
|
|||
# result: update/delete comment
|
||||
# step: update/delete comment
|
||||
can :manage_comment_in_module do |user, comment|
|
||||
my_module = get_comment_module(comment)
|
||||
my_module = ::PermissionsUtil.get_comment_module(comment)
|
||||
project = my_module.experiment.project
|
||||
# Same check as in `can_manage_comment_in_project?`
|
||||
project.present? &&
|
||||
|
@ -186,25 +186,10 @@ Canaid::Permissions.register_for(Comment) do
|
|||
# permissions
|
||||
%i(manage_comment_in_module).each do |perm|
|
||||
can perm do |_, comment|
|
||||
my_module = get_comment_module(comment)
|
||||
my_module = ::PermissionsUtil.get_comment_module(comment)
|
||||
my_module.active? &&
|
||||
my_module.experiment.active? &&
|
||||
my_module.experiment.project.active?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_comment_module(comment)
|
||||
comment = comment.becomes(comment.type.constantize)
|
||||
my_module = case comment
|
||||
when TaskComment
|
||||
comment.my_module
|
||||
when ResultComment
|
||||
comment.result.my_module
|
||||
when StepComment
|
||||
comment.step.protocol.my_module
|
||||
end
|
||||
my_module
|
||||
end
|
||||
|
|
20
app/utilities/permissions_util.rb
Normal file
20
app/utilities/permissions_util.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module PermissionsUtil
|
||||
def self.get_comment_module(comment)
|
||||
comment = comment.becomes(comment.type.constantize)
|
||||
my_module = case comment
|
||||
when TaskComment
|
||||
comment.my_module
|
||||
when ResultComment
|
||||
comment.result.my_module
|
||||
when StepComment
|
||||
comment.step.protocol.my_module
|
||||
end
|
||||
my_module
|
||||
end
|
||||
|
||||
def self.reference_project(obj)
|
||||
return obj.experiment.project if obj.is_a? MyModule
|
||||
return obj.project if obj.is_a? Experiment
|
||||
obj
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue