diff options
author | Stan Hu <stanhu@gmail.com> | 2019-06-12 16:03:46 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-06-14 07:36:35 -0700 |
commit | dcba5279b6e4bda905f5fa37a557b94f1fd42ba9 (patch) | |
tree | 193bd3221c0f8d1e1a790cbdfbd8542f39823451 /lib | |
parent | 89fa253864442096b7cf5bb5803f6b103aa0d92e (diff) | |
download | gitlab-ce-dcba5279b6e4bda905f5fa37a557b94f1fd42ba9.tar.gz |
Fix inability to set visibility_level on project via APIsh-fix-issue-63158
Consider the scenario:
1. The default visibility level is set to internal
2. A user attempts to create a private project within a private group
Previously this would always fail because default_value_for would
overwrite the private visibility setting, no matter what
visibility_level were specified. This was happening because
default_value_for was confused by the default value of 0 specified by
the database schema.
default_value_for attempts to assign the default value in the block by
checking whether the attribute has changed. The problem is that since
the default value by the database was 0, and the user requested 0, this
appeared as though no changes were made. As a result, default_value_for
would always overwrite the user's preference.
To fix this, we remove the use of default_value_for and only set the
visibility level to the default application setting when no preference
has been given at creation time.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/63158
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/visibility_level.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/gitlab/visibility_level.rb b/lib/gitlab/visibility_level.rb index 8f9d5cf1e63..e2787744f09 100644 --- a/lib/gitlab/visibility_level.rb +++ b/lib/gitlab/visibility_level.rb @@ -138,5 +138,18 @@ module Gitlab def visibility=(level) self[visibility_level_field] = Gitlab::VisibilityLevel.level_value(level) end + + def visibility_attribute_present?(attributes) + visibility_level_attributes.each do |attr| + return true if attributes[attr].present? + end + + false + end + + def visibility_level_attributes + [visibility_level_field, visibility_level_field.to_s, + :visibility, 'visibility'] + end end end |