Skip to content

Commit

Permalink
Merge pull request #116 from epochtalk/version-update
Browse files Browse the repository at this point in the history
Version update
  • Loading branch information
unenglishable authored Dec 6, 2024
2 parents 699b2af + eceefcb commit 7f6c195
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 130 deletions.
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.14.4-otp-25
erlang 25.3.1
elixir 1.17.3-otp-27
erlang 27.1.2
3 changes: 0 additions & 3 deletions lib/epochtalk_server_web/controllers/board.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ defmodule EpochtalkServerWeb.Controllers.Board do
400,
"Error, cannot convert slug: board does not exist"
)

_ ->
ErrorHelpers.render_json_error(conn, 400, "Error, cannot convert board slug to id")
end
end
end
2 changes: 0 additions & 2 deletions lib/epochtalk_server_web/controllers/image_reference.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ defmodule EpochtalkServerWeb.Controllers.ImageReference do
# checksum <- Validate.cast(attrs, "checksum", :string, required: true),
file_type <- Validate.cast(attrs, "file_type", :string, required: true) do
%{length: length, type: file_type}
else
_ -> %{error: "Invalid attrs"}
end
end
end
5 changes: 2 additions & 3 deletions lib/epochtalk_server_web/controllers/mention.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ defmodule EpochtalkServerWeb.Controllers.Mention do
pagination_data: data,
extended: extended
}),
else:
({:auth, nil} ->
ErrorHelpers.render_json_error(conn, 400, "Not logged in, cannot page mentions"))
else: ({:auth, nil} ->
ErrorHelpers.render_json_error(conn, 400, "Not logged in, cannot page mentions"))
end
end
12 changes: 2 additions & 10 deletions lib/epochtalk_server_web/controllers/moderation_log.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ defmodule EpochtalkServerWeb.Controllers.ModerationLog do
@moduledoc """
Controller For `ModerationLog` related API requests
"""
alias EpochtalkServer.Auth.Guardian
alias EpochtalkServer.Models.ModerationLog
alias EpochtalkServerWeb.ErrorHelpers
alias EpochtalkServerWeb.Helpers.Validate
Expand All @@ -14,21 +13,14 @@ defmodule EpochtalkServerWeb.Controllers.ModerationLog do
Used to page `ModerationLog` models for moderation log view`
"""
def page(conn, attrs) do
with {:auth, true} <- {:auth, Guardian.Plug.authenticated?(conn)},
:ok <- ACL.allow!(conn, "moderationLogs.page"),
with :ok <- ACL.allow!(conn, "moderationLogs.page"),
page <- Validate.cast(attrs, "page", :integer, min: 1),
limit <- Validate.cast(attrs, "limit", :integer, min: 1),
{:ok, moderation_logs, data} <- ModerationLog.page(attrs, page, per_page: limit) do
render(conn, :page, %{moderation_logs: moderation_logs, pagination_data: data})
else
{:auth, false} ->
ErrorHelpers.render_json_error(conn, 400, "Not logged in, cannot page moderation log")

{:error, data} ->
ErrorHelpers.render_json_error(conn, 400, data)

_ ->
ErrorHelpers.render_json_error(conn, 500, "There was an issue getting the moderation log")
ErrorHelpers.render_json_error(conn, 500, "There was an issue paging the moderation log")
end
end
end
7 changes: 0 additions & 7 deletions lib/epochtalk_server_web/controllers/notification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ defmodule EpochtalkServerWeb.Controllers.Notification do
400,
"Not logged in, cannot fetch notification counts"
)

{:access, false} ->
ErrorHelpers.render_json_error(
conn,
400,
"Not logged in, cannot fetch notification counts"
)
end
end

Expand Down
12 changes: 0 additions & 12 deletions lib/epochtalk_server_web/controllers/poll.ex
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ defmodule EpochtalkServerWeb.Controllers.Poll do
"Account must be active to modify lock on poll"
)

{:error, data} ->
ErrorHelpers.render_json_error(conn, 400, data)

_ ->
ErrorHelpers.render_json_error(conn, 400, "Error, cannot lock poll")
end
Expand Down Expand Up @@ -316,9 +313,6 @@ defmodule EpochtalkServerWeb.Controllers.Poll do
poll <- Poll.by_thread(thread_id) do
render(conn, :poll, %{poll: poll, has_voted: false})
else
{:valid_answers_list, false} ->
ErrorHelpers.render_json_error(conn, 400, "Error, 'answer_ids' must be a list")

{:can_read, {:ok, false}} ->
ErrorHelpers.render_json_error(
conn,
Expand Down Expand Up @@ -355,12 +349,6 @@ defmodule EpochtalkServerWeb.Controllers.Poll do
{:board_banned, {:ok, true}} ->
ErrorHelpers.render_json_error(conn, 403, "Unauthorized, you are banned from this board")

{:error, :board_does_not_exist} ->
ErrorHelpers.render_json_error(conn, 400, "Error, board does not exist")

{:error, data} ->
ErrorHelpers.render_json_error(conn, 400, data)

_ ->
ErrorHelpers.render_json_error(conn, 400, "Error, cannot cast vote")
end
Expand Down
3 changes: 0 additions & 3 deletions lib/epochtalk_server_web/controllers/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,6 @@ defmodule EpochtalkServerWeb.Controllers.Post do
Validate.cast(attrs, "body", :string, required: true, max: post_max_length, min: 1),
parsed_body <- Parse.markdown(body) do
render(conn, :preview, %{parsed_body: parsed_body})
else
_ ->
ErrorHelpers.render_json_error(conn, 400, "Error, cannot generate preview")
end
end

Expand Down
9 changes: 6 additions & 3 deletions lib/epochtalk_server_web/controllers/preference.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ defmodule EpochtalkServerWeb.Controllers.Preference do
def preferences(conn, _attrs) do
with {:auth, %{} = user} <- {:auth, Guardian.Plug.current_resource(conn)},
do: render(conn, :preferences, preferences: Preference.by_user_id(user.id)),
else:
({:auth, nil} ->
ErrorHelpers.render_json_error(conn, 400, "Not logged in, cannot fetch preferences"))
else: ({:auth, nil} ->
ErrorHelpers.render_json_error(
conn,
400,
"Not logged in, cannot fetch preferences"
))
end
end
33 changes: 7 additions & 26 deletions lib/epochtalk_server_web/controllers/thread.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
user_priority <- ACL.get_user_priority(conn),
threads <- Thread.recent(user, user_priority) do
render(conn, :recent, %{threads: threads})
else
_ -> ErrorHelpers.render_json_error(conn, 400, "Error, cannot fetch recent threads")
end
end

Expand Down Expand Up @@ -174,10 +172,11 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
user <- Guardian.Plug.current_resource(conn),
user_priority <- ACL.get_user_priority(conn),
:ok <- ACL.allow!(conn, "threads.byBoard"),
{:can_read, {:ok, true}} <-
{:can_read, Board.get_read_access_by_id(board_id, user_priority)},
{:ok, write_access} <- Board.get_write_access_by_id(board_id, user_priority),
{:ok, can_read} <- Board.get_read_access_by_id(board_id, user_priority),
{:can_read, true} <- {:can_read, can_read},
{:ok, board_banned} <- BoardBan.banned_from_board?(user, board_id: board_id),
{:board_banned, false} <- {:board_banned, board_banned},
{:ok, write_access} <- Board.get_write_access_by_id(board_id, user_priority),
{:ok, watching_board} <- WatchBoard.user_is_watching(user, board_id),
board_mapping <- BoardMapping.all(),
board_moderators <- BoardModerator.all(),
Expand Down Expand Up @@ -208,20 +207,14 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
{:error, :board_does_not_exist} ->
ErrorHelpers.render_json_error(conn, 400, "Error, board does not exist")

{:can_read, {:ok, false}} ->
{:can_read, false} ->
ErrorHelpers.render_json_error(conn, 403, "Unauthorized, you do not have permission")

{:can_read, {:error, :board_does_not_exist}} ->
ErrorHelpers.render_json_error(conn, 400, "Read error, board does not exist")

{:board_banned, {:ok, true}} ->
{:board_banned, true} ->
ErrorHelpers.render_json_error(conn, 403, "Unauthorized, you are banned from this board")

{:has_threads, false} ->
ErrorHelpers.render_json_error(conn, 404, "Error, requested threads not found in board")

_ ->
ErrorHelpers.render_json_error(conn, 400, "Error, cannot get threads by board")
end
end

Expand Down Expand Up @@ -340,9 +333,6 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
"Account must be active to unwatch thread"
)

{:error, data} ->
ErrorHelpers.render_json_error(conn, 400, data)

_ ->
ErrorHelpers.render_json_error(conn, 400, "Error, cannot unwatch thread")
end
Expand Down Expand Up @@ -401,9 +391,6 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
"Account must be active to modify lock on thread"
)

{:error, data} ->
ErrorHelpers.render_json_error(conn, 400, data)

_ ->
ErrorHelpers.render_json_error(conn, 400, "Error, cannot lock thread")
end
Expand Down Expand Up @@ -462,9 +449,6 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
"Account must be active to modify sticky on thread"
)

{:error, data} ->
ErrorHelpers.render_json_error(conn, 400, data)

_ ->
ErrorHelpers.render_json_error(conn, 400, "Error, cannot sticky thread")
end
Expand Down Expand Up @@ -638,9 +622,6 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
400,
"Error, cannot convert slug, thread does not exist"
)

_ ->
ErrorHelpers.render_json_error(conn, 400, "Error, cannot convert thread slug to id")
end
end

Expand All @@ -663,7 +644,7 @@ defmodule EpochtalkServerWeb.Controllers.Thread do
|> send_resp(200, [])
|> halt()
else
{:error, :board_does_not_exist} ->
{:can_read, {:error, :board_does_not_exist}} ->
ErrorHelpers.render_json_error(
conn,
400,
Expand Down
24 changes: 4 additions & 20 deletions lib/epochtalk_server_web/controllers/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ defmodule EpochtalkServerWeb.Controllers.User do
{:ok, _email} <- Mailer.send_confirm_account(user) do
render(conn, :register_with_verify, user: user)
else
# error in user.create
{:error, data} ->
ErrorHelpers.render_json_error(conn, 400, data)

# error email failed to send
{:error, :not_delivered} ->
ErrorHelpers.render_json_error(
Expand All @@ -106,6 +102,10 @@ defmodule EpochtalkServerWeb.Controllers.User do
"Sending of account confirmation email failed, mailer is not properly configured."
)

# error in user.create
{:error, data} ->
ErrorHelpers.render_json_error(conn, 400, data)

# Catch all for any other errors
_ ->
ErrorHelpers.render_json_error(conn, 500, "There was an issue registering")
Expand Down Expand Up @@ -139,12 +139,6 @@ defmodule EpochtalkServerWeb.Controllers.User do
500,
"There was an error banning malicious user, upon confirming account"
)

{:error, data} ->
ErrorHelpers.render_json_error(conn, 400, data)

_ ->
ErrorHelpers.render_json_error(conn, 500, "There was an issue registering")
end
end

Expand Down Expand Up @@ -182,14 +176,8 @@ defmodule EpochtalkServerWeb.Controllers.User do
{:error, :user_not_found} ->
ErrorHelpers.render_json_error(conn, 400, "Account not found")

{:error, data} ->
ErrorHelpers.render_json_error(conn, 400, data)

{:view_deleted, false} ->
ErrorHelpers.render_json_error(conn, 400, "Account not found")

_ ->
ErrorHelpers.render_json_error(conn, 500, "There was an issue finding user")
end
end

Expand Down Expand Up @@ -217,7 +205,6 @@ defmodule EpochtalkServerWeb.Controllers.User do
else
{:auth, false} -> ErrorHelpers.render_json_error(conn, 400, "Not logged in")
{:error, error} -> ErrorHelpers.render_json_error(conn, 500, error)
_ -> ErrorHelpers.render_json_error(conn, 500, "There was an issue signing out")
end
end

Expand Down Expand Up @@ -262,9 +249,6 @@ defmodule EpochtalkServerWeb.Controllers.User do

{:error, :unban_error} ->
ErrorHelpers.render_json_error(conn, 500, "There was an issue unbanning user, upon login")

_ ->
ErrorHelpers.render_json_error(conn, 500, "There was an issue while attempting to login")
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/epochtalk_server_web/json/thread_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ defmodule EpochtalkServerWeb.Controllers.ThreadJSON do
# handle deleted user
thread =
if thread.user_deleted,
do: thread |> Map.put(:user_id, '') |> Map.put(:username, ''),
do: thread |> Map.put(:user_id, "") |> Map.put(:username, ""),
else: thread

# format user output
Expand Down
2 changes: 1 addition & 1 deletion lib/epochtalk_server_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ defmodule EpochtalkServerWeb.Router do
get "/admin/modlog", ModerationLog, :page
get "/boards/movelist", Board, :movelist
post "/images/s3/upload", ImageReference, :s3_request_upload
delete "/logout", User, :logout
end

scope "/api", EpochtalkServerWeb.Controllers do
Expand All @@ -86,7 +87,6 @@ defmodule EpochtalkServerWeb.Router do
post "/register", User, :register
post "/login", User, :login
post "/confirm", User, :confirm
delete "/logout", User, :logout
end

scope "/", EpochtalkServerWeb.Controllers do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule EpochtalkServer.MixProject do
{:argon2_elixir, "~> 3.1.0"},
{:configparser_ex, "~> 4.0"},
{:corsica, "~> 1.3.0"},
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},
{:credo, "~> 1.7.9", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.2", only: [:dev], runtime: false},
{:dotenv_parser, "~> 2.0"},
{:earmark, "~> 1.4"},
Expand Down
Loading

0 comments on commit 7f6c195

Please sign in to comment.