Skip to content

Commit

Permalink
Merge pull request #458 from ChicagoWorldcon/stag-approval-queries
Browse files Browse the repository at this point in the history
plan-594 fix snapshot queries
  • Loading branch information
balen authored Jul 20, 2022
2 parents 6cd0d6c + bcc67f0 commit 4bb4c63
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ def includes
def references
[
:email_addresses,
:convention_roles,
{person_schedule_approvals: {schedule_workflow: :schedule_snapshot}}
:convention_roles
# {person_schedule_approvals: {schedule_workflow: :schedule_snapshot}}
]
end

Expand All @@ -397,10 +397,10 @@ def subquery(operation:, value:)

def get_table(column:)
if column.include?('draft_person_schedule_approvals')
return PersonScheduleApproval.arel_table
return PersonScheduleApproval.arel_table #.alias('draft_approvals')
end
if column.include?('firm_person_schedule_approvals')
return PersonScheduleApproval.arel_table
return PersonScheduleApproval.arel_table #.alias('firm_approvals')
end

return super(column: column)
Expand All @@ -418,14 +418,34 @@ def get_query_part(table:, column:, operation:, value:, top: false, key: nil)
end

def approval_query(table:, column:, operation:, value:, label:)
op = translate_operator(operation: operation)
people = Person.arel_table
schedule_snapshots = ScheduleSnapshot.arel_table
part = table[column.to_sym].send(op, value).and(schedule_snapshots[:label].eq(label))
schedule_workflows = ScheduleWorkflow.arel_table
if value == 'not_set'
part = part.or(table[column.to_sym].eq(nil))
people[:id].not_in(
table.project(:person_id)
.join(
schedule_workflows,
Arel::Nodes::OuterJoin
)
.on(table[:schedule_workflow_id].eq(schedule_workflows[:id]))
.where(
schedule_workflows[:state].eq(label).and(table[:approved].eq('yes')).or(table[:approved].eq('no'))
)
)
else
people[:id].in(
table.project(:person_id)
.join(
schedule_workflows,
Arel::Nodes::OuterJoin
)
.on(table[:schedule_workflow_id].eq(schedule_workflows[:id]))
.where(
schedule_workflows[:state].eq(label).and(table[:approved].eq(value))
)
)
end

return part
end


Expand Down

0 comments on commit 4bb4c63

Please sign in to comment.