forked from AkkomaGang/akkoma
Merge branch 'fix/nickname-fail' into 'develop'
Fix get_cached_by_nickname_or_id not allowing to get local users by nickname Closes #1293 See merge request pleroma/pleroma!1777
This commit is contained in:
commit
27e914955e
3 changed files with 59 additions and 1 deletions
|
@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
### Fixed
|
||||
- Mastodon API: Fix private and direct statuses not being filtered out from the public timeline for an authenticated user (`GET /api/v1/timelines/public`)
|
||||
- Mastodon API: Inability to get some local users by nickname in `/api/v1/accounts/:id_or_nickname`
|
||||
|
||||
## [1.1.0] - 2019-??-??
|
||||
### Security
|
||||
|
|
|
@ -583,7 +583,7 @@ def get_cached_by_nickname_or_id(nickname_or_id, opts \\ []) do
|
|||
is_integer(nickname_or_id) or FlakeId.flake_id?(nickname_or_id) ->
|
||||
get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id)
|
||||
|
||||
restrict_to_local == false ->
|
||||
restrict_to_local == false or not String.contains?(nickname_or_id, "@") ->
|
||||
get_cached_by_nickname(nickname_or_id)
|
||||
|
||||
restrict_to_local == :unauthenticated and match?(%User{}, opts[:for]) ->
|
||||
|
|
|
@ -1725,4 +1725,61 @@ test "update_info/2" do
|
|||
assert %{info: %{hide_follows: true}} = Repo.get(User, user.id)
|
||||
assert {:ok, %{info: %{hide_follows: true}}} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
|
||||
end
|
||||
|
||||
describe "get_cached_by_nickname_or_id" do
|
||||
setup do
|
||||
limit_to_local_content = Pleroma.Config.get([:instance, :limit_to_local_content])
|
||||
local_user = insert(:user)
|
||||
remote_user = insert(:user, nickname: "nickname@example.com", local: false)
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local_content)
|
||||
end)
|
||||
|
||||
[local_user: local_user, remote_user: remote_user]
|
||||
end
|
||||
|
||||
test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{
|
||||
remote_user: remote_user
|
||||
} do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], false)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
|
||||
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], true)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
|
||||
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
|
||||
end
|
||||
|
||||
test "disallows getting remote users by nickname without authentication when :limit_to_local_content is set to :unauthenticated",
|
||||
%{remote_user: remote_user} do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
|
||||
end
|
||||
|
||||
test "allows getting remote users by nickname with authentication when :limit_to_local_content is set to :unauthenticated",
|
||||
%{remote_user: remote_user, local_user: local_user} do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(remote_user.nickname, for: local_user)
|
||||
end
|
||||
|
||||
test "disallows getting remote users by nickname when :limit_to_local_content is set to true",
|
||||
%{remote_user: remote_user} do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], true)
|
||||
assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
|
||||
end
|
||||
|
||||
test "allows getting local users by nickname no matter what :limit_to_local_content is set to",
|
||||
%{local_user: local_user} do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], false)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
|
||||
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], true)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
|
||||
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue