summaryrefslogtreecommitdiff
path: root/app/models/snippet.rb
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-28 14:38:05 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-28 14:38:05 +0200
commit2846f95d2a6a7418fb655f6588037bd3173fe77f (patch)
tree6ee5282cf9851c08c65ce024486782d4b9a3a78c /app/models/snippet.rb
parentc019585cb83b1852451184663085e6f0e0d12024 (diff)
parent365015e3c935afd8e4d3073078712cccd3077204 (diff)
downloadgitlab-ce-2846f95d2a6a7418fb655f6588037bd3173fe77f.tar.gz
Merge branch 'master' into refactor/ci-config-move-global-entries
* master: (352 commits) Display last commit of deleted branch in push events (!4699) add changelog add missing attribute to attr_encrypted so it is fully backwards-compatible Add "GitLab team members only" to diagram link doc: note that .gitattributes uses default branch use the conf lexer so we have highlighted comments first draft of docs support cgi style options, such as erb?parent=json move the path alias to a more appropriate location make #custom_language private appease rubocop add an alias for Snippet#path appease rubocop check the tag so that an instance will pass too fix the spec, using project.change_head Revert "bump the master sha for gitlab-test!9" bump the master sha for gitlab-test!9 add custom highlighting via .gitattributes Rename Licenses API to License Templates API Check for conflict with wiki projects when creating a new project. ...
Diffstat (limited to 'app/models/snippet.rb')
-rw-r--r--app/models/snippet.rb17
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