Skip to content

Commit

Permalink
hack: fix issue with owner join references
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Jan 15, 2024
1 parent 34672a6 commit 3cb566b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions app/models/license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,15 @@ class License < ApplicationRecord
return where(user_id: owner_identifier) if
UUID_RE.match?(owner_identifier)

scope = joins(:owner).where('users.email ILIKE ?', "%#{sanitize_sql_like(owner_identifier)}%")
scope = joins(:owner).where.not(owner: { email: nil }) # FIXME(ezekg) hack so our join gets aliased
.where('owner.email ILIKE ?', "%#{sanitize_sql_like(owner_identifier)}%")
return scope unless
UUID_CHAR_RE.match?(owner_identifier)

scope.or(
joins(:owner).where(<<~SQL.squish, owner_identifier.gsub(SANITIZE_TSV_RE, ' '))
to_tsvector('simple', users.id::text)
joins(:owner).where.not(owner: { id: nil })
.where(<<~SQL.squish, owner_identifier.gsub(SANITIZE_TSV_RE, ' '))
to_tsvector('simple', owner.id::text)
@@
to_tsquery(
'simple',
Expand Down
8 changes: 5 additions & 3 deletions app/models/machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,17 @@ class ResurrectionExpiredError < StandardError; end
return none if
owner_identifier.empty?

return joins(:owner).where(users: { id: owner_identifier }) if
return joins(:owner).where(owner: { id: owner_identifier }) if
UUID_RE.match?(owner_identifier)

scope = joins(:owner).where('users.email ILIKE ?', "%#{sanitize_sql_like(owner_identifier)}%")
scope = joins(:owner).where.not(owner: { email: nil }) # FIXME(ezekg) hack so our join gets aliased
.where('owner.email ILIKE ?', "%#{sanitize_sql_like(owner_identifier)}%")
return scope unless
UUID_CHAR_RE.match?(owner_identifier)

scope.or(
joins(:owner).where(<<~SQL.squish, owner_identifier.gsub(SANITIZE_TSV_RE, ' '))
joins(:owner).where.not(owner: { id: nil })
.where(<<~SQL.squish, owner_identifier.gsub(SANITIZE_TSV_RE, ' '))
to_tsvector('simple', users.id::text)
@@
to_tsquery(
Expand Down

0 comments on commit 3cb566b

Please sign in to comment.