-
Notifications
You must be signed in to change notification settings - Fork 16
/
organization.rb
117 lines (90 loc) · 2.38 KB
/
organization.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# frozen_string_literal: true
class Organization < ApplicationRecord
has_one :vso_config, dependent: :destroy
has_many :tasks, as: :assigned_to
has_many :organizations_users, dependent: :destroy
has_many :users, through: :organizations_users
has_many :non_admin_users, -> { non_admin }, class_name: "OrganizationsUser"
validates :name, presence: true
validates :url, presence: true, uniqueness: true
before_save :clean_url
def admins
organizations_users.includes(:user).select(&:admin?).map(&:user)
end
def can_bulk_assign_tasks?
false
end
def show_regional_office_in_queue?
false
end
def show_reader_link_column?
true
end
def use_task_pages_api?
false
end
def non_admins
organizations_users.includes(:user).non_admin.map(&:user)
end
def self.assignable(task)
select { |org| org.can_receive_task?(task) }
end
def can_receive_task?(task)
return false if task.assigned_to == self
return false if task.assigned_to.is_a?(User) && task.parent && task.parent.assigned_to == self
true
end
def next_assignee(_options = {})
nil
end
def automatically_assign_to_member?
!!next_assignee
end
def selectable_in_queue?
true
end
def user_has_access?(user)
users.pluck(:id).include?(user&.id)
end
def user_is_admin?(user)
admins.include?(user)
end
def path
"/organizations/#{url || id}"
end
def user_admin_path
"#{path}/users"
end
def queue_tabs
[
unassigned_tasks_tab,
assigned_tasks_tab,
on_hold_tasks_tab,
completed_tasks_tab
]
end
def unassigned_tasks_tab
::UnassignedTasksTab.new(
assignee: self,
show_regional_office_column: show_regional_office_in_queue?,
show_reader_link_column: show_reader_link_column?,
allow_bulk_assign: can_bulk_assign_tasks?
)
end
def assigned_tasks_tab
::AssignedTasksTab.new(assignee: self, show_regional_office_column: show_regional_office_in_queue?)
end
def on_hold_tasks_tab
::OnHoldTasksTab.new(assignee: self, show_regional_office_column: show_regional_office_in_queue?)
end
def completed_tasks_tab
::CompletedTasksTab.new(assignee: self, show_regional_office_column: show_regional_office_in_queue?)
end
def ama_task_serializer
WorkQueue::TaskSerializer
end
private
def clean_url
self.url = url&.parameterize&.dasherize
end
end