2018-07-17 16:50:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-07 13:00:53 +00:00
|
|
|
module Lfs
|
|
|
|
class UnlockFileService < BaseService
|
|
|
|
def execute
|
|
|
|
unless can?(current_user, :push_code, project)
|
2018-05-17 16:43:54 +00:00
|
|
|
raise Gitlab::GitAccess::UnauthorizedError, _('You have no permissions')
|
2018-02-07 13:00:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
unlock_file
|
|
|
|
rescue Gitlab::GitAccess::UnauthorizedError => ex
|
|
|
|
error(ex.message, 403)
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
2018-05-17 16:43:54 +00:00
|
|
|
error(_('Lock not found'), 404)
|
2018-02-07 13:00:53 +00:00
|
|
|
rescue => ex
|
|
|
|
error(ex.message, 500)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def unlock_file
|
|
|
|
forced = params[:force] == true
|
|
|
|
|
|
|
|
if lock.can_be_unlocked_by?(current_user, forced)
|
|
|
|
lock.destroy!
|
|
|
|
|
|
|
|
success(lock: lock, http_status: :ok)
|
|
|
|
elsif forced
|
2018-06-04 01:38:05 +00:00
|
|
|
error(_('You must have maintainer access to force delete a lock'), 403)
|
2018-02-07 13:00:53 +00:00
|
|
|
else
|
2018-05-17 16:43:54 +00:00
|
|
|
error(_("%{lock_path} is locked by GitLab User %{lock_user_id}") % { lock_path: lock.path, lock_user_id: lock.user_id }, 403)
|
2018-02-07 13:00:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-02-07 13:00:53 +00:00
|
|
|
def lock
|
|
|
|
return @lock if defined?(@lock)
|
|
|
|
|
|
|
|
@lock = if params[:id].present?
|
|
|
|
project.lfs_file_locks.find(params[:id])
|
|
|
|
elsif params[:path].present?
|
|
|
|
project.lfs_file_locks.find_by!(path: params[:path])
|
|
|
|
end
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-02-07 13:00:53 +00:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
|
|
|
Lfs::UnlockFileService.prepend_if_ee('EE::Lfs::UnlockFileService')
|