diff --git a/assets/css/common/global.scss b/assets/css/common/global.scss index 3985ee9a..39b71755 100644 --- a/assets/css/common/global.scss +++ b/assets/css/common/global.scss @@ -30,6 +30,8 @@ $vote_up_color: #67af2b !default; $vote_down_color: #cf0001 !default; $hide_color: #cf0001 !default; +$destroyed_comment_color: #f3baba !default; + $assistant_color: #eeceed !default; $tag_normal_color: #6f8f0e !default; diff --git a/assets/css/themes/dark.scss b/assets/css/themes/dark.scss index 215b9eda..0bd705aa 100644 --- a/assets/css/themes/dark.scss +++ b/assets/css/themes/dark.scss @@ -17,6 +17,8 @@ $success_light_color: #144714 !default; $danger_light_color: #66211f !default; $warning_light_color: #7d4825 !default; +$destroyed_comment_color: #382c2f !default; + $meta_color: #191f2a !default; $header_color: #284371 !default; diff --git a/assets/css/views/comments.scss b/assets/css/views/comments.scss index e9f854a9..f2739171 100644 --- a/assets/css/views/comments.scss +++ b/assets/css/views/comments.scss @@ -7,6 +7,10 @@ color: $vote_down_color; } +.comment--destroyed { + background-color: $destroyed_comment_color; +} + .comment_under_review { color: blue; } diff --git a/lib/philomena/comments.ex b/lib/philomena/comments.ex index 861eb531..dc8171d9 100644 --- a/lib/philomena/comments.ex +++ b/lib/philomena/comments.ex @@ -146,6 +146,12 @@ defmodule Philomena.Comments do |> Repo.update() end + def destroy_comment(%Comment{} = comment) do + comment + |> Comment.destroy_changeset() + |> Repo.update() + end + @doc """ Returns an `%Ecto.Changeset{}` for tracking comment changes. diff --git a/lib/philomena/comments/comment.ex b/lib/philomena/comments/comment.ex index 1ce42353..01cf2e72 100644 --- a/lib/philomena/comments/comment.ex +++ b/lib/philomena/comments/comment.ex @@ -64,6 +64,12 @@ defmodule Philomena.Comments.Comment do |> put_change(:deletion_reason, "") end + def destroy_changeset(comment) do + change(comment) + |> put_change(:destroyed_content, true) + |> put_change(:body, "") + end + defp put_name_at_post_time(changeset, nil), do: changeset defp put_name_at_post_time(changeset, user), do: change(changeset, name_at_post_time: user.name) end diff --git a/lib/philomena_web/controllers/image/comment/delete_controller.ex b/lib/philomena_web/controllers/image/comment/delete_controller.ex index ff91f070..76c428e0 100644 --- a/lib/philomena_web/controllers/image/comment/delete_controller.ex +++ b/lib/philomena_web/controllers/image/comment/delete_controller.ex @@ -8,5 +8,19 @@ defmodule PhilomenaWeb.Image.Comment.DeleteController do plug :load_and_authorize_resource, model: Comment, id_name: "comment_id", persisted: true def delete(conn, _params) do + comment = conn.assigns.comment + + case Comments.destroy_comment(comment) do + {:ok, comment} -> + Comments.reindex_comment(comment) + + 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!") + |> redirect(to: Routes.image_path(conn, :show, comment.image_id) <> "#comment_#{comment.id}") + end end end diff --git a/lib/philomena_web/templates/comment/_comment.html.slime b/lib/philomena_web/templates/comment/_comment.html.slime index cef18867..ad3a1565 100644 --- a/lib/philomena_web/templates/comment/_comment.html.slime +++ b/lib/philomena_web/templates/comment/_comment.html.slime @@ -1,5 +1,5 @@ article.block.communication id="comment_#{@comment.id}" - .block__content.flex.flex--no-wrap + .block__content.flex.flex--no-wrap class=comment_body_class(@comment) .flex__fixed.spacing-right = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn .flex__grow.communication__body @@ -16,8 +16,13 @@ article.block.communication id="comment_#{@comment.id}" = @comment.deleted_by.name | ) = if can?(@conn, :delete, @comment) do - br - ==<> @body + = if @comment.destroyed_content do + br + strong.comment_deleted> + | This comment's contents have been destroyed. + - else + br + ==<> @body - else ==<> @body .block__content.communication__options 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 61092f6a..a91f5881 100644 --- a/lib/philomena_web/templates/comment/_comment_with_image.html.slime +++ b/lib/philomena_web/templates/comment/_comment_with_image.html.slime @@ -1,5 +1,5 @@ article.block.communication id="comment_#{@comment.id}" - .block__content.flex.flex--no-wrap + .block__content.flex.flex--no-wrap class=comment_body_class(@comment) .flex__fixed.spacing-right .post-image-container = render PhilomenaWeb.ImageView, "_image_container.html", image: @comment.image, size: :thumb_tiny, conn: @conn @@ -14,10 +14,20 @@ article.block.communication id="comment_#{@comment.id}" = if @comment.hidden_from_users do strong.comment_deleted ' Deletion reason: - => @comment.deletion_reason - - else - ==<> @body + =<> @comment.deletion_reason + = if can?(@conn, :delete, @comment) do + | ( + = @comment.deleted_by.name + | ) + = if can?(@conn, :delete, @comment) do + = if @comment.destroyed_content do + br + strong.comment_deleted> + | This comment's contents have been destroyed. + - else + br + ==<> @body .block__content.communication__options .flex.flex--wrap.flex--spaced-out - = render PhilomenaWeb.CommentView, "_comment_options.html", comment: @comment, conn: @conn \ No newline at end of file + = render PhilomenaWeb.CommentView, "_comment_options.html", comment: @comment, conn: @conn diff --git a/lib/philomena_web/views/comment_view.ex b/lib/philomena_web/views/comment_view.ex index fbe88c11..da9d88aa 100644 --- a/lib/philomena_web/views/comment_view.ex +++ b/lib/philomena_web/views/comment_view.ex @@ -1,3 +1,6 @@ defmodule PhilomenaWeb.CommentView do use PhilomenaWeb, :view + + defp comment_body_class(%{destroyed_content: true}), do: "comment--destroyed" + defp comment_body_class(_comment), do: nil end