* 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`
@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
"""
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
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
)
]
]
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
type: :object,
properties: %{
block_from_strangers: %Schema{type: :boolean},
- privacy_option: %Schema{type: :boolean}
+ hide_notification_contents: %Schema{type: :boolean}
}
},
relationship: AccountRelationship,
"tags" => [],
"notification_settings" => %{
"block_from_strangers" => false,
- "privacy_option" => false
+ "hide_notification_contents" => false
},
"relationship" => %{
"blocked_by" => false,
def build_content(
%{
- user: %{notification_settings: %{privacy_option: true}}
+ user: %{notification_settings: %{hide_notification_contents: true}}
} = notification,
_actor,
_object,
--- /dev/null
+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
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
notification_settings = %{
block_from_strangers: false,
- privacy_option: false
+ hide_notification_contents: false
}
privacy = user.default_scope
}
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, %{
}
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, %{
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