Fix fetching all user projects [SCI-2787]

This commit is contained in:
Matej Zrimšek 2018-10-24 00:29:30 +02:00
parent 9fd99d9fc5
commit 18e52e2c6f
4 changed files with 25 additions and 17 deletions

View file

@ -349,7 +349,7 @@ class ExperimentsController < ApplicationController
end end
def load_projects_tree def load_projects_tree
@projects_tree = current_user.projects_tree(current_team, nil) @projects_tree = current_user.projects_tree(current_team)
end end
def check_view_permissions def check_view_permissions

View file

@ -661,7 +661,7 @@ class MyModulesController < ApplicationController
end end
def load_projects_tree def load_projects_tree
@projects_tree = current_user.projects_tree(current_team, nil) @projects_tree = current_user.projects_tree(current_team)
end end
def check_manage_permissions def check_manage_permissions

View file

@ -357,7 +357,9 @@ class ProjectsController < ApplicationController
@current_team = current_team if current_team @current_team = current_team if current_team
@current_team ||= current_user.teams.first @current_team ||= current_user.teams.first
@current_sort ||= 'new' @current_sort ||= 'new'
@projects_tree = current_user.projects_tree(@current_team, @current_sort) @projects_tree = current_user.projects_tree(
@current_team, @current_filter, @current_sort
)
else else
@projects_tree = [] @projects_tree = []
end end

View file

@ -350,7 +350,7 @@ class User < ApplicationRecord
result || [] result || []
end end
def projects_tree(team, sort_by = nil) def projects_tree(team, filter_by = nil, sort_by = nil)
result = team.projects.includes(active_experiments: :active_my_modules) result = team.projects.includes(active_experiments: :active_my_modules)
unless is_admin_of_team?(team) unless is_admin_of_team?(team)
# Only admins see all projects of the team # Only admins see all projects of the team
@ -359,19 +359,25 @@ class User < ApplicationRecord
) )
end end
sort = result = case filter_by
case sort_by when 'archived'
when 'old' result.where(archived: true)
{ created_at: :asc } when 'active'
when 'atoz' result.where(archived: false)
{ name: :asc } else
when 'ztoa' result
{ name: :desc } end
else sort = case sort_by
{ created_at: :desc } when 'old'
end { created_at: :asc }
when 'atoz'
result.where(archived: false).distinct.order(sort) { name: :asc }
when 'ztoa'
{ name: :desc }
else
{ created_at: :desc }
end
result.distinct.order(sort)
end end
# Finds all activities of user that is assigned to project. If user # Finds all activities of user that is assigned to project. If user