mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-31 19:36:44 +01:00
Merge remote-tracking branch 'origin/staff-tools'
This commit is contained in:
commit
ff854fce73
12 changed files with 432 additions and 96 deletions
|
@ -190,6 +190,62 @@ defmodule Philomena.Topics do
|
|||
|> Repo.delete()
|
||||
end
|
||||
|
||||
def stick_topic(topic) do
|
||||
Topic.stick_changeset(topic)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def unstick_topic(topic) do
|
||||
Topic.unstick_changeset(topic)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def lock_topic(%Topic{} = topic, attrs, user) do
|
||||
Topic.lock_changeset(topic, attrs, user)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def unlock_topic(%Topic{} = topic) do
|
||||
Topic.unlock_changeset(topic)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def move_topic(topic, new_forum_id) do
|
||||
old_forum_id = topic.forum_id
|
||||
topic_changes = Topic.move_changeset(topic, new_forum_id)
|
||||
|
||||
Multi.new
|
||||
|> Multi.update(:topic, topic_changes)
|
||||
|> Multi.run(:update_old_forum, fn repo, %{topic: topic} ->
|
||||
{count, nil} =
|
||||
Forum
|
||||
|> where(id: ^old_forum_id)
|
||||
|> repo.update_all(inc: [post_count: -topic.post_count, topic_count: -1])
|
||||
|
||||
{:ok, count}
|
||||
end)
|
||||
|> Multi.run(:update_new_forum, fn repo, %{topic: topic} ->
|
||||
{count, nil} =
|
||||
Forum
|
||||
|> where(id: ^topic.forum_id)
|
||||
|> repo.update_all(inc: [post_count: topic.post_count, topic_count: 1])
|
||||
|
||||
{:ok, count}
|
||||
end)
|
||||
|> Repo.isolated_transaction(:serializable)
|
||||
end
|
||||
|
||||
def hide_topic(topic, deletion_reason, user) do
|
||||
Topic.hide_changeset(topic, deletion_reason, user)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def unhide_topic(topic) do
|
||||
Topic.unhide_changeset(topic)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def clear_notification(nil, _user), do: nil
|
||||
def clear_notification(_topic, nil), do: nil
|
||||
def clear_notification(topic, user) do
|
||||
Notifications.delete_unread_notification("Topic", topic.id, user)
|
||||
|
|
|
@ -25,7 +25,7 @@ defmodule Philomena.Topics.Topic do
|
|||
field :view_count, :integer, default: 0
|
||||
field :sticky, :boolean, default: false
|
||||
field :last_replied_to_at, :naive_datetime
|
||||
field :locked_at, :naive_datetime
|
||||
field :locked_at, :utc_datetime
|
||||
field :deletion_reason, :string
|
||||
field :lock_reason, :string
|
||||
field :slug, :string
|
||||
|
@ -64,6 +64,53 @@ defmodule Philomena.Topics.Topic do
|
|||
|> unique_constraint(:slug, name: :index_topics_on_forum_id_and_slug)
|
||||
end
|
||||
|
||||
def stick_changeset(topic) do
|
||||
change(topic)
|
||||
|> put_change(:sticky, true)
|
||||
end
|
||||
|
||||
def unstick_changeset(topic) do
|
||||
change(topic)
|
||||
|> put_change(:sticky, false)
|
||||
end
|
||||
|
||||
def lock_changeset(topic, attrs, user) do
|
||||
now = DateTime.utc_now() |> DateTime.truncate(:second)
|
||||
|
||||
change(topic)
|
||||
|> cast(attrs, [:lock_reason])
|
||||
|> put_change(:locked_at, now)
|
||||
|> put_change(:locked_by_id, user.id)
|
||||
|> validate_required([:lock_reason])
|
||||
end
|
||||
|
||||
def unlock_changeset(topic) do
|
||||
change(topic)
|
||||
|> put_change(:locked_at, nil)
|
||||
|> put_change(:locked_by_id, nil)
|
||||
|> put_change(:lock_reason, "")
|
||||
end
|
||||
|
||||
def move_changeset(topic, new_forum_id) do
|
||||
change(topic)
|
||||
|> put_change(:forum_id, new_forum_id)
|
||||
end
|
||||
|
||||
def hide_changeset(topic, deletion_reason, user) do
|
||||
change(topic)
|
||||
|> put_change(:hidden_from_users, true)
|
||||
|> put_change(:deleted_by_id, user.id)
|
||||
|> put_change(:deletion_reason, deletion_reason)
|
||||
|> validate_required([:deletion_reason])
|
||||
end
|
||||
|
||||
def unhide_changeset(topic) do
|
||||
change(topic)
|
||||
|> put_change(:hidden_from_users, false)
|
||||
|> put_change(:deleted_by_id, nil)
|
||||
|> put_change(:deletion_reason, "")
|
||||
end
|
||||
|
||||
def put_slug(changeset) do
|
||||
slug =
|
||||
changeset
|
||||
|
|
54
lib/philomena_web/controllers/topic/hide_controller.ex
Normal file
54
lib/philomena_web/controllers/topic/hide_controller.ex
Normal file
|
@ -0,0 +1,54 @@
|
|||
defmodule PhilomenaWeb.Topic.HideController do
|
||||
import Plug.Conn
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.Topics.Topic
|
||||
alias Philomena.Topics
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
plug :load_topic
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :hide, delete: :hide
|
||||
plug :authorize_resource, model: Topic, id_name: "topic_id", persisted: true
|
||||
|
||||
def create(conn, %{"topic" => topic_params}) do
|
||||
topic = conn.assigns.topic
|
||||
deletion_reason = topic_params["deletion_reason"]
|
||||
user = conn.assigns.current_user
|
||||
|
||||
case Topics.hide_topic(topic, deletion_reason, user) do
|
||||
{:ok, topic} ->
|
||||
conn
|
||||
|> put_flash(:info, "Topic successfully hidden!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
{:error, _changeset} ->
|
||||
conn
|
||||
|> put_flash(:error, "Unable to hide the topic!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, _opts) do
|
||||
topic = conn.assigns.topic
|
||||
|
||||
case Topics.unhide_topic(topic) do
|
||||
{:ok, topic} ->
|
||||
conn
|
||||
|> put_flash(:info, "Topic successfully restored!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
{:error, _changeset} ->
|
||||
conn
|
||||
|> put_flash(:error, "Unable to restore the topic!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
end
|
||||
end
|
||||
|
||||
defp load_topic(conn, _opts) do
|
||||
topic = Topic
|
||||
|> where(forum_id: ^conn.params["forum_id"], slug: ^conn.params["topic_id"])
|
||||
|> preload([:forum])
|
||||
|> Repo.one()
|
||||
|
||||
Plug.Conn.assign(conn, :topic, topic)
|
||||
end
|
||||
end
|
53
lib/philomena_web/controllers/topic/lock_controller.ex
Normal file
53
lib/philomena_web/controllers/topic/lock_controller.ex
Normal file
|
@ -0,0 +1,53 @@
|
|||
defmodule PhilomenaWeb.Topic.LockController do
|
||||
import Plug.Conn
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.Topics.Topic
|
||||
alias Philomena.Topics
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
plug :load_topic
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :lock, delete: :unlock
|
||||
plug :authorize_resource, model: Topic, id_name: "topic_id", persisted: true
|
||||
|
||||
def create(conn, %{"topic" => topic_params}) do
|
||||
topic = conn.assigns.topic
|
||||
user = conn.assigns.current_user
|
||||
|
||||
case Topics.lock_topic(topic, topic_params, user) do
|
||||
{:ok, topic} ->
|
||||
conn
|
||||
|> put_flash(:info, "Topic successfully locked!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
{:error, _changeset} ->
|
||||
conn
|
||||
|> put_flash(:error, "Unable to lock the topic!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, _opts) do
|
||||
topic = conn.assigns.topic
|
||||
|
||||
case Topics.unlock_topic(topic) do
|
||||
{:ok, topic} ->
|
||||
conn
|
||||
|> put_flash(:info, "Topic successfully unlocked!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
{:error, _changeset} ->
|
||||
conn
|
||||
|> put_flash(:error, "Unable to unlock the topic!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
end
|
||||
end
|
||||
|
||||
defp load_topic(conn, _opts) do
|
||||
topic = Topic
|
||||
|> where(forum_id: ^conn.params["forum_id"], slug: ^conn.params["topic_id"])
|
||||
|> preload([:forum])
|
||||
|> Repo.one()
|
||||
|
||||
Plug.Conn.assign(conn, :topic, topic)
|
||||
end
|
||||
end
|
43
lib/philomena_web/controllers/topic/move_controller.ex
Normal file
43
lib/philomena_web/controllers/topic/move_controller.ex
Normal file
|
@ -0,0 +1,43 @@
|
|||
defmodule PhilomenaWeb.Topic.MoveController do
|
||||
import Plug.Conn
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.Topics.Topic
|
||||
alias Philomena.Topics
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
plug :load_topic
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :move
|
||||
plug :authorize_resource, model: Topic, id_name: "topic_id", persisted: true
|
||||
|
||||
# intentionally blank
|
||||
# todo: moving
|
||||
def create(conn, %{"topic" => topic_params}) do
|
||||
topic = conn.assigns.topic
|
||||
target_forum_id = String.to_integer(topic_params["target_forum_id"])
|
||||
|
||||
case Topics.move_topic(topic, target_forum_id) do
|
||||
{:ok, %{topic: topic}} ->
|
||||
topic = Repo.preload(topic, :forum)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Topic successfully moved!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
{:error, _changeset} ->
|
||||
topic = Repo.preload(topic, :forum)
|
||||
|
||||
conn
|
||||
|> put_flash(:error, "Unable to move the topic!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
end
|
||||
end
|
||||
|
||||
defp load_topic(conn, _opts) do
|
||||
topic = Topic
|
||||
|> where(forum_id: ^conn.params["forum_id"], slug: ^conn.params["topic_id"])
|
||||
|> Repo.one()
|
||||
|
||||
Plug.Conn.assign(conn, :topic, topic)
|
||||
end
|
||||
end
|
|
@ -5,7 +5,7 @@ defmodule PhilomenaWeb.Topic.Post.DeleteController do
|
|||
alias Philomena.Posts
|
||||
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :hide
|
||||
plug :load_and_authorize_resource, model: Post, id_name: "post_id", persisted: true, preload: [:topic]
|
||||
plug :load_and_authorize_resource, model: Post, id_name: "post_id", persisted: true, preload: [:topic, topic: :forum]
|
||||
|
||||
def create(conn, _params) do
|
||||
post = conn.assigns.post
|
||||
|
@ -16,12 +16,12 @@ 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}")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum, post.topic) <> "#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}")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum, post.topic) <> "#post_#{post.id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ defmodule PhilomenaWeb.Topic.Post.HideController do
|
|||
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]
|
||||
plug :load_and_authorize_resource, model: Post, id_name: "post_id", persisted: true, preload: [:topic, topic: :forum]
|
||||
|
||||
def create(conn, %{"post" => post_params}) do
|
||||
post = conn.assigns.post
|
||||
|
@ -17,11 +17,11 @@ defmodule PhilomenaWeb.Topic.Post.HideController do
|
|||
|
||||
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}")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum, post.topic) <> "#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}")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum, post.topic) <> "#post_#{post.id}")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -34,11 +34,11 @@ defmodule PhilomenaWeb.Topic.Post.HideController do
|
|||
|
||||
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}")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum, post.topic) <> "#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}")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, post.topic.forum, post.topic) <> "#post_#{post.id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -83,4 +83,4 @@ defmodule PhilomenaWeb.Topic.PostController do
|
|||
Plug.Conn.assign(conn, :topic, topic)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
52
lib/philomena_web/controllers/topic/stick_controller.ex
Normal file
52
lib/philomena_web/controllers/topic/stick_controller.ex
Normal file
|
@ -0,0 +1,52 @@
|
|||
defmodule PhilomenaWeb.Topic.StickController do
|
||||
import Plug.Conn
|
||||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.Topics.Topic
|
||||
alias Philomena.Topics
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
plug :load_topic
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :stick, delete: :stick
|
||||
plug :authorize_resource, model: Topic, id_name: "topic_id", persisted: true
|
||||
|
||||
def create(conn, _opts) do
|
||||
topic = conn.assigns.topic
|
||||
|
||||
case Topics.stick_topic(topic) do
|
||||
{:ok, topic} ->
|
||||
conn
|
||||
|> put_flash(:info, "Topic successfully stickied!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
{:error, _changeset} ->
|
||||
conn
|
||||
|> put_flash(:error, "Unable to stick the topic!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, _opts) do
|
||||
topic = conn.assigns.topic
|
||||
|
||||
case Topics.unstick_topic(topic) do
|
||||
{:ok, topic} ->
|
||||
conn
|
||||
|> put_flash(:info, "Topic successfully unstickied!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
{:error, _changeset} ->
|
||||
conn
|
||||
|> put_flash(:error, "Unable to unstick the topic!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum, topic))
|
||||
end
|
||||
end
|
||||
|
||||
defp load_topic(conn, _opts) do
|
||||
topic = Topic
|
||||
|> where(forum_id: ^conn.params["forum_id"], slug: ^conn.params["topic_id"])
|
||||
|> preload([:forum])
|
||||
|> Repo.one()
|
||||
|
||||
Plug.Conn.assign(conn, :topic, topic)
|
||||
end
|
||||
end
|
|
@ -19,8 +19,8 @@ defmodule PhilomenaWeb.TopicController do
|
|||
forum = conn.assigns.forum
|
||||
topic =
|
||||
Topic
|
||||
|> where(forum_id: ^forum.id, slug: ^slug, hidden_from_users: false)
|
||||
|> preload([:user, poll: :options])
|
||||
|> where(forum_id: ^forum.id, slug: ^slug)
|
||||
|> preload([:deleted_by, :user, poll: :options])
|
||||
|> Repo.one()
|
||||
|
||||
user = conn.assigns.current_user
|
||||
|
|
|
@ -126,6 +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 "/move", Topic.MoveController, only: [:create], singleton: true
|
||||
resources "/stick", Topic.StickController, only: [:create, :delete], singleton: true
|
||||
resources "/lock", Topic.LockController, only: [:create, :delete], singleton: true
|
||||
resources "/hide", Topic.HideController, only: [:create, :delete], 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: [:create], singleton: true
|
||||
|
|
|
@ -3,6 +3,23 @@ elixir:
|
|||
pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @posts, route: route, last: true
|
||||
|
||||
h1 = @topic.title
|
||||
= if @topic.hidden_from_users do
|
||||
.block.block--fixed.block--danger
|
||||
h4 This topic has been deleted by a moderator
|
||||
p
|
||||
strong> Reason:
|
||||
em
|
||||
= @topic.deletion_reason
|
||||
= if can?(@conn, :unhide, @topic) do
|
||||
p
|
||||
strong> Deleted by:
|
||||
em
|
||||
strong
|
||||
= link(@topic.deleted_by.name, to: Routes.profile_path(@conn, :show, @topic.deleted_by))
|
||||
p
|
||||
= link(to: Routes.forum_topic_hide_path(@conn, :delete, @forum.id, @topic), method: :delete, class: "button") do
|
||||
i.fas.fa-check>
|
||||
' Restore
|
||||
/ Header section
|
||||
.block
|
||||
.block__header
|
||||
|
@ -11,60 +28,66 @@ h1 = @topic.title
|
|||
=> link(@forum.name, to: Routes.forum_path(@conn, :show, @forum))
|
||||
' »
|
||||
=> link(@topic.title, to: Routes.forum_topic_path(@conn, :show, @forum, @topic))
|
||||
a href=Routes.post_path(@conn, :index, pq: "topic_id:#{@topic.id}")
|
||||
i.fa.fa-fw.fa-search>
|
||||
' Search Posts
|
||||
.flex.flex--wrap.block__header.block__header--light
|
||||
.flex--fixed
|
||||
= pagination
|
||||
.flex--fixed.block__header__item
|
||||
' Started by
|
||||
=> render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @topic, conn: @conn
|
||||
.flex--fixed.block__header__item
|
||||
' Posted
|
||||
=< pretty_time(@topic.created_at)
|
||||
.flex--fixed.block__header__item
|
||||
=> @topic.post_count - 1
|
||||
' replies
|
||||
= render PhilomenaWeb.Topic.SubscriptionView, "_subscription.html", forum: @forum, topic: @topic, watching: @watching, conn: @conn
|
||||
= if not @topic.hidden_from_users or can?(@conn, :hide, @topic) do
|
||||
a href=Routes.post_path(@conn, :index, pq: "topic_id:#{@topic.id}")
|
||||
i.fa.fa-fw.fa-search>
|
||||
' Search Posts
|
||||
.flex.flex--wrap.block__header.block__header--light
|
||||
.flex--fixed
|
||||
= pagination
|
||||
.flex--fixed.block__header__item
|
||||
' Started by
|
||||
=> render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @topic, conn: @conn
|
||||
.flex--fixed.block__header__item
|
||||
' Posted
|
||||
=< pretty_time(@topic.created_at)
|
||||
.flex--fixed.block__header__item
|
||||
=> @topic.post_count - 1
|
||||
' replies
|
||||
= if not @topic.hidden_from_users do
|
||||
= render PhilomenaWeb.Topic.SubscriptionView, "_subscription.html", forum: @forum, topic: @topic, watching: @watching, conn: @conn
|
||||
|
||||
/ Display the poll, if any
|
||||
= if @topic.poll do
|
||||
= render PhilomenaWeb.Topic.PollView, "_display.html", poll: @topic.poll, conn: @conn
|
||||
= if not @topic.hidden_from_users or can?(@conn, :hide, @topic) do
|
||||
/ Display the poll, if any
|
||||
= if @topic.poll do
|
||||
= render PhilomenaWeb.Topic.PollView, "_display.html", poll: @topic.poll, conn: @conn
|
||||
|
||||
/ The actual posts
|
||||
.posts-area
|
||||
.post-list
|
||||
= for {post, body} <- @posts, (!post.destroyed_content or can?(@conn, :hide, post)) do
|
||||
= render PhilomenaWeb.PostView, "_post.html", conn: @conn, post: post, body: body
|
||||
/ The actual posts
|
||||
.posts-area
|
||||
.post-list
|
||||
= 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
|
||||
= render PhilomenaWeb.AdvertView, "_box.html", advert: @conn.assigns.advert, conn: @conn
|
||||
= if @conn.assigns.advert do
|
||||
= render PhilomenaWeb.AdvertView, "_box.html", advert: @conn.assigns.advert, conn: @conn
|
||||
|
||||
/ Post editability data for JS
|
||||
/.js-editable-posts data-editable=editable_communications(@posts).to_json
|
||||
/ Post editability data for JS
|
||||
/.js-editable-posts data-editable=editable_communications(@posts).to_json
|
||||
|
||||
/ Footer section
|
||||
.block
|
||||
.block__header.block__header--light
|
||||
= pagination
|
||||
/ Footer section
|
||||
.block
|
||||
.block__header.block__header--light
|
||||
= pagination
|
||||
|
||||
= if @topic.locked_at do
|
||||
.block.block--fixed.block--warning
|
||||
h4 This topic has been locked to new posts from non-moderators.
|
||||
p
|
||||
' Locked
|
||||
=> pretty_time(@topic.locked_at)
|
||||
|
||||
p
|
||||
' Lock reason:
|
||||
em = @topic.lock_reason
|
||||
= if @topic.locked_at do
|
||||
.block.block--fixed.block--warning
|
||||
h4 This topic has been locked to new posts from non-moderators.
|
||||
p
|
||||
' Locked
|
||||
=> pretty_time(@topic.locked_at)
|
||||
|
||||
p
|
||||
' Lock reason:
|
||||
em = @topic.lock_reason
|
||||
/ Post form
|
||||
= cond do
|
||||
- @conn.assigns.current_ban ->
|
||||
= render PhilomenaWeb.BanView, "_ban_reason.html", conn: @conn
|
||||
|
||||
- @topic.hidden_from_users ->
|
||||
.block.block--fixed.block--danger
|
||||
h4 Cannot reply to a deleted topic.
|
||||
|
||||
- @topic.post_count < 200_000 and can?(@conn, :create_post, @topic) ->
|
||||
= render PhilomenaWeb.Topic.PostView, "_form.html", conn: @conn, forum: @forum, topic: @topic, changeset: @changeset
|
||||
|
||||
|
@ -74,45 +97,49 @@ h1 = @topic.title
|
|||
p For various reasons, we'd like to ask you to start a new topic.
|
||||
|
||||
- true ->
|
||||
|
||||
/ Mod tools
|
||||
/- if can? :assist, Topic
|
||||
/ .block__content
|
||||
/ input.toggle-box id="administrator_tools" type="checkbox" checked=false
|
||||
/ label for="administrator_tools" Topic Admin Tools
|
||||
/ .toggle-box-container
|
||||
/ .toggle-box-container__content
|
||||
/ p
|
||||
/ - if can?(:unlock, @topic) && !@topic.locked_at.nil?
|
||||
/ => button_to forum_topic_lock_path(@forum, @topic), method: :delete, class: 'button' do
|
||||
/ i.fa.fa-lock>
|
||||
/ | Unlock
|
||||
/ - if can?(:stick, @topic) && !@topic.sticky
|
||||
/ => button_to forum_topic_stick_path(@forum, @topic), method: :post, class: 'button' do
|
||||
/ i.fa.fa-thumbtack>
|
||||
/ | Stick
|
||||
/ - if can?(:stick, @topic) && @topic.sticky
|
||||
/ => button_to forum_topic_stick_path(@forum, @topic), method: :delete, class: 'button' do
|
||||
/ i.fa.fa-thumbtack>
|
||||
/ | Unstick
|
||||
/ - if can?(:lock, @topic) && @topic.locked_at.nil?
|
||||
/ = form_tag forum_topic_lock_path(@forum, @topic), method: :post, class: 'hform' do
|
||||
/ .field
|
||||
/ => text_field_tag :lock_reason, '', placeholder: 'Lock reason', class: 'input hform__text'
|
||||
/ => button_tag class: 'hform__button button' do
|
||||
/ i.fa.fa-unlock>
|
||||
/ | Lock
|
||||
/ - if can? :move, @topic
|
||||
/ = form_tag forum_topic_move_path(@forum, @topic), method: :post, class: 'hform' do
|
||||
/ .field
|
||||
/ => select_tag :target_forum_id, options_from_collection_for_select(Forum.where.not(id: @forum.id).all, :short_name, :name), class: 'input hform__text'
|
||||
/ => button_tag class: 'hform__button button' do
|
||||
/ i.fa.fa-truck>
|
||||
/ | Move
|
||||
/ - if can?(:destroy, @topic) && !@topic.hidden_from_users
|
||||
/ = form_tag forum_topic_hide_path(@forum, @topic), method: :post, class: 'hform' do
|
||||
/ .field
|
||||
/ => text_field_tag :deletion_reason, '', placeholder: 'Deletion reason', required: true, class: 'input hform__text'
|
||||
/ => button_tag class: 'hform__button button' do
|
||||
/ i.fa.fa-trash>
|
||||
/ | Delete
|
||||
= if can?(@conn, :assist, Topic) do
|
||||
.block__content
|
||||
input.toggle-box id="administrator_tools" type="checkbox" checked=false
|
||||
label for="administrator_tools" Manage Topic
|
||||
.toggle-box-container
|
||||
.toggle-box-container__content
|
||||
p
|
||||
= if not @topic.hidden_from_users do
|
||||
= cond do
|
||||
- can?(@conn, :lock, @topic) and is_nil(@topic.locked_at) ->
|
||||
= form_for :topic, Routes.forum_topic_lock_path(@conn, :create, @forum.id, @topic), [method: :post, class: "hform"], fn f ->
|
||||
= text_input f, :lock_reason, class: "input hform__text", placeholder: "Lock reason", required: true
|
||||
= submit class: "hform__button button" do
|
||||
i.fas.fa-lock>
|
||||
' Lock
|
||||
- can?(@conn, :unlock, @topic) and not is_nil(@topic.locked_at) ->
|
||||
= link(to: Routes.forum_topic_lock_path(@conn, :delete, @forum.id, @topic), method: :delete, class: "button") do
|
||||
i.fas.fa-unlock>
|
||||
' Unlock
|
||||
- true ->
|
||||
= cond do
|
||||
- can?(@conn, :stick, @topic) and @topic.sticky ->
|
||||
= link(to: Routes.forum_topic_stick_path(@conn, :delete, @forum.id, @topic), method: :delete, class: "button") do
|
||||
i.fas.fa-thumbtack>
|
||||
' Unstick
|
||||
- can?(@conn, :stick, @topic) and not @topic.sticky ->
|
||||
= link(to: Routes.forum_topic_stick_path(@conn, :create, @forum.id, @topic), method: :post, class: "button") do
|
||||
i.fas.fa-thumbtack>
|
||||
' Stick
|
||||
- true ->
|
||||
= if can?(@conn, :move, @topic) do
|
||||
= form_for :topic, Routes.forum_topic_move_path(@conn, :create, @forum.id, @topic), [method: :post, class: "hform"], fn f ->
|
||||
.field
|
||||
= select f, :target_forum_id, @conn.assigns.forums |> Enum.map(fn forum -> {forum.name, forum.id} end), class: "input hform__text"
|
||||
= submit class: "hform__button button" do
|
||||
i.fas.fa-truck>
|
||||
' Move
|
||||
= if can?(@conn, :hide, @topic) do
|
||||
= form_for :topic, Routes.forum_topic_hide_path(@conn, :create, @forum.id, @topic), [method: :post, class: "hform"], fn f ->
|
||||
.field
|
||||
= text_input f, :deletion_reason, class: "input hform__text", placeholder: "Deletion reason", required: true
|
||||
= submit class: "hform__button button" do
|
||||
i.fas.fa-trash>
|
||||
' Delete
|
||||
- else
|
||||
| Moderation tools unavailable for deleted topics.
|
||||
|
|
Loading…
Reference in a new issue