diff --git a/app/controllers/my_module_repositories_controller.rb b/app/controllers/my_module_repositories_controller.rb index 5b5bee11f..5a1258762 100644 --- a/app/controllers/my_module_repositories_controller.rb +++ b/app/controllers/my_module_repositories_controller.rb @@ -4,11 +4,11 @@ class MyModuleRepositoriesController < ApplicationController include ApplicationHelper before_action :load_my_module - before_action :load_repository, except: %i(repositories_dropdown_list repositories_list_html) + before_action :load_repository, except: %i(repositories_dropdown_list repositories_list_html create) before_action :check_my_module_view_permissions, except: %i(update consume_modal update_consumption) - before_action :check_repository_view_permissions, except: %i(repositories_dropdown_list repositories_list_html) + before_action :check_repository_view_permissions, except: %i(repositories_dropdown_list repositories_list_html create) before_action :check_repository_row_consumption_permissions, only: %i(consume_modal update_consumption) - before_action :check_assign_repository_records_permissions, only: :update + before_action :check_assign_repository_records_permissions, only: %i(update create) def index_dt @draw = params[:draw].to_i @@ -41,6 +41,34 @@ class MyModuleRepositoriesController < ApplicationController render rows_view end + def create + repository_row = RepositoryRow.find(params[:repository_row_id]) + repository = repository_row.repository + return render_403 unless can_read_repository?(repository) + + ActiveRecord::Base.transaction do + @my_module.my_module_repository_rows.create!(repository_row: repository_row, assigned_by: current_user) + + Activities::CreateActivityService.call(activity_type: :assign_repository_record, + owner: current_user, + team: @my_module.experiment.project.team, + project: @my_module.experiment.project, + subject: @my_module, + message_items: { my_module: @my_module.id, + repository: repository.id, + record_names: repository_row.name }) + + render json: { + flash: t('my_modules.assigned_items.direct_assign.success') + } + end + rescue StandardError => e + Rails.logger.error e.message + render json: { + flash: t('my_modules.repository.flash.update_error') + }, status: :bad_request + end + def update service = RepositoryRows::MyModuleAssignUnassignService.call(my_module: @my_module, repository: @repository, diff --git a/config/locales/en.yml b/config/locales/en.yml index d10e8bac5..5fda93e9c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1007,6 +1007,8 @@ en: assigned_items: title: "Assigned items" assign_from: "Assign from" + direct_assign: + success: "Successfully assigned an item to the task." protocol: title: "Protocol" options_dropdown: diff --git a/config/routes.rb b/config/routes.rb index d7e9dd634..4253985a9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -432,7 +432,7 @@ Rails.application.routes.draw do get :repositories_dropdown_list, controller: :my_module_repositories get :repositories_list_html, controller: :my_module_repositories - resources :repositories, controller: :my_module_repositories, only: :update do + resources :repositories, controller: :my_module_repositories, only: %i(update create) do member do get :full_view_table post :index_dt