BigW Consortium Gitlab

repository_controller.rb 1.61 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

9
        define_protected_refs
10 11 12 13
      end

      private

14 15
      def define_protected_refs
        @protected_branches = @project.protected_branches.order(:name).page(params[:page])
16
        @protected_tags = @project.protected_tags.order(:name).page(params[:page])
17
        @protected_branch = @project.protected_branches.new
18
        @protected_tag = @project.protected_tags.new
19
        load_gon_index
20
      end
21

22 23
      def access_levels_options
        {
24
          create_access_levels: levels_for_dropdown(ProtectedTag::CreateAccessLevel),
25 26
          push_access_levels: levels_for_dropdown(ProtectedBranch::PushAccessLevel),
          merge_access_levels: levels_for_dropdown(ProtectedBranch::MergeAccessLevel)
27 28 29
        }
      end

30 31 32 33 34 35 36
      def levels_for_dropdown(access_level_type)
        roles = access_level_type.human_access_levels.map do |id, text|
          { id: id, text: text, before_divider: true }
        end
        { roles: roles }
      end

37 38
      def protectable_tags_for_dropdown
        { open_tags: ProtectableDropdown.new(@project, :tags).hash }
39 40
      end

41 42
      def protectable_branches_for_dropdown
        { open_branches: ProtectableDropdown.new(@project, :branches).hash }
43 44
      end

45
      def load_gon_index
46 47
        gon.push(protectable_tags_for_dropdown)
        gon.push(protectable_branches_for_dropdown)
48
        gon.push(access_levels_options)
49
      end
50 51 52
    end
  end
end