From ec07e087bcef49c9d2766df3c0ad9e6767720013 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Wed, 21 Feb 2018 23:31:57 +0300 Subject: [PATCH 1/2] Make user bio optional --- lib/pleroma/user.ex | 6 +++--- test/user_test.exs | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 81cec8265..59f6340b8 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -93,7 +93,7 @@ defmodule Pleroma.User do |> cast(params, [:bio, :name]) |> unique_constraint(:nickname) |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) - |> validate_length(:bio, min: 1, max: 1000) + |> validate_length(:bio, max: 1000) |> validate_length(:name, min: 1, max: 100) end @@ -119,13 +119,13 @@ defmodule Pleroma.User do def register_changeset(struct, params \\ %{}) do changeset = struct |> 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) |> unique_constraint(:email) |> unique_constraint(:nickname) |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) |> validate_format(:email, @email_regex) - |> validate_length(:bio, min: 1, max: 1000) + |> validate_length(:bio, max: 1000) |> validate_length(:name, min: 1, max: 100) if changeset.valid? do diff --git a/test/user_test.exs b/test/user_test.exs index 0c87b778c..6bfdfe1bf 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -101,13 +101,14 @@ defmodule Pleroma.UserTest do 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 |> Map.keys |> Enum.each(fn (key) -> params = Map.delete(@full_user_data, key) changeset = User.register_changeset(%User{}, params) - assert changeset.valid? == false + + assert (if key == :bio, do: changeset.valid?, else: not changeset.valid?) end) end From 0e20d5529a090f12636caccb41e5e040786eb0c6 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 5 Mar 2018 09:26:24 +0100 Subject: [PATCH 2/2] Add way to disable federation. --- config/config.exs | 3 ++- lib/pleroma/web/federator/federator.ex | 12 ++++++++---- lib/pleroma/web/router.ex | 26 +++++++++++++++++--------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/config/config.exs b/config/config.exs index 01109b30f..703c10c48 100644 --- a/config/config.exs +++ b/config/config.exs @@ -49,7 +49,8 @@ config :pleroma, :instance, name: "Pleroma", email: "example@example.com", limit: 5000, - registrations_open: true + registrations_open: true, + federating: true config :pleroma, :media_proxy, enabled: false, diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index c9f9dc7a1..8e28976a6 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -7,6 +7,8 @@ defmodule Pleroma.Web.Federator do @websub Application.get_env(:pleroma, :websub) @ostatus Application.get_env(:pleroma, :ostatus) @httpoison Application.get_env(:pleroma, :httpoison) + @instance Application.get_env(:pleroma, :instance) + @federating Keyword.get(@instance, :federating) @max_jobs 10 def start_link do @@ -80,10 +82,12 @@ defmodule Pleroma.Web.Federator do end def enqueue(type, payload, priority \\ 1) do - if Mix.env == :test do - handle(type, payload) - else - GenServer.cast(__MODULE__, {:enqueue, type, payload, priority}) + if @federating do + if Mix.env == :test do + handle(type, payload) + else + GenServer.cast(__MODULE__, {:enqueue, type, payload, priority}) + end end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 6e9f40955..59fb5cd6b 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -3,6 +3,9 @@ defmodule Pleroma.Web.Router do alias Pleroma.{Repo, User, Web.Router} + @instance Application.get_env(:pleroma, :instance) + @federating Keyword.get(@instance, :federating) + def user_fetcher(username) do {:ok, Repo.get_by(User, %{nickname: username})} end @@ -228,20 +231,25 @@ defmodule Pleroma.Web.Router do get "/objects/:uuid", OStatus.OStatusController, :object get "/activities/:uuid", OStatus.OStatusController, :activity get "/notice/:id", OStatus.OStatusController, :notice - get "/users/:nickname/feed", OStatus.OStatusController, :feed get "/users/:nickname", OStatus.OStatusController, :feed_redirect - post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming - post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request - get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation - post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming + + if @federating do + post "/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming + post "/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request + get "/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation + post "/push/subscriptions/:id", Websub.WebsubController, :websub_incoming + end + end - scope "/.well-known", Pleroma.Web do - pipe_through :well_known + if @federating do + scope "/.well-known", Pleroma.Web do + pipe_through :well_known - get "/host-meta", WebFinger.WebFingerController, :host_meta - get "/webfinger", WebFinger.WebFingerController, :webfinger + get "/host-meta", WebFinger.WebFingerController, :host_meta + get "/webfinger", WebFinger.WebFingerController, :webfinger + end end scope "/", Pleroma.Web.MastodonAPI do