diff --git a/assets/js/comment.js b/assets/js/comment.js index 8ba6bf0d..eb52a92d 100644 --- a/assets/js/comment.js +++ b/assets/js/comment.js @@ -29,7 +29,12 @@ function commentPosted(response) { commentEditForm.reset(); if (requestOk) { - response.text().then(text => displayComments(container, text)); + response.text().then(text => { + if (text.includes('
')) + window.location.reload(); + else + displayComments(container, text); + }); } else { window.location.reload(); diff --git a/lib/philomena/comments.ex b/lib/philomena/comments.ex index 7bc684e3..86ecd78d 100644 --- a/lib/philomena/comments.ex +++ b/lib/philomena/comments.ex @@ -43,7 +43,7 @@ defmodule Philomena.Comments do {:error, %Ecto.Changeset{}} """ - def create_comment(%Image{commenting_allowed: true} = image, attribution, params \\ %{}) do + def create_comment(image, attribution, params \\ %{}) do comment = Ecto.build_assoc(image, :comments) |> Comment.creation_changeset(params, attribution) diff --git a/lib/philomena_web/controllers/image/comment_controller.ex b/lib/philomena_web/controllers/image/comment_controller.ex index d67503cf..13b7b92c 100644 --- a/lib/philomena_web/controllers/image/comment_controller.ex +++ b/lib/philomena_web/controllers/image/comment_controller.ex @@ -15,13 +15,13 @@ defmodule PhilomenaWeb.Image.CommentController do edit: :create_comment, update: :create_comment - plug :load_resource, model: Image, id_name: "image_id", persisted: true + plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true plug :verify_authorized when action in [:show] # Undo the previous private parameter screwery plug PhilomenaWeb.LoadCommentPlug, [param: "id", show_hidden: true] when action in [:show] plug PhilomenaWeb.LoadCommentPlug, [param: "id"] when action in [:edit, :update] - plug PhilomenaWeb.CanaryMapPlug, create: :create, edit: :edit, update: :edit + plug PhilomenaWeb.CanaryMapPlug, create: :create_comment, edit: :edit, update: :edit plug :authorize_resource, model: Comment,