mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
Reverse order of type and id arguments
This commit is contained in:
parent
c8410e7957
commit
c898b83e6d
13 changed files with 25 additions and 29 deletions
|
@ -144,7 +144,7 @@ defmodule Philomena.Comments do
|
||||||
end
|
end
|
||||||
|
|
||||||
def hide_comment(%Comment{} = comment, attrs, user) do
|
def hide_comment(%Comment{} = comment, attrs, user) do
|
||||||
report_query = Reports.close_report_query("Comment", comment.id, user)
|
report_query = Reports.close_report_query({"Comment", comment.id}, user)
|
||||||
comment = Comment.hide_changeset(comment, attrs, user)
|
comment = Comment.hide_changeset(comment, attrs, user)
|
||||||
|
|
||||||
Multi.new()
|
Multi.new()
|
||||||
|
@ -185,7 +185,7 @@ defmodule Philomena.Comments do
|
||||||
end
|
end
|
||||||
|
|
||||||
def approve_comment(%Comment{} = comment, user) do
|
def approve_comment(%Comment{} = comment, user) do
|
||||||
report_query = Reports.close_report_query("Comment", comment.id, user)
|
report_query = Reports.close_report_query({"Comment", comment.id}, user)
|
||||||
comment = Comment.approve_changeset(comment)
|
comment = Comment.approve_changeset(comment)
|
||||||
|
|
||||||
Multi.new()
|
Multi.new()
|
||||||
|
@ -210,8 +210,7 @@ defmodule Philomena.Comments do
|
||||||
|
|
||||||
def report_non_approved(comment) do
|
def report_non_approved(comment) do
|
||||||
Reports.create_system_report(
|
Reports.create_system_report(
|
||||||
"Comment",
|
{"Comment", comment.id},
|
||||||
comment.id,
|
|
||||||
"Approval",
|
"Approval",
|
||||||
"Comment contains externally-embedded images and has been flagged for review."
|
"Comment contains externally-embedded images and has been flagged for review."
|
||||||
)
|
)
|
||||||
|
|
|
@ -208,7 +208,7 @@ defmodule Philomena.Conversations do
|
||||||
end
|
end
|
||||||
|
|
||||||
def approve_conversation_message(message, user) do
|
def approve_conversation_message(message, user) do
|
||||||
reports_query = Reports.close_report_query("Conversation", message.conversation_id, user)
|
reports_query = Reports.close_report_query({"Conversation", message.conversation_id}, user)
|
||||||
|
|
||||||
message_query =
|
message_query =
|
||||||
message
|
message
|
||||||
|
@ -236,8 +236,7 @@ defmodule Philomena.Conversations do
|
||||||
|
|
||||||
def report_non_approved(id) do
|
def report_non_approved(id) do
|
||||||
Reports.create_system_report(
|
Reports.create_system_report(
|
||||||
"Conversation",
|
{"Conversation", id},
|
||||||
id,
|
|
||||||
"Approval",
|
"Approval",
|
||||||
"PM contains externally-embedded images and has been flagged for review."
|
"PM contains externally-embedded images and has been flagged for review."
|
||||||
)
|
)
|
||||||
|
|
|
@ -193,8 +193,7 @@ defmodule Philomena.Images do
|
||||||
|
|
||||||
defp maybe_suggest_user_verification(%User{id: id, uploads_count: 5, verified: false}) do
|
defp maybe_suggest_user_verification(%User{id: id, uploads_count: 5, verified: false}) do
|
||||||
Reports.create_system_report(
|
Reports.create_system_report(
|
||||||
"User",
|
{"User", id},
|
||||||
id,
|
|
||||||
"Verification",
|
"Verification",
|
||||||
"User has uploaded enough approved images to be considered for verification."
|
"User has uploaded enough approved images to be considered for verification."
|
||||||
)
|
)
|
||||||
|
@ -577,7 +576,7 @@ defmodule Philomena.Images do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp hide_image_multi(changeset, image, user, multi) do
|
defp hide_image_multi(changeset, image, user, multi) do
|
||||||
report_query = Reports.close_report_query("Image", image.id, user)
|
report_query = Reports.close_report_query({"Image", image.id}, user)
|
||||||
|
|
||||||
galleries =
|
galleries =
|
||||||
Gallery
|
Gallery
|
||||||
|
|
|
@ -114,8 +114,7 @@ defmodule Philomena.Posts do
|
||||||
|
|
||||||
def report_non_approved(post) do
|
def report_non_approved(post) do
|
||||||
Reports.create_system_report(
|
Reports.create_system_report(
|
||||||
"Post",
|
{"Post", post.id},
|
||||||
post.id,
|
|
||||||
"Approval",
|
"Approval",
|
||||||
"Post contains externally-embedded images and has been flagged for review."
|
"Post contains externally-embedded images and has been flagged for review."
|
||||||
)
|
)
|
||||||
|
@ -203,7 +202,7 @@ defmodule Philomena.Posts do
|
||||||
end
|
end
|
||||||
|
|
||||||
def hide_post(%Post{} = post, attrs, user) do
|
def hide_post(%Post{} = post, attrs, user) do
|
||||||
report_query = Reports.close_report_query("Post", post.id, user)
|
report_query = Reports.close_report_query({"Post", post.id}, user)
|
||||||
|
|
||||||
topics =
|
topics =
|
||||||
Topic
|
Topic
|
||||||
|
@ -250,7 +249,7 @@ defmodule Philomena.Posts do
|
||||||
end
|
end
|
||||||
|
|
||||||
def approve_post(%Post{} = post, user) do
|
def approve_post(%Post{} = post, user) do
|
||||||
report_query = Reports.close_report_query("Post", post.id, user)
|
report_query = Reports.close_report_query({"Post", post.id}, user)
|
||||||
post = Post.approve_changeset(post)
|
post = Post.approve_changeset(post)
|
||||||
|
|
||||||
Multi.new()
|
Multi.new()
|
||||||
|
|
|
@ -78,8 +78,8 @@ defmodule Philomena.Reports do
|
||||||
{:error, %Ecto.Changeset{}}
|
{:error, %Ecto.Changeset{}}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def create_report(reportable_id, reportable_type, attribution, attrs \\ %{}) do
|
def create_report({reportable_type, reportable_id} = _type_and_id, attribution, attrs \\ %{}) do
|
||||||
%Report{reportable_id: reportable_id, reportable_type: reportable_type}
|
%Report{reportable_type: reportable_type, reportable_id: reportable_id}
|
||||||
|> Report.creation_changeset(attrs, attribution)
|
|> Report.creation_changeset(attrs, attribution)
|
||||||
|> Repo.insert()
|
|> Repo.insert()
|
||||||
|> reindex_after_update()
|
|> reindex_after_update()
|
||||||
|
@ -92,7 +92,7 @@ defmodule Philomena.Reports do
|
||||||
Because this is only a query due to the limitations of `m:Ecto.Multi`, this must be
|
Because this is only a query due to the limitations of `m:Ecto.Multi`, this must be
|
||||||
coupled with an associated call to `reindex_reports/1` to operate correctly, e.g.:
|
coupled with an associated call to `reindex_reports/1` to operate correctly, e.g.:
|
||||||
|
|
||||||
report_query = Reports.close_system_report_query("Image", image.id, user)
|
report_query = Reports.close_system_report_query({"Image", image.id}, user)
|
||||||
|
|
||||||
Multi.new()
|
Multi.new()
|
||||||
|> Multi.update_all(:reports, report_query, [])
|
|> Multi.update_all(:reports, report_query, [])
|
||||||
|
@ -113,7 +113,7 @@ defmodule Philomena.Reports do
|
||||||
#Ecto.Query<...>
|
#Ecto.Query<...>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def close_report_query(reportable_type, reportable_id, closing_user) do
|
def close_report_query({reportable_type, reportable_id} = _type_and_id, closing_user) do
|
||||||
from r in Report,
|
from r in Report,
|
||||||
where: r.reportable_type == ^reportable_type and r.reportable_id == ^reportable_id,
|
where: r.reportable_type == ^reportable_type and r.reportable_id == ^reportable_id,
|
||||||
select: r.id,
|
select: r.id,
|
||||||
|
@ -126,11 +126,11 @@ defmodule Philomena.Reports do
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
iex> create_system_report("Comment", 1, "Other", "Custom report reason")
|
iex> create_system_report({"Comment", 1}, "Other", "Custom report reason")
|
||||||
{:ok, %Report{}}
|
{:ok, %Report{}}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def create_system_report(reportable_type, reportable_id, category, reason) do
|
def create_system_report({reportable_type, reportable_id} = _type_and_id, category, reason) do
|
||||||
attrs = %{
|
attrs = %{
|
||||||
reason: reason,
|
reason: reason,
|
||||||
category: category
|
category: category
|
||||||
|
|
|
@ -42,6 +42,6 @@ defmodule PhilomenaWeb.Conversation.ReportController do
|
||||||
conversation = conn.assigns.conversation
|
conversation = conn.assigns.conversation
|
||||||
action = ~p"/conversations/#{conversation}/reports"
|
action = ~p"/conversations/#{conversation}/reports"
|
||||||
|
|
||||||
ReportController.create(conn, action, conversation, "Conversation", params)
|
ReportController.create(conn, action, "Conversation", conversation, params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,6 +41,6 @@ defmodule PhilomenaWeb.Gallery.ReportController do
|
||||||
gallery = conn.assigns.gallery
|
gallery = conn.assigns.gallery
|
||||||
action = ~p"/galleries/#{gallery}/reports"
|
action = ~p"/galleries/#{gallery}/reports"
|
||||||
|
|
||||||
ReportController.create(conn, action, gallery, "Gallery", params)
|
ReportController.create(conn, action, "Gallery", gallery, params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,6 +44,6 @@ defmodule PhilomenaWeb.Image.Comment.ReportController do
|
||||||
comment = conn.assigns.comment
|
comment = conn.assigns.comment
|
||||||
action = ~p"/images/#{comment.image}/comments/#{comment}/reports"
|
action = ~p"/images/#{comment.image}/comments/#{comment}/reports"
|
||||||
|
|
||||||
ReportController.create(conn, action, comment, "Comment", params)
|
ReportController.create(conn, action, "Comment", comment, params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,6 +41,6 @@ defmodule PhilomenaWeb.Image.ReportController do
|
||||||
image = conn.assigns.image
|
image = conn.assigns.image
|
||||||
action = ~p"/images/#{image}/reports"
|
action = ~p"/images/#{image}/reports"
|
||||||
|
|
||||||
ReportController.create(conn, action, image, "Image", params)
|
ReportController.create(conn, action, "Image", image, params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,7 +53,7 @@ defmodule PhilomenaWeb.Profile.Commission.ReportController do
|
||||||
commission = conn.assigns.user.commission
|
commission = conn.assigns.user.commission
|
||||||
action = ~p"/profiles/#{user}/commission/reports"
|
action = ~p"/profiles/#{user}/commission/reports"
|
||||||
|
|
||||||
ReportController.create(conn, action, commission, "Commission", params)
|
ReportController.create(conn, action, "Commission", commission, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp ensure_commission(conn, _opts) do
|
defp ensure_commission(conn, _opts) do
|
||||||
|
|
|
@ -41,6 +41,6 @@ defmodule PhilomenaWeb.Profile.ReportController do
|
||||||
user = conn.assigns.user
|
user = conn.assigns.user
|
||||||
action = ~p"/profiles/#{user}/reports"
|
action = ~p"/profiles/#{user}/reports"
|
||||||
|
|
||||||
ReportController.create(conn, action, user, "User", params)
|
ReportController.create(conn, action, "User", user, params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,7 +33,7 @@ defmodule PhilomenaWeb.ReportController do
|
||||||
# plug PhilomenaWeb.CheckCaptchaPlug when action in [:create]
|
# plug PhilomenaWeb.CheckCaptchaPlug when action in [:create]
|
||||||
# plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
# plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
||||||
|
|
||||||
def create(conn, action, reportable, reportable_type, %{"report" => report_params}) do
|
def create(conn, action, reportable_type, reportable, %{"report" => report_params}) do
|
||||||
attribution = conn.assigns.attributes
|
attribution = conn.assigns.attributes
|
||||||
|
|
||||||
case too_many_reports?(conn) do
|
case too_many_reports?(conn) do
|
||||||
|
@ -46,7 +46,7 @@ defmodule PhilomenaWeb.ReportController do
|
||||||
|> redirect(to: "/")
|
|> redirect(to: "/")
|
||||||
|
|
||||||
_falsy ->
|
_falsy ->
|
||||||
case Reports.create_report(reportable.id, reportable_type, attribution, report_params) do
|
case Reports.create_report({reportable_type, reportable.id}, attribution, report_params) do
|
||||||
{:ok, _report} ->
|
{:ok, _report} ->
|
||||||
conn
|
conn
|
||||||
|> put_flash(
|
|> put_flash(
|
||||||
|
|
|
@ -42,6 +42,6 @@ defmodule PhilomenaWeb.Topic.Post.ReportController do
|
||||||
post = conn.assigns.post
|
post = conn.assigns.post
|
||||||
action = ~p"/forums/#{topic.forum}/topics/#{topic}/posts/#{post}/reports"
|
action = ~p"/forums/#{topic.forum}/topics/#{topic}/posts/#{post}/reports"
|
||||||
|
|
||||||
ReportController.create(conn, action, post, "Post", params)
|
ReportController.create(conn, action, "Post", post, params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue