Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
bed0b398
Commit
bed0b398
authored
Apr 30, 2017
by
lain
Browse files
Add function to fetch users from fqn.
parent
eb12a89d
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/user.ex
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 @@ def get_cached_user_info(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
test/user_test.exs
View file @
bed0b398
...
...
@@ -86,4 +86,24 @@ test "it sets the password_hash, ap_id and following fields" 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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment