Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
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
kaniini
pleroma
Commits
bed0b398
Commit
bed0b398
authored
7 years ago
by
lain
Browse files
Options
Downloads
Patches
Plain Diff
Add function to fetch users from fqn.
parent
eb12a89d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pleroma/user.ex
+12
-0
12 additions, 0 deletions
lib/pleroma/user.ex
test/user_test.exs
+20
-0
20 additions, 0 deletions
test/user_test.exs
with
32 additions
and
0 deletions
lib/pleroma/user.ex
+
12
−
0
View file @
bed0b398
...
...
@@ -3,6 +3,7 @@ defmodule Pleroma.User do
import
Ecto
.
Changeset
import
Ecto
.
Query
alias
Pleroma
.
{
Repo
,
User
,
Activity
,
Object
}
alias
Pleroma
.
Web
.
OStatus
schema
"users"
do
field
:bio
,
:string
...
...
@@ -131,4 +132,15 @@ defmodule Pleroma.User do
key
=
"user_info:
#{
user
.
id
}
"
Cachex
.
get!
(
:user_cache
,
key
,
fallback:
fn
(
_
)
->
user_info
(
user
)
end
)
end
def
get_or_fetch_by_nickname
(
nickname
)
do
with
%
User
{}
=
user
<-
get_by_nickname
(
nickname
)
do
user
else
_e
->
with
{
:ok
,
user
}
<-
OStatus
.
make_user
(
nickname
)
do
user
else
_e
->
nil
end
end
end
end
This diff is collapsed.
Click to expand it.
test/user_test.exs
+
20
−
0
View file @
bed0b398
...
...
@@ -86,4 +86,24 @@ defmodule Pleroma.UserTest do
assert
changeset
.
changes
[
:following
]
==
[
User
.
ap_followers
(%
User
{
nickname:
@full_user_data
.
nickname
})]
end
end
describe
"fetching a user from nickname or trying to build one"
do
test
"gets an existing user"
do
user
=
insert
(
:user
)
fetched_user
=
User
.
get_or_fetch_by_nickname
(
user
.
nickname
)
assert
user
==
fetched_user
end
test
"fetches an external user via ostatus if no user exists"
do
fetched_user
=
User
.
get_or_fetch_by_nickname
(
"shp@social.heldscal.la"
)
assert
fetched_user
.
nickname
==
"shp@social.heldscal.la"
end
test
"returns nil if no user could be fetched"
do
fetched_user
=
User
.
get_or_fetch_by_nickname
(
"nonexistant@social.heldscal.la"
)
assert
fetched_user
==
nil
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