push_rules_controller.rb 1.15 KB
Newer Older
1
class Admin::PushRulesController < Admin::ApplicationController
2
  before_action :check_push_rules_available!
3 4 5 6
  before_action :push_rule

  respond_to :html

7
  def show
8 9 10
  end

  def update
11
    @push_rule.update_attributes(push_rule_params)
12 13

    if @push_rule.valid?
14
      redirect_to admin_push_rule_path, notice: 'Push Rule updated successfully.'
15
    else
16
      render :show
17 18 19 20 21
    end
  end

  private

22 23 24 25
  def check_push_rules_available!
    render_404 unless License.feature_available?(:push_rules)
  end

26
  def push_rule_params
27
    allowed_fields = %i[deny_delete_tag delete_branch_regex commit_message_regex commit_message_negative_regex
28 29 30 31 32 33 34
                        branch_name_regex force_push_regex author_email_regex
                        member_check file_name_regex max_file_size prevent_secrets]

    if @push_rule.available?(:reject_unsigned_commits)
      allowed_fields << :reject_unsigned_commits
    end

35 36
    if @push_rule.available?(:commit_committer_check)
      allowed_fields << :commit_committer_check
37 38 39
    end

    params.require(:push_rule).permit(allowed_fields)
40 41 42
  end

  def push_rule
43
    @push_rule ||= PushRule.find_or_initialize_by(is_sample: true)
44 45
  end
end