瀏覽代碼

User table: ensure bio is always a string

Gets rid of '|| ""' in multiple places and fixes #2067
message-debug-mode
rinpatch 3 年之前
父節點
當前提交
126461942b
共有 11 個檔案被更改,包括 27 行新增10 行删除
  1. +2
    -2
      lib/pleroma/user.ex
  2. +1
    -1
      lib/pleroma/web/activity_pub/activity_pub.ex
  3. +1
    -1
      lib/pleroma/web/auth/pleroma_authenticator.ex
  4. +1
    -1
      lib/pleroma/web/mastodon_api/views/account_view.ex
  5. +1
    -1
      lib/pleroma/web/metadata/opengraph.ex
  6. +1
    -1
      lib/pleroma/web/metadata/twitter_card.ex
  7. +7
    -0
      priv/repo/migrations/20200901061256_ensure_bio_is_string.exs
  8. +10
    -0
      priv/repo/migrations/20200901061637_bio_set_not_null.exs
  9. +1
    -1
      test/user_test.exs
  10. +1
    -1
      test/web/admin_api/controllers/admin_api_controller_test.exs
  11. +1
    -1
      test/web/twitter_api/util_controller_test.exs

+ 2
- 2
lib/pleroma/user.ex 查看文件

@@ -83,7 +83,7 @@ defmodule Pleroma.User do
]

schema "users" do
field(:bio, :string)
field(:bio, :string, default: "")
field(:raw_bio, :string)
field(:email, :string)
field(:name, :string)
@@ -1587,7 +1587,7 @@ defmodule Pleroma.User do
# "Right to be forgotten"
# https://gdpr.eu/right-to-be-forgotten/
change(user, %{
bio: nil,
bio: "",
raw_bio: nil,
email: nil,
name: nil,


+ 1
- 1
lib/pleroma/web/activity_pub/activity_pub.ex 查看文件

@@ -1224,7 +1224,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
name: data["name"],
follower_address: data["followers"],
following_address: data["following"],
bio: data["summary"],
bio: data["summary"] || "",
actor_type: actor_type,
also_known_as: Map.get(data, "alsoKnownAs", []),
public_key: public_key,


+ 1
- 1
lib/pleroma/web/auth/pleroma_authenticator.ex 查看文件

@@ -68,7 +68,7 @@ defmodule Pleroma.Web.Auth.PleromaAuthenticator do
nickname = value([registration_attrs["nickname"], Registration.nickname(registration)])
email = value([registration_attrs["email"], Registration.email(registration)])
name = value([registration_attrs["name"], Registration.name(registration)]) || nickname
bio = value([registration_attrs["bio"], Registration.description(registration)])
bio = value([registration_attrs["bio"], Registration.description(registration)]) || ""

random_password = :crypto.strong_rand_bytes(64) |> Base.encode64()



+ 1
- 1
lib/pleroma/web/mastodon_api/views/account_view.ex 查看文件

@@ -245,7 +245,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
followers_count: followers_count,
following_count: following_count,
statuses_count: user.note_count,
note: user.bio || "",
note: user.bio,
url: user.uri || user.ap_id,
avatar: image,
avatar_static: image,


+ 1
- 1
lib/pleroma/web/metadata/opengraph.ex 查看文件

@@ -61,7 +61,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do

@impl Provider
def build_tags(%{user: user}) do
with truncated_bio = Utils.scrub_html_and_truncate(user.bio || "") do
with truncated_bio = Utils.scrub_html_and_truncate(user.bio) do
[
{:meta,
[


+ 1
- 1
lib/pleroma/web/metadata/twitter_card.ex 查看文件

@@ -40,7 +40,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do

@impl Provider
def build_tags(%{user: user}) do
with truncated_bio = Utils.scrub_html_and_truncate(user.bio || "") do
with truncated_bio = Utils.scrub_html_and_truncate(user.bio) do
[
title_tag(user),
{:meta, [property: "twitter:description", content: truncated_bio], []},


+ 7
- 0
priv/repo/migrations/20200901061256_ensure_bio_is_string.exs 查看文件

@@ -0,0 +1,7 @@
defmodule Pleroma.Repo.Migrations.EnsureBioIsString do
use Ecto.Migration

def change do
execute("update users set bio = '' where bio is null", "")
end
end

+ 10
- 0
priv/repo/migrations/20200901061637_bio_set_not_null.exs 查看文件

@@ -0,0 +1,10 @@
defmodule Pleroma.Repo.Migrations.BioSetNotNull do
use Ecto.Migration

def change do
execute(
"alter table users alter column bio set not null",
"alter table users alter column bio drop not null"
)
end
end

+ 1
- 1
test/user_test.exs 查看文件

@@ -1466,7 +1466,7 @@ defmodule Pleroma.UserTest do
user = User.get_by_id(user.id)

assert %User{
bio: nil,
bio: "",
raw_bio: nil,
email: nil,
name: nil,


+ 1
- 1
test/web/admin_api/controllers/admin_api_controller_test.exs 查看文件

@@ -203,7 +203,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert user.note_count == 0
assert user.follower_count == 0
assert user.following_count == 0
assert user.bio == nil
assert user.bio == ""
assert user.name == nil

assert called(Pleroma.Web.Federator.publish(:_))


+ 1
- 1
test/web/twitter_api/util_controller_test.exs 查看文件

@@ -594,7 +594,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
user = User.get_by_id(user.id)
assert user.deactivated == true
assert user.name == nil
assert user.bio == nil
assert user.bio == ""
assert user.password_hash == nil
end
end


Loading…
取消
儲存