summaryrefslogtreecommitdiff
path: root/app/models/concerns/project_features_compatibility.rb
blob: f268a842db47b5d5ec13e5749bb75dc245aa1e9f (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
# frozen_string_literal: true

# Makes api V4 compatible with old project features permissions methods
#
# After migrating issues_enabled merge_requests_enabled builds_enabled snippets_enabled and wiki_enabled
# fields to a new table "project_features", support for the old fields is still needed in the API.
require 'gitlab/utils'

module ProjectFeaturesCompatibility
  extend ActiveSupport::Concern

  def wiki_enabled=(value)
    write_feature_attribute(:wiki_access_level, value)
  end

  def builds_enabled=(value)
    write_feature_attribute(:builds_access_level, value)
  end

  def merge_requests_enabled=(value)
    write_feature_attribute(:merge_requests_access_level, value)
  end

  def issues_enabled=(value)
    write_feature_attribute(:issues_access_level, value)
  end

  def snippets_enabled=(value)
    write_feature_attribute(:snippets_access_level, value)
  end

  private

  def write_feature_attribute(field, value)
    build_project_feature unless project_feature

    access_level = Gitlab::Utils.to_boolean(value) ? ProjectFeature::ENABLED : ProjectFeature::DISABLED
    project_feature.__send__(:write_attribute, field, access_level) # rubocop:disable GitlabSecurity/PublicSend
  end
end