2018-08-03 13:22:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-15 09:39:33 -04:00
|
|
|
# Makes api V4 compatible with old project features permissions methods
|
2016-08-01 18:31:21 -04:00
|
|
|
#
|
|
|
|
# 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.
|
2017-12-22 04:40:56 -05:00
|
|
|
require 'gitlab/utils'
|
2016-08-01 18:31:21 -04:00
|
|
|
|
|
|
|
module ProjectFeaturesCompatibility
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2019-05-15 07:19:16 -04:00
|
|
|
# TODO: remove in API v5, replaced by *_access_level
|
2016-08-01 18:31:21 -04:00
|
|
|
def wiki_enabled=(value)
|
2019-05-15 07:19:16 -04:00
|
|
|
write_feature_attribute_boolean(:wiki_access_level, value)
|
2016-08-01 18:31:21 -04:00
|
|
|
end
|
|
|
|
|
2019-05-15 07:19:16 -04:00
|
|
|
# TODO: remove in API v5, replaced by *_access_level
|
2016-08-01 18:31:21 -04:00
|
|
|
def builds_enabled=(value)
|
2019-05-15 07:19:16 -04:00
|
|
|
write_feature_attribute_boolean(:builds_access_level, value)
|
2016-08-01 18:31:21 -04:00
|
|
|
end
|
|
|
|
|
2019-05-15 07:19:16 -04:00
|
|
|
# TODO: remove in API v5, replaced by *_access_level
|
2016-08-01 18:31:21 -04:00
|
|
|
def merge_requests_enabled=(value)
|
2019-05-15 07:19:16 -04:00
|
|
|
write_feature_attribute_boolean(:merge_requests_access_level, value)
|
2016-08-01 18:31:21 -04:00
|
|
|
end
|
|
|
|
|
2019-05-15 07:19:16 -04:00
|
|
|
# TODO: remove in API v5, replaced by *_access_level
|
2016-08-01 18:31:21 -04:00
|
|
|
def issues_enabled=(value)
|
2019-05-15 07:19:16 -04:00
|
|
|
write_feature_attribute_boolean(:issues_access_level, value)
|
2016-08-01 18:31:21 -04:00
|
|
|
end
|
|
|
|
|
2019-05-15 07:19:16 -04:00
|
|
|
# TODO: remove in API v5, replaced by *_access_level
|
2016-08-01 18:31:21 -04:00
|
|
|
def snippets_enabled=(value)
|
2019-05-15 07:19:16 -04:00
|
|
|
write_feature_attribute_boolean(:snippets_access_level, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def repository_access_level=(value)
|
|
|
|
write_feature_attribute_string(:repository_access_level, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_access_level=(value)
|
|
|
|
write_feature_attribute_string(:wiki_access_level, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def builds_access_level=(value)
|
|
|
|
write_feature_attribute_string(:builds_access_level, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_requests_access_level=(value)
|
|
|
|
write_feature_attribute_string(:merge_requests_access_level, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def issues_access_level=(value)
|
|
|
|
write_feature_attribute_string(:issues_access_level, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def snippets_access_level=(value)
|
|
|
|
write_feature_attribute_string(:snippets_access_level, value)
|
2016-08-01 18:31:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-05-15 07:19:16 -04:00
|
|
|
def write_feature_attribute_boolean(field, value)
|
|
|
|
access_level = Gitlab::Utils.to_boolean(value) ? ProjectFeature::ENABLED : ProjectFeature::DISABLED
|
|
|
|
write_feature_attribute_raw(field, access_level)
|
|
|
|
end
|
|
|
|
|
|
|
|
def write_feature_attribute_string(field, value)
|
|
|
|
access_level = ProjectFeature.access_level_from_str(value)
|
|
|
|
write_feature_attribute_raw(field, access_level)
|
|
|
|
end
|
|
|
|
|
|
|
|
def write_feature_attribute_raw(field, value)
|
2016-08-01 18:31:21 -04:00
|
|
|
build_project_feature unless project_feature
|
|
|
|
|
2019-05-15 07:19:16 -04:00
|
|
|
project_feature.__send__(:write_attribute, field, value) # rubocop:disable GitlabSecurity/PublicSend
|
2016-08-01 18:31:21 -04:00
|
|
|
end
|
|
|
|
end
|