Fixed permission issues when moving experiment [SCI-6257] (#3655)

* Fixed permission issues when moving experiment [SCI-6257]

* Copy fixes [SCI-6248]

* Use canaid helper instead of permission_granted [SCI-6257]

* Fixes [SCI-6257]
This commit is contained in:
artoscinote 2021-11-12 12:59:49 +01:00 committed by GitHub
parent 1c3a2aa0a7
commit a6c61c2b4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 7 deletions

View file

@ -205,10 +205,10 @@ class Experiment < ApplicationRecord
# team and not archived), all users assigned on experiment.project has
# to be assigned on such project
def movable_projects(current_user)
current_user.projects
.where.not(id: project_id)
.where(archived: false, team: project.team)
.with_user_permission(current_user, ProjectPermissions::EXPERIMENTS_CREATE)
project.team.projects.active
.where.not(id: project_id)
.where(archived: false)
.with_granted_permissions(current_user, ProjectPermissions::EXPERIMENTS_CREATE)
end
def permission_parent

View file

@ -18,6 +18,11 @@ module Experiments
def call
return self unless valid?
unless can_create_project_experiments?(@user, @project)
@errors[:main] = I18n.t('move_to_project_service.project_permission_error')
return self
end
ActiveRecord::Base.transaction do
@exp.project = @project
@exp.my_modules.each do |my_module|
@ -32,7 +37,7 @@ module Experiments
sync_user_assignments(@exp)
rescue StandardError
if @exp.valid?
@errors[:main] = "Don't have permission for tasks manage"
@errors[:main] = I18n.t('move_to_project_service.my_modules_permission_error')
else
@errors.merge!(@exp.errors.to_hash)
end

View file

@ -1109,12 +1109,13 @@ en:
current_project: '(current project)'
move:
modal_title: 'Move experiment %{experiment}'
notice: 'Moving is possible only to projects that contain same (or additional) users.'
notice: 'Moving is possible to projects, where you have permissions to create experiments and tasks.'
label_title: 'Move'
modal_submit: 'Move'
success_flash: "Successfully moved experiment %{experiment}"
error_flash: ' Could not move the experiment. Experiment name is already in use. '
no_projects: 'No projects to move this experiment to.'
task_permission: 'No permission: You dont have edit access to all experiment tasks.'
no_projects: 'No projects: You dont have edit access to any other projects.'
canvas:
archive_confirm: "Are you sure to archive this experiment?"
actions: 'Actions'
@ -2504,6 +2505,11 @@ en:
from_project: "%{user_role} [from project]"
from_experiment: "%{user_role} [from experiment]"
experiment_select_role: "Change experiment role"
move_to_project_service:
project_permission_error: "No permission to create experiments at project"
my_modules_permission_error: "No manage permissions on tasks"
access_permissions:
create:
success: