forked from AkkomaGang/akkoma
Merge branch 'develop' into feature/activitypub
This commit is contained in:
commit
611ca385de
5 changed files with 38 additions and 24 deletions
|
@ -50,7 +50,8 @@
|
||||||
name: "Pleroma",
|
name: "Pleroma",
|
||||||
email: "example@example.com",
|
email: "example@example.com",
|
||||||
limit: 5000,
|
limit: 5000,
|
||||||
registrations_open: true
|
registrations_open: true,
|
||||||
|
federating: true
|
||||||
|
|
||||||
config :pleroma, :media_proxy,
|
config :pleroma, :media_proxy,
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|
|
@ -99,7 +99,7 @@ def update_changeset(struct, params \\ %{}) do
|
||||||
|> cast(params, [:bio, :name])
|
|> cast(params, [:bio, :name])
|
||||||
|> unique_constraint(:nickname)
|
|> unique_constraint(:nickname)
|
||||||
|> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
|
|> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
|
||||||
|> validate_length(:bio, min: 1, max: 5000)
|
|> validate_length(:bio, max: 1000)
|
||||||
|> validate_length(:name, min: 1, max: 100)
|
|> validate_length(:name, min: 1, max: 100)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -134,13 +134,13 @@ def reset_password(user, data) do
|
||||||
def register_changeset(struct, params \\ %{}) do
|
def register_changeset(struct, params \\ %{}) do
|
||||||
changeset = struct
|
changeset = struct
|
||||||
|> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation])
|
|> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation])
|
||||||
|> validate_required([:bio, :email, :name, :nickname, :password, :password_confirmation])
|
|> validate_required([:email, :name, :nickname, :password, :password_confirmation])
|
||||||
|> validate_confirmation(:password)
|
|> validate_confirmation(:password)
|
||||||
|> unique_constraint(:email)
|
|> unique_constraint(:email)
|
||||||
|> unique_constraint(:nickname)
|
|> unique_constraint(:nickname)
|
||||||
|> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
|
|> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
|
||||||
|> validate_format(:email, @email_regex)
|
|> validate_format(:email, @email_regex)
|
||||||
|> validate_length(:bio, min: 1, max: 1000)
|
|> validate_length(:bio, max: 1000)
|
||||||
|> validate_length(:name, min: 1, max: 100)
|
|> validate_length(:name, min: 1, max: 100)
|
||||||
|
|
||||||
if changeset.valid? do
|
if changeset.valid? do
|
||||||
|
|
|
@ -10,6 +10,8 @@ defmodule Pleroma.Web.Federator do
|
||||||
@websub Application.get_env(:pleroma, :websub)
|
@websub Application.get_env(:pleroma, :websub)
|
||||||
@ostatus Application.get_env(:pleroma, :ostatus)
|
@ostatus Application.get_env(:pleroma, :ostatus)
|
||||||
@httpoison Application.get_env(:pleroma, :httpoison)
|
@httpoison Application.get_env(:pleroma, :httpoison)
|
||||||
|
@instance Application.get_env(:pleroma, :instance)
|
||||||
|
@federating Keyword.get(@instance, :federating)
|
||||||
@max_jobs 10
|
@max_jobs 10
|
||||||
|
|
||||||
def start_link do
|
def start_link do
|
||||||
|
@ -107,12 +109,14 @@ def handle(type, _) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def enqueue(type, payload, priority \\ 1) do
|
def enqueue(type, payload, priority \\ 1) do
|
||||||
|
if @federating do
|
||||||
if Mix.env == :test do
|
if Mix.env == :test do
|
||||||
handle(type, payload)
|
handle(type, payload)
|
||||||
else
|
else
|
||||||
GenServer.cast(__MODULE__, {:enqueue, type, payload, priority})
|
GenServer.cast(__MODULE__, {:enqueue, type, payload, priority})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def maybe_start_job(running_jobs, queue) do
|
def maybe_start_job(running_jobs, queue) do
|
||||||
if (:sets.size(running_jobs) < @max_jobs) && queue != [] do
|
if (:sets.size(running_jobs) < @max_jobs) && queue != [] do
|
||||||
|
|
|
@ -3,6 +3,9 @@ defmodule Pleroma.Web.Router do
|
||||||
|
|
||||||
alias Pleroma.{Repo, User, Web.Router}
|
alias Pleroma.{Repo, User, Web.Router}
|
||||||
|
|
||||||
|
@instance Application.get_env(:pleroma, :instance)
|
||||||
|
@federating Keyword.get(@instance, :federating)
|
||||||
|
|
||||||
def user_fetcher(username) do
|
def user_fetcher(username) do
|
||||||
{:ok, Repo.get_by(User, %{nickname: username})}
|
{:ok, Repo.get_by(User, %{nickname: username})}
|
||||||
end
|
end
|
||||||
|
@ -228,20 +231,24 @@ def user_fetcher(username) do
|
||||||
get "/objects/:uuid", OStatus.OStatusController, :object
|
get "/objects/:uuid", OStatus.OStatusController, :object
|
||||||
get "/activities/:uuid", OStatus.OStatusController, :activity
|
get "/activities/:uuid", OStatus.OStatusController, :activity
|
||||||
get "/notice/:id", OStatus.OStatusController, :notice
|
get "/notice/:id", OStatus.OStatusController, :notice
|
||||||
|
|
||||||
get "/users/:nickname/feed", OStatus.OStatusController, :feed
|
get "/users/:nickname/feed", OStatus.OStatusController, :feed
|
||||||
get "/users/:nickname", OStatus.OStatusController, :feed_redirect
|
get "/users/:nickname", OStatus.OStatusController, :feed_redirect
|
||||||
|
|
||||||
|
if @federating do
|
||||||
post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
|
post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming
|
||||||
post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
|
post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request
|
||||||
get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
|
get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation
|
||||||
post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
|
post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
pipeline :activitypub do
|
pipeline :activitypub do
|
||||||
plug :accepts, ["activity+json"]
|
plug :accepts, ["activity+json"]
|
||||||
plug Pleroma.Web.Plugs.HTTPSignaturePlug
|
plug Pleroma.Web.Plugs.HTTPSignaturePlug
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @federating do
|
||||||
scope "/", Pleroma.Web.ActivityPub do
|
scope "/", Pleroma.Web.ActivityPub do
|
||||||
pipe_through :activitypub
|
pipe_through :activitypub
|
||||||
post "/users/:nickname/inbox", ActivityPubController, :inbox
|
post "/users/:nickname/inbox", ActivityPubController, :inbox
|
||||||
|
@ -254,6 +261,7 @@ def user_fetcher(username) do
|
||||||
get "/host-meta", WebFinger.WebFingerController, :host_meta
|
get "/host-meta", WebFinger.WebFingerController, :host_meta
|
||||||
get "/webfinger", WebFinger.WebFingerController, :webfinger
|
get "/webfinger", WebFinger.WebFingerController, :webfinger
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scope "/", Pleroma.Web.MastodonAPI do
|
scope "/", Pleroma.Web.MastodonAPI do
|
||||||
pipe_through :mastodon_html
|
pipe_through :mastodon_html
|
||||||
|
|
|
@ -102,13 +102,14 @@ test "test if a user is following another user" do
|
||||||
email: "email@example.com"
|
email: "email@example.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
test "it requires a bio, email, name, nickname and password" do
|
test "it requires an email, name, nickname and password, bio is optional" do
|
||||||
@full_user_data
|
@full_user_data
|
||||||
|> Map.keys
|
|> Map.keys
|
||||||
|> Enum.each(fn (key) ->
|
|> Enum.each(fn (key) ->
|
||||||
params = Map.delete(@full_user_data, key)
|
params = Map.delete(@full_user_data, key)
|
||||||
changeset = User.register_changeset(%User{}, params)
|
changeset = User.register_changeset(%User{}, params)
|
||||||
assert changeset.valid? == false
|
|
||||||
|
assert (if key == :bio, do: changeset.valid?, else: not changeset.valid?)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue