Skip to content
代码片段 群组 项目
提交 510bb818 编辑于 作者: Joe Woodward's avatar Joe Woodward 提交者: Joe Woodward
浏览文件

Nest path lock controller namespaces

Minor change to fix the rubocop offence

Related to https://gitlab.com/gitlab-org/gitlab/-/issues/512677
上级 6f785b63
No related branches found
No related tags found
无相关合并请求
......@@ -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'
......
# 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
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册