2018-08-03 17:22:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-15 13:39:33 +00:00
|
|
|
# Makes api V4 compatible with old project features permissions methods
|
2016-08-01 22:31:21 +00: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 09:40:56 +00:00
|
|
|
require 'gitlab/utils'
|
2016-08-01 22:31:21 +00:00
|
|
|
|
|
|
|
module ProjectFeaturesCompatibility
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2019-05-15 11:19:16 +00:00
|
|
|
# TODO: remove in API v5, replaced by *_access_level
|
2016-08-01 22:31:21 +00:00
|
|
|
def wiki_enabled=(value)
|
2019-05-15 11:19:16 +00:00
|
|
|
write_feature_attribute_boolean(:wiki_access_level, value)
|
2016-08-01 22:31:21 +00:00
|
|
|
end
|
|
|
|
|
2019-05-15 11:19:16 +00:00
|
|
|
# TODO: remove in API v5, replaced by *_access_level
|
2016-08-01 22:31:21 +00:00
|
|
|
def builds_enabled=(value)
|
2019-05-15 11:19:16 +00:00
|
|
|
write_feature_attribute_boolean(:builds_access_level, value)
|
2016-08-01 22:31:21 +00:00
|
|
|
end
|
|
|
|
|
2019-05-15 11:19:16 +00:00
|
|
|
# TODO: remove in API v5, replaced by *_access_level
|
2016-08-01 22:31:21 +00:00
|
|
|
def merge_requests_enabled=(value)
|
2019-05-15 11:19:16 +00:00
|
|
|
write_feature_attribute_boolean(:merge_requests_access_level, value)
|
2016-08-01 22:31:21 +00:00
|
|
|
end
|
|
|
|
|
2019-05-15 11:19:16 +00:00
|
|
|
# TODO: remove in API v5, replaced by *_access_level
|
2016-08-01 22:31:21 +00:00
|
|
|
def issues_enabled=(value)
|
2019-05-15 11:19:16 +00:00
|
|
|
write_feature_attribute_boolean(:issues_access_level, value)
|
2016-08-01 22:31:21 +00:00
|
|
|
end
|
|
|
|
|
2019-05-15 11:19:16 +00:00
|
|
|
# TODO: remove in API v5, replaced by *_access_level
|
2016-08-01 22:31:21 +00:00
|
|
|
def snippets_enabled=(value)
|
2019-05-15 11:19:16 +00:00
|
|
|
write_feature_attribute_boolean(:snippets_access_level, value)
|
|
|
|
end
|
|
|
|
|
2021-02-18 18:10:41 +00:00
|
|
|
def security_and_compliance_enabled=(value)
|
|
|
|
write_feature_attribute_boolean(:security_and_compliance_access_level, value)
|
|
|
|
end
|
|
|
|
|
2019-05-15 11:19:16 +00:00
|
|
|
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
|
|
|
|
|
2020-01-17 18:08:41 +00:00
|
|
|
def forking_access_level=(value)
|
|
|
|
write_feature_attribute_string(:forking_access_level, value)
|
|
|
|
end
|
|
|
|
|
2019-05-15 11:19:16 +00:00
|
|
|
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 22:31:21 +00:00
|
|
|
end
|
|
|
|
|
2022-05-30 15:08:03 +00:00
|
|
|
def package_registry_access_level=(value)
|
|
|
|
write_feature_attribute_string(:package_registry_access_level, value)
|
|
|
|
end
|
|
|
|
|
2020-01-23 12:08:38 +00:00
|
|
|
def pages_access_level=(value)
|
|
|
|
write_feature_attribute_string(:pages_access_level, value)
|
|
|
|
end
|
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
def metrics_dashboard_access_level=(value)
|
|
|
|
write_feature_attribute_string(:metrics_dashboard_access_level, value)
|
|
|
|
end
|
|
|
|
|
2020-12-16 21:09:57 +00:00
|
|
|
def analytics_access_level=(value)
|
|
|
|
write_feature_attribute_string(:analytics_access_level, value)
|
|
|
|
end
|
|
|
|
|
2020-11-27 12:09:14 +00:00
|
|
|
def operations_access_level=(value)
|
|
|
|
write_feature_attribute_string(:operations_access_level, value)
|
|
|
|
end
|
|
|
|
|
2022-09-15 00:14:10 +00:00
|
|
|
def monitor_access_level=(value)
|
|
|
|
write_feature_attribute_string(:monitor_access_level, value)
|
|
|
|
end
|
|
|
|
|
2021-02-18 18:10:41 +00:00
|
|
|
def security_and_compliance_access_level=(value)
|
|
|
|
write_feature_attribute_string(:security_and_compliance_access_level, value)
|
|
|
|
end
|
|
|
|
|
2021-03-08 12:09:01 +00:00
|
|
|
def container_registry_access_level=(value)
|
|
|
|
write_feature_attribute_string(:container_registry_access_level, value)
|
|
|
|
end
|
|
|
|
|
2022-08-02 09:11:05 +00:00
|
|
|
def environments_access_level=(value)
|
|
|
|
write_feature_attribute_string(:environments_access_level, value)
|
|
|
|
end
|
|
|
|
|
2022-08-11 18:11:57 +00:00
|
|
|
def feature_flags_access_level=(value)
|
|
|
|
write_feature_attribute_string(:feature_flags_access_level, value)
|
|
|
|
end
|
|
|
|
|
2022-08-15 06:12:42 +00:00
|
|
|
def releases_access_level=(value)
|
|
|
|
write_feature_attribute_string(:releases_access_level, value)
|
|
|
|
end
|
|
|
|
|
2022-10-26 21:09:20 +00:00
|
|
|
def infrastructure_access_level=(value)
|
|
|
|
write_feature_attribute_string(:infrastructure_access_level, value)
|
|
|
|
end
|
|
|
|
|
2021-07-26 12:10:08 +00:00
|
|
|
# TODO: Remove this method after we drop support for project create/edit APIs to set the
|
|
|
|
# container_registry_enabled attribute. They can instead set the container_registry_access_level
|
|
|
|
# attribute.
|
|
|
|
def container_registry_enabled=(value)
|
|
|
|
write_feature_attribute_boolean(:container_registry_access_level, value)
|
|
|
|
end
|
|
|
|
|
2016-08-01 22:31:21 +00:00
|
|
|
private
|
|
|
|
|
2019-05-15 11:19:16 +00: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 22:31:21 +00:00
|
|
|
build_project_feature unless project_feature
|
|
|
|
|
2019-05-15 11:19:16 +00:00
|
|
|
project_feature.__send__(:write_attribute, field, value) # rubocop:disable GitlabSecurity/PublicSend
|
2016-08-01 22:31:21 +00:00
|
|
|
end
|
|
|
|
end
|
2020-11-05 12:09:05 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
ProjectFeaturesCompatibility.prepend_mod_with('ProjectFeaturesCompatibility')
|