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
88b82e5c
Commit
88b82e5c
authored
Apr 21, 2020
by
minibikini
Browse files
Fix follow import
parent
3c828016
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/twitter_api/controllers/util_controller.ex
View file @
88b82e5c
...
...
@@ -199,15 +199,16 @@ def follow_import(conn, %{"list" => %Plug.Upload{} = listfile}) do
end
def
follow_import
(%{
assigns:
%{
user:
follower
}}
=
conn
,
%{
"list"
=>
list
})
do
with
lines
<-
String
.
split
(
list
,
"
\n
"
),
followed_identifiers
<-
Enum
.
map
(
lines
,
fn
line
->
String
.
split
(
line
,
","
)
|>
List
.
first
()
end
)
|>
List
.
delete
(
"Account address"
)
do
User
.
follow_import
(
follower
,
followed_identifiers
)
json
(
conn
,
"job started"
)
end
followed_identifiers
=
list
|>
String
.
split
(
"
\n
"
)
|>
Enum
.
map
(
&
(
&1
|>
String
.
split
(
","
)
|>
List
.
first
()))
|>
List
.
delete
(
"Account address"
)
|>
Enum
.
map
(
&
(
&1
|>
String
.
trim
()
|>
String
.
trim_leading
(
"@"
)))
|>
Enum
.
reject
(
&
(
&1
==
""
))
User
.
follow_import
(
follower
,
followed_identifiers
)
json
(
conn
,
"job started"
)
end
def
blocks_import
(
conn
,
%{
"list"
=>
%
Plug
.
Upload
{}
=
listfile
})
do
...
...
@@ -215,10 +216,8 @@ def blocks_import(conn, %{"list" => %Plug.Upload{} = listfile}) do
end
def
blocks_import
(%{
assigns:
%{
user:
blocker
}}
=
conn
,
%{
"list"
=>
list
})
do
with
blocked_identifiers
<-
String
.
split
(
list
)
do
User
.
blocks_import
(
blocker
,
blocked_identifiers
)
json
(
conn
,
"job started"
)
end
User
.
blocks_import
(
blocker
,
_blocked_identifiers
=
String
.
split
(
list
))
json
(
conn
,
"job started"
)
end
def
change_password
(%{
assigns:
%{
user:
user
}}
=
conn
,
params
)
do
...
...
test/web/twitter_api/util_controller_test.exs
View file @
88b82e5c
...
...
@@ -95,6 +95,30 @@ test "requires 'follow' or 'write:follows' permissions" do
end
end
end
test
"it imports with different nickname variations"
,
%{
conn:
conn
}
do
[
user2
,
user3
,
user4
,
user5
,
user6
]
=
insert_list
(
5
,
:user
)
identifiers
=
[
user2
.
ap_id
,
user3
.
nickname
,
" "
,
"@"
<>
user4
.
nickname
,
user5
.
nickname
<>
"@localhost"
,
"@"
<>
user6
.
nickname
<>
"@localhost"
]
|>
Enum
.
join
(
"
\n
"
)
response
=
conn
|>
post
(
"/api/pleroma/follow_import"
,
%{
"list"
=>
identifiers
})
|>
json_response
(
:ok
)
assert
response
==
"job started"
assert
[
job_result
]
=
ObanHelpers
.
perform_all
()
assert
job_result
==
[
user2
,
user3
,
user4
,
user5
,
user6
]
end
end
describe
"POST /api/pleroma/blocks_import"
do
...
...
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