Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alex Gleason
pleroma
Commits
a19f8778
Commit
a19f8778
authored
4 years ago
by
lain
Browse files
Options
Downloads
Patches
Plain Diff
User preloader: Put user info at correct key
parent
a2002ebb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pleroma/web/preload/user.ex
+6
-5
6 additions, 5 deletions
lib/pleroma/web/preload/user.ex
test/web/preload/user_test.exs
+7
-7
7 additions, 7 deletions
test/web/preload/user_test.exs
with
13 additions
and
12 deletions
lib/pleroma/web/preload/user.ex
+
6
−
5
View file @
a19f8778
...
...
@@ -3,11 +3,12 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma
.
Web
.
Preload
.
Providers
.
User
do
alias
Pleroma
.
User
alias
Pleroma
.
Web
.
MastodonAPI
.
AccountView
alias
Pleroma
.
Web
.
Preload
.
Providers
.
Provider
@behaviour
Provider
@account_url
:"/api/v1/accounts"
@account_url
_base
:"/api/v1/accounts"
@impl
Provider
def
generate_terms
(%{
user:
user
})
do
...
...
@@ -16,10 +17,10 @@ def generate_terms(%{user: user}) do
def
generate_terms
(
_params
),
do
:
%{}
def
build_accounts_tag
(
acc
,
nil
),
do
:
acc
def
build_accounts_tag
(
acc
,
user
)
do
def
build_accounts_tag
(
acc
,
%
User
{}
=
user
)
do
account_data
=
AccountView
.
render
(
"show.json"
,
%{
user:
user
,
for:
user
})
Map
.
put
(
acc
,
@account_url
,
account_data
)
Map
.
put
(
acc
,
:"
#{
@account_url
_base
}
/
#{
user
.
id
}
"
,
account_data
)
end
def
build_accounts_tag
(
acc
,
_
),
do
:
acc
end
This diff is collapsed.
Click to expand it.
test/web/preload/user_test.exs
+
7
−
7
View file @
a19f8778
...
...
@@ -9,13 +9,11 @@ defmodule Pleroma.Web.Preload.Providers.UserTest do
describe
"returns empty when user doesn't exist"
do
test
"nil user specified"
do
refute
User
.
generate_terms
(%{
user:
nil
})
|>
Map
.
has_key?
(
"/api/v1/accounts"
)
assert
User
.
generate_terms
(%{
user:
nil
})
==
%{}
end
test
"missing user specified"
do
refute
User
.
generate_terms
(%{
user:
:not_a_user
})
|>
Map
.
has_key?
(
"/api/v1/accounts"
)
assert
User
.
generate_terms
(%{
user:
:not_a_user
})
==
%{}
end
end
...
...
@@ -23,11 +21,13 @@ test "missing user specified" do
setup
do
user
=
insert
(
:user
)
{
:ok
,
User
.
generate_terms
(%{
user:
user
})}
terms
=
User
.
generate_terms
(%{
user:
user
})
%{
terms:
terms
,
user:
user
}
end
test
"account is rendered"
,
%{
"/api/v1/accounts"
:
accounts
}
do
assert
%{
acct:
user
,
username:
user
}
=
accounts
test
"account is rendered"
,
%{
terms:
terms
,
user:
user
}
do
account
=
terms
[
:"/api/v1/accounts/
#{
user
.
id
}
"
]
assert
%{
acct:
user
,
username:
user
}
=
account
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment