Skip to content

Commit

Permalink
Merge pull request #81 from epochtalk/add-authorizations
Browse files Browse the repository at this point in the history
Add authorizations
  • Loading branch information
unenglishable authored Nov 8, 2023
2 parents 4dfd4fb + 82007a6 commit 6efb0be
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 75 deletions.
4 changes: 2 additions & 2 deletions lib/epochtalk_server/models/mention.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ defmodule EpochtalkServer.Models.Mention do
def create_changeset(mention, attrs) do
now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)

attrs =
attrs
mention =
mention
|> Map.put(:created_at, now)

mention
Expand Down
2 changes: 1 addition & 1 deletion lib/epochtalk_server/models/notification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ defmodule EpochtalkServer.Models.Notification do
|> Repo.all()
|> case do
[] ->
%{message: 0, mentions: 0}
%{message: 0, mention: 0}

notifications ->
{messages, mentions} = Enum.split_with(notifications, &(&1.type == @types.message))
Expand Down
1 change: 1 addition & 0 deletions lib/epochtalk_server_web/controllers/board.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ defmodule EpochtalkServerWeb.Controllers.Board do
@doc """
Used to convert `Board` slug to id
"""
# TODO(akinsey): allow validate cast to match a regex, for completeness validate slug format
def slug_to_id(conn, attrs) do
with slug <- Validate.cast(attrs, "slug", :string, required: true),
{:ok, id} <- Board.slug_to_id(slug) do
Expand Down
2 changes: 2 additions & 0 deletions lib/epochtalk_server_web/controllers/moderation_log.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ defmodule EpochtalkServerWeb.Controllers.ModerationLog do
alias EpochtalkServer.Models.ModerationLog
alias EpochtalkServerWeb.ErrorHelpers
alias EpochtalkServerWeb.Helpers.Validate
alias EpochtalkServerWeb.Helpers.ACL

@doc """
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"),
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
Expand Down
1 change: 1 addition & 0 deletions lib/epochtalk_server_web/controllers/notification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ defmodule EpochtalkServerWeb.Controllers.Notification do

def dismiss(conn, %{"type" => type}) do
with {:auth, user} <- {:auth, Guardian.Plug.current_resource(conn)},
:ok <- ACL.allow!(conn, "notifications.dismiss"),
{_count, nil} <- Notification.dismiss_type_by_user_id(user.id, type) do
EpochtalkServerWeb.Endpoint.broadcast("user:#{user.id}", "refreshMentions", %{})
render(conn, :dismiss, success: true)
Expand Down
Loading

0 comments on commit 6efb0be

Please sign in to comment.