From: rinpatch Date: Wed, 17 Jun 2020 10:34:23 +0000 (+0000) Subject: Merge branch 'features/users-raw_bio' into 'develop' X-Git-Url: http://git.squeep.com/?a=commitdiff_plain;h=4ec2fb967e0eb0559e39a6d698107f6af4d7a891;hp=-c;p=akkoma Merge branch 'features/users-raw_bio' into 'develop' User: Add raw_bio, storing unformatted bio See merge request pleroma/pleroma!2326 --- 4ec2fb967e0eb0559e39a6d698107f6af4d7a891 diff --combined lib/pleroma/user.ex index 52ac9052b,23ca8c9f3..ff3ec1197 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@@ -79,6 -79,7 +79,7 @@@ defmodule Pleroma.User d schema "users" do field(:bio, :string) + field(:raw_bio, :string) field(:email, :string) field(:name, :string) field(:nickname, :string) @@@ -432,6 -433,7 +433,7 @@@ params, [ :bio, + :raw_bio, :name, :emoji, :avatar, @@@ -607,7 -609,16 +609,16 @@@ struct |> confirmation_changeset(need_confirmation: need_confirmation?) - |> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation, :emoji]) + |> cast(params, [ + :bio, + :raw_bio, + :email, + :name, + :nickname, + :password, + :password_confirmation, + :emoji + ]) |> validate_required([:name, :nickname, :password, :password_confirmation]) |> validate_confirmation(:password) |> unique_constraint(:email) @@@ -1488,9 -1499,6 +1499,9 @@@ end) delete_user_activities(user) + delete_notifications_from_user_activities(user) + + delete_outgoing_pending_follow_requests(user) delete_or_deactivate(user) end @@@ -1577,13 -1585,6 +1588,13 @@@ }) end + def delete_notifications_from_user_activities(%User{ap_id: ap_id}) do + Notification + |> join(:inner, [n], activity in assoc(n, :activity)) + |> where([n, a], fragment("? = ?", a.actor, ^ap_id)) + |> Repo.delete_all() + end + def delete_user_activities(%User{ap_id: ap_id} = user) do ap_id |> Activity.Queries.by_actor() @@@ -1621,12 -1622,6 +1632,12 @@@ defp delete_activity(_activity, _user), do: "Doing nothing" + defp delete_outgoing_pending_follow_requests(user) do + user + |> FollowingRelationship.outgoing_pending_follow_requests_query() + |> Repo.delete_all() + end + def html_filter_policy(%User{no_rich_text: true}) do Pleroma.HTML.Scrubber.TwitterText end diff --combined lib/pleroma/web/mastodon_api/controllers/account_controller.ex index 7cdd8f458,ebfa533dd..c38c2b895 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@@ -165,6 -165,7 +165,7 @@@ defmodule Pleroma.Web.MastodonAPI.Accou end) |> Maps.put_if_present(:name, params[:display_name]) |> Maps.put_if_present(:bio, params[:note]) + |> Maps.put_if_present(:raw_bio, params[:note]) |> Maps.put_if_present(:avatar, params[:avatar]) |> Maps.put_if_present(:banner, params[:header]) |> Maps.put_if_present(:background, params[:pleroma_background_image]) @@@ -244,7 -245,9 +245,7 @@@ params = params |> Map.delete(:tagged) - |> Enum.filter(&(not is_nil(&1))) - |> Map.new(fn {key, value} -> {to_string(key), value} end) - |> Map.put("tag", params[:tagged]) + |> Map.put(:tag, params[:tagged]) activities = ActivityPub.fetch_user_activities(user, reading_user, params) diff --combined lib/pleroma/web/mastodon_api/views/account_view.ex index 9fc06bf9d,5326b02c6..68beb69b8 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@@ -224,7 -224,7 +224,7 @@@ defmodule Pleroma.Web.MastodonAPI.Accou fields: user.fields, bot: bot, source: %{ - note: prepare_user_bio(user), + note: user.raw_bio || "", sensitive: false, fields: user.raw_fields, pleroma: %{ @@@ -235,7 -235,6 +235,7 @@@ # Pleroma extension pleroma: %{ + ap_id: user.ap_id, confirmation_pending: user.confirmation_pending, tags: user.tags, hide_followers_count: user.hide_followers_count, @@@ -260,17 -259,6 +260,6 @@@ |> maybe_put_unread_notification_count(user, opts[:for]) end - defp prepare_user_bio(%User{bio: ""}), do: "" - - defp prepare_user_bio(%User{bio: bio}) when is_binary(bio) do - bio - |> String.replace(~r(
), "\n") - |> Pleroma.HTML.strip_tags() - |> HtmlEntities.decode() - end - - defp prepare_user_bio(_), do: "" - defp username_from_nickname(string) when is_binary(string) do hd(String.split(string, "@")) end diff --combined test/support/factory.ex index e517d5bc6,1a9b96180..6e22b66a4 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@@ -42,7 -42,8 +42,8 @@@ defmodule Pleroma.Factory d user | ap_id: User.ap_id(user), follower_address: User.ap_followers(user), - following_address: User.ap_following(user) + following_address: User.ap_following(user), + raw_bio: user.bio } end @@@ -396,17 -397,24 +397,17 @@@ } end - def config_factory do + def config_factory(attrs \\ %{}) do %Pleroma.ConfigDB{ - key: - sequence(:key, fn key -> - # Atom dynamic registration hack in tests - "some_key_#{key}" - |> String.to_atom() - |> inspect() - end), - group: ":pleroma", + key: sequence(:key, &String.to_atom("some_key_#{&1}")), + group: :pleroma, value: sequence( :value, - fn key -> - :erlang.term_to_binary(%{another_key: "#{key}somevalue", another: "#{key}somevalue"}) - end + &%{another_key: "#{&1}somevalue", another: "#{&1}somevalue"} ) } + |> merge_attributes(attrs) end def marker_factory do diff --combined test/web/mastodon_api/views/account_view_test.exs index 044f088a4,7ac70dc58..80b1f734c --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@@ -33,7 -33,8 +33,8 @@@ defmodule Pleroma.Web.MastodonAPI.Accou bio: "valid html. a
b
c
d
f '&<>\"", inserted_at: ~N[2017-08-15 15:47:06.597036], - emoji: %{"karjalanpiirakka" => "/file.png"} + emoji: %{"karjalanpiirakka" => "/file.png"}, + raw_bio: "valid html. a\nb\nc\nd\nf '&<>\"" }) expected = %{ @@@ -72,7 -73,6 +73,7 @@@ fields: [] }, pleroma: %{ + ap_id: user.ap_id, background_image: "https://example.com/images/asuka_hospital.png", confirmation_pending: false, tags: [], @@@ -149,7 -149,6 +150,7 @@@ fields: [] }, pleroma: %{ + ap_id: user.ap_id, background_image: nil, confirmation_pending: false, tags: [],