mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-09 16:01:30 +08:00
replase user_projects with user_assignment where the permissions are calculated
This commit is contained in:
parent
784e43e328
commit
ddaa4b4c57
2 changed files with 13 additions and 17 deletions
|
|
@ -20,10 +20,6 @@ module PermissionCheckableModel
|
||||||
user_assignments.find_by(user: user)&.user_role&.permissions
|
user_assignments.find_by(user: user)&.user_role&.permissions
|
||||||
end
|
end
|
||||||
|
|
||||||
if user_role_permissions.blank? && permission_parent.present?
|
|
||||||
user_role_permissions = permission_parent.send :load_user_role_permissions, user
|
|
||||||
end
|
|
||||||
|
|
||||||
user_role_permissions
|
user_role_permissions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ class Project < ApplicationRecord
|
||||||
|
|
||||||
scope :visible_to, (lambda do |user, team|
|
scope :visible_to, (lambda do |user, team|
|
||||||
unless user.is_admin_of_team?(team)
|
unless user.is_admin_of_team?(team)
|
||||||
left_outer_joins(:user_projects)
|
left_outer_joins(:user_assignments)
|
||||||
.where('visibility = 1 OR user_projects.user_id = :id', id: user.id)
|
.where('visibility = 1 OR user_assignments.user_id = :id', id: user.id)
|
||||||
.group(:id)
|
.group(:id)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
@ -70,8 +70,8 @@ class Project < ApplicationRecord
|
||||||
if user.is_admin_of_team?(team)
|
if user.is_admin_of_team?(team)
|
||||||
projects.where('projects.archived IS FALSE AND projects.name ILIKE ?', "%#{name}%")
|
projects.where('projects.archived IS FALSE AND projects.name ILIKE ?', "%#{name}%")
|
||||||
else
|
else
|
||||||
projects.joins(:user_projects)
|
projects.joins(:user_assignments)
|
||||||
.where('user_projects.user_id = ? OR projects.visibility = 1', user.id)
|
.where('user_assignments.user_id = ? OR projects.visibility = 1', user.id)
|
||||||
.where('projects.archived IS FALSE AND projects.name ILIKE ?',
|
.where('projects.archived IS FALSE AND projects.name ILIKE ?',
|
||||||
"%#{name}%")
|
"%#{name}%")
|
||||||
end
|
end
|
||||||
|
|
@ -90,12 +90,12 @@ class Project < ApplicationRecord
|
||||||
new_query =
|
new_query =
|
||||||
Project
|
Project
|
||||||
.distinct
|
.distinct
|
||||||
.joins(:user_projects)
|
.joins(:user_assignments)
|
||||||
.where('projects.team_id = ?', current_team.id)
|
.where('projects.team_id = ?', current_team.id)
|
||||||
unless user.user_teams.find_by(team: current_team).try(:admin?)
|
unless user.user_teams.find_by(team: current_team).try(:admin?)
|
||||||
# Admins see all projects in the team
|
# Admins see all projects in the team
|
||||||
new_query = new_query.where(
|
new_query = new_query.where(
|
||||||
'projects.visibility = 1 OR user_projects.user_id = ?',
|
'projects.visibility = 1 OR user_assignments.user_id = ?',
|
||||||
user.id
|
user.id
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -115,10 +115,10 @@ class Project < ApplicationRecord
|
||||||
if include_archived
|
if include_archived
|
||||||
new_query =
|
new_query =
|
||||||
new_query
|
new_query
|
||||||
.joins(:user_projects)
|
.joins(:user_assignments)
|
||||||
.where(
|
.where(
|
||||||
'user_teams.role = 2 OR projects.visibility = 1 OR ' \
|
'user_teams.role = 2 OR projects.visibility = 1 OR ' \
|
||||||
'user_projects.user_id = ?',
|
'user_assignments.user_id = ?',
|
||||||
user.id
|
user.id
|
||||||
)
|
)
|
||||||
.where_attributes_like('projects.name', query, options)
|
.where_attributes_like('projects.name', query, options)
|
||||||
|
|
@ -126,10 +126,10 @@ class Project < ApplicationRecord
|
||||||
else
|
else
|
||||||
new_query =
|
new_query =
|
||||||
new_query
|
new_query
|
||||||
.joins(:user_projects)
|
.joins(:user_assignments)
|
||||||
.where(
|
.where(
|
||||||
'user_teams.role = 2 OR projects.visibility = 1 OR ' \
|
'user_teams.role = 2 OR projects.visibility = 1 OR ' \
|
||||||
'user_projects.user_id = ?',
|
'user_assignments.user_id = ?',
|
||||||
user.id
|
user.id
|
||||||
)
|
)
|
||||||
.where_attributes_like('projects.name', query, options)
|
.where_attributes_like('projects.name', query, options)
|
||||||
|
|
@ -153,9 +153,9 @@ class Project < ApplicationRecord
|
||||||
# If project is visible everyone from the team can view it
|
# If project is visible everyone from the team can view it
|
||||||
Project.where(team: teams)
|
Project.where(team: teams)
|
||||||
.left_outer_joins(team: :user_teams)
|
.left_outer_joins(team: :user_teams)
|
||||||
.left_outer_joins(:user_projects)
|
.left_outer_joins(:user_assignments)
|
||||||
.where('projects.visibility = 1 OR '\
|
.where('projects.visibility = 1 OR '\
|
||||||
'user_projects.user_id = :user_id OR '\
|
'user_assignments.user_id = :user_id OR '\
|
||||||
'(user_teams.user_id = :user_id AND user_teams.role = 2)',
|
'(user_teams.user_id = :user_id AND user_teams.role = 2)',
|
||||||
user_id: user.id)
|
user_id: user.id)
|
||||||
.distinct
|
.distinct
|
||||||
|
|
@ -209,7 +209,7 @@ class Project < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_role(user)
|
def user_role(user)
|
||||||
user_projects.find_by_user_id(user)&.role
|
user_assignments.find_by_user_id(user)&.user_role.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def sorted_experiments(sort_by = :new, archived = false)
|
def sorted_experiments(sort_by = :new, archived = false)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue