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

@ -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, %Forum{access_level: "normal"}), do: true
def can?(_user, :show, %Topic{hidden_from_users: false}), do: true def can?(_user, :show, %Topic{hidden_from_users: false}), do: true
def can?(_user, :show, %Post{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 def can?(%User{id: id}, :edit, %Post{hidden_from_users: false, user_id: id}), do: true
# View profile pages # 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_and_authorize_resource, model: Forum, id_field: "short_name", id_name: "forum_id", persisted: true
plug :load_topic 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 :authorize_resource, model: Topic, id_field: "slug", id_name: "topic_id", persisted: true
plug PhilomenaWeb.CanaryMapPlug, edit: :edit, update: :edit plug PhilomenaWeb.CanaryMapPlug, edit: :edit, update: :edit

View file

@ -50,12 +50,16 @@ h1 = @topic.title
= pagination = pagination
/ Post form / Post form
= if @topic.post_count < 200_000 do = cond do
= render PhilomenaWeb.Topic.PostView, "_form.html", conn: @conn, forum: @forum, topic: @topic, changeset: @changeset - @topic.post_count < 200_000 and can?(@conn, :create_post, @topic) ->
- else = render PhilomenaWeb.Topic.PostView, "_form.html", conn: @conn, forum: @forum, topic: @topic, changeset: @changeset
/h3 Okay, we're impressed
/p You're looking at a thread with over 200,000 posts in it! - @topic.post_count < 200_000 ->
/p For various reasons, we'd like to ask you to start a new topic. 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 / Mod tools
/- if can? :assist, Topic /- if can? :assist, Topic