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
0da1233e
Commit
0da1233e
authored
May 17, 2019
by
kaniini
Browse files
rich media: suppress link previews if post is marked as sensitive
parent
78588dbd
Pipeline
#11998
failed with stages
in 8 minutes and 30 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/rich_media/helpers.ex
View file @
0da1233e
...
...
@@ -24,6 +24,7 @@ defp validate_page_url(_), do: :error
def
fetch_data_for_activity
(%
Activity
{
data:
%{
"type"
=>
"Create"
}}
=
activity
)
do
with
true
<-
Pleroma
.
Config
.
get
([
:rich_media
,
:enabled
]),
%
Object
{}
=
object
<-
Object
.
normalize
(
activity
),
false
<-
object
.
data
[
"sensitive"
]
||
false
,
{
:ok
,
page_url
}
<-
HTML
.
extract_first_external_url
(
object
,
object
.
data
[
"content"
]),
:ok
<-
validate_page_url
(
page_url
),
{
:ok
,
rich_media
}
<-
Parser
.
parse
(
page_url
)
do
...
...
test/web/rich_media/helpers_test.exs
View file @
0da1233e
defmodule
Pleroma
.
Web
.
RichMedia
.
HelpersTest
do
use
Pleroma
.
DataCase
alias
Pleroma
.
Object
alias
Pleroma
.
Web
.
CommonAPI
import
Pleroma
.
Factory
...
...
@@ -59,4 +60,24 @@ test "crawls valid, complete URLs" do
Pleroma
.
Config
.
put
([
:rich_media
,
:enabled
],
false
)
end
test
"refuses to crawl URLs from posts marked sensitive"
do
user
=
insert
(
:user
)
{
:ok
,
activity
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"http://example.com/ogp"
,
"spoiler_text"
=>
"."
})
%
Object
{}
=
object
=
Object
.
normalize
(
activity
)
assert
object
.
data
[
"sensitive"
]
Pleroma
.
Config
.
put
([
:rich_media
,
:enabled
],
true
)
assert
%{}
=
Pleroma
.
Web
.
RichMedia
.
Helpers
.
fetch_data_for_activity
(
activity
)
Pleroma
.
Config
.
put
([
:rich_media
,
:enabled
],
false
)
end
end
feld
@feld
mentioned in issue
#2192 (closed)
·
Sep 28, 2020
mentioned in issue
#2192 (closed)
mentioned in issue #2192
Toggle commit list
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