Merge branch 'profile-location' into 'develop'
Support account "location" field Closes #67 See merge request soapbox-pub/soapbox-be!110
This commit is contained in:
commit
b0b8c89b9a
15 changed files with 76 additions and 8 deletions
|
@ -234,6 +234,7 @@
|
|||
limit_to_local_content: :unauthenticated,
|
||||
user_bio_length: 5000,
|
||||
user_name_length: 100,
|
||||
user_location_length: 50,
|
||||
max_account_fields: 10,
|
||||
max_remote_account_fields: 20,
|
||||
account_field_name_length: 512,
|
||||
|
|
|
@ -824,6 +824,14 @@
|
|||
100
|
||||
]
|
||||
},
|
||||
%{
|
||||
key: :user_location_length,
|
||||
type: :integer,
|
||||
description: "A user location maximum length. Default: 50.",
|
||||
suggestions: [
|
||||
50
|
||||
]
|
||||
},
|
||||
%{
|
||||
key: :skip_thread_containment,
|
||||
type: :boolean,
|
||||
|
|
|
@ -53,6 +53,7 @@ To add configuration to your config file, you can copy it from the base config.
|
|||
* `remote_post_retention_days`: The default amount of days to retain remote posts when pruning the database.
|
||||
* `user_bio_length`: A user bio maximum length (default: `5000`).
|
||||
* `user_name_length`: A user name maximum length (default: `100`).
|
||||
* `user_name_length`: A user location maximum length (default: `50`).
|
||||
* `skip_thread_containment`: Skip filter out broken threads. The default is `false`.
|
||||
* `limit_to_local_content`: Limit unauthenticated users to search for local statutes and users only. Possible values: `:unauthenticated`, `:all` and `false`. The default is `:unauthenticated`.
|
||||
* `max_account_fields`: The maximum number of custom fields in the user profile (default: `10`).
|
||||
|
|
|
@ -157,6 +157,7 @@ defmodule Pleroma.User do
|
|||
field(:last_status_at, :naive_datetime)
|
||||
field(:birthday, :date)
|
||||
field(:show_birthday, :boolean, default: false)
|
||||
field(:location, :string)
|
||||
|
||||
embeds_one(
|
||||
:notification_settings,
|
||||
|
@ -425,6 +426,7 @@ defp fix_follower_address(params), do: params
|
|||
def remote_user_changeset(struct \\ %User{local: false}, params) do
|
||||
bio_limit = Config.get([:instance, :user_bio_length], 5000)
|
||||
name_limit = Config.get([:instance, :user_name_length], 100)
|
||||
location_limit = Config.get([:instance, :user_location_length], 50)
|
||||
|
||||
name =
|
||||
case params[:name] do
|
||||
|
@ -475,7 +477,8 @@ def remote_user_changeset(struct \\ %User{local: false}, params) do
|
|||
:accepts_chat_messages,
|
||||
:pinned_objects,
|
||||
:birthday,
|
||||
:show_birthday
|
||||
:show_birthday,
|
||||
:location
|
||||
]
|
||||
)
|
||||
|> cast(params, [:name], empty_values: [])
|
||||
|
@ -485,6 +488,7 @@ def remote_user_changeset(struct \\ %User{local: false}, params) do
|
|||
|> validate_format(:nickname, @email_regex)
|
||||
|> validate_length(:bio, max: bio_limit)
|
||||
|> validate_length(:name, max: name_limit)
|
||||
|> validate_length(:location, max: location_limit)
|
||||
|> validate_fields(true)
|
||||
|> validate_non_local()
|
||||
end
|
||||
|
@ -503,6 +507,7 @@ defp validate_non_local(cng) do
|
|||
def update_changeset(struct, params \\ %{}) do
|
||||
bio_limit = Config.get([:instance, :user_bio_length], 5000)
|
||||
name_limit = Config.get([:instance, :user_name_length], 100)
|
||||
location_limit = Config.get([:instance, :user_location_length], 50)
|
||||
|
||||
struct
|
||||
|> cast(
|
||||
|
@ -539,13 +544,15 @@ def update_changeset(struct, params \\ %{}) do
|
|||
:disclose_client,
|
||||
:accepts_email_list,
|
||||
:birthday,
|
||||
:show_birthday
|
||||
:show_birthday,
|
||||
:location
|
||||
]
|
||||
)
|
||||
|> validate_min_age()
|
||||
|> unique_constraint(:nickname)
|
||||
|> validate_format(:nickname, local_nickname_regex())
|
||||
|> validate_length(:bio, max: bio_limit)
|
||||
|> validate_length(:location, max: location_limit)
|
||||
|> validate_length(:name, min: 1, max: name_limit)
|
||||
|> validate_inclusion(:actor_type, ["Person", "Service"])
|
||||
|> put_fields()
|
||||
|
|
|
@ -1549,7 +1549,8 @@ defp object_to_user_data(data) do
|
|||
accepts_chat_messages: accepts_chat_messages,
|
||||
pinned_objects: pinned_objects,
|
||||
birthday: birthday,
|
||||
show_birthday: show_birthday
|
||||
show_birthday: show_birthday,
|
||||
location: data["vcard:Address"] || ""
|
||||
}
|
||||
|
||||
# nickname can be nil because of virtual actors
|
||||
|
|
|
@ -122,7 +122,8 @@ def render("user.json", %{user: user}) do
|
|||
"discoverable" => user.is_discoverable,
|
||||
"capabilities" => capabilities,
|
||||
"alsoKnownAs" => user.also_known_as,
|
||||
"vcard:bday" => birthday
|
||||
"vcard:bday" => birthday,
|
||||
"vcard:Address" => user.location
|
||||
}
|
||||
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
|
||||
|> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
|
||||
|
|
|
@ -747,6 +747,11 @@ defp update_credentials_request do
|
|||
allOf: [BooleanLike],
|
||||
nullable: true,
|
||||
description: "User's birthday will be visible"
|
||||
},
|
||||
location: %Schema{
|
||||
type: :string,
|
||||
nullable: true,
|
||||
description: "User location"
|
||||
}
|
||||
},
|
||||
example: %{
|
||||
|
|
|
@ -55,6 +55,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
|
|||
"whether the user account is waiting on email confirmation to be activated"
|
||||
},
|
||||
show_birthday: %Schema{type: :boolean, nullable: true},
|
||||
location: %Schema{type: :string, nullable: true},
|
||||
hide_favorites: %Schema{type: :boolean},
|
||||
hide_followers_count: %Schema{
|
||||
type: :boolean,
|
||||
|
|
|
@ -222,6 +222,7 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p
|
|||
# Note: param name is indeed :discoverable (not an error)
|
||||
|> Maps.put_if_present(:is_discoverable, params[:discoverable])
|
||||
|> Maps.put_if_present(:birthday, params[:birthday])
|
||||
|> Maps.put_if_present(:location, params[:location])
|
||||
|
||||
# What happens here:
|
||||
#
|
||||
|
|
|
@ -297,7 +297,8 @@ defp do_render("show.json", %{user: user} = opts) do
|
|||
skip_thread_containment: user.skip_thread_containment,
|
||||
background_image: image_url(user.background) |> MediaProxy.url(),
|
||||
accepts_chat_messages: user.accepts_chat_messages,
|
||||
favicon: favicon
|
||||
favicon: favicon,
|
||||
location: user.location
|
||||
}
|
||||
}
|
||||
|> maybe_put_role(user, opts[:for])
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
defmodule Pleroma.Repo.Migrations.AddLocationToUsers do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:users) do
|
||||
add_if_not_exists(:location, :string)
|
||||
end
|
||||
end
|
||||
end
|
2
test/fixtures/birthdays/misskey-user.json
vendored
2
test/fixtures/birthdays/misskey-user.json
vendored
|
@ -1 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","Hashtag":"as:Hashtag","quoteUrl":"as:quoteUrl","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","featured":"toot:featured","discoverable":"toot:discoverable","schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value","misskey":"https://misskey.io/ns#","_misskey_content":"misskey:_misskey_content","_misskey_quote":"misskey:_misskey_quote","_misskey_reaction":"misskey:_misskey_reaction","_misskey_votes":"misskey:_misskey_votes","_misskey_talk":"misskey:_misskey_talk","isCat":"misskey:isCat","vcard":"http://www.w3.org/2006/vcard/ns#"}],"type":"Person","id":"https://misskey.io/users/8dhi2ne167","inbox":"https://misskey.io/users/8dhi2ne167/inbox","outbox":"https://misskey.io/users/8dhi2ne167/outbox","followers":"https://misskey.io/users/8dhi2ne167/followers","following":"https://misskey.io/users/8dhi2ne167/following","sharedInbox":"https://misskey.io/inbox","endpoints":{"sharedInbox":"https://misskey.io/inbox"},"url":"https://misskey.io/@mkljczk","preferredUsername":"mkljczk","name":null,"summary":null,"icon":null,"image":null,"tag":[],"manuallyApprovesFollowers":false,"discoverable":true,"publicKey":{"id":"https://misskey.io/users/8dhi2ne167#main-key","type":"Key","owner":"https://misskey.io/users/8dhi2ne167","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA7CI3Ol1M0TDdLL+E8Uhd\nJ8l/RTEtxl39MKxsqSCZr9itf/EBn4dGTifK9LN3XZD2fjmX4hdwaxndp2HYVDqn\ndc6O57u8dHxFv9wTwXQrLzEonOzbrBec6WB42ZpkFHi4XEyqg8iYGu5Yy7ttXJ21\nOfWqi+eytttcTErKuu4z8MX1L1IlmpfSmH1trMyDZLFMRqVJ0416/qI0K3l3cmIf\n8cuWbJ57UxVbYxp9242der/3vrNIU24rAouYQYe1atUgFPKil3w8dCY7magy36Wg\nOXC1hdRsFcsVW54/3cSQ9fc/+1HIg16/zlS+AWb4dVDhrAUJLYIBrkMPRnu/cDuI\ndvyL+KtZUxhDBoSO0JLrd1+GZGt0WD+mfutCugJS8IGlWQmGq8WRmM2vYfZgEYkq\nCv4392VSsWvg4iluKz0eX+8l7QKHseJwGBvk89Txlz6f7QkooBXYuuyHZS1ZLZBW\nfooK+RNAquDU+cVUu1gVt1V5yt3IxF1qvMRtlElNJKN5NUJT9/K2YcVX6UoMXhDd\noSOpARqPm9E2pdjI62pAOBbCplMSoBprhoCYm0iozf9QhNyUBGWDcTsFDDgqOwy4\nYjGQ5jsnCrkhSzRkTViWD+Pgw+Ar4fxcjySGUf0x7HkNfteDPSdLMD8J2vTJXfoB\nGAQQmGMZmFgONC62FrDphlsCAwEAAQ==\n-----END PUBLIC KEY-----\n"},"isCat":true,"vcard:bday":"2001-02-12"}
|
||||
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","Hashtag":"as:Hashtag","quoteUrl":"as:quoteUrl","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","featured":"toot:featured","discoverable":"toot:discoverable","schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value","misskey":"https://misskey.io/ns#","_misskey_content":"misskey:_misskey_content","_misskey_quote":"misskey:_misskey_quote","_misskey_reaction":"misskey:_misskey_reaction","_misskey_votes":"misskey:_misskey_votes","_misskey_talk":"misskey:_misskey_talk","isCat":"misskey:isCat","vcard":"http://www.w3.org/2006/vcard/ns#"}],"type":"Person","id":"https://misskey.io/users/8dhi2ne167","inbox":"https://misskey.io/users/8dhi2ne167/inbox","outbox":"https://misskey.io/users/8dhi2ne167/outbox","followers":"https://misskey.io/users/8dhi2ne167/followers","following":"https://misskey.io/users/8dhi2ne167/following","sharedInbox":"https://misskey.io/inbox","endpoints":{"sharedInbox":"https://misskey.io/inbox"},"url":"https://misskey.io/@mkljczk","preferredUsername":"mkljczk","name":null,"summary":null,"icon":null,"image":null,"tag":[],"manuallyApprovesFollowers":false,"discoverable":true,"publicKey":{"id":"https://misskey.io/users/8dhi2ne167#main-key","type":"Key","owner":"https://misskey.io/users/8dhi2ne167","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA7CI3Ol1M0TDdLL+E8Uhd\nJ8l/RTEtxl39MKxsqSCZr9itf/EBn4dGTifK9LN3XZD2fjmX4hdwaxndp2HYVDqn\ndc6O57u8dHxFv9wTwXQrLzEonOzbrBec6WB42ZpkFHi4XEyqg8iYGu5Yy7ttXJ21\nOfWqi+eytttcTErKuu4z8MX1L1IlmpfSmH1trMyDZLFMRqVJ0416/qI0K3l3cmIf\n8cuWbJ57UxVbYxp9242der/3vrNIU24rAouYQYe1atUgFPKil3w8dCY7magy36Wg\nOXC1hdRsFcsVW54/3cSQ9fc/+1HIg16/zlS+AWb4dVDhrAUJLYIBrkMPRnu/cDuI\ndvyL+KtZUxhDBoSO0JLrd1+GZGt0WD+mfutCugJS8IGlWQmGq8WRmM2vYfZgEYkq\nCv4392VSsWvg4iluKz0eX+8l7QKHseJwGBvk89Txlz6f7QkooBXYuuyHZS1ZLZBW\nfooK+RNAquDU+cVUu1gVt1V5yt3IxF1qvMRtlElNJKN5NUJT9/K2YcVX6UoMXhDd\noSOpARqPm9E2pdjI62pAOBbCplMSoBprhoCYm0iozf9QhNyUBGWDcTsFDDgqOwy4\nYjGQ5jsnCrkhSzRkTViWD+Pgw+Ar4fxcjySGUf0x7HkNfteDPSdLMD8J2vTJXfoB\nGAQQmGMZmFgONC62FrDphlsCAwEAAQ==\n-----END PUBLIC KEY-----\n"},"isCat":true,"vcard:bday":"2001-02-12","vcard:Address":"Poland"}
|
|
@ -409,6 +409,26 @@ test "fetches user birthday information from misskey" do
|
|||
|
||||
assert user.birthday == ~D[2001-02-12]
|
||||
end
|
||||
|
||||
test "fetches user location information from misskey" do
|
||||
user_id = "https://misskey.io/@mkljczk"
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: ^user_id
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/birthdays/misskey-user.json"),
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
|
||||
|
||||
assert user.location == "Poland"
|
||||
end
|
||||
end
|
||||
|
||||
test "it fetches the appropriate tag-restricted posts" do
|
||||
|
|
|
@ -397,6 +397,16 @@ test "updates the user's show_birthday status", %{conn: conn} do
|
|||
assert user_data["source"]["pleroma"]["show_birthday"] == true
|
||||
end
|
||||
|
||||
test "updates location", %{conn: conn} do
|
||||
res =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{
|
||||
"location" => "Pleroma, Fediverse"
|
||||
})
|
||||
|
||||
assert user_data = json_response_and_validate_schema(res, 200)
|
||||
assert user_data["pleroma"]["location"] == "Pleroma, Fediverse"
|
||||
end
|
||||
|
||||
test "emojis in fields labels", %{conn: conn} do
|
||||
fields = [
|
||||
%{"name" => ":firefox:", "value" => "is best 2hu"},
|
||||
|
|
|
@ -92,7 +92,8 @@ test "Represent a user account" do
|
|||
hide_follows_count: false,
|
||||
relationship: %{},
|
||||
skip_thread_containment: false,
|
||||
accepts_chat_messages: nil
|
||||
accepts_chat_messages: nil,
|
||||
location: nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,7 +195,8 @@ test "Represent a Service(bot) account" do
|
|||
hide_follows_count: false,
|
||||
relationship: %{},
|
||||
skip_thread_containment: false,
|
||||
accepts_chat_messages: nil
|
||||
accepts_chat_messages: nil,
|
||||
location: nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue