diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-02-03 17:46:34 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-02-03 17:46:34 +0000 |
commit | edc18e777ca72442986c9843624934f248a8a2fe (patch) | |
tree | a09bbc7359c4c94d7cc1bd0da612d016617efe27 /app | |
parent | 6addb15b15f3d59469d7569271b6449a2a164b87 (diff) | |
parent | 6a87daed765ddfbaa30ac942de8ccf55cc3a64a4 (diff) | |
download | gitlab-ce-edc18e777ca72442986c9843624934f248a8a2fe.tar.gz |
Merge branch 'bug/filtering' into 'master'
Bug in issue and merge request filtering
Fixes #1006
Diffstat (limited to 'app')
-rw-r--r-- | app/services/filtering_service.rb | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/app/services/filtering_service.rb b/app/services/filtering_service.rb index b339065890b..ebd394ee758 100644 --- a/app/services/filtering_service.rb +++ b/app/services/filtering_service.rb @@ -24,7 +24,8 @@ class FilteringService @current_user = current_user @params = params - items = by_scope + items = init_collection + items = by_scope(items) items = by_state(items) items = by_group(items) items = by_project(items) @@ -37,20 +38,30 @@ class FilteringService private - def by_scope + def init_collection table_name = klass.table_name + return klass.of_projects(Project.public_only) unless current_user + + if project + if current_user.can?(:read_project, project) + project.send(table_name) + else + [] + end + else + klass.of_projects(current_user.authorized_projects) + end + end + + def by_scope(items) case params[:scope] when 'created-by-me', 'authored' then - current_user.send(table_name) + klass.where(author_id: current_user.id) when 'all' then - if current_user - klass.of_projects(current_user.authorized_projects.pluck(:id)) - else - klass.of_projects(Project.public_only) - end + klass when 'assigned-to-me' then - current_user.send("assigned_#{table_name}") + klass.where(assignee_id: current_user.id) else raise 'You must specify default scope' end @@ -120,4 +131,8 @@ class FilteringService items end + + def project + Project.where(id: params[:project_id]).first if params[:project_id].present? + end end |