Skip to content

Commit

Permalink
Refator sign order from view to login-aware query
Browse files Browse the repository at this point in the history
  • Loading branch information
r-tae committed Aug 29, 2024
1 parent bf53542 commit ad8ca1f
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 251 deletions.
19 changes: 13 additions & 6 deletions lib/signbank/dictionary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,24 @@ defmodule Signbank.Dictionary do
@doc """
Finds next and previous Signs in predefined sorting order.
"""
def get_prev_next_signs!(%Sign{id: id}) do
# TODO: this won't work with unpublished signs, we need to know the publishing status of every sign to actually
# direct people to the correct sign
def get_prev_next_signs!(%Sign{id: id}, current_user) do
query =
Signbank.SignOrder.order_query(
Signbank.SignOrder.default_order(),
case current_user do
%User{role: role} when role in [:tech, :editor] -> true
_ -> false
end
)

Repo.one!(
from so in "sign_order",
from so in subquery(query),
left_join: p in Sign,
on: [id: so.previous],
left_join: n in Sign,
on: [id: so.next],
where: so.sign_id == ^id,
select: %{previous: p, position: so.row_number, next: n}
select: %{previous: p, next: n, position: so.position},
where: so.id == ^id
)
end

Expand Down
Loading

0 comments on commit ad8ca1f

Please sign in to comment.