Rename notification "privacy_option" setting
authorMark Felder <feld@FreeBSD.org>
Fri, 26 Jun 2020 17:45:46 +0000 (12:45 -0500)
committerMark Felder <feld@FreeBSD.org>
Fri, 26 Jun 2020 17:45:46 +0000 (12:45 -0500)
docs/API/pleroma_api.md
lib/mix/tasks/pleroma/notification_settings.ex
lib/pleroma/user/notification_setting.ex
lib/pleroma/web/api_spec/schemas/account.ex
lib/pleroma/web/push/impl.ex
priv/repo/migrations/20200626163359_rename_notification_privacy_option.exs [new file with mode: 0644]
test/user/notification_setting_test.exs
test/web/mastodon_api/views/account_view_test.exs
test/web/push/impl_test.exs
test/web/twitter_api/util_controller_test.exs

index 6d8a88a447b9e11470357af515e2eee0e70ed2cb..5bd38ad364d9db7be00fbb0750a9de3ddbe1e1e8 100644 (file)
@@ -288,7 +288,7 @@ See [Admin-API](admin_api.md)
 * Authentication: required
 * Params:
     * `block_from_strangers`: BOOLEAN field, blocks notifications from accounts you do not follow
-    * `privacy_option`: BOOLEAN field. When set to true, it removes the contents of a message from the push notification.
+    * `hide_notification_contents`: BOOLEAN field. When set to true, it removes the contents of a message from the push notification.
 * Response: JSON. Returns `{"status": "success"}` if the update was successful, otherwise returns `{"error": "error_msg"}`
 
 ## `/api/pleroma/healthcheck`
index 7d65f058763365e0a724b6ee1b57bb1ac1674631..00f5ba7bfe61ce5aba33238deb81fce5e1aab65a 100644 (file)
@@ -3,8 +3,8 @@ defmodule Mix.Tasks.Pleroma.NotificationSettings do
   @moduledoc """
   Example:
 
-  > mix pleroma.notification_settings --privacy-option=false --nickname-users="parallel588"  # set false only for parallel588 user
-  > mix pleroma.notification_settings --privacy-option=true # set true for all users
+  > mix pleroma.notification_settings --hide-notification-contents=false --nickname-users="parallel588"  # set false only for parallel588 user
+  > mix pleroma.notification_settings --hide-notification-contents=true # set true for all users
 
   """
 
@@ -19,16 +19,16 @@ defmodule Mix.Tasks.Pleroma.NotificationSettings do
       OptionParser.parse(
         args,
         strict: [
-          privacy_option: :boolean,
+          hide_notification_contents: :boolean,
           email_users: :string,
           nickname_users: :string
         ]
       )
 
-    privacy_option = Keyword.get(options, :privacy_option)
+    hide_notification_contents = Keyword.get(options, :hide_notification_contents)
 
-    if not is_nil(privacy_option) do
-      privacy_option
+    if not is_nil(hide_notification_contents) do
+      hide_notification_contents
       |> build_query(options)
       |> Pleroma.Repo.update_all([])
     end
@@ -36,15 +36,15 @@ defmodule Mix.Tasks.Pleroma.NotificationSettings do
     shell_info("Done")
   end
 
-  defp build_query(privacy_option, options) do
+  defp build_query(hide_notification_contents, options) do
     query =
       from(u in Pleroma.User,
         update: [
           set: [
             notification_settings:
               fragment(
-                "jsonb_set(notification_settings, '{privacy_option}', ?)",
-                ^privacy_option
+                "jsonb_set(notification_settings, '{hide_notification_contents}', ?)",
+                ^hide_notification_contents
               )
           ]
         ]
index ffe9860de28706513589e0dc574aed58d3c82db8..7d9e8a000f095c06036b93db168e065d6b96379c 100644 (file)
@@ -11,14 +11,14 @@ defmodule Pleroma.User.NotificationSetting do
 
   embedded_schema do
     field(:block_from_strangers, :boolean, default: false)
-    field(:privacy_option, :boolean, default: false)
+    field(:hide_notification_contents, :boolean, default: false)
   end
 
   def changeset(schema, params) do
     schema
     |> cast(prepare_attrs(params), [
       :block_from_strangers,
-      :privacy_option
+      :hide_notification_contents
     ])
   end
 
index 91bb1ba88ff359456749f95b1cdea69995fa9877..71d402b186a0d18e3a0d8fb10b16f40e696d27a5 100644 (file)
@@ -58,7 +58,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
             type: :object,
             properties: %{
               block_from_strangers: %Schema{type: :boolean},
-              privacy_option: %Schema{type: :boolean}
+              hide_notification_contents: %Schema{type: :boolean}
             }
           },
           relationship: AccountRelationship,
@@ -121,7 +121,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
         "tags" => [],
         "notification_settings" => %{
           "block_from_strangers" => false,
-          "privacy_option" => false
+          "hide_notification_contents" => false
         },
         "relationship" => %{
           "blocked_by" => false,
index cdb827e7664820f7d08088ad489a7e7f21a033ef..16368485e57d1028e241c8302c103d942cc99123 100644 (file)
@@ -104,7 +104,7 @@ defmodule Pleroma.Web.Push.Impl do
 
   def build_content(
         %{
-          user: %{notification_settings: %{privacy_option: true}}
+          user: %{notification_settings: %{hide_notification_contents: true}}
         } = notification,
         _actor,
         _object,
diff --git a/priv/repo/migrations/20200626163359_rename_notification_privacy_option.exs b/priv/repo/migrations/20200626163359_rename_notification_privacy_option.exs
new file mode 100644 (file)
index 0000000..06d7f72
--- /dev/null
@@ -0,0 +1,19 @@
+defmodule Pleroma.Repo.Migrations.RenameNotificationPrivacyOption do
+  use Ecto.Migration
+
+  def up do
+    execute(
+      "UPDATE users SET notification_settings = notification_settings - 'privacy_option' || jsonb_build_object('hide_notification_contents', notification_settings->'privacy_option')
+where notification_settings ? 'privacy_option'
+and local"
+    )
+  end
+
+  def down do
+    execute(
+      "UPDATE users SET notification_settings = notification_settings - 'hide_notification_contents' || jsonb_build_object('privacy_option', notification_settings->'hide_notification_contents')
+where notification_settings ? 'hide_notification_contents'
+and local"
+    )
+  end
+end
index 95bca22c41229042337c141e172475429a4ebf98..308da216a3a0fd97f1188751658df31bc2dc34af 100644 (file)
@@ -8,11 +8,11 @@ defmodule Pleroma.User.NotificationSettingTest do
   alias Pleroma.User.NotificationSetting
 
   describe "changeset/2" do
-    test "sets valid privacy option" do
+    test "sets option to hide notification contents" do
       changeset =
         NotificationSetting.changeset(
           %NotificationSetting{},
-          %{"privacy_option" => true}
+          %{"hide_notification_contents" => true}
         )
 
       assert %Ecto.Changeset{valid?: true} = changeset
index b6d820b3fdf97786dee87101a0e4cba36cef500c..ce45cb9e93767c554f40d10aeeea6ec7d2a2d661 100644 (file)
@@ -97,7 +97,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
 
     notification_settings = %{
       block_from_strangers: false,
-      privacy_option: false
+      hide_notification_contents: false
     }
 
     privacy = user.default_scope
index b48952b29026ffde4f12e2017736d4875ea69063..15de5e85351757269e5622f3d719b3bbab2200c8 100644 (file)
@@ -238,9 +238,9 @@ defmodule Pleroma.Web.Push.ImplTest do
              }
     end
 
-    test "hides details for notifications when privacy option enabled" do
+    test "hides contents of notifications when option enabled" do
       user = insert(:user, nickname: "Bob")
-      user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: true})
+      user2 = insert(:user, nickname: "Rob", notification_settings: %{hide_notification_contents: true})
 
       {:ok, activity} =
         CommonAPI.post(user, %{
@@ -284,9 +284,9 @@ defmodule Pleroma.Web.Push.ImplTest do
              }
     end
 
-    test "returns regular content for notifications with privacy option disabled" do
+    test "returns regular content when hiding contents option disabled" do
       user = insert(:user, nickname: "Bob")
-      user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: false})
+      user2 = insert(:user, nickname: "Rob", notification_settings: %{hide_notification_contents: false})
 
       {:ok, activity} =
         CommonAPI.post(user, %{
index da3f6fa61ef633c36e0ae72ec457f0d88aa92f6a..b8ddadb50462303dcbad1934bc50a6100e4eb383 100644 (file)
@@ -200,20 +200,20 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
 
       assert %Pleroma.User.NotificationSetting{
                block_from_strangers: true,
-               privacy_option: false
+               hide_notification_contents: false
              } == user.notification_settings
     end
 
-    test "it updates notification privacy option", %{user: user, conn: conn} do
+    test "it updates notification settings to enable hiding contents", %{user: user, conn: conn} do
       conn
-      |> put("/api/pleroma/notification_settings", %{"privacy_option" => "1"})
+      |> put("/api/pleroma/notification_settings", %{"hide_notification_contents" => "1"})
       |> json_response(:ok)
 
       user = refresh_record(user)
 
       assert %Pleroma.User.NotificationSetting{
                block_from_strangers: false,
-               privacy_option: true
+               hide_notification_contents: true
              } == user.notification_settings
     end
   end