diff options
author | Valery Sizov <valery@gitlab.com> | 2014-10-08 16:44:25 +0300 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2014-10-09 17:09:53 +0300 |
commit | 47f539f5a6a930b2cfd4f9834b4d1bd5e1c180cb (patch) | |
tree | 0b528d431aa1625d92d3598f6a86ef8aa93b6491 /app/models | |
parent | f7dc15c6bdb75a5f611c389ece3fe251f94a2d8f (diff) | |
download | gitlab-ce-47f539f5a6a930b2cfd4f9834b4d1bd5e1c180cb.tar.gz |
Snippets: public/internal/private
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project_team.rb | 4 | ||||
-rw-r--r-- | app/models/snippet.rb | 16 |
2 files changed, 16 insertions, 4 deletions
diff --git a/app/models/project_team.rb b/app/models/project_team.rb index e065554d3b8..657ee23ae23 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -133,6 +133,10 @@ class ProjectTeam max_tm_access(user.id) == Gitlab::Access::MASTER end + def member?(user_id) + !!find_tm(user_id) + end + def max_tm_access(user_id) access = [] access << project.project_members.find_by(user_id: user_id).try(:access_field) diff --git a/app/models/snippet.rb b/app/models/snippet.rb index addde2d106a..974c239da5c 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -17,8 +17,9 @@ class Snippet < ActiveRecord::Base include Linguist::BlobHelper + include Gitlab::VisibilityLevel - default_value_for :private, true + default_value_for :visibility_level, Snippet::PRIVATE belongs_to :author, class_name: "User" @@ -30,10 +31,13 @@ class Snippet < ActiveRecord::Base validates :title, presence: true, length: { within: 0..255 } validates :file_name, presence: true, length: { within: 0..255 } validates :content, presence: true + validates :visibility_level, inclusion: { in: Gitlab::VisibilityLevel.values } # Scopes - scope :are_internal, -> { where(private: false) } - scope :are_private, -> { where(private: true) } + scope :are_internal, -> { where(visibility_level: Snippet::INTERNAL) } + scope :are_private, -> { where(visibility_level: Snippet::PRIVATE) } + scope :are_public, -> { where(visibility_level: Snippet::PUBLIC) } + scope :public_and_internal, -> { where(visibility_level: [Snippet::PUBLIC, Snippet::INTERNAL]) } scope :fresh, -> { order("created_at DESC") } scope :expired, -> { where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) } scope :non_expired, -> { where(["expires_at IS NULL OR expires_at > ?", Time.current]) } @@ -66,6 +70,10 @@ class Snippet < ActiveRecord::Base expires_at && expires_at < Time.current end + def visibility_level_field + visibility_level + end + class << self def search(query) where('(title LIKE :query OR file_name LIKE :query)', query: "%#{query}%") @@ -76,7 +84,7 @@ class Snippet < ActiveRecord::Base end def accessible_to(user) - where('private = ? OR author_id = ?', false, user) + where('visibility_level IN (?) OR author_id = ?', [Snippet::INTERNAL, Snippet::PUBLIC], user) end end end |