mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 13:14:29 +08:00
refactor update protocol in repository permission
This commit is contained in:
parent
e0d1ae174e
commit
806fcbce36
13 changed files with 67 additions and 44 deletions
|
@ -128,7 +128,8 @@ class AssetsController < ApplicationController
|
|||
|
||||
def check_edit_permission
|
||||
if @assoc.class == Step
|
||||
unless can_edit_step_in_protocol(@protocol)
|
||||
if @protocol.in_module? && !can_edit_step_in_protocol(@protocol) ||
|
||||
@protocol.in_repository? && !can_update_protocol_in_repository?(@protocol)
|
||||
render_403 and return
|
||||
end
|
||||
elsif @assoc.class == Result
|
||||
|
|
|
@ -935,7 +935,7 @@ class ProtocolsController < ApplicationController
|
|||
load_team_and_type
|
||||
@protocol = Protocol.find_by_id(params[:id])
|
||||
|
||||
unless can_edit_protocol(@protocol)
|
||||
unless can_update_protocol_in_repository?(@protocol)
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
|
|
@ -431,7 +431,9 @@ class StepsController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
if step
|
||||
if can_reorder_step_in_protocol(step.protocol)
|
||||
protocol = step.protocol
|
||||
if protocol.in_module? && can_reorder_step_in_protocol(protocol) ||
|
||||
protocol.in_repository? && can_update_protocol_in_repository?(protocol)
|
||||
if step.position > 0
|
||||
step_down = step.protocol.steps.where(position: step.position - 1).first
|
||||
step.position -= 1
|
||||
|
@ -476,7 +478,9 @@ class StepsController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
if step
|
||||
if can_reorder_step_in_protocol(step.protocol)
|
||||
protocol = step.protocol
|
||||
if protocol.in_module? && can_reorder_step_in_protocol(protocol) ||
|
||||
protocol.in_repository? && can_update_protocol_in_repository?(protocol)
|
||||
if step.position < step.protocol.steps.count - 1
|
||||
step_up = step.protocol.steps.where(position: step.position + 1).first
|
||||
step.position += 1
|
||||
|
@ -646,19 +650,22 @@ class StepsController < ApplicationController
|
|||
end
|
||||
|
||||
def check_create_permissions
|
||||
unless can_create_step_in_protocol(@protocol)
|
||||
if @protocol.in_module? && !can_create_step_in_protocol(@protocol) ||
|
||||
@protocol.in_repository? && !can_update_protocol_in_repository?(@protocol)
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def check_edit_permissions
|
||||
unless can_edit_step_in_protocol(@protocol)
|
||||
if @protocol.in_module? && !can_edit_step_in_protocol(@protocol) ||
|
||||
@protocol.in_repository? && !can_update_protocol_in_repository?(@protocol)
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def check_destroy_permissions
|
||||
unless can_delete_step_in_protocol(@protocol)
|
||||
if @protocol.in_module? && !can_delete_step_in_protocol(@protocol) ||
|
||||
@protocol.in_repository? && !can_update_protocol_in_repository?(@protocol)
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
|
|
@ -280,10 +280,9 @@ class WopiController < ActionController::Base
|
|||
# current_user
|
||||
@current_user = @user
|
||||
if @assoc.class == Step
|
||||
@can_write = can_edit_step_in_protocol(@protocol)
|
||||
|
||||
if @protocol.in_module?
|
||||
@can_read = can_view_steps_in_protocol(@protocol)
|
||||
@can_write = can_edit_step_in_protocol(@protocol)
|
||||
@close_url = protocols_my_module_url(@protocol.my_module,
|
||||
only_path: false,
|
||||
host: ENV['WOPI_USER_HOST'])
|
||||
|
@ -296,6 +295,7 @@ class WopiController < ActionController::Base
|
|||
@breadcrumb_folder_name = @protocol.my_module.name
|
||||
else
|
||||
@can_read = can_read_protocol_in_repository?(@protocol)
|
||||
@can_write = can_update_protocol_in_repository?(@protocol)
|
||||
@close_url = protocols_url(only_path: false,
|
||||
host: ENV['WOPI_USER_HOST'])
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ class ProtocolsDatatable < CustomDatatable
|
|||
include ActiveRecord::Sanitization::ClassMethods
|
||||
include InputSanitizeHelper
|
||||
|
||||
def_delegator :@view, :can_edit_protocol
|
||||
def_delegator :@view, :can_update_protocol_in_repository?
|
||||
def_delegator :@view, :edit_protocol_path
|
||||
def_delegator :@view, :can_clone_protocol
|
||||
def_delegator :@view, :clone_protocol_path
|
||||
|
@ -85,8 +85,8 @@ class ProtocolsDatatable < CustomDatatable
|
|||
protocol = Protocol.find(record.id)
|
||||
result_data << {
|
||||
'DT_RowId': record.id,
|
||||
'DT_CanEdit': can_edit_protocol(protocol),
|
||||
'DT_EditUrl': if can_edit_protocol(protocol)
|
||||
'DT_CanEdit': can_update_protocol_in_repository?(protocol),
|
||||
'DT_EditUrl': if can_update_protocol_in_repository?(protocol)
|
||||
edit_protocol_path(protocol,
|
||||
team: @team,
|
||||
type: @type)
|
||||
|
|
|
@ -720,10 +720,10 @@ module PermissionHelper
|
|||
end
|
||||
end
|
||||
|
||||
def can_edit_protocol(protocol)
|
||||
is_normal_user_or_admin_of_team(protocol.team) and
|
||||
current_user == protocol.added_by and (not protocol.in_repository_archived?)
|
||||
end
|
||||
# def can_edit_protocol(protocol)
|
||||
# is_normal_user_or_admin_of_team(protocol.team) and
|
||||
# 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
|
||||
|
@ -858,28 +858,28 @@ module PermissionHelper
|
|||
end
|
||||
end
|
||||
|
||||
def can_create_step_in_protocol(protocol)
|
||||
if protocol.in_module?
|
||||
def can_create_step_in_protocol(protocol) # WIP
|
||||
if protocol.in_module? # TBD
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project)
|
||||
elsif protocol.in_repository?
|
||||
elsif protocol.in_repository? # DONE
|
||||
protocol.in_repository_active? and can_edit_protocol(protocol)
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def can_reorder_step_in_protocol(protocol)
|
||||
if protocol.in_module?
|
||||
def can_reorder_step_in_protocol(protocol) # WIP
|
||||
if protocol.in_module? # TBD
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project)
|
||||
elsif protocol.in_repository?
|
||||
elsif protocol.in_repository? # DONE
|
||||
protocol.in_repository_active? and can_edit_protocol(protocol)
|
||||
else
|
||||
false
|
||||
|
@ -892,28 +892,28 @@ module PermissionHelper
|
|||
# - adding assets
|
||||
# - adding tables
|
||||
# but right now we have 1 page to rule them all.
|
||||
def can_edit_step_in_protocol(protocol)
|
||||
if protocol.in_module?
|
||||
def can_edit_step_in_protocol(protocol) # WIP
|
||||
if protocol.in_module? # TBD
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_user_or_higher_of_project(my_module.experiment.project)
|
||||
elsif protocol.in_repository?
|
||||
elsif protocol.in_repository? # DONE
|
||||
protocol.in_repository_active? and can_edit_protocol(protocol)
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def can_delete_step_in_protocol(protocol)
|
||||
if protocol.in_module?
|
||||
def can_delete_step_in_protocol(protocol) # WIP
|
||||
if protocol.in_module? # TBD
|
||||
my_module = protocol.my_module
|
||||
my_module.active? &&
|
||||
my_module.experiment.project.active? &&
|
||||
my_module.experiment.active? &&
|
||||
is_owner_of_project(my_module.experiment.project)
|
||||
elsif protocol.in_repository?
|
||||
elsif protocol.in_repository? # DONE
|
||||
protocol.in_repository_active? and can_edit_protocol(protocol)
|
||||
else
|
||||
false
|
||||
|
|
|
@ -40,4 +40,12 @@ Canaid::Permissions.register_for(Protocol) do
|
|||
(protocol.in_repository_public? ||
|
||||
protocol.in_repository_private? && user == protocol.added_by)
|
||||
end
|
||||
|
||||
# edit protocol in repository,
|
||||
# create, edit, delete or reorder step in repository
|
||||
can :update_protocol_in_repository do |user, protocol|
|
||||
user.is_normal_user_or_admin_of_team?(protocol.team) &&
|
||||
user == protocol.added_by &&
|
||||
protocol.in_repository_active?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="page-header">
|
||||
<% if can_edit_protocol(@protocol) %>
|
||||
<% if can_update_protocol_in_repository?(@protocol) %>
|
||||
<a class="edit-name-link" data-action="edit-name" data-role="name-refresh" data-remote="true" href="<%= edit_name_modal_protocol_path(@protocol, format: :json) %>" style="color: inherit;">
|
||||
<%= render partial: "protocols/header/name_label.html.erb" %>
|
||||
</a>
|
||||
|
@ -41,7 +41,7 @@
|
|||
|
||||
<div class="col-xs-12 col-sm-6 col-md-6">
|
||||
<div class="badge-icon bg-primary">
|
||||
<% if can_edit_protocol(@protocol) %>
|
||||
<% if can_update_protocol_in_repository?(@protocol) %>
|
||||
<a data-action="edit-keywords" data-remote="true" href="<%= edit_keywords_modal_protocol_path(@protocol, format: :json) %>" style="color: inherit;">
|
||||
<span class="glyphicon glyphicon-text-color"></span>
|
||||
</a>
|
||||
|
@ -51,7 +51,7 @@
|
|||
</div>
|
||||
<div class="well well-sm">
|
||||
<span class="hidden-xs hidden-sm hidden-md"><%=t "protocols.header.keywords" %>:</span>
|
||||
<% if can_edit_protocol(@protocol) %>
|
||||
<% if can_update_protocol_in_repository?(@protocol) %>
|
||||
<%= link_to edit_keywords_modal_protocol_path(@protocol, format: :json), remote: true, style: "color: inherit;", data: { action: "edit-keywords", role: "keywords-refresh" } do %>
|
||||
<%= render partial: "protocols/header/keywords_label.html.erb" %>
|
||||
<% end %>
|
||||
|
@ -63,7 +63,7 @@
|
|||
|
||||
<div class="col-xs-12 col-sm-6 col-md-6">
|
||||
<div class="badge-icon bg-primary">
|
||||
<% if can_edit_protocol(@protocol) %>
|
||||
<% if can_update_protocol_in_repository?(@protocol) %>
|
||||
<a data-action="edit-authors" data-remote="true" href="<%= edit_authors_modal_protocol_path(@protocol, format: :json) %>" style="color: inherit;">
|
||||
<span class="glyphicon glyphicon-education"></span>
|
||||
</a>
|
||||
|
@ -73,7 +73,7 @@
|
|||
</div>
|
||||
<div class="well well-sm">
|
||||
<span class="hidden-xs hidden-sm hidden-md"><%=t "protocols.header.authors" %>:</span>
|
||||
<% if can_edit_protocol(@protocol) %>
|
||||
<% if can_update_protocol_in_repository?(@protocol) %>
|
||||
<%= link_to edit_authors_modal_protocol_path(@protocol, format: :json), remote: true, style: "color: inherit;", data: { action: "edit-authors", role: "authors-refresh" } do %>
|
||||
<%= render partial: "protocols/header/authors_label.html.erb" %>
|
||||
<% end %>
|
||||
|
@ -85,7 +85,7 @@
|
|||
|
||||
<div class="col-xs-12 col-sm-12 col-md-12">
|
||||
<div class="badge-icon bg-primary">
|
||||
<% if can_edit_protocol(@protocol) %>
|
||||
<% if can_update_protocol_in_repository?(@protocol) %>
|
||||
<a data-action="edit-description" data-remote="true" href="<%= edit_description_modal_protocol_path(@protocol, format: :json) %>" style="color: inherit;">
|
||||
<span class="glyphicon glyphicon-info-sign"></span>
|
||||
</a>
|
||||
|
@ -95,7 +95,7 @@
|
|||
</div>
|
||||
<div class="well well-sm">
|
||||
<span class="hidden-xs hidden-sm hidden-md"><%=t "protocols.header.description" %>:</span>
|
||||
<% if can_edit_protocol(@protocol) %>
|
||||
<% if can_update_protocol_in_repository?(@protocol) %>
|
||||
<%= link_to edit_description_modal_protocol_path(@protocol, format: :json), remote: true, style: "color: inherit;", data: { action: "edit-description", role: "description-refresh" } do %>
|
||||
<%= render partial: "protocols/header/description_label.html.erb" %>
|
||||
<% end %>
|
||||
|
@ -108,4 +108,4 @@
|
|||
|
||||
<%= render partial: "protocols/header/edit_metadata_modal.html.erb" %>
|
||||
|
||||
<%= javascript_include_tag "protocols/header" %>
|
||||
<%= javascript_include_tag "protocols/header" %>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<div class="row">
|
||||
<div class="pull-right" style="margin: 20px 15px 0 0;">
|
||||
<% if can_create_step_in_protocol(@protocol) %>
|
||||
<% if @protocol.in_module? && can_create_step_in_protocol(@protocol) ||
|
||||
@protocol.in_repository? && can_update_protocol_in_repository?(@protocol) %>
|
||||
<a href="#"
|
||||
class="btn btn-primary"
|
||||
data-action="new-step"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<button type="button" class="btn btn-default" data-dismiss="modal"><%=t "general.close" %></button>
|
||||
<% if can_edit_protocol(@protocol) %>
|
||||
<% if can_update_protocol_in_repository?(@protocol) %>
|
||||
<%= route_to_other_team_btn edit_protocol_path(protocol),
|
||||
protocol.team,
|
||||
t('general.edit') %>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
step.protocol.team,
|
||||
text %>
|
||||
<% end %>
|
||||
<% elsif can_edit_protocol(step.protocol) %>
|
||||
<% elsif step.protocol.in_repository? && can_update_protocol_in_repository?(step.protocol) %>
|
||||
<%= route_to_other_team edit_protocol_path(step.protocol),
|
||||
step.protocol.team,
|
||||
text %>
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<div class="panel-options pull-right">
|
||||
<% if can_reorder_step_in_protocol(@protocol) %>
|
||||
<% if @protocol.in_module? && can_reorder_step_in_protocol(@protocol) ||
|
||||
@protocol.in_repository? && can_update_protocol_in_repository?(@protocol) %>
|
||||
<a data-action="move-step"
|
||||
class="btn btn-link"
|
||||
href="<%= move_up_step_path(step, format: :json) %>"
|
||||
|
@ -19,7 +20,8 @@
|
|||
data-remote="true">
|
||||
<span class="glyphicon glyphicon-arrow-down"></a>
|
||||
<% end %>
|
||||
<% if can_edit_step_in_protocol(@protocol) %>
|
||||
<% if @protocol.in_module? && can_edit_step_in_protocol(@protocol) ||
|
||||
@protocol.in_repository? && can_update_protocol_in_repository?(@protocol) %>
|
||||
<a data-action="edit-step"
|
||||
class="btn btn-link"
|
||||
title="<%= t("protocols.steps.options.edit_title") %>"
|
||||
|
@ -28,7 +30,8 @@
|
|||
<span class="glyphicon glyphicon-edit">
|
||||
</a>
|
||||
<% end %>
|
||||
<% if can_delete_step_in_protocol(@protocol) && step.can_destroy? %>
|
||||
<% if (@protocol.in_module? && can_delete_step_in_protocol(@protocol) ||
|
||||
@protocol.in_repository? && can_update_protocol_in_repository?(@protocol)) && step.can_destroy? %>
|
||||
<%= link_to(step_path(step), title: t("protocols.steps.options.delete_title"), method: "delete", class: "btn btn-link",
|
||||
data: {action: "delete-step", confirm: t("protocols.steps.destroy.confirm", step: step.name)}) do %>
|
||||
<span class="glyphicon glyphicon-trash">
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
<% end %>
|
||||
<%= wopi_asset_view_button(asset) %>
|
||||
<% view_only ||= false %>
|
||||
<% if !view_only && can_edit_step_in_protocol(@protocol) %>
|
||||
<%= wopi_asset_edit_button(asset) %>
|
||||
<% if !view_only %>
|
||||
<% if @protocol.in_module? && can_edit_step_in_protocol(@protocol) ||
|
||||
@protocol.in_repository? && can_update_protocol_in_repository?(@protocol) %>
|
||||
<%= wopi_asset_edit_button(asset) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
Loading…
Add table
Reference in a new issue