Merge branch 'develop' into features/remove-user-source_data
authorrinpatch <rinpatch@sdf.org>
Thu, 16 Apr 2020 18:28:52 +0000 (21:28 +0300)
committerrinpatch <rinpatch@sdf.org>
Thu, 16 Apr 2020 18:28:52 +0000 (21:28 +0300)
1  2 
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/mastodon_api/controllers/account_controller.ex
lib/pleroma/web/mastodon_api/views/account_view.ex
lib/pleroma/web/pleroma_api/controllers/account_controller.ex
test/user_test.exs
test/web/activity_pub/transmogrifier_test.exs
test/web/activity_pub/views/user_view_test.exs
test/web/common_api/common_api_test.exs

index d05dfb480e596ccce95df22e72470bac67feb344,d9410535bdd0aedcfe922c8afa11bb5812012c93..896bab14021b1a228f286b3d2ec44626c5989de0
@@@ -344,14 -339,7 +344,14 @@@ defmodule Pleroma.User d
      end
    end
  
-   def remote_user_creation(params) do
 +  defp fix_follower_address(%{follower_address: _, following_address: _} = params), do: params
 +
 +  defp fix_follower_address(%{nickname: nickname} = params),
 +    do: Map.put(params, :follower_address, ap_followers(%User{nickname: nickname}))
 +
 +  defp fix_follower_address(params), do: params
 +
+   def remote_user_changeset(struct \\ %User{local: false}, params) do
      bio_limit = Pleroma.Config.get([:instance, :user_bio_length], 5000)
      name_limit = Pleroma.Config.get([:instance, :user_name_length], 100)
  
        |> truncate_if_exists(:name, name_limit)
        |> truncate_if_exists(:bio, bio_limit)
        |> truncate_fields_param()
 +      |> fix_follower_address()
  
-     %User{local: false}
 -    changeset =
 -      struct
 -      |> cast(
 -        params,
 -        [
 -          :bio,
 -          :name,
 -          :ap_id,
 -          :nickname,
 -          :avatar,
 -          :ap_enabled,
 -          :source_data,
 -          :banner,
 -          :locked,
 -          :magic_key,
 -          :uri,
 -          :hide_followers,
 -          :hide_follows,
 -          :hide_followers_count,
 -          :hide_follows_count,
 -          :follower_count,
 -          :fields,
 -          :following_count,
 -          :discoverable,
 -          :invisible,
 -          :actor_type,
 -          :also_known_as,
 -          :last_refreshed_at
 -        ]
 -      )
 -      |> validate_required([:name, :ap_id])
 -      |> unique_constraint(:nickname)
 -      |> validate_format(:nickname, @email_regex)
 -      |> validate_length(:bio, max: bio_limit)
 -      |> validate_length(:name, max: name_limit)
 -      |> validate_fields(true)
 -
 -    case params[:source_data] do
 -      %{"followers" => followers, "following" => following} ->
 -        changeset
 -        |> put_change(:follower_address, followers)
 -        |> put_change(:following_address, following)
 -
 -      _ ->
 -        followers = ap_followers(%User{nickname: get_field(changeset, :nickname)})
 -        put_change(changeset, :follower_address, followers)
 -    end
++    struct
 +    |> cast(
 +      params,
 +      [
 +        :bio,
 +        :name,
 +        :emoji,
 +        :ap_id,
 +        :inbox,
 +        :shared_inbox,
 +        :nickname,
 +        :public_key,
 +        :avatar,
 +        :ap_enabled,
 +        :banner,
 +        :locked,
++        :last_refreshed_at,
 +        :magic_key,
 +        :uri,
 +        :follower_address,
 +        :following_address,
 +        :hide_followers,
 +        :hide_follows,
 +        :hide_followers_count,
 +        :hide_follows_count,
 +        :follower_count,
 +        :fields,
 +        :following_count,
 +        :discoverable,
 +        :invisible,
 +        :actor_type,
 +        :also_known_as
 +      ]
 +    )
 +    |> validate_required([:name, :ap_id])
 +    |> unique_constraint(:nickname)
 +    |> validate_format(:nickname, @email_regex)
 +    |> validate_length(:bio, max: bio_limit)
 +    |> validate_length(:name, max: name_limit)
 +    |> validate_fields(true)
    end
  
    def update_changeset(struct, params \\ %{}) do
Simple merge