Skip to content
GitLab
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
98795172
Commit
98795172
authored
Nov 17, 2018
by
kaniini
Browse files
ostatus controller: respond with AS2 objects instead of activities to notice URIs
parent
d73c7cc0
Pipeline
#4552
passed with stages
in 7 minutes and 38 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/ostatus/ostatus_controller.ex
View file @
98795172
defmodule
Pleroma
.
Web
.
OStatus
.
OStatusController
do
use
Pleroma
.
Web
,
:controller
alias
Pleroma
.
{
User
,
Activity
}
alias
Pleroma
.
{
User
,
Activity
,
Object
}
alias
Pleroma
.
Web
.
OStatus
.
{
FeedRepresenter
,
ActivityRepresenter
}
alias
Pleroma
.
Repo
alias
Pleroma
.
Web
.
{
OStatus
,
Federator
}
...
...
@@ -153,10 +153,21 @@ def notice(conn, %{"id" => id}) do
end
end
defp
represent_activity
(
conn
,
"activity+json"
,
activity
,
user
)
do
defp
represent_activity
(
conn
,
"activity+json"
,
%
Activity
{
data:
%{
"type"
=>
"Create"
}}
=
activity
,
user
)
do
object
=
Object
.
normalize
(
activity
.
data
[
"object"
])
conn
|>
put_resp_header
(
"content-type"
,
"application/activity+json"
)
|>
json
(
ObjectView
.
render
(
"object.json"
,
%{
object:
activity
}))
|>
json
(
ObjectView
.
render
(
"object.json"
,
%{
object:
object
}))
end
defp
represent_activity
(
conn
,
"activity+json"
,
_
,
_
)
do
{
:error
,
:not_found
}
end
defp
represent_activity
(
conn
,
_
,
activity
,
user
)
do
...
...
test/web/ostatus/ostatus_controller_test.exs
View file @
98795172
...
...
@@ -2,6 +2,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use
Pleroma
.
Web
.
ConnCase
import
Pleroma
.
Factory
alias
Pleroma
.
{
User
,
Repo
}
alias
Pleroma
.
Web
.
CommonAPI
alias
Pleroma
.
Web
.
OStatus
.
ActivityRepresenter
test
"decodes a salmon"
,
%{
conn:
conn
}
do
...
...
@@ -167,6 +168,32 @@ test "gets a notice in AS2 format", %{conn: conn} do
assert
json_response
(
conn
,
200
)
end
test
"only gets a notice in AS2 format for Create messages"
,
%{
conn:
conn
}
do
note_activity
=
insert
(
:note_activity
)
url
=
"/notice/
#{
note_activity
.
id
}
"
conn
=
conn
|>
put_req_header
(
"accept"
,
"application/activity+json"
)
|>
get
(
url
)
assert
json_response
(
conn
,
200
)
user
=
insert
(
:user
)
{
:ok
,
like_activity
,
_
}
=
CommonAPI
.
favorite
(
note_activity
.
id
,
user
)
url
=
"/notice/
#{
like_activity
.
id
}
"
assert
like_activity
.
data
[
"type"
]
==
"Like"
conn
=
build_conn
()
|>
put_req_header
(
"accept"
,
"application/activity+json"
)
|>
get
(
url
)
assert
response
(
conn
,
404
)
end
test
"gets an activity in AS2 format"
,
%{
conn:
conn
}
do
note_activity
=
insert
(
:note_activity
)
[
_
,
uuid
]
=
hd
(
Regex
.
scan
(
~r/.+\/
([\
w
-
]
+
)
$
/
,
note_activity
.
data
[
"id"
]))
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment