From d7b772be13d72a536d9fa673e24fb29676bbcd57 Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 2 Sep 2025 15:55:48 +0200 Subject: [PATCH] Moved permission to taggable concern [SCI-12286] --- app/controllers/concerns/taggable_actions.rb | 15 +++++++---- app/controllers/my_modules_controller.rb | 3 +-- app/javascript/vue/shared/tags_input.vue | 12 ++++----- app/serializers/lists/my_module_serializer.rb | 4 +-- app/serializers/my_module_serializer.rb | 4 +-- .../experiments/table_view_service.rb | 3 +-- .../canvas/full_zoom/_my_module.html.erb | 6 ++--- .../canvas/full_zoom/_tags_modal.html.erb | 2 +- app/views/experiments/canvas.html.erb | 2 +- .../my_modules/_my_module_details.html.erb | 8 ------ app/views/my_modules/_tags.html.erb | 26 ------------------- app/views/my_modules/index.html.erb | 2 +- config/routes.rb | 4 +-- 13 files changed, 30 insertions(+), 61 deletions(-) delete mode 100644 app/views/my_modules/_tags.html.erb diff --git a/app/controllers/concerns/taggable_actions.rb b/app/controllers/concerns/taggable_actions.rb index 343f21789..8ddf83cd5 100644 --- a/app/controllers/concerns/taggable_actions.rb +++ b/app/controllers/concerns/taggable_actions.rb @@ -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 diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index b9321d1f5..962e109db 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -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 diff --git a/app/javascript/vue/shared/tags_input.vue b/app/javascript/vue/shared/tags_input.vue index 8e31855b8..3d579f367 100644 --- a/app/javascript/vue/shared/tags_input.vue +++ b/app/javascript/vue/shared/tags_input.vue @@ -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]); diff --git a/app/serializers/lists/my_module_serializer.rb b/app/serializers/lists/my_module_serializer.rb index 045ee812c..f38f8a889 100644 --- a/app/serializers/lists/my_module_serializer.rb +++ b/app/serializers/lists/my_module_serializer.rb @@ -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), diff --git a/app/serializers/my_module_serializer.rb b/app/serializers/my_module_serializer.rb index 006dec253..3599c232d 100644 --- a/app/serializers/my_module_serializer.rb +++ b/app/serializers/my_module_serializer.rb @@ -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 diff --git a/app/services/experiments/table_view_service.rb b/app/services/experiments/table_view_service.rb index 64fceb796..a487884b4 100644 --- a/app/services/experiments/table_view_service.rb +++ b/app/services/experiments/table_view_service.rb @@ -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 diff --git a/app/views/canvas/full_zoom/_my_module.html.erb b/app/views/canvas/full_zoom/_my_module.html.erb index 112377cfe..a24e14555 100644 --- a/app/views/canvas/full_zoom/_my_module.html.erb +++ b/app/views/canvas/full_zoom/_my_module.html.erb @@ -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) %>">
- + <%= render partial: "canvas/tags", locals: { my_module: my_module } %>
- + <%= render partial: "canvas/tags", locals: { my_module: my_module } %>
diff --git a/app/views/canvas/full_zoom/_tags_modal.html.erb b/app/views/canvas/full_zoom/_tags_modal.html.erb index 82807b1f9..b734da127 100644 --- a/app/views/canvas/full_zoom/_tags_modal.html.erb +++ b/app/views/canvas/full_zoom/_tags_modal.html.erb @@ -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" diff --git a/app/views/experiments/canvas.html.erb b/app/views/experiments/canvas.html.erb index ebeabe9c7..235b8e9b1 100644 --- a/app/views/experiments/canvas.html.erb +++ b/app/views/experiments/canvas.html.erb @@ -60,7 +60,7 @@ <% if @active_modules %> -
+
<%= render partial: 'canvas/full_zoom', locals: { experiment: @experiment, my_modules: @active_modules } %>
<% else %> diff --git a/app/views/my_modules/_my_module_details.html.erb b/app/views/my_modules/_my_module_details.html.erb index cfb4d3445..10da89232 100644 --- a/app/views/my_modules/_my_module_details.html.erb +++ b/app/views/my_modules/_my_module_details.html.erb @@ -52,13 +52,5 @@
-
-
- - - <%= render partial: "my_modules/tags", locals: { my_module: @my_module, editable: my_module_editable } %> -
-
- <%= render partial: "my_modules/modals/manage_module_tags_modal", locals: { my_module: @my_module } %> diff --git a/app/views/my_modules/_tags.html.erb b/app/views/my_modules/_tags.html.erb deleted file mode 100644 index eb42396eb..000000000 --- a/app/views/my_modules/_tags.html.erb +++ /dev/null @@ -1,26 +0,0 @@ -
- - <%= 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 - } %> -
diff --git a/app/views/my_modules/index.html.erb b/app/views/my_modules/index.html.erb index 8a714d750..ae1e376e1 100644 --- a/app/views/my_modules/index.html.erb +++ b/app/views/my_modules/index.html.erb @@ -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?%>" /> diff --git a/config/routes.rb b/config/routes.rb index d04e8b4c9..7d3838542 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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