mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2026-01-06 16:24:49 +08:00
Moved permission to taggable concern [SCI-12286]
This commit is contained in:
parent
1baec4f47d
commit
d7b772be13
13 changed files with 30 additions and 61 deletions
|
|
@ -4,11 +4,12 @@ module TaggableActions
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_action :load_taggable_item, only: %i(link_tag unlink_tag)
|
||||
before_action :load_tag, only: %i(link_tag unlink_tag)
|
||||
before_action :load_taggable_item, only: %i(tag_resource untag_resource)
|
||||
before_action :load_tag, only: %i(tag_resource untag_resource)
|
||||
before_action :check_tag_manage_permissions, only: %i(tag_resource untag_resource)
|
||||
end
|
||||
|
||||
def link_tag
|
||||
def tag_resource
|
||||
tagging = @taggable_item.taggings.new(tag: @tag, created_by: current_user)
|
||||
if tagging.save
|
||||
render json: { tag: [@tag.id, @tag.name, @tag.color] }
|
||||
|
|
@ -17,7 +18,7 @@ module TaggableActions
|
|||
end
|
||||
end
|
||||
|
||||
def unlink_tag
|
||||
def untag_resource
|
||||
tagging = @taggable_item.taggings.find_by(tag_id: @tag.id)
|
||||
if tagging&.destroy
|
||||
render json: { status: :ok }
|
||||
|
|
@ -33,7 +34,11 @@ module TaggableActions
|
|||
end
|
||||
|
||||
def load_tag
|
||||
@tag = @taggable_item.team.tags.find_by(id: params[:tag_id])
|
||||
@tag = current_team.tags.find_by(id: params[:tag_id])
|
||||
render_404 unless @tag
|
||||
end
|
||||
|
||||
def check_tag_manage_permissions
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ class MyModulesController < ApplicationController
|
|||
before_action :check_manage_permissions, only: %i(
|
||||
description due_date update_description update_protocol_description update_protocol
|
||||
)
|
||||
before_action :check_tag_manage_permissions, only: %i(link_tag unlink_tag)
|
||||
before_action :check_read_permissions, except: %i(create new update update_description
|
||||
inventory_assigning_my_module_filter
|
||||
update_protocol_description restore_group
|
||||
|
|
@ -517,7 +516,7 @@ class MyModulesController < ApplicationController
|
|||
end
|
||||
|
||||
def check_tag_manage_permissions
|
||||
render_403 && return unless can_manage_my_module_tags?(@my_module)
|
||||
render_403 && return unless can_manage_my_module_tags?(@taggable_item)
|
||||
end
|
||||
|
||||
def set_inline_name_editing
|
||||
|
|
|
|||
|
|
@ -62,11 +62,11 @@ export default {
|
|||
tagsUrl() {
|
||||
return list_users_settings_team_tags_path({team_id: this.subject.attributes.team_id});
|
||||
},
|
||||
linkTagUrl() {
|
||||
return this.subject.attributes.urls.link_tag;
|
||||
tagResourceUrl() {
|
||||
return this.subject.attributes.urls.tag_resource;
|
||||
},
|
||||
unlinkTagUrl() {
|
||||
return this.subject.attributes.urls.unlink_tag;
|
||||
untagResourceUrl() {
|
||||
return this.subject.attributes.urls.untag_resource;
|
||||
},
|
||||
},
|
||||
created() {
|
||||
|
|
@ -99,7 +99,7 @@ export default {
|
|||
|
||||
this.linkingTag = true;
|
||||
|
||||
axios.post(this.linkTagUrl, {
|
||||
axios.post(this.tagResourceUrl, {
|
||||
tag_id: tag[0],
|
||||
}).then((response) => {
|
||||
this.tags.push(response.data.tag);
|
||||
|
|
@ -117,7 +117,7 @@ export default {
|
|||
|
||||
this.linkingTag = true;
|
||||
|
||||
axios.post(this.unlinkTagUrl, {
|
||||
axios.post(this.untagResourceUrl, {
|
||||
tag_id: tag[0],
|
||||
}).then((response) => {
|
||||
this.tags = this.tags.filter(t => t[0] !== tag[0]);
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ module Lists
|
|||
urls_list = {
|
||||
show: protocols_my_module_path(object, view_mode: archived ? 'archived' : 'active'),
|
||||
results: my_module_results_path(object),
|
||||
assign_tags: my_module_my_module_tags_path(object),
|
||||
assigned_tags: assigned_tags_my_module_my_module_tags_path(object),
|
||||
assign_tags: '',
|
||||
assigned_tags: '',
|
||||
users_list: search_my_module_user_my_module_path(object, my_module_id: object.id),
|
||||
experiments_to_move: experiments_to_move_experiment_path(object.experiment),
|
||||
update: my_module_path(object),
|
||||
|
|
|
|||
|
|
@ -58,8 +58,8 @@ class MyModuleSerializer < ActiveModel::Serializer
|
|||
{
|
||||
show_access: access_permissions_my_module_path(object),
|
||||
show_user_group_assignments_access: show_user_group_assignments_access_permissions_my_module_path(object),
|
||||
link_tag: link_tag_my_module_path(object),
|
||||
unlink_tag: unlink_tag_my_module_path(object)
|
||||
tag_resource: tag_resource_my_module_path(object),
|
||||
untag_resource: untag_resource_my_module_path(object)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -173,8 +173,7 @@ module Experiments
|
|||
{
|
||||
my_module_id: my_module.id,
|
||||
tags: my_module.tags.length,
|
||||
can_create: can_manage_my_module_tags?(@user, my_module),
|
||||
edit_url: my_module_tags_edit_path(my_module, format: :json)
|
||||
can_create: can_manage_my_module_tags?(@user, my_module)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -10,17 +10,17 @@
|
|||
data-module-y="<%= my_module.y %>"
|
||||
data-module-conns="<%= construct_module_connections(my_module) %>"
|
||||
data-module-users-tab-url="<%= designated_users_my_module_user_my_modules_url(my_module_id: my_module.id, format: :json) %>"
|
||||
data-module-tags-url="<%= my_module_tags_experiment_path(my_module.experiment, format: :json) %>"
|
||||
data-module-tags-url=""
|
||||
data-module-url="<%= my_module_path(my_module, format: :json) %>">
|
||||
|
||||
<div data-view-mode="active">
|
||||
<a class="edit-tags-link pull-right" data-remote="true" href="<%= my_module_tags_edit_url(my_module, format: :json) %>">
|
||||
<a class="edit-tags-link pull-right" data-remote="true" href="">
|
||||
<%= render partial: "canvas/tags", locals: { my_module: my_module } %>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div data-view-mode="archived">
|
||||
<a class="edit-tags-link pull-right" data-remote="true" href="<%= my_module_tags_edit_url(my_module, format: :json) %>">
|
||||
<a class="edit-tags-link pull-right" data-remote="true" href="">
|
||||
<%= render partial: "canvas/tags", locals: { my_module: my_module } %>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
:tags-colors="<%= Constants::TAG_COLORS.to_json %>"
|
||||
:params="myModuleParams"
|
||||
project-name="<%= @project.name %>"
|
||||
project-tags-url="<%= project_tags_path(@project) %>"
|
||||
project-tags-url=""
|
||||
@close="close"
|
||||
@tags-loaded="syncTags"
|
||||
@tag-deleted="tagDeleted = true"
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
</span>
|
||||
</div>
|
||||
<% if @active_modules %>
|
||||
<div id="canvas-container" data-project-id="<%= @project.id %>" data-module-tags-url="<%= my_module_tags_experiment_path(@experiment, format: :json) %>">
|
||||
<div id="canvas-container" data-project-id="<%= @project.id %>" data-module-tags-url="">
|
||||
<%= render partial: 'canvas/full_zoom', locals: { experiment: @experiment, my_modules: @active_modules } %>
|
||||
</div>
|
||||
<% else %>
|
||||
|
|
|
|||
|
|
@ -52,13 +52,5 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="module-tags">
|
||||
<div class="tags-wrapper" id="module-tags" data-module-tags-url="<%= my_module_my_module_tags_url(@my_module, format: :json) %>">
|
||||
<span class="sn-icon block-icon sn-icon-tag mr-2.5"></span>
|
||||
<span class="hidden-xs hidden-sm tags-title"><%=t "my_modules.details.tags" %></span>
|
||||
<%= render partial: "my_modules/tags", locals: { my_module: @my_module, editable: my_module_editable } %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Manage tags modal -->
|
||||
<%= render partial: "my_modules/modals/manage_module_tags_modal", locals: { my_module: @my_module } %>
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
<div class="select-container" data-e2e="e2e-IF-task-details-tags">
|
||||
<div class="edit-button-container hidden">
|
||||
<a class="edit-tags-link" data-remote="true" href="<%= my_module_path(my_module, format: :json) %>">
|
||||
<i class="sn-icon sn-icon-settings"></i>
|
||||
<span class="hidden-xs"><%= t("my_modules.details.manage_tags") %></span>
|
||||
</a>
|
||||
</div>
|
||||
<%= select_tag "activity",
|
||||
options_for_select(my_module.tags.order(:id).map { |i|
|
||||
[
|
||||
escape_input(i[:name]),
|
||||
escape_input(i[:id]),
|
||||
{'data-params' => {color: escape_input(i[:color])}.to_json}
|
||||
]
|
||||
}),
|
||||
{
|
||||
id: 'module-tags-selector',
|
||||
'data-module-id': my_module.id,
|
||||
'data-project-id': my_module.experiment.project_id,
|
||||
'data-placeholder': t("my_modules.details.no_tags"),
|
||||
'data-tags-create-url': project_tags_path(project_id: my_module.experiment.project_id),
|
||||
'data-ajax-url': search_tags_my_module_my_module_tags_path(@my_module),
|
||||
'data-update-module-tags-url': my_module_my_module_tags_path(@my_module),
|
||||
'data-view-mode': !editable
|
||||
} %>
|
||||
</div>
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
:tags-colors="<%= Constants::TAG_COLORS.to_json %>"
|
||||
project-name="<%= @experiment.project.name %>"
|
||||
:statuses-list="<%= MyModuleStatus.all.order(:id).map{ |i| [i.id, i.name] }.to_json %>"
|
||||
project-tags-url="<%= project_tags_path(@experiment.project) %>"
|
||||
project-tags-url=""
|
||||
canvas-url="<%= view_mode == 'active' ? canvas_experiment_path(@experiment) : module_archive_experiment_path(@experiment) %>"
|
||||
:archived="<%= @experiment.archived_branch?%>"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -525,8 +525,8 @@ Rails.application.routes.draw do
|
|||
post :favorite
|
||||
post :unfavorite
|
||||
get :assigned_users
|
||||
post :link_tag
|
||||
post :unlink_tag
|
||||
post :tag_resource
|
||||
post :untag_resource
|
||||
end
|
||||
resources :user_my_modules, path: '/users', only: %i(index create destroy) do
|
||||
collection do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue