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

git_access_design.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fb8df0d217a3dedfc48f7c9f5e6b3ee2ceb5762a (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
50
51
52
53
54
55
56
# frozen_string_literal: true

module Gitlab
  class GitAccessDesign < GitAccess
    extend ::Gitlab::Utils::Override

    # TODO Re-factor so that correct container is passed to the constructor
    # and this method can be removed from here
    # https://gitlab.com/gitlab-org/gitlab/-/issues/409454
    def initialize(
      actor, container, protocol, authentication_abilities:, repository_path: nil, redirected_path: nil,
      auth_result_type: nil)
      super(
        actor,
        select_container(container),
        protocol,
        authentication_abilities: authentication_abilities,
        repository_path: repository_path,
        redirected_path: redirected_path,
        auth_result_type: auth_result_type
      )
    end

    def check(_cmd, _changes)
      check_protocol!
      check_can_create_design!

      success_result
    end

    override :push_ability
    def push_ability
      :create_design
    end

    private

    def select_container(container)
      container.is_a?(::DesignManagement::Repository) ? container.project : container
    end

    def check_protocol!
      if protocol != 'web'
        raise ::Gitlab::GitAccess::ForbiddenError, "Designs are only accessible using the web interface"
      end
    end

    def check_can_create_design!
      unless user_can_push?
        raise ::Gitlab::GitAccess::ForbiddenError, "You are not allowed to manage designs of this project"
      end
    end
  end
end

Gitlab::GitAccessDesign.prepend_mod_with('Gitlab::GitAccessDesign')