mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 05:04:35 +08:00
refactor clone protocol permission
This commit is contained in:
parent
f6d36ae6a2
commit
0d37f9c85a
4 changed files with 17 additions and 11 deletions
|
@ -926,7 +926,7 @@ class ProtocolsController < ApplicationController
|
|||
@original = Protocol.find_by_id(params[:id])
|
||||
|
||||
if @original.blank? ||
|
||||
!can_clone_protocol(@original) || @type == :archive
|
||||
!can_clone_protocol?(@original) || @type == :archive
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ class ProtocolsDatatable < CustomDatatable
|
|||
|
||||
def_delegator :@view, :can_update_protocol_in_repository?
|
||||
def_delegator :@view, :edit_protocol_path
|
||||
def_delegator :@view, :can_clone_protocol
|
||||
def_delegator :@view, :can_clone_protocol?
|
||||
def_delegator :@view, :clone_protocol_path
|
||||
def_delegator :@view, :can_update_protocol_type_in_repository?
|
||||
def_delegator :@view, :can_read_protocol_in_repository?
|
||||
|
@ -88,8 +88,8 @@ class ProtocolsDatatable < CustomDatatable
|
|||
team: @team,
|
||||
type: @type)
|
||||
end,
|
||||
'DT_CanClone': can_clone_protocol(protocol),
|
||||
'DT_CloneUrl': if can_clone_protocol(protocol)
|
||||
'DT_CanClone': can_clone_protocol?(protocol),
|
||||
'DT_CloneUrl': if can_clone_protocol?(protocol)
|
||||
clone_protocol_path(protocol,
|
||||
team: @team,
|
||||
type: @type)
|
||||
|
|
|
@ -725,13 +725,13 @@ module PermissionHelper
|
|||
# current_user == protocol.added_by and (not protocol.in_repository_archived?)
|
||||
# end
|
||||
|
||||
def can_clone_protocol(protocol)
|
||||
is_normal_user_or_admin_of_team(protocol.team) and
|
||||
(
|
||||
protocol.in_repository_public? or
|
||||
(protocol.in_repository_private? and current_user == protocol.added_by)
|
||||
)
|
||||
end
|
||||
# def can_clone_protocol(protocol)
|
||||
# is_normal_user_or_admin_of_team(protocol.team) and
|
||||
# (
|
||||
# protocol.in_repository_public? or
|
||||
# (protocol.in_repository_private? and current_user == protocol.added_by)
|
||||
# )
|
||||
# end
|
||||
|
||||
# def can_make_protocol_private(protocol)
|
||||
# protocol.added_by == current_user and
|
||||
|
|
|
@ -53,4 +53,10 @@ Canaid::Permissions.register_for(Protocol) do
|
|||
user.is_normal_user_or_admin_of_team?(protocol.team) &&
|
||||
user == protocol.added_by
|
||||
end
|
||||
|
||||
# clone protocol in repository
|
||||
can :clone_protocol do |user, protocol|
|
||||
can_create_protocol?(user, protocol.team) &&
|
||||
can_read_protocol_in_repository?(user, protocol)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue