Skip to content

Commit

Permalink
feat(board-moderators): Added query to get moderators for all boards …
Browse files Browse the repository at this point in the history
…in smf repo
  • Loading branch information
crod951 committed Nov 15, 2024
1 parent 72e7857 commit 755640e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/epochtalk_server_web/controllers/board.ex
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ defmodule EpochtalkServerWeb.Controllers.Board do
stripped <- Validate.cast(attrs, "stripped", :boolean, default: false),
user_priority <- ACL.get_user_priority(conn),
board_mapping <- BoardMapping.all(stripped: stripped),
board_moderators <- BoardModerator.all(),
{:ok, board_moderators} <- ProxyConversion.build_model("boards.moderators"),
{:ok, board_counts} <- ProxyConversion.build_model("boards.counts"),
{:ok, board_last_post_info} <- ProxyConversion.build_model("boards.last_post_info"),
categories <- Category.all() do
Expand Down
2 changes: 1 addition & 1 deletion lib/epochtalk_server_web/controllers/thread.ex
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
user_priority <- ACL.get_user_priority(conn),
:ok <- ACL.allow!(conn, "threads.byBoard"),
board_mapping <- BoardMapping.all(),
board_moderators <- BoardModerator.all(),
{:ok, board_moderators} <- ProxyConversion.build_model("boards.moderators"),
{:ok, board_counts} <- ProxyConversion.build_model("boards.counts"),
{:ok, board_last_post_info} <- ProxyConversion.build_model("boards.last_post_info"),
{:ok, threads, data} <-
Expand Down
29 changes: 29 additions & 0 deletions lib/epochtalk_server_web/helpers/proxy_conversion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ defmodule EpochtalkServerWeb.Helpers.ProxyConversion do
"boards.last_post_info" ->
build_board_last_post_info()

"boards.moderators" ->
build_board_moderators()

"threads.recent" ->
build_recent_threads()

Expand Down Expand Up @@ -227,6 +230,32 @@ defmodule EpochtalkServerWeb.Helpers.ProxyConversion do
end
end

def build_board_moderators() do
%{id_board_blacklist: id_board_blacklist} =
Application.get_env(:epochtalk_server, :proxy_config)

from(b in "smf_boards",
where: b.id_board not in ^id_board_blacklist
)
|> join(:left, [b], mod in "smf_moderators", on: b.id_board == mod.id_board)
|> join(:left, [b, mod], m in "smf_members", on: mod.id_member == m.id_member)
|> select([b, mod, m], %{
board_id: b.id_board,
user_id: m.id_member,
user: %{
username: m.realname
}
})
|> SmfRepo.all()
|> case do
[] ->
{:error, "Board Moderators not found"}

moderators ->
return_tuple(moderators)
end
end

def build_board(id) do
%{id_board_blacklist: id_board_blacklist} =
Application.get_env(:epochtalk_server, :proxy_config)
Expand Down

0 comments on commit 755640e

Please sign in to comment.