Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
pleroma
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Steven Fuchs
pleroma
Commits
7bf269fe
Commit
7bf269fe
authored
Sep 14, 2020
by
Haelwenn
Committed by
rinpatch
Sep 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix MRF reject for ChatMessage
parent
abf25e5d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
5 deletions
+30
-5
lib/pleroma/web/api_spec/operations/chat_operation.ex
lib/pleroma/web/api_spec/operations/chat_operation.ex
+2
-1
lib/pleroma/web/api_spec/operations/status_operation.ex
lib/pleroma/web/api_spec/operations/status_operation.ex
+1
-1
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/common_api/common_api.ex
+3
-0
lib/pleroma/web/pleroma_api/controllers/chat_controller.ex
lib/pleroma/web/pleroma_api/controllers/chat_controller.ex
+10
-0
test/web/common_api/common_api_test.exs
test/web/common_api/common_api_test.exs
+11
-0
test/web/pleroma_api/controllers/chat_controller_test.exs
test/web/pleroma_api/controllers/chat_controller_test.exs
+3
-3
No files found.
lib/pleroma/web/api_spec/operations/chat_operation.ex
View file @
7bf269fe
...
@@ -184,7 +184,8 @@ def post_chat_message_operation do
...
@@ -184,7 +184,8 @@ def post_chat_message_operation do
"application/json"
,
"application/json"
,
ChatMessage
ChatMessage
),
),
400
=>
Operation
.
response
(
"Bad Request"
,
"application/json"
,
ApiError
)
400
=>
Operation
.
response
(
"Bad Request"
,
"application/json"
,
ApiError
),
422
=>
Operation
.
response
(
"MRF Rejection"
,
"application/json"
,
ApiError
)
},
},
security:
[
security:
[
%{
%{
...
...
lib/pleroma/web/api_spec/operations/status_operation.ex
View file @
7bf269fe
...
@@ -55,7 +55,7 @@ def create_operation do
...
@@ -55,7 +55,7 @@ def create_operation do
"application/json"
,
"application/json"
,
%
Schema
{
oneOf:
[
Status
,
ScheduledStatus
]}
%
Schema
{
oneOf:
[
Status
,
ScheduledStatus
]}
),
),
422
=>
Operation
.
response
(
"Bad Request"
,
"application/json"
,
ApiError
)
422
=>
Operation
.
response
(
"Bad Request
/ MRF Rejection
"
,
"application/json"
,
ApiError
)
}
}
}
}
end
end
...
...
lib/pleroma/web/common_api/common_api.ex
View file @
7bf269fe
...
@@ -48,6 +48,9 @@ def post_chat_message(%User{} = user, %User{} = recipient, content, opts \\ [])
...
@@ -48,6 +48,9 @@ def post_chat_message(%User{} = user, %User{} = recipient, content, opts \\ [])
local:
true
local:
true
)}
do
)}
do
{
:ok
,
activity
}
{
:ok
,
activity
}
else
{
:common_pipeline
,
{
:reject
,
_
}
=
e
}
->
e
e
->
e
end
end
end
end
...
...
lib/pleroma/web/pleroma_api/controllers/chat_controller.ex
View file @
7bf269fe
...
@@ -90,6 +90,16 @@ def post_chat_message(
...
@@ -90,6 +90,16 @@ def post_chat_message(
conn
conn
|>
put_view
(
MessageReferenceView
)
|>
put_view
(
MessageReferenceView
)
|>
render
(
"show.json"
,
chat_message_reference:
cm_ref
)
|>
render
(
"show.json"
,
chat_message_reference:
cm_ref
)
else
{
:reject
,
message
}
->
conn
|>
put_status
(
:unprocessable_entity
)
|>
json
(%{
error:
message
})
{
:error
,
message
}
->
conn
|>
put_status
(
:bad_request
)
|>
json
(%{
error:
message
})
end
end
end
end
...
...
test/web/common_api/common_api_test.exs
View file @
7bf269fe
...
@@ -217,6 +217,17 @@ test "it reject messages over the local limit" do
...
@@ -217,6 +217,17 @@ test "it reject messages over the local limit" do
assert
message
==
:content_too_long
assert
message
==
:content_too_long
end
end
test
"it reject messages via MRF"
do
clear_config
([
:mrf_keyword
,
:reject
],
[
"GNO"
])
clear_config
([
:mrf
,
:policies
],
[
Pleroma
.
Web
.
ActivityPub
.
MRF
.
KeywordPolicy
])
author
=
insert
(
:user
)
recipient
=
insert
(
:user
)
assert
{
:reject
,
"[KeywordPolicy] Matches with rejected keyword"
}
==
CommonAPI
.
post_chat_message
(
author
,
recipient
,
"GNO/Linux"
)
end
end
end
describe
"unblocking"
do
describe
"unblocking"
do
...
...
test/web/pleroma_api/controllers/chat_controller_test.exs
View file @
7bf269fe
...
@@ -100,7 +100,7 @@ test "it fails if there is no content", %{conn: conn, user: user} do
...
@@ -100,7 +100,7 @@ test "it fails if there is no content", %{conn: conn, user: user} do
|>
post
(
"/api/v1/pleroma/chats/
#{
chat
.
id
}
/messages"
)
|>
post
(
"/api/v1/pleroma/chats/
#{
chat
.
id
}
/messages"
)
|>
json_response_and_validate_schema
(
400
)
|>
json_response_and_validate_schema
(
400
)
assert
result
assert
%{
"error"
=>
"no_content"
}
==
result
end
end
test
"it works with an attachment"
,
%{
conn:
conn
,
user:
user
}
do
test
"it works with an attachment"
,
%{
conn:
conn
,
user:
user
}
do
...
@@ -139,9 +139,9 @@ test "gets MRF reason when rejected", %{conn: conn, user: user} do
...
@@ -139,9 +139,9 @@ test "gets MRF reason when rejected", %{conn: conn, user: user} do
conn
conn
|>
put_req_header
(
"content-type"
,
"application/json"
)
|>
put_req_header
(
"content-type"
,
"application/json"
)
|>
post
(
"/api/v1/pleroma/chats/
#{
chat
.
id
}
/messages"
,
%{
"content"
=>
"GNO/Linux"
})
|>
post
(
"/api/v1/pleroma/chats/
#{
chat
.
id
}
/messages"
,
%{
"content"
=>
"GNO/Linux"
})
|>
json_response_and_validate_schema
(
200
)
|>
json_response_and_validate_schema
(
422
)
assert
result
==
%{}
assert
%{
"error"
=>
"[KeywordPolicy] Matches with rejected keyword"
}
==
result
end
end
end
end
...
...
Write
Preview
Markdown
is supported
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