Skip to content

Commit

Permalink
refactor(json/post): wip implement function which cleans posts array …
Browse files Browse the repository at this point in the history
…before returning
  • Loading branch information
akinsey committed Jul 27, 2023
1 parent 7e86603 commit f8d242a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/epochtalk_server_web/json/post_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ defmodule EpochtalkServerWeb.Controllers.PostJSON do

## === Private Helper Functions ===

defp clean_posts(posts, thread, user, user_priority, view_deleted_posts, override_allow_view \\ false) do
defp clean_posts(posts, thread, user, authed_user_priority, view_deleted_posts, override_allow_view \\ false) do
authed_user_id = if user, do: user.id, else: nil
has_self_mod_bypass = ACL.has_permission(user, "posts.byThread.bypass.viewDeletedPosts.selfMod")
has_priority_bypass = ACL.has_permission(user, "posts.byThread.bypass.viewDeletedPosts.priority")

Check warning on line 76 in lib/epochtalk_server_web/json/post_json.ex

View workflow job for this annotation

GitHub Actions / Run tests (1.14.4, 25.3.1)

variable "has_priority_bypass" is unused (if the variable is not meant to be used, prefix it with an underscore)
Expand All @@ -79,7 +79,21 @@ defmodule EpochtalkServerWeb.Controllers.PostJSON do
view_deleted_posts_is_board_list = is_list(view_deleted_posts)

Enum.map(posts, fn post ->

# check if metadata map exists
metadata_map_exists = !!post.metadata and Map.keys(post.metadata) != []

# get information about how current post was hidden
post_hidden_by_priority = if metadata_map_exists,
do: post.metadata.hidden_by_priority,
else: post.user.priority
post_hidden_by_id = if metadata_map_exists,
do: post.metadata.hidden_by_id,
else: post.user.id

# check if user has priority to view hidden post,
# or if the user was the one who hid the post
authed_user_has_priority = authed_user_priority <= post_hidden_by_priority

Check warning on line 95 in lib/epochtalk_server_web/json/post_json.ex

View workflow job for this annotation

GitHub Actions / Run tests (1.14.4, 25.3.1)

variable "authed_user_has_priority" is unused (if the variable is not meant to be used, prefix it with an underscore)
authed_user_hid_post = post_hidden_by_id == authed_user_id

Check warning on line 96 in lib/epochtalk_server_web/json/post_json.ex

View workflow job for this annotation

GitHub Actions / Run tests (1.14.4, 25.3.1)

variable "authed_user_hid_post" is unused (if the variable is not meant to be used, prefix it with an underscore)
end)

# return posts for now
Expand Down

0 comments on commit f8d242a

Please sign in to comment.