Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unlock_file_service.rb « lfs « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a13e89904a0d3290e56732b3b26d49deae0d2477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

module Lfs
  class UnlockFileService < BaseService
    def execute
      unless can?(current_user, :push_code, project)
        raise Gitlab::GitAccess::ForbiddenError, _('You have no permissions')
      end

      unlock_file
    rescue Gitlab::GitAccess::ForbiddenError => ex
      error(ex.message, 403)
    rescue ActiveRecord::RecordNotFound
      error(_('Lock not found'), 404)
    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
        error(_('You must have maintainer access to force delete a lock'), 403)
      else
        error(_("%{lock_path} is locked by GitLab User %{lock_user_id}") % { lock_path: lock.path, lock_user_id: lock.user_id }, 403)
      end
    end

    # rubocop: disable CodeReuse/ActiveRecord
    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
    # rubocop: enable CodeReuse/ActiveRecord
  end
end

Lfs::UnlockFileService.prepend_if_ee('EE::Lfs::UnlockFileService')