more appropriate comment fix

This commit is contained in:
Luna D 2020-02-22 10:31:30 -05:00
parent 29dd045202
commit d5337eb75a
No known key found for this signature in database
GPG key ID: D0F46C94720BAA4B
3 changed files with 9 additions and 4 deletions

View file

@ -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('<div class="flash flash--warning">'))
window.location.reload();
else
displayComments(container, text);
});
}
else {
window.location.reload();

View file

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

View file

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