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
2bc924ba
Verified
Commit
2bc924ba
authored
Nov 06, 2018
by
href
Browse files
Get rid of Pleroma.Config in favor of Application
Discussed in
pleroma/pleroma!426 (comment 7232)
parent
0f6c4635
Changes
7
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/application.ex
View file @
2bc924ba
...
...
@@ -10,7 +10,6 @@ def start(_type, _args) do
# Define workers and child supervisors to be supervised
children
=
[
worker
(
Pleroma
.
Config
,
[
Application
.
get_all_env
(
:pleroma
)]),
# Start the Ecto repository
supervisor
(
Pleroma
.
Repo
,
[]),
worker
(
Pleroma
.
Emoji
,
[]),
...
...
lib/pleroma/config.ex
deleted
100644 → 0
View file @
0f6c4635
defmodule
Pleroma
.
Config
do
use
Agent
def
start_link
(
initial
)
do
Agent
.
start_link
(
fn
->
initial
end
,
name:
__MODULE__
)
end
def
get
(
path
)
do
Agent
.
get
(
__MODULE__
,
Kernel
,
:get_in
,
[
path
])
end
def
put
(
path
,
value
)
do
Agent
.
update
(
__MODULE__
,
Kernel
,
:put_in
,
[
path
,
value
])
end
end
lib/pleroma/web/activity_pub/activity_pub_controller.ex
View file @
2bc924ba
...
...
@@ -6,7 +6,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
alias
Pleroma
.
Web
.
ActivityPub
.
Relay
alias
Pleroma
.
Web
.
ActivityPub
.
Utils
alias
Pleroma
.
Web
.
Federator
alias
Pleroma
.
Config
require
Logger
...
...
@@ -15,7 +14,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
plug
(
:relay_active?
when
action
in
[
:relay
])
def
relay_active?
(
conn
,
_
)
do
if
Config
.
get
([
:instance
,
:allow_relay
]
)
do
if
Keyword
.
get
(
Application
.
get_env
(
:pleroma
,
:instance
)
,
:allow_relay
)
do
conn
else
conn
...
...
lib/pleroma/web/federator/federator.ex
View file @
2bc924ba
...
...
@@ -7,7 +7,6 @@ defmodule Pleroma.Web.Federator do
alias
Pleroma
.
Web
.
ActivityPub
.
Relay
alias
Pleroma
.
Web
.
ActivityPub
.
Transmogrifier
alias
Pleroma
.
Web
.
ActivityPub
.
Utils
alias
Pleroma
.
Config
require
Logger
@websub
Application
.
get_env
(
:pleroma
,
:websub
)
...
...
@@ -72,7 +71,7 @@ def handle(:publish, activity) do
Logger
.
info
(
fn
->
"Sending
#{
activity
.
data
[
"id"
]
}
out via Salmon"
end
)
Pleroma
.
Web
.
Salmon
.
publish
(
actor
,
activity
)
if
Config
.
get
([
:instance
,
:allow_relay
]
)
do
if
Keyword
.
get
(
Application
.
get_env
(
:pleroma
,
:instance
)
,
:allow_relay
)
do
Logger
.
info
(
fn
->
"Relaying
#{
activity
.
data
[
"id"
]
}
out"
end
)
Relay
.
publish
(
activity
)
end
...
...
test/config_test.exs
deleted
100644 → 0
View file @
0f6c4635
defmodule
Pleroma
.
ConfigTest
do
use
Pleroma
.
DataCase
alias
Pleroma
.
Config
test
"get returns the item at the path if there is one"
do
Config
.
put
([
:instance
,
:name
],
"Plemora"
)
assert
Config
.
get
([
:instance
,
:name
])
==
"Plemora"
assert
Config
.
get
([
:unknown
])
==
nil
end
end
test/web/activity_pub/activity_pub_controller_test.exs
View file @
2bc924ba
...
...
@@ -4,12 +4,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
alias
Pleroma
.
Web
.
ActivityPub
.
{
UserView
,
ObjectView
}
alias
Pleroma
.
{
Repo
,
User
}
alias
Pleroma
.
Activity
alias
Pleroma
.
Config
describe
"/relay"
do
test
"with the relay active, it returns the relay user"
,
%{
conn:
conn
}
do
Config
.
put
([
:instance
,
:allow_relay
],
true
)
res
=
conn
|>
get
(
activity_pub_path
(
conn
,
:relay
))
...
...
@@ -19,12 +16,23 @@ test "with the relay active, it returns the relay user", %{conn: conn} do
end
test
"with the relay disabled, it returns 404"
,
%{
conn:
conn
}
do
Config
.
put
([
:instance
,
:allow_relay
],
false
)
instance
=
Application
.
get_env
(
:pleroma
,
:instance
)
|>
Keyword
.
put
(
:allow_relay
,
false
)
Application
.
put_env
(
:pleroma
,
:instance
,
instance
)
res
=
conn
|>
get
(
activity_pub_path
(
conn
,
:relay
))
|>
json_response
(
404
)
instance
=
Application
.
get_env
(
:pleroma
,
:instance
)
|>
Keyword
.
put
(
:allow_relay
,
true
)
Application
.
put_env
(
:pleroma
,
:instance
,
instance
)
end
end
...
...
test/web/federator_test.exs
View file @
2bc924ba
defmodule
Pleroma
.
Web
.
FederatorTest
do
alias
Pleroma
.
Web
.
Federator
alias
Pleroma
.
Web
.
CommonAPI
alias
Pleroma
.
Config
use
Pleroma
.
DataCase
import
Pleroma
.
Factory
import
Mock
...
...
@@ -40,8 +39,6 @@ test "with relays active, it publishes to the relay", %{
activity:
activity
,
relay_mock:
relay_mock
}
do
Config
.
put
([
:instance
,
:allow_relay
],
true
)
with_mocks
([
relay_mock
])
do
Federator
.
handle
(
:publish
,
activity
)
end
...
...
@@ -53,13 +50,23 @@ test "with relays deactivated, it does not publish to the relay", %{
activity:
activity
,
relay_mock:
relay_mock
}
do
Config
.
put
([
:instance
,
:allow_relay
],
false
)
instance
=
Application
.
get_env
(
:pleroma
,
:instance
)
|>
Keyword
.
put
(
:allow_relay
,
false
)
Application
.
put_env
(
:pleroma
,
:instance
,
instance
)
with_mocks
([
relay_mock
])
do
Federator
.
handle
(
:publish
,
activity
)
end
refute_received
:relay_publish
instance
=
Application
.
get_env
(
:pleroma
,
:instance
)
|>
Keyword
.
put
(
:allow_relay
,
true
)
Application
.
put_env
(
:pleroma
,
:instance
,
instance
)
end
end
end
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