Browse Source

fix(webmention): Set global moderation status.

jackyalcine 7 months ago
parent
commit
731dcbbea6
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D

+ 3
- 1
lib/repo/webmention.ex View File

@@ -236,7 +236,9 @@ defmodule Koype.Repo.Webmention do
236 236
   def attempt_auto_moderation(model)
237 237
 
238 238
   def attempt_auto_moderation(%Koype.Repo.Webmention{moderated_at: nil} = model) do
239
-    detected_status = Koype.Repo.DomainRuleSet.get_status_for_url(model.source) || :pending
239
+    detected_status =
240
+      Koype.Repo.DomainRuleSet.get_status_for_url(model.source) ||
241
+        Koype.Webmention.default_moderation_state()
240 242
 
241 243
     case set_moderation_status(model, detected_status) do
242 244
       {:ok, model} -> model

+ 13
- 0
lib/webmention.ex View File

@@ -281,4 +281,17 @@ defmodule Koype.Webmention do
281 281
   end
282 282
 
283 283
   def reprocess(), do: Koype.Job.create(Koype.Job.Webmention.Process, [])
284
+
285
+  def default_moderation_status(),
286
+    do: Koype.Setting.get("webmention:moderation_status", "pending") |> String.to_existing_atom()
287
+
288
+  def set_default_moderation_status(status \\ "pending")
289
+
290
+  def set_default_moderation_status(status) when status in ~w(pending approved rejected),
291
+    do: Koype.Setting.set("webmention:moderation_status", status)
292
+
293
+  def set_default_moderation_status(status) when is_binary(status),
294
+    do: set_default_moderation_status(Atom.to_string(status))
295
+
296
+  def set_default_moderation_status(_), do: set_default_moderation_status("pending")
284 297
 end

+ 6
- 0
web/controllers/domain_rule_list_controller.ex View File

@@ -16,4 +16,10 @@ defmodule Koype.Web.DomainRuleSetController do
16 16
 
17 17
     redirect(conn, to: domain_rule_set_path(conn, :index))
18 18
   end
19
+
20
+  def global_status(conn, params) do
21
+    Koype.Webmention.set_default_moderation_status(params["status"])
22
+
23
+    redirect(conn, to: domain_rule_set_path(conn, :index))
24
+  end
19 25
 end

+ 1
- 0
web/router.ex View File

@@ -114,6 +114,7 @@ defmodule Koype.Web.Router do
114 114
     resources("/themes", ThemeController, except: ~w(edit create)a)
115 115
 
116 116
     resources("/domain-rule-sets", DomainRuleSetController, except: ~w(new)a)
117
+    post("/domain-rule-sets/global", DomainRuleSetController, :global_status)
117 118
   end
118 119
 
119 120
   scope "/~/indie", Koype.Web do

+ 11
- 2
web/templates/domain_rule_set/index.html.eex View File

@@ -5,12 +5,21 @@
5 5
     Set the rules on who can interact with your site. This controls which <a class="blue" href="https://webmention.net">Webmentions</a> show automatically with no moderation on your site.
6 6
   </p>
7 7
   <% end %>
8
+  <form method="post" action="<%= domain_rule_set_path(@conn, :global_status) %>">
9
+    <input type="hidden" name="_csrf_token" value="<%= Phoenix.Controller.get_csrf_token %>" />
10
+    <select name="status">
11
+      <option value="approved" <%= if Koype.Webmention.default_moderation_status() == :approved, do: "selected" %>>Always Show</option>
12
+      <option value="rejected" <%= if Koype.Webmention.default_moderation_status() == :rejected, do: "selected" %>>Always Hide</option>
13
+      <option value="pending" <%= if Koype.Webmention.default_moderation_status() == :pending, do: "selected" %>>Require Moderation</option>
14
+    </select>
15
+    <button type="submit">Set</button>
16
+  </form>
8 17
   <form method="post" action="<%= domain_rule_set_path(@conn, :create) %>">
9 18
     <input type="hidden" name="_csrf_token" value="<%= Phoenix.Controller.get_csrf_token %>" />
10 19
     <input type="url" name="uri" value="<%= @conn.params["url"] %>" />
11 20
     <select name="type">
12
-      <option value="approved" selected>Always Show</option>
13
-      <option value="rejected">Always Hide</option>
21
+      <option value="approved" selected>Show by Default</option>
22
+      <option value="rejected">Hide by Default</option>
14 23
       <option value="pending">Require Moderation</option>
15 24
     </select>
16 25
     <button type="submit">Add</button>

Loading…
Cancel
Save