don't allow posting in locked topics

This commit is contained in:
byte[] 2019-12-06 18:25:05 -05:00
parent 9b94636376
commit b89e9c464f
3 changed files with 14 additions and 9 deletions

View file

@ -109,7 +109,8 @@ defimpl Canada.Can, for: [Atom, Philomena.Users.User] do
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

View file

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

View file

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