From e381651df2a59c94460fc85d113ea0c3f763c3fd Mon Sep 17 00:00:00 2001 From: Giga Chubinidze Date: Wed, 19 Jul 2023 10:31:14 +0400 Subject: [PATCH] added scope functionality --- app/models/project.rb | 5 +++++ app/services/toolbars/projects_service.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 2735d78a7..5c4723419 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -71,6 +71,11 @@ class Project < ApplicationRecord end end) + scope :not_assigned_to_user, lambda { |user| + left_joins(:user_assignments) + .where('user_assignments.user_id = ? AND user_assignments.id IS NULL', user.id) + } + scope :templates, -> { where(template: true) } after_create :auto_assign_project_members, if: :visible? diff --git a/app/services/toolbars/projects_service.rb b/app/services/toolbars/projects_service.rb index a653a1f34..57ad67a81 100644 --- a/app/services/toolbars/projects_service.rb +++ b/app/services/toolbars/projects_service.rb @@ -13,7 +13,7 @@ module Toolbars @project_folders = current_user.current_team.project_folders.where(id: project_folder_ids) @items = @projects + @project_folders - @not_assigned = @projects.any? { |project| !project.assigned_users.include?(current_user) } + @not_assigned = current_user.current_team.projects.not_assigned_to_user(current_user).any? @single = @items.length == 1