diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 03:07:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 03:07:27 +0300 |
commit | b7e6df1abde1112ae1fa0778f45d6053eec3f052 (patch) | |
tree | a879d991b78433cbf419e4968c410982802dece3 /app/models/snippet.rb | |
parent | e924e9e7cb9df21b3bc3d51d5f955da28ba3a225 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r-- | app/models/snippet.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 4e693a94c6b..b6c0976cd43 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -33,8 +33,6 @@ class Snippet < ApplicationRecord default_content_html_invalidator || file_name_changed? end - default_value_for(:visibility_level) { Gitlab::CurrentSettings.default_snippet_visibility } - belongs_to :author, class_name: 'User' belongs_to :project @@ -139,6 +137,24 @@ class Snippet < ApplicationRecord @link_reference_pattern ||= super("snippets", /(?<snippet>\d+)/) end + def initialize(attributes = {}) + # We can't use default_value_for because the database has a default + # value of 0 for visibility_level. If someone attempts to create a + # private snippet, default_value_for will assume that the + # visibility_level hasn't changed and will use the application + # setting default, which could be internal or public. + # + # To fix the problem, we assign the actual snippet default if no + # explicit visibility has been initialized. + attributes ||= {} + + unless visibility_attribute_present?(attributes) + attributes[:visibility_level] = Gitlab::CurrentSettings.default_snippet_visibility + end + + super + end + def to_reference(from = nil, full: false) reference = "#{self.class.reference_prefix}#{id}" |