Read about our upcoming Code of Conduct on this issue

repository_controller.rb 2.1 KB
Newer Older
1
2
3
module Projects
  module Settings
    class RepositoryController < Projects::ApplicationController
4
5
      before_action :authorize_admin_project!

6
      def show
7
        @deploy_keys = DeployKeysPresenter.new(@project, current_user: current_user)
8
        @deploy_tokens = DeployTokensPresenter.new(@project.deploy_tokens.active, current_user: current_user, project: project)
9

10
        define_deploy_token
11
        define_protected_refs
12
13
14
15
      end

      private

16
17
      def define_protected_refs
        @protected_branches = @project.protected_branches.order(:name).page(params[:page])
18
        @protected_tags = @project.protected_tags.order(:name).page(params[:page])
19
        @protected_branch = @project.protected_branches.new
20
        @protected_tag = @project.protected_tags.new
21
22
23
24

        @protected_branches_count = @protected_branches.reduce(0) { |sum, branch| sum + branch.matching(@project.repository.branches).size }
        @protected_tags_count = @protected_tags.reduce(0) { |sum, tag| sum + tag.matching(@project.repository.tags).size }

Jose Ivan Vargas's avatar
Jose Ivan Vargas committed
25
        load_gon_index
26
      end
27

28
29
      def access_levels_options
        {
30
31
32
          create_access_levels: levels_for_dropdown,
          push_access_levels: levels_for_dropdown,
          merge_access_levels: levels_for_dropdown
33
34
35
        }
      end

36
37
      def levels_for_dropdown
        roles = ProtectedRefAccess::HUMAN_ACCESS_LEVELS.map do |id, text|
38
39
40
41
42
          { id: id, text: text, before_divider: true }
        end
        { roles: roles }
      end

43
44
      def protectable_tags_for_dropdown
        { open_tags: ProtectableDropdown.new(@project, :tags).hash }
45
46
      end

47
48
      def protectable_branches_for_dropdown
        { open_branches: ProtectableDropdown.new(@project, :branches).hash }
49
50
      end

51
      def load_gon_index
52
53
        gon.push(protectable_tags_for_dropdown)
        gon.push(protectable_branches_for_dropdown)
54
        gon.push(access_levels_options)
55
      end
56
57

      def define_deploy_token
Mayra Cabrera's avatar
Mayra Cabrera committed
58
        attributes = @deploy_tokens.attributes_deploy_token
Mayra Cabrera's avatar
Mayra Cabrera committed
59
        @deploy_token = DeployToken.new(attributes)
Mayra Cabrera's avatar
Mayra Cabrera committed
60
        @deploy_token.valid? unless attributes.empty?
61
      end
62
63
64
    end
  end
end