mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-11 22:36:33 +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
|
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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,8 +359,15 @@ class User < ApplicationRecord
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
sort =
|
result = case filter_by
|
||||||
case sort_by
|
when 'archived'
|
||||||
|
result.where(archived: true)
|
||||||
|
when 'active'
|
||||||
|
result.where(archived: false)
|
||||||
|
else
|
||||||
|
result
|
||||||
|
end
|
||||||
|
sort = case sort_by
|
||||||
when 'old'
|
when 'old'
|
||||||
{ created_at: :asc }
|
{ created_at: :asc }
|
||||||
when 'atoz'
|
when 'atoz'
|
||||||
|
@ -370,8 +377,7 @@ class User < ApplicationRecord
|
||||||
else
|
else
|
||||||
{ created_at: :desc }
|
{ created_at: :desc }
|
||||||
end
|
end
|
||||||
|
result.distinct.order(sort)
|
||||||
result.where(archived: false).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
|
||||||
|
|
Loading…
Add table
Reference in a new issue