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
Hakaba Hitoyo
pleroma
Commits
074fa790
Commit
074fa790
authored
Dec 09, 2018
by
Maksim
Browse files
fix compile warnings
parent
cf85a9ae
Changes
53
Hide whitespace changes
Inline
Side-by-side
lib/mix/tasks/pleroma/common.ex
View file @
074fa790
defmodule
Mix
.
Tasks
.
Pleroma
.
Common
do
@
short
doc
"Common functions to be reused in mix tasks"
@doc
"Common functions to be reused in mix tasks"
def
start_pleroma
do
Mix
.
Task
.
run
(
"app.start"
)
end
...
...
lib/mix/tasks/pleroma/instance.ex
View file @
074fa790
defmodule
Mix
.
Tasks
.
Pleroma
.
Instance
do
use
Mix
.
Task
alias
Pleroma
.
{
Repo
,
User
}
alias
Mix
.
Tasks
.
Pleroma
.
Common
@shortdoc
"Manages Pleroma instance"
...
...
lib/mix/tasks/pleroma/relay.ex
View file @
074fa790
...
...
@@ -22,7 +22,7 @@ defmodule Mix.Tasks.Pleroma.Relay do
def
run
([
"follow"
,
target
])
do
Common
.
start_pleroma
()
with
{
:ok
,
activity
}
<-
Relay
.
follow
(
target
)
do
with
{
:ok
,
_
activity
}
<-
Relay
.
follow
(
target
)
do
# put this task to sleep to allow the genserver to push out the messages
:timer
.
sleep
(
500
)
else
...
...
@@ -33,7 +33,7 @@ def run(["follow", target]) do
def
run
([
"unfollow"
,
target
])
do
Common
.
start_pleroma
()
with
{
:ok
,
activity
}
<-
Relay
.
unfollow
(
target
)
do
with
{
:ok
,
_
activity
}
<-
Relay
.
unfollow
(
target
)
do
# put this task to sleep to allow the genserver to push out the messages
:timer
.
sleep
(
500
)
else
...
...
lib/mix/tasks/pleroma/uploads.ex
View file @
074fa790
defmodule
Mix
.
Tasks
.
Pleroma
.
Uploads
do
use
Mix
.
Task
import
Mix
.
Ecto
alias
Pleroma
.
{
Upload
,
Uploaders
.
Local
,
Uploaders
.
S3
}
alias
Pleroma
.
{
Upload
,
Uploaders
.
Local
}
alias
Mix
.
Tasks
.
Pleroma
.
Common
require
Logger
@log_every
50
@shortdoc
"Migrate uploads from local to remote storage"
@
long
doc
"""
@doc
"""
Manages uploads
## Migrate uploads from local to remote storage
"""
def
run
([
"migrate_local"
,
target_uploader
|
args
])
do
delete?
=
Enum
.
member?
(
args
,
"--delete"
)
Common
.
start_pleroma
()
...
...
@@ -59,7 +57,7 @@ def run(["migrate_local", target_uploader | args]) do
File
.
exists?
(
root_path
)
->
file
=
Path
.
basename
(
id
)
[
hash
,
ext
]
=
String
.
split
(
id
,
"."
)
[
hash
,
_
ext
]
=
String
.
split
(
id
,
"."
)
{%
Pleroma
.
Upload
{
id:
hash
,
name:
file
,
path:
file
,
tempfile:
root_path
},
root_path
}
true
->
...
...
lib/mix/tasks/pleroma/user.ex
View file @
074fa790
...
...
@@ -20,7 +20,7 @@ defmodule Mix.Tasks.Pleroma.User do
- `--admin`/`--no-admin` - whether the user is an admin
## Generate an invite link.
mix pleroma.user invite
## Delete the user's account.
...
...
@@ -32,7 +32,7 @@ defmodule Mix.Tasks.Pleroma.User do
mix pleroma.user toggle_activated NICKNAME
## Unsubscribe local users from user's account and deactivate it
mix pleroma.user unsubscribe NICKNAME
## Create a password reset link.
...
...
@@ -235,6 +235,26 @@ def run(["set", nickname | rest]) do
end
end
def
run
([
"invite"
])
do
Common
.
start_pleroma
()
with
{
:ok
,
token
}
<-
Pleroma
.
UserInviteToken
.
create_token
()
do
Mix
.
shell
()
.
info
(
"Generated user invite token"
)
url
=
Pleroma
.
Web
.
Router
.
Helpers
.
redirect_url
(
Pleroma
.
Web
.
Endpoint
,
:registration_page
,
token
.
token
)
IO
.
puts
(
url
)
else
_
->
Mix
.
shell
()
.
error
(
"Could not create invite token."
)
end
end
defp
set_moderator
(
user
,
value
)
do
info_cng
=
User
.
Info
.
admin_api_update
(
user
.
info
,
%{
is_moderator:
value
})
...
...
@@ -270,24 +290,4 @@ defp set_locked(user, value) do
Mix
.
shell
()
.
info
(
"Locked status of
#{
user
.
nickname
}
:
#{
user
.
info
.
locked
}
"
)
end
def
run
([
"invite"
])
do
Common
.
start_pleroma
()
with
{
:ok
,
token
}
<-
Pleroma
.
UserInviteToken
.
create_token
()
do
Mix
.
shell
()
.
info
(
"Generated user invite token"
)
url
=
Pleroma
.
Web
.
Router
.
Helpers
.
redirect_url
(
Pleroma
.
Web
.
Endpoint
,
:registration_page
,
token
.
token
)
IO
.
puts
(
url
)
else
_
->
Mix
.
shell
()
.
error
(
"Could not create invite token."
)
end
end
end
lib/pleroma/application.ex
View file @
074fa790
...
...
@@ -15,7 +15,6 @@ def user_agent() do
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
@env
Mix
.
env
()
def
start
(
_type
,
_args
)
do
import
Cachex
.
Spec
...
...
lib/pleroma/emoji.ex
View file @
074fa790
...
...
@@ -165,7 +165,7 @@ defp load_from_file(file) do
defp
load_from_file_stream
(
stream
)
do
stream
|>
Stream
.
map
(
&
String
.
s
tri
p
/
1
)
|>
Stream
.
map
(
&
String
.
tri
m
/
1
)
|>
Stream
.
map
(
fn
line
->
case
String
.
split
(
line
,
~r/,\s*/
)
do
[
name
,
file
]
->
{
name
,
file
}
...
...
lib/pleroma/filter.ex
View file @
074fa790
defmodule
Pleroma
.
Filter
do
use
Ecto
.
Schema
import
Ecto
.
{
Changeset
,
Query
}
alias
Pleroma
.
{
User
,
Repo
,
Activity
}
alias
Pleroma
.
{
User
,
Repo
}
schema
"filters"
do
belongs_to
(
:user
,
Pleroma
.
User
)
belongs_to
(
:user
,
User
)
field
(
:filter_id
,
:integer
)
field
(
:hide
,
:boolean
,
default:
false
)
field
(
:whole_word
,
:boolean
,
default:
true
)
...
...
@@ -26,7 +26,7 @@ def get(id, %{id: user_id} = _user) do
Repo
.
one
(
query
)
end
def
get_filters
(%
Pleroma
.
User
{
id:
user_id
}
=
user
)
do
def
get_filters
(%
User
{
id:
user_id
}
=
_
user
)
do
query
=
from
(
f
in
Pleroma
.
Filter
,
...
...
@@ -38,9 +38,9 @@ def get_filters(%Pleroma.User{id: user_id} = user) do
def
create
(%
Pleroma
.
Filter
{
user_id:
user_id
,
filter_id:
nil
}
=
filter
)
do
# If filter_id wasn't given, use the max filter_id for this user plus 1.
# XXX This could result in a race condition if a user tries to add two
# different filters for their account from two different clients at the
# same time, but that should be unlikely.
# XXX This could result in a race condition if a user tries to add two
# different filters for their account from two different clients at the
# same time, but that should be unlikely.
max_id_query
=
from
(
...
...
lib/pleroma/html.ex
View file @
074fa790
...
...
@@ -166,7 +166,7 @@ def scrub_attribute("img", {"src", "http" <> target}) do
{
"src"
,
media_url
}
end
def
scrub_attribute
(
tag
,
attribute
),
do
:
attribute
def
scrub_attribute
(
_
tag
,
attribute
),
do
:
attribute
def
scrub
({
"img"
,
attributes
,
children
})
do
attributes
=
...
...
@@ -177,9 +177,9 @@ def scrub({"img", attributes, children}) do
{
"img"
,
attributes
,
children
}
end
def
scrub
({
:comment
,
children
}),
do
:
""
def
scrub
({
:comment
,
_
children
}),
do
:
""
def
scrub
({
tag
,
attributes
,
children
}),
do
:
{
tag
,
attributes
,
children
}
def
scrub
({
tag
,
children
}),
do
:
children
def
scrub
({
_
tag
,
children
}),
do
:
children
def
scrub
(
text
),
do
:
text
end
lib/pleroma/http/connection.ex
View file @
074fa790
...
...
@@ -25,7 +25,7 @@ def new(opts \\ []) do
# fetch Hackney options
#
defp
hackney_options
(
opts
\\
[]
)
do
defp
hackney_options
(
opts
)
do
options
=
Keyword
.
get
(
opts
,
:adapter
,
[])
@hackney_options
++
options
end
...
...
lib/pleroma/list.ex
View file @
074fa790
...
...
@@ -23,7 +23,7 @@ def follow_changeset(list, attrs \\ %{}) do
|>
validate_required
([
:following
])
end
def
for_user
(
user
,
opts
)
do
def
for_user
(
user
,
_
opts
)
do
query
=
from
(
l
in
Pleroma
.
List
,
...
...
@@ -46,7 +46,7 @@ def get(id, %{id: user_id} = _user) do
Repo
.
one
(
query
)
end
def
get_following
(%
Pleroma
.
List
{
following:
following
}
=
list
)
do
def
get_following
(%
Pleroma
.
List
{
following:
following
}
=
_
list
)
do
q
=
from
(
u
in
User
,
...
...
lib/pleroma/mime.ex
View file @
074fa790
...
...
@@ -33,10 +33,10 @@ def bin_mime_type(<<head::binary-size(@read_bytes), _::binary>>) do
{
:ok
,
check_mime_type
(
head
)}
end
def
mime_type
(
<<
_
::
binary
>>
),
do
:
{
:ok
,
@default
}
def
bin_mime_type
(
_
),
do
:
:error
def
mime_type
(
<<
_
::
binary
>>
),
do
:
{
:ok
,
@default
}
defp
fix_extension
(
filename
,
content_type
)
do
parts
=
String
.
split
(
filename
,
"."
)
...
...
lib/pleroma/notification.ex
View file @
074fa790
...
...
@@ -118,7 +118,7 @@ def create_notification(%Activity{} = activity, %User{} = user) do
def
get_notified_from_activity
(
activity
,
local_only
\\
true
)
def
get_notified_from_activity
(
%
Activity
{
data:
%{
"to"
=>
_
,
"type"
=>
type
}
=
data
}
=
activity
,
%
Activity
{
data:
%{
"to"
=>
_
,
"type"
=>
type
}
=
_
data
}
=
activity
,
local_only
)
when
type
in
[
"Create"
,
"Like"
,
"Announce"
,
"Follow"
]
do
...
...
@@ -131,18 +131,18 @@ def get_notified_from_activity(
User
.
get_users_from_set
(
recipients
,
local_only
)
end
def
get_notified_from_activity
(
_
,
local_only
),
do
:
[]
def
get_notified_from_activity
(
_
,
_
local_only
),
do
:
[]
defp
maybe_notify_to_recipients
(
recipients
,
%
Activity
{
data:
%{
"to"
=>
to
,
"type"
=>
type
}}
=
activity
%
Activity
{
data:
%{
"to"
=>
to
,
"type"
=>
_
type
}}
=
_
activity
)
do
recipients
++
to
end
defp
maybe_notify_mentioned_recipients
(
recipients
,
%
Activity
{
data:
%{
"to"
=>
to
,
"type"
=>
type
}
=
data
}
=
activity
%
Activity
{
data:
%{
"to"
=>
_
to
,
"type"
=>
type
}
=
data
}
=
_
activity
)
when
type
==
"Create"
do
object
=
Object
.
normalize
(
data
[
"object"
])
...
...
lib/pleroma/plugs/authentication_plug.ex
View file @
074fa790
...
...
@@ -26,14 +26,7 @@ def call(
end
end
def
call
(
%{
assigns:
%{
auth_credentials:
%{
password:
password
}
}
}
=
conn
,
_
)
do
def
call
(%{
assigns:
%{
auth_credentials:
%{
password:
_
}}}
=
conn
,
_
)
do
Pbkdf2
.
dummy_checkpw
()
conn
end
...
...
lib/pleroma/plugs/basic_auth_decoder_plug.ex
View file @
074fa790
...
...
@@ -5,7 +5,7 @@ def init(options) do
options
end
def
call
(
conn
,
opts
)
do
def
call
(
conn
,
_
opts
)
do
with
[
"Basic "
<>
header
]
<-
get_req_header
(
conn
,
"authorization"
),
{
:ok
,
userinfo
}
<-
Base
.
decode64
(
header
),
[
username
,
password
]
<-
String
.
split
(
userinfo
,
":"
,
parts:
2
)
do
...
...
lib/pleroma/plugs/federating_plug.ex
View file @
074fa790
...
...
@@ -5,7 +5,7 @@ def init(options) do
options
end
def
call
(
conn
,
opts
)
do
def
call
(
conn
,
_
opts
)
do
if
Keyword
.
get
(
Application
.
get_env
(
:pleroma
,
:instance
),
:federating
)
do
conn
else
...
...
lib/pleroma/plugs/http_security_plug.ex
View file @
074fa790
...
...
@@ -4,11 +4,11 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do
def
init
(
opts
),
do
:
opts
def
call
(
conn
,
options
)
do
def
call
(
conn
,
_
options
)
do
if
Config
.
get
([
:http_security
,
:enabled
])
do
conn
=
merge_resp_headers
(
conn
,
headers
())
|>
maybe_send_sts_header
(
Config
.
get
([
:http_security
,
:sts
]))
conn
|>
merge_resp_headers
(
headers
())
|>
maybe_send_sts_header
(
Config
.
get
([
:http_security
,
:sts
]))
else
conn
end
...
...
@@ -42,7 +42,7 @@ defp csp_string do
"script-src 'self'"
,
"connect-src 'self' "
<>
String
.
replace
(
Pleroma
.
Web
.
Endpoint
.
static_url
(),
"http"
,
"ws"
),
"manifest-src 'self'"
,
if
@
protocol
==
"https"
do
if
protocol
==
"https"
do
"upgrade-insecure-requests"
end
]
...
...
lib/pleroma/plugs/session_authentication_plug.ex
View file @
074fa790
defmodule
Pleroma
.
Plugs
.
SessionAuthenticationPlug
do
import
Plug
.
Conn
alias
Pleroma
.
User
def
init
(
options
)
do
options
...
...
lib/pleroma/plugs/uploaded_media.ex
View file @
074fa790
...
...
@@ -8,10 +8,6 @@ defmodule Pleroma.Plugs.UploadedMedia do
@behaviour
Plug
# no slashes
@path
"media"
@cache_control
%{
default:
"public, max-age=1209600"
,
error:
"public, must-revalidate, max-age=160"
}
def
init
(
_opts
)
do
static_plug_opts
=
...
...
lib/pleroma/plugs/user_fetcher_plug.ex
View file @
074fa790
...
...
@@ -7,7 +7,7 @@ def init(options) do
options
end
def
call
(
conn
,
options
)
do
def
call
(
conn
,
_
options
)
do
with
%{
auth_credentials:
%{
username:
username
}}
<-
conn
.
assigns
,
{
:ok
,
%
User
{}
=
user
}
<-
user_fetcher
(
username
)
do
conn
...
...
Prev
1
2
3
Next
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