diff --git a/lib/philomena/users/ability.ex b/lib/philomena/users/ability.ex index 0c094eb8..b65f7a7a 100644 --- a/lib/philomena/users/ability.ex +++ b/lib/philomena/users/ability.ex @@ -108,8 +108,9 @@ defimpl Canada.Can, for: [Atom, Philomena.Users.User] do def can?(_user, :show, %Forum{access_level: "normal"}), do: true def can?(_user, :show, %Topic{hidden_from_users: false}), do: true def can?(_user, :show, %Post{hidden_from_users: false}), do: true - - # Edit posts + + # Create and edit posts + def can?(_user, :create_post, %Topic{locked_at: nil, hidden_from_users: false}), do: true def can?(%User{id: id}, :edit, %Post{hidden_from_users: false, user_id: id}), do: true # View profile pages diff --git a/lib/philomena_web/controllers/topic/post_controller.ex b/lib/philomena_web/controllers/topic/post_controller.ex index f91c10c3..8e620d77 100644 --- a/lib/philomena_web/controllers/topic/post_controller.ex +++ b/lib/philomena_web/controllers/topic/post_controller.ex @@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Topic.PostController do plug :load_and_authorize_resource, model: Forum, id_field: "short_name", id_name: "forum_id", persisted: true plug :load_topic - plug PhilomenaWeb.CanaryMapPlug, create: :show, edit: :show, update: :show + plug PhilomenaWeb.CanaryMapPlug, create: :create_post, edit: :create_post, update: :create_post plug :authorize_resource, model: Topic, id_field: "slug", id_name: "topic_id", persisted: true plug PhilomenaWeb.CanaryMapPlug, edit: :edit, update: :edit diff --git a/lib/philomena_web/templates/topic/show.html.slime b/lib/philomena_web/templates/topic/show.html.slime index 776c84a8..ceead9ea 100644 --- a/lib/philomena_web/templates/topic/show.html.slime +++ b/lib/philomena_web/templates/topic/show.html.slime @@ -50,12 +50,16 @@ h1 = @topic.title = pagination / Post form - = if @topic.post_count < 200_000 do - = render PhilomenaWeb.Topic.PostView, "_form.html", conn: @conn, forum: @forum, topic: @topic, changeset: @changeset - - else - /h3 Okay, we're impressed - /p You're looking at a thread with over 200,000 posts in it! - /p For various reasons, we'd like to ask you to start a new topic. + = cond do + - @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 + + - @topic.post_count < 200_000 -> + h3 Okay, we're impressed + p You're looking at a thread with over 200,000 posts in it! + p For various reasons, we'd like to ask you to start a new topic. + + - true -> / Mod tools /- if can? :assist, Topic