diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-06-29 11:31:50 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-06-29 11:32:38 -0300 |
commit | d2971315abd0e6e94860505e50ec71082c3679da (patch) | |
tree | 0f3dcf23406ec9fb3d6362b7f746e978ace692b3 /app/models/snippet.rb | |
parent | 36d48120f66d52dcc8697893ca1ab85322ba7c8b (diff) | |
parent | bef4294c58e0bbadc01f633fc8bea514801de7ae (diff) | |
download | gitlab-ce-issue_3359_3.tar.gz |
Merge branch 'master' into issue_3359_3issue_3359_3
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r-- | app/models/snippet.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/app/models/snippet.rb b/app/models/snippet.rb index f8034cb5e6b..5ec933601ac 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -20,6 +20,7 @@ class Snippet < ActiveRecord::Base length: { within: 0..255 }, format: { with: Gitlab::Regex.file_name_regex, message: Gitlab::Regex.file_name_regex_message } + validates :content, presence: true validates :visibility_level, inclusion: { in: Gitlab::VisibilityLevel.values } @@ -81,6 +82,11 @@ class Snippet < ActiveRecord::Base 0 end + # alias for compatibility with blobs and highlighting + def path + file_name + end + def name file_name end @@ -135,7 +141,16 @@ class Snippet < ActiveRecord::Base end def accessible_to(user) - where('visibility_level IN (?) OR author_id = ?', [Snippet::INTERNAL, Snippet::PUBLIC], user) + return are_public unless user.present? + return all if user.admin? + + where( + 'visibility_level IN (:visibility_levels) + OR author_id = :author_id + OR project_id IN (:project_ids)', + visibility_levels: [Snippet::PUBLIC, Snippet::INTERNAL], + author_id: user.id, + project_ids: user.authorized_projects.select(:id)) end end end |