diff --git a/.rubocop_todo/style/class_and_module_children.yml b/.rubocop_todo/style/class_and_module_children.yml index b3a7186e39acd5da0a96a11c2c5655824ecf1bc5..b3eae8ecce1a9a3773c516968e314cae274c3a89 100644 --- a/.rubocop_todo/style/class_and_module_children.yml +++ b/.rubocop_todo/style/class_and_module_children.yml @@ -389,7 +389,6 @@ Style/ClassAndModuleChildren: - 'ee/app/controllers/projects/insights_controller.rb' - 'ee/app/controllers/projects/iteration_cadences_controller.rb' - 'ee/app/controllers/projects/iterations_controller.rb' - - 'ee/app/controllers/projects/path_locks_controller.rb' - 'ee/app/controllers/projects/protected_environments_controller.rb' - 'ee/app/controllers/projects/push_rules_controller.rb' - 'ee/app/controllers/projects/quality/test_cases_controller.rb' diff --git a/ee/app/controllers/projects/path_locks_controller.rb b/ee/app/controllers/projects/path_locks_controller.rb index 423c86fc9987e22657b9894d465449bfc9a6041f..1873b5e7d4e24e7381677bbf496e73fb7d8260ed 100644 --- a/ee/app/controllers/projects/path_locks_controller.rb +++ b/ee/app/controllers/projects/path_locks_controller.rb @@ -1,102 +1,104 @@ # frozen_string_literal: true -class Projects::PathLocksController < Projects::ApplicationController - include PathLocksHelper +module Projects + class PathLocksController < Projects::ApplicationController + include PathLocksHelper - # Authorize - before_action :require_non_empty_project - before_action :authorize_read_code! - before_action :authorize_push_code!, only: [:toggle] + # Authorize + before_action :require_non_empty_project + before_action :authorize_read_code! + before_action :authorize_push_code!, only: [:toggle] - before_action :check_license + before_action :check_license - feature_category :source_code_management - urgency :low, [:index] + feature_category :source_code_management + urgency :low, [:index] - def index - @path_locks = @project.path_locks.page(allowed_params[:page]) - end - - def toggle - path_lock = @project.path_locks.for_path(path) - - if path_lock - unlock_file(path_lock) - else - lock_file + def index + @path_locks = @project.path_locks.page(allowed_params[:page]) end - head :ok - rescue PathLocks::UnlockService::AccessDenied, PathLocks::LockService::AccessDenied - access_denied! - end + def toggle + path_lock = @project.path_locks.for_path(path) - def destroy - path_lock = @project.path_locks.find(allowed_params[:id]) + if path_lock + unlock_file(path_lock) + else + lock_file + end - begin - PathLocks::UnlockService.new(project, current_user).execute(path_lock) - rescue PathLocks::UnlockService::AccessDenied - return access_denied! + head :ok + rescue PathLocks::UnlockService::AccessDenied, PathLocks::LockService::AccessDenied + access_denied! end - respond_to do |format| - format.html do - redirect_to project_locks_path(@project), status: :found + def destroy + path_lock = @project.path_locks.find(allowed_params[:id]) + + begin + PathLocks::UnlockService.new(project, current_user).execute(path_lock) + rescue PathLocks::UnlockService::AccessDenied + return access_denied! + end + + respond_to do |format| + format.html do + redirect_to project_locks_path(@project), status: :found + end + format.js end - format.js end - end - private + private - def check_license - unless @project.feature_available?(:file_locks) - flash[:alert] = _('You need a different license to enable FileLocks feature') - redirect_to admin_subscription_path + def check_license + unless @project.feature_available?(:file_locks) + flash[:alert] = _('You need a different license to enable FileLocks feature') + redirect_to admin_subscription_path + end end - end - def lock_file - path_lock = PathLocks::LockService.new(project, current_user).execute(path) + def lock_file + path_lock = PathLocks::LockService.new(project, current_user).execute(path) - if path_lock.persisted? && sync_with_lfs? - Lfs::LockFileService.new( - project, - current_user, - path: path, - create_path_lock: false - ).execute + if path_lock.persisted? && sync_with_lfs? + Lfs::LockFileService.new( + project, + current_user, + path: path, + create_path_lock: false + ).execute + end end - end - def unlock_file(path_lock) - PathLocks::UnlockService.new(project, current_user).execute(path_lock) + def unlock_file(path_lock) + PathLocks::UnlockService.new(project, current_user).execute(path_lock) - if sync_with_lfs? - Lfs::UnlockFileService.new(project, current_user, path: path_lock.path, force: true).execute + if sync_with_lfs? + Lfs::UnlockFileService.new(project, current_user, path: path_lock.path, force: true).execute + end end - end - def lfs_file? - blob = repository.blob_at_branch(repository.root_ref, path) + def lfs_file? + blob = repository.blob_at_branch(repository.root_ref, path) - return false unless blob + return false unless blob - lfs_blob_ids = LfsPointersFinder.new(repository, path).execute + lfs_blob_ids = LfsPointersFinder.new(repository, path).execute - lfs_blob_ids.include?(blob.id) - end + lfs_blob_ids.include?(blob.id) + end - def sync_with_lfs? - project.lfs_enabled? && lfs_file? - end + def sync_with_lfs? + project.lfs_enabled? && lfs_file? + end - def path - allowed_params[:path] - end + def path + allowed_params[:path] + end - def allowed_params - params.permit(:path, :id, :page) + def allowed_params + params.permit(:path, :id, :page) + end end end