diff options
author | Marcia Ramos <virtua.creative@gmail.com> | 2017-05-03 12:27:16 -0300 |
---|---|---|
committer | Marcia Ramos <virtua.creative@gmail.com> | 2017-05-03 12:27:16 -0300 |
commit | 17d5b333af19ccab3685592082740ad1db0e2fb4 (patch) | |
tree | 280d52a6b0ec4e438013c5d293a5e0eda99ae572 /app/finders/snippets_finder.rb | |
parent | dd91260899912956534ffffda2272053668c8f68 (diff) | |
parent | c33c23104246b14f25d4c535e7f153a0cb389f7f (diff) | |
download | gitlab-ce-17d5b333af19ccab3685592082740ad1db0e2fb4.tar.gz |
Merge branch 'new-docs-topic-issues' of gitlab.com:gitlab-org/gitlab-ce into new-docs-topic-issuesnew-docs-topic-issues
Diffstat (limited to 'app/finders/snippets_finder.rb')
-rw-r--r-- | app/finders/snippets_finder.rb | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/app/finders/snippets_finder.rb b/app/finders/snippets_finder.rb index 00ff1611039..da6e6e87a6f 100644 --- a/app/finders/snippets_finder.rb +++ b/app/finders/snippets_finder.rb @@ -1,14 +1,17 @@ class SnippetsFinder def execute(current_user, params = {}) filter = params[:filter] + user = params.fetch(:user, current_user) case filter when :all then snippets(current_user).fresh + when :public then + Snippet.are_public.fresh when :by_user then - by_user(current_user, params[:user], params[:scope]) + by_user(current_user, user, params[:scope]) when :by_project - by_project(current_user, params[:project]) + by_project(current_user, params[:project], params[:scope]) end end @@ -29,35 +32,35 @@ class SnippetsFinder def by_user(current_user, user, scope) snippets = user.snippets.fresh - return snippets.are_public unless current_user - - if user == current_user - case scope - when 'are_internal' then - snippets.are_internal - when 'are_private' then - snippets.are_private - when 'are_public' then - snippets.are_public - else - snippets - end + if current_user + include_private = user == current_user + by_scope(snippets, scope, include_private) else - snippets.public_and_internal + snippets.are_public end end - def by_project(current_user, project) + def by_project(current_user, project, scope) snippets = project.snippets.fresh if current_user - if project.team.member?(current_user) || current_user.admin? - snippets - else - snippets.public_and_internal - end + include_private = project.team.member?(current_user) || current_user.admin? + by_scope(snippets, scope, include_private) else snippets.are_public end end + + def by_scope(snippets, scope = nil, include_private = false) + case scope.to_s + when 'are_private' + include_private ? snippets.are_private : Snippet.none + when 'are_internal' + snippets.are_internal + when 'are_public' + snippets.are_public + else + include_private ? snippets : snippets.public_and_internal + end + end end |