routing, control flow and whitespace fixes

This commit is contained in:
byte[] 2019-12-11 23:41:33 -05:00
parent 6293c6d45d
commit 54be9dfa5d
8 changed files with 56 additions and 23 deletions

View file

@ -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!")

View file

@ -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!")

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -1,11 +1,14 @@
= if !!@object.user and !anonymous?(@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
- else
- not is_nil(@object.user) and can?(@conn, :reveal_anon, @object) ->
strong<>
= if can?(@conn, :reveal_anon, @object) do
= link(anonymous_name(@object, true), to: Routes.profile_path(@conn, :show, @object.user))
- else
- true ->
strong<>
= anonymous_name(@object)

View file

@ -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