From 1128fedc51f1f48cb328c5956ebd3bfad8792316 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 20 May 2019 13:13:31 +0200 Subject: [PATCH] Refactor title inline editing permission checking [SCI-3471] --- app/controllers/experiments_controller.rb | 11 +++++++++++ app/controllers/my_modules_controller.rb | 11 +++++++++++ app/controllers/projects_controller.rb | 11 +++++++++++ app/views/experiments/canvas.html.erb | 11 +---------- app/views/my_modules/protocols.html.erb | 11 +---------- app/views/projects/show.html.erb | 11 +---------- app/views/shared/_inline_editing.html.erb | 14 +++++++------- app/views/shared/_secondary_navigation.html.erb | 15 ++++----------- 8 files changed, 47 insertions(+), 48 deletions(-) diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index 9b615494f..7ff2856af 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -20,6 +20,7 @@ class ExperimentsController < ApplicationController before_action :check_archive_permissions, only: :archive before_action :check_clone_permissions, only: %i(clone_modal clone) before_action :check_move_permissions, only: %i(move_modal move) + before_action :set_inline_name_editing, only: %i(canvas module_archive) layout 'fluid'.freeze @@ -311,6 +312,16 @@ class ExperimentsController < ApplicationController render_403 unless can_move_experiment?(@experiment) end + def set_inline_name_editing + return unless can_manage_experiment?(@experiment) + @inline_editable_title_config = { + name: 'title', + params_group: 'experiment', + field_to_udpate: 'name', + path_to_update: experiment_path(@experiment) + } + end + def experiment_annotation_notification(old_text = nil) smart_annotation_notification( old_text: old_text, diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index 38303ce10..ad876c878 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -39,6 +39,7 @@ class MyModulesController < ApplicationController unassign_repository_records assign_samples unassign_samples) + before_action :set_inline_name_editing, only: %i(protocols results activities repository archive) layout 'fluid'.freeze @@ -703,6 +704,16 @@ class MyModulesController < ApplicationController render_403 unless can_complete_module?(@my_module) end + def set_inline_name_editing + return unless can_manage_module?(@my_module) + @inline_editable_title_config = { + name: 'title', + params_group: 'my_module', + field_to_udpate: 'name', + path_to_update: my_module_path(@my_module) + } + end + def my_module_params params.require(:my_module).permit(:name, :description, :due_date, :archived) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f1b56d258..88c68fdf7 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -16,6 +16,7 @@ class ProjectsController < ApplicationController samples_index) before_action :check_create_permissions, only: %i(new create) before_action :check_manage_permissions, only: :edit + before_action :set_inline_name_editing, only: %i(show experiment_archive) # except parameter could be used but it is not working. layout 'fluid' @@ -339,6 +340,16 @@ class ProjectsController < ApplicationController render_403 unless can_manage_project?(@project) end + def set_inline_name_editing + return unless can_manage_project?(@project) + @inline_editable_title_config = { + name: 'title', + params_group: 'project', + field_to_udpate: 'name', + path_to_update: project_path(@project) + } + end + def log_activity(type_of, message_items = {}) message_items = { project: @project.id }.merge(message_items) diff --git a/app/views/experiments/canvas.html.erb b/app/views/experiments/canvas.html.erb index c50336b0b..2769de66f 100644 --- a/app/views/experiments/canvas.html.erb +++ b/app/views/experiments/canvas.html.erb @@ -1,15 +1,6 @@ <% provide(:head_title, t("experiments.canvas.head_title", project: h(@project.name)).html_safe) %> <%= render partial: "shared/sidebar", locals: { current_experiment: @experiment, page: 'canvas' } %> -<%= render partial: "shared/secondary_navigation" , locals: { - editable: { - name: 'title', - active: can_manage_experiment?(@experiment), - width: 'calc(100% - 500px)', - params_group: 'experiment', - field_to_udpate: 'name', - path_to_update: experiment_path(@experiment) - } -}%> +<%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/my_modules/protocols.html.erb b/app/views/my_modules/protocols.html.erb index 39571ef18..c8f037715 100644 --- a/app/views/my_modules/protocols.html.erb +++ b/app/views/my_modules/protocols.html.erb @@ -2,16 +2,7 @@ <%= render partial: 'shared/drag_n_drop_overlay' %> <%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %> -<%= render partial: "shared/secondary_navigation", locals: { - editable: { - name: 'title', - active: can_manage_module?(@my_module), - width: 'calc(100% - 580px)', - params_group: 'my_module', - field_to_udpate: 'name', - path_to_update: my_module_path(@my_module) - } -} %> +<%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index f9d5d7a7f..89c689ad9 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -1,15 +1,6 @@ <% provide(:head_title, t("projects.show.head_title", project: h(@project.name)).html_safe) %> <%= render partial: "shared/sidebar", locals: { current_project: @project, page: 'project' } %> -<%= render partial: "shared/secondary_navigation", locals: { - editable: { - name: 'title', - active: can_manage_project?(@project), - width: 'calc(100% - 500px)', - params_group: 'project', - field_to_udpate: 'name', - path_to_update: project_path(@project) - } -}%> +<%= render partial: "shared/secondary_navigation" %>
diff --git a/app/views/shared/_inline_editing.html.erb b/app/views/shared/_inline_editing.html.erb index dfeb144ee..1fb212739 100644 --- a/app/views/shared/_inline_editing.html.erb +++ b/app/views/shared/_inline_editing.html.erb @@ -1,8 +1,8 @@ -
@@ -15,5 +15,5 @@
\ No newline at end of file + initInlineEditing('<%= @inline_editable_title_config[:name] %>') + diff --git a/app/views/shared/_secondary_navigation.html.erb b/app/views/shared/_secondary_navigation.html.erb index 1707ae1ef..c1075945d 100644 --- a/app/views/shared/_secondary_navigation.html.erb +++ b/app/views/shared/_secondary_navigation.html.erb @@ -149,17 +149,10 @@ - <% editable = false if local_assigns[:editable].nil? %> -