2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module Lfs
|
|
|
|
class UnlockFileService < BaseService
|
|
|
|
def execute
|
|
|
|
unless can?(current_user, :push_code, project)
|
2020-04-08 14:13:33 +05:30
|
|
|
raise Gitlab::GitAccess::ForbiddenError, _('You have no permissions')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
unlock_file
|
2020-04-08 14:13:33 +05:30
|
|
|
rescue Gitlab::GitAccess::ForbiddenError => ex
|
2018-03-17 18:26:18 +05:30
|
|
|
error(ex.message, 403)
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
2018-11-08 19:23:39 +05:30
|
|
|
error(_('Lock not found'), 404)
|
2021-06-08 01:23:25 +05:30
|
|
|
rescue StandardError => ex
|
2018-03-17 18:26:18 +05:30
|
|
|
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-11-08 19:23:39 +05:30
|
|
|
error(_('You must have maintainer access to force delete a lock'), 403)
|
2018-03-17 18:26:18 +05:30
|
|
|
else
|
2018-11-08 19:23:39 +05:30
|
|
|
error(_("%{lock_path} is locked by GitLab User %{lock_user_id}") % { lock_path: lock.path, lock_user_id: lock.user_id }, 403)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
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-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Lfs::UnlockFileService.prepend_mod_with('Lfs::UnlockFileService')
|