From 54be9dfa5d2e75b7b288a0ff61614d0bbba7c344 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Wed, 11 Dec 2019 23:41:33 -0500 Subject: [PATCH] routing, control flow and whitespace fixes --- .../image/comment/delete_controller.ex | 5 ++-- .../topic/post/delete_controller.ex | 5 ++-- lib/philomena_web/router.ex | 4 ++-- .../templates/comment/_comment.html.slime | 13 +++++++++-- .../comment/_comment_with_image.html.slime | 15 ++++++++++-- .../templates/post/_post.html.slime | 12 ++++++++-- .../user_attribution/_anon_user.html.slime | 23 +++++++++++-------- .../views/user_attribution_view.ex | 2 +- 8 files changed, 56 insertions(+), 23 deletions(-) diff --git a/lib/philomena_web/controllers/image/comment/delete_controller.ex b/lib/philomena_web/controllers/image/comment/delete_controller.ex index 76c428e0..c79eb9eb 100644 --- a/lib/philomena_web/controllers/image/comment/delete_controller.ex +++ b/lib/philomena_web/controllers/image/comment/delete_controller.ex @@ -4,10 +4,10 @@ defmodule PhilomenaWeb.Image.Comment.DeleteController do alias Philomena.Comments.Comment alias Philomena.Comments - plug PhilomenaWeb.CanaryMapPlug, create: :hide, delete: :hide + plug PhilomenaWeb.CanaryMapPlug, create: :hide plug :load_and_authorize_resource, model: Comment, id_name: "comment_id", persisted: true - def delete(conn, _params) do + def create(conn, _params) do comment = conn.assigns.comment case Comments.destroy_comment(comment) do @@ -17,6 +17,7 @@ defmodule PhilomenaWeb.Image.Comment.DeleteController do conn |> put_flash(:info, "Comment successfully destroyed!") |> redirect(to: Routes.image_path(conn, :show, comment.image_id) <> "#comment_#{comment.id}") + {:error, _changeset} -> conn |> put_flash(:error, "Unable to destroy comment!") diff --git a/lib/philomena_web/controllers/topic/post/delete_controller.ex b/lib/philomena_web/controllers/topic/post/delete_controller.ex index 64334018..90e9942e 100644 --- a/lib/philomena_web/controllers/topic/post/delete_controller.ex +++ b/lib/philomena_web/controllers/topic/post/delete_controller.ex @@ -4,10 +4,10 @@ defmodule PhilomenaWeb.Topic.Post.DeleteController do alias Philomena.Posts.Post alias Philomena.Posts - plug PhilomenaWeb.CanaryMapPlug, create: :hide, delete: :hide + plug PhilomenaWeb.CanaryMapPlug, create: :hide plug :load_and_authorize_resource, model: Post, id_name: "post_id", persisted: true, preload: [:topic] - def delete(conn, _params) do + def create(conn, _params) do post = conn.assigns.post case Posts.destroy_post(post) do @@ -17,6 +17,7 @@ defmodule PhilomenaWeb.Topic.Post.DeleteController do conn |> put_flash(:info, "Post successfully destroyed!") |> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum_id, post.topic_id) <> "#post_#{post.id}") + {:error, _changeset} -> conn |> put_flash(:error, "Unable to destroy post!") diff --git a/lib/philomena_web/router.ex b/lib/philomena_web/router.ex index 7eef54a1..cfe42c31 100644 --- a/lib/philomena_web/router.ex +++ b/lib/philomena_web/router.ex @@ -117,7 +117,7 @@ defmodule PhilomenaWeb.Router do resources "/read", Image.ReadController, only: [:create], singleton: true resources "/comments", Image.CommentController, only: [:edit, :update] do resources "/hide", Image.Comment.HideController, only: [:create, :delete], singleton: true - resources "/delete", Image.Comment.DeleteController, only: [:delete], singleton: true + resources "/delete", Image.Comment.DeleteController, only: [:create], singleton: true end resources "/delete", Image.DeleteController, only: [:create, :delete], singleton: true end @@ -128,7 +128,7 @@ defmodule PhilomenaWeb.Router do resources "/read", Topic.ReadController, only: [:create], singleton: true resources "/posts", Topic.PostController, only: [:edit, :update] do resources "/hide", Topic.Post.HideController, only: [:create, :delete], singleton: true - resources "/delete", Topic.Post.DeleteController, only: [:delete], singleton: true + resources "/delete", Topic.Post.DeleteController, only: [:create], singleton: true end end diff --git a/lib/philomena_web/templates/comment/_comment.html.slime b/lib/philomena_web/templates/comment/_comment.html.slime index 1b61f1b1..dbfd04e0 100644 --- a/lib/philomena_web/templates/comment/_comment.html.slime +++ b/lib/philomena_web/templates/comment/_comment.html.slime @@ -15,6 +15,7 @@ article.block.communication id="comment_#{@comment.id}" | ( = @comment.deleted_by.name | ) + = if can?(@conn, :hide, @comment) do = if @comment.destroyed_content do br @@ -23,32 +24,40 @@ article.block.communication id="comment_#{@comment.id}" - else br ==<> @body + - else ==<> @body + .block__content.communication__options .flex.flex--wrap.flex--spaced-out = render PhilomenaWeb.CommentView, "_comment_options.html", comment: @comment, conn: @conn + = if can?(@conn, :hide, @comment) do .js-staff-action = cond do - @comment.hidden_from_users and not @comment.destroyed_content -> - = link(to: Routes.image_comment_hide_path(@conn, :delete, @comment.image_id, @comment), data: [confirm: "Are you sure?"], method: :delete, class: "communication__interaction") do + = link(to: Routes.image_comment_hide_path(@conn, :delete, @comment.image_id, @comment), data: [confirm: "Are you sure?"], method: "delete", class: "communication__interaction") do i.fas.fa-check> ' Restore + = if can?(@conn, :delete, @comment) do - = link(to: Routes.image_comment_delete_path(@conn, :delete, @comment.image_id, @comment), data: [confirm: "Are you sure?"], method: :delete, class: "communication__interaction") do + = link(to: Routes.image_comment_delete_path(@conn, :create, @comment.image_id, @comment), data: [confirm: "Are you sure?"], method: "post", class: "communication__interaction") do i.fas.fa-times> ' Delete Contents + - not @comment.hidden_from_users and not @comment.destroyed_content -> a.communication__interaction.togglable-delete-form-link href="#" data-click-toggle="#inline-del-form-comment-#{@comment.id}" i.fas.fa-times> ' Delete + - true -> + = if can?(@conn, :show, :ip_address) do .communication__info =<> link_to_ip(@conn, @comment.ip) .communication__info =<> link_to_fingerprint(@conn, @comment.fingerprint) + = form_for :comment, Routes.image_comment_hide_path(@conn, :create, @comment.image_id, @comment), [class: "togglable-delete-form hidden flex", id: "inline-del-form-comment-#{@comment.id}"], fn f -> = text_input f, :deletion_reason, class: "input input--wide", placeholder: "Deletion Reason", id: "inline-del-reason-comment-#{@comment.id}", required: true = submit "Delete", class: "button" diff --git a/lib/philomena_web/templates/comment/_comment_with_image.html.slime b/lib/philomena_web/templates/comment/_comment_with_image.html.slime index 315ac8fd..631e209b 100644 --- a/lib/philomena_web/templates/comment/_comment_with_image.html.slime +++ b/lib/philomena_web/templates/comment/_comment_with_image.html.slime @@ -15,10 +15,12 @@ article.block.communication id="comment_#{@comment.id}" strong.comment_deleted ' Deletion reason: =<> @comment.deletion_reason + = if can?(@conn, :hide, @comment) do | ( = @comment.deleted_by.name | ) + = if can?(@conn, :hide, @comment) do = if @comment.destroyed_content do br @@ -28,30 +30,39 @@ article.block.communication id="comment_#{@comment.id}" br ==<> @body + - else + ==<> @body + .block__content.communication__options .flex.flex--wrap.flex--spaced-out = render PhilomenaWeb.CommentView, "_comment_options.html", comment: @comment, conn: @conn + = if can?(@conn, :hide, @comment) do .js-staff-action = cond do - @comment.hidden_from_users and not @comment.destroyed_content -> - = link(to: Routes.image_comment_hide_path(@conn, :delete, @comment.image_id, @comment), data: [confirm: "Are you sure?"], method: :delete, class: "communication__interaction") do + = link(to: Routes.image_comment_hide_path(@conn, :delete, @comment.image_id, @comment), data: [confirm: "Are you sure?"], method: "delete", class: "communication__interaction") do i.fas.fa-check> ' Restore + = if can?(@conn, :delete, @comment) do - = link(to: Routes.image_comment_delete_path(@conn, :delete, @comment.image_id, @comment), data: [confirm: "Are you sure?"], method: :delete, class: "communication__interaction") do + = link(to: Routes.image_comment_delete_path(@conn, :create, @comment.image_id, @comment), data: [confirm: "Are you sure?"], method: "post", class: "communication__interaction") do i.fas.fa-times> ' Delete Contents + - not @comment.hidden_from_users and not @comment.destroyed_content -> a.communication__interaction.togglable-delete-form-link href="#" data-click-toggle="#inline-del-form-comment-#{@comment.id}" i.fas.fa-times> ' Delete + - true -> + = if can?(@conn, :show, :ip_address) do .communication__info =<> link_to_ip(@conn, @comment.ip) .communication__info =<> link_to_fingerprint(@conn, @comment.fingerprint) + = form_for :comment, Routes.image_comment_hide_path(@conn, :create, @comment.image_id, @comment), [class: "togglable-delete-form hidden flex", id: "inline-del-form-comment-#{@comment.id}"], fn f -> = text_input f, :deletion_reason, class: "input input--wide", placeholder: "Deletion Reason", id: "inline-del-reason-comment-#{@comment.id}", required: true = submit "Delete", class: "button" diff --git a/lib/philomena_web/templates/post/_post.html.slime b/lib/philomena_web/templates/post/_post.html.slime index f2add634..ba2aa79a 100644 --- a/lib/philomena_web/templates/post/_post.html.slime +++ b/lib/philomena_web/templates/post/_post.html.slime @@ -15,6 +15,7 @@ article.block.communication id="post_#{@post.id}" | ( = @post.deleted_by.name | ) + = if can?(@conn, :hide, @post) do = if @post.destroyed_content do br @@ -23,31 +24,38 @@ article.block.communication id="post_#{@post.id}" - else br ==<> @body + - else ==<> @body + .block__content.communication__options .flex.flex--wrap.flex--spaced-out = render PhilomenaWeb.PostView, "_post_options.html", conn: @conn, post: @post + = if can?(@conn, :hide, @post) do = cond do - @post.hidden_from_users and not @post.destroyed_content -> - = link(to: Routes.forum_topic_post_hide_path(@conn, :delete, @post.topic.forum, @post.topic, @post), data: [confirm: "Are you sure?"], method: :delete, class: "communication__interaction") do + = link(to: Routes.forum_topic_post_hide_path(@conn, :delete, @post.topic.forum, @post.topic, @post), data: [confirm: "Are you sure?"], method: "delete", class: "communication__interaction") do i.fas.fa-check> ' Restore = if can?(@conn, :delete, @post) do - = link(to: Routes.forum_topic_post_delete_path(@conn, :delete, @post.topic.forum, @post.topic, @post), data: [confirm: "Are you sure?"], method: :delete, class: "communication__interaction") do + = link(to: Routes.forum_topic_post_delete_path(@conn, :create, @post.topic.forum, @post.topic, @post), data: [confirm: "Are you sure?"], method: "post", class: "communication__interaction") do i.fas.fa-times> ' Delete Contents + - not @post.hidden_from_users and not @post.destroyed_content -> a.communication__interaction.togglable-delete-form-link href="#" data-click-toggle="#inline-del-form-post-#{@post.id}" i.fa.fa-times> ' Delete + - true -> + = if can?(@conn, :show, :ip_address) do .communication__info =<> link_to_ip(@conn, @post.ip) .communication__info =<> link_to_fingerprint(@conn, @post.fingerprint) + = form_for :post, Routes.forum_topic_post_hide_path(@conn, :create, @post.topic.forum, @post.topic, @post), [class: "togglable-delete-form hidden flex", id: "inline-del-form-post-#{@post.id}"], fn f -> = text_input f, :deletion_reason, class: "input input--wide", placeholder: "Deletion Reason", id: "inline-del-reason-post-#{@post.id}", required: true = submit "Delete", class: "button" diff --git a/lib/philomena_web/templates/user_attribution/_anon_user.html.slime b/lib/philomena_web/templates/user_attribution/_anon_user.html.slime index d02c1a6b..4c7c6ba3 100644 --- a/lib/philomena_web/templates/user_attribution/_anon_user.html.slime +++ b/lib/philomena_web/templates/user_attribution/_anon_user.html.slime @@ -1,11 +1,14 @@ -= if !!@object.user and !anonymous?(@object) do - strong<> - = link(@object.user.name, to: Routes.profile_path(@conn, :show, @object.user)) - = if assigns[:awards] do - = render PhilomenaWeb.ProfileView, "_awards.html", awards: @object.user.awards -- else - strong<> - = if can?(@conn, :reveal_anon, @object) do += cond do + - not is_nil(@object.user) and not anonymous?(@object) -> + strong<> + = link(@object.user.name, to: Routes.profile_path(@conn, :show, @object.user)) + = if assigns[:awards] do + = render PhilomenaWeb.ProfileView, "_awards.html", awards: @object.user.awards + + - not is_nil(@object.user) and can?(@conn, :reveal_anon, @object) -> + strong<> = link(anonymous_name(@object, true), to: Routes.profile_path(@conn, :show, @object.user)) - - else - = anonymous_name(@object) + + - true -> + strong<> + = anonymous_name(@object) \ No newline at end of file diff --git a/lib/philomena_web/views/user_attribution_view.ex b/lib/philomena_web/views/user_attribution_view.ex index b05ebef1..9b1584db 100644 --- a/lib/philomena_web/views/user_attribution_view.ex +++ b/lib/philomena_web/views/user_attribution_view.ex @@ -17,7 +17,7 @@ defmodule PhilomenaWeb.UserAttributionView do |> Integer.to_string(16) |> String.pad_leading(4, "0") - case reveal_anon? do + case not is_nil(object.user) and reveal_anon? do true -> "#{object.user.name} (##{hash}, hidden)" false -> "Background Pony ##{hash}" end