mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-02 18:04:29 +08:00
Fix fetching all user projects [SCI-2787]
This commit is contained in:
parent
9fd99d9fc5
commit
18e52e2c6f
4 changed files with 25 additions and 17 deletions
|
@ -349,7 +349,7 @@ class ExperimentsController < ApplicationController
|
|||
end
|
||||
|
||||
def load_projects_tree
|
||||
@projects_tree = current_user.projects_tree(current_team, nil)
|
||||
@projects_tree = current_user.projects_tree(current_team)
|
||||
end
|
||||
|
||||
def check_view_permissions
|
||||
|
|
|
@ -661,7 +661,7 @@ class MyModulesController < ApplicationController
|
|||
end
|
||||
|
||||
def load_projects_tree
|
||||
@projects_tree = current_user.projects_tree(current_team, nil)
|
||||
@projects_tree = current_user.projects_tree(current_team)
|
||||
end
|
||||
|
||||
def check_manage_permissions
|
||||
|
|
|
@ -357,7 +357,9 @@ class ProjectsController < ApplicationController
|
|||
@current_team = current_team if current_team
|
||||
@current_team ||= current_user.teams.first
|
||||
@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
|
||||
@projects_tree = []
|
||||
end
|
||||
|
|
|
@ -350,7 +350,7 @@ class User < ApplicationRecord
|
|||
result || []
|
||||
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)
|
||||
unless is_admin_of_team?(team)
|
||||
# Only admins see all projects of the team
|
||||
|
@ -359,19 +359,25 @@ class User < ApplicationRecord
|
|||
)
|
||||
end
|
||||
|
||||
sort =
|
||||
case sort_by
|
||||
when 'old'
|
||||
{ created_at: :asc }
|
||||
when 'atoz'
|
||||
{ name: :asc }
|
||||
when 'ztoa'
|
||||
{ name: :desc }
|
||||
else
|
||||
{ created_at: :desc }
|
||||
end
|
||||
|
||||
result.where(archived: false).distinct.order(sort)
|
||||
result = case filter_by
|
||||
when 'archived'
|
||||
result.where(archived: true)
|
||||
when 'active'
|
||||
result.where(archived: false)
|
||||
else
|
||||
result
|
||||
end
|
||||
sort = case sort_by
|
||||
when 'old'
|
||||
{ created_at: :asc }
|
||||
when 'atoz'
|
||||
{ name: :asc }
|
||||
when 'ztoa'
|
||||
{ name: :desc }
|
||||
else
|
||||
{ created_at: :desc }
|
||||
end
|
||||
result.distinct.order(sort)
|
||||
end
|
||||
|
||||
# Finds all activities of user that is assigned to project. If user
|
||||
|
|
Loading…
Add table
Reference in a new issue