From 057da2dd9c54448744318eb71b46d9f3cb5952bd Mon Sep 17 00:00:00 2001 From: Sergey Suprunenko Date: Sun, 12 Jul 2020 23:15:33 +0200 Subject: [PATCH] Add `show_attachment_filenames` field to users --- CHANGELOG.md | 1 + lib/pleroma/user.ex | 2 ++ lib/pleroma/web/admin_api/views/account_view.ex | 1 + .../web/api_spec/operations/account_operation.ex | 6 ++++++ lib/pleroma/web/api_spec/operations/media_operation.ex | 1 + lib/pleroma/web/api_spec/schemas/account.ex | 2 ++ lib/pleroma/web/api_spec/schemas/attachment.ex | 6 +++++- lib/pleroma/web/api_spec/schemas/chat.ex | 1 + lib/pleroma/web/api_spec/schemas/status.ex | 1 + .../web/mastodon_api/controllers/account_controller.ex | 1 + lib/pleroma/web/mastodon_api/views/account_view.ex | 1 + ...210146_add_attachment_filename_setting_to_users.exs | 9 +++++++++ .../web/mastodon_api/update_credentials_test.exs | 10 ++++++++++ .../web/mastodon_api/views/account_view_test.exs | 5 ++++- 14 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20200712210146_add_attachment_filename_setting_to_users.exs diff --git a/CHANGELOG.md b/CHANGELOG.md index 109a1ed48..0776e85b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -273,6 +273,7 @@ switched to a new configuration mechanism, however it was not officially removed - Mastodon API: Support irreversible property for filters. - Mastodon API: Add pleroma.favicon field to accounts. - Mastodon API: Add `filename` parameter to `POST /api/v1/media` and `POST /api/v2/media`. +- Mastodon API: Add account setting for providing filename to post attachments - Admin API: endpoints for create/update/delete OAuth Apps. - Admin API: endpoint for status view. - OTP: Add command to reload emoji packs diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index bcd5256c8..073f537be 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -138,6 +138,7 @@ defmodule Pleroma.User do field(:is_discoverable, :boolean, default: false) field(:invisible, :boolean, default: false) field(:allow_following_move, :boolean, default: true) + field(:show_attachment_filenames, :boolean, default: false) field(:skip_thread_containment, :boolean, default: false) field(:actor_type, :string, default: "Person") field(:also_known_as, {:array, :string}, default: []) @@ -503,6 +504,7 @@ def update_changeset(struct, params \\ %{}) do :allow_following_move, :background, :show_role, + :show_attachment_filenames, :skip_thread_containment, :fields, :raw_fields, diff --git a/lib/pleroma/web/admin_api/views/account_view.ex b/lib/pleroma/web/admin_api/views/account_view.ex index 8bac24d3e..7f86c001d 100644 --- a/lib/pleroma/web/admin_api/views/account_view.ex +++ b/lib/pleroma/web/admin_api/views/account_view.ex @@ -48,6 +48,7 @@ def render("credentials.json", %{user: user, for: for_user}) do :hide_followers, :hide_favorites, :allow_following_move, + :show_attachment_filenames, :show_role, :skip_thread_containment, :pleroma_settings_store, diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index 280100c3d..0f04721b0 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -604,6 +604,11 @@ defp update_credentials_request do nullable: true, description: "Opaque user settings to be saved on the backend." }, + show_attachment_filenames: %Schema{ + allOf: [BooleanLike], + nullable: true, + description: "Show the attachment filenames" + }, skip_thread_containment: %Schema{ allOf: [BooleanLike], nullable: true, @@ -642,6 +647,7 @@ defp update_credentials_request do show_role: false, default_scope: "private", pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}}, + show_attachment_filenames: false, skip_thread_containment: false, allow_following_move: false, discoverable: false, diff --git a/lib/pleroma/web/api_spec/operations/media_operation.ex b/lib/pleroma/web/api_spec/operations/media_operation.ex index cfd436f27..4c1496dd7 100644 --- a/lib/pleroma/web/api_spec/operations/media_operation.ex +++ b/lib/pleroma/web/api_spec/operations/media_operation.ex @@ -48,6 +48,7 @@ defp create_request do }, filename: %Schema{ type: :string, + nullable: true, description: "Filename of the media." }, focus: %Schema{ diff --git a/lib/pleroma/web/api_spec/schemas/account.ex b/lib/pleroma/web/api_spec/schemas/account.ex index 684f6fc92..996d15303 100644 --- a/lib/pleroma/web/api_spec/schemas/account.ex +++ b/lib/pleroma/web/api_spec/schemas/account.ex @@ -76,6 +76,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do type: :boolean, description: "whether the user is a moderator of the local instance" }, + show_attachment_filenames: %Schema{type: :boolean}, skip_thread_containment: %Schema{type: :boolean}, tags: %Schema{ type: :array, @@ -172,6 +173,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do "hide_follows_count" => false, "is_admin" => false, "is_moderator" => false, + "show_attachment_filenames" => false, "skip_thread_containment" => false, "accepts_chat_messages" => true, "chat_token" => diff --git a/lib/pleroma/web/api_spec/schemas/attachment.ex b/lib/pleroma/web/api_spec/schemas/attachment.ex index c2984546a..5695abf71 100644 --- a/lib/pleroma/web/api_spec/schemas/attachment.ex +++ b/lib/pleroma/web/api_spec/schemas/attachment.ex @@ -51,7 +51,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Attachment do type: :object, properties: %{ mime_type: %Schema{type: :string, description: "mime type of the attachment"}, - filename: %Schema{type: :string, description: "filename of the attachment"} + filename: %Schema{ + type: :string, + nullable: true, + description: "filename of the attachment" + } } } }, diff --git a/lib/pleroma/web/api_spec/schemas/chat.ex b/lib/pleroma/web/api_spec/schemas/chat.ex index 65f908e33..b50d4f7e7 100644 --- a/lib/pleroma/web/api_spec/schemas/chat.ex +++ b/lib/pleroma/web/api_spec/schemas/chat.ex @@ -31,6 +31,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Chat do "hide_follows_count" => false, "hide_follows" => false, "background_image" => nil, + "show_attachment_filenames" => false, "skip_thread_containment" => false, "hide_followers" => false, "relationship" => %{}, diff --git a/lib/pleroma/web/api_spec/schemas/status.ex b/lib/pleroma/web/api_spec/schemas/status.ex index e6890df2d..d7665c043 100644 --- a/lib/pleroma/web/api_spec/schemas/status.ex +++ b/lib/pleroma/web/api_spec/schemas/status.ex @@ -278,6 +278,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do "showing_reblogs" => true, "subscribing" => false }, + "show_attachment_filenames" => false, "skip_thread_containment" => false, "tags" => [] }, diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index 7011b7eb1..0bc37fff4 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -182,6 +182,7 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p :hide_followers, :hide_follows, :hide_favorites, + :show_attachment_filenames, :show_role, :skip_thread_containment, :allow_following_move, diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 3158d09ed..9e5d087e3 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -277,6 +277,7 @@ defp do_render("show.json", %{user: user} = opts) do hide_follows: user.hide_follows, hide_favorites: user.hide_favorites, relationship: relationship, + show_attachment_filenames: user.show_attachment_filenames, skip_thread_containment: user.skip_thread_containment, background_image: image_url(user.background) |> MediaProxy.url(), accepts_chat_messages: user.accepts_chat_messages, diff --git a/priv/repo/migrations/20200712210146_add_attachment_filename_setting_to_users.exs b/priv/repo/migrations/20200712210146_add_attachment_filename_setting_to_users.exs new file mode 100644 index 000000000..ba657f742 --- /dev/null +++ b/priv/repo/migrations/20200712210146_add_attachment_filename_setting_to_users.exs @@ -0,0 +1,9 @@ +defmodule Pleroma.Repo.Migrations.AddAttachmentFilenameSettingToUsers do + use Ecto.Migration + + def change do + alter table(:users) do + add(:show_attachment_filenames, :boolean, default: false) + end + end +end diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index ed1921c91..58bab9f46 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -180,6 +180,16 @@ test "updates the user's skip_thread_containment option", %{user: user, conn: co assert refresh_record(user).skip_thread_containment end + test "updates the user's show_attachment_filenames option", %{user: user, conn: conn} do + response = + conn + |> patch("/api/v1/accounts/update_credentials", %{show_attachment_filenames: "true"}) + |> json_response_and_validate_schema(200) + + assert response["pleroma"]["show_attachment_filenames"] + assert refresh_record(user).show_attachment_filenames + end + test "updates the user's hide_follows status", %{conn: conn} do conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_follows: "true"}) diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs index 139e32362..46938aec5 100644 --- a/test/pleroma/web/mastodon_api/views/account_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs @@ -35,7 +35,8 @@ test "Represent a user account" do "valid html. a
b
c
d
f '&<>\"", inserted_at: ~N[2017-08-15 15:47:06.597036], emoji: %{"karjalanpiirakka" => "/file.png"}, - raw_bio: "valid html. a\nb\nc\nd\nf '&<>\"" + raw_bio: "valid html. a\nb\nc\nd\nf '&<>\"", + show_attachment_filenames: true }) expected = %{ @@ -87,6 +88,7 @@ test "Represent a user account" do hide_followers_count: false, hide_follows_count: false, relationship: %{}, + show_attachment_filenames: true, skip_thread_containment: false, accepts_chat_messages: nil } @@ -185,6 +187,7 @@ test "Represent a Service(bot) account" do hide_followers_count: false, hide_follows_count: false, relationship: %{}, + show_attachment_filenames: false, skip_thread_containment: false, accepts_chat_messages: nil }