mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
Merge remote-tracking branch 'origin/staff-tools'
This commit is contained in:
commit
6293c6d45d
28 changed files with 374 additions and 77 deletions
|
@ -30,6 +30,8 @@ $vote_up_color: #67af2b !default;
|
|||
$vote_down_color: #cf0001 !default;
|
||||
$hide_color: #cf0001 !default;
|
||||
|
||||
$destroyed_content_color: #ffdcdc !default;
|
||||
|
||||
$assistant_color: #eeceed !default;
|
||||
|
||||
$tag_normal_color: #6f8f0e !default;
|
||||
|
|
|
@ -74,6 +74,7 @@ a.header__link:hover, .header__dropdown:hover > a {
|
|||
|
||||
background: $header_field_color;
|
||||
color: $text_light_color;
|
||||
-webkit-text-fill-color: $text_light_color;
|
||||
|
||||
text-overflow: ellipsis;
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ $success_light_color: #144714 !default;
|
|||
$danger_light_color: #66211f !default;
|
||||
$warning_light_color: #7d4825 !default;
|
||||
|
||||
$destroyed_content_color: #382c2f !default;
|
||||
|
||||
$meta_color: #191f2a !default;
|
||||
|
||||
$header_color: #284371 !default;
|
||||
|
|
|
@ -22,6 +22,8 @@ $success_light_color: #2e4e2e !default;
|
|||
$danger_light_color: #7b3b00 !default;
|
||||
$warning_light_color: #5b5b00 !default;
|
||||
|
||||
$destroyed_content_color: #412f2f !default;
|
||||
|
||||
$meta_color: #411d1d !default;
|
||||
|
||||
$header_color: #923131 !default;
|
||||
|
|
|
@ -97,3 +97,7 @@ span.communication__sender__stats,
|
|||
display: inline-block;
|
||||
margin-right: 2em;
|
||||
}
|
||||
|
||||
.communication--destroyed {
|
||||
background-color: $destroyed_content_color;
|
||||
}
|
||||
|
|
|
@ -134,6 +134,24 @@ defmodule Philomena.Comments do
|
|||
Repo.delete(comment)
|
||||
end
|
||||
|
||||
def hide_comment(%Comment{} = comment, attrs, user) do
|
||||
comment
|
||||
|> Comment.hide_changeset(attrs, user)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def unhide_comment(%Comment{} = comment) do
|
||||
comment
|
||||
|> Comment.unhide_changeset()
|
||||
|> 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.
|
||||
|
||||
|
|
|
@ -50,6 +50,26 @@ defmodule Philomena.Comments.Comment do
|
|||
|> validate_length(:edit_reason, max: 70, count: :bytes)
|
||||
end
|
||||
|
||||
def hide_changeset(comment, attrs, user) do
|
||||
comment
|
||||
|> cast(attrs, [:deletion_reason])
|
||||
|> put_change(:hidden_from_users, true)
|
||||
|> put_change(:deleted_by_id, user.id)
|
||||
|> validate_required([:deletion_reason])
|
||||
end
|
||||
|
||||
def unhide_changeset(comment) do
|
||||
change(comment)
|
||||
|> put_change(:hidden_from_users, false)
|
||||
|> 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
|
||||
|
|
|
@ -160,6 +160,24 @@ defmodule Philomena.Posts do
|
|||
Repo.delete(post)
|
||||
end
|
||||
|
||||
def hide_post(%Post{} = post, attrs, user) do
|
||||
post
|
||||
|> Post.hide_changeset(attrs, user)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def unhide_post(%Post{} = post) do
|
||||
post
|
||||
|> Post.unhide_changeset()
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def destroy_post(%Post{} = post) do
|
||||
post
|
||||
|> Post.destroy_changeset()
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking post changes.
|
||||
|
||||
|
|
|
@ -64,6 +64,26 @@ defmodule Philomena.Posts.Post do
|
|||
|> put_name_at_post_time(attribution[:user])
|
||||
end
|
||||
|
||||
def hide_changeset(post, attrs, user) do
|
||||
post
|
||||
|> cast(attrs, [:deletion_reason])
|
||||
|> put_change(:hidden_from_users, true)
|
||||
|> put_change(:deleted_by_id, user.id)
|
||||
|> validate_required([:deletion_reason])
|
||||
end
|
||||
|
||||
def unhide_changeset(post) do
|
||||
change(post)
|
||||
|> put_change(:hidden_from_users, false)
|
||||
|> put_change(:deletion_reason, "")
|
||||
end
|
||||
|
||||
def destroy_changeset(post) do
|
||||
change(post)
|
||||
|> 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
|
||||
|
|
|
@ -57,6 +57,9 @@ defimpl Canada.Can, for: [Atom, Philomena.Users.User] do
|
|||
def can?(%User{role: "moderator"}, :edit, %UserLink{}), do: true
|
||||
def can?(%User{role: "moderator"}, :index, UserLink), do: true
|
||||
|
||||
# Reveal anon users
|
||||
def can?(%User{role: "moderator"}, :reveal_anon, _object), do: true
|
||||
|
||||
#
|
||||
# Assistants can...
|
||||
#
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
defmodule PhilomenaWeb.Image.Comment.DeleteController do
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.Comments.Comment
|
||||
alias Philomena.Comments
|
||||
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :hide, delete: :hide
|
||||
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
|
|
@ -0,0 +1,44 @@
|
|||
defmodule PhilomenaWeb.Image.Comment.HideController do
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.Comments.Comment
|
||||
alias Philomena.Comments
|
||||
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :hide, delete: :hide
|
||||
plug :load_and_authorize_resource, model: Comment, id_name: "comment_id", persisted: true
|
||||
|
||||
def create(conn, %{"comment" => comment_params}) do
|
||||
comment = conn.assigns.comment
|
||||
user = conn.assigns.current_user
|
||||
|
||||
case Comments.hide_comment(comment, comment_params, user) do
|
||||
{:ok, comment} ->
|
||||
Comments.reindex_comment(comment)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Comment successfully hidden!")
|
||||
|> redirect(to: Routes.image_path(conn, :show, comment.image_id) <> "#comment_#{comment.id}")
|
||||
{:error, _changeset} ->
|
||||
conn
|
||||
|> put_flash(:error, "Unable to hide comment!")
|
||||
|> redirect(to: Routes.image_path(conn, :show, comment.image_id) <> "#comment_#{comment.id}")
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, _params) do
|
||||
comment = conn.assigns.comment
|
||||
|
||||
case Comments.unhide_comment(comment) do
|
||||
{:ok, comment} ->
|
||||
Comments.reindex_comment(comment)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Comment successfully unhidden!")
|
||||
|> redirect(to: Routes.image_path(conn, :show, comment.image_id) <> "#comment_#{comment.id}")
|
||||
{:error, _changeset} ->
|
||||
conn
|
||||
|> put_flash(:error, "Unable to unhide comment!")
|
||||
|> redirect(to: Routes.image_path(conn, :show, comment.image_id) <> "#comment_#{comment.id}")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -41,7 +41,7 @@ defmodule PhilomenaWeb.ImageController do
|
|||
comments =
|
||||
Comment
|
||||
|> where(image_id: ^image.id)
|
||||
|> preload([:image, user: [awards: :badge]])
|
||||
|> preload([:image, :deleted_by, user: [awards: :badge]])
|
||||
|> order_by(desc: :created_at)
|
||||
|> limit(25)
|
||||
|> Repo.paginate(conn.assigns.comment_scrivener)
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
defmodule PhilomenaWeb.Topic.Post.DeleteController do
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.Posts.Post
|
||||
alias Philomena.Posts
|
||||
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :hide, delete: :hide
|
||||
plug :load_and_authorize_resource, model: Post, id_name: "post_id", persisted: true, preload: [:topic]
|
||||
|
||||
def delete(conn, _params) do
|
||||
post = conn.assigns.post
|
||||
|
||||
case Posts.destroy_post(post) do
|
||||
{:ok, post} ->
|
||||
Posts.reindex_post(post)
|
||||
|
||||
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!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum_id, post.topic_id) <> "#post_#{post.id}")
|
||||
end
|
||||
end
|
||||
end
|
44
lib/philomena_web/controllers/topic/post/hide_controller.ex
Normal file
44
lib/philomena_web/controllers/topic/post/hide_controller.ex
Normal file
|
@ -0,0 +1,44 @@
|
|||
defmodule PhilomenaWeb.Topic.Post.HideController do
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.Posts.Post
|
||||
alias Philomena.Posts
|
||||
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :hide, delete: :hide
|
||||
plug :load_and_authorize_resource, model: Post, id_name: "post_id", persisted: true, preload: [:topic]
|
||||
|
||||
def create(conn, %{"post" => post_params}) do
|
||||
post = conn.assigns.post
|
||||
user = conn.assigns.current_user
|
||||
|
||||
case Posts.hide_post(post, post_params, user) do
|
||||
{:ok, post} ->
|
||||
Posts.reindex_post(post)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Post successfully hidden!")
|
||||
|> 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 hide post!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum_id, post.topic_id) <> "#post_#{post.id}")
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, _params) do
|
||||
post = conn.assigns.post
|
||||
|
||||
case Posts.unhide_post(post) do
|
||||
{:ok, post} ->
|
||||
Posts.reindex_post(post)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Post successfully unhidden!")
|
||||
|> 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 unhide post!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum_id, post.topic_id) <> "#post_#{post.id}")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -49,7 +49,7 @@ defmodule PhilomenaWeb.TopicController do
|
|||
|> where(topic_id: ^conn.assigns.topic.id)
|
||||
|> where([p], p.topic_position >= ^(25 * (page - 1)) and p.topic_position < ^(25 * page))
|
||||
|> order_by(asc: :created_at)
|
||||
|> preload([topic: :forum, user: [awards: :badge]])
|
||||
|> preload([:deleted_by, :topic, topic: :forum, user: [awards: :badge]])
|
||||
|> Repo.all()
|
||||
|
||||
rendered =
|
||||
|
|
|
@ -115,7 +115,10 @@ defmodule PhilomenaWeb.Router do
|
|||
resources "/hide", Image.HideController, only: [:create, :delete], singleton: true
|
||||
resources "/subscription", Image.SubscriptionController, only: [:create, :delete], singleton: true
|
||||
resources "/read", Image.ReadController, only: [:create], singleton: true
|
||||
resources "/comments", Image.CommentController, only: [:edit, :update]
|
||||
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
|
||||
end
|
||||
resources "/delete", Image.DeleteController, only: [:create, :delete], singleton: true
|
||||
end
|
||||
|
||||
|
@ -123,7 +126,10 @@ defmodule PhilomenaWeb.Router do
|
|||
resources "/topics", TopicController, only: [:new, :create] do
|
||||
resources "/subscription", Topic.SubscriptionController, only: [:create, :delete], singleton: true
|
||||
resources "/read", Topic.ReadController, only: [:create], singleton: true
|
||||
resources "/posts", Topic.PostController, only: [:edit, :update]
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
resources "/subscription", Forum.SubscriptionController, only: [:create, :delete], singleton: true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
article.block.communication id="comment_#{@comment.id}"
|
||||
.block__content.flex.flex--no-wrap
|
||||
.block__content.flex.flex--no-wrap class=communication_body_class(@comment)
|
||||
.flex__fixed.spacing-right
|
||||
= render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn
|
||||
.flex__grow.communication__body
|
||||
|
@ -10,7 +10,19 @@ article.block.communication id="comment_#{@comment.id}"
|
|||
= if @comment.hidden_from_users do
|
||||
strong.comment_deleted
|
||||
' Deletion reason:
|
||||
=> @comment.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
|
||||
strong.comment_deleted>
|
||||
| This comment's contents have been destroyed.
|
||||
- else
|
||||
br
|
||||
==<> @body
|
||||
- else
|
||||
==<> @body
|
||||
.block__content.communication__options
|
||||
|
@ -18,34 +30,25 @@ article.block.communication id="comment_#{@comment.id}"
|
|||
= render PhilomenaWeb.CommentView, "_comment_options.html", comment: @comment, conn: @conn
|
||||
= if can?(@conn, :hide, @comment) do
|
||||
.js-staff-action
|
||||
/ todo: make delete button work
|
||||
a.communication__interaction.togglable-delete-form-link href="#"
|
||||
i.fa.fa-times
|
||||
=<> "Delete"
|
||||
= if can?(@conn, :manage, @comment) do
|
||||
= 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
|
||||
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
|
||||
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)
|
||||
/- if can?(:hide, Comment)
|
||||
/ .js-staff-action
|
||||
/ - if !comment.hidden_from_users && !comment.destroyed_content
|
||||
/ =<> link_to '#', class: 'communication__interaction togglable-delete-form-link', 'data-click-toggle': "#inline-del-form-comment-#{comment.id}" do
|
||||
/ i.fa.fa-times
|
||||
/ =<> 'Delete'
|
||||
/ - elsif comment.hidden_from_users && !comment.destroyed_content
|
||||
/ =<> link_to image_comment_hide_path(comment.image, comment), data: { confirm: t('are_you_sure') }, method: :delete, class: 'communication__interaction' do
|
||||
/ i.fa.fa-check
|
||||
/ =<> 'Restore'
|
||||
/ - if can?(:manage, Comment)
|
||||
/ =<> link_to image_comment_path(comment.image, comment), method: :delete, data: { confirm: t('are_you_sure') }, class: 'communication__interaction' do
|
||||
/ i.fa.fa-times
|
||||
/ =<> 'Delete Contents'
|
||||
/ - if can?(:manage, Comment)
|
||||
/ .communication__info
|
||||
/ =<> link_to_ip(comment.ip)
|
||||
/ .communication__info
|
||||
/ =<> link_to_fingerprint(comment.fingerprint, comment.user_agent)
|
||||
/ = form_tag image_comment_hide_path(comment.image, comment), class: 'togglable-delete-form hidden flex', id: "inline-del-form-comment-#{comment.id}"
|
||||
/ = text_field_tag :deletion_reason, nil, class: 'input input--wide', placeholder: 'Deletion Reason', id: "inline-del-reason-comment-#{comment.id}", required: true
|
||||
/ = submit_tag 'Delete', class: 'button'
|
||||
= 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"
|
||||
|
|
|
@ -37,5 +37,5 @@ div
|
|||
span.owner-options
|
||||
strong
|
||||
a.communication__interaction href=Routes.image_comment_path(@conn, :edit, @comment.image, @comment)
|
||||
i.fa.fa-pencil>
|
||||
i.fas.fa-edit>
|
||||
' Edit
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
article.block.communication id="comment_#{@comment.id}"
|
||||
.block__content.flex.flex--no-wrap
|
||||
.block__content.flex.flex--no-wrap class=communication_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,44 @@ article.block.communication id="comment_#{@comment.id}"
|
|||
= if @comment.hidden_from_users do
|
||||
strong.comment_deleted
|
||||
' Deletion reason:
|
||||
=> @comment.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
|
||||
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
|
||||
= 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
|
||||
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
|
||||
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"
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
span.image_uploader
|
||||
' by
|
||||
=> render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @image, awards: true, conn: @conn
|
||||
= if can?(@conn, :manage, @image) do
|
||||
= if can?(@conn, :show, :ip_address) do
|
||||
=> link_to_ip(@conn, @image.ip)
|
||||
=> link_to_fingerprint(@conn, @image.fingerprint)
|
||||
a href="#"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
article.block.communication id="post_#{@post.id}"
|
||||
.block__content.flex.flex--no-wrap
|
||||
.block__content.flex.flex--no-wrap class=communication_body_class(@post)
|
||||
.flex__fixed.spacing-right
|
||||
= render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn
|
||||
.flex__grow.communication__body
|
||||
|
@ -11,40 +11,43 @@ article.block.communication id="post_#{@post.id}"
|
|||
strong.comment_deleted
|
||||
' Deletion reason:
|
||||
=> @post.deletion_reason
|
||||
= if can?(@conn, :hide, @post) do
|
||||
| (
|
||||
= @post.deleted_by.name
|
||||
| )
|
||||
= if can?(@conn, :hide, @post) do
|
||||
= if @post.destroyed_content do
|
||||
br
|
||||
strong.comment_deleted>
|
||||
| This post's contents have been destroyed.
|
||||
- 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
|
||||
/ todo: make post deletion work
|
||||
a.communication__interaction.togglable-delete-form-link href="#"
|
||||
i.fa.fa-times
|
||||
=<> "Delete"
|
||||
= if can?(@conn, :manage, @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
|
||||
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
|
||||
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)
|
||||
/- if can?(:hide, Post)
|
||||
/ .js-staff-action
|
||||
/ - if !post.hidden_from_users && !post.destroyed_content
|
||||
/ =<> link_to '#', class: 'communication__interaction togglable-delete-form-link', 'data-click-toggle': "#inline-del-form-post-#{post.id}" do
|
||||
/ i.fa.fa-times
|
||||
/ =<> 'Delete'
|
||||
/ - elsif post.hidden_from_users && !post.destroyed_content
|
||||
/ =<> link_to forum_topic_post_hide_path(post.topic.forum, post.topic, post), data: { confirm: t('are_you_sure') }, method: :delete, class: 'communication__interaction' do
|
||||
/ i.fa.fa-check
|
||||
/ =<> 'Restore'
|
||||
/ - if can?(:manage, Post)
|
||||
/ =<> link_to forum_topic_post_path(post.topic.forum, post.topic, post, deletion_reason: post.deletion_reason), method: :delete, data: { confirm: t('are_you_sure') }, class: 'communication__interaction' do
|
||||
/ i.fa.fa-times
|
||||
/ =<> 'Delete Contents'
|
||||
/ - if can?(:manage, Post)
|
||||
/ .communication__info
|
||||
/ =<> link_to_ip(post.ip)
|
||||
/ .communication__info
|
||||
/ =<> link_to_fingerprint(post.fingerprint, post.user_agent)
|
||||
/ = form_tag forum_topic_post_hide_path(post.topic.forum, post.topic, post), class: 'togglable-delete-form hidden flex', id: "inline-del-form-post-#{post.id}"
|
||||
/ = text_field_tag :deletion_reason, nil, class: 'input input--wide', placeholder: 'Deletion Reason', id: "inline-del-reason-post-#{post.id}", required: true
|
||||
/ = submit_tag 'Delete', class: 'button'
|
||||
= 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"
|
||||
|
|
|
@ -37,5 +37,5 @@ div
|
|||
span.owner-options
|
||||
strong
|
||||
a.communication__interaction href=Routes.forum_topic_post_path(@conn, :edit, @post.topic.forum, @post.topic, @post)
|
||||
i.fa.fa-pencil>
|
||||
i.fa.fa-edit>
|
||||
' Edit
|
||||
|
|
|
@ -35,7 +35,7 @@ h1 = @topic.title
|
|||
/ The actual posts
|
||||
.posts-area
|
||||
.post-list
|
||||
= for {post, body} <- @posts, !post.destroyed_content do
|
||||
= for {post, body} <- @posts, (!post.destroyed_content or can?(@conn, :hide, post)) do
|
||||
= render PhilomenaWeb.PostView, "_post.html", conn: @conn, post: post, body: body
|
||||
|
||||
= if @conn.assigns.advert do
|
||||
|
|
|
@ -5,4 +5,7 @@
|
|||
= render PhilomenaWeb.ProfileView, "_awards.html", awards: @object.user.awards
|
||||
- else
|
||||
strong<>
|
||||
= if can?(@conn, :reveal_anon, @object) do
|
||||
= link(anonymous_name(@object, true), to: Routes.profile_path(@conn, :show, @object.user))
|
||||
- else
|
||||
= anonymous_name(@object)
|
|
@ -127,15 +127,30 @@ defmodule PhilomenaWeb.AppView do
|
|||
end
|
||||
|
||||
defp text_or_na(nil), do: "N/A"
|
||||
defp text_or_na(text), do: text
|
||||
defp text_or_na(text), do: to_string(text)
|
||||
|
||||
def link_to_ip(conn, ip) do
|
||||
link(text_or_na(ip), to: Routes.ip_profile_path(conn, :show, to_string(ip)))
|
||||
link(to: Routes.ip_profile_path(conn, :show, to_string(ip))) do
|
||||
[
|
||||
content_tag(:i, "", class: "fas fa-network-wired"),
|
||||
" ",
|
||||
text_or_na(ip)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
def link_to_fingerprint(conn, fp) do
|
||||
link(String.slice(text_or_na(fp), 0..6), to: Routes.fingerprint_profile_path(conn, :show, fp))
|
||||
link(to: Routes.fingerprint_profile_path(conn, :show, fp)) do
|
||||
[
|
||||
content_tag(:i, "", class: "fas fa-desktop"),
|
||||
" ",
|
||||
String.slice(text_or_na(fp), 0..6)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
def communication_body_class(%{destroyed_content: true}), do: "communication--destroyed"
|
||||
def communication_body_class(_communication), do: nil
|
||||
|
||||
def blank?(nil), do: true
|
||||
def blank?(""), do: true
|
||||
|
|
|
@ -7,7 +7,7 @@ defmodule PhilomenaWeb.UserAttributionView do
|
|||
Attribution.anonymous?(object)
|
||||
end
|
||||
|
||||
def anonymous_name(object) do
|
||||
def anonymous_name(object, reveal_anon? \\ false) do
|
||||
salt = anonymous_name_salt()
|
||||
id = Attribution.object_identifier(object)
|
||||
user_id = Attribution.best_user_identifier(object)
|
||||
|
@ -17,7 +17,10 @@ defmodule PhilomenaWeb.UserAttributionView do
|
|||
|> Integer.to_string(16)
|
||||
|> String.pad_leading(4, "0")
|
||||
|
||||
"Background Pony ##{hash}"
|
||||
case reveal_anon? do
|
||||
true -> "#{object.user.name} (##{hash}, hidden)"
|
||||
false -> "Background Pony ##{hash}"
|
||||
end
|
||||
end
|
||||
|
||||
def anonymous_avatar(_object, class \\ "avatar--100px") do
|
||||
|
|
Loading…
Reference in a new issue