|> Enum.each(fn user ->
shell_info(
"#{user.nickname} moderator: #{user.is_moderator}, admin: #{user.is_admin}, locked: #{
- user.locked
+ user.is_locked
}, deactivated: #{user.deactivated}"
)
end)
defp set_locked(user, value) do
{:ok, user} =
user
- |> Changeset.change(%{locked: value})
+ |> Changeset.change(%{is_locked: value})
|> User.update_and_set_cache()
- shell_info("Locked status of #{user.nickname}: #{user.locked}")
+ shell_info("Locked status of #{user.nickname}: #{user.is_locked}")
user
end
field(:note_count, :integer, default: 0)
field(:follower_count, :integer, default: 0)
field(:following_count, :integer, default: 0)
- field(:locked, :boolean, default: false)
+ field(:is_locked, :boolean, default: false)
field(:confirmation_pending, :boolean, default: false)
field(:password_reset_pending, :boolean, default: false)
field(:approval_pending, :boolean, default: false)
:avatar,
:ap_enabled,
:banner,
- :locked,
+ :is_locked,
:last_refreshed_at,
:uri,
:follower_address,
:public_key,
:inbox,
:shared_inbox,
- :locked,
+ :is_locked,
:no_rich_text,
:default_scope,
:banner,
@spec maybe_direct_follow(User.t(), User.t()) :: {:ok, User.t()} | {:error, String.t()}
# "Locked" (self-locked) users demand explicit authorization of follow requests
- def maybe_direct_follow(%User{} = follower, %User{local: true, locked: true} = followed) do
+ def maybe_direct_follow(%User{} = follower, %User{local: true, is_locked: true} = followed) do
follow(follower, followed, :follow_pending)
end
end
def locked?(%User{} = user) do
- user.locked || false
+ user.is_locked || false
end
def get_by_id(id) do
note_count: 0,
follower_count: 0,
following_count: 0,
- locked: false,
+ is_locked: false,
confirmation_pending: false,
password_reset_pending: false,
approval_pending: false,
{String.trim(name, ":"), url}
end)
- locked = data["manuallyApprovesFollowers"] || false
+ is_locked = data["manuallyApprovesFollowers"] || false
capabilities = data["capabilities"] || %{}
accepts_chat_messages = capabilities["acceptsChatMessages"]
data = Transmogrifier.maybe_fix_user_object(data)
banner: banner,
fields: fields,
emoji: emojis,
- locked: locked,
+ is_locked: is_locked,
discoverable: discoverable,
invisible: invisible,
avatar: avatar,
%User{} = followed <- User.get_cached_by_ap_id(followed_user),
{_, {:ok, _}, _, _} <-
{:following, User.follow(follower, followed, :follow_pending), follower, followed} do
- if followed.local && !followed.locked do
+ if followed.local && !followed.is_locked do
{:ok, accept_data, _} = Builder.accept(followed, object)
{:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true)
end
"name" => user.name,
"summary" => user.bio,
"url" => user.ap_id,
- "manuallyApprovesFollowers" => user.locked,
+ "manuallyApprovesFollowers" => user.is_locked,
"publicKey" => %{
"id" => "#{user.ap_id}#main-key",
"owner" => user.ap_id,
:fields,
:name,
:nickname,
- :locked,
+ :is_locked,
:no_rich_text,
:default_scope,
:hide_follows,
description: "Header image encoded using multipart/form-data",
format: :binary
},
- locked: %Schema{
+ is_locked: %Schema{
allOf: [BooleanLike],
nullable: true,
description: "Whether manual approval of follow requests is required."
"fields" => []
},
"statuses_count" => 1,
- "locked" => false,
+ "is_locked" => false,
"created_at" => "2020-04-16T13:40:15.000Z",
"display_name" => "lain",
"fields" => [],
header_static: %Schema{type: :string, format: :uri},
header: %Schema{type: :string, format: :uri},
id: FlakeID,
- locked: %Schema{type: :boolean},
+ is_locked: %Schema{type: :boolean},
note: %Schema{type: :string, format: :html},
statuses_count: %Schema{type: :integer},
url: %Schema{type: :string, format: :uri},
"header" => "https://mypleroma.com/images/banner.png",
"header_static" => "https://mypleroma.com/images/banner.png",
"id" => "9tKi3esbG7OQgZ2920",
- "locked" => false,
+ "is_locked" => false,
"note" => "cofe",
"pleroma" => %{
"allow_following_move" => true,
"fields" => []
},
"statuses_count" => 1,
- "locked" => false,
+ "is_locked" => false,
"created_at" => "2020-04-16T13:40:15.000Z",
"display_name" => "lain",
"fields" => [],
"header" => "http://localhost:4001/images/banner.png",
"header_static" => "http://localhost:4001/images/banner.png",
"id" => "9toJCsKN7SmSf3aj5c",
- "locked" => false,
+ "is_locked" => false,
"note" => "Tester Number 6",
"pleroma" => %{
"background_image" => nil,
user_params =
[
:no_rich_text,
- :locked,
+ :is_locked,
:hide_followers_count,
:hide_follows_count,
:hide_followers,
username: username_from_nickname(user.nickname),
acct: user.nickname,
display_name: display_name,
- locked: user.locked,
+ is_locked: user.is_locked,
created_at: Utils.to_masto_date(user.inserted_at),
followers_count: followers_count,
following_count: following_count,
--- /dev/null
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Repo.Migrations.RefactorLockedUserField do
+ use Ecto.Migration
+
+ def up do
+ execute("ALTER TABLE users RENAME COLUMN locked TO is_locked;")
+ end
+
+ def down do
+ execute("ALTER TABLE users RENAME COLUMN is_locked TO locked;")
+ end
+end
describe "follow / follow_request notifications" do
test "it creates `follow` notification for approved Follow activity" do
user = insert(:user)
- followed_user = insert(:user, locked: false)
+ followed_user = insert(:user, is_locked: false)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
assert FollowingRelationship.following?(user, followed_user)
test "it creates `follow_request` notification for pending Follow activity" do
user = insert(:user)
- followed_user = insert(:user, locked: true)
+ followed_user = insert(:user, is_locked: true)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
refute FollowingRelationship.following?(user, followed_user)
test "it doesn't create a notification for follow-unfollow-follow chains" do
user = insert(:user)
- followed_user = insert(:user, locked: false)
+ followed_user = insert(:user, is_locked: false)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
assert FollowingRelationship.following?(user, followed_user)
end
test "dismisses the notification on follow request rejection" do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
follower = insert(:user)
{:ok, _, _, _follow_activity} = CommonAPI.follow(follower, user)
assert [notification] = Notification.for_user(user)
user = User.get_cached_by_nickname(user.nickname)
assert user.is_moderator
- assert user.locked
+ assert user.is_locked
assert user.is_admin
refute user.confirmation_pending
end
test "All statuses unset" do
user =
- insert(:user, locked: true, is_moderator: true, is_admin: true, confirmation_pending: true)
+ insert(:user, is_locked: true, is_moderator: true, is_admin: true, confirmation_pending: true)
Mix.Tasks.Pleroma.User.run([
"set",
user = User.get_cached_by_nickname(user.nickname)
refute user.is_moderator
- refute user.locked
+ refute user.is_locked
refute user.is_admin
assert user.confirmation_pending
end
test "returns all pending follow requests" do
unlocked = insert(:user)
- locked = insert(:user, locked: true)
+ locked = insert(:user, is_locked: true)
follower = insert(:user)
CommonAPI.follow(follower, unlocked)
end
test "doesn't return already accepted or duplicate follow requests" do
- locked = insert(:user, locked: true)
+ locked = insert(:user, is_locked: true)
pending_follower = insert(:user)
accepted_follower = insert(:user)
end
test "doesn't return follow requests for deactivated accounts" do
- locked = insert(:user, locked: true)
+ locked = insert(:user, is_locked: true)
pending_follower = insert(:user, %{deactivated: true})
CommonAPI.follow(pending_follower, locked)
end
test "clears follow requests when requester is blocked" do
- followed = insert(:user, locked: true)
+ followed = insert(:user, is_locked: true)
follower = insert(:user)
CommonAPI.follow(follower, followed)
end
test "local users do not automatically follow local locked accounts" do
- follower = insert(:user, locked: true)
- followed = insert(:user, locked: true)
+ follower = insert(:user, is_locked: true)
+ followed = insert(:user, is_locked: true)
{:ok, follower} = User.maybe_direct_follow(follower, followed)
follower = insert(:user)
{:ok, follower} = User.follow(follower, user)
- locked_user = insert(:user, name: "locked", locked: true)
+ locked_user = insert(:user, name: "locked", is_locked: true)
{:ok, _} = User.follow(user, locked_user, :follow_pending)
object = insert(:note, user: user)
note_count: 9,
follower_count: 9,
following_count: 9001,
- locked: true,
+ is_locked: true,
confirmation_pending: true,
password_reset_pending: true,
approval_pending: true,
note_count: 0,
follower_count: 0,
following_count: 0,
- locked: false,
+ is_locked: false,
confirmation_pending: false,
password_reset_pending: false,
approval_pending: false,
test "creates an undo activity for a pending follow request" do
follower = insert(:user)
- followed = insert(:user, %{locked: true})
+ followed = insert(:user, %{is_locked: true})
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
{:ok, activity} = ActivityPub.unfollow(follower, followed)
test "it works for incoming accepts which are referenced by IRI only" do
follower = insert(:user)
- followed = insert(:user, locked: true)
+ followed = insert(:user, is_locked: true)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
test "it fails for incoming accepts which cannot be correlated" do
follower = insert(:user)
- followed = insert(:user, locked: true)
+ followed = insert(:user, is_locked: true)
accept_data =
File.read!("test/fixtures/mastodon-accept-activity.json")
end
test "with locked accounts, it does create a Follow, but not an Accept" do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
data =
File.read!("test/fixtures/mastodon-follow-activity.json")
test "it works for incoming follows to locked account" do
pending_follower = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
data =
File.read!("test/fixtures/mastodon-follow-activity.json")
test "it fails for incoming rejects which cannot be correlated" do
follower = insert(:user)
- followed = insert(:user, locked: true)
+ followed = insert(:user, is_locked: true)
accept_data =
File.read!("test/fixtures/mastodon-reject-activity.json")
test "it works for incoming rejects which are referenced by IRI only" do
follower = insert(:user)
- followed = insert(:user, locked: true)
+ followed = insert(:user, is_locked: true)
{:ok, follower} = User.follow(follower, followed)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(update_data)
user = User.get_cached_by_ap_id(user.ap_id)
- assert user.locked == true
+ assert user.is_locked == true
end
end
describe "update_follow_state_for_all/2" do
test "updates the state of all Follow activities with the same actor and object" do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
follower = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user)
describe "update_follow_state/2" do
test "updates the state of the given follow activity" do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
follower = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user)
test "cancels a pending follow for a local user" do
follower = insert(:user)
- followed = insert(:user, locked: true)
+ followed = insert(:user, is_locked: true)
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
CommonAPI.follow(follower, followed)
test "cancels a pending follow for a remote user" do
follower = insert(:user)
- followed = insert(:user, locked: true, local: false, ap_enabled: true)
+ followed = insert(:user, is_locked: true, local: false, ap_enabled: true)
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
CommonAPI.follow(follower, followed)
describe "accept_follow_request/2" do
test "after acceptance, it sets all existing pending follow request states to 'accept'" do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
follower = insert(:user)
follower_two = insert(:user)
end
test "after rejection, it sets all existing pending follow request states to 'reject'" do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
follower = insert(:user)
follower_two = insert(:user)
end
test "doesn't create a following relationship if the corresponding follow request doesn't exist" do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
not_follower = insert(:user)
CommonAPI.accept_follow_request(not_follower, user)
end
test "updates the user's locking status", %{conn: conn} do
- conn = patch(conn, "/api/v1/accounts/update_credentials", %{locked: "true"})
+ conn = patch(conn, "/api/v1/accounts/update_credentials", %{is_locked: "true"})
assert user_data = json_response_and_validate_schema(conn, 200)
assert user_data["locked"] == true
end
test "cancelling follow request", %{conn: conn} do
- %{id: other_user_id} = insert(:user, %{locked: true})
+ %{id: other_user_id} = insert(:user, %{is_locked: true})
assert %{"id" => ^other_user_id, "following" => false, "requested" => true} =
conn
describe "locked accounts" do
setup do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
%{conn: conn} = oauth_access(["follow"], user: user)
%{user: user, conn: conn}
end
username: "shp",
acct: user.nickname,
display_name: user.name,
- locked: false,
+ is_locked: false,
created_at: "2017-08-15T15:47:06.000Z",
followers_count: 3,
following_count: 0,
username: "shp",
acct: user.nickname,
display_name: user.name,
- locked: false,
+ is_locked: false,
created_at: "2017-08-15T15:47:06.000Z",
followers_count: 3,
following_count: 0,
test "represent a relationship for the user with a pending follow request" do
user = insert(:user)
- other_user = insert(:user, locked: true)
+ other_user = insert(:user, is_locked: true)
{:ok, user, other_user, _} = CommonAPI.follow(user, other_user)
user = User.get_cached_by_id(user.id)
end
test "shows non-zero when follow requests are pending" do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
- assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
+ assert %{is_locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
- assert %{locked: true, follow_requests_count: 1} =
+ assert %{is_locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user})
end
test "decreases when accepting a follow request" do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
- assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
+ assert %{is_locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user)
{:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
- assert %{locked: true, follow_requests_count: 1} =
+ assert %{is_locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user})
{:ok, _other_user} = CommonAPI.accept_follow_request(other_user, user)
- assert %{locked: true, follow_requests_count: 0} =
+ assert %{is_locked: true, follow_requests_count: 0} =
AccountView.render("show.json", %{user: user, for: user})
end
test "decreases when rejecting a follow request" do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
- assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
+ assert %{is_locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user)
{:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
- assert %{locked: true, follow_requests_count: 1} =
+ assert %{is_locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user})
{:ok, _other_user} = CommonAPI.reject_follow_request(other_user, user)
- assert %{locked: true, follow_requests_count: 0} =
+ assert %{is_locked: true, follow_requests_count: 0} =
AccountView.render("show.json", %{user: user, for: user})
end
test "shows non-zero when historical unapproved requests are present" do
- user = insert(:user, locked: true)
+ user = insert(:user, is_locked: true)
- assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
+ assert %{is_locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
- {:ok, user} = User.update_and_set_cache(user, %{locked: false})
+ {:ok, user} = User.update_and_set_cache(user, %{is_locked: false})
- assert %{locked: false, follow_requests_count: 1} =
+ assert %{is_locked: false, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user})
end
end