Skip to content

Commit

Permalink
Merge pull request #455 from ChicagoWorldcon/stag-approval-queries
Browse files Browse the repository at this point in the history
plan-594 fix approval queries
  • Loading branch information
Gailbear authored Jul 20, 2022
2 parents d66fab8 + 03c6c43 commit 6cd0d6c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/controllers/concerns/resource_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,14 @@ def query_part(filter:)
# change to allowd limiting to named cols?, pass in list of cols to include based in what is displayed ...
model_class.columns.each do |col|
next unless [:text, :string].include?(col.type)
query_part = get_query_part(table: col_table, column: col.name, operation: 'like', value: value)
query_part = get_query_part(table: col_table, column: col.name, operation: 'like', value: value, key: key)
part = part ? part.or(query_part) : query_part
end
# This for survey submissions ....
if model_class == Survey::Submission
Survey::Response.columns.each do |col|
next unless [:text, :string].include?(col.type)
query_part = get_query_part(table: Arel::Table.new('survey_responses'), column: col.name, operation: 'like', value: value)
query_part = get_query_part(table: Arel::Table.new('survey_responses'), column: col.name, operation: 'like', value: value, key: key)
part = part ? part.or(query_part) : query_part
end
end
Expand All @@ -320,7 +320,7 @@ def query_part(filter:)
if array_col?(col_name: col)
col_table = array_table(col_name: col)
end
part = get_query_part(table: col_table, column: col, operation: operation, value: value, top: true)
part = get_query_part(table: col_table, column: col, operation: operation, value: value, top: true, key: key)

if (key.include?('responses.'))
key.slice! "responses."
Expand Down Expand Up @@ -365,7 +365,7 @@ def get_column(column:)
return col
end

def get_query_part(table:, column:, operation:, value:, top: false)
def get_query_part(table:, column:, operation:, value:, top: false, key: nil)
op = translate_operator(operation: operation)

return nil if value.kind_of?(String) && value.blank?
Expand Down
25 changes: 24 additions & 1 deletion app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ def includes
def references
[
:email_addresses,
:convention_roles
:convention_roles,
{person_schedule_approvals: {schedule_workflow: :schedule_snapshot}}
]
end

Expand Down Expand Up @@ -405,6 +406,28 @@ def get_table(column:)
return super(column: column)
end

def get_query_part(table:, column:, operation:, value:, top: false, key: nil)
if key.include?('draft_person_schedule_approvals')
return approval_query(table: table, column: column, operation: operation, value: value, label: 'draft')
end
if key.include?('firm_person_schedule_approvals')
return approval_query(table: table, column: column, operation: operation, value: value, label: 'firm')
end

return super(table: table, column: column, operation: operation, value: value, top: top, key: key)
end

def approval_query(table:, column:, operation:, value:, label:)
op = translate_operator(operation: operation)
schedule_snapshots = ScheduleSnapshot.arel_table
part = table[column.to_sym].send(op, value).and(schedule_snapshots[:label].eq(label))
if value == 'not_set'
part = part.or(table[column.to_sym].eq(nil))
end

return part
end


# TODO: on create must have at least one email_addresses_attributes
# def join_tables
Expand Down

0 comments on commit 6cd0d6c

Please sign in to comment.