From 4a6855d9eedf07159520b2205c554c891e70c7d4 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sun, 1 Jan 2017 03:10:08 +0300 Subject: Provide plaintext representations of content/cw in MastoAPI --- lib/pleroma/web/mastodon_api/views/status_view.ex | 31 +++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 4c0b53bdd..d4a8e4fff 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -147,20 +147,39 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do content = object |> render_content() + + content_html = + content |> HTML.get_cached_scrubbed_html_for_activity( User.html_filter_policy(opts[:for]), activity, "mastoapi:content" ) - summary = - (object["summary"] || "") + content_plaintext = + content + |> HTML.get_cached_stripped_html_for_activity( + activity, + "mastoapi:content" + ) + + summary = object["summary"] || "" + + summary_html = + summary |> HTML.get_cached_scrubbed_html_for_activity( User.html_filter_policy(opts[:for]), activity, "mastoapi:summary" ) + summary_plaintext = + summary + |> HTML.get_cached_stripped_html_for_activity( + activity, + "mastoapi:summary" + ) + card = render("card.json", Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)) url = @@ -179,7 +198,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id), reblog: nil, card: card, - content: content, + content: content_html, created_at: created_at, reblogs_count: announcement_count, replies_count: object["repliesCount"] || 0, @@ -190,7 +209,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do muted: CommonAPI.thread_muted?(user, activity) || User.mutes?(opts[:for], user), pinned: pinned?(activity, user), sensitive: sensitive, - spoiler_text: summary, + spoiler_text: summary_html, visibility: get_visibility(object), media_attachments: attachments, mentions: mentions, @@ -203,7 +222,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do emojis: build_emojis(activity.data["object"]["emoji"]), pleroma: %{ local: activity.local, - conversation_id: get_context_id(activity) + conversation_id: get_context_id(activity), + content: %{"text/plain" => content_plaintext}, + spoiler_text: %{"text/plain" => summary_plaintext} } } end -- cgit v1.2.3 From 8a1dc0de92c8c99bd6216281355be829cbcfb21f Mon Sep 17 00:00:00 2001 From: Jorty Date: Thu, 28 Jun 2018 20:24:51 -0400 Subject: Refactor Mix tasks 1. Move Mix tasks into a `pleroma` namespace, to avoid collisions with dependent packages. 2. Rename and condense tasks into two `pleroma.user` and `pleroma.gen.instance` tasks for consistency with Hex and Phoenix. 3. Add additional functionality to the tasks to make them more user-friendly. Arguments with sensible defaults were demoted to flags and in the interactive `generate_config` (renamed to `pleroma.gen.instance`), flags were added to allow non-interactive use, though interactive use remains the primary interface. That task also now prompts the user for database parameters. 4. Documentation has been added to both tasks such that `mix help` now shows useful information. 5. Finally, use of IO.puts in tasks has been replaced with Mix.shell() equivalents to make the behavior more consistent with Mix tasks in other packages, and such that variables like MIX_QUIET are respected. The only exception is in `mix pleroma.user reset_password`, wherein the URL must always be printed regardless of the value of MIX_QUIET since that's its entire purpose. --- lib/mix/tasks/deactivate_user.ex | 13 -- lib/mix/tasks/fix_ap_users.ex | 28 ----- lib/mix/tasks/generate_config.ex | 39 ------ lib/mix/tasks/generate_password_reset.ex | 27 ---- lib/mix/tasks/make_moderator.ex | 30 ----- lib/mix/tasks/pleroma/gen_instance.ex | 161 ++++++++++++++++++++++++ lib/mix/tasks/pleroma/sample_config.eex | 30 +++++ lib/mix/tasks/pleroma/sample_psql.eex | 9 ++ lib/mix/tasks/pleroma/user.ex | 207 +++++++++++++++++++++++++++++++ lib/mix/tasks/register_user.ex | 22 ---- lib/mix/tasks/rm_user.ex | 13 -- lib/mix/tasks/sample_config.eex | 26 ---- lib/mix/tasks/sample_psql.eex | 9 -- lib/mix/tasks/set_locked.ex | 30 ----- 14 files changed, 407 insertions(+), 237 deletions(-) delete mode 100644 lib/mix/tasks/deactivate_user.ex delete mode 100644 lib/mix/tasks/fix_ap_users.ex delete mode 100644 lib/mix/tasks/generate_config.ex delete mode 100644 lib/mix/tasks/generate_password_reset.ex delete mode 100644 lib/mix/tasks/make_moderator.ex create mode 100644 lib/mix/tasks/pleroma/gen_instance.ex create mode 100644 lib/mix/tasks/pleroma/sample_config.eex create mode 100644 lib/mix/tasks/pleroma/sample_psql.eex create mode 100644 lib/mix/tasks/pleroma/user.ex delete mode 100644 lib/mix/tasks/register_user.ex delete mode 100644 lib/mix/tasks/rm_user.ex delete mode 100644 lib/mix/tasks/sample_config.eex delete mode 100644 lib/mix/tasks/sample_psql.eex delete mode 100644 lib/mix/tasks/set_locked.ex (limited to 'lib') diff --git a/lib/mix/tasks/deactivate_user.ex b/lib/mix/tasks/deactivate_user.ex deleted file mode 100644 index 96b3db6e4..000000000 --- a/lib/mix/tasks/deactivate_user.ex +++ /dev/null @@ -1,13 +0,0 @@ -defmodule Mix.Tasks.DeactivateUser do - use Mix.Task - alias Pleroma.User - - @shortdoc "Toggle deactivation status for a user" - def run([nickname]) do - Mix.Task.run("app.start") - - with user <- User.get_by_nickname(nickname) do - User.deactivate(user) - end - end -end diff --git a/lib/mix/tasks/fix_ap_users.ex b/lib/mix/tasks/fix_ap_users.ex deleted file mode 100644 index 7e970850e..000000000 --- a/lib/mix/tasks/fix_ap_users.ex +++ /dev/null @@ -1,28 +0,0 @@ -defmodule Mix.Tasks.FixApUsers do - use Mix.Task - import Ecto.Query - alias Pleroma.{Repo, User} - - @shortdoc "Grab all ap users again" - def run([]) do - Mix.Task.run("app.start") - - q = - from( - u in User, - where: fragment("? @> ?", u.info, ^%{"ap_enabled" => true}), - where: u.local == false - ) - - users = Repo.all(q) - - Enum.each(users, fn user -> - try do - IO.puts("Fetching #{user.nickname}") - Pleroma.Web.ActivityPub.Transmogrifier.upgrade_user_from_ap_id(user.ap_id, false) - rescue - e -> IO.inspect(e) - end - end) - end -end diff --git a/lib/mix/tasks/generate_config.ex b/lib/mix/tasks/generate_config.ex deleted file mode 100644 index 70a110561..000000000 --- a/lib/mix/tasks/generate_config.ex +++ /dev/null @@ -1,39 +0,0 @@ -defmodule Mix.Tasks.GenerateConfig do - use Mix.Task - - @shortdoc "Generates a new config" - def run(_) do - IO.puts("Answer a few questions to generate a new config\n") - IO.puts("--- THIS WILL OVERWRITE YOUR config/generated_config.exs! ---\n") - domain = IO.gets("What is your domain name? (e.g. pleroma.soykaf.com): ") |> String.trim() - name = IO.gets("What is the name of your instance? (e.g. Pleroma/Soykaf): ") |> String.trim() - email = IO.gets("What's your admin email address: ") |> String.trim() - - secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) - dbpass = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) - - resultSql = EEx.eval_file("lib/mix/tasks/sample_psql.eex", dbpass: dbpass) - - result = - EEx.eval_file( - "lib/mix/tasks/sample_config.eex", - domain: domain, - email: email, - name: name, - secret: secret, - dbpass: dbpass - ) - - IO.puts( - "\nWriting config to config/generated_config.exs.\n\nCheck it and configure your database, then copy it to either config/dev.secret.exs or config/prod.secret.exs" - ) - - File.write("config/generated_config.exs", result) - - IO.puts( - "\nWriting setup_db.psql, please run it as postgre superuser, i.e.: sudo su postgres -c 'psql -f config/setup_db.psql'" - ) - - File.write("config/setup_db.psql", resultSql) - end -end diff --git a/lib/mix/tasks/generate_password_reset.ex b/lib/mix/tasks/generate_password_reset.ex deleted file mode 100644 index 6bf640150..000000000 --- a/lib/mix/tasks/generate_password_reset.ex +++ /dev/null @@ -1,27 +0,0 @@ -defmodule Mix.Tasks.GeneratePasswordReset do - use Mix.Task - alias Pleroma.User - - @shortdoc "Generate password reset link for user" - def run([nickname]) do - Mix.Task.run("app.start") - - with %User{local: true} = user <- User.get_by_nickname(nickname), - {:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do - IO.puts("Generated password reset token for #{user.nickname}") - - IO.puts( - "Url: #{ - Pleroma.Web.Router.Helpers.util_url( - Pleroma.Web.Endpoint, - :show_password_reset, - token.token - ) - }" - ) - else - _ -> - IO.puts("No local user #{nickname}") - end - end -end diff --git a/lib/mix/tasks/make_moderator.ex b/lib/mix/tasks/make_moderator.ex deleted file mode 100644 index a454a958e..000000000 --- a/lib/mix/tasks/make_moderator.ex +++ /dev/null @@ -1,30 +0,0 @@ -defmodule Mix.Tasks.SetModerator do - use Mix.Task - import Mix.Ecto - alias Pleroma.{Repo, User} - - @shortdoc "Set moderator status" - def run([nickname | rest]) do - Application.ensure_all_started(:pleroma) - - moderator = - case rest do - [moderator] -> moderator == "true" - _ -> true - end - - with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("is_moderator", !!moderator) - - cng = User.info_changeset(user, %{info: info}) - {:ok, user} = User.update_and_set_cache(cng) - - IO.puts("Moderator status of #{nickname}: #{user.info["is_moderator"]}") - else - _ -> - IO.puts("No local user #{nickname}") - end - end -end diff --git a/lib/mix/tasks/pleroma/gen_instance.ex b/lib/mix/tasks/pleroma/gen_instance.ex new file mode 100644 index 000000000..94f2220b1 --- /dev/null +++ b/lib/mix/tasks/pleroma/gen_instance.ex @@ -0,0 +1,161 @@ +defmodule Mix.Tasks.Pleroma.Gen.Instance do + use Mix.Task + + @shortdoc "Generates the configuration for a new instance" + @moduledoc """ + Generates the configuration for a new instance. + + If any options are left unspecified, you will be prompted interactively. This + means the simplest invocation would be + + mix pleroma.gen.instance + + ## Options + + - `-f`, `--force` - overwrite any output files + - `-o PATH`, `--output PATH` - the output file for the generated configuration + - `--output-psql PATH` - the output file for the generated PostgreSQL setup + - `--domain DOMAIN` - the domain of your instance + - `--instance-name INSTANCE_NAME` - the name of your instance + - `--admin-email ADMIN_EMAIL` - the email address of the instance admin + - `--dbhost HOSTNAME` - the hostname of the PostgreSQL database to use + - `--dbname DBNAME` - the name of the database to use + - `--dbuser DBUSER` - the user (aka role) to use for the database connection + - `--dbpass DBPASS` - the password to use for the database connection + """ + + def run(rest) do + {options, [], []} = + OptionParser.parse( + rest, + strict: [ + force: :boolean, + output: :string, + output_psql: :string, + domain: :string, + instance_name: :string, + admin_email: :string, + dbhost: :string, + dbname: :string, + dbuser: :string, + dbpass: :string + ], + aliases: [ + o: :output, + f: :force + ] + ) + + paths = + [config_path, psql_path] = [ + Keyword.get(options, :output, "config/generated_config.exs"), + Keyword.get(options, :output_psql, "config/setup_db.psql") + ] + + will_overwrite = Enum.filter(paths, &File.exists?/1) + proceed? = Enum.empty?(will_overwrite) or Keyword.get(options, :force, false) + + unless not proceed? do + domain = + Keyword.get(options, :domain) || + Mix.shell().prompt("What domain will your instance use? (e.g. pleroma.soykaf.com)") + |> String.trim() + + name = + Keyword.get(options, :name) || + Mix.shell().prompt("What is the name of your instance? (e.g. Pleroma/Soykaf)") + |> String.trim() + + email = + Keyword.get(options, :admin_email) || + Mix.shell().prompt("What is your admin email address?") + |> String.trim() + + dbhost = + Keyword.get(options, :dbhost) || + case Mix.shell().prompt("What is the hostname of your database? [localhost]") do + "\n" -> "localhost" + dbhost -> dbhost |> String.trim() + end + + dbname = + Keyword.get(options, :dbname) || + case Mix.shell().prompt("What is the name of your database? [pleroma_dev]") do + "\n" -> "pleroma_dev" + dbname -> dbname |> String.trim() + end + + dbuser = + Keyword.get(options, :dbuser) || + case Mix.shell().prompt("What is the user used to connect to your database? [pleroma]") do + "\n" -> "pleroma" + dbuser -> dbuser |> String.trim() + end + + dbpass = + Keyword.get(options, :dbpass) || + case Mix.shell().prompt( + "What is the password used to connect to your database? [autogenerated]" + ) do + "\n" -> :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) + dbpass -> dbpass |> String.trim() + end + + secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) + + result_config = + EEx.eval_file( + "sample_config.eex" |> Path.expand(__DIR__), + domain: domain, + email: email, + name: name, + dbhost: dbhost, + dbname: dbname, + dbuser: dbuser, + dbpass: dbpass, + version: Pleroma.Mixfile.project() |> Keyword.get(:version), + secret: secret + ) + + result_psql = + EEx.eval_file( + "sample_psql.eex" |> Path.expand(__DIR__), + dbname: dbname, + dbuser: dbuser, + dbpass: dbpass + ) + + Mix.shell().info( + "Writing config to #{config_path}. You should rename it to config/prod.secret.exs or config/dev.secret.exs." + ) + + File.write(config_path, result_config) + Mix.shell().info("Writing #{psql_path}.") + File.write(psql_path, result_psql) + + Mix.shell().info( + "\n" <> + """ + To get started: + 1. Verify the contents of the generated files. + 2. Run `sudo -u postgres psql -f #{escape_sh_path(psql_path)}`. + """ <> + if config_path in ["config/dev.secret.exs", "config/prod.secret.exs"] do + "" + else + "3. Run `mv #{escape_sh_path(config_path)} 'config/prod.secret.exs'`." + end + ) + else + Mix.shell().error( + "The task would have overwritten the following files:\n" <> + (Enum.map(paths, &"- #{&1}\n") |> Enum.join("")) <> + "Rerun with `--force` to overwrite them." + ) + end + end + + defp escape_sh_path(path) do + ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(') + end +end diff --git a/lib/mix/tasks/pleroma/sample_config.eex b/lib/mix/tasks/pleroma/sample_config.eex new file mode 100644 index 000000000..066939981 --- /dev/null +++ b/lib/mix/tasks/pleroma/sample_config.eex @@ -0,0 +1,30 @@ +# Pleroma instance configuration + +# NOTE: This file should not be committed to a repo or otherwise made public +# without removing sensitive information. + +use Mix.Config + +config :pleroma, Pleroma.Web.Endpoint, + url: [host: "<%= domain %>", scheme: "https", port: 443], + secret_key_base: "<%= secret %>" + +config :pleroma, :instance, + name: "<%= name %>", + email: "<%= email %>", + limit: 5000, + registrations_open: true, + dedupe_media: false + +config :pleroma, :media_proxy, + enabled: false, + redirect_on_failure: true + #base_url: "https://cache.pleroma.social" + +config :pleroma, Pleroma.Repo, + adapter: Ecto.Adapters.Postgres, + username: "<%= dbuser %>", + password: "<%= dbpass %>", + database: "<%= dbname %>", + hostname: "<%= dbhost %>", + pool_size: 10 diff --git a/lib/mix/tasks/pleroma/sample_psql.eex b/lib/mix/tasks/pleroma/sample_psql.eex new file mode 100644 index 000000000..66f76752f --- /dev/null +++ b/lib/mix/tasks/pleroma/sample_psql.eex @@ -0,0 +1,9 @@ +CREATE USER <%= dbuser %> WITH ENCRYPTED PASSWORD '<%= dbpass %>' CREATEDB; +-- in case someone runs this second time accidentally +ALTER USER <%= dbuser %> WITH ENCRYPTED PASSWORD '<%= dbpass %>' CREATEDB; +CREATE DATABASE <%= dbname %>; +ALTER DATABASE <%= dbname %> OWNER TO <%= dbuser %>; +\c <%= dbname %>; +--Extensions made by ecto.migrate that need superuser access +CREATE EXTENSION IF NOT EXISTS citext; +CREATE EXTENSION IF NOT EXISTS pg_trgm; diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex new file mode 100644 index 000000000..c20fecaa1 --- /dev/null +++ b/lib/mix/tasks/pleroma/user.ex @@ -0,0 +1,207 @@ +defmodule Mix.Tasks.Pleroma.User do + use Mix.Task + alias Pleroma.{Repo, User} + + @shortdoc "Manages Pleroma users" + @moduledoc """ + Manages Pleroma users. + + ## Create a new user. + + mix pleroma.user new NICKNAME EMAIL [OPTION...] + + Options: + - `--name NAME` - the user's name (i.e., "Lain Iwakura") + - `--bio BIO` - the user's bio + - `--password PASSWORD` - the user's password + - `--moderator`/`--no-moderator` - whether the user is a moderator + + ## Delete the user's account. + + mix pleroma.user rm NICKNAME + + ## Deactivate or activate the user's account. + + mix pleroma.user toggle_activated NICKNAME + + ## Create a password reset link. + + mix pleroma.user reset_password NICKNAME + + ## Set the value of the given user's settings. + + mix pleroma.user set NICKNAME [OPTION...] + + Options: + - `--locked`/`--no-locked` - whether the user's account is locked + - `--moderator`/`--no-moderator` - whether the user is a moderator + """ + + def run(["new", nickname, email | rest]) do + {options, [], []} = + OptionParser.parse( + rest, + strict: [ + name: :string, + bio: :string, + password: :string, + moderator: :boolean + ] + ) + + name = Keyword.get(options, :name, nickname) + bio = Keyword.get(options, :bio, "") + + {password, generated_password?} = + case Keyword.get(options, :password) do + nil -> + {:crypto.strong_rand_bytes(16) |> Base.encode64(), true} + + password -> + {password, false} + end + + moderator? = Keyword.get(options, :moderator, false) + + Mix.shell().info(""" + A user will be created with the following information: + - nickname: #{nickname} + - email: #{email} + - password: #{ + if(generated_password?, do: "[generated; a reset link will be created]", else: password) + } + - name: #{name} + - bio: #{bio} + - moderator: #{if(moderator?, do: "true", else: "false")} + """) + + proceed? = Mix.shell().yes?("Continue?") + + unless not proceed? do + Mix.Task.run("app.start") + + params = + %{ + nickname: nickname, + email: email, + password: password, + password_confirmation: password, + name: name, + bio: bio + } + |> IO.inspect() + + user = User.register_changeset(%User{}, params) + Repo.insert!(user) + + Mix.shell().info("User #{nickname} created") + + if moderator? do + run(["set", nickname, "--moderator"]) + end + + if generated_password? do + run(["reset_password", nickname]) + end + else + Mix.shell().info("User will not be created.") + end + end + + def run(["rm", nickname]) do + Mix.Task.run("app.start") + + with %User{local: true} = user <- User.get_by_nickname(nickname) do + User.delete(user) + end + + Mix.shell().info("User #{nickname} deleted.") + end + + def run(["toggle_activated", nickname]) do + Mix.Task.run("app.start") + + with user <- User.get_by_nickname(nickname) do + User.deactivate(user) + end + end + + def run(["reset_password", nickname]) do + Mix.Task.run("app.start") + + with %User{local: true} = user <- User.get_by_nickname(nickname), + {:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do + Mix.shell().info("Generated password reset token for #{user.nickname}") + + IO.puts( + "URL: #{ + Pleroma.Web.Router.Helpers.util_url( + Pleroma.Web.Endpoint, + :show_password_reset, + token.token + ) + }" + ) + else + _ -> + Mix.shell().error("No local user #{nickname}") + end + end + + def run(["set", nickname | rest]) do + {options, [], []} = + OptionParser.parse( + rest, + strict: [ + moderator: :boolean, + locked: :boolean + ] + ) + + case Keyword.get(options, :moderator) do + nil -> nil + value -> set_moderator(nickname, value) + end + + case Keyword.get(options, :locked) do + nil -> nil + value -> set_locked(nickname, value) + end + end + + defp set_moderator(nickname, value) do + Application.ensure_all_started(:pleroma) + + with %User{local: true} = user <- User.get_by_nickname(nickname) do + info = + user.info + |> Map.put("is_moderator", value) + + cng = User.info_changeset(user, %{info: info}) + {:ok, user} = User.update_and_set_cache(cng) + + Mix.shell().info("Moderator status of #{nickname}: #{user.info["is_moderator"]}") + else + _ -> + Mix.shell().error("No local user #{nickname}") + end + end + + defp set_locked(nickname, value) do + Mix.Ecto.ensure_started(Repo, []) + + with %User{local: true} = user <- User.get_by_nickname(nickname) do + info = + user.info + |> Map.put("locked", value) + + cng = User.info_changeset(user, %{info: info}) + user = Repo.update!(cng) + + IO.puts("Locked status of #{nickname}: #{user.info["locked"]}") + else + _ -> + IO.puts("No local user #{nickname}") + end + end +end diff --git a/lib/mix/tasks/register_user.ex b/lib/mix/tasks/register_user.ex deleted file mode 100644 index e74721c49..000000000 --- a/lib/mix/tasks/register_user.ex +++ /dev/null @@ -1,22 +0,0 @@ -defmodule Mix.Tasks.RegisterUser do - use Mix.Task - alias Pleroma.{Repo, User} - - @shortdoc "Register user" - def run([name, nickname, email, bio, password]) do - Mix.Task.run("app.start") - - params = %{ - name: name, - nickname: nickname, - email: email, - password: password, - password_confirmation: password, - bio: bio - } - - user = User.register_changeset(%User{}, params) - - Repo.insert!(user) - end -end diff --git a/lib/mix/tasks/rm_user.ex b/lib/mix/tasks/rm_user.ex deleted file mode 100644 index 27521b745..000000000 --- a/lib/mix/tasks/rm_user.ex +++ /dev/null @@ -1,13 +0,0 @@ -defmodule Mix.Tasks.RmUser do - use Mix.Task - alias Pleroma.User - - @shortdoc "Permanently delete a user" - def run([nickname]) do - Mix.Task.run("app.start") - - with %User{local: true} = user <- User.get_by_nickname(nickname) do - User.delete(user) - end - end -end diff --git a/lib/mix/tasks/sample_config.eex b/lib/mix/tasks/sample_config.eex deleted file mode 100644 index 6db36fa09..000000000 --- a/lib/mix/tasks/sample_config.eex +++ /dev/null @@ -1,26 +0,0 @@ -use Mix.Config - -config :pleroma, Pleroma.Web.Endpoint, - url: [host: "<%= domain %>", scheme: "https", port: 443], - secret_key_base: "<%= secret %>" - -config :pleroma, :instance, - name: "<%= name %>", - email: "<%= email %>", - limit: 5000, - registrations_open: true, - dedupe_media: false - -config :pleroma, :media_proxy, - enabled: false, - redirect_on_failure: true - #base_url: "https://cache.pleroma.social" - -# Configure your database -config :pleroma, Pleroma.Repo, - adapter: Ecto.Adapters.Postgres, - username: "pleroma", - password: "<%= dbpass %>", - database: "pleroma_dev", - hostname: "localhost", - pool_size: 10 diff --git a/lib/mix/tasks/sample_psql.eex b/lib/mix/tasks/sample_psql.eex deleted file mode 100644 index bc22f166c..000000000 --- a/lib/mix/tasks/sample_psql.eex +++ /dev/null @@ -1,9 +0,0 @@ -CREATE USER pleroma WITH ENCRYPTED PASSWORD '<%= dbpass %>' CREATEDB; --- in case someone runs this second time accidentally -ALTER USER pleroma WITH ENCRYPTED PASSWORD '<%= dbpass %>' CREATEDB; -CREATE DATABASE pleroma_dev; -ALTER DATABASE pleroma_dev OWNER TO pleroma; -\c pleroma_dev; ---Extensions made by ecto.migrate that need superuser access -CREATE EXTENSION IF NOT EXISTS citext; -CREATE EXTENSION IF NOT EXISTS pg_trgm; diff --git a/lib/mix/tasks/set_locked.ex b/lib/mix/tasks/set_locked.ex deleted file mode 100644 index 2b3b18b09..000000000 --- a/lib/mix/tasks/set_locked.ex +++ /dev/null @@ -1,30 +0,0 @@ -defmodule Mix.Tasks.SetLocked do - use Mix.Task - import Mix.Ecto - alias Pleroma.{Repo, User} - - @shortdoc "Set locked status" - def run([nickname | rest]) do - ensure_started(Repo, []) - - locked = - case rest do - [locked] -> locked == "true" - _ -> true - end - - with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("locked", !!locked) - - cng = User.info_changeset(user, %{info: info}) - user = Repo.update!(cng) - - IO.puts("locked status of #{nickname}: #{user.info["locked"]}") - else - _ -> - IO.puts("No local user #{nickname}") - end - end -end -- cgit v1.2.3 From ba6e3eba33f16bdd2fede086d5fb5c86201cb57b Mon Sep 17 00:00:00 2001 From: Jorty Date: Thu, 23 Aug 2018 12:37:20 -0400 Subject: Move invite task to pleroma namespace Some other minor changes were made to make it consistent with the behavior of other tasks both within Pleroma and the conventions set by dependencies such as Phoenix. Namely, the task is named `gen.invite` and `IO.puts` has been replaced with references to `Mix.shell()` where appropriate. --- lib/mix/tasks/generate_invite_token.ex | 25 ------------------------- lib/mix/tasks/pleroma/gen_invite.ex | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 25 deletions(-) delete mode 100644 lib/mix/tasks/generate_invite_token.ex create mode 100644 lib/mix/tasks/pleroma/gen_invite.ex (limited to 'lib') diff --git a/lib/mix/tasks/generate_invite_token.ex b/lib/mix/tasks/generate_invite_token.ex deleted file mode 100644 index c4daa9a6c..000000000 --- a/lib/mix/tasks/generate_invite_token.ex +++ /dev/null @@ -1,25 +0,0 @@ -defmodule Mix.Tasks.GenerateInviteToken do - use Mix.Task - - @shortdoc "Generate invite token for user" - def run([]) do - Mix.Task.run("app.start") - - with {:ok, token} <- Pleroma.UserInviteToken.create_token() do - IO.puts("Generated user invite token") - - IO.puts( - "Url: #{ - Pleroma.Web.Router.Helpers.redirect_url( - Pleroma.Web.Endpoint, - :registration_page, - token.token - ) - }" - ) - else - _ -> - IO.puts("Error creating token") - end - end -end diff --git a/lib/mix/tasks/pleroma/gen_invite.ex b/lib/mix/tasks/pleroma/gen_invite.ex new file mode 100644 index 000000000..0aa028f1e --- /dev/null +++ b/lib/mix/tasks/pleroma/gen_invite.ex @@ -0,0 +1,24 @@ +defmodule Mix.Tasks.Pleroma.Gen.Invite do + use Mix.Task + + @shortdoc "Generates a user invite token" + def run([]) do + Mix.Task.run("app.start") + + 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: #{url}") + else + _ -> + Mix.shell().error("Could not create invite token.") + end + end +end -- cgit v1.2.3 From c2d592c9c5db8e0392948d5fc589761f482fc4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20K=C3=BChl?= Date: Tue, 18 Sep 2018 11:39:06 +0200 Subject: Assign token to connection --- lib/pleroma/plugs/oauth_plug.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 0380ce14d..651485e09 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -18,10 +18,11 @@ defmodule Pleroma.Plugs.OAuthPlug do end with token when not is_nil(token) <- token, - %Token{user_id: user_id} <- Repo.get_by(Token, token: token), + %Token{user_id: user_id} = token <- Repo.get_by(Token, token: token), %User{} = user <- Repo.get(User, user_id), false <- !!user.info["deactivated"] do conn + |> assign(:token, token) |> assign(:user, user) else _ -> conn -- cgit v1.2.3 From d94ee5cd50005a947c3c3a734b086fd5cd266c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20K=C3=BChl?= Date: Tue, 18 Sep 2018 11:56:46 +0200 Subject: Mastodon API: Support push subscription CRUD --- .../web/mastodon_api/mastodon_api_controller.ex | 27 +++++++++ .../mastodon_api/views/push_subscription_view.ex | 14 +++++ lib/pleroma/web/push/subscription.ex | 66 ++++++++++++++++++++++ lib/pleroma/web/router.ex | 5 ++ 4 files changed, 112 insertions(+) create mode 100644 lib/pleroma/web/mastodon_api/views/push_subscription_view.ex create mode 100644 lib/pleroma/web/push/subscription.ex (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 391a79885..7f06ee607 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1138,6 +1138,33 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json(conn, %{}) end + def create_push_subscription(%{assigns: %{user: user, token: token}} = conn, params) do + Pleroma.Web.Push.Subscription.delete_if_exists(user, token) + {:ok, subscription} = Pleroma.Web.Push.Subscription.create(user, token, params) + view = PushSubscriptionView.render("push_subscription.json", subscription: subscription) + json(conn, view) + end + + def get_push_subscription(%{assigns: %{user: user, token: token}} = conn, params) do + subscription = Pleroma.Web.Push.Subscription.get(user, token) + view = PushSubscriptionView.render("push_subscription.json", subscription: subscription) + json(conn, view) + end + + def update_push_subscription( + %{assigns: %{user: user, token: token}} = conn, + params + ) do + {:ok, subscription} = Pleroma.Web.Push.Subscription.update(user, token, params) + view = PushSubscriptionView.render("push_subscription.json", subscription: subscription) + json(conn, view) + end + + def delete_push_subscription(%{assigns: %{user: user, token: token}} = conn, params) do + {:ok, _response} = Pleroma.Web.Push.Subscription.delete(user, token) + json(conn, %{}) + end + def errors(conn, _) do conn |> put_status(500) diff --git a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex new file mode 100644 index 000000000..a910bb43e --- /dev/null +++ b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex @@ -0,0 +1,14 @@ +defmodule Pleroma.Web.MastodonAPI.PushSubscriptionView do + use Pleroma.Web, :view + alias Pleroma.Web.MastodonAPI.PushSubscriptionView + + def render("push_subscription.json", %{subscription: subscription}) do + %{ + id: to_string(subscription.id), + endpoint: subscription.endpoint, + alerts: Map.get(subscription.data, "alerts"), + # TODO: generate VAPID server key + server_key: "N/A" + } + end +end diff --git a/lib/pleroma/web/push/subscription.ex b/lib/pleroma/web/push/subscription.ex new file mode 100644 index 000000000..dc8fe9f33 --- /dev/null +++ b/lib/pleroma/web/push/subscription.ex @@ -0,0 +1,66 @@ +defmodule Pleroma.Web.Push.Subscription do + use Ecto.Schema + import Ecto.{Changeset, Query} + alias Pleroma.{Repo, User} + alias Pleroma.Web.OAuth.Token + alias Pleroma.Web.Push.Subscription + + schema "push_subscriptions" do + belongs_to(:user, User) + belongs_to(:token, Token) + field(:endpoint, :string) + field(:key_p256dh, :string) + field(:key_auth, :string) + field(:data, :map, default: %{}) + + timestamps() + end + + @supported_alert_types ~w[follow favourite mention reblog] + + defp alerts(%{"data" => %{"alerts" => alerts}}) do + alerts = Map.take(alerts, @supported_alert_types) + %{"alerts" => alerts} + end + + def create( + %User{} = user, + %Token{} = token, + %{ + "subscription" => %{ + "endpoint" => endpoint, + "keys" => %{"auth" => key_auth, "p256dh" => key_p256dh} + } + } = params + ) do + Repo.insert(%Subscription{ + user_id: user.id, + token_id: token.id, + endpoint: endpoint, + key_auth: key_auth, + key_p256dh: key_p256dh, + data: alerts(params) + }) + end + + def get(%User{id: user_id}, %Token{id: token_id}) do + Repo.get_by(Subscription, user_id: user_id, token_id: token_id) + end + + def update(user, token, params) do + get(user, token) + |> change(data: alerts(params)) + |> Repo.update() + end + + def delete(user, token) do + Repo.delete(get(user, token)) + end + + def delete_if_exists(user, token) do + case get(user, token) do + nil -> {:ok, nil} + sub -> Repo.delete(sub) + end + end +end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index ddfaa8c42..04dc80444 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -171,6 +171,11 @@ defmodule Pleroma.Web.Router do put("/filters/:id", MastodonAPIController, :update_filter) delete("/filters/:id", MastodonAPIController, :delete_filter) + post("/push/subscription", MastodonAPIController, :create_push_subscription) + get("/push/subscription", MastodonAPIController, :get_push_subscription) + put("/push/subscription", MastodonAPIController, :update_push_subscription) + delete("/push/subscription", MastodonAPIController, :delete_push_subscription) + get("/suggestions", MastodonAPIController, :suggestions) get("/endorsements", MastodonAPIController, :empty_array) -- cgit v1.2.3 From 5f91d6b8592f601553355e2c94832c90afe17d66 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 1 Dec 2018 18:33:53 +0300 Subject: Fix toggle_deactivated to reactivate a deactivated user --- lib/mix/tasks/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index c20fecaa1..c7c69ed01 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -122,7 +122,7 @@ defmodule Mix.Tasks.Pleroma.User do Mix.Task.run("app.start") with user <- User.get_by_nickname(nickname) do - User.deactivate(user) + User.deactivate(user, !user.info["deactivated"]) end end -- cgit v1.2.3 From 6f174cbb7100bc5ae6a0eba4e7e926704ee11dc3 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 1 Dec 2018 18:34:26 +0300 Subject: Delete reactivate user task --- lib/mix/tasks/reactivate_user.ex | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 lib/mix/tasks/reactivate_user.ex (limited to 'lib') diff --git a/lib/mix/tasks/reactivate_user.ex b/lib/mix/tasks/reactivate_user.ex deleted file mode 100644 index a30d3ac8b..000000000 --- a/lib/mix/tasks/reactivate_user.ex +++ /dev/null @@ -1,19 +0,0 @@ -defmodule Mix.Tasks.ReactivateUser do - use Mix.Task - alias Pleroma.User - - @moduledoc """ - Reactivate a user - - Usage: ``mix reactivate_user `` - - Example: ``mix reactivate_user lain`` - """ - def run([nickname]) do - Mix.Task.run("app.start") - - with user <- User.get_by_nickname(nickname) do - User.deactivate(user, false) - end - end -end -- cgit v1.2.3 From ae82852330105edb681d131fd33cf35557c8614c Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 1 Dec 2018 18:55:52 +0300 Subject: Move set_admin task to lib/mix/tasks/pleroma/user.ex --- lib/mix/tasks/pleroma/user.ex | 26 ++++++++++++++++++++++++++ lib/mix/tasks/set_admin.ex | 32 -------------------------------- 2 files changed, 26 insertions(+), 32 deletions(-) delete mode 100644 lib/mix/tasks/set_admin.ex (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index c7c69ed01..9aa569b2a 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -15,6 +15,7 @@ defmodule Mix.Tasks.Pleroma.User do - `--bio BIO` - the user's bio - `--password PASSWORD` - the user's password - `--moderator`/`--no-moderator` - whether the user is a moderator + - `--admin`/`--no-admin` - whether the user is an admin ## Delete the user's account. @@ -35,6 +36,7 @@ defmodule Mix.Tasks.Pleroma.User do Options: - `--locked`/`--no-locked` - whether the user's account is locked - `--moderator`/`--no-moderator` - whether the user is a moderator + - `--admin`/`--no-admin` - whether the user is an admin """ def run(["new", nickname, email | rest]) do @@ -154,6 +156,7 @@ defmodule Mix.Tasks.Pleroma.User do rest, strict: [ moderator: :boolean, + admin: :boolean, locked: :boolean ] ) @@ -167,6 +170,11 @@ defmodule Mix.Tasks.Pleroma.User do nil -> nil value -> set_locked(nickname, value) end + + case Keyword.get(options, :admin) do + nil -> nil + value -> set_admin(nickname, value) + end end defp set_moderator(nickname, value) do @@ -187,6 +195,24 @@ defmodule Mix.Tasks.Pleroma.User do end end + defp set_admin(nickname, value) do + Application.ensure_all_started(:pleroma) + + with %User{local: true} = user <- User.get_by_nickname(nickname) do + info = + user.info + |> Map.put("is_admin", value) + + cng = User.info_changeset(user, %{info: info}) + {:ok, user} = User.update_and_set_cache(cng) + + Mix.shell().info("Admin status of #{nickname}: #{user.info["is_admin"]}") + else + _ -> + Mix.shell().error("No local user #{nickname}") + end + end + defp set_locked(nickname, value) do Mix.Ecto.ensure_started(Repo, []) diff --git a/lib/mix/tasks/set_admin.ex b/lib/mix/tasks/set_admin.ex deleted file mode 100644 index d5ccf261b..000000000 --- a/lib/mix/tasks/set_admin.ex +++ /dev/null @@ -1,32 +0,0 @@ -defmodule Mix.Tasks.SetAdmin do - use Mix.Task - alias Pleroma.User - - @doc """ - Sets admin status - Usage: set_admin nickname [true|false] - """ - def run([nickname | rest]) do - Application.ensure_all_started(:pleroma) - - status = - case rest do - [status] -> status == "true" - _ -> true - end - - with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("is_admin", !!status) - - cng = User.info_changeset(user, %{info: info}) - {:ok, user} = User.update_and_set_cache(cng) - - IO.puts("Admin status of #{nickname}: #{user.info["is_admin"]}") - else - _ -> - IO.puts("No local user #{nickname}") - end - end -end -- cgit v1.2.3 From a8ef6b1190aff949140e0c79603d833668647a31 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 2 Dec 2018 09:36:31 +0100 Subject: Add admin option to pleroma.user new. Add user existence checking to toggle_activated --- lib/mix/tasks/pleroma/user.ex | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 9aa569b2a..40d920866 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -47,7 +47,8 @@ defmodule Mix.Tasks.Pleroma.User do name: :string, bio: :string, password: :string, - moderator: :boolean + moderator: :boolean, + admin: :boolean ] ) @@ -64,6 +65,7 @@ defmodule Mix.Tasks.Pleroma.User do end moderator? = Keyword.get(options, :moderator, false) + admin? = Keyword.get(options, :admin, false) Mix.shell().info(""" A user will be created with the following information: @@ -75,6 +77,7 @@ defmodule Mix.Tasks.Pleroma.User do - name: #{name} - bio: #{bio} - moderator: #{if(moderator?, do: "true", else: "false")} + - admin: #{if(admin?, do: "true", else: "false")} """) proceed? = Mix.shell().yes?("Continue?") @@ -102,9 +105,14 @@ defmodule Mix.Tasks.Pleroma.User do run(["set", nickname, "--moderator"]) end + if admin? do + run(["set", nickname, "--admin"]) + end + if generated_password? do run(["reset_password", nickname]) end + else Mix.shell().info("User will not be created.") end @@ -115,16 +123,22 @@ defmodule Mix.Tasks.Pleroma.User do with %User{local: true} = user <- User.get_by_nickname(nickname) do User.delete(user) + Mix.shell().info("User #{nickname} deleted.") + else + _ -> + Mix.shell().error("No local user #{nickname}") end - - Mix.shell().info("User #{nickname} deleted.") end def run(["toggle_activated", nickname]) do Mix.Task.run("app.start") - with user <- User.get_by_nickname(nickname) do + with %User{local: true} = user <- User.get_by_nickname(nickname) do User.deactivate(user, !user.info["deactivated"]) + Mix.shell().info("Activation status of #{nickname}: #{user.info["deactivated"]}") + else + _ -> + Mix.shell().error("No local user #{nickname}") end end -- cgit v1.2.3 From 31b3ac05accd3bc56f6663fad554ad67baf0c549 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 2 Dec 2018 10:01:17 +0100 Subject: Lint fix --- lib/mix/tasks/pleroma/user.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 40d920866..d7a6be844 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -112,7 +112,6 @@ defmodule Mix.Tasks.Pleroma.User do if generated_password? do run(["reset_password", nickname]) end - else Mix.shell().info("User will not be created.") end -- cgit v1.2.3 From 6be0ab1e55e2e9f0c1e6f937631cfd3da899bc79 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 2 Dec 2018 17:35:32 +0100 Subject: Hide network in ap. --- lib/pleroma/user/info.ex | 1 + lib/pleroma/web/activity_pub/views/user_view.ex | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 94d403bf7..83fab7e3d 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -24,6 +24,7 @@ defmodule Pleroma.User.Info do field(:topic, :string, default: nil) field(:hub, :string, default: nil) field(:salmon, :string, default: nil) + field(:hide_network, :boolean, default: false) # Found in the wild # ap_id -> Where is this used? diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index aaa777602..869934172 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -82,7 +82,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = from(user in query, select: [:ap_id]) following = Repo.all(query) - collection(following, "#{user.ap_id}/following", page) + collection(following, "#{user.ap_id}/following", page, !user.info.hide_network) |> Map.merge(Utils.make_json_ld_header()) end @@ -95,7 +95,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{user.ap_id}/following", "type" => "OrderedCollection", "totalItems" => length(following), - "first" => collection(following, "#{user.ap_id}/following", 1) + "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_network) } |> Map.merge(Utils.make_json_ld_header()) end @@ -105,7 +105,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = from(user in query, select: [:ap_id]) followers = Repo.all(query) - collection(followers, "#{user.ap_id}/followers", page) + collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_network) |> Map.merge(Utils.make_json_ld_header()) end @@ -118,7 +118,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{user.ap_id}/followers", "type" => "OrderedCollection", "totalItems" => length(followers), - "first" => collection(followers, "#{user.ap_id}/followers", 1) + "first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_network) } |> Map.merge(Utils.make_json_ld_header()) end @@ -172,7 +172,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do end end - def collection(collection, iri, page, total \\ nil) do + def collection(collection, iri, page, show_items \\ true, total \\ nil) do offset = (page - 1) * 10 items = Enum.slice(collection, offset, 10) items = Enum.map(items, fn user -> user.ap_id end) @@ -183,7 +183,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "type" => "OrderedCollectionPage", "partOf" => iri, "totalItems" => total, - "orderedItems" => items + "orderedItems" => if(show_items, do: items, else: []) } if offset < total do -- cgit v1.2.3 From 2a639de9b30aacd44b8ba648b872ad6cb7ab1d6c Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 2 Dec 2018 17:48:00 +0100 Subject: MastodonApi: Implement hide_network. --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index d19d55044..715a2f1a9 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -502,10 +502,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) end - # TODO: Pagination def followers(conn, %{"id" => id}) do with %User{} = user <- Repo.get(User, id), {:ok, followers} <- User.get_followers(user) do + followers = if(user.info.hide_network, do: [], else: followers) render(conn, AccountView, "accounts.json", %{users: followers, as: :user}) end end @@ -513,6 +513,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def following(conn, %{"id" => id}) do with %User{} = user <- Repo.get(User, id), {:ok, followers} <- User.get_friends(user) do + followers = if(user.info.hide_network, do: [], else: followers) render(conn, AccountView, "accounts.json", %{users: followers, as: :user}) end end -- cgit v1.2.3 From 7983b0bdfe40c88d159af2f0562d96e8812c31e3 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 2 Dec 2018 18:05:59 +0100 Subject: Move unsubscribe user task to pleroma/user.ex. Delete unsubscribe_user.ex. Fix pleroma.user toggle_activated to work not only on local users. --- lib/mix/tasks/pleroma/user.ex | 33 +++++++++++++++++++++++++++++++-- lib/mix/tasks/unsubscribe_user.ex | 38 -------------------------------------- 2 files changed, 31 insertions(+), 40 deletions(-) delete mode 100644 lib/mix/tasks/unsubscribe_user.ex (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index d7a6be844..d7e172994 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -132,12 +132,12 @@ defmodule Mix.Tasks.Pleroma.User do def run(["toggle_activated", nickname]) do Mix.Task.run("app.start") - with %User{local: true} = user <- User.get_by_nickname(nickname) do + with %User{} = user <- User.get_by_nickname(nickname) do User.deactivate(user, !user.info["deactivated"]) Mix.shell().info("Activation status of #{nickname}: #{user.info["deactivated"]}") else _ -> - Mix.shell().error("No local user #{nickname}") + Mix.shell().error("No user #{nickname}") end end @@ -163,6 +163,35 @@ defmodule Mix.Tasks.Pleroma.User do end end + def run(["unsubscribe", nickname]) do + Mix.Task.run("app.start") + + with %User{} = user <- User.get_by_nickname(nickname) do + Mix.shell().info("Deactivating #{user.nickname}") + User.deactivate(user) + + {:ok, friends} = User.get_friends(user) + + Enum.each(friends, fn friend -> + user = Repo.get(User, user.id) + + Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}") + User.unfollow(user, friend) + end) + + :timer.sleep(500) + + user = Repo.get(User, user.id) + + if length(user.following) == 0 do + Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}") + end + else + _ -> + Mix.shell().error("No user #{nickname}") + end + end + def run(["set", nickname | rest]) do {options, [], []} = OptionParser.parse( diff --git a/lib/mix/tasks/unsubscribe_user.ex b/lib/mix/tasks/unsubscribe_user.ex deleted file mode 100644 index 62ea61a5c..000000000 --- a/lib/mix/tasks/unsubscribe_user.ex +++ /dev/null @@ -1,38 +0,0 @@ -defmodule Mix.Tasks.UnsubscribeUser do - use Mix.Task - alias Pleroma.{User, Repo} - require Logger - - @moduledoc """ - Deactivate and Unsubscribe local users from a user - - Usage: ``mix unsubscribe_user `` - - Example: ``mix unsubscribe_user lain`` - """ - def run([nickname]) do - Mix.Task.run("app.start") - - with %User{} = user <- User.get_by_nickname(nickname) do - Logger.info("Deactivating #{user.nickname}") - User.deactivate(user) - - {:ok, friends} = User.get_friends(user) - - Enum.each(friends, fn friend -> - user = Repo.get(User, user.id) - - Logger.info("Unsubscribing #{friend.nickname} from #{user.nickname}") - User.unfollow(user, friend) - end) - - :timer.sleep(500) - - user = Repo.get(User, user.id) - - if length(user.following) == 0 do - Logger.info("Successfully unsubscribed all followers from #{user.nickname}") - end - end - end -end -- cgit v1.2.3 From 8c9a4e8b403d4575400f239dd87dab2ae7ecec6c Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 2 Dec 2018 18:14:13 +0100 Subject: TwitterAPI: Implement hide_network. --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index ff644dd79..a59badfdb 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -343,6 +343,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def followers(conn, params) do with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params), {:ok, followers} <- User.get_followers(user) do + followers = if(user.info.hide_network, do: [], else: followers) render(conn, UserView, "index.json", %{users: followers, for: conn.assigns[:user]}) else _e -> bad_request_reply(conn, "Can't get followers") @@ -352,6 +353,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def friends(conn, params) do with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params), {:ok, friends} <- User.get_friends(user) do + friends = if(user.info.hide_network, do: [], else: friends) render(conn, UserView, "index.json", %{users: friends, for: conn.assigns[:user]}) else _e -> bad_request_reply(conn, "Can't get friends") -- cgit v1.2.3 From faf1f2b304d8b2a7e26856e767002f3fcf46d67c Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 2 Dec 2018 19:18:06 +0100 Subject: Move gen.instance to instance.ex --- lib/mix/tasks/pleroma/gen_instance.ex | 161 --------------------------------- lib/mix/tasks/pleroma/instance.ex | 164 ++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+), 161 deletions(-) delete mode 100644 lib/mix/tasks/pleroma/gen_instance.ex create mode 100644 lib/mix/tasks/pleroma/instance.ex (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/gen_instance.ex b/lib/mix/tasks/pleroma/gen_instance.ex deleted file mode 100644 index 94f2220b1..000000000 --- a/lib/mix/tasks/pleroma/gen_instance.ex +++ /dev/null @@ -1,161 +0,0 @@ -defmodule Mix.Tasks.Pleroma.Gen.Instance do - use Mix.Task - - @shortdoc "Generates the configuration for a new instance" - @moduledoc """ - Generates the configuration for a new instance. - - If any options are left unspecified, you will be prompted interactively. This - means the simplest invocation would be - - mix pleroma.gen.instance - - ## Options - - - `-f`, `--force` - overwrite any output files - - `-o PATH`, `--output PATH` - the output file for the generated configuration - - `--output-psql PATH` - the output file for the generated PostgreSQL setup - - `--domain DOMAIN` - the domain of your instance - - `--instance-name INSTANCE_NAME` - the name of your instance - - `--admin-email ADMIN_EMAIL` - the email address of the instance admin - - `--dbhost HOSTNAME` - the hostname of the PostgreSQL database to use - - `--dbname DBNAME` - the name of the database to use - - `--dbuser DBUSER` - the user (aka role) to use for the database connection - - `--dbpass DBPASS` - the password to use for the database connection - """ - - def run(rest) do - {options, [], []} = - OptionParser.parse( - rest, - strict: [ - force: :boolean, - output: :string, - output_psql: :string, - domain: :string, - instance_name: :string, - admin_email: :string, - dbhost: :string, - dbname: :string, - dbuser: :string, - dbpass: :string - ], - aliases: [ - o: :output, - f: :force - ] - ) - - paths = - [config_path, psql_path] = [ - Keyword.get(options, :output, "config/generated_config.exs"), - Keyword.get(options, :output_psql, "config/setup_db.psql") - ] - - will_overwrite = Enum.filter(paths, &File.exists?/1) - proceed? = Enum.empty?(will_overwrite) or Keyword.get(options, :force, false) - - unless not proceed? do - domain = - Keyword.get(options, :domain) || - Mix.shell().prompt("What domain will your instance use? (e.g. pleroma.soykaf.com)") - |> String.trim() - - name = - Keyword.get(options, :name) || - Mix.shell().prompt("What is the name of your instance? (e.g. Pleroma/Soykaf)") - |> String.trim() - - email = - Keyword.get(options, :admin_email) || - Mix.shell().prompt("What is your admin email address?") - |> String.trim() - - dbhost = - Keyword.get(options, :dbhost) || - case Mix.shell().prompt("What is the hostname of your database? [localhost]") do - "\n" -> "localhost" - dbhost -> dbhost |> String.trim() - end - - dbname = - Keyword.get(options, :dbname) || - case Mix.shell().prompt("What is the name of your database? [pleroma_dev]") do - "\n" -> "pleroma_dev" - dbname -> dbname |> String.trim() - end - - dbuser = - Keyword.get(options, :dbuser) || - case Mix.shell().prompt("What is the user used to connect to your database? [pleroma]") do - "\n" -> "pleroma" - dbuser -> dbuser |> String.trim() - end - - dbpass = - Keyword.get(options, :dbpass) || - case Mix.shell().prompt( - "What is the password used to connect to your database? [autogenerated]" - ) do - "\n" -> :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) - dbpass -> dbpass |> String.trim() - end - - secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) - - result_config = - EEx.eval_file( - "sample_config.eex" |> Path.expand(__DIR__), - domain: domain, - email: email, - name: name, - dbhost: dbhost, - dbname: dbname, - dbuser: dbuser, - dbpass: dbpass, - version: Pleroma.Mixfile.project() |> Keyword.get(:version), - secret: secret - ) - - result_psql = - EEx.eval_file( - "sample_psql.eex" |> Path.expand(__DIR__), - dbname: dbname, - dbuser: dbuser, - dbpass: dbpass - ) - - Mix.shell().info( - "Writing config to #{config_path}. You should rename it to config/prod.secret.exs or config/dev.secret.exs." - ) - - File.write(config_path, result_config) - Mix.shell().info("Writing #{psql_path}.") - File.write(psql_path, result_psql) - - Mix.shell().info( - "\n" <> - """ - To get started: - 1. Verify the contents of the generated files. - 2. Run `sudo -u postgres psql -f #{escape_sh_path(psql_path)}`. - """ <> - if config_path in ["config/dev.secret.exs", "config/prod.secret.exs"] do - "" - else - "3. Run `mv #{escape_sh_path(config_path)} 'config/prod.secret.exs'`." - end - ) - else - Mix.shell().error( - "The task would have overwritten the following files:\n" <> - (Enum.map(paths, &"- #{&1}\n") |> Enum.join("")) <> - "Rerun with `--force` to overwrite them." - ) - end - end - - defp escape_sh_path(path) do - ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(') - end -end diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex new file mode 100644 index 000000000..639893985 --- /dev/null +++ b/lib/mix/tasks/pleroma/instance.ex @@ -0,0 +1,164 @@ +defmodule Mix.Tasks.Pleroma.Instance do + use Mix.Task + alias Pleroma.{Repo, User} + + @shortdoc "Manages Pleroma instance" + @moduledoc """ + Manages Pleroma instance. + + ## Generate a new instance. + + mix pleroma.instance new [OPTION...] + + If any options are left unspecified, you will be prompted interactively + + ## Options + + - `-f`, `--force` - overwrite any output files + - `-o PATH`, `--output PATH` - the output file for the generated configuration + - `--output-psql PATH` - the output file for the generated PostgreSQL setup + - `--domain DOMAIN` - the domain of your instance + - `--instance-name INSTANCE_NAME` - the name of your instance + - `--admin-email ADMIN_EMAIL` - the email address of the instance admin + - `--dbhost HOSTNAME` - the hostname of the PostgreSQL database to use + - `--dbname DBNAME` - the name of the database to use + - `--dbuser DBUSER` - the user (aka role) to use for the database connection + - `--dbpass DBPASS` - the password to use for the database connection + """ + + def run(["new" | rest]) do + {options, [], []} = + OptionParser.parse( + rest, + strict: [ + force: :boolean, + output: :string, + output_psql: :string, + domain: :string, + instance_name: :string, + admin_email: :string, + dbhost: :string, + dbname: :string, + dbuser: :string, + dbpass: :string + ], + aliases: [ + o: :output, + f: :force + ] + ) + + paths = + [config_path, psql_path] = [ + Keyword.get(options, :output, "config/generated_config.exs"), + Keyword.get(options, :output_psql, "config/setup_db.psql") + ] + + will_overwrite = Enum.filter(paths, &File.exists?/1) + proceed? = Enum.empty?(will_overwrite) or Keyword.get(options, :force, false) + + unless not proceed? do + domain = + Keyword.get(options, :domain) || + Mix.shell().prompt("What domain will your instance use? (e.g. pleroma.soykaf.com)") + |> String.trim() + + name = + Keyword.get(options, :name) || + Mix.shell().prompt("What is the name of your instance? (e.g. Pleroma/Soykaf)") + |> String.trim() + + email = + Keyword.get(options, :admin_email) || + Mix.shell().prompt("What is your admin email address?") + |> String.trim() + + dbhost = + Keyword.get(options, :dbhost) || + case Mix.shell().prompt("What is the hostname of your database? [localhost]") do + "\n" -> "localhost" + dbhost -> dbhost |> String.trim() + end + + dbname = + Keyword.get(options, :dbname) || + case Mix.shell().prompt("What is the name of your database? [pleroma_dev]") do + "\n" -> "pleroma_dev" + dbname -> dbname |> String.trim() + end + + dbuser = + Keyword.get(options, :dbuser) || + case Mix.shell().prompt("What is the user used to connect to your database? [pleroma]") do + "\n" -> "pleroma" + dbuser -> dbuser |> String.trim() + end + + dbpass = + Keyword.get(options, :dbpass) || + case Mix.shell().prompt( + "What is the password used to connect to your database? [autogenerated]" + ) do + "\n" -> :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) + dbpass -> dbpass |> String.trim() + end + + secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) + + result_config = + EEx.eval_file( + "sample_config.eex" |> Path.expand(__DIR__), + domain: domain, + email: email, + name: name, + dbhost: dbhost, + dbname: dbname, + dbuser: dbuser, + dbpass: dbpass, + version: Pleroma.Mixfile.project() |> Keyword.get(:version), + secret: secret + ) + + result_psql = + EEx.eval_file( + "sample_psql.eex" |> Path.expand(__DIR__), + dbname: dbname, + dbuser: dbuser, + dbpass: dbpass + ) + + Mix.shell().info( + "Writing config to #{config_path}. You should rename it to config/prod.secret.exs or config/dev.secret.exs." + ) + + File.write(config_path, result_config) + Mix.shell().info("Writing #{psql_path}.") + File.write(psql_path, result_psql) + + Mix.shell().info( + "\n" <> + """ + To get started: + 1. Verify the contents of the generated files. + 2. Run `sudo -u postgres psql -f #{escape_sh_path(psql_path)}`. + """ <> + if config_path in ["config/dev.secret.exs", "config/prod.secret.exs"] do + "" + else + "3. Run `mv #{escape_sh_path(config_path)} 'config/prod.secret.exs'`." + end + ) + else + Mix.shell().error( + "The task would have overwritten the following files:\n" <> + (Enum.map(paths, &"- #{&1}\n") |> Enum.join("")) <> + "Rerun with `--force` to overwrite them." + ) + end + end + + defp escape_sh_path(path) do + ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(') + end +end + -- cgit v1.2.3 From cbe22deb510317bca811cc2df30d5cd7e892e4b5 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 2 Dec 2018 19:20:50 +0100 Subject: Lint fix --- lib/mix/tasks/pleroma/instance.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 639893985..8c728625a 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -7,7 +7,7 @@ defmodule Mix.Tasks.Pleroma.Instance do Manages Pleroma instance. ## Generate a new instance. - + mix pleroma.instance new [OPTION...] If any options are left unspecified, you will be prompted interactively @@ -161,4 +161,3 @@ defmodule Mix.Tasks.Pleroma.Instance do ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(') end end - -- cgit v1.2.3 From d924b6cd3da7ad96c522f9de45eb8f7453e0f53a Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 2 Dec 2018 20:04:33 +0100 Subject: Refactor copypasta to a private function in instance.ex --- lib/mix/tasks/pleroma/instance.ex | 74 ++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 36 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 8c728625a..b3e0f99df 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -59,49 +59,37 @@ defmodule Mix.Tasks.Pleroma.Instance do unless not proceed? do domain = - Keyword.get(options, :domain) || - Mix.shell().prompt("What domain will your instance use? (e.g. pleroma.soykaf.com)") - |> String.trim() + get_option( + options, + :domain, + "What domain will your instance use? (e.g pleroma.soykaf.com)" + ) name = - Keyword.get(options, :name) || - Mix.shell().prompt("What is the name of your instance? (e.g. Pleroma/Soykaf)") - |> String.trim() - - email = - Keyword.get(options, :admin_email) || - Mix.shell().prompt("What is your admin email address?") - |> String.trim() - - dbhost = - Keyword.get(options, :dbhost) || - case Mix.shell().prompt("What is the hostname of your database? [localhost]") do - "\n" -> "localhost" - dbhost -> dbhost |> String.trim() - end + get_option(options, :name, "What is the name of your instance? (e.g. Pleroma/Soykaf)") - dbname = - Keyword.get(options, :dbname) || - case Mix.shell().prompt("What is the name of your database? [pleroma_dev]") do - "\n" -> "pleroma_dev" - dbname -> dbname |> String.trim() - end + email = get_option(options, :admin_email, "What is your admin email address?") + + dbhost = get_option(options, :dbhost, "What is the hostname of your database?", "localhost") + + dbname = get_option(options, :dbname, "What is the name of your database?", "pleroma_dev") dbuser = - Keyword.get(options, :dbuser) || - case Mix.shell().prompt("What is the user used to connect to your database? [pleroma]") do - "\n" -> "pleroma" - dbuser -> dbuser |> String.trim() - end + get_option( + options, + :dbuser, + "What is the user used to connect to your database?", + "pleroma" + ) dbpass = - Keyword.get(options, :dbpass) || - case Mix.shell().prompt( - "What is the password used to connect to your database? [autogenerated]" - ) do - "\n" -> :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) - dbpass -> dbpass |> String.trim() - end + get_option( + options, + :dbpass, + "What is the password used to connect to your database?", + :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64), + "autogenerated" + ) secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) @@ -160,4 +148,18 @@ defmodule Mix.Tasks.Pleroma.Instance do defp escape_sh_path(path) do ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(') end + + defp get_option(options, opt, prompt, def \\ nil, defname \\ nil) do + Keyword.get(options, opt) || + case Mix.shell().prompt("#{prompt} [#{defname || def}]") do + "\n" -> + case def do + nil -> get_option(options, opt, prompt, def) + def -> def + end + + opt -> + opt |> String.trim() + end + end end -- cgit v1.2.3 From 57c71f846880083d8a78247f433713963c284ab9 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 2 Dec 2018 20:26:15 +0100 Subject: Move generate_invite to user.ex --- lib/mix/tasks/pleroma/gen_invite.ex | 24 ------------------------ lib/mix/tasks/pleroma/instance.ex | 3 ++- lib/mix/tasks/pleroma/user.ex | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 25 deletions(-) delete mode 100644 lib/mix/tasks/pleroma/gen_invite.ex (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/gen_invite.ex b/lib/mix/tasks/pleroma/gen_invite.ex deleted file mode 100644 index 0aa028f1e..000000000 --- a/lib/mix/tasks/pleroma/gen_invite.ex +++ /dev/null @@ -1,24 +0,0 @@ -defmodule Mix.Tasks.Pleroma.Gen.Invite do - use Mix.Task - - @shortdoc "Generates a user invite token" - def run([]) do - Mix.Task.run("app.start") - - 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: #{url}") - else - _ -> - Mix.shell().error("Could not create invite token.") - end - end -end diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index b3e0f99df..05653c238 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -6,7 +6,7 @@ defmodule Mix.Tasks.Pleroma.Instance do @moduledoc """ Manages Pleroma instance. - ## Generate a new instance. + ## Generate a new instance config. mix pleroma.instance new [OPTION...] @@ -145,6 +145,7 @@ defmodule Mix.Tasks.Pleroma.Instance do end end + defp escape_sh_path(path) do ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(') end diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index d7e172994..c23c5cdf3 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -16,6 +16,10 @@ defmodule Mix.Tasks.Pleroma.User do - `--password PASSWORD` - the user's password - `--moderator`/`--no-moderator` - whether the user is a moderator - `--admin`/`--no-admin` - whether the user is an admin + + ## Generate an invite link. + + mix pleroma.user invite ## Delete the user's account. @@ -255,6 +259,26 @@ defmodule Mix.Tasks.Pleroma.User do end end + def run(["invite"]) do + Mix.Task.run("app.start") + + 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_locked(nickname, value) do Mix.Ecto.ensure_started(Repo, []) -- cgit v1.2.3 From 03b2d1016d25ab2b17a5a511249b4df59c4743fd Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 2 Dec 2018 20:27:49 +0100 Subject: F O R M A T I N G --- lib/mix/tasks/pleroma/instance.ex | 1 - lib/mix/tasks/pleroma/user.ex | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 05653c238..6a85880bf 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -145,7 +145,6 @@ defmodule Mix.Tasks.Pleroma.Instance do end end - defp escape_sh_path(path) do ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(') end diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index c23c5cdf3..39825762d 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -16,7 +16,7 @@ defmodule Mix.Tasks.Pleroma.User do - `--password PASSWORD` - the user's password - `--moderator`/`--no-moderator` - whether the user is a moderator - `--admin`/`--no-admin` - whether the user is an admin - + ## Generate an invite link. mix pleroma.user invite @@ -276,9 +276,9 @@ defmodule Mix.Tasks.Pleroma.User do else _ -> Mix.shell().error("Could not create invite token.") + end end - end defp set_locked(nickname, value) do Mix.Ecto.ensure_started(Repo, []) -- cgit v1.2.3 From a3953ca37ab4122772119ae345705e712e23dd17 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 3 Dec 2018 00:22:19 +0300 Subject: Change @read_bytes to 35 --- lib/pleroma/mime.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/mime.ex b/lib/pleroma/mime.ex index db8b7c742..99063ded6 100644 --- a/lib/pleroma/mime.ex +++ b/lib/pleroma/mime.ex @@ -3,7 +3,7 @@ defmodule Pleroma.MIME do Returns the mime-type of a binary and optionally a normalized file-name. """ @default "application/octet-stream" - @read_bytes 31 + @read_bytes 35 @spec file_mime_type(String.t()) :: {:ok, content_type :: String.t(), filename :: String.t()} | {:error, any()} | :error -- cgit v1.2.3 From 3ce16e5a56be01686a03f40931f666ac164df6e8 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sat, 1 Dec 2018 08:26:59 +0300 Subject: init tesla and updated the http requests in Pleroma.Web.Websub --- lib/pleroma/http/connection.ex | 22 +++++++ lib/pleroma/http/http.ex | 16 ++++- lib/pleroma/http/request_builder.ex | 126 ++++++++++++++++++++++++++++++++++++ lib/pleroma/web/websub/websub.ex | 14 ++-- 4 files changed, 169 insertions(+), 9 deletions(-) create mode 100644 lib/pleroma/http/connection.ex create mode 100644 lib/pleroma/http/request_builder.ex (limited to 'lib') diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex new file mode 100644 index 000000000..12667b663 --- /dev/null +++ b/lib/pleroma/http/connection.ex @@ -0,0 +1,22 @@ +defmodule Pleroma.HTTP.Connection do + @hackney_options [pool: :default] + + @doc """ + Configure a client connection + + # Returns + + Tesla.Env.client + """ + @spec new(Keyword.t()) :: Tesla.Env.client() + def new(opts \\ []) do + Tesla.client([], {Tesla.Adapter.Hackney, hackney_options(opts)}) + end + + # fetch Hackney options + # + defp hackney_options(opts \\ []) do + options = Keyword.get(opts, :adapter, []) + @hackney_options ++ options + end +end diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex index e64266ae7..93ac9d62b 100644 --- a/lib/pleroma/http/http.ex +++ b/lib/pleroma/http/http.ex @@ -1,12 +1,21 @@ defmodule Pleroma.HTTP do require HTTPoison + alias Pleroma.HTTP.Connection + alias Pleroma.HTTP.RequestBuilder, as: Builder def request(method, url, body \\ "", headers \\ [], options \\ []) do options = process_request_options(options) |> process_sni_options(url) - HTTPoison.request(method, url, body, headers, options) + %{} + |> Builder.method(method) + |> Builder.headers(headers) + |> Builder.opts(options) + |> Builder.url(url) + |> Builder.add_param(:body, :body, body) + |> Enum.into([]) + |> (&Tesla.request(Connection.new(), &1)).() end defp process_sni_options(options, url) do @@ -22,7 +31,7 @@ defmodule Pleroma.HTTP do def process_request_options(options) do config = Application.get_env(:pleroma, :http, []) proxy = Keyword.get(config, :proxy_url, nil) - options = options ++ [hackney: [pool: :default]] + options = options ++ [adapter: [pool: :default]] case proxy do nil -> options @@ -30,7 +39,8 @@ defmodule Pleroma.HTTP do end end - def get(url, headers \\ [], options \\ []), do: request(:get, url, "", headers, options) + def get(url, headers \\ [], options \\ []), + do: request(:get, url, "", headers, options) def post(url, body, headers \\ [], options \\ []), do: request(:post, url, body, headers, options) diff --git a/lib/pleroma/http/request_builder.ex b/lib/pleroma/http/request_builder.ex new file mode 100644 index 000000000..5aee2b8ae --- /dev/null +++ b/lib/pleroma/http/request_builder.ex @@ -0,0 +1,126 @@ +defmodule Pleroma.HTTP.RequestBuilder do + @moduledoc """ + Helper functions for building Tesla requests + """ + + @doc """ + Specify the request method when building a request + + ## Parameters + + - request (Map) - Collected request options + - m (atom) - Request method + + ## Returns + + Map + """ + @spec method(map(), atom) :: map() + def method(request, m) do + Map.put_new(request, :method, m) + end + + @doc """ + Specify the request method when building a request + + ## Parameters + + - request (Map) - Collected request options + - u (String) - Request URL + + ## Returns + + Map + """ + @spec url(map(), String.t()) :: map() + def url(request, u) do + Map.put_new(request, :url, u) + end + + @doc """ + Add headers to the request + """ + @spec headers(map(), list(tuple)) :: map() + def headers(request, h) do + Map.put_new(request, :headers, h) + end + + @doc """ + Add custom, per-request middleware or adapter options to the request + """ + @spec opts(map(), Keyword.t()) :: map() + def opts(request, options) do + Map.put_new(request, :opts, options) + end + + @doc """ + Add optional parameters to the request + + ## Parameters + + - request (Map) - Collected request options + - definitions (Map) - Map of parameter name to parameter location. + - options (KeywordList) - The provided optional parameters + + ## Returns + + Map + """ + @spec add_optional_params(map(), %{optional(atom) => atom}, keyword()) :: map() + def add_optional_params(request, _, []), do: request + + def add_optional_params(request, definitions, [{key, value} | tail]) do + case definitions do + %{^key => location} -> + request + |> add_param(location, key, value) + |> add_optional_params(definitions, tail) + + _ -> + add_optional_params(request, definitions, tail) + end + end + + @doc """ + Add optional parameters to the request + + ## Parameters + + - request (Map) - Collected request options + - location (atom) - Where to put the parameter + - key (atom) - The name of the parameter + - value (any) - The value of the parameter + + ## Returns + + Map + """ + @spec add_param(map(), atom, atom, any()) :: map() + def add_param(request, :body, :body, value), do: Map.put(request, :body, value) + + def add_param(request, :body, key, value) do + request + |> Map.put_new_lazy(:body, &Tesla.Multipart.new/0) + |> Map.update!( + :body, + &Tesla.Multipart.add_field(&1, key, Poison.encode!(value), + headers: [{:"Content-Type", "application/json"}] + ) + ) + end + + def add_param(request, :file, name, path) do + request + |> Map.put_new_lazy(:body, &Tesla.Multipart.new/0) + |> Map.update!(:body, &Tesla.Multipart.add_file(&1, path, name: name)) + end + + def add_param(request, :form, name, value) do + request + |> Map.update(:body, %{name => value}, &Map.put(&1, name, value)) + end + + def add_param(request, location, key, value) do + Map.update(request, location, [{key, value}], &(&1 ++ [{key, value}])) + end +end diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 905d8d658..ed1a99d8d 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -173,7 +173,7 @@ defmodule Pleroma.Web.Websub do def gather_feed_data(topic, getter \\ &@httpoison.get/1) do with {:ok, response} <- getter.(topic), - status_code when status_code in 200..299 <- response.status_code, + status_code when status_code in 200..299 <- response.status, body <- response.body, doc <- XML.parse_document(body), uri when not is_nil(uri) <- XML.string_from_xpath("/feed/author[1]/uri", doc), @@ -221,7 +221,7 @@ defmodule Pleroma.Web.Websub do task = Task.async(websub_checker) - with {:ok, %{status_code: 202}} <- + with {:ok, %{status: 202}} <- poster.(websub.hub, {:form, data}, "Content-type": "application/x-www-form-urlencoded"), {:ok, websub} <- Task.yield(task, timeout) do {:ok, websub} @@ -257,7 +257,7 @@ defmodule Pleroma.Web.Websub do signature = sign(secret || "", xml) Logger.info(fn -> "Pushing #{topic} to #{callback}" end) - with {:ok, %{status_code: code}} <- + with {:ok, %{status: code}} <- @httpoison.post( callback, xml, @@ -265,9 +265,11 @@ defmodule Pleroma.Web.Websub do {"Content-Type", "application/atom+xml"}, {"X-Hub-Signature", "sha1=#{signature}"} ], - timeout: 10000, - recv_timeout: 20000, - hackney: [pool: :default] + adapter: [ + timeout: 10000, + recv_timeout: 20000, + pool: :default + ] ) do Logger.info(fn -> "Pushed to #{callback}, code #{code}" end) {:ok, code} -- cgit v1.2.3 From ec34de0c1fd58942c8ecefddef92696750b70420 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sun, 2 Dec 2018 16:58:38 +0300 Subject: WebSub fix test --- lib/pleroma/http/connection.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index 12667b663..f64d4e18e 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -1,5 +1,6 @@ defmodule Pleroma.HTTP.Connection do @hackney_options [pool: :default] + @adapter Application.get_env(:tesla, :adapter) @doc """ Configure a client connection @@ -10,7 +11,7 @@ defmodule Pleroma.HTTP.Connection do """ @spec new(Keyword.t()) :: Tesla.Env.client() def new(opts \\ []) do - Tesla.client([], {Tesla.Adapter.Hackney, hackney_options(opts)}) + Tesla.client([], {@adapter, hackney_options(opts)}) end # fetch Hackney options -- cgit v1.2.3 From 97252a27d9bdde3483cc6d676c0c61150d2174ad Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sun, 2 Dec 2018 17:00:33 +0300 Subject: fix http request in Salmon --- lib/pleroma/web/salmon/salmon.ex | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index b98ece6c9..97251c05e 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -158,14 +158,16 @@ defmodule Pleroma.Web.Salmon do end defp send_to_user(%{info: %{salmon: salmon}}, feed, poster) do - with {:ok, %{status_code: code}} <- + with {:ok, %{status: code}} <- poster.( salmon, feed, [{"Content-Type", "application/magic-envelope+xml"}], - timeout: 10000, - recv_timeout: 20000, - hackney: [pool: :default] + adapter: [ + timeout: 10000, + recv_timeout: 20000, + pool: :default + ] ) do Logger.debug(fn -> "Pushed to #{salmon}, code #{code}" end) else -- cgit v1.2.3 From 87109482f336422186981c80eb3c3023637f09e8 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sun, 2 Dec 2018 17:08:36 +0300 Subject: status_code -> status --- lib/pleroma/uploaders/mdii.ex | 2 +- lib/pleroma/uploaders/swift/keystone.ex | 4 ++-- lib/pleroma/uploaders/swift/swift.ex | 4 ++-- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +- lib/pleroma/web/ostatus/ostatus.ex | 8 +++++--- lib/pleroma/web/web_finger/web_finger.ex | 4 ++-- lib/pleroma/web/websub/websub.ex | 2 +- 8 files changed, 15 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/uploaders/mdii.ex b/lib/pleroma/uploaders/mdii.ex index 35d36d3e4..820cf88f5 100644 --- a/lib/pleroma/uploaders/mdii.ex +++ b/lib/pleroma/uploaders/mdii.ex @@ -20,7 +20,7 @@ defmodule Pleroma.Uploaders.MDII do extension = String.split(upload.name, ".") |> List.last() query = "#{cgi}?#{extension}" - with {:ok, %{status_code: 200, body: body}} <- @httpoison.post(query, file_data) do + with {:ok, %{status: 200, body: body}} <- @httpoison.post(query, file_data) do remote_file_name = String.split(body) |> List.first() public_url = "#{files}/#{remote_file_name}.#{extension}" {:ok, {:url, public_url}} diff --git a/lib/pleroma/uploaders/swift/keystone.ex b/lib/pleroma/uploaders/swift/keystone.ex index e578b3c61..4aed977b1 100644 --- a/lib/pleroma/uploaders/swift/keystone.ex +++ b/lib/pleroma/uploaders/swift/keystone.ex @@ -25,10 +25,10 @@ defmodule Pleroma.Uploaders.Swift.Keystone do ["Content-Type": "application/json"], hackney: [:insecure] ) do - {:ok, %HTTPoison.Response{status_code: 200, body: body}} -> + {:ok, %Tesla.Env{status: 200, body: body}} -> body["access"]["token"]["id"] - {:ok, %HTTPoison.Response{status_code: _}} -> + {:ok, %Tesla.Env{status: _}} -> "" end end diff --git a/lib/pleroma/uploaders/swift/swift.ex b/lib/pleroma/uploaders/swift/swift.ex index 1e865f101..a5b3d2852 100644 --- a/lib/pleroma/uploaders/swift/swift.ex +++ b/lib/pleroma/uploaders/swift/swift.ex @@ -13,10 +13,10 @@ defmodule Pleroma.Uploaders.Swift.Client do token = Pleroma.Uploaders.Swift.Keystone.get_token() case put("#{filename}", body, "X-Auth-Token": token, "Content-Type": content_type) do - {:ok, %HTTPoison.Response{status_code: 201}} -> + {:ok, %Tesla.Env{status: 201}} -> {:ok, {:file, filename}} - {:ok, %HTTPoison.Response{status_code: 401}} -> + {:ok, %Tesla.Env{status: 401}} -> {:error, "Unauthorized, Bad Token"} {:error, _} -> diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 7e207c620..60253a715 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -762,7 +762,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do Logger.info("Fetching #{id} via AP") with true <- String.starts_with?(id, "http"), - {:ok, %{body: body, status_code: code}} when code in 200..299 <- + {:ok, %{body: body, status: code}} when code in 200..299 <- @httpoison.get( id, [Accept: "application/activity+json"], diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 543fdf416..ea64f163d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1168,7 +1168,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do user = user.nickname url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) - with {:ok, %{status_code: 200, body: body}} <- + with {:ok, %{status: 200, body: body}} <- @httpoison.get(url, [], timeout: timeout, recv_timeout: timeout), {:ok, data} <- Jason.decode(body) do data2 = diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 6a27f1730..67df354db 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -346,13 +346,15 @@ defmodule Pleroma.Web.OStatus do def fetch_activity_from_atom_url(url) do with true <- String.starts_with?(url, "http"), - {:ok, %{body: body, status_code: code}} when code in 200..299 <- + {:ok, %{body: body, status: code}} when code in 200..299 <- @httpoison.get( url, [Accept: "application/atom+xml"], follow_redirect: true, - timeout: 10000, - recv_timeout: 20000 + adapter: [ + timeout: 10000, + recv_timeout: 20000 + ] ) do Logger.debug("Got document from #{url}, handling...") handle_incoming(body) diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index eaee3a8c6..99c65a6bf 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -220,7 +220,7 @@ defmodule Pleroma.Web.WebFinger do end def find_lrdd_template(domain) do - with {:ok, %{status_code: status_code, body: body}} when status_code in 200..299 <- + with {:ok, %{status: status, body: body}} when status in 200..299 <- @httpoison.get("http://#{domain}/.well-known/host-meta", [], follow_redirect: true) do get_template_from_xml(body) else @@ -259,7 +259,7 @@ defmodule Pleroma.Web.WebFinger do [Accept: "application/xrd+xml,application/jrd+json"], follow_redirect: true ), - {:ok, %{status_code: status_code, body: body}} when status_code in 200..299 <- response do + {:ok, %{status: status, body: body}} when status in 200..299 <- response do doc = XML.parse_document(body) if doc != :error do diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index ed1a99d8d..0761b5475 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -173,7 +173,7 @@ defmodule Pleroma.Web.Websub do def gather_feed_data(topic, getter \\ &@httpoison.get/1) do with {:ok, response} <- getter.(topic), - status_code when status_code in 200..299 <- response.status, + status when status in 200..299 <- response.status, body <- response.body, doc <- XML.parse_document(body), uri when not is_nil(uri) <- XML.string_from_xpath("/feed/author[1]/uri", doc), -- cgit v1.2.3 From a9e4a975866c33553c477667c431187590329447 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Tue, 4 Dec 2018 14:01:39 +0300 Subject: update test --- lib/pleroma/http/http.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex index 93ac9d62b..59afacf4c 100644 --- a/lib/pleroma/http/http.ex +++ b/lib/pleroma/http/http.ex @@ -18,6 +18,7 @@ defmodule Pleroma.HTTP do |> (&Tesla.request(Connection.new(), &1)).() end + defp process_sni_options(options, nil), do: options defp process_sni_options(options, url) do uri = URI.parse(url) host = uri.host |> to_charlist() -- cgit v1.2.3 From dd8aee332cf939f1a76f60a95b117ab90530178b Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Tue, 4 Dec 2018 17:48:55 +0300 Subject: formatting the code --- lib/pleroma/http/connection.ex | 4 ++++ lib/pleroma/http/http.ex | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index f64d4e18e..5e8f2aabd 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -1,4 +1,8 @@ defmodule Pleroma.HTTP.Connection do + @moduledoc """ + Connection for http-requests. + """ + @hackney_options [pool: :default] @adapter Application.get_env(:tesla, :adapter) diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex index 59afacf4c..4ab12ed3a 100644 --- a/lib/pleroma/http/http.ex +++ b/lib/pleroma/http/http.ex @@ -1,8 +1,10 @@ defmodule Pleroma.HTTP do - require HTTPoison alias Pleroma.HTTP.Connection alias Pleroma.HTTP.RequestBuilder, as: Builder + @doc """ + Builds and perform http request. + """ def request(method, url, body \\ "", headers \\ [], options \\ []) do options = process_request_options(options) @@ -19,6 +21,7 @@ defmodule Pleroma.HTTP do end defp process_sni_options(options, nil), do: options + defp process_sni_options(options, url) do uri = URI.parse(url) host = uri.host |> to_charlist() -- cgit v1.2.3 From 50e72f6c4851d50b27f213b34b5d383b9e8aabb9 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Tue, 4 Dec 2018 17:51:49 +0300 Subject: remove httpoison_mock --- lib/pleroma/http/http.ex | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex index 4ab12ed3a..3c0256575 100644 --- a/lib/pleroma/http/http.ex +++ b/lib/pleroma/http/http.ex @@ -1,9 +1,24 @@ defmodule Pleroma.HTTP do + @moduledoc """ + + """ + alias Pleroma.HTTP.Connection alias Pleroma.HTTP.RequestBuilder, as: Builder @doc """ Builds and perform http request. + + # Arguments: + `method` - :get, :post, :put, :delete + `url` + `body` + `headers` - a keyworld list of headers, e.g. `[{"content-type", "text/plain"}]` + `options` - custom, per-request middleware or adapter options + + # Returns: + `{:ok, %Tesla.Env{}}` or `{:error, error}` + """ def request(method, url, body \\ "", headers \\ [], options \\ []) do options = @@ -43,9 +58,19 @@ defmodule Pleroma.HTTP do end end + @doc """ + Performs GET request. + + See `Pleroma.HTTP.request/5` + """ def get(url, headers \\ [], options \\ []), do: request(:get, url, "", headers, options) + @doc """ + Performs POST request. + + See `Pleroma.HTTP.request/5` + """ def post(url, body, headers \\ [], options \\ []), do: request(:post, url, body, headers, options) end -- cgit v1.2.3 From 826fc446d56b48b67e97144c74bbf74109fb8168 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 4 Dec 2018 18:35:57 +0300 Subject: [#210] TwitterAPI: implemented /api/media/metadata/create to allow uploads description (alt text) setting. --- lib/pleroma/web/router.ex | 1 + lib/pleroma/web/twitter_api/twitter_api_controller.ex | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index d6a9d5779..b7c79d2eb 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -324,6 +324,7 @@ defmodule Pleroma.Web.Router do post("/statusnet/media/upload", TwitterAPI.Controller, :upload) post("/media/upload", TwitterAPI.Controller, :upload_json) + post("/media/metadata/create", TwitterAPI.Controller, :update_media) post("/favorites/create/:id", TwitterAPI.Controller, :favorite) post("/favorites/create", TwitterAPI.Controller, :favorite) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 961250d92..a9e45f91e 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -4,7 +4,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView} alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils - alias Pleroma.{Repo, Activity, User, Notification} + alias Pleroma.{Repo, Activity, Object, User, Notification} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Ecto.Changeset @@ -226,6 +226,22 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + @doc "https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create" + def update_media(%{assigns: %{user: _}} = conn, %{"media_id" => id} = data) do + description = get_in(data, ["alt_text", "text"]) || data["name"] || data["description"] + + with %Object{} = object <- Repo.get(Object, id), is_binary(description) do + new_data = Map.put(object.data, "name", description) + + change = Object.change(object, %{data: new_data}) + {:ok, _} = Repo.update(change) + end + + conn + |> put_status(:no_content) + |> json("") + end + def upload(conn, %{"media" => media}) do response = TwitterAPI.upload(media) -- cgit v1.2.3 From 48e6193bf2c6a03068f1c6a96429fadffaa7794b Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 4 Dec 2018 19:24:41 +0300 Subject: [#210] Refactoring. --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index a9e45f91e..c846dbd60 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -232,9 +232,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do with %Object{} = object <- Repo.get(Object, id), is_binary(description) do new_data = Map.put(object.data, "name", description) - - change = Object.change(object, %{data: new_data}) - {:ok, _} = Repo.update(change) + {:ok, _} = object |> Object.change(%{data: new_data}) |> Repo.update() end conn -- cgit v1.2.3 From 6396f1b58f69b727e801df4b52a32c47da08e517 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Tue, 4 Dec 2018 19:00:45 +0100 Subject: change new to gen in instance.ex . Refactor user.ex --- lib/mix/tasks/pleroma/instance.ex | 4 +- lib/mix/tasks/pleroma/user.ex | 98 +++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 58 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 6a85880bf..eb578644d 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -8,7 +8,7 @@ defmodule Mix.Tasks.Pleroma.Instance do ## Generate a new instance config. - mix pleroma.instance new [OPTION...] + mix pleroma.instance gen [OPTION...] If any options are left unspecified, you will be prompted interactively @@ -26,7 +26,7 @@ defmodule Mix.Tasks.Pleroma.Instance do - `--dbpass DBPASS` - the password to use for the database connection """ - def run(["new" | rest]) do + def run(["gen" | rest]) do {options, [], []} = OptionParser.parse( rest, diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 39825762d..68c6bd2b6 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -197,6 +197,8 @@ defmodule Mix.Tasks.Pleroma.User do end def run(["set", nickname | rest]) do + Application.ensure_all_started(:pleroma) + {options, [], []} = OptionParser.parse( rest, @@ -207,56 +209,58 @@ defmodule Mix.Tasks.Pleroma.User do ] ) - case Keyword.get(options, :moderator) do - nil -> nil - value -> set_moderator(nickname, value) - end - - case Keyword.get(options, :locked) do - nil -> nil - value -> set_locked(nickname, value) - end - - case Keyword.get(options, :admin) do - nil -> nil - value -> set_admin(nickname, value) - end - end - - defp set_moderator(nickname, value) do - Application.ensure_all_started(:pleroma) - with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("is_moderator", value) + case Keyword.get(options, :moderator) do + nil -> nil + value -> set_moderator(user, value) + end - cng = User.info_changeset(user, %{info: info}) - {:ok, user} = User.update_and_set_cache(cng) + case Keyword.get(options, :locked) do + nil -> nil + value -> set_locked(user, value) + end - Mix.shell().info("Moderator status of #{nickname}: #{user.info["is_moderator"]}") + case Keyword.get(options, :admin) do + nil -> nil + value -> set_admin(user, value) + end else _ -> Mix.shell().error("No local user #{nickname}") end end - defp set_admin(nickname, value) do - Application.ensure_all_started(:pleroma) + defp set_moderator(user, value) do + info = + user.info + |> Map.put("is_moderator", value) - with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("is_admin", value) + cng = User.info_changeset(user, %{info: info}) + {:ok, user} = User.update_and_set_cache(cng) - cng = User.info_changeset(user, %{info: info}) - {:ok, user} = User.update_and_set_cache(cng) + Mix.shell().info("Moderator status of #{user.nickname}: #{user.info["is_moderator"]}") + end - Mix.shell().info("Admin status of #{nickname}: #{user.info["is_admin"]}") - else - _ -> - Mix.shell().error("No local user #{nickname}") - end + defp set_admin(user, value) do + info = + user.info + |> Map.put("is_admin", value) + + cng = User.info_changeset(user, %{info: info}) + {:ok, user} = User.update_and_set_cache(cng) + + Mix.shell().info("Admin status of #{user.nickname}: #{user.info["is_admin"]}") + end + + defp set_locked(user, value) do + info = + user.info + |> Map.put("locked", value) + + cng = User.info_changeset(user, %{info: info}) + user = Repo.update!(cng) + + IO.puts("Locked status of #{user.nickname}: #{user.info["locked"]}") end def run(["invite"]) do @@ -278,22 +282,4 @@ defmodule Mix.Tasks.Pleroma.User do Mix.shell().error("Could not create invite token.") end end - - defp set_locked(nickname, value) do - Mix.Ecto.ensure_started(Repo, []) - - with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("locked", value) - - cng = User.info_changeset(user, %{info: info}) - user = Repo.update!(cng) - - IO.puts("Locked status of #{nickname}: #{user.info["locked"]}") - else - _ -> - IO.puts("No local user #{nickname}") - end - end end -- cgit v1.2.3 From b57d83e3c9988e46d30af3383789a7ad01f2eac3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 4 Dec 2018 18:28:38 +0000 Subject: MRF: simple policy: fix media removal --- lib/pleroma/web/activity_pub/mrf/simple_policy.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex index 86dcf5080..12fc3b181 100644 --- a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex @@ -23,7 +23,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do defp check_media_removal( %{host: actor_host} = _actor_info, - %{"type" => "Create", "object" => %{"attachement" => child_attachment}} = object + %{"type" => "Create", "object" => %{"attachment" => child_attachment}} = object ) when length(child_attachment) > 0 do object = -- cgit v1.2.3 From 925b05054ff71b89725b4ba21a9106c63e2a1401 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 4 Dec 2018 19:54:42 +0100 Subject: Make retry queue optional. At the moment, it can use a lot of memory really fast. --- lib/pleroma/web/federator/retry_queue.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex index 06c094f26..13df40c80 100644 --- a/lib/pleroma/web/federator/retry_queue.ex +++ b/lib/pleroma/web/federator/retry_queue.ex @@ -17,7 +17,15 @@ defmodule Pleroma.Web.Federator.RetryQueue do end def start_link() do - GenServer.start_link(__MODULE__, %{delivered: 0, dropped: 0}, name: __MODULE__) + enabled = Pleroma.Config.get([:retry_queue, :enabled], false) + + if enabled do + Logger.info("Starting retry queue") + GenServer.start_link(__MODULE__, %{delivered: 0, dropped: 0}, name: __MODULE__) + else + Logger.info("Retry queue disabled") + :ignore + end end def enqueue(data, transport, retries \\ 0) do -- cgit v1.2.3 From 8a1df182cf836eafc2558be32cf58ad07839f46a Mon Sep 17 00:00:00 2001 From: scarlett Date: Tue, 4 Dec 2018 21:39:18 +0000 Subject: Add a MRF Policy for appending re: to identical subjects in replies. --- .../web/activity_pub/mrf/ensure_re_prepended.ex | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex new file mode 100644 index 000000000..3f216010e --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex @@ -0,0 +1,37 @@ +defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do + alias Pleroma.Activity + + @behaviour Pleroma.Web.ActivityPub.MRF + + def filter_by_summary( + %{"summary" => parent_summary} = parent, + %{"summary" => child_summary} = child + ) + when not is_nil(child_summary) and child_summary == parent_summary and + byte_size(child_summary) > 1 do + if not String.starts_with?(child_summary, "re:") do + Map.put(child, "summary", "re: " <> child_summary) + else + child + end + end + + def filter_by_summary(parent, child), do: child + + def filter(%{"type" => activity_type} = object) when activity_type == "Create" do + child = object["object"] + in_reply_to = Activity.get_create_activity_by_object_ap_id(child["inReplyTo"]) + + child = + if(in_reply_to, + do: filter_by_summary(in_reply_to.data["object"], child), + else: child + ) + + object = Map.put(object, "object", child) + + {:ok, object} + end + + def filter(object), do: {:ok, object} +end -- cgit v1.2.3 From 956f3c75ca8dec32534f432d7bde9f6235a3e7b3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 5 Dec 2018 03:35:41 +0000 Subject: user: put default user info when registering a user --- lib/pleroma/user.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 3bd92c157..74ae5ef0d 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -177,6 +177,7 @@ defmodule Pleroma.User do |> validate_format(:email, @email_regex) |> validate_length(:bio, max: 1000) |> validate_length(:name, min: 1, max: 100) + |> put_change(:info, %Pleroma.User.Info{}) if changeset.valid? do hashed = Pbkdf2.hashpwsalt(changeset.changes[:password]) -- cgit v1.2.3 From a418547bdfc95b72497faa0eb5da69b04f6a8566 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Wed, 5 Dec 2018 16:08:34 +0900 Subject: debug /api/v1/suggestions --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index ea64f163d..f9007a808 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1169,7 +1169,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) with {:ok, %{status: 200, body: body}} <- - @httpoison.get(url, [], timeout: timeout, recv_timeout: timeout), + @httpoison.get( + url, + [], + follow_redirect: true, + adapter: [ + timeout: timeout, + recv_timeout: timeout + ] + ), {:ok, data} <- Jason.decode(body) do data2 = Enum.slice(data, 0, limit) -- cgit v1.2.3 From be187f82f798a904755fc754538d560cde901a88 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 5 Dec 2018 11:48:50 +0300 Subject: [#210] Further refactoring. --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index c846dbd60..c9e845aea 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -226,13 +226,21 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end - @doc "https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create" + @doc """ + Updates metadata of uploaded media object. + Derived from [Twitter API endpoint](https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create). + """ def update_media(%{assigns: %{user: _}} = conn, %{"media_id" => id} = data) do description = get_in(data, ["alt_text", "text"]) || data["name"] || data["description"] - with %Object{} = object <- Repo.get(Object, id), is_binary(description) do + with %Object{} = object <- Repo.get(Object, id), + is_binary(description) do new_data = Map.put(object.data, "name", description) - {:ok, _} = object |> Object.change(%{data: new_data}) |> Repo.update() + + {:ok, _} = + object + |> Object.change(%{data: new_data}) + |> Repo.update() end conn -- cgit v1.2.3 From 848151f7cbf372d008c178d13c9a74942164c955 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 5 Dec 2018 13:37:06 +0300 Subject: [#210] [TwitterAPI] Made actor be stored for uploads. Added ownership check to `update_media` action. Added controller tests for `upload` and `update_media` actions. Refactoring. --- lib/pleroma/web/activity_pub/activity_pub.ex | 3 +- lib/pleroma/web/twitter_api/twitter_api.ex | 8 +++- .../web/twitter_api/twitter_api_controller.ex | 43 ++++++++++++++-------- 3 files changed, 36 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 7e207c620..39692163f 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -574,7 +574,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def upload(file, opts \\ []) do with {:ok, data} <- Upload.store(file, opts) do - Repo.insert(%Object{data: data}) + obj_data = if opts[:actor], do: Map.put(data, "actor", opts[:actor]), else: data + Repo.insert(%Object{data: obj_data}) end end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index c19a4f084..b9468ab03 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -93,8 +93,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do end end - def upload(%Plug.Upload{} = file, format \\ "xml") do - {:ok, object} = ActivityPub.upload(file) + def ap_upload(%Plug.Upload{} = file, %User{} = user) do + ActivityPub.upload(file, actor: User.ap_id(user)) + end + + def upload(%Plug.Upload{} = file, %User{} = user, format \\ "xml") do + {:ok, object} = ap_upload(file, user) url = List.first(object.data["url"]) href = url["href"] diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index c9e845aea..2f12131e7 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -230,34 +230,47 @@ defmodule Pleroma.Web.TwitterAPI.Controller do Updates metadata of uploaded media object. Derived from [Twitter API endpoint](https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-metadata-create). """ - def update_media(%{assigns: %{user: _}} = conn, %{"media_id" => id} = data) do + def update_media(%{assigns: %{user: user}} = conn, %{"media_id" => id} = data) do + object = Repo.get(Object, id) description = get_in(data, ["alt_text", "text"]) || data["name"] || data["description"] - with %Object{} = object <- Repo.get(Object, id), - is_binary(description) do - new_data = Map.put(object.data, "name", description) + {conn, status, response_body} = + cond do + !object -> + {halt(conn), :not_found, ""} - {:ok, _} = - object - |> Object.change(%{data: new_data}) - |> Repo.update() - end + object.data["actor"] != User.ap_id(user) -> + {halt(conn), :forbidden, "You can only update your own uploads."} + + !is_binary(description) -> + {conn, :not_modified, ""} + + true -> + new_data = Map.put(object.data, "name", description) + + {:ok, _} = + object + |> Object.change(%{data: new_data}) + |> Repo.update() + + {conn, :no_content, ""} + end conn - |> put_status(:no_content) - |> json("") + |> put_status(status) + |> json(response_body) end - def upload(conn, %{"media" => media}) do - response = TwitterAPI.upload(media) + def upload(%{assigns: %{user: user}} = conn, %{"media" => media}) do + response = TwitterAPI.upload(media, user) conn |> put_resp_content_type("application/atom+xml") |> send_resp(200, response) end - def upload_json(conn, %{"media" => media}) do - response = TwitterAPI.upload(media, "json") + def upload_json(%{assigns: %{user: user}} = conn, %{"media" => media}) do + response = TwitterAPI.upload(media, user, "json") conn |> json_reply(200, response) -- cgit v1.2.3 From c524c50509d47fe04f2dc48b30ef1c3d6f6d2ffd Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Wed, 5 Dec 2018 17:29:49 +0300 Subject: fix/273 --- lib/pleroma/plugs/oauth_plug.ex | 74 +++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 630f15eec..75f9209c2 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -1,30 +1,68 @@ defmodule Pleroma.Plugs.OAuthPlug do import Plug.Conn - alias Pleroma.User - alias Pleroma.Repo - alias Pleroma.Web.OAuth.Token + import Ecto.Query - def init(options) do - options - end + alias Pleroma.{ + User, + Repo, + Web.OAuth.Token + } + + @realm_reg Regex.compile!("Bearer\:?\s+(.*)$", "i") + + def init(options), do: options def call(%{assigns: %{user: %User{}}} = conn, _), do: conn def call(conn, _) do - token = - case get_req_header(conn, "authorization") do - ["Bearer " <> header] -> header - _ -> get_session(conn, :oauth_token) - end - - with token when not is_nil(token) <- token, - %Token{user_id: user_id} <- Repo.get_by(Token, token: token), - %User{} = user <- Repo.get(User, user_id), - false <- !!user.info.deactivated do - conn - |> assign(:user, user) + with {:ok, token} <- fetch_token(conn), + {:ok, user} <- fetch_user(token) do + assign(conn, :user, user) else _ -> conn end end + + # Gets user by token + # + @spec fetch_user(String.t()) :: {:ok, User.t()} | nil + defp fetch_user(token) do + query = from(q in Token, where: q.token == ^token, preload: [:user]) + + with %Token{user: %{info: %{deactivated: false} = _} = user} <- Repo.one(query) do + {:ok, user} + end + end + + # Gets token from session by :oauth_token key + # + @spec fetch_token_from_session(Plug.Conn.t()) :: :no_token_found | {:ok, String.t()} + defp fetch_token_from_session(conn) do + case get_session(conn, :oauth_token) do + nil -> :no_token_found + token -> {:ok, token} + end + end + + # Gets token from headers + # + @spec fetch_token(Plug.Conn.t()) :: :no_token_found | {:ok, String.t()} + defp fetch_token(%Plug.Conn{} = conn) do + headers = get_req_header(conn, "authorization") + + with :no_token_found <- fetch_token(headers), + do: fetch_token_from_session(conn) + end + + @spec fetch_token(Keyword.t()) :: :no_token_found | {:ok, String.t()} + defp fetch_token([]), do: :no_token_found + + defp fetch_token([token | tail]) do + trimmed_token = String.trim(token) + + case Regex.run(@realm_reg, trimmed_token) do + [_, match] -> {:ok, String.trim(match)} + _ -> fetch_token(tail) + end + end end -- cgit v1.2.3 From 5427d2af3a1bd9a5b571375b4aca2ccd9042b3b9 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Wed, 5 Dec 2018 16:41:50 +0100 Subject: Update mix tasks since User.info.info_changeset is deprecated --- lib/mix/tasks/make_moderator.ex | 14 ++++++-------- lib/mix/tasks/set_admin.ex | 17 ++++++++--------- lib/mix/tasks/set_locked.ex | 18 ++++++++---------- 3 files changed, 22 insertions(+), 27 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/make_moderator.ex b/lib/mix/tasks/make_moderator.ex index 15586dc30..9ea6c45c1 100644 --- a/lib/mix/tasks/make_moderator.ex +++ b/lib/mix/tasks/make_moderator.ex @@ -8,7 +8,7 @@ defmodule Mix.Tasks.SetModerator do """ use Mix.Task - import Mix.Ecto + import Ecto.Changeset alias Pleroma.{Repo, User} def run([nickname | rest]) do @@ -21,14 +21,12 @@ defmodule Mix.Tasks.SetModerator do end with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("is_moderator", !!moderator) + info_cng = User.Info.admin_api_update(user.info, %{is_moderator: !!moderator}) + user_cng = Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) - cng = User.info_changeset(user, %{info: info}) - {:ok, user} = User.update_and_set_cache(cng) - - IO.puts("Moderator status of #{nickname}: #{user.info["is_moderator"]}") + IO.puts("Moderator status of #{nickname}: #{user.info.is_moderator}") else _ -> IO.puts("No local user #{nickname}") diff --git a/lib/mix/tasks/set_admin.ex b/lib/mix/tasks/set_admin.ex index d5ccf261b..9788e49b9 100644 --- a/lib/mix/tasks/set_admin.ex +++ b/lib/mix/tasks/set_admin.ex @@ -1,5 +1,6 @@ defmodule Mix.Tasks.SetAdmin do use Mix.Task + import Ecto.Changeset alias Pleroma.User @doc """ @@ -9,21 +10,19 @@ defmodule Mix.Tasks.SetAdmin do def run([nickname | rest]) do Application.ensure_all_started(:pleroma) - status = + admin = case rest do - [status] -> status == "true" + [admin] -> admin == "true" _ -> true end with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("is_admin", !!status) + info_cng = User.Info.admin_api_update(user.info, %{is_admin: !!admin}) + user_cng = Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) - cng = User.info_changeset(user, %{info: info}) - {:ok, user} = User.update_and_set_cache(cng) - - IO.puts("Admin status of #{nickname}: #{user.info["is_admin"]}") + IO.puts("Admin status of #{nickname}: #{user.info.is_admin}") else _ -> IO.puts("No local user #{nickname}") diff --git a/lib/mix/tasks/set_locked.ex b/lib/mix/tasks/set_locked.ex index a154595ca..42d978599 100644 --- a/lib/mix/tasks/set_locked.ex +++ b/lib/mix/tasks/set_locked.ex @@ -8,13 +8,13 @@ defmodule Mix.Tasks.SetLocked do Example: ``mix set_locked lain`` """ - + use Mix.Task - import Mix.Ecto + import Ecto.Changeset alias Pleroma.{Repo, User} def run([nickname | rest]) do - ensure_started(Repo, []) + Application.ensure_all_started(:pleroma) locked = case rest do @@ -23,14 +23,12 @@ defmodule Mix.Tasks.SetLocked do end with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("locked", !!locked) - - cng = User.info_changeset(user, %{info: info}) - user = Repo.update!(cng) + info_cng = User.Info.profile_update(user.info, %{locked: !!locked}) + user_cng = Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) - IO.puts("locked status of #{nickname}: #{user.info["locked"]}") + IO.puts("Locked status of #{nickname}: #{user.info.locked}") else _ -> IO.puts("No local user #{nickname}") -- cgit v1.2.3 From c3519132dfdcd5f59c0ebe99fa8ab4b764ac4982 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Wed, 5 Dec 2018 16:44:15 +0100 Subject: Sorry --- lib/mix/tasks/make_moderator.ex | 7 +++++-- lib/mix/tasks/set_admin.ex | 7 +++++-- lib/mix/tasks/set_locked.ex | 9 ++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/make_moderator.ex b/lib/mix/tasks/make_moderator.ex index 9ea6c45c1..8dc0a04dd 100644 --- a/lib/mix/tasks/make_moderator.ex +++ b/lib/mix/tasks/make_moderator.ex @@ -22,8 +22,11 @@ defmodule Mix.Tasks.SetModerator do with %User{local: true} = user <- User.get_by_nickname(nickname) do info_cng = User.Info.admin_api_update(user.info, %{is_moderator: !!moderator}) - user_cng = Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) + + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) IO.puts("Moderator status of #{nickname}: #{user.info.is_moderator}") diff --git a/lib/mix/tasks/set_admin.ex b/lib/mix/tasks/set_admin.ex index 9788e49b9..ac26516f1 100644 --- a/lib/mix/tasks/set_admin.ex +++ b/lib/mix/tasks/set_admin.ex @@ -18,8 +18,11 @@ defmodule Mix.Tasks.SetAdmin do with %User{local: true} = user <- User.get_by_nickname(nickname) do info_cng = User.Info.admin_api_update(user.info, %{is_admin: !!admin}) - user_cng = Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) + + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) IO.puts("Admin status of #{nickname}: #{user.info.is_admin}") diff --git a/lib/mix/tasks/set_locked.ex b/lib/mix/tasks/set_locked.ex index 42d978599..e93a63505 100644 --- a/lib/mix/tasks/set_locked.ex +++ b/lib/mix/tasks/set_locked.ex @@ -8,7 +8,7 @@ defmodule Mix.Tasks.SetLocked do Example: ``mix set_locked lain`` """ - + use Mix.Task import Ecto.Changeset alias Pleroma.{Repo, User} @@ -24,8 +24,11 @@ defmodule Mix.Tasks.SetLocked do with %User{local: true} = user <- User.get_by_nickname(nickname) do info_cng = User.Info.profile_update(user.info, %{locked: !!locked}) - user_cng = Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) + + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) IO.puts("Locked status of #{nickname}: #{user.info.locked}") -- cgit v1.2.3 From e8ba579efe7d9ca4be32c5aacf62be0de1ec09df Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Wed, 5 Dec 2018 17:58:26 +0100 Subject: Switch from User.info_changeset because it is deprecated --- lib/mix/tasks/pleroma/user.ex | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 68c6bd2b6..14ba60bf4 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -1,5 +1,6 @@ defmodule Mix.Tasks.Pleroma.User do use Mix.Task + import Ecto.Changeset alias Pleroma.{Repo, User} @shortdoc "Manages Pleroma users" @@ -235,10 +236,14 @@ defmodule Mix.Tasks.Pleroma.User do user.info |> Map.put("is_moderator", value) - cng = User.info_changeset(user, %{info: info}) - {:ok, user} = User.update_and_set_cache(cng) + info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value}) + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) - Mix.shell().info("Moderator status of #{user.nickname}: #{user.info["is_moderator"]}") + {:ok, user} = User.update_and_set_cache(user_cng) + + Mix.shell().info("Moderator status of #{user.nickname}: #{user.info.is_moderator}") end defp set_admin(user, value) do @@ -246,10 +251,14 @@ defmodule Mix.Tasks.Pleroma.User do user.info |> Map.put("is_admin", value) - cng = User.info_changeset(user, %{info: info}) - {:ok, user} = User.update_and_set_cache(cng) + info_cng = User.Info.admin_api_update(user.info, %{is_admin: value}) + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + + {:ok, user} = User.update_and_set_cache(user_cng) - Mix.shell().info("Admin status of #{user.nickname}: #{user.info["is_admin"]}") + Mix.shell().info("Admin status of #{user.nickname}: #{user.info.is_moderator}") end defp set_locked(user, value) do @@ -257,10 +266,14 @@ defmodule Mix.Tasks.Pleroma.User do user.info |> Map.put("locked", value) - cng = User.info_changeset(user, %{info: info}) - user = Repo.update!(cng) + info_cng = User.Info.user_upgrade(user.info, %{locked: value}) + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + + {:ok, user} = User.update_and_set_cache(user_cng) - IO.puts("Locked status of #{user.nickname}: #{user.info["locked"]}") + Mix.shell().info("Locked status of #{user.nickname}: #{user.info.locked}") end def run(["invite"]) do -- cgit v1.2.3 From facfd03bc1f9ec2464fb0b78ece2c7d3162521db Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Wed, 5 Dec 2018 18:11:59 +0100 Subject: Move relay tasks to relay.ex --- lib/mix/tasks/pleroma/relay.ex | 42 +++++++++++++++++++++++++++++++++++++++++ lib/mix/tasks/relay_follow.ex | 24 ----------------------- lib/mix/tasks/relay_unfollow.ex | 23 ---------------------- 3 files changed, 42 insertions(+), 47 deletions(-) create mode 100644 lib/mix/tasks/pleroma/relay.ex delete mode 100644 lib/mix/tasks/relay_follow.ex delete mode 100644 lib/mix/tasks/relay_unfollow.ex (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex new file mode 100644 index 000000000..aa0232a32 --- /dev/null +++ b/lib/mix/tasks/pleroma/relay.ex @@ -0,0 +1,42 @@ +defmodule Mix.Tasks.Pleroma.Relay do + use Mix.Task + alias Pleroma.Web.ActivityPub.Relay + + @shortdoc "Manages remote relays" + @moduledoc """ + Manages remote relays + + ## Follow a remote relay + + ``mix pleroma.relay unfollow `` + + Example: ``mix pleroma.relay follow https://example.org/relay`` + + ## Unfollow a remote relay + + ``mix pleroma.relay unfollow `` + + Example: ``mix pleroma.relay unfollow https://example.org/relay`` + """ + def run(["follow", target]) do + Mix.Task.run("app.start") + + 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 + {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}") + end + end + + def run(["unfollow", target]) do + Mix.Task.run("app.start") + + 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 + {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}") + end + end +end diff --git a/lib/mix/tasks/relay_follow.ex b/lib/mix/tasks/relay_follow.ex deleted file mode 100644 index 85b1c024d..000000000 --- a/lib/mix/tasks/relay_follow.ex +++ /dev/null @@ -1,24 +0,0 @@ -defmodule Mix.Tasks.RelayFollow do - use Mix.Task - require Logger - alias Pleroma.Web.ActivityPub.Relay - - @shortdoc "Follows a remote relay" - @moduledoc """ - Follows a remote relay - - Usage: ``mix relay_follow `` - - Example: ``mix relay_follow https://example.org/relay`` - """ - def run([target]) do - Mix.Task.run("app.start") - - 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 - {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}") - end - end -end diff --git a/lib/mix/tasks/relay_unfollow.ex b/lib/mix/tasks/relay_unfollow.ex deleted file mode 100644 index 237fb771c..000000000 --- a/lib/mix/tasks/relay_unfollow.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule Mix.Tasks.RelayUnfollow do - use Mix.Task - require Logger - alias Pleroma.Web.ActivityPub.Relay - - @moduledoc """ - Unfollows a remote relay - - Usage: ``mix relay_follow `` - - Example: ``mix relay_follow https://example.org/relay`` - """ - def run([target]) do - Mix.Task.run("app.start") - - 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 - {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}") - end - end -end -- cgit v1.2.3 From c4f3c5e939638905f94cdee53db7a0704a80d133 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 5 Dec 2018 20:23:28 +0300 Subject: [#210] Stylistic change. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 39692163f..4eb9d96ab 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -574,7 +574,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def upload(file, opts \\ []) do with {:ok, data} <- Upload.store(file, opts) do - obj_data = if opts[:actor], do: Map.put(data, "actor", opts[:actor]), else: data + obj_data = (opts[:actor] && Map.put(data, "actor", opts[:actor])) || data Repo.insert(%Object{data: obj_data}) end end -- cgit v1.2.3 From ffec96d8ccee6d51e3806d209ae176fb2c589beb Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Wed, 5 Dec 2018 19:05:37 +0100 Subject: Everything should use Mix.Task.Run --- lib/mix/tasks/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 14ba60bf4..e2b9b6236 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -198,7 +198,7 @@ defmodule Mix.Tasks.Pleroma.User do end def run(["set", nickname | rest]) do - Application.ensure_all_started(:pleroma) + Mix.Task.run("app.start") {options, [], []} = OptionParser.parse( -- cgit v1.2.3 From dfc9c08796055c723fac11dd13eea90d340fa0ae Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Wed, 5 Dec 2018 19:12:23 +0100 Subject: formating --- lib/mix/tasks/pleroma/relay.ex | 4 ++-- lib/mix/tasks/pleroma/user.ex | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index aa0232a32..eaaded5cb 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -11,9 +11,9 @@ defmodule Mix.Tasks.Pleroma.Relay do ``mix pleroma.relay unfollow `` Example: ``mix pleroma.relay follow https://example.org/relay`` - + ## Unfollow a remote relay - + ``mix pleroma.relay unfollow `` Example: ``mix pleroma.relay unfollow https://example.org/relay`` diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index e2b9b6236..aa023aae8 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -237,9 +237,10 @@ defmodule Mix.Tasks.Pleroma.User do |> Map.put("is_moderator", value) info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value}) - user_cng = - Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) + + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) {:ok, user} = User.update_and_set_cache(user_cng) @@ -252,9 +253,10 @@ defmodule Mix.Tasks.Pleroma.User do |> Map.put("is_admin", value) info_cng = User.Info.admin_api_update(user.info, %{is_admin: value}) - user_cng = - Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) + + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) {:ok, user} = User.update_and_set_cache(user_cng) @@ -267,9 +269,10 @@ defmodule Mix.Tasks.Pleroma.User do |> Map.put("locked", value) info_cng = User.Info.user_upgrade(user.info, %{locked: value}) - user_cng = - Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) + + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) {:ok, user} = User.update_and_set_cache(user_cng) -- cgit v1.2.3 From 839526a9134ba85c0a45fe85740d04a54076224c Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 5 Dec 2018 19:22:40 +0100 Subject: TwitterAPI: Add network hiding. --- lib/pleroma/user/info.ex | 3 ++- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 83fab7e3d..cefe33577 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -135,7 +135,8 @@ defmodule Pleroma.User.Info do :locked, :no_rich_text, :default_scope, - :banner + :banner, + :hide_network ]) end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index a59badfdb..959312683 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -431,7 +431,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do defp build_info_cng(user, params) do info_params = - ["no_rich_text", "locked"] + ["no_rich_text", "locked", "hide_network"] |> Enum.reduce(%{}, fn key, res -> if value = params[key] do Map.put(res, key, value == "true") -- cgit v1.2.3 From 3b5be09f4544ab1b3f6821fd4bbe047f94ef71ac Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 5 Dec 2018 21:48:21 +0300 Subject: [#210] Stylistic change. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 4eb9d96ab..39692163f 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -574,7 +574,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def upload(file, opts \\ []) do with {:ok, data} <- Upload.store(file, opts) do - obj_data = (opts[:actor] && Map.put(data, "actor", opts[:actor])) || data + obj_data = if opts[:actor], do: Map.put(data, "actor", opts[:actor]), else: data Repo.insert(%Object{data: obj_data}) end end -- cgit v1.2.3 From 3ccfe226c0e7710c2321b19643a43fcc6458a1e9 Mon Sep 17 00:00:00 2001 From: Vald Date: Thu, 6 Dec 2018 01:05:41 +0530 Subject: added data attrs for user and tag --- lib/pleroma/formatter.ex | 10 +++++++--- lib/pleroma/html.ex | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 1a5c07c8a..5b03e9aeb 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -114,7 +114,7 @@ defmodule Pleroma.Formatter do subs = subs ++ - Enum.map(mentions, fn {match, %User{ap_id: ap_id, info: info}, uuid} -> + Enum.map(mentions, fn {match, %User{id: id, ap_id: ap_id, info: info}, uuid} -> ap_id = if is_binary(info.source_data["url"]) do info.source_data["url"] @@ -125,7 +125,7 @@ defmodule Pleroma.Formatter do short_match = String.split(match, "@") |> tl() |> hd() {uuid, - "@#{short_match}"} + "@#{short_match}"} end) {subs, uuid_text} @@ -147,7 +147,11 @@ defmodule Pleroma.Formatter do subs = subs ++ Enum.map(tags, fn {tag_text, tag, uuid} -> - url = "" + url = + "" + {uuid, url} end) diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 1b920d7fd..271a48b57 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -86,7 +86,7 @@ defmodule Pleroma.HTML.Scrubber.Default do Meta.remove_cdata_sections_before_scrub() Meta.strip_comments() - Meta.allow_tag_with_uri_attributes("a", ["href"], @valid_schemes) + Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes) Meta.allow_tag_with_these_attributes("a", ["name", "title"]) Meta.allow_tag_with_these_attributes("abbr", ["title"]) -- cgit v1.2.3 From fdac215091332d5f7df818855b62e600870d6786 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 5 Dec 2018 21:14:06 +0100 Subject: TwitterAPI: Show users their own network. --- .../web/twitter_api/twitter_api_controller.ex | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 959312683..591557cca 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -340,20 +340,32 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end - def followers(conn, params) do - with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params), + def followers(%{assigns: %{user: for_user}} = conn, params) do + with {:ok, user} <- TwitterAPI.get_user(for_user, params), {:ok, followers} <- User.get_followers(user) do - followers = if(user.info.hide_network, do: [], else: followers) + followers = + cond do + for_user && user.id == for_user.id -> followers + user.info.hide_network -> [] + true -> followers + end + render(conn, UserView, "index.json", %{users: followers, for: conn.assigns[:user]}) else _e -> bad_request_reply(conn, "Can't get followers") end end - def friends(conn, params) do + def friends(%{assigns: %{user: for_user}} = conn, params) do with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params), {:ok, friends} <- User.get_friends(user) do - friends = if(user.info.hide_network, do: [], else: friends) + friends = + cond do + for_user && user.id == for_user.id -> friends + user.info.hide_network -> [] + true -> friends + end + render(conn, UserView, "index.json", %{users: friends, for: conn.assigns[:user]}) else _e -> bad_request_reply(conn, "Can't get friends") -- cgit v1.2.3 From 3ea4476445a5e9b6ec1625d7caa537f79254e9d0 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 5 Dec 2018 21:25:06 +0100 Subject: MastodonAPI: Show users their own network. --- .../web/mastodon_api/mastodon_api_controller.ex | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 715a2f1a9..c8b2eae4d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -502,18 +502,30 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) end - def followers(conn, %{"id" => id}) do + def followers(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do with %User{} = user <- Repo.get(User, id), {:ok, followers} <- User.get_followers(user) do - followers = if(user.info.hide_network, do: [], else: followers) + followers = + cond do + for_user && user.id == for_user.id -> followers + user.info.hide_network -> [] + true -> followers + end + render(conn, AccountView, "accounts.json", %{users: followers, as: :user}) end end - def following(conn, %{"id" => id}) do + def following(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do with %User{} = user <- Repo.get(User, id), {:ok, followers} <- User.get_friends(user) do - followers = if(user.info.hide_network, do: [], else: followers) + followers = + cond do + for_user && user.id == for_user.id -> followers + user.info.hide_network -> [] + true -> followers + end + render(conn, AccountView, "accounts.json", %{users: followers, as: :user}) end end -- cgit v1.2.3 From 7d5720f2e40015502fe646b86768ab8454f571fe Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 5 Dec 2018 21:31:02 +0100 Subject: Fix merge. --- lib/pleroma/user/info.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 6829c26f6..7a99787f8 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -136,7 +136,7 @@ defmodule Pleroma.User.Info do :no_rich_text, :default_scope, :banner, - :hide_network + :hide_network, :background ]) end -- cgit v1.2.3 From 194869c7db1d31b139254d3a0c6a449cee0068fe Mon Sep 17 00:00:00 2001 From: Vald Date: Thu, 6 Dec 2018 02:14:56 +0530 Subject: added data attrs to twitter scrubber --- lib/pleroma/html.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 271a48b57..5daaa5e69 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -45,7 +45,7 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do Meta.strip_comments() # links - Meta.allow_tag_with_uri_attributes("a", ["href"], @valid_schemes) + Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes) Meta.allow_tag_with_these_attributes("a", ["name", "title"]) # paragraphs and linebreaks -- cgit v1.2.3 From 27792b2d77564717e7d4063ab3524ab9e1cb1fb6 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Thu, 6 Dec 2018 11:23:15 +0900 Subject: remove pool and timeout options which duplicate with the default --- lib/pleroma/http/connection.ex | 6 +++++- lib/pleroma/web/activity_pub/activity_pub.ex | 4 +--- lib/pleroma/web/ostatus/ostatus.ex | 9 ++------- lib/pleroma/web/salmon/salmon.ex | 7 +------ lib/pleroma/web/websub/websub.ex | 5 ----- 5 files changed, 9 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index 5e8f2aabd..66e0d0568 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -3,7 +3,11 @@ defmodule Pleroma.HTTP.Connection do Connection for http-requests. """ - @hackney_options [pool: :default] + @hackney_options [ + pool: :default, + timeout: 10000, + recv_timeout: 20000 + ] @adapter Application.get_env(:tesla, :adapter) @doc """ diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 60253a715..03a607f83 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -766,9 +766,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do @httpoison.get( id, [Accept: "application/activity+json"], - follow_redirect: true, - timeout: 10000, - recv_timeout: 20000 + follow_redirect: true ), {:ok, data} <- Jason.decode(body), :ok <- Transmogrifier.contain_origin_from_id(id, data) do diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 67df354db..bc14b8785 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -350,11 +350,7 @@ defmodule Pleroma.Web.OStatus do @httpoison.get( url, [Accept: "application/atom+xml"], - follow_redirect: true, - adapter: [ - timeout: 10000, - recv_timeout: 20000 - ] + follow_redirect: true ) do Logger.debug("Got document from #{url}, handling...") handle_incoming(body) @@ -369,8 +365,7 @@ defmodule Pleroma.Web.OStatus do Logger.debug("Trying to fetch #{url}") with true <- String.starts_with?(url, "http"), - {:ok, %{body: body}} <- - @httpoison.get(url, [], follow_redirect: true, timeout: 10000, recv_timeout: 20000), + {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true), {:ok, atom_url} <- get_atom_url(body) do fetch_activity_from_atom_url(atom_url) else diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 97251c05e..0e2cfddd0 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -162,12 +162,7 @@ defmodule Pleroma.Web.Salmon do poster.( salmon, feed, - [{"Content-Type", "application/magic-envelope+xml"}], - adapter: [ - timeout: 10000, - recv_timeout: 20000, - pool: :default - ] + [{"Content-Type", "application/magic-envelope+xml"}] ) do Logger.debug(fn -> "Pushed to #{salmon}, code #{code}" end) else diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 0761b5475..8cb07006f 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -264,11 +264,6 @@ defmodule Pleroma.Web.Websub do [ {"Content-Type", "application/atom+xml"}, {"X-Hub-Signature", "sha1=#{signature}"} - ], - adapter: [ - timeout: 10000, - recv_timeout: 20000, - pool: :default ] ) do Logger.info(fn -> "Pushed to #{callback}, code #{code}" end) -- cgit v1.2.3 From 96ba95df2e6690c1c6a58cf087c91eab7af728b4 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Thu, 6 Dec 2018 11:38:33 +0900 Subject: remove follow_redirect options --- lib/pleroma/http/connection.ex | 3 ++- lib/pleroma/reverse_proxy.ex | 2 +- lib/pleroma/web/activity_pub/activity_pub.ex | 3 +-- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 1 - lib/pleroma/web/ostatus/ostatus.ex | 5 ++--- lib/pleroma/web/web_finger/web_finger.ex | 2 +- 6 files changed, 7 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index 66e0d0568..db46f9e55 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -6,7 +6,8 @@ defmodule Pleroma.HTTP.Connection do @hackney_options [ pool: :default, timeout: 10000, - recv_timeout: 20000 + recv_timeout: 20000, + follow_redirect: true ] @adapter Application.get_env(:tesla, :adapter) diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index ad9dc82fe..4ca84152a 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -56,7 +56,7 @@ defmodule Pleroma.ReverseProxy do @hackney Application.get_env(:pleroma, :hackney, :hackney) @httpoison Application.get_env(:pleroma, :httpoison, HTTPoison) - @default_hackney_options [{:follow_redirect, true}] + @default_hackney_options [] @inline_content_types [ "image/gif", diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 03a607f83..922ffb946 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -765,8 +765,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {:ok, %{body: body, status: code}} when code in 200..299 <- @httpoison.get( id, - [Accept: "application/activity+json"], - follow_redirect: true + Accept: "application/activity+json" ), {:ok, data} <- Jason.decode(body), :ok <- Transmogrifier.contain_origin_from_id(id, data) do diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 300bdc04a..fc4f3fdc7 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1185,7 +1185,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do @httpoison.get( url, [], - follow_redirect: true, adapter: [ timeout: timeout, recv_timeout: timeout diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index bc14b8785..9f33cd5cd 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -349,8 +349,7 @@ defmodule Pleroma.Web.OStatus do {:ok, %{body: body, status: code}} when code in 200..299 <- @httpoison.get( url, - [Accept: "application/atom+xml"], - follow_redirect: true + Accept: "application/atom+xml" ) do Logger.debug("Got document from #{url}, handling...") handle_incoming(body) @@ -365,7 +364,7 @@ defmodule Pleroma.Web.OStatus do Logger.debug("Trying to fetch #{url}") with true <- String.starts_with?(url, "http"), - {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true), + {:ok, %{body: body}} <- @httpoison.get(url, []), {:ok, atom_url} <- get_atom_url(body) do fetch_activity_from_atom_url(atom_url) else diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 99c65a6bf..0ff3b8b5f 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -221,7 +221,7 @@ defmodule Pleroma.Web.WebFinger do def find_lrdd_template(domain) do with {:ok, %{status: status, body: body}} when status in 200..299 <- - @httpoison.get("http://#{domain}/.well-known/host-meta", [], follow_redirect: true) do + @httpoison.get("http://#{domain}/.well-known/host-meta", []) do get_template_from_xml(body) else _ -> -- cgit v1.2.3 From 3e90f688f14310e92fe9343f2680c58d74f71cb6 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 6 Dec 2018 10:26:17 +0300 Subject: [#210] Mastodon: actor storing for media uploads, ownership check to update_media. Refactoring. --- lib/pleroma/object.ex | 9 +++++- lib/pleroma/web/activity_pub/activity_pub.ex | 8 ++++- .../web/mastodon_api/mastodon_api_controller.ex | 34 ++++++++++------------ lib/pleroma/web/twitter_api/twitter_api.ex | 6 +--- .../web/twitter_api/twitter_api_controller.ex | 2 +- 5 files changed, 33 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 03a75dfbd..31c8dd5bd 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -1,6 +1,6 @@ defmodule Pleroma.Object do use Ecto.Schema - alias Pleroma.{Repo, Object, Activity} + alias Pleroma.{Repo, Object, User, Activity} import Ecto.{Query, Changeset} schema "objects" do @@ -31,6 +31,13 @@ defmodule Pleroma.Object do def normalize(ap_id) when is_binary(ap_id), do: Object.get_by_ap_id(ap_id) def normalize(_), do: nil + # Owned objects can only be mutated by their owner + def authorize_mutation(%Object{data: %{"actor" => actor}}, %User{ap_id: ap_id}), + do: actor == ap_id + + # Legacy objects can be mutated by anybody + def authorize_mutation(%Object{}, %User{}), do: true + if Mix.env() == :test do def get_cached_by_ap_id(ap_id) do get_by_ap_id(ap_id) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 39692163f..aaf9d3854 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -574,7 +574,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def upload(file, opts \\ []) do with {:ok, data} <- Upload.store(file, opts) do - obj_data = if opts[:actor], do: Map.put(data, "actor", opts[:actor]), else: data + obj_data = + if opts[:actor] do + Map.put(data, "actor", opts[:actor]) + else + data + end + Repo.insert(%Object{data: obj_data}) end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 543fdf416..ef204f7f3 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -433,33 +433,31 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> json([]) end - def update_media(%{assigns: %{user: _}} = conn, data) do + def update_media(%{assigns: %{user: user}} = conn, data) do with %Object{} = object <- Repo.get(Object, data["id"]), + true <- Object.authorize_mutation(object, user), true <- is_binary(data["description"]), description <- data["description"] do new_data = %{object.data | "name" => description} - change = Object.change(object, %{data: new_data}) - {:ok, _} = Repo.update(change) + {:ok, _} = + object + |> Object.change(%{data: new_data}) + |> Repo.update() - data = - new_data - |> Map.put("id", object.id) - - render(conn, StatusView, "attachment.json", %{attachment: data}) + attachment_data = Map.put(new_data, "id", object.id) + render(conn, StatusView, "attachment.json", %{attachment: attachment_data}) end end - def upload(%{assigns: %{user: _}} = conn, %{"file" => file} = data) do - with {:ok, object} <- ActivityPub.upload(file, description: Map.get(data, "description")) do - change = Object.change(object, %{data: object.data}) - {:ok, object} = Repo.update(change) - - objdata = - object.data - |> Map.put("id", object.id) - - render(conn, StatusView, "attachment.json", %{attachment: objdata}) + def upload(%{assigns: %{user: user}} = conn, %{"file" => file} = data) do + with {:ok, object} <- + ActivityPub.upload(file, + actor: User.ap_id(user), + description: Map.get(data, "description") + ) do + attachment_data = Map.put(object.data, "id", object.id) + render(conn, StatusView, "attachment.json", %{attachment: attachment_data}) end end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index b9468ab03..9c485d965 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -93,12 +93,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do end end - def ap_upload(%Plug.Upload{} = file, %User{} = user) do - ActivityPub.upload(file, actor: User.ap_id(user)) - end - def upload(%Plug.Upload{} = file, %User{} = user, format \\ "xml") do - {:ok, object} = ap_upload(file, user) + {:ok, object} = ActivityPub.upload(file, actor: User.ap_id(user)) url = List.first(object.data["url"]) href = url["href"] diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 2f12131e7..c19ee230f 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -239,7 +239,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do !object -> {halt(conn), :not_found, ""} - object.data["actor"] != User.ap_id(user) -> + !Object.authorize_mutation(object, user) -> {halt(conn), :forbidden, "You can only update your own uploads."} !is_binary(description) -> -- cgit v1.2.3 From a09ed0f5afe6336763b47edab0c0d9a629a74ad0 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Thu, 6 Dec 2018 18:41:29 +0900 Subject: avoid mix format bug --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/ostatus/ostatus.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 922ffb946..a1637ccad 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -765,7 +765,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {:ok, %{body: body, status: code}} when code in 200..299 <- @httpoison.get( id, - Accept: "application/activity+json" + [{:Accept, "application/activity+json"}] ), {:ok, data} <- Jason.decode(body), :ok <- Transmogrifier.contain_origin_from_id(id, data) do diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 9f33cd5cd..53d71440e 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -349,7 +349,7 @@ defmodule Pleroma.Web.OStatus do {:ok, %{body: body, status: code}} when code in 200..299 <- @httpoison.get( url, - Accept: "application/atom+xml" + [{:Accept, "application/atom+xml"}] ) do Logger.debug("Got document from #{url}, handling...") handle_incoming(body) -- cgit v1.2.3 From 6a6aaa0e1aade45bc2e3b68ee2c4686cc80f46cd Mon Sep 17 00:00:00 2001 From: scarlett Date: Thu, 6 Dec 2018 11:37:29 +0000 Subject: Use object.normalize. --- lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex index 3f216010e..06fafb3ee 100644 --- a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex +++ b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex @@ -1,5 +1,5 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do - alias Pleroma.Activity + alias Pleroma.Object @behaviour Pleroma.Web.ActivityPub.MRF @@ -20,11 +20,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do def filter(%{"type" => activity_type} = object) when activity_type == "Create" do child = object["object"] - in_reply_to = Activity.get_create_activity_by_object_ap_id(child["inReplyTo"]) + in_reply_to = Object.normalize(child["inReplyTo"]) child = if(in_reply_to, - do: filter_by_summary(in_reply_to.data["object"], child), + do: filter_by_summary(in_reply_to.data, child), else: child ) -- cgit v1.2.3 From 04a48286e69704bf83429b85dbcdb70863bdcff1 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 6 Dec 2018 19:29:04 +0700 Subject: Add web push support --- lib/mix/tasks/generate_config.ex | 6 +- lib/mix/tasks/sample_config.eex | 6 + lib/pleroma/application.ex | 3 +- lib/pleroma/notification.ex | 1 + .../web/mastodon_api/mastodon_api_controller.ex | 6 +- lib/pleroma/web/push/push.ex | 126 +++++++++++++++++++++ lib/pleroma/web/push/subscription.ex | 2 +- .../web/twitter_api/controllers/util_controller.ex | 6 +- 8 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 lib/pleroma/web/push/push.ex (limited to 'lib') diff --git a/lib/mix/tasks/generate_config.ex b/lib/mix/tasks/generate_config.ex index 70a110561..58ce3113b 100644 --- a/lib/mix/tasks/generate_config.ex +++ b/lib/mix/tasks/generate_config.ex @@ -14,6 +14,8 @@ defmodule Mix.Tasks.GenerateConfig do resultSql = EEx.eval_file("lib/mix/tasks/sample_psql.eex", dbpass: dbpass) + {web_push_public_key, web_push_private_key} = :crypto.generate_key(:ecdh, :prime256v1) + result = EEx.eval_file( "lib/mix/tasks/sample_config.eex", @@ -21,7 +23,9 @@ defmodule Mix.Tasks.GenerateConfig do email: email, name: name, secret: secret, - dbpass: dbpass + dbpass: dbpass, + web_push_public_key: Base.url_encode64(web_push_public_key, padding: false), + web_push_private_key: Base.url_encode64(web_push_private_key, padding: false) ) IO.puts( diff --git a/lib/mix/tasks/sample_config.eex b/lib/mix/tasks/sample_config.eex index 3881ead26..f2272b10a 100644 --- a/lib/mix/tasks/sample_config.eex +++ b/lib/mix/tasks/sample_config.eex @@ -25,6 +25,12 @@ config :pleroma, Pleroma.Repo, hostname: "localhost", pool_size: 10 +# Configure web push notifications +config :web_push_encryption, :vapid_details, + subject: "mailto:<%= email %>", + public_key: "<%= web_push_public_key %>", + private_key: "<%= web_push_private_key %>" + # Configure S3 support if desired. # The public S3 endpoint is different depending on region and provider, # consult your S3 provider's documentation for details on what to use. diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index a89728471..565e938fd 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -41,7 +41,8 @@ defmodule Pleroma.Application do ), worker(Pleroma.Web.Federator, []), worker(Pleroma.Gopher.Server, []), - worker(Pleroma.Stats, []) + worker(Pleroma.Stats, []), + worker(Pleroma.Web.Push, []) ] ++ if Mix.env() == :test, do: [], diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index e0dcd9823..6163413c8 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -96,6 +96,7 @@ defmodule Pleroma.Notification do notification = %Notification{user_id: user.id, activity: activity} {:ok, notification} = Repo.insert(notification) Pleroma.Web.Streamer.stream("user", notification) + Pleroma.Web.Push.send(notification) notification end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 7f06ee607..de5b2696f 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1138,6 +1138,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json(conn, %{}) end + alias Pleroma.Web.MastodonAPI.PushSubscriptionView + def create_push_subscription(%{assigns: %{user: user, token: token}} = conn, params) do Pleroma.Web.Push.Subscription.delete_if_exists(user, token) {:ok, subscription} = Pleroma.Web.Push.Subscription.create(user, token, params) @@ -1145,7 +1147,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json(conn, view) end - def get_push_subscription(%{assigns: %{user: user, token: token}} = conn, params) do + def get_push_subscription(%{assigns: %{user: user, token: token}} = conn, _params) do subscription = Pleroma.Web.Push.Subscription.get(user, token) view = PushSubscriptionView.render("push_subscription.json", subscription: subscription) json(conn, view) @@ -1160,7 +1162,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json(conn, view) end - def delete_push_subscription(%{assigns: %{user: user, token: token}} = conn, params) do + def delete_push_subscription(%{assigns: %{user: user, token: token}} = conn, _params) do {:ok, _response} = Pleroma.Web.Push.Subscription.delete(user, token) json(conn, %{}) end diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex new file mode 100644 index 000000000..d27750ab6 --- /dev/null +++ b/lib/pleroma/web/push/push.ex @@ -0,0 +1,126 @@ +defmodule Pleroma.Web.Push do + use GenServer + + alias Pleroma.{Repo, User} + alias Pleroma.Web.Push.Subscription + + require Logger + import Ecto.Query + + @types ["Create", "Follow", "Announce", "Like"] + + @gcm_api_key nil + + def start_link() do + GenServer.start_link(__MODULE__, :ok, name: __MODULE__) + end + + def init(:ok) do + case Application.get_env(:web_push_encryption, :vapid_details) do + nil -> + Logger.error( + "VAPID key pair is not found. Please, add VAPID configuration to config. Run `mix web_push.gen.keypair` mix task to create a key pair" + ) + + {:error, %{}} + + _ -> + {:ok, %{}} + end + end + + def send(notification) do + GenServer.cast(Pleroma.Web.Push, {:send, notification}) + end + + def handle_cast( + {:send, %{activity: %{data: %{"type" => type}}, user_id: user_id} = notification}, + state + ) + when type in @types do + actor = User.get_cached_by_ap_id(notification.activity.data["actor"]) + body = notification |> format(actor) |> Jason.encode!() + + Subscription + |> where(user_id: ^user_id) + |> Repo.all() + |> Enum.each(fn record -> + subscription = %{ + keys: %{ + p256dh: record.key_p256dh, + auth: record.key_auth + }, + endpoint: record.endpoint + } + + case WebPushEncryption.send_web_push(body, subscription, @gcm_api_key) do + {:ok, %{status_code: code}} when 400 <= code and code < 500 -> + Logger.debug("Removing subscription record") + Repo.delete!(record) + :ok + + {:ok, %{status_code: code}} when 200 <= code and code < 300 -> + :ok + + {:ok, %{status_code: code}} -> + Logger.error("Web Push Nonification failed with code: #{code}") + :error + + data -> + Logger.error("Web Push Nonification failed with unknown error") + IO.inspect(data) + :error + end + end) + + {:noreply, state} + end + + def handle_cast({:send, _}, state) do + Logger.warn("Unknown notification type") + {:noreply, state} + end + + def format(%{activity: %{data: %{"type" => "Create"}}}, actor) do + %{ + title: "New Mention", + body: "@#{actor.nickname} has mentiond you", + icon: get_avatar_url(actor) + } + end + + def format(%{activity: %{data: %{"type" => "Follow"}}}, actor) do + %{ + title: "New Follower", + body: "@#{actor.nickname} has followed you", + icon: get_avatar_url(actor) + } + end + + def format(%{activity: %{data: %{"type" => "Announce"}}}, actor) do + %{ + title: "New Announce", + body: "@#{actor.nickname} has announced your post", + icon: get_avatar_url(actor) + } + end + + def format(%{activity: %{data: %{"type" => "Like"}}}, actor) do + %{ + title: "New Like", + body: "@#{actor.nickname} has liked your post", + icon: get_avatar_url(actor) + } + end + + def get_avatar_url(%{avatar: %{"type" => "Image", "url" => urls}}) do + case List.first(urls) do + %{"href" => url} -> url + _ -> get_avatar_url(nil) + end + end + + def get_avatar_url(_) do + Pleroma.Web.Endpoint.static_url() <> "/images/avi.png" + end +end diff --git a/lib/pleroma/web/push/subscription.ex b/lib/pleroma/web/push/subscription.ex index dc8fe9f33..cfab7a98e 100644 --- a/lib/pleroma/web/push/subscription.ex +++ b/lib/pleroma/web/push/subscription.ex @@ -1,6 +1,6 @@ defmodule Pleroma.Web.Push.Subscription do use Ecto.Schema - import Ecto.{Changeset, Query} + import Ecto.Changeset alias Pleroma.{Repo, User} alias Pleroma.Web.OAuth.Token alias Pleroma.Web.Push.Subscription diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 886b70f5f..f06020a3e 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -156,13 +156,17 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do |> send_resp(200, response) _ -> + vapid_public_key = + Keyword.get(Application.get_env(:web_push_encryption, :vapid_details), :public_key) + data = %{ name: Keyword.get(@instance, :name), description: Keyword.get(@instance, :description), server: Web.base_url(), textlimit: to_string(Keyword.get(@instance, :limit)), closed: if(Keyword.get(@instance, :registrations_open), do: "0", else: "1"), - private: if(Keyword.get(@instance, :public, true), do: "0", else: "1") + private: if(Keyword.get(@instance, :public, true), do: "0", else: "1"), + vapidPublicKey: vapid_public_key } pleroma_fe = %{ -- cgit v1.2.3 From bac58b152495c3ebf72e3ad1c3102de075fcc366 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 6 Dec 2018 19:56:56 +0700 Subject: show warning if VAPID is not set --- lib/pleroma/web/push/push.ex | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index d27750ab6..4ac3be8a3 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -18,11 +18,11 @@ defmodule Pleroma.Web.Push do def init(:ok) do case Application.get_env(:web_push_encryption, :vapid_details) do nil -> - Logger.error( + Logger.warn( "VAPID key pair is not found. Please, add VAPID configuration to config. Run `mix web_push.gen.keypair` mix task to create a key pair" ) - {:error, %{}} + :ignore _ -> {:ok, %{}} @@ -30,7 +30,9 @@ defmodule Pleroma.Web.Push do end def send(notification) do - GenServer.cast(Pleroma.Web.Push, {:send, notification}) + if Application.get_env(:web_push_encryption, :vapid_details) do + GenServer.cast(Pleroma.Web.Push, {:send, notification}) + end end def handle_cast( -- cgit v1.2.3 From 3d492795b76cfe3b3616607f815a0effe44c1ce5 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 6 Dec 2018 20:42:00 +0700 Subject: clean up --- lib/pleroma/web/mastodon_api/views/push_subscription_view.ex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex index a910bb43e..68bb45494 100644 --- a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex +++ b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex @@ -6,9 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.PushSubscriptionView do %{ id: to_string(subscription.id), endpoint: subscription.endpoint, - alerts: Map.get(subscription.data, "alerts"), - # TODO: generate VAPID server key - server_key: "N/A" + alerts: Map.get(subscription.data, "alerts") } end end -- cgit v1.2.3 From 3dff61ebec4f4b216903d79261ec5cac80e70a08 Mon Sep 17 00:00:00 2001 From: scarlett Date: Thu, 6 Dec 2018 13:48:12 +0000 Subject: Harden re: detection. --- lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex index 06fafb3ee..a3b9c4616 100644 --- a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex +++ b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex @@ -3,13 +3,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do @behaviour Pleroma.Web.ActivityPub.MRF + @have_re Regex.compile!("^re:[[:space:]]*", [:caseless]) def filter_by_summary( %{"summary" => parent_summary} = parent, %{"summary" => child_summary} = child ) - when not is_nil(child_summary) and child_summary == parent_summary and - byte_size(child_summary) > 1 do - if not String.starts_with?(child_summary, "re:") do + when not is_nil(child_summary) and byte_size(child_summary) > 0 and + not is_nil(parent_summary) and byte_size(parent_summary) > 0 do + if (child_summary == parent_summary and not Regex.match?(@have_re, child_summary)) or + (Regex.match?(@have_re, parent_summary) && + Regex.replace(@have_re, parent_summary, "") == child_summary) do Map.put(child, "summary", "re: " <> child_summary) else child -- cgit v1.2.3 From 79668c08fc566dad6ecb9d2909a23612f91d06ed Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 6 Dec 2018 20:50:20 +0700 Subject: cleanup --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 15 +++++++++++---- lib/pleroma/web/push/push.ex | 1 - 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index dd6b0a361..c9530c748 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -2,13 +2,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do use Pleroma.Web, :controller alias Pleroma.{Repo, Object, Activity, User, Notification, Stats} alias Pleroma.Web - alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView, ListView, FilterView} + + alias Pleroma.Web.MastodonAPI.{ + StatusView, + AccountView, + MastodonView, + ListView, + FilterView, + PushSubscriptionView + } + alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.CommonAPI alias Pleroma.Web.OAuth.{Authorization, Token, App} alias Pleroma.Web.MediaProxy - alias Comeonin.Pbkdf2 + import Ecto.Query require Logger @@ -1160,8 +1169,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json(conn, %{}) end - alias Pleroma.Web.MastodonAPI.PushSubscriptionView - def create_push_subscription(%{assigns: %{user: user, token: token}} = conn, params) do Pleroma.Web.Push.Subscription.delete_if_exists(user, token) {:ok, subscription} = Pleroma.Web.Push.Subscription.create(user, token, params) diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index 4ac3be8a3..4e9bc5741 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -70,7 +70,6 @@ defmodule Pleroma.Web.Push do data -> Logger.error("Web Push Nonification failed with unknown error") - IO.inspect(data) :error end end) -- cgit v1.2.3 From 6f36e903b0a8702ec279df29c1d039cb08a574d4 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 6 Dec 2018 20:55:46 +0700 Subject: use `User.avatar_url` --- lib/pleroma/web/push/push.ex | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index 4e9bc5741..5a873ec19 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -68,7 +68,7 @@ defmodule Pleroma.Web.Push do Logger.error("Web Push Nonification failed with code: #{code}") :error - data -> + _ -> Logger.error("Web Push Nonification failed with unknown error") :error end @@ -86,7 +86,7 @@ defmodule Pleroma.Web.Push do %{ title: "New Mention", body: "@#{actor.nickname} has mentiond you", - icon: get_avatar_url(actor) + icon: User.avatar_url(actor) } end @@ -94,7 +94,7 @@ defmodule Pleroma.Web.Push do %{ title: "New Follower", body: "@#{actor.nickname} has followed you", - icon: get_avatar_url(actor) + icon: User.avatar_url(actor) } end @@ -102,7 +102,7 @@ defmodule Pleroma.Web.Push do %{ title: "New Announce", body: "@#{actor.nickname} has announced your post", - icon: get_avatar_url(actor) + icon: User.avatar_url(actor) } end @@ -110,18 +110,7 @@ defmodule Pleroma.Web.Push do %{ title: "New Like", body: "@#{actor.nickname} has liked your post", - icon: get_avatar_url(actor) + icon: User.avatar_url(actor) } end - - def get_avatar_url(%{avatar: %{"type" => "Image", "url" => urls}}) do - case List.first(urls) do - %{"href" => url} -> url - _ -> get_avatar_url(nil) - end - end - - def get_avatar_url(_) do - Pleroma.Web.Endpoint.static_url() <> "/images/avi.png" - end end -- cgit v1.2.3 From d27e3f269f5e93efd91397ada72656120be3db41 Mon Sep 17 00:00:00 2001 From: scarlett Date: Thu, 6 Dec 2018 14:00:41 +0000 Subject: Rename regular expression 'have_re' to 'reply_prefix'. --- lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex index a3b9c4616..c8c74ede6 100644 --- a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex +++ b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex @@ -3,16 +3,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do @behaviour Pleroma.Web.ActivityPub.MRF - @have_re Regex.compile!("^re:[[:space:]]*", [:caseless]) + @reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless]) def filter_by_summary( %{"summary" => parent_summary} = parent, %{"summary" => child_summary} = child ) when not is_nil(child_summary) and byte_size(child_summary) > 0 and not is_nil(parent_summary) and byte_size(parent_summary) > 0 do - if (child_summary == parent_summary and not Regex.match?(@have_re, child_summary)) or - (Regex.match?(@have_re, parent_summary) && - Regex.replace(@have_re, parent_summary, "") == child_summary) do + if (child_summary == parent_summary and not Regex.match?(@reply_prefix, child_summary)) or + (Regex.match?(@reply_prefix, parent_summary) && + Regex.replace(@reply_prefix, parent_summary, "") == child_summary) do Map.put(child, "summary", "re: " <> child_summary) else child -- cgit v1.2.3 From 2ae1128d9f7a89aff6ba7fb3d486a00f76dbc28b Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 6 Dec 2018 17:42:07 +0300 Subject: MastoAPI: Fix put_settings --- lib/pleroma/user.ex | 4 ---- lib/pleroma/user/info.ex | 5 +++++ lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 8 +++++--- 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 74ae5ef0d..9da674982 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -62,10 +62,6 @@ defmodule Pleroma.User do |> validate_required([:following]) end - def info_changeset(struct, params \\ %{}) do - raise "NOT VALID ANYMORE" - end - def user_info(%User{} = user) do oneself = if user.local, do: 1, else: 0 diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 7a99787f8..d81b45b8d 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -149,6 +149,11 @@ defmodule Pleroma.User.Info do ]) end + def mastodon_settings_update(info, params) do + info + |> cast(params, [:settings]) + end + def set_source_data(info, source_data) do params = %{source_data: source_data} diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index eecfc742b..e8dd9db15 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -970,9 +970,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do - with new_info <- Map.put(user.info, "settings", settings), - change <- User.info_changeset(user, %{info: new_info}), - {:ok, _user} <- User.update_and_set_cache(change) do + info_cng = User.Info.mastodon_settings_update(user.info, settings) + + with changeset <- User.update_changeset(user), + changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng), + {:ok, user} <- User.update_and_set_cache(changeset) do conn |> json(%{}) else -- cgit v1.2.3 From 3a84511df10b647f08d5ec2df789663b60646c02 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Thu, 6 Dec 2018 17:35:33 +0100 Subject: remove migrate_local_uploads.ex --- lib/mix/tasks/migrate_local_uploads.ex | 97 ---------------------------------- 1 file changed, 97 deletions(-) delete mode 100644 lib/mix/tasks/migrate_local_uploads.ex (limited to 'lib') diff --git a/lib/mix/tasks/migrate_local_uploads.ex b/lib/mix/tasks/migrate_local_uploads.ex deleted file mode 100644 index 8f9e210c0..000000000 --- a/lib/mix/tasks/migrate_local_uploads.ex +++ /dev/null @@ -1,97 +0,0 @@ -defmodule Mix.Tasks.MigrateLocalUploads do - use Mix.Task - import Mix.Ecto - alias Pleroma.{Upload, Uploaders.Local, Uploaders.S3} - require Logger - - @log_every 50 - @shortdoc "Migrate uploads from local to remote storage" - - def run([target_uploader | args]) do - delete? = Enum.member?(args, "--delete") - Application.ensure_all_started(:pleroma) - - local_path = Pleroma.Config.get!([Local, :uploads]) - uploader = Module.concat(Pleroma.Uploaders, target_uploader) - - unless Code.ensure_loaded?(uploader) do - raise("The uploader #{inspect(uploader)} is not an existing/loaded module.") - end - - target_enabled? = Pleroma.Config.get([Upload, :uploader]) == uploader - - unless target_enabled? do - Pleroma.Config.put([Upload, :uploader], uploader) - end - - Logger.info("Migrating files from local #{local_path} to #{to_string(uploader)}") - - if delete? do - Logger.warn( - "Attention: uploaded files will be deleted, hope you have backups! (--delete ; cancel with ^C)" - ) - - :timer.sleep(:timer.seconds(5)) - end - - uploads = - File.ls!(local_path) - |> Enum.map(fn id -> - root_path = Path.join(local_path, id) - - cond do - File.dir?(root_path) -> - files = for file <- File.ls!(root_path), do: {id, file, Path.join([root_path, file])} - - case List.first(files) do - {id, file, path} -> - {%Pleroma.Upload{id: id, name: file, path: id <> "/" <> file, tempfile: path}, - root_path} - - _ -> - nil - end - - File.exists?(root_path) -> - file = Path.basename(id) - [hash, ext] = String.split(id, ".") - {%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path} - - true -> - nil - end - end) - |> Enum.filter(& &1) - - total_count = length(uploads) - Logger.info("Found #{total_count} uploads") - - uploads - |> Task.async_stream( - fn {upload, root_path} -> - case Upload.store(upload, uploader: uploader, filters: [], size_limit: nil) do - {:ok, _} -> - if delete?, do: File.rm_rf!(root_path) - Logger.debug("uploaded: #{inspect(upload.path)} #{inspect(upload)}") - :ok - - error -> - Logger.error("failed to upload #{inspect(upload.path)}: #{inspect(error)}") - end - end, - timeout: 150_000 - ) - |> Stream.chunk_every(@log_every) - |> Enum.reduce(0, fn done, count -> - count = count + length(done) - Logger.info("Uploaded #{count}/#{total_count} files") - count - end) - - Logger.info("Done!") - end - - def run(_) do - Logger.error("Usage: migrate_local_uploads S3|Swift [--delete]") - end -end -- cgit v1.2.3 From 4a2a7ce636ac4616ec71665b4af4ee0ab884ac15 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Thu, 6 Dec 2018 18:00:24 +0100 Subject: Refactor common functions to common.ex --- lib/mix/tasks/pleroma/instance.ex | 34 ++++++++++------------------------ lib/mix/tasks/pleroma/relay.ex | 6 +++--- lib/mix/tasks/pleroma/user.ex | 16 ++++++++-------- 3 files changed, 21 insertions(+), 35 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index eb578644d..88fc3ba75 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -1,6 +1,7 @@ defmodule Mix.Tasks.Pleroma.Instance do use Mix.Task alias Pleroma.{Repo, User} + alias Mix.Tasks.Pleroma.Common @shortdoc "Manages Pleroma instance" @moduledoc """ @@ -59,23 +60,23 @@ defmodule Mix.Tasks.Pleroma.Instance do unless not proceed? do domain = - get_option( + Common.get_option( options, :domain, "What domain will your instance use? (e.g pleroma.soykaf.com)" ) name = - get_option(options, :name, "What is the name of your instance? (e.g. Pleroma/Soykaf)") + Common.get_option(options, :name, "What is the name of your instance? (e.g. Pleroma/Soykaf)") - email = get_option(options, :admin_email, "What is your admin email address?") + email = Common.get_option(options, :admin_email, "What is your admin email address?") - dbhost = get_option(options, :dbhost, "What is the hostname of your database?", "localhost") + dbhost = Common.get_option(options, :dbhost, "What is the hostname of your database?", "localhost") - dbname = get_option(options, :dbname, "What is the name of your database?", "pleroma_dev") + dbname = Common.get_option(options, :dbname, "What is the name of your database?", "pleroma_dev") dbuser = - get_option( + Common.get_option( options, :dbuser, "What is the user used to connect to your database?", @@ -83,7 +84,7 @@ defmodule Mix.Tasks.Pleroma.Instance do ) dbpass = - get_option( + Common.get_option( options, :dbpass, "What is the password used to connect to your database?", @@ -128,12 +129,12 @@ defmodule Mix.Tasks.Pleroma.Instance do """ To get started: 1. Verify the contents of the generated files. - 2. Run `sudo -u postgres psql -f #{escape_sh_path(psql_path)}`. + 2. Run `sudo -u postgres psql -f #{Common.escape_sh_path(psql_path)}`. """ <> if config_path in ["config/dev.secret.exs", "config/prod.secret.exs"] do "" else - "3. Run `mv #{escape_sh_path(config_path)} 'config/prod.secret.exs'`." + "3. Run `mv #{Common.escape_sh_path(config_path)} 'config/prod.secret.exs'`." end ) else @@ -145,21 +146,6 @@ defmodule Mix.Tasks.Pleroma.Instance do end end - defp escape_sh_path(path) do - ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(') - end - defp get_option(options, opt, prompt, def \\ nil, defname \\ nil) do - Keyword.get(options, opt) || - case Mix.shell().prompt("#{prompt} [#{defname || def}]") do - "\n" -> - case def do - nil -> get_option(options, opt, prompt, def) - def -> def - end - opt -> - opt |> String.trim() - end - end end diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index eaaded5cb..828c7cd3d 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -1,6 +1,7 @@ defmodule Mix.Tasks.Pleroma.Relay do use Mix.Task alias Pleroma.Web.ActivityPub.Relay + alias Mix.Tasks.Pleroma.Common @shortdoc "Manages remote relays" @moduledoc """ @@ -19,8 +20,7 @@ defmodule Mix.Tasks.Pleroma.Relay do Example: ``mix pleroma.relay unfollow https://example.org/relay`` """ def run(["follow", target]) do - Mix.Task.run("app.start") - + Common.start_pleroma with {:ok, activity} <- Relay.follow(target) do # put this task to sleep to allow the genserver to push out the messages :timer.sleep(500) @@ -30,7 +30,7 @@ defmodule Mix.Tasks.Pleroma.Relay do end def run(["unfollow", target]) do - Mix.Task.run("app.start") + Common.start_pleroma with {:ok, activity} <- Relay.follow(target) do # put this task to sleep to allow the genserver to push out the messages diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index aa023aae8..82f351456 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -2,6 +2,7 @@ defmodule Mix.Tasks.Pleroma.User do use Mix.Task import Ecto.Changeset alias Pleroma.{Repo, User} + alias Mix.Tasks.Pleroma.Common @shortdoc "Manages Pleroma users" @moduledoc """ @@ -43,7 +44,6 @@ defmodule Mix.Tasks.Pleroma.User do - `--moderator`/`--no-moderator` - whether the user is a moderator - `--admin`/`--no-admin` - whether the user is an admin """ - def run(["new", nickname, email | rest]) do {options, [], []} = OptionParser.parse( @@ -88,7 +88,7 @@ defmodule Mix.Tasks.Pleroma.User do proceed? = Mix.shell().yes?("Continue?") unless not proceed? do - Mix.Task.run("app.start") + Common.start_pleroma() params = %{ @@ -123,7 +123,7 @@ defmodule Mix.Tasks.Pleroma.User do end def run(["rm", nickname]) do - Mix.Task.run("app.start") + Common.start_pleroma() with %User{local: true} = user <- User.get_by_nickname(nickname) do User.delete(user) @@ -135,7 +135,7 @@ defmodule Mix.Tasks.Pleroma.User do end def run(["toggle_activated", nickname]) do - Mix.Task.run("app.start") + Common.start_pleroma() with %User{} = user <- User.get_by_nickname(nickname) do User.deactivate(user, !user.info["deactivated"]) @@ -147,7 +147,7 @@ defmodule Mix.Tasks.Pleroma.User do end def run(["reset_password", nickname]) do - Mix.Task.run("app.start") + Common.start_pleroma() with %User{local: true} = user <- User.get_by_nickname(nickname), {:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do @@ -169,7 +169,7 @@ defmodule Mix.Tasks.Pleroma.User do end def run(["unsubscribe", nickname]) do - Mix.Task.run("app.start") + Common.start_pleroma() with %User{} = user <- User.get_by_nickname(nickname) do Mix.shell().info("Deactivating #{user.nickname}") @@ -198,7 +198,7 @@ defmodule Mix.Tasks.Pleroma.User do end def run(["set", nickname | rest]) do - Mix.Task.run("app.start") + Common.start_pleroma() {options, [], []} = OptionParser.parse( @@ -280,7 +280,7 @@ defmodule Mix.Tasks.Pleroma.User do end def run(["invite"]) do - Mix.Task.run("app.start") + Common.start_pleroma() with {:ok, token} <- Pleroma.UserInviteToken.create_token() do Mix.shell().info("Generated user invite token") -- cgit v1.2.3 From ca7b46fb3ba576fb7e67eba02654e6df9299392a Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Thu, 6 Dec 2018 18:01:28 +0100 Subject: Refactor common functions to common.ex --- lib/mix/tasks/pleroma/instance.ex | 15 +++++++++------ lib/mix/tasks/pleroma/relay.ex | 5 +++-- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 88fc3ba75..e0ebb3f5e 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -67,13 +67,19 @@ defmodule Mix.Tasks.Pleroma.Instance do ) name = - Common.get_option(options, :name, "What is the name of your instance? (e.g. Pleroma/Soykaf)") + Common.get_option( + options, + :name, + "What is the name of your instance? (e.g. Pleroma/Soykaf)" + ) email = Common.get_option(options, :admin_email, "What is your admin email address?") - dbhost = Common.get_option(options, :dbhost, "What is the hostname of your database?", "localhost") + dbhost = + Common.get_option(options, :dbhost, "What is the hostname of your database?", "localhost") - dbname = Common.get_option(options, :dbname, "What is the name of your database?", "pleroma_dev") + dbname = + Common.get_option(options, :dbname, "What is the name of your database?", "pleroma_dev") dbuser = Common.get_option( @@ -145,7 +151,4 @@ defmodule Mix.Tasks.Pleroma.Instance do ) end end - - - end diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index 828c7cd3d..4aea52732 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -20,7 +20,8 @@ defmodule Mix.Tasks.Pleroma.Relay do Example: ``mix pleroma.relay unfollow https://example.org/relay`` """ def run(["follow", target]) do - Common.start_pleroma + Common.start_pleroma() + with {:ok, activity} <- Relay.follow(target) do # put this task to sleep to allow the genserver to push out the messages :timer.sleep(500) @@ -30,7 +31,7 @@ defmodule Mix.Tasks.Pleroma.Relay do end def run(["unfollow", target]) do - Common.start_pleroma + Common.start_pleroma() with {:ok, activity} <- Relay.follow(target) do # put this task to sleep to allow the genserver to push out the messages -- cgit v1.2.3 From 7b194873895f510b3e31b00643b4570ba04cb728 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 6 Dec 2018 20:06:50 +0300 Subject: [#394] Added `users.tags` and admin routes to tag and untag users. Added tests. --- lib/pleroma/user.ex | 43 ++++++++++++++++++++++ lib/pleroma/web/admin_api/admin_api_controller.ex | 12 ++++++ lib/pleroma/web/controller_helper.ex | 9 +++++ lib/pleroma/web/mastodon_api/views/account_view.ex | 4 +- lib/pleroma/web/router.ex | 2 + lib/pleroma/web/twitter_api/views/user_view.ex | 4 +- 6 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 lib/pleroma/web/controller_helper.ex (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 74ae5ef0d..24bc80894 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -23,6 +23,7 @@ defmodule Pleroma.User do field(:local, :boolean, default: true) field(:follower_address, :string) field(:search_distance, :float, virtual: true) + field(:tags, {:array, :string}, default: []) field(:last_refreshed_at, :naive_datetime) has_many(:notifications, Notification) embeds_one(:info, Pleroma.User.Info) @@ -819,4 +820,46 @@ defmodule Pleroma.User do CommonUtils.format_input(bio, mentions, tags, "text/plain") |> Formatter.emojify(emoji) end + + def tag(user_identifiers, tags), do: tag_or_untag(user_identifiers, tags, :tag) + + def untag(user_identifiers, tags), do: tag_or_untag(user_identifiers, tags, :untag) + + defp tag_or_untag(user_identifier, tags, action) when not is_list(user_identifier), + do: tag_or_untag([user_identifier], tags, action) + + defp tag_or_untag([hd | _] = nicknames, tags, action) when is_binary(hd) do + users = Repo.all(from(u in User, where: u.nickname in ^nicknames)) + + if length(users) == length(nicknames) do + tag_or_untag(users, tags, action) + else + {:error, :not_found} + end + end + + defp tag_or_untag([hd | _] = users, tags, action) when is_map(hd) do + tags = + [tags] + |> List.flatten() + |> Enum.map(&String.downcase(&1)) + + Repo.transaction(fn -> + for user <- users do + new_tags = + if action == :tag do + Enum.uniq(user.tags ++ tags) + else + user.tags -- tags + end + + {:ok, updated_user} = + user + |> change(%{tags: new_tags}) + |> Repo.update() + + updated_user + end + end) + end end diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 2c67d9cda..0bd85e0b6 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -3,6 +3,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do alias Pleroma.{User, Repo} alias Pleroma.Web.ActivityPub.Relay + import Pleroma.Web.ControllerHelper, only: [json_response: 3] + require Logger action_fallback(:errors) @@ -40,6 +42,16 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do |> json(new_user.nickname) end + def tag_users(conn, %{"nicknames" => nicknames, "tags" => tags}) do + with {:ok, _} <- User.tag(nicknames, tags), + do: json_response(conn, :no_content, "") + end + + def untag_users(conn, %{"nicknames" => nicknames, "tags" => tags}) do + with {:ok, _} <- User.untag(nicknames, tags), + do: json_response(conn, :no_content, "") + end + def right_add(conn, %{"permission_group" => permission_group, "nickname" => nickname}) when permission_group in ["moderator", "admin"] do user = User.get_by_nickname(nickname) diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex new file mode 100644 index 000000000..ddf958811 --- /dev/null +++ b/lib/pleroma/web/controller_helper.ex @@ -0,0 +1,9 @@ +defmodule Pleroma.Web.ControllerHelper do + use Pleroma.Web, :controller + + def json_response(conn, status, json) do + conn + |> put_status(status) + |> json(json) + end +end diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index bcfa8836e..0add1b686 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -58,7 +58,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do note: "", privacy: user_info.default_scope, sensitive: false - } + }, + # Note: Mastodon does not return this field: + tags: user.tags } end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index b7c79d2eb..ae942701e 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -98,6 +98,8 @@ defmodule Pleroma.Web.Router do pipe_through(:admin_api) delete("/user", AdminAPIController, :user_delete) post("/user", AdminAPIController, :user_create) + put("/users/tag", AdminAPIController, :tag_users) + put("/users/untag", AdminAPIController, :untag_users) get("/permission_group/:nickname", AdminAPIController, :right_get) get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get) diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index b78024ed7..dae656372 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -77,7 +77,9 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "locked" => user.info.locked, "default_scope" => user.info.default_scope, "no_rich_text" => user.info.no_rich_text, - "fields" => fields + "fields" => fields, + # Note: twitter.com does not return this field: + "tags" => user.tags } if assigns[:token] do -- cgit v1.2.3 From 66313cda02d8c335a2c24c0b7ad64ba6cebc4df8 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Thu, 6 Dec 2018 18:16:51 +0100 Subject: Update instance.ex for web push --- lib/mix/tasks/pleroma/instance.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index e0ebb3f5e..c66322707 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -99,6 +99,7 @@ defmodule Mix.Tasks.Pleroma.Instance do ) secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) + {web_push_public_key, web_push_private_key} = :crypto.generate_key(:ecdh, :prime256v1) result_config = EEx.eval_file( @@ -111,7 +112,9 @@ defmodule Mix.Tasks.Pleroma.Instance do dbuser: dbuser, dbpass: dbpass, version: Pleroma.Mixfile.project() |> Keyword.get(:version), - secret: secret + secret: secret, + web_push_public_key: Base.url_encode64(web_push_public_key, padding: false), + web_push_private_key: Base.url_encode64(web_push_private_key, padding: false) ) result_psql = -- cgit v1.2.3 From 7bcb6a183a13cabd32bafd0e3ca20f8ca543565b Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 6 Dec 2018 20:23:16 +0300 Subject: [#394] Refactoring. --- lib/pleroma/user.ex | 11 +++++------ lib/pleroma/web/mastodon_api/views/account_view.ex | 2 +- lib/pleroma/web/twitter_api/views/user_view.ex | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 24bc80894..3984e610e 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -846,12 +846,7 @@ defmodule Pleroma.User do Repo.transaction(fn -> for user <- users do - new_tags = - if action == :tag do - Enum.uniq(user.tags ++ tags) - else - user.tags -- tags - end + new_tags = mutate_tags(user, tags, action) {:ok, updated_user} = user @@ -862,4 +857,8 @@ defmodule Pleroma.User do end end) end + + defp mutate_tags(user, tags, :tag), do: Enum.uniq(user.tags ++ tags) + + defp mutate_tags(user, tags, :untag), do: user.tags -- tags end diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 0add1b686..2762813ae 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -59,7 +59,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do privacy: user_info.default_scope, sensitive: false }, - # Note: Mastodon does not return this field: + # Pleroma extension tags: user.tags } end diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index dae656372..f460ddd80 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -78,7 +78,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "default_scope" => user.info.default_scope, "no_rich_text" => user.info.no_rich_text, "fields" => fields, - # Note: twitter.com does not return this field: + # Pleroma extension "tags" => user.tags } -- cgit v1.2.3 From 71d5cf9ed86089bb2e5b280c462759590307b94d Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Thu, 6 Dec 2018 18:25:39 +0100 Subject: Remove unused vars from user.ex --- lib/mix/tasks/pleroma/user.ex | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 82f351456..12b5af774 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -232,10 +232,6 @@ defmodule Mix.Tasks.Pleroma.User do end defp set_moderator(user, value) do - info = - user.info - |> Map.put("is_moderator", value) - info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value}) user_cng = @@ -248,10 +244,6 @@ defmodule Mix.Tasks.Pleroma.User do end defp set_admin(user, value) do - info = - user.info - |> Map.put("is_admin", value) - info_cng = User.Info.admin_api_update(user.info, %{is_admin: value}) user_cng = @@ -264,10 +256,6 @@ defmodule Mix.Tasks.Pleroma.User do end defp set_locked(user, value) do - info = - user.info - |> Map.put("locked", value) - info_cng = User.Info.user_upgrade(user.info, %{locked: value}) user_cng = -- cgit v1.2.3 From 7a2162bbcb2e3a64ed6b56229311aa9fd487351a Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 6 Dec 2018 22:26:25 +0300 Subject: [#394] User view (Twitter & Mastadon API): wrapped "tags" in "pleroma" map. --- lib/pleroma/web/mastodon_api/views/account_view.ex | 5 ++++- lib/pleroma/web/twitter_api/views/user_view.ex | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 2762813ae..ebcf9230b 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -59,8 +59,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do privacy: user_info.default_scope, sensitive: false }, + # Pleroma extension - tags: user.tags + pleroma: %{ + tags: user.tags + } } end diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index f460ddd80..b3459af9a 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -78,8 +78,11 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "default_scope" => user.info.default_scope, "no_rich_text" => user.info.no_rich_text, "fields" => fields, + # Pleroma extension - "tags" => user.tags + "pleroma" => %{ + "tags" => user.tags + } } if assigns[:token] do -- cgit v1.2.3 From 1d11c4cf11e27992c6b79731015456a954307e8f Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Fri, 7 Dec 2018 06:12:39 +0100 Subject: add common.ex --- lib/mix/tasks/pleroma/common.ex | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/mix/tasks/pleroma/common.ex (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/common.ex b/lib/mix/tasks/pleroma/common.ex new file mode 100644 index 000000000..2e246c4b5 --- /dev/null +++ b/lib/mix/tasks/pleroma/common.ex @@ -0,0 +1,24 @@ +defmodule Mix.Tasks.Pleroma.Common do + @shortdoc "Common functions to be reused in mix tasks" + def start_pleroma do + Mix.Task.run("app.start") + end + + def get_option(options, opt, prompt, def \\ nil, defname \\ nil) do + Keyword.get(options, opt) || + case Mix.shell().prompt("#{prompt} [#{defname || def}]") do + "\n" -> + case def do + nil -> get_option(options, opt, prompt, def) + def -> def + end + + opt -> + opt |> String.trim() + end + end + + def escape_sh_path(path) do + ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(') + end +end -- cgit v1.2.3 From 08e10a70ec8752b30010389c0f5e14105fc58c3e Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 7 Dec 2018 09:46:13 +0300 Subject: Rename def to defval --- lib/mix/tasks/pleroma/common.ex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/common.ex b/lib/mix/tasks/pleroma/common.ex index 2e246c4b5..06893af05 100644 --- a/lib/mix/tasks/pleroma/common.ex +++ b/lib/mix/tasks/pleroma/common.ex @@ -4,13 +4,13 @@ defmodule Mix.Tasks.Pleroma.Common do Mix.Task.run("app.start") end - def get_option(options, opt, prompt, def \\ nil, defname \\ nil) do + def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do Keyword.get(options, opt) || - case Mix.shell().prompt("#{prompt} [#{defname || def}]") do + case Mix.shell().prompt("#{prompt} [#{defname || defval}]") do "\n" -> - case def do - nil -> get_option(options, opt, prompt, def) - def -> def + case defval do + nil -> get_option(options, opt, prompt, defval) + defval -> defval end opt -> -- cgit v1.2.3 From f6618138078f199ea34801ddee4f51cd6bae03e6 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 7 Dec 2018 10:39:54 +0300 Subject: Add mix pleroma.user unsubscribe to mix doc --- lib/mix/tasks/pleroma/user.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 12b5af774..5299448c3 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -21,7 +21,7 @@ defmodule Mix.Tasks.Pleroma.User do ## Generate an invite link. - mix pleroma.user invite + mix pleroma.user invite ## Delete the user's account. @@ -30,6 +30,10 @@ defmodule Mix.Tasks.Pleroma.User do ## Deactivate or activate the user's account. 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. -- cgit v1.2.3 From f7e23aee9068664af4ed3c00dfe16878a73daa61 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 7 Dec 2018 10:44:54 +0300 Subject: Oops --- lib/mix/tasks/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 5299448c3..590553443 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -30,7 +30,7 @@ defmodule Mix.Tasks.Pleroma.User do ## Deactivate or activate the user's account. mix pleroma.user toggle_activated NICKNAME - + ## Unsubscribe local users from user's account and deactivate it mix pleroma.user unsubscribe NICKNAME -- cgit v1.2.3 From 6ed5044c4e1889a51a1dc6015b602759b83fc3b7 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 7 Dec 2018 11:04:39 +0300 Subject: [#394] Refactoring (using Ecto.Multi; "untag" route change). --- lib/pleroma/user.ex | 16 ++++++---------- lib/pleroma/web/router.ex | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 3984e610e..511e6956e 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -2,6 +2,7 @@ defmodule Pleroma.User do use Ecto.Schema import Ecto.{Changeset, Query} + alias Ecto.Multi alias Pleroma.{Repo, User, Object, Web, Activity, Notification} alias Comeonin.Pbkdf2 alias Pleroma.Formatter @@ -844,18 +845,13 @@ defmodule Pleroma.User do |> List.flatten() |> Enum.map(&String.downcase(&1)) - Repo.transaction(fn -> - for user <- users do + multi = + Enum.reduce(users, Multi.new(), fn user, multi -> new_tags = mutate_tags(user, tags, action) + Multi.update(multi, {:user, user.id}, change(user, %{tags: new_tags})) + end) - {:ok, updated_user} = - user - |> change(%{tags: new_tags}) - |> Repo.update() - - updated_user - end - end) + Repo.transaction(multi) end defp mutate_tags(user, tags, :tag), do: Enum.uniq(user.tags ++ tags) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index ae942701e..a07607366 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -99,7 +99,7 @@ defmodule Pleroma.Web.Router do delete("/user", AdminAPIController, :user_delete) post("/user", AdminAPIController, :user_create) put("/users/tag", AdminAPIController, :tag_users) - put("/users/untag", AdminAPIController, :untag_users) + delete("/users/tag", AdminAPIController, :untag_users) get("/permission_group/:nickname", AdminAPIController, :right_get) get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get) -- cgit v1.2.3 From 4e2250b1dd1661094a142382e75b359ab742e996 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 7 Dec 2018 11:41:01 +0300 Subject: Fix a typo in relay.ex moduledoc --- lib/mix/tasks/pleroma/relay.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index 4aea52732..2502923af 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -9,7 +9,7 @@ defmodule Mix.Tasks.Pleroma.Relay do ## Follow a remote relay - ``mix pleroma.relay unfollow `` + ``mix pleroma.relay follow `` Example: ``mix pleroma.relay follow https://example.org/relay`` -- cgit v1.2.3 From 1cea97df646566bfd6e31d9696047ba87f1e82c1 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 7 Dec 2018 12:27:32 +0300 Subject: [#394] Refactoring of User.tag and User.untag (removed User.tag_or_untag etc.) --- lib/pleroma/user.ex | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 511e6956e..198f05f8a 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -822,39 +822,40 @@ defmodule Pleroma.User do CommonUtils.format_input(bio, mentions, tags, "text/plain") |> Formatter.emojify(emoji) end - def tag(user_identifiers, tags), do: tag_or_untag(user_identifiers, tags, :tag) + def tag(user_identifiers, tags) when is_list(user_identifiers) do + Repo.transaction(fn -> + for user_identifier <- user_identifiers, do: tag(user_identifier, tags) + end) + end - def untag(user_identifiers, tags), do: tag_or_untag(user_identifiers, tags, :untag) + def untag(user_identifiers, tags) when is_list(user_identifiers) do + Repo.transaction(fn -> + for user_identifier <- user_identifiers, do: untag(user_identifier, tags) + end) + end - defp tag_or_untag(user_identifier, tags, action) when not is_list(user_identifier), - do: tag_or_untag([user_identifier], tags, action) + def tag(nickname, tags) when is_binary(nickname), do: tag(User.get_by_nickname(nickname), tags) - defp tag_or_untag([hd | _] = nicknames, tags, action) when is_binary(hd) do - users = Repo.all(from(u in User, where: u.nickname in ^nicknames)) + def untag(nickname, tags) when is_binary(nickname), + do: untag(User.get_by_nickname(nickname), tags) - if length(users) == length(nicknames) do - tag_or_untag(users, tags, action) - else - {:error, :not_found} - end - end + def tag(%User{} = user, tags), + do: update_tags(user, Enum.uniq(user.tags ++ normalize_tags(tags))) - defp tag_or_untag([hd | _] = users, tags, action) when is_map(hd) do - tags = - [tags] - |> List.flatten() - |> Enum.map(&String.downcase(&1)) + def untag(%User{} = user, tags), do: update_tags(user, user.tags -- normalize_tags(tags)) - multi = - Enum.reduce(users, Multi.new(), fn user, multi -> - new_tags = mutate_tags(user, tags, action) - Multi.update(multi, {:user, user.id}, change(user, %{tags: new_tags})) - end) + defp update_tags(%User{} = user, new_tags) do + {:ok, updated_user} = + user + |> change(%{tags: new_tags}) + |> Repo.update() - Repo.transaction(multi) + updated_user end - defp mutate_tags(user, tags, :tag), do: Enum.uniq(user.tags ++ tags) - - defp mutate_tags(user, tags, :untag), do: user.tags -- tags + defp normalize_tags(tags) do + [tags] + |> List.flatten() + |> Enum.map(&String.downcase(&1)) + end end -- cgit v1.2.3 From 3c925e9d889da7f7ec22c98572a9ef2b080f81be Mon Sep 17 00:00:00 2001 From: href Date: Fri, 7 Dec 2018 11:16:27 +0100 Subject: Emojis: Alphabetical ordering --- lib/pleroma/emoji.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex index 0a5e1d5ce..523dea652 100644 --- a/lib/pleroma/emoji.ex +++ b/lib/pleroma/emoji.ex @@ -10,7 +10,7 @@ defmodule Pleroma.Emoji do """ use GenServer @ets __MODULE__.Ets - @ets_options [:set, :protected, :named_table, {:read_concurrency, true}] + @ets_options [:ordered_set, :protected, :named_table, {:read_concurrency, true}] @doc false def start_link() do -- cgit v1.2.3 From 3b27f61ffa737dd6f4f9ec3a50c248d9077ddb51 Mon Sep 17 00:00:00 2001 From: href Date: Fri, 7 Dec 2018 14:07:11 +0100 Subject: AnonymizeFilename: allow for a pre-defined text instead of random string Improve docs --- lib/pleroma/upload/filter/anonymize_filename.ex | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/upload/filter/anonymize_filename.ex b/lib/pleroma/upload/filter/anonymize_filename.ex index a83e764e5..39eed7af3 100644 --- a/lib/pleroma/upload/filter/anonymize_filename.ex +++ b/lib/pleroma/upload/filter/anonymize_filename.ex @@ -1,10 +1,23 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilename do - @moduledoc "Replaces the original filename with a randomly generated string." + @moduledoc """ + Replaces the original filename with a pre-defined text or randomly generated string. + + Should be used after `Pleroma.Upload.Filter.Dedupe`. + """ @behaviour Pleroma.Upload.Filter def filter(upload) do extension = List.last(String.split(upload.name, ".")) - string = Base.url_encode64(:crypto.strong_rand_bytes(10), padding: false) - {:ok, %Pleroma.Upload{upload | name: string <> "." <> extension}} + name = Pleroma.Config.get([__MODULE__, :text], random(extension)) + {:ok, %Pleroma.Upload{upload | name: name}} + end + + defp random(extension) do + string = + 10 + |> :crypto.strong_rand_bytes() + |> Base.url_encode64(padding: false) + + string <> "." <> extension end end -- cgit v1.2.3 From a02e0c18bc0814817ece3495888c5cb03921ca2e Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Fri, 7 Dec 2018 15:13:57 +0100 Subject: Mix Tasks: Add task uploads.ex for migrating local uploads. --- lib/mix/tasks/pleroma/uploads.ex | 98 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 lib/mix/tasks/pleroma/uploads.ex (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex new file mode 100644 index 000000000..0783a0ccc --- /dev/null +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -0,0 +1,98 @@ +defmodule Mix.Tasks.Pleroma.Uploads do + use Mix.Task + import Mix.Ecto + alias Pleroma.{Upload, Uploaders.Local, Uploaders.S3} + alias Mix.Tasks.Pleroma.Common + require Logger + + @log_every 50 + @shortdoc "Migrate uploads from local to remote storage" + @longdioc """ + 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() + local_path = Pleroma.Config.get!([Local, :uploads]) + uploader = Module.concat(Pleroma.Uploaders, target_uploader) + + unless Code.ensure_loaded?(uploader) do + raise("The uploader #{inspect(uploader)} is not an existing/loaded module.") + end + + target_enabled? = Pleroma.Config.get([Upload, :uploader]) == uploader + + unless target_enabled? do + Pleroma.Config.put([Upload, :uploader], uploader) + end + + Mix.shell().info("Migrating files from local #{local_path} to #{to_string(uploader)}") + + if delete? do + Mix.shell().info( + "Attention: uploaded files will be deleted, hope you have backups! (--delete ; cancel with ^C)" + ) + + :timer.sleep(:timer.seconds(5)) + end + + uploads = + File.ls!(local_path) + |> Enum.map(fn id -> + root_path = Path.join(local_path, id) + + cond do + File.dir?(root_path) -> + files = for file <- File.ls!(root_path), do: {id, file, Path.join([root_path, file])} + + case List.first(files) do + {id, file, path} -> + {%Pleroma.Upload{id: id, name: file, path: id <> "/" <> file, tempfile: path}, + root_path} + + _ -> + nil + end + + File.exists?(root_path) -> + file = Path.basename(id) + [hash, ext] = String.split(id, ".") + {%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path} + + true -> + nil + end + end) + |> Enum.filter(& &1) + + total_count = length(uploads) + Mix.shell().info("Found #{total_count} uploads") + + uploads + |> Task.async_stream( + fn {upload, root_path} -> + case Upload.store(upload, uploader: uploader, filters: [], size_limit: nil) do + {:ok, _} -> + if delete?, do: File.rm_rf!(root_path) + Logger.debug("uploaded: #{inspect(upload.path)} #{inspect(upload)}") + :ok + + error -> + Mix.shell().error("failed to upload #{inspect(upload.path)}: #{inspect(error)}") + end + end, + timeout: 150_000 + ) + |> Stream.chunk_every(@log_every) + |> Enum.reduce(0, fn done, count -> + count = count + length(done) + Mix.shell().info("Uploaded #{count}/#{total_count} files") + count + end) + + Mix.shell().info("Done!") + end +end -- cgit v1.2.3 From fd5c7b445f9911ab3d3cfb5ac06bfd6bb092b10a Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Fri, 7 Dec 2018 19:19:14 +0100 Subject: Fix a typo --- lib/mix/tasks/pleroma/uploads.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index 0783a0ccc..0742ab378 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -7,7 +7,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do @log_every 50 @shortdoc "Migrate uploads from local to remote storage" - @longdioc """ + @longdoc """ Manages uploads ## Migrate uploads from local to remote storage -- cgit v1.2.3 From 09f20de0d71d072aa64c9bbad4525bc5140dd9a0 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Fri, 7 Dec 2018 19:21:58 +0100 Subject: Make gopher respect ip --- lib/pleroma/gopher/server.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index 3b0569a99..4d582ef25 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -22,7 +22,7 @@ defmodule Pleroma.Gopher.Server do :gopher, 100, :ranch_tcp, - [port: port], + [ip: ip, port: port], __MODULE__.ProtocolHandler, [] ) -- cgit v1.2.3 From d8fcf7c5cfc63cbdf823248bb259e7e6a25fd333 Mon Sep 17 00:00:00 2001 From: href Date: Fri, 7 Dec 2018 19:36:44 +0100 Subject: Media proxy: follow HTTP redirects by default --- lib/pleroma/web/media_proxy/controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex index e1b87e026..d0b92d0c1 100644 --- a/lib/pleroma/web/media_proxy/controller.ex +++ b/lib/pleroma/web/media_proxy/controller.ex @@ -2,7 +2,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do use Pleroma.Web, :controller alias Pleroma.{Web.MediaProxy, ReverseProxy} - @default_proxy_opts [max_body_length: 25 * 1_048_576] + @default_proxy_opts [max_body_length: 25 * 1_048_576, http: [follow_redirect: true]] def remote(conn, params = %{"sig" => sig64, "url" => url64}) do with config <- Pleroma.Config.get([:media_proxy], []), -- cgit v1.2.3 From 134cc94cbde7d456fbfc489f6d7eff80b98c64dd Mon Sep 17 00:00:00 2001 From: href Date: Fri, 7 Dec 2018 19:44:45 +0100 Subject: Nodeinfo: remove null features; relay feature. --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 39 ++++++++++++++----------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 2ea75cf16..277dc6ba1 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -71,23 +71,28 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do %{} end - features = [ - "pleroma_api", - "mastodon_api", - "mastodon_api_streaming", - if Keyword.get(media_proxy, :enabled) do - "media_proxy" - end, - if Keyword.get(gopher, :enabled) do - "gopher" - end, - if Keyword.get(chat, :enabled) do - "chat" - end, - if Keyword.get(suggestions, :enabled) do - "suggestions" - end - ] + features = + [ + "pleroma_api", + "mastodon_api", + "mastodon_api_streaming", + if Keyword.get(media_proxy, :enabled) do + "media_proxy" + end, + if Keyword.get(gopher, :enabled) do + "gopher" + end, + if Keyword.get(chat, :enabled) do + "chat" + end, + if Keyword.get(suggestions, :enabled) do + "suggestions" + end, + if Keyword.get(instance, :allow_relay) do + "relay" + end + ] + |> Enum.filter(& &1) response = %{ version: "2.0", -- cgit v1.2.3 From 578051809f38c3d5d65155e264203c3b978a10a8 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Fri, 7 Dec 2018 20:03:30 +0100 Subject: Add uploadlimit to Twitter API config --- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 092779010..36ecefa76 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -165,6 +165,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do description: Keyword.get(instance, :description), server: Web.base_url(), textlimit: to_string(Keyword.get(instance, :limit)), + uploadlimit: to_string(Keyword.get(instance, :upload_limit)), closed: if(Keyword.get(instance, :registrations_open), do: "0", else: "1"), private: if(Keyword.get(instance, :public, true), do: "0", else: "1"), vapidPublicKey: vapid_public_key -- cgit v1.2.3 From bdc8112e4031a17c39a570bc8fc4bb6b8c35f9aa Mon Sep 17 00:00:00 2001 From: href Date: Fri, 7 Dec 2018 21:44:04 +0100 Subject: Media proxy: fix url encoding --- lib/pleroma/web/media_proxy/controller.ex | 7 ++++++- lib/pleroma/web/media_proxy/media_proxy.ex | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex index d0b92d0c1..f496fc936 100644 --- a/lib/pleroma/web/media_proxy/controller.ex +++ b/lib/pleroma/web/media_proxy/controller.ex @@ -24,7 +24,12 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do end def filename_matches(has_filename, path, url) do - filename = MediaProxy.filename(url) + filename = + url + |> MediaProxy.filename() + |> URI.decode() + + path = URI.decode(path) cond do has_filename && filename && Path.basename(path) != filename -> {:wrong_filename, filename} diff --git a/lib/pleroma/web/media_proxy/media_proxy.ex b/lib/pleroma/web/media_proxy/media_proxy.ex index 28aacb0b1..902ab1b77 100644 --- a/lib/pleroma/web/media_proxy/media_proxy.ex +++ b/lib/pleroma/web/media_proxy/media_proxy.ex @@ -14,7 +14,14 @@ defmodule Pleroma.Web.MediaProxy do url else secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base] - base64 = Base.url_encode64(url, @base64_opts) + + # The URL is url-decoded and encoded again to ensure it is correctly encoded and not twice. + base64 = + url + |> URI.decode() + |> URI.encode() + |> Base.url_encode64(@base64_opts) + sig = :crypto.hmac(:sha, secret, base64) sig64 = sig |> Base.url_encode64(@base64_opts) -- cgit v1.2.3 From 6c73136aeca26357b405058e338d8020dc0dfe4e Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sat, 8 Dec 2018 08:30:34 +0100 Subject: [#283] Mix Tasks: Fix a typo in relay.ex --- lib/mix/tasks/pleroma/relay.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index 2502923af..f4b7ff6a0 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -33,7 +33,7 @@ defmodule Mix.Tasks.Pleroma.Relay do def run(["unfollow", target]) do Common.start_pleroma() - with {:ok, activity} <- Relay.follow(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 -- cgit v1.2.3 From 15616eda5e98bb13b1382109fb1f84537c58fcb1 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sat, 8 Dec 2018 21:48:49 +0100 Subject: Make uploadlimit an object that stores upload limits for avatars, banners, backgrounds, general content --- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 36ecefa76..1459f3c90 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -160,12 +160,19 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do vapid_public_key = Keyword.get(Application.get_env(:web_push_encryption, :vapid_details), :public_key) + uploadlimit = %{ + uploadlimit: to_string(Keyword.get(instance, :upload_limit)), + avatarlimit: to_string(Keyword.get(instance, :avatar_upload_limit)), + backgroundlimit: to_string(Keyword.get(instance, :background_upload_limit)), + bannerlimit: to_string(Keyword.get(instance, :banner_upload_limit)) + } + data = %{ name: Keyword.get(instance, :name), description: Keyword.get(instance, :description), server: Web.base_url(), textlimit: to_string(Keyword.get(instance, :limit)), - uploadlimit: to_string(Keyword.get(instance, :upload_limit)), + uploadlimit: uploadlimit, closed: if(Keyword.get(instance, :registrations_open), do: "0", else: "1"), private: if(Keyword.get(instance, :public, true), do: "0", else: "1"), vapidPublicKey: vapid_public_key -- cgit v1.2.3 From 9442588ae9b049ae1b152b082842e4c13fa49ebb Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Thu, 6 Dec 2018 21:50:34 +0300 Subject: fix hashtags in api response --- lib/pleroma/web/mastodon_api/views/status_view.ex | 120 +++++++++++++--------- 1 file changed, 71 insertions(+), 49 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 2d9a915f0..b5574b039 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -1,18 +1,26 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do use Pleroma.Web, :view - alias Pleroma.Web.MastodonAPI.{AccountView, StatusView} - alias Pleroma.{User, Activity} - alias Pleroma.Web.CommonAPI.Utils - alias Pleroma.Web.MediaProxy - alias Pleroma.Repo - alias Pleroma.HTML + + alias Pleroma.{ + Activity, + HTML, + Repo, + User + } + + alias Pleroma.Web.{ + CommonAPI.Utils, + MastodonAPI.AccountView, + MastodonAPI.StatusView, + MediaProxy + } # TODO: Add cached version. defp get_replied_to_activities(activities) do activities |> Enum.map(fn - %{data: %{"type" => "Create", "object" => %{"inReplyTo" => inReplyTo}}} -> - inReplyTo != "" && inReplyTo + %{data: %{"type" => "Create", "object" => %{"inReplyTo" => in_reply_to}}} -> + in_reply_to != "" && in_reply_to _ -> nil @@ -28,8 +36,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do def render("index.json", opts) do replied_to_activities = get_replied_to_activities(opts.activities) - render_many( - opts.activities, + opts.activities + |> render_many( StatusView, "status.json", Map.put(opts, :replied_to_activities, replied_to_activities) @@ -72,9 +80,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do sensitive: false, spoiler_text: "", visibility: "public", - media_attachments: [], + media_attachments: reblogged[:media_attachments] || [], mentions: mentions, - tags: [], + tags: reblogged[:tags] || [], application: %{ name: "Web", website: nil @@ -111,20 +119,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do reply_to = get_reply_to(activity, opts) reply_to_user = reply_to && User.get_cached_by_ap_id(reply_to.data["actor"]) - emojis = - (activity.data["object"]["emoji"] || []) - |> Enum.map(fn {name, url} -> - name = HTML.strip_tags(name) - - url = - HTML.strip_tags(url) - |> MediaProxy.url() - - %{shortcode: name, url: url, static_url: url, visible_in_picker: false} - end) - content = - render_content(object) + object + |> render_content() |> HTML.filter_tags(User.html_filter_policy(opts[:for])) %{ @@ -140,22 +137,21 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do reblogs_count: announcement_count, replies_count: 0, favourites_count: like_count, - reblogged: !!repeated, - favourited: !!favorited, + reblogged: present?(repeated), + favourited: present?(favorited), muted: false, sensitive: sensitive, spoiler_text: object["summary"] || "", visibility: get_visibility(object), media_attachments: attachments |> Enum.take(4), mentions: mentions, - # fix, - tags: [], + tags: tags, application: %{ name: "Web", website: nil }, language: nil, - emojis: emojis + emojis: build_emojis(activity.data["object"]["emoji"]) } end @@ -224,30 +220,56 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do end def render_content(%{"type" => "Video"} = object) do - name = object["name"] - - content = - if !!name and name != "" do - "

#{name}

#{object["content"]}" - else - object["content"] || "" - end + with name when not is_nil(name) and name != "" <- object["name"] do + "

#{name}

#{object["content"]}" + else + _ -> object["content"] || "" + end + end - content + def render_content(%{"type" => object_type} = object) + when object_type in ["Article", "Page"] do + with summary when not is_nil(summary) and summary != "" <- object["name"], + url when is_bitstring(url) <- object["url"] do + "

#{summary}

#{object["content"]}" + else + _ -> object["content"] || "" + end end - def render_content(%{"type" => object_type} = object) when object_type in ["Article", "Page"] do - summary = object["name"] + def render_content(object), do: object["content"] || "" - content = - if !!summary and summary != "" and is_bitstring(object["url"]) do - "

#{summary}

#{object["content"]}" - else - object["content"] || "" - end + @doc """ + Builds list emojis. + + Arguments: `nil` or list tuple of name and url. + + Returns list emojis. + + ## Examples - content + iex> Pleroma.Web.MastodonAPI.StatusView.build_emojis([{"2hu", "corndog.png"}]) + [%{shortcode: "2hu", static_url: "corndog.png", url: "corndog.png", visible_in_picker: false}] + + """ + @spec build_emojis(nil | list(tuple())) :: list(map()) + def build_emojis(nil), do: [] + + def build_emojis(emojis) do + emojis + |> Enum.map(fn {name, url} -> + name = HTML.strip_tags(name) + + url = + url + |> HTML.strip_tags() + |> MediaProxy.url() + + %{shortcode: name, url: url, static_url: url, visible_in_picker: false} + end) end - def render_content(object), do: object["content"] || "" + defp present?(nil), do: false + defp present?(false), do: false + defp present?(_), do: true end -- cgit v1.2.3 From 068353ac0b36e6c391a49bae8b96faf4df3f0775 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Fri, 7 Dec 2018 07:53:14 +0300 Subject: formatting --- lib/pleroma/web/mastodon_api/views/status_view.ex | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index b5574b039..c3c735d5d 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -1,19 +1,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do use Pleroma.Web, :view - alias Pleroma.{ - Activity, - HTML, - Repo, - User - } - - alias Pleroma.Web.{ - CommonAPI.Utils, - MastodonAPI.AccountView, - MastodonAPI.StatusView, - MediaProxy - } + alias Pleroma.Activity + alias Pleroma.HTML + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.MediaProxy + alias Pleroma.Web.MastodonAPI.AccountView + alias Pleroma.Web.MastodonAPI.StatusView # TODO: Add cached version. defp get_replied_to_activities(activities) do -- cgit v1.2.3 From 074fa790ba6282772cd8b2d40926032228d17c81 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sun, 9 Dec 2018 12:12:48 +0300 Subject: fix compile warnings --- lib/mix/tasks/pleroma/common.ex | 2 +- lib/mix/tasks/pleroma/instance.ex | 1 - lib/mix/tasks/pleroma/relay.ex | 4 +- lib/mix/tasks/pleroma/uploads.ex | 8 +-- lib/mix/tasks/pleroma/user.ex | 44 ++++++------ lib/pleroma/application.ex | 1 - lib/pleroma/emoji.ex | 2 +- lib/pleroma/filter.ex | 12 ++-- lib/pleroma/html.ex | 6 +- lib/pleroma/http/connection.ex | 2 +- lib/pleroma/list.ex | 4 +- lib/pleroma/mime.ex | 4 +- lib/pleroma/notification.ex | 8 +-- lib/pleroma/plugs/authentication_plug.ex | 9 +-- lib/pleroma/plugs/basic_auth_decoder_plug.ex | 2 +- lib/pleroma/plugs/federating_plug.ex | 2 +- lib/pleroma/plugs/http_security_plug.ex | 10 +-- lib/pleroma/plugs/session_authentication_plug.ex | 1 - lib/pleroma/plugs/uploaded_media.ex | 4 -- lib/pleroma/plugs/user_fetcher_plug.ex | 2 +- lib/pleroma/reverse_proxy.ex | 41 +++++------ lib/pleroma/upload.ex | 25 +++---- lib/pleroma/upload/filter/dedupe.ex | 2 +- lib/pleroma/upload/filter/mogrify.ex | 2 +- lib/pleroma/uploaders/local.ex | 2 - lib/pleroma/uploaders/mdii.ex | 4 +- lib/pleroma/uploaders/swift/swift.ex | 1 - lib/pleroma/user.ex | 17 +++-- lib/pleroma/user_invite_token.ex | 3 +- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- .../web/activity_pub/activity_pub_controller.ex | 2 +- .../web/activity_pub/mrf/ensure_re_prepended.ex | 4 +- lib/pleroma/web/activity_pub/transmogrifier.ex | 82 +++++++++++----------- lib/pleroma/web/activity_pub/utils.ex | 2 +- lib/pleroma/web/admin_api/admin_api_controller.ex | 52 ++++++-------- lib/pleroma/web/common_api/utils.ex | 4 +- lib/pleroma/web/federator/federator.ex | 3 +- lib/pleroma/web/federator/retry_queue.ex | 11 +-- .../web/mastodon_api/mastodon_api_controller.ex | 15 ++-- lib/pleroma/web/mastodon_api/mastodon_socket.ex | 8 +-- .../web/mastodon_api/views/mastodon_view.ex | 1 - .../mastodon_api/views/push_subscription_view.ex | 1 - lib/pleroma/web/media_proxy/controller.ex | 2 +- lib/pleroma/web/oauth/oauth_controller.ex | 2 +- lib/pleroma/web/ostatus/ostatus.ex | 2 +- lib/pleroma/web/ostatus/ostatus_controller.ex | 4 +- lib/pleroma/web/router.ex | 2 - lib/pleroma/web/streamer.ex | 2 - .../web/twitter_api/controllers/util_controller.ex | 3 +- .../representers/activity_representer.ex | 6 +- lib/pleroma/web/twitter_api/twitter_api.ex | 13 +--- .../web/twitter_api/twitter_api_controller.ex | 8 +-- lib/pleroma/web/xml/xml.ex | 8 +-- 53 files changed, 204 insertions(+), 260 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/common.ex b/lib/mix/tasks/pleroma/common.ex index 06893af05..36432c291 100644 --- a/lib/mix/tasks/pleroma/common.ex +++ b/lib/mix/tasks/pleroma/common.ex @@ -1,5 +1,5 @@ defmodule Mix.Tasks.Pleroma.Common do - @shortdoc "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 diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index c66322707..3be856115 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -1,6 +1,5 @@ defmodule Mix.Tasks.Pleroma.Instance do use Mix.Task - alias Pleroma.{Repo, User} alias Mix.Tasks.Pleroma.Common @shortdoc "Manages Pleroma instance" diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index f4b7ff6a0..03586d6c3 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -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 @@ defmodule Mix.Tasks.Pleroma.Relay 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 diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index 0742ab378..45bfd254c 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -1,18 +1,16 @@ 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" - @longdoc """ + @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 @@ defmodule Mix.Tasks.Pleroma.Uploads 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 -> diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 590553443..2675b021d 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -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 @@ defmodule Mix.Tasks.Pleroma.User 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 @@ defmodule Mix.Tasks.Pleroma.User 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 diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 0b0ec0197..8705395a4 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -15,7 +15,6 @@ defmodule Pleroma.Application 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 diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex index 523dea652..bedad99d6 100644 --- a/lib/pleroma/emoji.ex +++ b/lib/pleroma/emoji.ex @@ -165,7 +165,7 @@ defmodule Pleroma.Emoji do defp load_from_file_stream(stream) do stream - |> Stream.map(&String.strip/1) + |> Stream.map(&String.trim/1) |> Stream.map(fn line -> case String.split(line, ~r/,\s*/) do [name, file] -> {name, file} diff --git a/lib/pleroma/filter.ex b/lib/pleroma/filter.ex index 25ed38f34..c57bd3bf8 100644 --- a/lib/pleroma/filter.ex +++ b/lib/pleroma/filter.ex @@ -1,10 +1,10 @@ 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 @@ defmodule Pleroma.Filter 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 @@ defmodule Pleroma.Filter 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( diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 5daaa5e69..8a0333461 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -166,7 +166,7 @@ defmodule Pleroma.HTML.Transform.MediaProxy 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 @@ defmodule Pleroma.HTML.Transform.MediaProxy 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 diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index db46f9e55..7b11060b2 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -25,7 +25,7 @@ defmodule Pleroma.HTTP.Connection do # fetch Hackney options # - defp hackney_options(opts \\ []) do + defp hackney_options(opts) do options = Keyword.get(opts, :adapter, []) @hackney_options ++ options end diff --git a/lib/pleroma/list.ex b/lib/pleroma/list.ex index 891c73f5a..c5bf3e083 100644 --- a/lib/pleroma/list.ex +++ b/lib/pleroma/list.ex @@ -23,7 +23,7 @@ defmodule Pleroma.List 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 @@ defmodule Pleroma.List 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, diff --git a/lib/pleroma/mime.ex b/lib/pleroma/mime.ex index db8b7c742..5e1c109e9 100644 --- a/lib/pleroma/mime.ex +++ b/lib/pleroma/mime.ex @@ -33,10 +33,10 @@ defmodule Pleroma.MIME 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, ".") diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index a40b8f8c9..47f6b6ee7 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -118,7 +118,7 @@ defmodule Pleroma.Notification 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 @@ defmodule Pleroma.Notification do 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"]) diff --git a/lib/pleroma/plugs/authentication_plug.ex b/lib/pleroma/plugs/authentication_plug.ex index 3ac301b97..b240ff29f 100644 --- a/lib/pleroma/plugs/authentication_plug.ex +++ b/lib/pleroma/plugs/authentication_plug.ex @@ -26,14 +26,7 @@ defmodule Pleroma.Plugs.AuthenticationPlug do end end - def call( - %{ - assigns: %{ - auth_credentials: %{password: password} - } - } = conn, - _ - ) do + def call(%{assigns: %{auth_credentials: %{password: _}}} = conn, _) do Pbkdf2.dummy_checkpw() conn end diff --git a/lib/pleroma/plugs/basic_auth_decoder_plug.ex b/lib/pleroma/plugs/basic_auth_decoder_plug.ex index fc8fcee98..f7ebf7db2 100644 --- a/lib/pleroma/plugs/basic_auth_decoder_plug.ex +++ b/lib/pleroma/plugs/basic_auth_decoder_plug.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Plugs.BasicAuthDecoderPlug 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 diff --git a/lib/pleroma/plugs/federating_plug.ex b/lib/pleroma/plugs/federating_plug.ex index 4108d90af..f0442ca15 100644 --- a/lib/pleroma/plugs/federating_plug.ex +++ b/lib/pleroma/plugs/federating_plug.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.FederatingPlug 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 diff --git a/lib/pleroma/plugs/http_security_plug.ex b/lib/pleroma/plugs/http_security_plug.ex index 4c32653ea..f34f2364b 100644 --- a/lib/pleroma/plugs/http_security_plug.ex +++ b/lib/pleroma/plugs/http_security_plug.ex @@ -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 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug 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 ] diff --git a/lib/pleroma/plugs/session_authentication_plug.ex b/lib/pleroma/plugs/session_authentication_plug.ex index 904a27952..aed619432 100644 --- a/lib/pleroma/plugs/session_authentication_plug.ex +++ b/lib/pleroma/plugs/session_authentication_plug.ex @@ -1,6 +1,5 @@ defmodule Pleroma.Plugs.SessionAuthenticationPlug do import Plug.Conn - alias Pleroma.User def init(options) do options diff --git a/lib/pleroma/plugs/uploaded_media.ex b/lib/pleroma/plugs/uploaded_media.ex index 994cc8bf6..7e1e84126 100644 --- a/lib/pleroma/plugs/uploaded_media.ex +++ b/lib/pleroma/plugs/uploaded_media.ex @@ -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 = diff --git a/lib/pleroma/plugs/user_fetcher_plug.ex b/lib/pleroma/plugs/user_fetcher_plug.ex index 9cbaaf40a..e24785ad1 100644 --- a/lib/pleroma/plugs/user_fetcher_plug.ex +++ b/lib/pleroma/plugs/user_fetcher_plug.ex @@ -7,7 +7,7 @@ defmodule Pleroma.Plugs.UserFetcherPlug 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 diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index 4ca84152a..7f328d00d 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -85,7 +85,9 @@ defmodule Pleroma.ReverseProxy do | {:redirect_on_failure, boolean()} @spec call(Plug.Conn.t(), url :: String.t(), [option()]) :: Plug.Conn.t() - def call(conn = %{method: method}, url, opts \\ []) when method in @methods do + def call(_conn, _url, _opts \\ []) + + def call(conn = %{method: method}, url, opts) when method in @methods do hackney_opts = @default_hackney_options |> Keyword.merge(Keyword.get(opts, :http, [])) @@ -240,24 +242,23 @@ defmodule Pleroma.ReverseProxy do end defp build_req_headers(headers, opts) do - headers = - headers - |> downcase_headers() - |> Enum.filter(fn {k, _} -> k in @keep_req_headers end) - |> (fn headers -> - headers = headers ++ Keyword.get(opts, :req_headers, []) - - if Keyword.get(opts, :keep_user_agent, false) do - List.keystore( - headers, - "user-agent", - 0, - {"user-agent", Pleroma.Application.user_agent()} - ) - else - headers - end - end).() + headers + |> downcase_headers() + |> Enum.filter(fn {k, _} -> k in @keep_req_headers end) + |> (fn headers -> + headers = headers ++ Keyword.get(opts, :req_headers, []) + + if Keyword.get(opts, :keep_user_agent, false) do + List.keystore( + headers, + "user-agent", + 0, + {"user-agent", Pleroma.Application.user_agent()} + ) + else + headers + end + end).() end defp build_resp_headers(headers, opts) do @@ -268,7 +269,7 @@ defmodule Pleroma.ReverseProxy do |> (fn headers -> headers ++ Keyword.get(opts, :resp_headers, []) end).() end - defp build_resp_cache_headers(headers, opts) do + defp build_resp_cache_headers(headers, _opts) do has_cache? = Enum.any?(headers, fn {k, _} -> k in @resp_cache_headers end) if has_cache? do diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index bf2c60102..77cba2cd2 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -128,19 +128,18 @@ defmodule Pleroma.Upload do opts end - opts = - if Pleroma.Config.get([:instance, :dedupe_media]) == true && - !Enum.member?(opts.filters, Pleroma.Upload.Filter.Dedupe) do - Logger.warn(""" - Pleroma: configuration `:instance, :dedupe_media` is deprecated, please instead set: + if Pleroma.Config.get([:instance, :dedupe_media]) == true && + !Enum.member?(opts.filters, Pleroma.Upload.Filter.Dedupe) do + Logger.warn(""" + Pleroma: configuration `:instance, :dedupe_media` is deprecated, please instead set: - :pleroma, Pleroma.Upload, [filters: [Pleroma.Upload.Filter.Dedupe]] - """) + :pleroma, Pleroma.Upload, [filters: [Pleroma.Upload.Filter.Dedupe]] + """) - Map.put(opts, :filters, opts.filters ++ [Pleroma.Upload.Filter.Dedupe]) - else - opts - end + Map.put(opts, :filters, opts.filters ++ [Pleroma.Upload.Filter.Dedupe]) + else + opts + end end defp prepare_upload(%Plug.Upload{} = file, opts) do @@ -215,8 +214,4 @@ defmodule Pleroma.Upload do [base_url, "media", path] |> Path.join() end - - defp url_from_spec({:url, url}) do - url - end end diff --git a/lib/pleroma/upload/filter/dedupe.ex b/lib/pleroma/upload/filter/dedupe.ex index 28091a627..81ddd9b29 100644 --- a/lib/pleroma/upload/filter/dedupe.ex +++ b/lib/pleroma/upload/filter/dedupe.ex @@ -1,7 +1,7 @@ defmodule Pleroma.Upload.Filter.Dedupe do @behaviour Pleroma.Upload.Filter - def filter(upload = %Pleroma.Upload{name: name, tempfile: path}) do + def filter(upload = %Pleroma.Upload{name: name, tempfile: _path}) do extension = String.split(name, ".") |> List.last() shasum = :crypto.hash(:sha256, File.read!(upload.tempfile)) |> Base.encode16(case: :lower) filename = shasum <> "." <> extension diff --git a/lib/pleroma/upload/filter/mogrify.ex b/lib/pleroma/upload/filter/mogrify.ex index d6ed471ed..f106bd4b1 100644 --- a/lib/pleroma/upload/filter/mogrify.ex +++ b/lib/pleroma/upload/filter/mogrify.ex @@ -1,5 +1,5 @@ defmodule Pleroma.Upload.Filter.Mogrify do - @behaviour Pleroma.Uploader.Filter + @behaviour Pleroma.Upload.Filter @type conversion :: action :: String.t() | {action :: String.t(), opts :: String.t()} @type conversions :: conversion() | [conversion()] diff --git a/lib/pleroma/uploaders/local.ex b/lib/pleroma/uploaders/local.ex index 434a6b515..2994bcd51 100644 --- a/lib/pleroma/uploaders/local.ex +++ b/lib/pleroma/uploaders/local.ex @@ -1,8 +1,6 @@ defmodule Pleroma.Uploaders.Local do @behaviour Pleroma.Uploaders.Uploader - alias Pleroma.Web - def get_file(_) do {:ok, {:static_dir, upload_path()}} end diff --git a/lib/pleroma/uploaders/mdii.ex b/lib/pleroma/uploaders/mdii.ex index 820cf88f5..f06755056 100644 --- a/lib/pleroma/uploaders/mdii.ex +++ b/lib/pleroma/uploaders/mdii.ex @@ -12,8 +12,8 @@ defmodule Pleroma.Uploaders.MDII do end def put_file(upload) do - cgi = Pleroma.Config.get([Pleroma.Uploaders.MDII, :cgi]) - files = Pleroma.Config.get([Pleroma.Uploaders.MDII, :files]) + cgi = Config.get([Pleroma.Uploaders.MDII, :cgi]) + files = Config.get([Pleroma.Uploaders.MDII, :files]) {:ok, file_data} = File.read(upload.tempfile) diff --git a/lib/pleroma/uploaders/swift/swift.ex b/lib/pleroma/uploaders/swift/swift.ex index a5b3d2852..d4e758bbb 100644 --- a/lib/pleroma/uploaders/swift/swift.ex +++ b/lib/pleroma/uploaders/swift/swift.ex @@ -9,7 +9,6 @@ defmodule Pleroma.Uploaders.Swift.Client do end def upload_file(filename, body, content_type) do - object_url = Pleroma.Config.get!([Pleroma.Uploaders.Swift, :object_url]) token = Pleroma.Uploaders.Swift.Keystone.get_token() case put("#{filename}", body, "X-Auth-Token": token, "Content-Type": content_type) do diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index a290db04a..6a267ee58 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -2,7 +2,6 @@ defmodule Pleroma.User do use Ecto.Schema import Ecto.{Changeset, Query} - alias Ecto.Multi alias Pleroma.{Repo, User, Object, Web, Activity, Notification} alias Comeonin.Pbkdf2 alias Pleroma.Formatter @@ -10,6 +9,8 @@ defmodule Pleroma.User do alias Pleroma.Web.{OStatus, Websub, OAuth} alias Pleroma.Web.ActivityPub.{Utils, ActivityPub} + @type t :: %__MODULE__{} + schema "users" do field(:bio, :string) field(:email, :string) @@ -218,7 +219,7 @@ defmodule Pleroma.User do end end - def maybe_follow(%User{} = follower, %User{info: info} = followed) do + def maybe_follow(%User{} = follower, %User{info: _info} = followed) do if not following?(follower, followed) do follow(follower, followed) else @@ -280,6 +281,7 @@ defmodule Pleroma.User do end end + @spec following?(User.t(), User.t()) :: boolean def following?(%User{} = follower, %User{} = followed) do Enum.member?(follower.following, followed.follower_address) end @@ -824,20 +826,21 @@ defmodule Pleroma.User do end) end + def tag(nickname, tags) when is_binary(nickname), + do: tag(User.get_by_nickname(nickname), tags) + + def tag(%User{} = user, tags), + do: update_tags(user, Enum.uniq(user.tags ++ normalize_tags(tags))) + def untag(user_identifiers, tags) when is_list(user_identifiers) do Repo.transaction(fn -> for user_identifier <- user_identifiers, do: untag(user_identifier, tags) end) end - def tag(nickname, tags) when is_binary(nickname), do: tag(User.get_by_nickname(nickname), tags) - def untag(nickname, tags) when is_binary(nickname), do: untag(User.get_by_nickname(nickname), tags) - def tag(%User{} = user, tags), - do: update_tags(user, Enum.uniq(user.tags ++ normalize_tags(tags))) - def untag(%User{} = user, tags), do: update_tags(user, user.tags -- normalize_tags(tags)) defp update_tags(%User{} = user, new_tags) do diff --git a/lib/pleroma/user_invite_token.ex b/lib/pleroma/user_invite_token.ex index 48ee1019a..ce804f78e 100644 --- a/lib/pleroma/user_invite_token.ex +++ b/lib/pleroma/user_invite_token.ex @@ -3,7 +3,8 @@ defmodule Pleroma.UserInviteToken do import Ecto.Changeset - alias Pleroma.{User, UserInviteToken, Repo} + alias Pleroma.UserInviteToken + alias Pleroma.Repo schema "user_invite_tokens" do field(:token, :string) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index bf81d8039..31455343c 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -799,7 +799,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end # guard - def entire_thread_visible_for_user?(nil, user), do: false + def entire_thread_visible_for_user?(nil, _user), do: false # child def entire_thread_visible_for_user?( diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 3570a75cb..0317f3c8c 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -141,7 +141,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do json(conn, "error") end - def relay(conn, params) do + def relay(conn, _params) do with %User{} = user <- Relay.get_actor(), {:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do conn diff --git a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex index c8c74ede6..6fa48454a 100644 --- a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex +++ b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do @reply_prefix Regex.compile!("^re:[[:space:]]*", [:caseless]) def filter_by_summary( - %{"summary" => parent_summary} = parent, + %{"summary" => parent_summary} = _parent, %{"summary" => child_summary} = child ) when not is_nil(child_summary) and byte_size(child_summary) > 0 and @@ -19,7 +19,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do end end - def filter_by_summary(parent, child), do: child + def filter_by_summary(_parent, child), do: child def filter(%{"type" => activity_type} = object) when activity_type == "Create" do child = object["object"] diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 17b063609..e6af4b211 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -37,9 +37,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do @doc """ Checks that an imported AP object's actor matches the domain it came from. """ - def contain_origin(id, %{"actor" => nil}), do: :error + def contain_origin(_id, %{"actor" => nil}), do: :error - def contain_origin(id, %{"actor" => actor} = params) do + def contain_origin(id, %{"actor" => _actor} = params) do id_uri = URI.parse(id) actor_uri = URI.parse(get_actor(params)) @@ -50,9 +50,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do end end - def contain_origin_from_id(id, %{"id" => nil}), do: :error + def contain_origin_from_id(_id, %{"id" => nil}), do: :error - def contain_origin_from_id(id, %{"id" => other_id} = params) do + def contain_origin_from_id(id, %{"id" => other_id} = _params) do id_uri = URI.parse(id) other_uri = URI.parse(other_id) @@ -266,6 +266,32 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do def fix_content_map(object), do: object + defp mastodon_follow_hack(%{"id" => id, "actor" => follower_id}, followed) do + with true <- id =~ "follows", + %User{local: true} = follower <- User.get_cached_by_ap_id(follower_id), + %Activity{} = activity <- Utils.fetch_latest_follow(follower, followed) do + {:ok, activity} + else + _ -> {:error, nil} + end + end + + defp mastodon_follow_hack(_, _), do: {:error, nil} + + defp get_follow_activity(follow_object, followed) do + with object_id when not is_nil(object_id) <- Utils.get_ap_id(follow_object), + {_, %Activity{} = activity} <- {:activity, Activity.get_by_ap_id(object_id)} do + {:ok, activity} + else + # Can't find the activity. This might a Mastodon 2.3 "Accept" + {:activity, nil} -> + mastodon_follow_hack(follow_object, followed) + + _ -> + {:error, nil} + end + end + # disallow objects with bogus IDs def handle_incoming(%{"id" => nil}), do: :error def handle_incoming(%{"id" => ""}), do: :error @@ -331,34 +357,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do end end - defp mastodon_follow_hack(%{"id" => id, "actor" => follower_id}, followed) do - with true <- id =~ "follows", - %User{local: true} = follower <- User.get_cached_by_ap_id(follower_id), - %Activity{} = activity <- Utils.fetch_latest_follow(follower, followed) do - {:ok, activity} - else - _ -> {:error, nil} - end - end - - defp mastodon_follow_hack(_), do: {:error, nil} - - defp get_follow_activity(follow_object, followed) do - with object_id when not is_nil(object_id) <- Utils.get_ap_id(follow_object), - {_, %Activity{} = activity} <- {:activity, Activity.get_by_ap_id(object_id)} do - {:ok, activity} - else - # Can't find the activity. This might a Mastodon 2.3 "Accept" - {:activity, nil} -> - mastodon_follow_hack(follow_object, followed) - - _ -> - {:error, nil} - end - end - def handle_incoming( - %{"type" => "Accept", "object" => follow_object, "actor" => actor, "id" => id} = data + %{"type" => "Accept", "object" => follow_object, "actor" => _actor, "id" => _id} = data ) do with actor <- get_actor(data), %User{} = followed <- User.get_or_fetch_by_ap_id(actor), @@ -374,7 +374,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do local: false }) do if not User.following?(follower, followed) do - {:ok, follower} = User.follow(follower, followed) + {:ok, _follower} = User.follow(follower, followed) end {:ok, activity} @@ -384,7 +384,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do end def handle_incoming( - %{"type" => "Reject", "object" => follow_object, "actor" => actor, "id" => id} = data + %{"type" => "Reject", "object" => follow_object, "actor" => _actor, "id" => _id} = data ) do with actor <- get_actor(data), %User{} = followed <- User.get_or_fetch_by_ap_id(actor), @@ -408,7 +408,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do end def handle_incoming( - %{"type" => "Like", "object" => object_id, "actor" => actor, "id" => id} = data + %{"type" => "Like", "object" => object_id, "actor" => _actor, "id" => id} = data ) do with actor <- get_actor(data), %User{} = actor <- User.get_or_fetch_by_ap_id(actor), @@ -421,7 +421,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do end def handle_incoming( - %{"type" => "Announce", "object" => object_id, "actor" => actor, "id" => id} = data + %{"type" => "Announce", "object" => object_id, "actor" => _actor, "id" => id} = data ) do with actor <- get_actor(data), %User{} = actor <- User.get_or_fetch_by_ap_id(actor), @@ -492,7 +492,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do %{ "type" => "Undo", "object" => %{"type" => "Announce", "object" => object_id}, - "actor" => actor, + "actor" => _actor, "id" => id } = data ) do @@ -520,7 +520,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do User.unfollow(follower, followed) {:ok, activity} else - e -> :error + _e -> :error end end @@ -539,12 +539,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do User.unblock(blocker, blocked) {:ok, activity} else - e -> :error + _e -> :error end end def handle_incoming( - %{"type" => "Block", "object" => blocked, "actor" => blocker, "id" => id} = data + %{"type" => "Block", "object" => blocked, "actor" => blocker, "id" => id} = _data ) do with true <- Pleroma.Config.get([:activitypub, :accept_blocks]), %User{local: true} = blocked = User.get_cached_by_ap_id(blocked), @@ -554,7 +554,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do User.block(blocker, blocked) {:ok, activity} else - e -> :error + _e -> :error end end @@ -562,7 +562,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do %{ "type" => "Undo", "object" => %{"type" => "Like", "object" => object_id}, - "actor" => actor, + "actor" => _actor, "id" => id } = data ) do diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 549148989..074622f2b 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -292,7 +292,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do """ def make_follow_data( %User{ap_id: follower_id}, - %User{ap_id: followed_id} = followed, + %User{ap_id: followed_id} = _followed, activity_id ) do data = %{ diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 0bd85e0b6..451a87900 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -66,10 +66,15 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_cng) - {:ok, user} = User.update_and_set_cache(cng) + {:ok, _user} = User.update_and_set_cache(cng) + json(conn, info) + end + + def right_add(conn, _) do conn - |> json(info) + |> put_status(404) + |> json(%{error: "No such permission_group"}) end def right_get(conn, %{"nickname" => nickname}) do @@ -82,12 +87,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do }) end - def right_add(conn, _) do - conn - |> put_status(404) - |> json(%{error: "No such permission_group"}) - end - def right_delete( %{assigns: %{user: %User{:nickname => admin_nickname}}} = conn, %{ @@ -113,10 +112,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_cng) - {:ok, user} = User.update_and_set_cache(cng) + {:ok, _user} = User.update_and_set_cache(cng) - conn - |> json(info) + json(conn, info) end end @@ -127,32 +125,28 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do end def relay_follow(conn, %{"relay_url" => target}) do - {status, message} = Relay.follow(target) - - if status == :ok do - conn - |> json(target) + with {:ok, _message} <- Relay.follow(target) do + json(conn, target) else - conn - |> put_status(500) - |> json(target) + _ -> + conn + |> put_status(500) + |> json(target) end end def relay_unfollow(conn, %{"relay_url" => target}) do - {status, message} = Relay.unfollow(target) - - if status == :ok do - conn - |> json(target) + with {:ok, _message} <- Relay.unfollow(target) do + json(conn, target) else - conn - |> put_status(500) - |> json(target) + _ -> + conn + |> put_status(500) + |> json(target) end end - @shortdoc "Get a account registeration invite token (base64 string)" + @doc "Get a account registeration invite token (base64 string)" def get_invite_token(conn, _params) do {:ok, token} = Pleroma.UserInviteToken.create_token() @@ -160,7 +154,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do |> json(token.token) end - @shortdoc "Get a password reset token (base64 string) for given nickname" + @doc "Get a password reset token (base64 string) for given nickname" def get_password_reset(conn, %{"nickname" => nickname}) do (%User{local: true} = user) = User.get_by_nickname(nickname) {:ok, token} = Pleroma.PasswordResetToken.create_token(user) diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 728f24c7e..8f2625cef 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -122,7 +122,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do |> Formatter.finalize() end - def format_input(text, mentions, tags, "text/html") do + def format_input(text, mentions, _tags, "text/html") do text |> Formatter.html_escape("text/html") |> String.replace(~r/\r?\n/, "
") @@ -236,7 +236,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do end end - def emoji_from_profile(%{info: info} = user) do + def emoji_from_profile(%{info: _info} = user) do (Formatter.get_emoji(user.bio) ++ Formatter.get_emoji(user.name)) |> Enum.map(fn {shortcode, url} -> %{ diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index ac3d7c132..6dbf07e13 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -13,7 +13,6 @@ defmodule Pleroma.Web.Federator do @websub Application.get_env(:pleroma, :websub) @ostatus Application.get_env(:pleroma, :ostatus) - @httpoison Application.get_env(:pleroma, :httpoison) @max_jobs 20 def init(args) do @@ -134,7 +133,7 @@ defmodule Pleroma.Web.Federator do def handle( :publish_single_websub, - %{xml: xml, topic: topic, callback: callback, secret: secret} = params + %{xml: _xml, topic: _topic, callback: _callback, secret: _secret} = params ) do case Websub.publish_one(params) do {:ok, _} -> diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex index 13df40c80..3997d68a7 100644 --- a/lib/pleroma/web/federator/retry_queue.ex +++ b/lib/pleroma/web/federator/retry_queue.ex @@ -1,13 +1,8 @@ defmodule Pleroma.Web.Federator.RetryQueue do use GenServer - alias Pleroma.Web.{WebFinger, Websub} - alias Pleroma.Web.ActivityPub.ActivityPub + require Logger - @websub Application.get_env(:pleroma, :websub) - @ostatus Application.get_env(:pleroma, :websub) - @httpoison Application.get_env(:pleroma, :websub) - @instance Application.get_env(:pleroma, :websub) # initial timeout, 5 min @initial_timeout 30_000 @max_retries 5 @@ -42,7 +37,7 @@ defmodule Pleroma.Web.Federator.RetryQueue do def handle_cast({:maybe_enqueue, data, transport, retries}, %{dropped: drop_count} = state) do case get_retry_params(retries) do - {:retry, timeout} -> + {:retry, _timeout} -> Process.send_after( __MODULE__, {:send, data, transport, retries}, @@ -62,7 +57,7 @@ defmodule Pleroma.Web.Federator.RetryQueue do {:ok, _} -> {:noreply, %{state | delivered: delivery_count + 1}} - {:error, reason} -> + {:error, _reason} -> enqueue(data, transport, retries) {:noreply, state} end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 2d7b1a00c..5c8602322 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -437,10 +437,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end # Instead of returning a 400 when no "id" params is present, Mastodon returns an empty array. - def relationships(%{assigns: %{user: user}} = conn, _) do - conn - |> json([]) - end + def relationships(%{assigns: %{user: _user}} = conn, _), do: json(conn, []) def update_media(%{assigns: %{user: user}} = conn, data) do with %Object{} = object <- Repo.get(Object, data["id"]), @@ -850,7 +847,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def list_timeline(%{assigns: %{user: user}} = conn, %{"list_id" => id} = params) do - with %Pleroma.List{title: title, following: following} <- Pleroma.List.get(id, user) do + with %Pleroma.List{title: _title, following: following} <- Pleroma.List.get(id, user) do params = params |> Map.put("type", "Create") @@ -983,13 +980,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do with changeset <- User.update_changeset(user), changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng), - {:ok, user} <- User.update_and_set_cache(changeset) do - conn - |> json(%{}) + {:ok, _user} <- User.update_and_set_cache(changeset) do + json(conn, %{}) else e -> - conn - |> json(%{error: inspect(e)}) + json(conn, %{error: inspect(e)}) end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_socket.ex b/lib/pleroma/web/mastodon_api/mastodon_socket.ex index f3c13d1aa..d85f2a462 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_socket.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_socket.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do alias Pleroma.{User, Repo} transport( - :streaming, + :websocket, Phoenix.Transports.WebSocket.Raw, # We never receive data. timeout: :infinity @@ -52,13 +52,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do _ -> stream end - with socket = - socket - |> assign(:topic, topic) do + with socket <- assign(socket, :topic, topic) do Pleroma.Web.Streamer.add_socket(topic, socket) {:ok, socket} - else - _e -> :error end end diff --git a/lib/pleroma/web/mastodon_api/views/mastodon_view.ex b/lib/pleroma/web/mastodon_api/views/mastodon_view.ex index 370fad374..1fd05d9f1 100644 --- a/lib/pleroma/web/mastodon_api/views/mastodon_view.ex +++ b/lib/pleroma/web/mastodon_api/views/mastodon_view.ex @@ -1,5 +1,4 @@ defmodule Pleroma.Web.MastodonAPI.MastodonView do use Pleroma.Web, :view import Phoenix.HTML - import Phoenix.HTML.Form end diff --git a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex index 68bb45494..c8b95d14c 100644 --- a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex +++ b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex @@ -1,6 +1,5 @@ defmodule Pleroma.Web.MastodonAPI.PushSubscriptionView do use Pleroma.Web, :view - alias Pleroma.Web.MastodonAPI.PushSubscriptionView def render("push_subscription.json", %{subscription: subscription}) do %{ diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex index f496fc936..ce4f15be0 100644 --- a/lib/pleroma/web/media_proxy/controller.ex +++ b/lib/pleroma/web/media_proxy/controller.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do with config <- Pleroma.Config.get([:media_proxy], []), true <- Keyword.get(config, :enabled, false), {:ok, url} <- MediaProxy.decode_url(sig64, url64), - filename <- Path.basename(URI.parse(url).path), + _filename <- Path.basename(URI.parse(url).path), :ok <- filename_matches(Map.has_key?(params, "filename"), conn.request_path, url) do ReverseProxy.call(conn, url, Keyword.get(config, :proxy_opts, @default_proxy_opts)) else diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index d03c8b05a..20c2e799b 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -121,7 +121,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do def token_exchange( conn, - %{"grant_type" => "password", "name" => name, "password" => password} = params + %{"grant_type" => "password", "name" => name, "password" => _password} = params ) do params = params diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 53d71440e..3ad2e7591 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -376,7 +376,7 @@ defmodule Pleroma.Web.OStatus do def fetch_activity_from_url(url) do try do - with {:ok, activities} when length(activities) > 0 <- fetch_activity_from_atom_url(url) do + with {:ok, activities} when activities != [] <- fetch_activity_from_atom_url(url) do {:ok, activities} else _e -> diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index af6e22c2b..9dfcf0f95 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -157,7 +157,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do conn, "activity+json", %Activity{data: %{"type" => "Create"}} = activity, - user + _user ) do object = Object.normalize(activity.data["object"]) @@ -166,7 +166,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do |> json(ObjectView.render("object.json", %{object: object})) end - defp represent_activity(conn, "activity+json", _, _) do + defp represent_activity(_conn, "activity+json", _, _) do {:error, :not_found} end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 4d24d4c1c..9c06fac4f 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -1,8 +1,6 @@ defmodule Pleroma.Web.Router do use Pleroma.Web, :router - alias Pleroma.{Repo, User, Web.Router} - pipeline :api do plug(:accepts, ["json"]) plug(:fetch_session) diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index 99b8b7063..29c44e9d5 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -61,8 +61,6 @@ defmodule Pleroma.Web.Streamer do end def handle_cast(%{action: :stream, topic: "list", item: item}, topics) do - author = User.get_cached_by_ap_id(item.data["actor"]) - # filter the recipient list if the activity is not public, see #270. recipient_lists = case ActivityPub.is_public?(item) do diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 092779010..0ed519ea6 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -6,9 +6,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do alias Pleroma.Web.WebFinger alias Pleroma.Web.CommonAPI alias Comeonin.Pbkdf2 - alias Pleroma.{Formatter, Emoji} alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.{Repo, PasswordResetToken, User} + alias Pleroma.{Repo, PasswordResetToken, User, Emoji} def show_password_reset(conn, %{"token" => token}) do with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}), diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index fbd33f07e..2808192b0 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -141,7 +141,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do end def to_map( - %Activity{data: %{"object" => %{"content" => content} = object}} = activity, + %Activity{data: %{"object" => %{"content" => _content} = object}} = activity, %{user: user} = opts ) do created_at = object["published"] |> Utils.date_to_asctime() @@ -165,7 +165,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags - {summary, content} = ActivityView.render_content(object) + {_summary, content} = ActivityView.render_content(object) html = HTML.filter_tags(content, User.html_filter_policy(opts[:for])) @@ -173,7 +173,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do video = if object["type"] == "Video" do - vid = [object] + [object] else [] end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 9c485d965..79ea48d86 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -2,18 +2,15 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do alias Pleroma.{UserInviteToken, User, Activity, Repo, Object} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.UserView - alias Pleroma.Web.{OStatus, CommonAPI} - alias Pleroma.Web.MediaProxy + alias Pleroma.Web.CommonAPI import Ecto.Query - @httpoison Application.get_env(:pleroma, :httpoison) - def create_status(%User{} = user, %{"status" => _} = data) do CommonAPI.post(user, data) end def delete(%User{} = user, id) do - with %Activity{data: %{"type" => type}} <- Repo.get(Activity, id), + with %Activity{data: %{"type" => _type}} <- Repo.get(Activity, id), {:ok, activity} <- CommonAPI.delete(id, user) do {:ok, activity} end @@ -37,7 +34,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do def unfollow(%User{} = follower, params) do with {:ok, %User{} = unfollowed} <- get_user(params), - {:ok, follower, follow_activity} <- User.unfollow(follower, unfollowed), + {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed), {:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed) do {:ok, follower, unfollowed} else @@ -244,10 +241,6 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do _activities = Repo.all(q) end - defp make_date do - DateTime.utc_now() |> DateTime.to_iso8601() - end - # DEPRECATED mostly, context objects are now created at insertion time. def context_to_conversation_id(context) do with %Object{id: id} <- Object.get_cached_by_ap_id(context) do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 0ccf937b0..786849aa3 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -1,9 +1,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do use Pleroma.Web, :controller - alias Pleroma.Formatter alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView} alias Pleroma.Web.CommonAPI - alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils alias Pleroma.{Repo, Activity, Object, User, Notification} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils @@ -155,7 +153,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do |> render(NotificationView, "notification.json", %{notifications: notifications, for: user}) end - def notifications_read(%{assigns: %{user: user}} = conn, _) do + def notifications_read(%{assigns: %{user: _user}} = conn, _) do bad_request_reply(conn, "You need to specify latest_id") end @@ -416,7 +414,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end - def approve_friend_request(conn, %{"user_id" => uid} = params) do + def approve_friend_request(conn, %{"user_id" => uid} = _params) do with followed <- conn.assigns[:user], uid when is_number(uid) <- String.to_integer(uid), %User{} = follower <- Repo.get(User, uid), @@ -436,7 +434,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end - def deny_friend_request(conn, %{"user_id" => uid} = params) do + def deny_friend_request(conn, %{"user_id" => uid} = _params) do with followed <- conn.assigns[:user], uid when is_number(uid) <- String.to_integer(uid), %User{} = follower <- Repo.get(User, uid), diff --git a/lib/pleroma/web/xml/xml.ex b/lib/pleroma/web/xml/xml.ex index da3f68ecb..63d3302e0 100644 --- a/lib/pleroma/web/xml/xml.ex +++ b/lib/pleroma/web/xml/xml.ex @@ -28,12 +28,12 @@ defmodule Pleroma.Web.XML do |> :xmerl_scan.string() doc - catch - :exit, _error -> + rescue + _e -> Logger.debug("Couldn't parse XML: #{inspect(text)}") :error - rescue - e -> + catch + :exit, _error -> Logger.debug("Couldn't parse XML: #{inspect(text)}") :error end -- cgit v1.2.3 From cbe048bb3ffb8f74752e4668957fbf105cedbf62 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 9 Dec 2018 20:17:35 +0100 Subject: Mix tasks: improve uploads.ex moduledoc --- lib/mix/tasks/pleroma/uploads.ex | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index 0742ab378..d934bd6dc 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -6,11 +6,17 @@ defmodule Mix.Tasks.Pleroma.Uploads do require Logger @log_every 50 - @shortdoc "Migrate uploads from local to remote storage" - @longdoc """ - Manages uploads + @shortdoc "Manages uploads" + @moduledoc """ + Manages uploads. + ## Migrate uploads from local to remote storage + mix pleroma.uploads migrate_local TARGET_UPLOADER [OPTIONS...] + Options: + - `--delete` - delete local uploads after migrating them to the target uploader + + A list of avalible uploaders can be seen in config.exs """ def run(["migrate_local", target_uploader | args]) do -- cgit v1.2.3 From 9ba4a1c5fe1cbc6f028f04be9c953a189a08bd09 Mon Sep 17 00:00:00 2001 From: raeno Date: Mon, 10 Dec 2018 01:01:43 +0400 Subject: Fixes #415. Properly handle nil and empty string by User.parse_bio --- lib/pleroma/user.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index a290db04a..5d05dddfa 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -804,7 +804,11 @@ defmodule Pleroma.User do end end - def parse_bio(bio, user \\ %User{info: %{source_data: %{}}}) do + def parse_bio(bio, user \\ %User{info: %{source_data: %{}}}) + def parse_bio(nil, user), do: "" + def parse_bio(bio, user) when bio == "", do: bio + + def parse_bio(bio, user) do mentions = Formatter.parse_mentions(bio) tags = Formatter.parse_tags(bio) -- cgit v1.2.3 From 993c8c8bd4e94985c647f4f9e927cbaa7148e6a0 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 10 Dec 2018 08:03:17 +0300 Subject: Keep the shortdoc descriptive --- lib/mix/tasks/pleroma/uploads.ex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index d934bd6dc..6ffc941c9 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -6,10 +6,8 @@ defmodule Mix.Tasks.Pleroma.Uploads do require Logger @log_every 50 - @shortdoc "Manages uploads" + @shortdoc "Migrates uploads from local to remote storage" @moduledoc """ - Manages uploads. - ## Migrate uploads from local to remote storage mix pleroma.uploads migrate_local TARGET_UPLOADER [OPTIONS...] Options: -- cgit v1.2.3 From e94c3442f4b88f4eedf4e4cc67e91a1375df6afd Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Mon, 10 Dec 2018 09:39:57 +0300 Subject: updates --- lib/mix/tasks/pleroma/uploads.ex | 2 +- lib/pleroma/upload.ex | 2 ++ lib/pleroma/upload/filter/dedupe.ex | 5 +++-- lib/pleroma/web/admin_api/admin_api_controller.ex | 3 ++- lib/pleroma/web/federator/retry_queue.ex | 4 ++-- lib/pleroma/web/mastodon_api/mastodon_socket.ex | 13 +++++++++---- lib/pleroma/web/media_proxy/controller.ex | 8 ++++---- lib/pleroma/web/ostatus/ostatus.ex | 21 ++++++++------------- 8 files changed, 31 insertions(+), 27 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index 45bfd254c..c6b840130 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -57,7 +57,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do File.exists?(root_path) -> file = Path.basename(id) - [hash, _ext] = String.split(id, ".") + hash = Path.rootname(id) {%Pleroma.Upload{id: hash, name: file, path: file, tempfile: root_path}, root_path} true -> diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 77cba2cd2..07031ac58 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -214,4 +214,6 @@ defmodule Pleroma.Upload do [base_url, "media", path] |> Path.join() end + + defp url_from_spec(_base_url, {:url, url}), do: url end diff --git a/lib/pleroma/upload/filter/dedupe.ex b/lib/pleroma/upload/filter/dedupe.ex index 81ddd9b29..0657b2c8d 100644 --- a/lib/pleroma/upload/filter/dedupe.ex +++ b/lib/pleroma/upload/filter/dedupe.ex @@ -1,10 +1,11 @@ defmodule Pleroma.Upload.Filter.Dedupe do @behaviour Pleroma.Upload.Filter + alias Pleroma.Upload - def filter(upload = %Pleroma.Upload{name: name, tempfile: _path}) do + def filter(upload = %Upload{name: name}) do extension = String.split(name, ".") |> List.last() shasum = :crypto.hash(:sha256, File.read!(upload.tempfile)) |> Base.encode16(case: :lower) filename = shasum <> "." <> extension - {:ok, %Pleroma.Upload{upload | id: shasum, path: filename}} + {:ok, %Upload{upload | id: shasum, path: filename}} end end diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 451a87900..06c3c7c81 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -63,7 +63,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do info_cng = User.Info.admin_api_update(user.info, info) cng = - Ecto.Changeset.change(user) + user + |> Ecto.Changeset.change() |> Ecto.Changeset.put_embed(:info, info_cng) {:ok, _user} = User.update_and_set_cache(cng) diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex index 3997d68a7..510b4315d 100644 --- a/lib/pleroma/web/federator/retry_queue.ex +++ b/lib/pleroma/web/federator/retry_queue.ex @@ -37,11 +37,11 @@ defmodule Pleroma.Web.Federator.RetryQueue do def handle_cast({:maybe_enqueue, data, transport, retries}, %{dropped: drop_count} = state) do case get_retry_params(retries) do - {:retry, _timeout} -> + {:retry, timeout} -> Process.send_after( __MODULE__, {:send, data, transport, retries}, - growth_function(retries) + timeout ) {:noreply, state} diff --git a/lib/pleroma/web/mastodon_api/mastodon_socket.ex b/lib/pleroma/web/mastodon_api/mastodon_socket.ex index d85f2a462..755ac5730 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_socket.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_socket.ex @@ -11,6 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do timeout: :infinity ) + @spec connect(params :: map(), Phoenix.Socket.t()) :: {:ok, Phoenix.Socket.t()} | :error def connect(%{"access_token" => token} = params, socket) do with %Token{user_id: user_id} <- Repo.get_by(Token, token: token), %User{} = user <- Repo.get(User, user_id), @@ -52,12 +53,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do _ -> stream end - with socket <- assign(socket, :topic, topic) do - Pleroma.Web.Streamer.add_socket(topic, socket) - {:ok, socket} - end + socket = + socket + |> assign(:topic, topic) + + Pleroma.Web.Streamer.add_socket(topic, socket) + {:ok, socket} end + def connect(_params, _socket), do: :error + def id(_), do: nil def handle(:text, message, _state) do diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex index ce4f15be0..63140feb9 100644 --- a/lib/pleroma/web/media_proxy/controller.ex +++ b/lib/pleroma/web/media_proxy/controller.ex @@ -8,7 +8,6 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do with config <- Pleroma.Config.get([:media_proxy], []), true <- Keyword.get(config, :enabled, false), {:ok, url} <- MediaProxy.decode_url(sig64, url64), - _filename <- Path.basename(URI.parse(url).path), :ok <- filename_matches(Map.has_key?(params, "filename"), conn.request_path, url) do ReverseProxy.call(conn, url, Keyword.get(config, :proxy_opts, @default_proxy_opts)) else @@ -31,9 +30,10 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do path = URI.decode(path) - cond do - has_filename && filename && Path.basename(path) != filename -> {:wrong_filename, filename} - true -> :ok + if has_filename && filename && Path.basename(path) != filename do + {:wrong_filename, filename} + else + :ok end end end diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 3ad2e7591..c6440c20e 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -375,19 +375,14 @@ defmodule Pleroma.Web.OStatus do end def fetch_activity_from_url(url) do - try do - with {:ok, activities} when activities != [] <- fetch_activity_from_atom_url(url) do - {:ok, activities} - else - _e -> - with {:ok, activities} <- fetch_activity_from_html_url(url) do - {:ok, activities} - end - end - rescue - e -> - Logger.debug("Couldn't get #{url}: #{inspect(e)}") - {:error, "Couldn't get #{url}: #{inspect(e)}"} + with {:ok, [_ | _] = activities} <- fetch_activity_from_atom_url(url) do + {:ok, activities} + else + _e -> fetch_activity_from_html_url(url) end + rescue + e -> + Logger.debug("Couldn't get #{url}: #{inspect(e)}") + {:error, "Couldn't get #{url}: #{inspect(e)}"} end end -- cgit v1.2.3 From c81c74d84715b25447840cf8536ac4ba0a4e98f1 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 10 Dec 2018 19:13:53 +0100 Subject: Treat warnings as errors outside of tests. --- lib/pleroma/web/federator/federator.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index 6dbf07e13..a9c7aecd5 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -150,7 +150,7 @@ defmodule Pleroma.Web.Federator do end if Mix.env() == :test do - def enqueue(type, payload, priority \\ 1) do + def enqueue(type, payload, _priority \\ 1) do if Pleroma.Config.get([:instance, :federating]) do handle(type, payload) end -- cgit v1.2.3 From d6bf06ab4fb493d5e240092988fe37f2d6a655a3 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 10 Dec 2018 20:49:06 +0100 Subject: Fix warnings. --- lib/pleroma/user.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index dc67f29c6..bcc34b38f 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -807,8 +807,8 @@ defmodule Pleroma.User do end def parse_bio(bio, user \\ %User{info: %{source_data: %{}}}) - def parse_bio(nil, user), do: "" - def parse_bio(bio, user) when bio == "", do: bio + def parse_bio(nil, _user), do: "" + def parse_bio(bio, _user) when bio == "", do: bio def parse_bio(bio, user) do mentions = Formatter.parse_mentions(bio) -- cgit v1.2.3 From 213176c3c33088794ec2557fe54b10481ed603ed Mon Sep 17 00:00:00 2001 From: scarlett Date: Mon, 10 Dec 2018 23:15:01 +0000 Subject: Add new frontend options to server-side config. --- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 0ed519ea6..b1e4c77e8 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -183,7 +183,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do formattingOptionsEnabled: Keyword.get(instance_fe, :formatting_options_enabled), collapseMessageWithSubject: Keyword.get(instance_fe, :collapse_message_with_subject), hidePostStats: Keyword.get(instance_fe, :hide_post_stats), - hideUserStats: Keyword.get(instance_fe, :hide_user_stats) + hideUserStats: Keyword.get(instance_fe, :hide_user_stats), + scopeCopy: Keyword.get(instance_fe, :scope_copy), + subjectLineBehavior: Keyword.get(instance_fe, :subject_line_behavior), + alwaysShowSubjectInput: Keyword.get(instance_fe, :always_show_subject_input) } managed_config = Keyword.get(instance, :managed_config) -- cgit v1.2.3 From 89b3729afa130a62a47ed6372350ebfc5acb4064 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Tue, 11 Dec 2018 15:31:52 +0300 Subject: fix warnings --- lib/pleroma/user.ex | 20 ++++++++++---------- lib/pleroma/web/common_api/utils.ex | 11 ++++++----- lib/pleroma/web/salmon/salmon.ex | 2 +- lib/pleroma/web/web_finger/web_finger.ex | 3 +-- lib/pleroma/web/xml/xml.ex | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index bcc34b38f..e146b562c 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -212,7 +212,7 @@ defmodule Pleroma.User do end def maybe_direct_follow(%User{} = follower, %User{} = followed) do - if !User.ap_enabled?(followed) do + if not User.ap_enabled?(followed) do follow(follower, followed) else {:ok, follower} @@ -736,7 +736,8 @@ defmodule Pleroma.User do source_data: %{"publicKey" => %{"publicKeyPem" => public_key_pem}} }) do key = - :public_key.pem_decode(public_key_pem) + public_key_pem + |> :public_key.pem_decode() |> hd() |> :public_key.pem_entry_decode() @@ -774,13 +775,10 @@ defmodule Pleroma.User do def ap_enabled?(%User{info: info}), do: info.ap_enabled def ap_enabled?(_), do: false - def get_or_fetch(uri_or_nickname) do - if String.starts_with?(uri_or_nickname, "http") do - get_or_fetch_by_ap_id(uri_or_nickname) - else - get_or_fetch_by_nickname(uri_or_nickname) - end - end + @doc "Gets or fetch a user by uri or nickname." + @spec get_or_fetch(String.t()) :: User.t() + def get_or_fetch("http" <> _host = uri), do: get_or_fetch_by_ap_id(uri) + def get_or_fetch(nickname), do: get_or_fetch_by_nickname(nickname) # wait a period of time and return newest version of the User structs # this is because we have synchronous follow APIs and need to simulate them @@ -821,7 +819,9 @@ defmodule Pleroma.User do {String.trim(name, ":"), url} end) - CommonUtils.format_input(bio, mentions, tags, "text/plain") |> Formatter.emojify(emoji) + bio + |> CommonUtils.format_input(mentions, tags, "text/plain") + |> Formatter.emojify(emoji) end def tag(user_identifiers, tags) when is_list(user_identifiers) do diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 8f2625cef..ce0926b99 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -1,11 +1,12 @@ defmodule Pleroma.Web.CommonAPI.Utils do - alias Pleroma.{Repo, Object, Formatter, Activity} + alias Calendar.Strftime + alias Comeonin.Pbkdf2 + alias Pleroma.{Activity, Formatter, Object, Repo} + alias Pleroma.User + alias Pleroma.Web alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.Endpoint alias Pleroma.Web.MediaProxy - alias Pleroma.User - alias Calendar.Strftime - alias Comeonin.Pbkdf2 # This is a hack for twidere. def get_by_id_or_ap_id(id) do @@ -148,7 +149,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do |> Enum.sort_by(fn {tag, _} -> -String.length(tag) end) Enum.reduce(tags, text, fn {full, tag}, text -> - url = "" + url = "" String.replace(text, full, url) end) end diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 0e2cfddd0..b67b1333f 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -180,7 +180,7 @@ defmodule Pleroma.Web.Salmon do "Undo", "Delete" ] - def publish(user, activity, poster \\ &@httpoison.post/4) + def publish(user, activity, poster \\ &@httpoison.post/3) def publish(%{info: %{keys: keys}} = user, %{data: %{"type" => type}} = activity, poster) when type in @supported_activities do diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 0ff3b8b5f..47c733da2 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -256,8 +256,7 @@ defmodule Pleroma.Web.WebFinger do with response <- @httpoison.get( address, - [Accept: "application/xrd+xml,application/jrd+json"], - follow_redirect: true + Accept: "application/xrd+xml,application/jrd+json" ), {:ok, %{status: status, body: body}} when status in 200..299 <- response do doc = XML.parse_document(body) diff --git a/lib/pleroma/web/xml/xml.ex b/lib/pleroma/web/xml/xml.ex index 63d3302e0..b3ccf4a55 100644 --- a/lib/pleroma/web/xml/xml.ex +++ b/lib/pleroma/web/xml/xml.ex @@ -25,7 +25,7 @@ defmodule Pleroma.Web.XML do {doc, _rest} = text |> :binary.bin_to_list() - |> :xmerl_scan.string() + |> :xmerl_scan.string(quiet: true) doc rescue -- cgit v1.2.3 From 10c156d98fee44444ed6d1366e615ddcdb2ee68a Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Mon, 10 Dec 2018 20:20:50 +0300 Subject: [#114] SMTP deps and config. --- lib/pleroma/emails/mailer.ex | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lib/pleroma/emails/mailer.ex (limited to 'lib') diff --git a/lib/pleroma/emails/mailer.ex b/lib/pleroma/emails/mailer.ex new file mode 100644 index 000000000..14ed32ea8 --- /dev/null +++ b/lib/pleroma/emails/mailer.ex @@ -0,0 +1,3 @@ +defmodule Pleroma.Mailer do + use Swoosh.Mailer, otp_app: :pleroma +end -- cgit v1.2.3 From 12905ce1ad39106251e401fec81b871799708cc4 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 11 Dec 2018 14:59:25 +0300 Subject: [#114] Added /dev/mailbox dev-only route (emails preview). Added mailer config examples. --- lib/pleroma/web/router.ex | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 9c06fac4f..19b8750fc 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -85,6 +85,15 @@ defmodule Pleroma.Web.Router do plug(:accepts, ["html", "json"]) end + pipeline :mailbox_preview do + plug(:accepts, ["html"]) + + plug(:put_secure_browser_headers, %{ + "content-security-policy" => + "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'" + }) + end + scope "/api/pleroma", Pleroma.Web.TwitterAPI do pipe_through(:pleroma_api) get("/password_reset/:token", UtilController, :show_password_reset) @@ -268,6 +277,7 @@ defmodule Pleroma.Web.Router do get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation) post("/account/register", TwitterAPI.Controller, :register) + post("/account/reset_password", TwitterAPI.Controller, :reset_password) get("/search", TwitterAPI.Controller, :search) get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline) @@ -424,6 +434,14 @@ defmodule Pleroma.Web.Router do get("/:sig/:url/:filename", MediaProxyController, :remote) end + if Mix.env() == :dev do + scope "/dev" do + pipe_through([:mailbox_preview]) + + forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox") + end + end + scope "/", Fallback do get("/registration/:token", RedirectController, :registration_page) get("/*path", RedirectController, :redirector) -- cgit v1.2.3 From f5afb11032913fe523bd688954b4923f357c7802 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 11 Dec 2018 20:17:49 +0300 Subject: [#114] Initial implementation of user password reset emails (user-initiated). --- lib/pleroma/emails/user_email.ex | 37 ++++++++++++++++++++++ lib/pleroma/web/router.ex | 2 +- .../web/twitter_api/twitter_api_controller.ex | 19 +++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lib/pleroma/emails/user_email.ex (limited to 'lib') diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex new file mode 100644 index 000000000..46d8b9c2d --- /dev/null +++ b/lib/pleroma/emails/user_email.ex @@ -0,0 +1,37 @@ +defmodule Pleroma.UserEmail do + @moduledoc "User emails" + + import Swoosh.Email + + alias Pleroma.Web.{Endpoint, Router} + + defp instance_config, do: Pleroma.Config.get(:instance) + + defp instance_name, do: instance_config()[:name] + + defp from do + {instance_name(), instance_config()[:email]} + end + + def password_reset_email(user, password_reset_token) when is_binary(password_reset_token) do + password_reset_url = + Router.Helpers.util_url( + Endpoint, + :show_password_reset, + password_reset_token + ) + + html_body = """ +

Reset your password at #{instance_name()}

+

Someone has requested password change for your account at #{instance_name()}.

+

If it was you, visit the following link to proceed: reset password.

+

If it was someone else, nothing to worry about: your data is secure and your password has not been changed.

+ """ + + new() + |> to({user.name, user.email}) + |> from(from()) + |> subject("Password reset") + |> html_body(html_body) + end +end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 19b8750fc..6253a28db 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -277,7 +277,7 @@ defmodule Pleroma.Web.Router do get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation) post("/account/register", TwitterAPI.Controller, :register) - post("/account/reset_password", TwitterAPI.Controller, :reset_password) + post("/account/password_reset", TwitterAPI.Controller, :password_reset) get("/search", TwitterAPI.Controller, :search) get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 786849aa3..8837db566 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -1,5 +1,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do use Pleroma.Web, :controller + + import Pleroma.Web.ControllerHelper, only: [json_response: 3] + + alias Pleroma.Formatter alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView} alias Pleroma.Web.CommonAPI alias Pleroma.{Repo, Activity, Object, User, Notification} @@ -322,6 +326,21 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def password_reset(conn, params) do + nickname_or_email = params["email"] || params["nickname"] + + with is_binary(nickname_or_email), + %User{local: true} = user <- User.get_by_nickname_or_email(nickname_or_email) do + {:ok, token_record} = Pleroma.PasswordResetToken.create_token(user) + + user + |> Pleroma.UserEmail.password_reset_email(token_record.token) + |> Pleroma.Mailer.deliver() + + json_response(conn, :no_content, "") + end + end + def update_avatar(%{assigns: %{user: user}} = conn, params) do {:ok, object} = ActivityPub.upload(params, type: :avatar) change = Changeset.change(user, %{avatar: object.data}) -- cgit v1.2.3 From e3a21bcd45dd1f27a2f6a74041d86c64ad8256e9 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 12 Dec 2018 17:14:31 +0300 Subject: [#114] Addressed warnings. Fix of `with` statement clause in `password_reset`. --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 8837db566..479c92381 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -3,7 +3,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do import Pleroma.Web.ControllerHelper, only: [json_response: 3] - alias Pleroma.Formatter alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView} alias Pleroma.Web.CommonAPI alias Pleroma.{Repo, Activity, Object, User, Notification} @@ -329,7 +328,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def password_reset(conn, params) do nickname_or_email = params["email"] || params["nickname"] - with is_binary(nickname_or_email), + with true <- is_binary(nickname_or_email), %User{local: true} = user <- User.get_by_nickname_or_email(nickname_or_email) do {:ok, token_record} = Pleroma.PasswordResetToken.create_token(user) -- cgit v1.2.3 From bfff2399ff2d7b479b066c6f92bf9331f80bb914 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 12 Dec 2018 20:15:43 +0300 Subject: [#114] Routes and config for `confirm_email` and `email_invite` (Twitter API). --- lib/pleroma/web/router.ex | 3 +++ lib/pleroma/web/twitter_api/controllers/util_controller.ex | 3 +++ lib/pleroma/web/twitter_api/twitter_api_controller.ex | 4 ++++ 3 files changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 6253a28db..6a2e0d6c4 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -278,6 +278,7 @@ defmodule Pleroma.Web.Router do post("/account/register", TwitterAPI.Controller, :register) post("/account/password_reset", TwitterAPI.Controller, :password_reset) + get("/account/confirm_email", TwitterAPI.Controller, :confirm_email) get("/search", TwitterAPI.Controller, :search) get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline) @@ -312,6 +313,8 @@ defmodule Pleroma.Web.Router do post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner) post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background) + post("/email_invite", TwitterAPI.Controller, :email_invite) + get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline) get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline) get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index b1e4c77e8..cacfbbf91 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -166,6 +166,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do textlimit: to_string(Keyword.get(instance, :limit)), closed: if(Keyword.get(instance, :registrations_open), do: "0", else: "1"), private: if(Keyword.get(instance, :public, true), do: "0", else: "1"), + accountActivationRequired: + if(Keyword.get(instance, :account_activation_required, false), do: "1", else: "0"), + invitesEnabled: if(Keyword.get(instance, :invites_enabled, true), do: "1", else: "0"), vapidPublicKey: vapid_public_key } diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 479c92381..911dd6a48 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -340,6 +340,10 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def confirm_email(_conn, _params), do: :noop + + def email_invite(_conn, _params), do: :noop + def update_avatar(%{assigns: %{user: user}} = conn, params) do {:ok, object} = ActivityPub.upload(params, type: :avatar) change = Changeset.change(user, %{avatar: object.data}) -- cgit v1.2.3 From 7d9ddbe6894a29dd41789ab584b2cd9f0e686c47 Mon Sep 17 00:00:00 2001 From: href Date: Wed, 12 Dec 2018 18:17:15 +0100 Subject: Allow underscores in usernames. Fixes #429. --- lib/pleroma/formatter.ex | 2 +- lib/pleroma/user.ex | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 5b03e9aeb..1fea1c57a 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -18,7 +18,7 @@ defmodule Pleroma.Formatter do def parse_mentions(text) do # Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address regex = - ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]*@?[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u + ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]*@?[a-zA-Z0-9_](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u Regex.scan(regex, text) |> List.flatten() diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index e146b562c..f10cdfbc8 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -11,6 +11,11 @@ defmodule Pleroma.User do @type t :: %__MODULE__{} + @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ + + @strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/ + @extended_local_nickname_regex ~r/^[a-zA-Z\d_]+$/ + schema "users" do field(:bio, :string) field(:email, :string) @@ -77,7 +82,6 @@ defmodule Pleroma.User do } end - @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ def remote_user_creation(params) do params = params @@ -117,7 +121,7 @@ defmodule Pleroma.User do struct |> cast(params, [:bio, :name, :avatar]) |> unique_constraint(:nickname) - |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) + |> validate_format(:nickname, local_nickname_regex()) |> validate_length(:bio, max: 5000) |> validate_length(:name, min: 1, max: 100) end @@ -134,7 +138,7 @@ defmodule Pleroma.User do struct |> cast(params, [:bio, :name, :follower_address, :avatar, :last_refreshed_at]) |> unique_constraint(:nickname) - |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) + |> validate_format(:nickname, local_nickname_regex()) |> validate_length(:bio, max: 5000) |> validate_length(:name, max: 100) |> put_embed(:info, info_cng) @@ -172,7 +176,7 @@ defmodule Pleroma.User do |> validate_confirmation(:password) |> unique_constraint(:email) |> unique_constraint(:nickname) - |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) + |> validate_format(:nickname, local_nickname_regex()) |> validate_format(:email, @email_regex) |> validate_length(:bio, max: 1000) |> validate_length(:name, min: 1, max: 100) @@ -861,4 +865,12 @@ defmodule Pleroma.User do |> List.flatten() |> Enum.map(&String.downcase(&1)) end + + defp local_nickname_regex() do + if Pleroma.Config.get([:instance, :extended_nickname_format]) do + @extended_local_nickname_regex + else + @strict_local_nickname_regex + end + end end -- cgit v1.2.3 From a40ba3ba57158401583c5f80aaa78d80b4ca319f Mon Sep 17 00:00:00 2001 From: link0ff Date: Wed, 12 Dec 2018 22:30:16 +0200 Subject: Fix toggle_activated in mix task User --- lib/mix/tasks/pleroma/user.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 2675b021d..bcc3b9e50 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -142,8 +142,11 @@ defmodule Mix.Tasks.Pleroma.User do Common.start_pleroma() with %User{} = user <- User.get_by_nickname(nickname) do - User.deactivate(user, !user.info["deactivated"]) - Mix.shell().info("Activation status of #{nickname}: #{user.info["deactivated"]}") + {:ok, user} = User.deactivate(user, !user.info.deactivated) + + Mix.shell().info( + "Activation status of #{nickname}: #{if(user.info.deactivated, do: "de", else: "")}activated" + ) else _ -> Mix.shell().error("No user #{nickname}") -- cgit v1.2.3 From 51dd294c486474d453dbbd508995505017597bc2 Mon Sep 17 00:00:00 2001 From: link0ff Date: Wed, 12 Dec 2018 22:32:32 +0200 Subject: Allow to set both admin and moderator at the same time in mix task User --- lib/mix/tasks/pleroma/user.ex | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index bcc3b9e50..fe6e6935f 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -218,20 +218,23 @@ defmodule Mix.Tasks.Pleroma.User do ) with %User{local: true} = user <- User.get_by_nickname(nickname) do - case Keyword.get(options, :moderator) do - nil -> nil - value -> set_moderator(user, value) - end - - case Keyword.get(options, :locked) do - nil -> nil - value -> set_locked(user, value) - end - - case Keyword.get(options, :admin) do - nil -> nil - value -> set_admin(user, value) - end + user = + case Keyword.get(options, :moderator) do + nil -> user + value -> set_moderator(user, value) + end + + user = + case Keyword.get(options, :locked) do + nil -> user + value -> set_locked(user, value) + end + + _user = + case Keyword.get(options, :admin) do + nil -> user + value -> set_admin(user, value) + end else _ -> Mix.shell().error("No local user #{nickname}") @@ -268,6 +271,7 @@ defmodule Mix.Tasks.Pleroma.User do {:ok, user} = User.update_and_set_cache(user_cng) Mix.shell().info("Moderator status of #{user.nickname}: #{user.info.is_moderator}") + user end defp set_admin(user, value) do @@ -279,7 +283,8 @@ defmodule Mix.Tasks.Pleroma.User do {:ok, user} = User.update_and_set_cache(user_cng) - Mix.shell().info("Admin status of #{user.nickname}: #{user.info.is_moderator}") + Mix.shell().info("Admin status of #{user.nickname}: #{user.info.is_admin}") + user end defp set_locked(user, value) do @@ -292,5 +297,6 @@ defmodule Mix.Tasks.Pleroma.User do {:ok, user} = User.update_and_set_cache(user_cng) Mix.shell().info("Locked status of #{user.nickname}: #{user.info.locked}") + user end end -- cgit v1.2.3 From 7214d574630842e4efb76d6c3494a180cbc2a930 Mon Sep 17 00:00:00 2001 From: href Date: Wed, 12 Dec 2018 21:44:08 +0100 Subject: Extended nicknames: allow dashes. --- lib/pleroma/formatter.ex | 2 +- lib/pleroma/user.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 1fea1c57a..133683794 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -18,7 +18,7 @@ defmodule Pleroma.Formatter do def parse_mentions(text) do # Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address regex = - ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]*@?[a-zA-Z0-9_](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u + ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]*@?[a-zA-Z0-9_-](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u Regex.scan(regex, text) |> List.flatten() diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index f10cdfbc8..49928bc13 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -14,7 +14,7 @@ defmodule Pleroma.User do @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ @strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/ - @extended_local_nickname_regex ~r/^[a-zA-Z\d_]+$/ + @extended_local_nickname_regex ~r/^[a-zA-Z\d_-]+$/ schema "users" do field(:bio, :string) -- cgit v1.2.3 From 908943352fe2d81c34323a5571ad5c1d391969e1 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 13 Dec 2018 13:17:49 +0300 Subject: [#114] Refactored `password_reset` (moved to TwitterAPI). Added homepage links to password reset result pages. --- .../twitter_api/util/password_reset_failed.html.eex | 1 + .../twitter_api/util/password_reset_success.html.eex | 1 + lib/pleroma/web/twitter_api/twitter_api.ex | 19 +++++++++++++++++++ lib/pleroma/web/twitter_api/twitter_api_controller.ex | 9 +-------- 4 files changed, 22 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex b/lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex index 58a3736fd..df037c01e 100644 --- a/lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex +++ b/lib/pleroma/web/templates/twitter_api/util/password_reset_failed.html.eex @@ -1 +1,2 @@

Password reset failed

+

Homepage

diff --git a/lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex b/lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex index c7dfcb6dd..f30ba3274 100644 --- a/lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex +++ b/lib/pleroma/web/templates/twitter_api/util/password_reset_success.html.eex @@ -1 +1,2 @@

Password changed!

+

Homepage

diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 79ea48d86..1e764f24a 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -167,6 +167,25 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do end end + def password_reset(nickname_or_email) do + with true <- is_binary(nickname_or_email), + %User{local: true} = user <- User.get_by_nickname_or_email(nickname_or_email), + {:ok, token_record} <- Pleroma.PasswordResetToken.create_token(user) do + user + |> Pleroma.UserEmail.password_reset_email(token_record.token) + |> Pleroma.Mailer.deliver() + else + false -> + {:error, "bad user identifier"} + + %User{local: false} -> + {:error, "remote user"} + + nil -> + {:error, "unknown user"} + end + end + def get_by_id_or_nickname(id_or_nickname) do if !is_integer(id_or_nickname) && :error == Integer.parse(id_or_nickname) do Repo.get_by(User, nickname: id_or_nickname) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 911dd6a48..a45fdcf51 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -328,14 +328,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def password_reset(conn, params) do nickname_or_email = params["email"] || params["nickname"] - with true <- is_binary(nickname_or_email), - %User{local: true} = user <- User.get_by_nickname_or_email(nickname_or_email) do - {:ok, token_record} = Pleroma.PasswordResetToken.create_token(user) - - user - |> Pleroma.UserEmail.password_reset_email(token_record.token) - |> Pleroma.Mailer.deliver() - + with {:ok, _} <- TwitterAPI.password_reset(nickname_or_email) do json_response(conn, :no_content, "") end end -- cgit v1.2.3 From 00744c6b03d043defcf87696f539d65e41ad6a62 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 13 Dec 2018 14:30:48 +0300 Subject: [#114] Initial implementation of user email invitations. --- lib/pleroma/emails/user_email.ex | 30 +++++++++++++++++++--- .../web/twitter_api/controllers/util_controller.ex | 2 +- .../web/twitter_api/twitter_api_controller.ex | 8 +++++- 3 files changed, 35 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index 46d8b9c2d..47dcd42e0 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -9,10 +9,13 @@ defmodule Pleroma.UserEmail do defp instance_name, do: instance_config()[:name] - defp from do + defp sender do {instance_name(), instance_config()[:email]} end + defp recipient(email, nil), do: email + defp recipient(email, name), do: {name, email} + def password_reset_email(user, password_reset_token) when is_binary(password_reset_token) do password_reset_url = Router.Helpers.util_url( @@ -29,9 +32,30 @@ defmodule Pleroma.UserEmail do """ new() - |> to({user.name, user.email}) - |> from(from()) + |> to(recipient(user.email, user.name)) + |> from(sender()) |> subject("Password reset") |> html_body(html_body) end + + def user_invitation_email(user, to_email, to_name \\ nil) do + registration_url = + Router.Helpers.redirect_url( + Endpoint, + :registration_page, + "" + ) + + html_body = """ +

You are invited to #{instance_name()}

+

#{user.name} invites you to join #{instance_name()}, an instance of Pleroma federated social networking platform.

+

Click the following link to register: accept invitation.

+ """ + + new() + |> to(recipient(to_email, to_name)) + |> from(sender()) + |> subject("Invitation to #{instance_name()}") + |> html_body(html_body) + end end diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index cacfbbf91..cbde45e52 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -168,7 +168,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do private: if(Keyword.get(instance, :public, true), do: "0", else: "1"), accountActivationRequired: if(Keyword.get(instance, :account_activation_required, false), do: "1", else: "0"), - invitesEnabled: if(Keyword.get(instance, :invites_enabled, true), do: "1", else: "0"), + invitesEnabled: if(Keyword.get(instance, :invites_enabled, false), do: "1", else: "0"), vapidPublicKey: vapid_public_key } diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index a45fdcf51..d51d71299 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -335,7 +335,13 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def confirm_email(_conn, _params), do: :noop - def email_invite(_conn, _params), do: :noop + def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do + with true <- Pleroma.Config.get([:instance, :invites_enabled]), + email <- Pleroma.UserEmail.user_invitation_email(user, email, params["name"]), + {:ok, _} <- Pleroma.Mailer.deliver(email) do + json_response(conn, :no_content, "") + end + end def update_avatar(%{assigns: %{user: user}} = conn, params) do {:ok, object} = ActivityPub.upload(params, type: :avatar) -- cgit v1.2.3 From 18b9467d1a63766123f625a964303f6b4d28a39f Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 13 Dec 2018 16:22:42 +0300 Subject: [#114] Removed `email_invite` implementation (to be addressed separately). --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index d51d71299..a45fdcf51 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -335,13 +335,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def confirm_email(_conn, _params), do: :noop - def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do - with true <- Pleroma.Config.get([:instance, :invites_enabled]), - email <- Pleroma.UserEmail.user_invitation_email(user, email, params["name"]), - {:ok, _} <- Pleroma.Mailer.deliver(email) do - json_response(conn, :no_content, "") - end - end + def email_invite(_conn, _params), do: :noop def update_avatar(%{assigns: %{user: user}} = conn, params) do {:ok, object} = ActivityPub.upload(params, type: :avatar) -- cgit v1.2.3 From 9e689de06302df8b1d281c41f7774d43a0db3758 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 13 Dec 2018 16:22:42 +0300 Subject: [#114] Removed `email_invite` implementation (to be addressed separately). --- lib/pleroma/emails/user_email.ex | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index 47dcd42e0..9cdf002f3 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -37,25 +37,4 @@ defmodule Pleroma.UserEmail do |> subject("Password reset") |> html_body(html_body) end - - def user_invitation_email(user, to_email, to_name \\ nil) do - registration_url = - Router.Helpers.redirect_url( - Endpoint, - :registration_page, - "" - ) - - html_body = """ -

You are invited to #{instance_name()}

-

#{user.name} invites you to join #{instance_name()}, an instance of Pleroma federated social networking platform.

-

Click the following link to register: accept invitation.

- """ - - new() - |> to(recipient(to_email, to_name)) - |> from(sender()) - |> subject("Invitation to #{instance_name()}") - |> html_body(html_body) - end end -- cgit v1.2.3 From 21afdf6d9966265de95df860d90d250c76bdbe08 Mon Sep 17 00:00:00 2001 From: raeno Date: Mon, 10 Dec 2018 16:25:33 +0400 Subject: Insert meta tags into static index.html on the fly for OStatus#notice --- lib/pleroma/web/oembed/oembed_controller.ex | 11 +++++++++++ lib/pleroma/web/ostatus/ostatus.ex | 15 +++++++++++++++ lib/pleroma/web/ostatus/ostatus_controller.ex | 14 +++++++++++--- lib/pleroma/web/router.ex | 10 ++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 lib/pleroma/web/oembed/oembed_controller.ex (limited to 'lib') diff --git a/lib/pleroma/web/oembed/oembed_controller.ex b/lib/pleroma/web/oembed/oembed_controller.ex new file mode 100644 index 000000000..e9030049e --- /dev/null +++ b/lib/pleroma/web/oembed/oembed_controller.ex @@ -0,0 +1,11 @@ +defmodule Pleroma.Web.OEmbed.OEmbedController do + use Pleroma.Web, :controller + + alias Pleroma.Repo + + def url(conn, %{ "url" => uri} ) do + conn + |> put_resp_content_type("application/json") + |> json(%{ status: "success"} ) + end +end \ No newline at end of file diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index c6440c20e..8ec92d5f1 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -26,6 +26,16 @@ defmodule Pleroma.Web.OStatus do end end + def metadata(url), do: oembed_links(url) + + def oembed_links(url) do + Enum.map(["xml", "json"], fn format -> + href = oembed_path(url, format) + " Enum.join("\r\n") + end + def feed_path(user) do "#{user.ap_id}/feed.atom" end @@ -42,6 +52,11 @@ defmodule Pleroma.Web.OStatus do "#{Web.base_url()}/ostatus_subscribe?acct={uri}" end + def oembed_path(url, format) do + query = URI.encode_query(%{url: url, format: format}) + "#{Web.base_url()}/oembed?#{query}" + end + def handle_incoming(xml_string) do with doc when doc != :error <- parse_document(xml_string) do entries = :xmerl_xpath.string('//entry', doc) diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 9dfcf0f95..635189619 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -9,6 +9,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do alias Pleroma.Web.ActivityPub.ObjectView alias Pleroma.Web.ActivityPub.ActivityPubController alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Router.Helpers, as: Routes plug(Pleroma.Web.FederatingPlug when action in [:salmon_incoming]) action_fallback(:errors) @@ -134,9 +135,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do case format = get_format(conn) do "html" -> - conn - |> put_resp_content_type("text/html") - |> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html")) + serve_static_with_meta(conn, activity) _ -> represent_activity(conn, format, activity, user) @@ -153,6 +152,15 @@ defmodule Pleroma.Web.OStatus.OStatusController do end end + defp serve_static_with_meta(conn, activity) do + {:ok, index_content } = File.read(Application.app_dir(:pleroma, "priv/static/index.html")) + links = OStatus.metadata(request_url(conn)) + response = String.replace(index_content, "", links) + conn + |> put_resp_content_type("text/html") + |> send_resp(200, response) + end + defp represent_activity( conn, "activity+json", diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 9c06fac4f..3239249f9 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -354,6 +354,10 @@ defmodule Pleroma.Web.Router do plug(:accepts, ["xml", "atom", "html", "activity+json"]) end + pipeline :oembed do + plug(:accepts, ["json", "xml"]) + end + scope "/", Pleroma.Web do pipe_through(:ostatus) @@ -369,6 +373,12 @@ defmodule Pleroma.Web.Router do post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming) end + scope "/", Pleroma.Web do + pipe_through(:oembed) + + get("/oembed", OEmbed.OEmbedController, :url) + end + pipeline :activitypub do plug(:accepts, ["activity+json"]) plug(Pleroma.Web.Plugs.HTTPSignaturePlug) -- cgit v1.2.3 From 8902942128e3aee814c215d700e2eaee21b491e9 Mon Sep 17 00:00:00 2001 From: raeno Date: Mon, 10 Dec 2018 23:08:02 +0400 Subject: WIP. Implement oembed route and handle both json/xml for "Note" type activity --- lib/pleroma/formatter.ex | 16 ++++++++++++++++ lib/pleroma/web/oembed/activity_representer.ex | 25 +++++++++++++++++++++++++ lib/pleroma/web/oembed/oembed.ex | 23 +++++++++++++++++++++++ lib/pleroma/web/oembed/oembed_controller.ex | 26 +++++++++++++++++++++++--- lib/pleroma/web/oembed/views/note_view.ex | 21 +++++++++++++++++++++ lib/pleroma/web/ostatus/ostatus.ex | 2 +- lib/pleroma/web/ostatus/ostatus_controller.ex | 1 - lib/pleroma/web/templates/o_embed/note.xml.eex | 10 ++++++++++ 8 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 lib/pleroma/web/oembed/activity_representer.ex create mode 100644 lib/pleroma/web/oembed/oembed.ex create mode 100644 lib/pleroma/web/oembed/views/note_view.ex create mode 100644 lib/pleroma/web/templates/o_embed/note.xml.eex (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 133683794..b63f592fb 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -163,4 +163,20 @@ defmodule Pleroma.Formatter do String.replace(result_text, uuid, replacement) end) end + + def truncate(text, opts \\ []) do + max_length = opts[:max_length] || 200 + omission = opts[:omission] || "..." + + cond do + not String.valid?(text) -> + text + String.length(text) < max_length -> + text + true -> + length_with_omission = max_length - String.length(omission) + + "#{String.slice(text, 0, length_with_omission)}#{omission}" + end + end end diff --git a/lib/pleroma/web/oembed/activity_representer.ex b/lib/pleroma/web/oembed/activity_representer.ex new file mode 100644 index 000000000..0e65090ee --- /dev/null +++ b/lib/pleroma/web/oembed/activity_representer.ex @@ -0,0 +1,25 @@ +defmodule Pleroma.Web.OEmbed.ActivityRepresenter do + alias Pleroma.{Activity, User, Object} + alias Pleroma.Web.OStatus.UserRepresenter + + def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user, with_author) do + h = fn str -> [to_charlist(str)] end + + content = if activity.data["object"]["content"] do + [{:content, [], h.(activity.data["object"]["content"])}] + else + [] + end + + [ + {:version, ["1.0"]}, + {:type, ["link"]}, + ] ++ content + + end + + def wrap_with_entry(simple_form) do + [ { :oembed, [], simple_form } ] + end + +end diff --git a/lib/pleroma/web/oembed/oembed.ex b/lib/pleroma/web/oembed/oembed.ex new file mode 100644 index 000000000..a52aa6004 --- /dev/null +++ b/lib/pleroma/web/oembed/oembed.ex @@ -0,0 +1,23 @@ +defmodule Pleroma.Web.OEmbed do + alias Pleroma.{Repo, Object, Activity, User} + alias Pleroma.Formatter + + def recognize_path(url) do + details = Regex.named_captures(~r/.+\/(?.+)\/(?\w+).*$/, url) + + case details do + %{ "route" => "notice", "id" => id } -> + %{type: :activity, entity: Repo.get(Activity, id) } + %{ "route" => "users", "id" => nickname } -> + %{type: :user, entity: User.get_by_nickname(nickname) } + _ -> + { :error, "no matching route"} + end + end + + def truncated_content(activity) do + content = activity.data['object']['content'] + IO.puts(content) + Formatter.truncate(content) + end +end diff --git a/lib/pleroma/web/oembed/oembed_controller.ex b/lib/pleroma/web/oembed/oembed_controller.ex index e9030049e..d63d3c58c 100644 --- a/lib/pleroma/web/oembed/oembed_controller.ex +++ b/lib/pleroma/web/oembed/oembed_controller.ex @@ -1,11 +1,31 @@ defmodule Pleroma.Web.OEmbed.OEmbedController do use Pleroma.Web, :controller + alias Pleroma.Web.OEmbed + alias Pleroma.Web.OEmbed.{NoteView, ActivityRepresenter} + alias Pleroma.Web.MediaProxy alias Pleroma.Repo + alias Pleroma.User - def url(conn, %{ "url" => uri} ) do + def url(conn, %{ "url" => url} ) do + case format = get_format(conn) do + _ -> + result = OEmbed.recognize_path(url) + render_oembed(conn, format, result) + end + end + + def render_oembed(conn, format \\ "json", result) + def render_oembed(conn, "json", result) do conn |> put_resp_content_type("application/json") - |> json(%{ status: "success"} ) + |> json(NoteView.render("note.json", result)) + end + + def render_oembed(conn, "xml", result) do + conn + |> put_resp_content_type("application/xml") + |> NoteView.render("note.json", result) + end -end \ No newline at end of file +end diff --git a/lib/pleroma/web/oembed/views/note_view.ex b/lib/pleroma/web/oembed/views/note_view.ex new file mode 100644 index 000000000..ecdabc04b --- /dev/null +++ b/lib/pleroma/web/oembed/views/note_view.ex @@ -0,0 +1,21 @@ +defmodule Pleroma.Web.OEmbed.NoteView do + use Pleroma.Web, :view + alias Pleroma.{User, Activity} + alias Pleroma.Web.OEmbed + + def render("note.json", %{type: type, entity: activity }) do + oembed_data(activity) + end + + def oembed_data(activity) do + with %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]), + image = User.avatar_url(user) |> MediaProxy.url() do + %{ + version: "1.0", + type: "link", + title: OEmbed.truncated_content(activity), + provider_url: "https://pleroma.site", + thumbnail_url: image, + } + end +end diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 8ec92d5f1..0f6756d16 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -31,7 +31,7 @@ defmodule Pleroma.Web.OStatus do def oembed_links(url) do Enum.map(["xml", "json"], fn format -> href = oembed_path(url, format) - "" end) |> Enum.join("\r\n") end diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 635189619..27ec24f57 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -9,7 +9,6 @@ defmodule Pleroma.Web.OStatus.OStatusController do alias Pleroma.Web.ActivityPub.ObjectView alias Pleroma.Web.ActivityPub.ActivityPubController alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Router.Helpers, as: Routes plug(Pleroma.Web.FederatingPlug when action in [:salmon_incoming]) action_fallback(:errors) diff --git a/lib/pleroma/web/templates/o_embed/note.xml.eex b/lib/pleroma/web/templates/o_embed/note.xml.eex new file mode 100644 index 000000000..e814a4cb3 --- /dev/null +++ b/lib/pleroma/web/templates/o_embed/note.xml.eex @@ -0,0 +1,10 @@ + + + 1.0 + link + raeno + http://iamcal.com/ + 86400 + iamcal.com + http://iamcal.com/ + \ No newline at end of file -- cgit v1.2.3 From d903e34cacd18157a2a60e7b112eb05af2766266 Mon Sep 17 00:00:00 2001 From: raeno Date: Wed, 12 Dec 2018 22:37:00 +0300 Subject: Add opengraph/twitter_card:summary support. Add config to toggle on/off specific metadata --- lib/pleroma/web/ostatus/ostatus.ex | 58 ++++++++++++++++++++++++--- lib/pleroma/web/ostatus/ostatus_controller.ex | 6 +-- 2 files changed, 55 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 0f6756d16..73cdd3837 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -5,11 +5,12 @@ defmodule Pleroma.Web.OStatus do import Pleroma.Web.XML require Logger - alias Pleroma.{Repo, User, Web, Object, Activity} + alias Pleroma.{Repo, User, Web, Object, Activity, Formatter} alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.{WebFinger, Websub} + alias Pleroma.Web.{WebFinger, Websub, MediaProxy} alias Pleroma.Web.OStatus.{FollowHandler, UnfollowHandler, NoteHandler, DeleteHandler} alias Pleroma.Web.ActivityPub.Transmogrifier + alias Phoenix.HTML def is_representable?(%Activity{data: data}) do object = Object.normalize(data["object"]) @@ -26,14 +27,59 @@ defmodule Pleroma.Web.OStatus do end end - def metadata(url), do: oembed_links(url) + def metadata(activity, user, url) do + Enum.concat([ + if(meta_enabled?(:opengraph), do: opengraph_tags(activity, user), else: []), + if(meta_enabled?(:oembed), do: oembed_links(url), else: []) + ]) + |> Enum.map(&to_tag/1) + |> Enum.map(&HTML.safe_to_string/1) + |> Enum.join("\n") + end + + def meta_enabled?(type) do + config = Pleroma.Config.get(:metadata, []) + Keyword.get(config, type, false) + end + + def to_tag(data) do + with {name, attrs, _content = []} <- data do + HTML.Tag.tag(name, attrs) + else + {name, attrs, content} -> + HTML.Tag.content_tag(name, content, attrs) + + _ -> + raise ArgumentError, message: "make_tag invalid args" + end + end def oembed_links(url) do Enum.map(["xml", "json"], fn format -> - href = oembed_path(url, format) - "" + href = HTML.raw(oembed_path(url, format)) + { :link, [ type: ["application/#{format}+oembed"], href: href, rel: 'alternate'], [] } end) - |> Enum.join("\r\n") + end + + def opengraph_tags(activity, user) do + with image = User.avatar_url(user) |> MediaProxy.url(), + truncated_content = Formatter.truncate(activity.data["object"]["content"]), + domain = Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN") do + [ + {:meta, + [ + property: "og:title", + content: "#{user.name} (@#{user.nickname}@#{domain}) post ##{activity.id}" + ], []}, + {:meta, [property: "og:url", content: activity.data["id"]], []}, + {:meta, [property: "og:description", content: truncated_content], + []}, + {:meta, [property: "og:image", content: image], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []}, + {:meta, [property: "twitter:card", content: "summary"], []} + ] + end end def feed_path(user) do diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 27ec24f57..bfc36c0c4 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -134,7 +134,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do case format = get_format(conn) do "html" -> - serve_static_with_meta(conn, activity) + serve_static_with_meta(conn, activity, user) _ -> represent_activity(conn, format, activity, user) @@ -151,9 +151,9 @@ defmodule Pleroma.Web.OStatus.OStatusController do end end - defp serve_static_with_meta(conn, activity) do + defp serve_static_with_meta(conn, activity, user) do {:ok, index_content } = File.read(Application.app_dir(:pleroma, "priv/static/index.html")) - links = OStatus.metadata(request_url(conn)) + links = OStatus.metadata(activity, user, request_url(conn)) response = String.replace(index_content, "", links) conn |> put_resp_content_type("text/html") -- cgit v1.2.3 From 9b3a6cdb07383631c9ac11ce5de51306f6c4a464 Mon Sep 17 00:00:00 2001 From: raeno Date: Wed, 12 Dec 2018 22:55:01 +0300 Subject: Extract opengraph/oembed into separate module --- lib/pleroma/web/ostatus/metadata.ex | 66 +++++++++++++++++++++++++++ lib/pleroma/web/ostatus/ostatus.ex | 63 +------------------------ lib/pleroma/web/ostatus/ostatus_controller.ex | 6 +-- 3 files changed, 70 insertions(+), 65 deletions(-) create mode 100644 lib/pleroma/web/ostatus/metadata.ex (limited to 'lib') diff --git a/lib/pleroma/web/ostatus/metadata.ex b/lib/pleroma/web/ostatus/metadata.ex new file mode 100644 index 000000000..dd099e2ad --- /dev/null +++ b/lib/pleroma/web/ostatus/metadata.ex @@ -0,0 +1,66 @@ +defmodule Pleroma.Web.Metadata do + alias Phoenix.HTML + alias Pleroma.{Web, Formatter} + alias Pleroma.{User, Activity} + alias Pleroma.Web.MediaProxy + + def build_tags(activity, user, url) do + Enum.concat([ + if(meta_enabled?(:opengraph), do: opengraph_tags(activity, user), else: []), + if(meta_enabled?(:oembed), do: oembed_links(url), else: []) + ]) + |> Enum.map(&to_tag/1) + |> Enum.map(&HTML.safe_to_string/1) + |> Enum.join("\n") + end + + def meta_enabled?(type) do + config = Pleroma.Config.get(:metadata, []) + Keyword.get(config, type, false) + end + + def to_tag(data) do + with {name, attrs, _content = []} <- data do + HTML.Tag.tag(name, attrs) + else + {name, attrs, content} -> + HTML.Tag.content_tag(name, content, attrs) + + _ -> + raise ArgumentError, message: "make_tag invalid args" + end + end + + defp oembed_links(url) do + Enum.map(["xml", "json"], fn format -> + href = HTML.raw(oembed_path(url, format)) + { :link, [ type: ["application/#{format}+oembed"], href: href, rel: 'alternate'], [] } + end) + end + + defp opengraph_tags(activity, user) do + with image = User.avatar_url(user) |> MediaProxy.url(), + truncated_content = Formatter.truncate(activity.data["object"]["content"]), + domain = Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN") do + [ + {:meta, + [ + property: "og:title", + content: "#{user.name} (@#{user.nickname}@#{domain}) post ##{activity.id}" + ], []}, + {:meta, [property: "og:url", content: activity.data["id"]], []}, + {:meta, [property: "og:description", content: truncated_content], + []}, + {:meta, [property: "og:image", content: image], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []}, + {:meta, [property: "twitter:card", content: "summary"], []} + ] + end + end + + defp oembed_path(url, format) do + query = URI.encode_query(%{url: url, format: format}) + "#{Web.base_url()}/oembed?#{query}" + end +end \ No newline at end of file diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index 73cdd3837..ba44b2e99 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -7,10 +7,9 @@ defmodule Pleroma.Web.OStatus do alias Pleroma.{Repo, User, Web, Object, Activity, Formatter} alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.{WebFinger, Websub, MediaProxy} + alias Pleroma.Web.{WebFinger, Websub} alias Pleroma.Web.OStatus.{FollowHandler, UnfollowHandler, NoteHandler, DeleteHandler} alias Pleroma.Web.ActivityPub.Transmogrifier - alias Phoenix.HTML def is_representable?(%Activity{data: data}) do object = Object.normalize(data["object"]) @@ -27,61 +26,6 @@ defmodule Pleroma.Web.OStatus do end end - def metadata(activity, user, url) do - Enum.concat([ - if(meta_enabled?(:opengraph), do: opengraph_tags(activity, user), else: []), - if(meta_enabled?(:oembed), do: oembed_links(url), else: []) - ]) - |> Enum.map(&to_tag/1) - |> Enum.map(&HTML.safe_to_string/1) - |> Enum.join("\n") - end - - def meta_enabled?(type) do - config = Pleroma.Config.get(:metadata, []) - Keyword.get(config, type, false) - end - - def to_tag(data) do - with {name, attrs, _content = []} <- data do - HTML.Tag.tag(name, attrs) - else - {name, attrs, content} -> - HTML.Tag.content_tag(name, content, attrs) - - _ -> - raise ArgumentError, message: "make_tag invalid args" - end - end - - def oembed_links(url) do - Enum.map(["xml", "json"], fn format -> - href = HTML.raw(oembed_path(url, format)) - { :link, [ type: ["application/#{format}+oembed"], href: href, rel: 'alternate'], [] } - end) - end - - def opengraph_tags(activity, user) do - with image = User.avatar_url(user) |> MediaProxy.url(), - truncated_content = Formatter.truncate(activity.data["object"]["content"]), - domain = Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN") do - [ - {:meta, - [ - property: "og:title", - content: "#{user.name} (@#{user.nickname}@#{domain}) post ##{activity.id}" - ], []}, - {:meta, [property: "og:url", content: activity.data["id"]], []}, - {:meta, [property: "og:description", content: truncated_content], - []}, - {:meta, [property: "og:image", content: image], []}, - {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []}, - {:meta, [property: "twitter:card", content: "summary"], []} - ] - end - end - def feed_path(user) do "#{user.ap_id}/feed.atom" end @@ -98,11 +42,6 @@ defmodule Pleroma.Web.OStatus do "#{Web.base_url()}/ostatus_subscribe?acct={uri}" end - def oembed_path(url, format) do - query = URI.encode_query(%{url: url, format: format}) - "#{Web.base_url()}/oembed?#{query}" - end - def handle_incoming(xml_string) do with doc when doc != :error <- parse_document(xml_string) do entries = :xmerl_xpath.string('//entry', doc) diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index bfc36c0c4..23ca8e088 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -4,7 +4,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do alias Pleroma.{User, Activity, Object} alias Pleroma.Web.OStatus.{FeedRepresenter, ActivityRepresenter} alias Pleroma.Repo - alias Pleroma.Web.{OStatus, Federator} + alias Pleroma.Web.{OStatus, Federator, Metadata} alias Pleroma.Web.XML alias Pleroma.Web.ActivityPub.ObjectView alias Pleroma.Web.ActivityPub.ActivityPubController @@ -153,8 +153,8 @@ defmodule Pleroma.Web.OStatus.OStatusController do defp serve_static_with_meta(conn, activity, user) do {:ok, index_content } = File.read(Application.app_dir(:pleroma, "priv/static/index.html")) - links = OStatus.metadata(activity, user, request_url(conn)) - response = String.replace(index_content, "", links) + tags = Metadata.build_tags(activity, user, request_url(conn)) + response = String.replace(index_content, "", tags) conn |> put_resp_content_type("text/html") |> send_resp(200, response) -- cgit v1.2.3 From 49c4f7d604be921bf5c6fb966b279fbb037b6cfa Mon Sep 17 00:00:00 2001 From: raeno Date: Wed, 12 Dec 2018 22:57:01 +0300 Subject: Set Pleroma.instance.domain when config is generated --- lib/mix/tasks/pleroma/sample_config.eex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/sample_config.eex b/lib/mix/tasks/pleroma/sample_config.eex index 0cd572797..8eacefab2 100644 --- a/lib/mix/tasks/pleroma/sample_config.eex +++ b/lib/mix/tasks/pleroma/sample_config.eex @@ -12,6 +12,7 @@ config :pleroma, Pleroma.Web.Endpoint, config :pleroma, :instance, name: "<%= name %>", email: "<%= email %>", + domain: "<%= domain %>, limit: 5000, registrations_open: true, dedupe_media: false -- cgit v1.2.3 From 018516d3f3fcc6e902a5382517792832841695d3 Mon Sep 17 00:00:00 2001 From: raeno Date: Thu, 13 Dec 2018 22:13:02 +0100 Subject: Refactor ostatus_controller, extract metatags redirection to Redirector itself. Set 'html' as default type for ostatus links --- lib/pleroma/web/ostatus/metadata.ex | 82 ++++++++++++++++++--------- lib/pleroma/web/ostatus/ostatus_controller.ex | 21 +++---- lib/pleroma/web/router.ex | 13 ++++- 3 files changed, 74 insertions(+), 42 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/ostatus/metadata.ex b/lib/pleroma/web/ostatus/metadata.ex index dd099e2ad..4f319b360 100644 --- a/lib/pleroma/web/ostatus/metadata.ex +++ b/lib/pleroma/web/ostatus/metadata.ex @@ -4,10 +4,10 @@ defmodule Pleroma.Web.Metadata do alias Pleroma.{User, Activity} alias Pleroma.Web.MediaProxy - def build_tags(activity, user, url) do + def build_tags(request_url, params) do Enum.concat([ - if(meta_enabled?(:opengraph), do: opengraph_tags(activity, user), else: []), - if(meta_enabled?(:oembed), do: oembed_links(url), else: []) + if(meta_enabled?(:opengraph), do: opengraph_tags(params), else: []), + if(meta_enabled?(:oembed), do: oembed_links(request_url), else: []) ]) |> Enum.map(&to_tag/1) |> Enum.map(&HTML.safe_to_string/1) @@ -19,39 +19,38 @@ defmodule Pleroma.Web.Metadata do Keyword.get(config, type, false) end - def to_tag(data) do - with {name, attrs, _content = []} <- data do - HTML.Tag.tag(name, attrs) - else - {name, attrs, content} -> - HTML.Tag.content_tag(name, content, attrs) - - _ -> - raise ArgumentError, message: "make_tag invalid args" - end - end - - defp oembed_links(url) do - Enum.map(["xml", "json"], fn format -> - href = HTML.raw(oembed_path(url, format)) - { :link, [ type: ["application/#{format}+oembed"], href: href, rel: 'alternate'], [] } - end) - end - - defp opengraph_tags(activity, user) do - with image = User.avatar_url(user) |> MediaProxy.url(), - truncated_content = Formatter.truncate(activity.data["object"]["content"]), - domain = Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN") do + # opengraph for single status + defp opengraph_tags(%{activity: activity, user: user}) do + with truncated_content = Formatter.truncate(activity.data["object"]["content"]) do [ {:meta, [ property: "og:title", - content: "#{user.name} (@#{user.nickname}@#{domain}) post ##{activity.id}" + content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) post ##{activity.id}" ], []}, {:meta, [property: "og:url", content: activity.data["id"]], []}, {:meta, [property: "og:description", content: truncated_content], []}, - {:meta, [property: "og:image", content: image], []}, + {:meta, [property: "og:image", content: user_avatar_url(user)], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []}, + {:meta, [property: "twitter:card", content: "summary"], []} + ] + end + end + + # opengraph for user card + defp opengraph_tags(%{user: user}) do + with truncated_bio = Formatter.truncate(user.bio) do + [ + {:meta, + [ + property: "og:title", + content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) profile" + ], []}, + {:meta, [property: "og:url", content: User.profile_url(user)], []}, + {:meta, [property: "og:description", content: truncated_bio], []}, + {:meta, [property: "og:image", content: user_avatar_url(user)], []}, {:meta, [property: "og:image:width", content: 120], []}, {:meta, [property: "og:image:height", content: 120], []}, {:meta, [property: "twitter:card", content: "summary"], []} @@ -59,8 +58,35 @@ defmodule Pleroma.Web.Metadata do end end + defp oembed_links(url) do + Enum.map(["xml", "json"], fn format -> + href = HTML.raw(oembed_path(url, format)) + { :link, [ type: ["application/#{format}+oembed"], href: href, rel: 'alternate'], [] } + end) + end + + def to_tag(data) do + with {name, attrs, _content = []} <- data do + HTML.Tag.tag(name, attrs) + else + {name, attrs, content} -> + HTML.Tag.content_tag(name, content, attrs) + + _ -> + raise ArgumentError, message: "make_tag invalid args" + end + end + defp oembed_path(url, format) do query = URI.encode_query(%{url: url, format: format}) "#{Web.base_url()}/oembed?#{query}" end + + defp user_avatar_url(user) do + User.avatar_url(user) |> MediaProxy.url() + end + + def pleroma_domain do + Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN") + end end \ No newline at end of file diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 23ca8e088..fbd25c5f5 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -4,7 +4,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do alias Pleroma.{User, Activity, Object} alias Pleroma.Web.OStatus.{FeedRepresenter, ActivityRepresenter} alias Pleroma.Repo - alias Pleroma.Web.{OStatus, Federator, Metadata} + alias Pleroma.Web.{OStatus, Federator} alias Pleroma.Web.XML alias Pleroma.Web.ActivityPub.ObjectView alias Pleroma.Web.ActivityPub.ActivityPubController @@ -14,9 +14,13 @@ defmodule Pleroma.Web.OStatus.OStatusController do action_fallback(:errors) def feed_redirect(conn, %{"nickname" => nickname}) do - case get_format(conn) do + format = get_format(conn) + IO.puts(format) + case format do "html" -> - Fallback.RedirectController.redirector(conn, nil) + with %User{} = user <- User.get_cached_by_nickname(nickname) do + Fallback.RedirectController.redirector_with_meta(conn, %{user: user}) + end "activity+json" -> ActivityPubController.call(conn, :user) @@ -134,7 +138,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do case format = get_format(conn) do "html" -> - serve_static_with_meta(conn, activity, user) + Fallback.RedirectController.redirector_with_meta(conn, %{activity: activity, user: user}) _ -> represent_activity(conn, format, activity, user) @@ -151,15 +155,6 @@ defmodule Pleroma.Web.OStatus.OStatusController do end end - defp serve_static_with_meta(conn, activity, user) do - {:ok, index_content } = File.read(Application.app_dir(:pleroma, "priv/static/index.html")) - tags = Metadata.build_tags(activity, user, request_url(conn)) - response = String.replace(index_content, "", tags) - conn - |> put_resp_content_type("text/html") - |> send_resp(200, response) - end - defp represent_activity( conn, "activity+json", diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 3239249f9..ad26093ac 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -351,7 +351,7 @@ defmodule Pleroma.Web.Router do end pipeline :ostatus do - plug(:accepts, ["xml", "atom", "html", "activity+json"]) + plug(:accepts, ["html", "xml", "atom", "activity+json"]) end pipeline :oembed do @@ -444,6 +444,7 @@ end defmodule Fallback.RedirectController do use Pleroma.Web, :controller + alias Pleroma.Web.Metadata def redirector(conn, _params) do conn @@ -451,6 +452,16 @@ defmodule Fallback.RedirectController do |> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html")) end + def redirector_with_meta(conn, params) do + {:ok, index_content } = File.read(Application.app_dir(:pleroma, "priv/static/index.html")) + tags = Metadata.build_tags(request_url(conn), params) + response = String.replace(index_content, "", tags) + + conn + |> put_resp_content_type("text/html") + |> send_resp(200, response) + end + def registration_page(conn, params) do redirector(conn, params) end -- cgit v1.2.3 From b5de7c4c4d90d1049b59381953cbd76e79b77e66 Mon Sep 17 00:00:00 2001 From: raeno Date: Thu, 13 Dec 2018 22:16:54 +0100 Subject: Remove oembed for now, will submit it in another MR. Fix warnings --- lib/pleroma/formatter.ex | 6 ++-- lib/pleroma/web/oembed/activity_representer.ex | 25 --------------- lib/pleroma/web/oembed/oembed.ex | 23 -------------- lib/pleroma/web/oembed/oembed_controller.ex | 31 ------------------- lib/pleroma/web/oembed/views/note_view.ex | 21 ------------- lib/pleroma/web/ostatus/metadata.ex | 43 ++++++++------------------ lib/pleroma/web/ostatus/ostatus.ex | 2 +- lib/pleroma/web/ostatus/ostatus_controller.ex | 4 +-- lib/pleroma/web/router.ex | 4 +-- 9 files changed, 21 insertions(+), 138 deletions(-) delete mode 100644 lib/pleroma/web/oembed/activity_representer.ex delete mode 100644 lib/pleroma/web/oembed/oembed.ex delete mode 100644 lib/pleroma/web/oembed/oembed_controller.ex delete mode 100644 lib/pleroma/web/oembed/views/note_view.ex (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index b63f592fb..1d5dc0c99 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -165,14 +165,16 @@ defmodule Pleroma.Formatter do end def truncate(text, opts \\ []) do - max_length = opts[:max_length] || 200 - omission = opts[:omission] || "..." + max_length = opts[:max_length] || 200 + omission = opts[:omission] || "..." cond do not String.valid?(text) -> text + String.length(text) < max_length -> text + true -> length_with_omission = max_length - String.length(omission) diff --git a/lib/pleroma/web/oembed/activity_representer.ex b/lib/pleroma/web/oembed/activity_representer.ex deleted file mode 100644 index 0e65090ee..000000000 --- a/lib/pleroma/web/oembed/activity_representer.ex +++ /dev/null @@ -1,25 +0,0 @@ -defmodule Pleroma.Web.OEmbed.ActivityRepresenter do - alias Pleroma.{Activity, User, Object} - alias Pleroma.Web.OStatus.UserRepresenter - - def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user, with_author) do - h = fn str -> [to_charlist(str)] end - - content = if activity.data["object"]["content"] do - [{:content, [], h.(activity.data["object"]["content"])}] - else - [] - end - - [ - {:version, ["1.0"]}, - {:type, ["link"]}, - ] ++ content - - end - - def wrap_with_entry(simple_form) do - [ { :oembed, [], simple_form } ] - end - -end diff --git a/lib/pleroma/web/oembed/oembed.ex b/lib/pleroma/web/oembed/oembed.ex deleted file mode 100644 index a52aa6004..000000000 --- a/lib/pleroma/web/oembed/oembed.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule Pleroma.Web.OEmbed do - alias Pleroma.{Repo, Object, Activity, User} - alias Pleroma.Formatter - - def recognize_path(url) do - details = Regex.named_captures(~r/.+\/(?.+)\/(?\w+).*$/, url) - - case details do - %{ "route" => "notice", "id" => id } -> - %{type: :activity, entity: Repo.get(Activity, id) } - %{ "route" => "users", "id" => nickname } -> - %{type: :user, entity: User.get_by_nickname(nickname) } - _ -> - { :error, "no matching route"} - end - end - - def truncated_content(activity) do - content = activity.data['object']['content'] - IO.puts(content) - Formatter.truncate(content) - end -end diff --git a/lib/pleroma/web/oembed/oembed_controller.ex b/lib/pleroma/web/oembed/oembed_controller.ex deleted file mode 100644 index d63d3c58c..000000000 --- a/lib/pleroma/web/oembed/oembed_controller.ex +++ /dev/null @@ -1,31 +0,0 @@ -defmodule Pleroma.Web.OEmbed.OEmbedController do - use Pleroma.Web, :controller - - alias Pleroma.Web.OEmbed - alias Pleroma.Web.OEmbed.{NoteView, ActivityRepresenter} - alias Pleroma.Web.MediaProxy - alias Pleroma.Repo - alias Pleroma.User - - def url(conn, %{ "url" => url} ) do - case format = get_format(conn) do - _ -> - result = OEmbed.recognize_path(url) - render_oembed(conn, format, result) - end - end - - def render_oembed(conn, format \\ "json", result) - def render_oembed(conn, "json", result) do - conn - |> put_resp_content_type("application/json") - |> json(NoteView.render("note.json", result)) - end - - def render_oembed(conn, "xml", result) do - conn - |> put_resp_content_type("application/xml") - |> NoteView.render("note.json", result) - - end -end diff --git a/lib/pleroma/web/oembed/views/note_view.ex b/lib/pleroma/web/oembed/views/note_view.ex deleted file mode 100644 index ecdabc04b..000000000 --- a/lib/pleroma/web/oembed/views/note_view.ex +++ /dev/null @@ -1,21 +0,0 @@ -defmodule Pleroma.Web.OEmbed.NoteView do - use Pleroma.Web, :view - alias Pleroma.{User, Activity} - alias Pleroma.Web.OEmbed - - def render("note.json", %{type: type, entity: activity }) do - oembed_data(activity) - end - - def oembed_data(activity) do - with %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]), - image = User.avatar_url(user) |> MediaProxy.url() do - %{ - version: "1.0", - type: "link", - title: OEmbed.truncated_content(activity), - provider_url: "https://pleroma.site", - thumbnail_url: image, - } - end -end diff --git a/lib/pleroma/web/ostatus/metadata.ex b/lib/pleroma/web/ostatus/metadata.ex index 4f319b360..792b4a4bd 100644 --- a/lib/pleroma/web/ostatus/metadata.ex +++ b/lib/pleroma/web/ostatus/metadata.ex @@ -1,14 +1,10 @@ defmodule Pleroma.Web.Metadata do alias Phoenix.HTML - alias Pleroma.{Web, Formatter} - alias Pleroma.{User, Activity} + alias Pleroma.{Formatter, User} alias Pleroma.Web.MediaProxy - def build_tags(request_url, params) do - Enum.concat([ - if(meta_enabled?(:opengraph), do: opengraph_tags(params), else: []), - if(meta_enabled?(:oembed), do: oembed_links(request_url), else: []) - ]) + def build_tags(params) do + if(meta_enabled?(:opengraph), do: opengraph_tags(params), else: []) |> Enum.map(&to_tag/1) |> Enum.map(&HTML.safe_to_string/1) |> Enum.join("\n") @@ -24,13 +20,12 @@ defmodule Pleroma.Web.Metadata do with truncated_content = Formatter.truncate(activity.data["object"]["content"]) do [ {:meta, - [ - property: "og:title", - content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) post ##{activity.id}" - ], []}, + [ + property: "og:title", + content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) post ##{activity.id}" + ], []}, {:meta, [property: "og:url", content: activity.data["id"]], []}, - {:meta, [property: "og:description", content: truncated_content], - []}, + {:meta, [property: "og:description", content: truncated_content], []}, {:meta, [property: "og:image", content: user_avatar_url(user)], []}, {:meta, [property: "og:image:width", content: 120], []}, {:meta, [property: "og:image:height", content: 120], []}, @@ -44,10 +39,10 @@ defmodule Pleroma.Web.Metadata do with truncated_bio = Formatter.truncate(user.bio) do [ {:meta, - [ - property: "og:title", - content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) profile" - ], []}, + [ + property: "og:title", + content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) profile" + ], []}, {:meta, [property: "og:url", content: User.profile_url(user)], []}, {:meta, [property: "og:description", content: truncated_bio], []}, {:meta, [property: "og:image", content: user_avatar_url(user)], []}, @@ -58,13 +53,6 @@ defmodule Pleroma.Web.Metadata do end end - defp oembed_links(url) do - Enum.map(["xml", "json"], fn format -> - href = HTML.raw(oembed_path(url, format)) - { :link, [ type: ["application/#{format}+oembed"], href: href, rel: 'alternate'], [] } - end) - end - def to_tag(data) do with {name, attrs, _content = []} <- data do HTML.Tag.tag(name, attrs) @@ -77,11 +65,6 @@ defmodule Pleroma.Web.Metadata do end end - defp oembed_path(url, format) do - query = URI.encode_query(%{url: url, format: format}) - "#{Web.base_url()}/oembed?#{query}" - end - defp user_avatar_url(user) do User.avatar_url(user) |> MediaProxy.url() end @@ -89,4 +72,4 @@ defmodule Pleroma.Web.Metadata do def pleroma_domain do Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN") end -end \ No newline at end of file +end diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index ba44b2e99..c6440c20e 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.OStatus do import Pleroma.Web.XML require Logger - alias Pleroma.{Repo, User, Web, Object, Activity, Formatter} + alias Pleroma.{Repo, User, Web, Object, Activity} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.{WebFinger, Websub} alias Pleroma.Web.OStatus.{FollowHandler, UnfollowHandler, NoteHandler, DeleteHandler} diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index fbd25c5f5..55dbcab93 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -14,9 +14,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do action_fallback(:errors) def feed_redirect(conn, %{"nickname" => nickname}) do - format = get_format(conn) - IO.puts(format) - case format do + case get_format(conn) do "html" -> with %User{} = user <- User.get_cached_by_nickname(nickname) do Fallback.RedirectController.redirector_with_meta(conn, %{user: user}) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index ad26093ac..914cd6a6d 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -453,8 +453,8 @@ defmodule Fallback.RedirectController do end def redirector_with_meta(conn, params) do - {:ok, index_content } = File.read(Application.app_dir(:pleroma, "priv/static/index.html")) - tags = Metadata.build_tags(request_url(conn), params) + {:ok, index_content} = File.read(Application.app_dir(:pleroma, "priv/static/index.html")) + tags = Metadata.build_tags(params) response = String.replace(index_content, "", tags) conn -- cgit v1.2.3 From c5c3ad90d00f1ea599e489aa03cfecada44c998c Mon Sep 17 00:00:00 2001 From: raeno Date: Fri, 14 Dec 2018 02:59:33 +0100 Subject: Fix tests. Remove oembed template --- lib/pleroma/web/templates/o_embed/note.xml.eex | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 lib/pleroma/web/templates/o_embed/note.xml.eex (limited to 'lib') diff --git a/lib/pleroma/web/templates/o_embed/note.xml.eex b/lib/pleroma/web/templates/o_embed/note.xml.eex deleted file mode 100644 index e814a4cb3..000000000 --- a/lib/pleroma/web/templates/o_embed/note.xml.eex +++ /dev/null @@ -1,10 +0,0 @@ - - - 1.0 - link - raeno - http://iamcal.com/ - 86400 - iamcal.com - http://iamcal.com/ - \ No newline at end of file -- cgit v1.2.3 From 1ca080c8628d261cdb95145331aa36e631e90a3f Mon Sep 17 00:00:00 2001 From: eal Date: Fri, 14 Dec 2018 07:56:49 +0200 Subject: Prevent accidental double RTs or favorites --- lib/pleroma/web/common_api/common_api.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index e3385310f..f01d36370 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -1,6 +1,7 @@ defmodule Pleroma.Web.CommonAPI do alias Pleroma.{User, Repo, Activity, Object} alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Formatter import Pleroma.Web.CommonAPI.Utils @@ -16,7 +17,8 @@ defmodule Pleroma.Web.CommonAPI do def repeat(id_or_ap_id, user) do with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id), - object <- Object.normalize(activity.data["object"]["id"]) do + object <- Object.normalize(activity.data["object"]["id"]), + nil <- Utils.get_existing_announce(user.ap_id, object) do ActivityPub.announce(user, object) else _ -> @@ -36,7 +38,8 @@ defmodule Pleroma.Web.CommonAPI do def favorite(id_or_ap_id, user) do with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id), - object <- Object.normalize(activity.data["object"]["id"]) do + object <- Object.normalize(activity.data["object"]["id"]), + nil <- Utils.get_existing_like(user.ap_id, object) do ActivityPub.like(user, object) else _ -> -- cgit v1.2.3 From 61ad2ce4221b86f77977d82c448d0eddb8add5aa Mon Sep 17 00:00:00 2001 From: eal Date: Fri, 14 Dec 2018 08:24:18 +0200 Subject: TwitterAPI: Include favorited post in json --- lib/pleroma/web/twitter_api/views/activity_view.ex | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 83e8fb765..e5caed28f 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -190,6 +190,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do text = "#{user.nickname} favorited a status." + favorited_status = + if liked_activity, + do: render("activity.json", Map.merge(opts, %{activity: liked_activity})), + else: nil + %{ "id" => activity.id, "user" => UserView.render("show.json", %{user: user, for: opts[:for]}), @@ -199,6 +204,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do "is_post_verb" => false, "uri" => "tag:#{activity.data["id"]}:objectType=Favourite", "created_at" => created_at, + "favorited_status" => favorited_status, "in_reply_to_status_id" => liked_activity_id, "external_url" => activity.data["id"], "activity_type" => "like" -- cgit v1.2.3 From f81213910fb32505b92fc19270cc483e00862d0c Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 14 Dec 2018 12:09:55 +0300 Subject: [#114] Addressed MR comments. Removed functionality to be extracted to other MRs. --- lib/pleroma/web/router.ex | 3 --- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 3 --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 4 ---- 3 files changed, 10 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 6a2e0d6c4..6253a28db 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -278,7 +278,6 @@ defmodule Pleroma.Web.Router do post("/account/register", TwitterAPI.Controller, :register) post("/account/password_reset", TwitterAPI.Controller, :password_reset) - get("/account/confirm_email", TwitterAPI.Controller, :confirm_email) get("/search", TwitterAPI.Controller, :search) get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline) @@ -313,8 +312,6 @@ defmodule Pleroma.Web.Router do post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner) post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background) - post("/email_invite", TwitterAPI.Controller, :email_invite) - get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline) get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline) get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index cbde45e52..b1e4c77e8 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -166,9 +166,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do textlimit: to_string(Keyword.get(instance, :limit)), closed: if(Keyword.get(instance, :registrations_open), do: "0", else: "1"), private: if(Keyword.get(instance, :public, true), do: "0", else: "1"), - accountActivationRequired: - if(Keyword.get(instance, :account_activation_required, false), do: "1", else: "0"), - invitesEnabled: if(Keyword.get(instance, :invites_enabled, false), do: "1", else: "0"), vapidPublicKey: vapid_public_key } diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index a45fdcf51..38eff8191 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -333,10 +333,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end - def confirm_email(_conn, _params), do: :noop - - def email_invite(_conn, _params), do: :noop - def update_avatar(%{assigns: %{user: user}} = conn, params) do {:ok, object} = ActivityPub.upload(params, type: :avatar) change = Changeset.change(user, %{avatar: object.data}) -- cgit v1.2.3 From cc83d7ffe786f639172e28005e2912a0bad26234 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 13 Dec 2018 16:30:10 +0300 Subject: [#114] Naive implementation of email invitations. --- lib/pleroma/emails/user_email.ex | 21 +++++++++++++++++++++ .../web/twitter_api/twitter_api_controller.ex | 10 ++++++++++ 2 files changed, 31 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index 9cdf002f3..47dcd42e0 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -37,4 +37,25 @@ defmodule Pleroma.UserEmail do |> subject("Password reset") |> html_body(html_body) end + + def user_invitation_email(user, to_email, to_name \\ nil) do + registration_url = + Router.Helpers.redirect_url( + Endpoint, + :registration_page, + "" + ) + + html_body = """ +

You are invited to #{instance_name()}

+

#{user.name} invites you to join #{instance_name()}, an instance of Pleroma federated social networking platform.

+

Click the following link to register: accept invitation.

+ """ + + new() + |> to(recipient(to_email, to_name)) + |> from(sender()) + |> subject("Invitation to #{instance_name()}") + |> html_body(html_body) + end end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 38eff8191..d51d71299 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -333,6 +333,16 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def confirm_email(_conn, _params), do: :noop + + def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do + with true <- Pleroma.Config.get([:instance, :invites_enabled]), + email <- Pleroma.UserEmail.user_invitation_email(user, email, params["name"]), + {:ok, _} <- Pleroma.Mailer.deliver(email) do + json_response(conn, :no_content, "") + end + end + def update_avatar(%{assigns: %{user: user}} = conn, params) do {:ok, object} = ActivityPub.upload(params, type: :avatar) change = Changeset.change(user, %{avatar: object.data}) -- cgit v1.2.3 From 3cbf16a5fe9f7618cae557eb260093881febd1d1 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 13 Dec 2018 17:58:40 +0300 Subject: [#114] Added UserInviteToken creation, adjusted invitation email link to include it. --- lib/pleroma/emails/user_email.ex | 4 ++-- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index 47dcd42e0..ee41ce50a 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -38,12 +38,12 @@ defmodule Pleroma.UserEmail do |> html_body(html_body) end - def user_invitation_email(user, to_email, to_name \\ nil) do + def user_invitation_email(user, user_invite_token, to_email, to_name \\ nil) do registration_url = Router.Helpers.redirect_url( Endpoint, :registration_page, - "" + user_invite_token.token ) html_body = """ diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index d51d71299..0607a1a6a 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -336,8 +336,12 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def confirm_email(_conn, _params), do: :noop def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do - with true <- Pleroma.Config.get([:instance, :invites_enabled]), - email <- Pleroma.UserEmail.user_invitation_email(user, email, params["name"]), + with true <- + Pleroma.Config.get([:instance, :invites_enabled]) && + !Pleroma.Config.get([:instance, :registrations_open]), + {:ok, invite_token} <- Pleroma.UserInviteToken.create_token(), + email <- + Pleroma.UserEmail.user_invitation_email(user, invite_token, email, params["name"]), {:ok, _} <- Pleroma.Mailer.deliver(email) do json_response(conn, :no_content, "") end -- cgit v1.2.3 From a89e3b4b60b357992aeaedad8e3ff8d086f693a0 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 13 Dec 2018 18:23:05 +0300 Subject: [#114] Moved email_invite action to AdminAPIController, adjusted tests. --- lib/pleroma/web/admin_api/admin_api_controller.ex | 13 +++++++++++++ lib/pleroma/web/router.ex | 2 ++ lib/pleroma/web/twitter_api/twitter_api_controller.ex | 12 ------------ 3 files changed, 15 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 06c3c7c81..4d73cf219 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -147,6 +147,19 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do end end + @doc "Sends registration invite via email" + def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do + with true <- + Pleroma.Config.get([:instance, :invites_enabled]) && + !Pleroma.Config.get([:instance, :registrations_open]), + {:ok, invite_token} <- Pleroma.UserInviteToken.create_token(), + email <- + Pleroma.UserEmail.user_invitation_email(user, invite_token, email, params["name"]), + {:ok, _} <- Pleroma.Mailer.deliver(email) do + json_response(conn, :no_content, "") + end + end + @doc "Get a account registeration invite token (base64 string)" def get_invite_token(conn, _params) do {:ok, token} = Pleroma.UserInviteToken.create_token() diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 6253a28db..daff3362c 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -117,6 +117,8 @@ defmodule Pleroma.Web.Router do delete("/relay", AdminAPIController, :relay_unfollow) get("/invite_token", AdminAPIController, :get_invite_token) + post("/email_invite", AdminAPIController, :email_invite) + get("/password_reset", AdminAPIController, :get_password_reset) end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 0607a1a6a..0ae0a0fea 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -335,18 +335,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def confirm_email(_conn, _params), do: :noop - def email_invite(%{assigns: %{user: user}} = conn, %{"email" => email} = params) do - with true <- - Pleroma.Config.get([:instance, :invites_enabled]) && - !Pleroma.Config.get([:instance, :registrations_open]), - {:ok, invite_token} <- Pleroma.UserInviteToken.create_token(), - email <- - Pleroma.UserEmail.user_invitation_email(user, invite_token, email, params["name"]), - {:ok, _} <- Pleroma.Mailer.deliver(email) do - json_response(conn, :no_content, "") - end - end - def update_avatar(%{assigns: %{user: user}} = conn, params) do {:ok, object} = ActivityPub.upload(params, type: :avatar) change = Changeset.change(user, %{avatar: object.data}) -- cgit v1.2.3 From 9666376f5f98a66f8006971d9b29b2e529b2af68 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 14 Dec 2018 12:37:06 +0300 Subject: [#114] Readded `invites_enabled` config setting, updated readme. --- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index b1e4c77e8..fb3b99d25 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -166,7 +166,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do textlimit: to_string(Keyword.get(instance, :limit)), closed: if(Keyword.get(instance, :registrations_open), do: "0", else: "1"), private: if(Keyword.get(instance, :public, true), do: "0", else: "1"), - vapidPublicKey: vapid_public_key + vapidPublicKey: vapid_public_key, + invitesEnabled: if(Keyword.get(instance, :invites_enabled, false), do: "1", else: "0") } pleroma_fe = %{ -- cgit v1.2.3 From 07e93f99404787b2c6b6193f90cb4102d00a72f9 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 14 Dec 2018 13:52:04 +0300 Subject: [#114] Improved tests. --- lib/pleroma/emails/user_email.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index ee41ce50a..7e3e9b020 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -38,7 +38,12 @@ defmodule Pleroma.UserEmail do |> html_body(html_body) end - def user_invitation_email(user, user_invite_token, to_email, to_name \\ nil) do + def user_invitation_email( + user, + %Pleroma.UserInviteToken{} = user_invite_token, + to_email, + to_name \\ nil + ) do registration_url = Router.Helpers.redirect_url( Endpoint, -- cgit v1.2.3 From 66380b0641534f252f297b67b03d811a714b848d Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 14 Dec 2018 14:01:00 +0300 Subject: [#114] Removed `confirm_email` action stub (to be addressed in a separate MR). --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 0ae0a0fea..38eff8191 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -333,8 +333,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end - def confirm_email(_conn, _params), do: :noop - def update_avatar(%{assigns: %{user: user}} = conn, params) do {:ok, object} = ActivityPub.upload(params, type: :avatar) change = Changeset.change(user, %{avatar: object.data}) -- cgit v1.2.3 From 69fd63e248d39cf2e10657646bc11e9e559e6e45 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 14 Dec 2018 14:13:13 +0300 Subject: [#114] Added `invitesEnabled` to `metadata` of nodeinfo. --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 277dc6ba1..44c11f40a 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -132,6 +132,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do banner: Keyword.get(instance, :banner_upload_limit), background: Keyword.get(instance, :background_upload_limit) }, + invitesEnabled: Keyword.get(instance, :invites_enabled, false), features: features } } -- cgit v1.2.3 From 658edb166fc91e77399ff6022a48076db5404fb1 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Fri, 7 Dec 2018 15:55:28 +0700 Subject: fix and improve web push; add configuration docs --- lib/pleroma/plugs/oauth_plug.ex | 28 +++++++++++----------- .../mastodon_api/views/push_subscription_view.ex | 7 +++++- lib/pleroma/web/push/push.ex | 8 +++---- 3 files changed, 24 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 8b99a74d1..13c914c1b 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -15,10 +15,10 @@ defmodule Pleroma.Plugs.OAuthPlug do def call(%{assigns: %{user: %User{}}} = conn, _), do: conn def call(conn, _) do - with {:ok, token} <- fetch_token(conn), - {:ok, user} <- fetch_user(token) do + with {:ok, token_str} <- fetch_token_str(conn), + {:ok, user, token_record} <- fetch_user_and_token(token_str) do conn - |> assign(:token, token) + |> assign(:token, token_record) |> assign(:user, user) else _ -> conn @@ -27,12 +27,12 @@ defmodule Pleroma.Plugs.OAuthPlug do # Gets user by token # - @spec fetch_user(String.t()) :: {:ok, User.t()} | nil - defp fetch_user(token) do + @spec fetch_user_and_token(String.t()) :: {:ok, User.t(), Token.t()} | nil + defp fetch_user_and_token(token) do query = from(q in Token, where: q.token == ^token, preload: [:user]) - with %Token{user: %{info: %{deactivated: false} = _} = user} <- Repo.one(query) do - {:ok, user} + with %Token{user: %{info: %{deactivated: false} = _} = user} = token_record <- Repo.one(query) do + {:ok, user, token_record} end end @@ -48,23 +48,23 @@ defmodule Pleroma.Plugs.OAuthPlug do # Gets token from headers # - @spec fetch_token(Plug.Conn.t()) :: :no_token_found | {:ok, String.t()} - defp fetch_token(%Plug.Conn{} = conn) do + @spec fetch_token_str(Plug.Conn.t()) :: :no_token_found | {:ok, String.t()} + defp fetch_token_str(%Plug.Conn{} = conn) do headers = get_req_header(conn, "authorization") - with :no_token_found <- fetch_token(headers), + with :no_token_found <- fetch_token_str(headers), do: fetch_token_from_session(conn) end - @spec fetch_token(Keyword.t()) :: :no_token_found | {:ok, String.t()} - defp fetch_token([]), do: :no_token_found + @spec fetch_token_str(Keyword.t()) :: :no_token_found | {:ok, String.t()} + defp fetch_token_str([]), do: :no_token_found - defp fetch_token([token | tail]) do + defp fetch_token_str([token | tail]) do trimmed_token = String.trim(token) case Regex.run(@realm_reg, trimmed_token) do [_, match] -> {:ok, String.trim(match)} - _ -> fetch_token(tail) + _ -> fetch_token_str(tail) end end end diff --git a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex index c8b95d14c..67e86294e 100644 --- a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex +++ b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex @@ -5,7 +5,12 @@ defmodule Pleroma.Web.MastodonAPI.PushSubscriptionView do %{ id: to_string(subscription.id), endpoint: subscription.endpoint, - alerts: Map.get(subscription.data, "alerts") + alerts: Map.get(subscription.data, "alerts"), + server_key: server_key() } end + + defp server_key do + Keyword.get(Application.get_env(:web_push_encryption, :vapid_details), :public_key) + end end diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index 5a873ec19..fb6605f30 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -100,16 +100,16 @@ defmodule Pleroma.Web.Push do def format(%{activity: %{data: %{"type" => "Announce"}}}, actor) do %{ - title: "New Announce", - body: "@#{actor.nickname} has announced your post", + title: "New Repeat", + body: "@#{actor.nickname} has repeated your post", icon: User.avatar_url(actor) } end def format(%{activity: %{data: %{"type" => "Like"}}}, actor) do %{ - title: "New Like", - body: "@#{actor.nickname} has liked your post", + title: "New Favorite", + body: "@#{actor.nickname} has favorited your post", icon: User.avatar_url(actor) } end -- cgit v1.2.3 From 324933a0ac8db810669375315d43fc9250a93a7b Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Fri, 7 Dec 2018 21:08:42 +0700 Subject: improve push message format (compatibility with mastodon) --- lib/pleroma/web/push/push.ex | 54 ++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 29 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index fb6605f30..4af3e159a 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -41,10 +41,10 @@ defmodule Pleroma.Web.Push do ) when type in @types do actor = User.get_cached_by_ap_id(notification.activity.data["actor"]) - body = notification |> format(actor) |> Jason.encode!() Subscription |> where(user_id: ^user_id) + |> preload(:token) |> Repo.all() |> Enum.each(fn record -> subscription = %{ @@ -55,6 +55,16 @@ defmodule Pleroma.Web.Push do endpoint: record.endpoint } + body = + Jason.encode!(%{ + title: format_title(notification), + body: format_body(notification, actor), + notification_id: notification.id, + icon: User.avatar_url(actor), + preferred_locale: "en", + access_token: record.token.token + }) + case WebPushEncryption.send_web_push(body, subscription, @gcm_api_key) do {:ok, %{status_code: code}} when 400 <= code and code < 500 -> Logger.debug("Removing subscription record") @@ -82,35 +92,21 @@ defmodule Pleroma.Web.Push do {:noreply, state} end - def format(%{activity: %{data: %{"type" => "Create"}}}, actor) do - %{ - title: "New Mention", - body: "@#{actor.nickname} has mentiond you", - icon: User.avatar_url(actor) - } - end - - def format(%{activity: %{data: %{"type" => "Follow"}}}, actor) do - %{ - title: "New Follower", - body: "@#{actor.nickname} has followed you", - icon: User.avatar_url(actor) - } - end - - def format(%{activity: %{data: %{"type" => "Announce"}}}, actor) do - %{ - title: "New Repeat", - body: "@#{actor.nickname} has repeated your post", - icon: User.avatar_url(actor) - } + defp format_title(%{activity: %{data: %{"type" => type}}}) do + case type do + "Create" -> "New Mention" + "Follow" -> "New Follower" + "Announce" -> "New Repeat" + "Like" -> "New Favorite" + end end - def format(%{activity: %{data: %{"type" => "Like"}}}, actor) do - %{ - title: "New Favorite", - body: "@#{actor.nickname} has favorited your post", - icon: User.avatar_url(actor) - } + defp format_body(%{activity: %{data: %{"type" => type}}}, actor) do + case type do + "Create" -> "@#{actor.nickname} has mentiond you" + "Follow" -> "@#{actor.nickname} has followed you" + "Announce" -> "@#{actor.nickname} has repeated your post" + "Like" -> "@#{actor.nickname} has favorited your post" + end end end -- cgit v1.2.3 From 7facbb2b8d68abc608d6d36f21207d5c0f131029 Mon Sep 17 00:00:00 2001 From: href Date: Sat, 8 Dec 2018 17:32:58 +0100 Subject: Push.Subscription: convert base64 to base64 urlsafe --- lib/pleroma/web/push/subscription.ex | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/push/subscription.ex b/lib/pleroma/web/push/subscription.ex index cfab7a98e..1ad405daf 100644 --- a/lib/pleroma/web/push/subscription.ex +++ b/lib/pleroma/web/push/subscription.ex @@ -37,8 +37,8 @@ defmodule Pleroma.Web.Push.Subscription do user_id: user.id, token_id: token.id, endpoint: endpoint, - key_auth: key_auth, - key_p256dh: key_p256dh, + key_auth: ensure_base64_urlsafe(key_auth), + key_p256dh: ensure_base64_urlsafe(key_p256dh), data: alerts(params) }) end @@ -63,4 +63,14 @@ defmodule Pleroma.Web.Push.Subscription do sub -> Repo.delete(sub) end end + + # Some webpush clients (e.g. iOS Toot!) use an non urlsafe base64 as an encoding for the key. + # However, the web push rfs specify to use base64 urlsafe, and the `web_push_encryption` library we use + # requires the key to be properly encoded. So we just convert base64 to urlsafe base64. + defp ensure_base64_urlsafe(string) do + string + |> String.replace("+", "-") + |> String.replace("/", "_") + |> String.replace("=", "") + end end -- cgit v1.2.3 From d8984b7bf83e1ee076a73aab682db0f2673e3735 Mon Sep 17 00:00:00 2001 From: href Date: Sat, 8 Dec 2018 17:34:13 +0100 Subject: Push: add missing notification_type field --- lib/pleroma/web/push/push.ex | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index 4af3e159a..8b59e54cb 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -58,14 +58,15 @@ defmodule Pleroma.Web.Push do body = Jason.encode!(%{ title: format_title(notification), + access_token: record.token.token, body: format_body(notification, actor), notification_id: notification.id, + notification_type: format_type(notification), icon: User.avatar_url(actor), - preferred_locale: "en", - access_token: record.token.token + preferred_locale: "en" }) - case WebPushEncryption.send_web_push(body, subscription, @gcm_api_key) do + case WebPushEncryption.send_web_push(body, subscription) do {:ok, %{status_code: code}} when 400 <= code and code < 500 -> Logger.debug("Removing subscription record") Repo.delete!(record) @@ -92,6 +93,16 @@ defmodule Pleroma.Web.Push do {:noreply, state} end + # https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19 + defp format_type(%{activity: %{data: %{"type" => type}}}) do + case type do + "Create" -> "mention" + "Follow" -> "follow" + "Announce" -> "reblog" + "Favorite" -> "favourite" + end + end + defp format_title(%{activity: %{data: %{"type" => type}}}) do case type do "Create" -> "New Mention" -- cgit v1.2.3 From b1bcd97a0f47832d5a87fdfa814f5e2ef54d605f Mon Sep 17 00:00:00 2001 From: href Date: Sat, 8 Dec 2018 18:07:10 +0100 Subject: Push: respect alerts settings --- lib/pleroma/web/push/push.ex | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index 8b59e54cb..d9c3410fe 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -42,45 +42,50 @@ defmodule Pleroma.Web.Push do when type in @types do actor = User.get_cached_by_ap_id(notification.activity.data["actor"]) + type = format_type(notification) + Subscription |> where(user_id: ^user_id) |> preload(:token) |> Repo.all() - |> Enum.each(fn record -> - subscription = %{ + |> Enum.filter(fn subscription -> + get_in(subscription.data, ["alerts", type]) || false + end) + |> Enum.each(fn subscription -> + sub = %{ keys: %{ - p256dh: record.key_p256dh, - auth: record.key_auth + p256dh: subscription.key_p256dh, + auth: subscription.key_auth }, - endpoint: record.endpoint + endpoint: subscription.endpoint } body = Jason.encode!(%{ title: format_title(notification), - access_token: record.token.token, + access_token: subscription.token.token, body: format_body(notification, actor), notification_id: notification.id, - notification_type: format_type(notification), + notification_type: type, icon: User.avatar_url(actor), preferred_locale: "en" }) - case WebPushEncryption.send_web_push(body, subscription) do + case WebPushEncryption.send_web_push(body, sub) do {:ok, %{status_code: code}} when 400 <= code and code < 500 -> Logger.debug("Removing subscription record") - Repo.delete!(record) + Repo.delete!(subscription) :ok {:ok, %{status_code: code}} when 200 <= code and code < 300 -> :ok {:ok, %{status_code: code}} -> - Logger.error("Web Push Nonification failed with code: #{code}") + Logger.error("Web Push Notification failed with code: #{code}") :error _ -> - Logger.error("Web Push Nonification failed with unknown error") + Logger.error("Web Push Notification failed with unknown error") :error end end) -- cgit v1.2.3 From 68229161832fd98ee59679fb19aafc3baceea2ae Mon Sep 17 00:00:00 2001 From: href Date: Sat, 8 Dec 2018 20:02:59 +0100 Subject: Typos --- lib/pleroma/web/push/push.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index d9c3410fe..291e04a6e 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -104,7 +104,7 @@ defmodule Pleroma.Web.Push do "Create" -> "mention" "Follow" -> "follow" "Announce" -> "reblog" - "Favorite" -> "favourite" + "Like" -> "favourite" end end @@ -119,7 +119,7 @@ defmodule Pleroma.Web.Push do defp format_body(%{activity: %{data: %{"type" => type}}}, actor) do case type do - "Create" -> "@#{actor.nickname} has mentiond you" + "Create" -> "@#{actor.nickname} has mentioned you" "Follow" -> "@#{actor.nickname} has followed you" "Announce" -> "@#{actor.nickname} has repeated your post" "Like" -> "@#{actor.nickname} has favorited your post" -- cgit v1.2.3 From 331396cbcdabe9dbfe0b84ec299a642385093605 Mon Sep 17 00:00:00 2001 From: href Date: Sun, 9 Dec 2018 13:45:21 +0100 Subject: Properly disable Web Push if no VAPID key is set --- .../web/mastodon_api/mastodon_api_controller.ex | 4 ++ lib/pleroma/web/push/push.ex | 44 +++++++++++++++------- .../web/twitter_api/controllers/util_controller.ex | 3 +- 3 files changed, 35 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 5c8602322..e105a1e15 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1167,6 +1167,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def create_push_subscription(%{assigns: %{user: user, token: token}} = conn, params) do + true = Pleroma.Web.Push.enabled() Pleroma.Web.Push.Subscription.delete_if_exists(user, token) {:ok, subscription} = Pleroma.Web.Push.Subscription.create(user, token, params) view = PushSubscriptionView.render("push_subscription.json", subscription: subscription) @@ -1174,6 +1175,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def get_push_subscription(%{assigns: %{user: user, token: token}} = conn, _params) do + true = Pleroma.Web.Push.enabled() subscription = Pleroma.Web.Push.Subscription.get(user, token) view = PushSubscriptionView.render("push_subscription.json", subscription: subscription) json(conn, view) @@ -1183,12 +1185,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do %{assigns: %{user: user, token: token}} = conn, params ) do + true = Pleroma.Web.Push.enabled() {:ok, subscription} = Pleroma.Web.Push.Subscription.update(user, token, params) view = PushSubscriptionView.render("push_subscription.json", subscription: subscription) json(conn, view) end def delete_push_subscription(%{assigns: %{user: user, token: token}} = conn, _params) do + true = Pleroma.Web.Push.enabled() {:ok, _response} = Pleroma.Web.Push.Subscription.delete(user, token) json(conn, %{}) end diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index 291e04a6e..35e14c243 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -9,32 +9,44 @@ defmodule Pleroma.Web.Push do @types ["Create", "Follow", "Announce", "Like"] - @gcm_api_key nil - def start_link() do GenServer.start_link(__MODULE__, :ok, name: __MODULE__) end - def init(:ok) do - case Application.get_env(:web_push_encryption, :vapid_details) do - nil -> - Logger.warn( - "VAPID key pair is not found. Please, add VAPID configuration to config. Run `mix web_push.gen.keypair` mix task to create a key pair" - ) - - :ignore + def vapid_config() do + Application.get_env(:web_push_encryption, :vapid_details, []) + end - _ -> - {:ok, %{}} + def enabled() do + case vapid_config() do + [] -> false + list when is_list(list) -> true + _ -> false end end def send(notification) do - if Application.get_env(:web_push_encryption, :vapid_details) do + if enabled() do GenServer.cast(Pleroma.Web.Push, {:send, notification}) end end + def init(:ok) do + if enabled() do + Logger.warn(""" + VAPID key pair is not found. If you wish to enabled web push, please run + + mix web_push.gen.keypair + + and add the resulting output to your configuration file. + """) + + :ignore + else + {:ok, nil} + end + end + def handle_cast( {:send, %{activity: %{data: %{"type" => type}}, user_id: user_id} = notification}, state @@ -71,7 +83,11 @@ defmodule Pleroma.Web.Push do preferred_locale: "en" }) - case WebPushEncryption.send_web_push(body, sub) do + case WebPushEncryption.send_web_push( + body, + sub, + Application.get_env(:web_push_encryption, :gcm_api_key) + ) do {:ok, %{status_code: code}} when 400 <= code and code < 500 -> Logger.debug("Removing subscription record") Repo.delete!(subscription) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index b1e4c77e8..29edca9fe 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -156,8 +156,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do |> send_resp(200, response) _ -> - vapid_public_key = - Keyword.get(Application.get_env(:web_push_encryption, :vapid_details), :public_key) + vapid_public_key = Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key) data = %{ name: Keyword.get(instance, :name), -- cgit v1.2.3 From ec0e613ecaa8dc411e0c821c4c9b2ca893b45f67 Mon Sep 17 00:00:00 2001 From: href Date: Mon, 10 Dec 2018 15:50:10 +0100 Subject: Pleroma.Activity.mastodon_notification_type/1 --- lib/pleroma/activity.ex | 15 +++++ .../web/mastodon_api/mastodon_api_controller.ex | 71 +++++++++------------- lib/pleroma/web/push/push.ex | 12 +--- 3 files changed, 44 insertions(+), 54 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index c065f3b6c..200addd6e 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -3,6 +3,14 @@ defmodule Pleroma.Activity do alias Pleroma.{Repo, Activity, Notification} import Ecto.Query + # https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19 + @mastodon_notification_types %{ + "Create" => "mention", + "Follow" => "follow", + "Announce" => "reblog", + "Like" => "favourite" + } + schema "activities" do field(:data, :map) field(:local, :boolean, default: true) @@ -88,4 +96,11 @@ defmodule Pleroma.Activity do end def get_in_reply_to_activity(_), do: nil + + for {ap_type, type} <- @mastodon_notification_types do + def mastodon_notification_type(%Activity{data: %{"type" => unquote(ap_type)}}), + do: unquote(type) + end + + def mastodon_notification_type(%Activity{}), do: nil end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index e105a1e15..4db7cd60f 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1055,52 +1055,37 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def render_notification(user, %{id: id, activity: activity, inserted_at: created_at} = _params) do actor = User.get_cached_by_ap_id(activity.data["actor"]) + parent_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + mastodon_type = Activity.mastodon_notification_type(activity) - created_at = - NaiveDateTime.to_iso8601(created_at) - |> String.replace(~r/(\.\d+)?$/, ".000Z", global: false) - - id = id |> to_string + response = %{ + id: to_string(id), + type: mastodon_type, + created_at: CommonAPI.Utils.to_masto_date(activity.inserted_at), + account: AccountView.render("account.json", %{user: actor, for: user}) + } - case activity.data["type"] do - "Create" -> - %{ - id: id, - type: "mention", - created_at: created_at, - account: AccountView.render("account.json", %{user: actor, for: user}), + case mastodon_type do + "mention" -> + response + |> Map.merge(%{ status: StatusView.render("status.json", %{activity: activity, for: user}) - } - - "Like" -> - liked_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) - - %{ - id: id, - type: "favourite", - created_at: created_at, - account: AccountView.render("account.json", %{user: actor, for: user}), - status: StatusView.render("status.json", %{activity: liked_activity, for: user}) - } - - "Announce" -> - announced_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) - - %{ - id: id, - type: "reblog", - created_at: created_at, - account: AccountView.render("account.json", %{user: actor, for: user}), - status: StatusView.render("status.json", %{activity: announced_activity, for: user}) - } - - "Follow" -> - %{ - id: id, - type: "follow", - created_at: created_at, - account: AccountView.render("account.json", %{user: actor, for: user}) - } + }) + + "favourite" -> + response + |> Map.merge(%{ + status: StatusView.render("status.json", %{activity: parent_activity, for: user}) + }) + + "reblog" -> + response + |> Map.merge(%{ + status: StatusView.render("status.json", %{activity: parent_activity, for: user}) + }) + + "follow" -> + response _ -> nil diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index 35e14c243..8fa28ee8e 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -54,7 +54,7 @@ defmodule Pleroma.Web.Push do when type in @types do actor = User.get_cached_by_ap_id(notification.activity.data["actor"]) - type = format_type(notification) + type = Pleroma.Activity.mastodon_notification_type(notification.activity) Subscription |> where(user_id: ^user_id) @@ -114,16 +114,6 @@ defmodule Pleroma.Web.Push do {:noreply, state} end - # https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19 - defp format_type(%{activity: %{data: %{"type" => type}}}) do - case type do - "Create" -> "mention" - "Follow" -> "follow" - "Announce" -> "reblog" - "Like" -> "favourite" - end - end - defp format_title(%{activity: %{data: %{"type" => type}}}) do case type do "Create" -> "New Mention" -- cgit v1.2.3 From 0b4c61e8d5a8a24be44aa6bf48c404b47289d0a8 Mon Sep 17 00:00:00 2001 From: href Date: Fri, 14 Dec 2018 13:56:42 +0100 Subject: Fix warning --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 4db7cd60f..0414d73d8 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1061,7 +1061,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do response = %{ id: to_string(id), type: mastodon_type, - created_at: CommonAPI.Utils.to_masto_date(activity.inserted_at), + created_at: CommonAPI.Utils.to_masto_date(created_at), account: AccountView.render("account.json", %{user: actor, for: user}) } -- cgit v1.2.3 From baead4ea4b84ab1190b87a2dc73cdc4afaa6ebc6 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Fri, 14 Dec 2018 12:41:55 +0300 Subject: fix markdown formatting --- lib/pleroma/formatter.ex | 14 ++++++++++++++ lib/pleroma/html.ex | 10 ++-------- lib/pleroma/web/common_api/utils.ex | 10 ++++++++++ lib/pleroma/web/twitter_api/views/activity_view.ex | 3 ++- 4 files changed, 28 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 133683794..b6079551c 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -5,6 +5,8 @@ defmodule Pleroma.Formatter do alias Pleroma.Emoji @tag_regex ~r/\#\w+/u + @mardown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/ + def parse_tags(text, data \\ %{}) do Regex.scan(@tag_regex, text) |> Enum.map(fn ["#" <> tag = full_tag] -> {full_tag, String.downcase(tag)} end) @@ -76,6 +78,18 @@ defmodule Pleroma.Formatter do |> Enum.join("") end + @doc """ + Escapes a special characters in mention names. + """ + @spec mentions_escape(String.t(), list({String.t(), any()})) :: String.t() + def mentions_escape(text, mentions) do + mentions + |> Enum.reduce(text, fn {name, _}, acc -> + escape_name = String.replace(name, @mardown_characters_regex, "\\\\\\1") + String.replace(acc, name, escape_name) + end) + end + @doc "changes scheme:... urls to html links" def add_links({subs, text}) do links = diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 8a0333461..583f05aeb 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -17,15 +17,9 @@ defmodule Pleroma.HTML do end) end - def filter_tags(html, scrubber) do - html |> Scrubber.scrub(scrubber) - end - + def filter_tags(html, scrubber), do: Scrubber.scrub(html, scrubber) def filter_tags(html), do: filter_tags(html, nil) - - def strip_tags(html) do - html |> Scrubber.scrub(Scrubber.StripTags) - end + def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags) end defmodule Pleroma.HTML.Scrubber.TwitterText do diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index ce0926b99..142283684 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -112,6 +112,9 @@ defmodule Pleroma.Web.CommonAPI.Utils do Enum.join([text | attachment_text], "
") end + @doc """ + Formatting text to plain text. + """ def format_input(text, mentions, tags, "text/plain") do text |> Formatter.html_escape("text/plain") @@ -123,6 +126,9 @@ defmodule Pleroma.Web.CommonAPI.Utils do |> Formatter.finalize() end + @doc """ + Formatting text to html. + """ def format_input(text, mentions, _tags, "text/html") do text |> Formatter.html_escape("text/html") @@ -132,8 +138,12 @@ defmodule Pleroma.Web.CommonAPI.Utils do |> Formatter.finalize() end + @doc """ + Formatting text to markdown. + """ def format_input(text, mentions, tags, "text/markdown") do text + |> Formatter.mentions_escape(mentions) |> Earmark.as_html!() |> Formatter.html_escape("text/html") |> String.replace(~r/\r?\n/, "") diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index e5caed28f..433c3b141 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -239,7 +239,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do {summary, content} = render_content(object) html = - HTML.filter_tags(content, User.html_filter_policy(opts[:for])) + content + |> HTML.filter_tags(User.html_filter_policy(opts[:for])) |> Formatter.emojify(object["emoji"]) reply_parent = Activity.get_in_reply_to_activity(activity) -- cgit v1.2.3 From 412df2cd3845802daf80c6d45db13f23f1e1b78b Mon Sep 17 00:00:00 2001 From: href Date: Fri, 14 Dec 2018 16:17:27 +0100 Subject: Warn if push is disabled.. --- lib/pleroma/web/push/push.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index 8fa28ee8e..477943450 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -32,7 +32,7 @@ defmodule Pleroma.Web.Push do end def init(:ok) do - if enabled() do + if !enabled() do Logger.warn(""" VAPID key pair is not found. If you wish to enabled web push, please run -- cgit v1.2.3 From 84b9a9d49749603ca1e21042c194032772c924e7 Mon Sep 17 00:00:00 2001 From: href Date: Fri, 14 Dec 2018 17:24:33 +0100 Subject: TwitterAPI.ActivityView: Ignore unhandled activities --- lib/pleroma/web/twitter_api/views/activity_view.ex | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index e5caed28f..e4d364118 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -14,6 +14,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do alias Pleroma.HTML import Ecto.Query + require Logger defp query_context_ids([]), do: [] @@ -276,6 +277,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do } end + def render("activity.json", %{activity: unhandled_activity}) do + Logger.warn("#{__MODULE__} unhandled activity: #{inspect(unhandled_activity)}") + nil + end + def render_content(%{"type" => "Note"} = object) do summary = object["summary"] -- cgit v1.2.3 From bc6262d2503fa5a9656898fa2dcd91b2111cf2b5 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Fri, 14 Dec 2018 21:21:37 +0300 Subject: fixed typo --- lib/pleroma/formatter.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index b6079551c..46d0d926a 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Formatter do alias Pleroma.Emoji @tag_regex ~r/\#\w+/u - @mardown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/ + @markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/ def parse_tags(text, data \\ %{}) do Regex.scan(@tag_regex, text) @@ -85,7 +85,7 @@ defmodule Pleroma.Formatter do def mentions_escape(text, mentions) do mentions |> Enum.reduce(text, fn {name, _}, acc -> - escape_name = String.replace(name, @mardown_characters_regex, "\\\\\\1") + escape_name = String.replace(name, @markdown_characters_regex, "\\\\\\1") String.replace(acc, name, escape_name) end) end -- cgit v1.2.3 From 46486595ff96e0af0c3193e60879a8e67f77b933 Mon Sep 17 00:00:00 2001 From: raeno Date: Fri, 14 Dec 2018 19:55:40 +0100 Subject: Handle "users/:id" links as well. Fix comments in MR. --- lib/pleroma/user.ex | 13 +++++++++++++ lib/pleroma/web/ostatus/metadata.ex | 5 ++--- lib/pleroma/web/ostatus/ostatus_controller.ex | 4 +++- lib/pleroma/web/router.ex | 8 ++++++-- 4 files changed, 24 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 49928bc13..28ff08a39 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -294,6 +294,10 @@ defmodule Pleroma.User do user.info.locked || false end + def get_by_id(id) do + Repo.get_by(User, id: id) + end + def get_by_ap_id(ap_id) do Repo.get_by(User, ap_id: ap_id) end @@ -320,11 +324,20 @@ defmodule Pleroma.User do Cachex.fetch!(:user_cache, key, fn _ -> get_by_ap_id(ap_id) end) end + def get_cached_by_id(id) do + key = "id:#{id}" + Cachex.fetch!(:user_cache, key, fn _ -> get_by_id(id) end) + end + def get_cached_by_nickname(nickname) do key = "nickname:#{nickname}" Cachex.fetch!(:user_cache, key, fn _ -> get_or_fetch_by_nickname(nickname) end) end + def get_cached_by_nickname_or_id(nickname_or_id) do + get_cached_by_nickname(nickname_or_id) || get_cached_by_id(nickname_or_id) + end + def get_by_nickname(nickname) do Repo.get_by(User, nickname: nickname) end diff --git a/lib/pleroma/web/ostatus/metadata.ex b/lib/pleroma/web/ostatus/metadata.ex index 792b4a4bd..120a89a8b 100644 --- a/lib/pleroma/web/ostatus/metadata.ex +++ b/lib/pleroma/web/ostatus/metadata.ex @@ -11,8 +11,7 @@ defmodule Pleroma.Web.Metadata do end def meta_enabled?(type) do - config = Pleroma.Config.get(:metadata, []) - Keyword.get(config, type, false) + Pleroma.Config.get([:metadata, type], false) end # opengraph for single status @@ -70,6 +69,6 @@ defmodule Pleroma.Web.Metadata do end def pleroma_domain do - Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN") + Pleroma.Web.Endpoint.host() end end diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 55dbcab93..5dbee20e1 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -16,8 +16,10 @@ defmodule Pleroma.Web.OStatus.OStatusController do def feed_redirect(conn, %{"nickname" => nickname}) do case get_format(conn) do "html" -> - with %User{} = user <- User.get_cached_by_nickname(nickname) do + with %User{} = user <- User.get_cached_by_nickname_or_id(nickname) do Fallback.RedirectController.redirector_with_meta(conn, %{user: user}) + else + nil -> {:error, :not_found} end "activity+json" -> diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 914cd6a6d..ad97698dd 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -449,11 +449,11 @@ defmodule Fallback.RedirectController do def redirector(conn, _params) do conn |> put_resp_content_type("text/html") - |> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html")) + |> send_file(200, index_file_path()) end def redirector_with_meta(conn, params) do - {:ok, index_content} = File.read(Application.app_dir(:pleroma, "priv/static/index.html")) + {:ok, index_content} = File.read(index_file_path()) tags = Metadata.build_tags(params) response = String.replace(index_content, "", tags) @@ -462,6 +462,10 @@ defmodule Fallback.RedirectController do |> send_resp(200, response) end + def index_file_path do + Application.app_dir(:pleroma, "priv/static/index.html") + end + def registration_page(conn, params) do redirector(conn, params) end -- cgit v1.2.3 From d3ec09bb380bb990bea6edc5dae6bbda7f2322c5 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Thu, 13 Dec 2018 15:13:02 +0300 Subject: fix tags --- lib/pleroma/web/mastodon_api/views/status_view.ex | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index c3c735d5d..f2a47f594 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -140,7 +140,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do visibility: get_visibility(object), media_attachments: attachments |> Enum.take(4), mentions: mentions, - tags: tags, + tags: build_tags(tags), application: %{ name: "Web", website: nil @@ -234,6 +234,25 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do def render_content(object), do: object["content"] || "" + @doc """ + Builds a dictionary tags. + + ## Examples + + iex> Pleroma.Web.MastodonAPI.StatusView.build_tags(["fediverse", "nextcloud"]) + [{"name": "fediverse", "url": "/tag/fediverse"}, + {"name": "nextcloud", "url": "/tag/nextcloud"}] + + """ + @spec build_tags(list(String.t())) :: list(map()) + def build_tags(object_tags) when is_list(object_tags) do + Enum.reduce(object_tags, [], fn tag, tags -> + tags ++ [%{name: tag, url: "/tag/#{tag}"}] + end) + end + + def build_tags(_), do: [] + @doc """ Builds list emojis. -- cgit v1.2.3 From b0c3211984c0aa807ea58897308f04ad42651cf1 Mon Sep 17 00:00:00 2001 From: raeno Date: Fri, 14 Dec 2018 21:07:06 +0100 Subject: Scrub html from activity.content or user.bio for opengraph meta --- lib/pleroma/web/ostatus/metadata.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/ostatus/metadata.ex b/lib/pleroma/web/ostatus/metadata.ex index 120a89a8b..9935726fc 100644 --- a/lib/pleroma/web/ostatus/metadata.ex +++ b/lib/pleroma/web/ostatus/metadata.ex @@ -16,7 +16,7 @@ defmodule Pleroma.Web.Metadata do # opengraph for single status defp opengraph_tags(%{activity: activity, user: user}) do - with truncated_content = Formatter.truncate(activity.data["object"]["content"]) do + with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do [ {:meta, [ @@ -35,7 +35,7 @@ defmodule Pleroma.Web.Metadata do # opengraph for user card defp opengraph_tags(%{user: user}) do - with truncated_bio = Formatter.truncate(user.bio) do + with truncated_bio = scrub_html_and_truncate(user.bio) do [ {:meta, [ @@ -64,6 +64,14 @@ defmodule Pleroma.Web.Metadata do end end + defp scrub_html_and_truncate(content) do + content + # html content comes from DB already encoded, decode first and scrub after + |> HtmlEntities.decode() + |> Pleroma.HTML.strip_tags() + |> Formatter.truncate() + end + defp user_avatar_url(user) do User.avatar_url(user) |> MediaProxy.url() end -- cgit v1.2.3 From 30812f84518f1b2fcc70a416d1a6b9f81264f3a5 Mon Sep 17 00:00:00 2001 From: raeno Date: Fri, 14 Dec 2018 21:08:25 +0100 Subject: Remove domain from sample_config template --- lib/mix/tasks/pleroma/sample_config.eex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/sample_config.eex b/lib/mix/tasks/pleroma/sample_config.eex index 8eacefab2..0cd572797 100644 --- a/lib/mix/tasks/pleroma/sample_config.eex +++ b/lib/mix/tasks/pleroma/sample_config.eex @@ -12,7 +12,6 @@ config :pleroma, Pleroma.Web.Endpoint, config :pleroma, :instance, name: "<%= name %>", email: "<%= email %>", - domain: "<%= domain %>, limit: 5000, registrations_open: true, dedupe_media: false -- cgit v1.2.3 From ea72ac549b2ac52623462d6862154fb6f800c01c Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Fri, 14 Dec 2018 22:56:37 +0300 Subject: fix case when tags is invalid --- lib/pleroma/web/mastodon_api/views/status_view.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index f2a47f594..46c559e3a 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -244,8 +244,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do {"name": "nextcloud", "url": "/tag/nextcloud"}] """ - @spec build_tags(list(String.t())) :: list(map()) + @spec build_tags(list(any())) :: list(map()) def build_tags(object_tags) when is_list(object_tags) do + object_tags = for tag when is_binary(tag) <- object_tags, do: tag + Enum.reduce(object_tags, [], fn tag, tags -> tags ++ [%{name: tag, url: "/tag/#{tag}"}] end) -- cgit v1.2.3 From a2399c1c7c17ee1c8e85ae0b6095405c7cb9f6f1 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sat, 15 Dec 2018 01:31:19 +0300 Subject: Add base CAPTCHA support (currently only kocaptcha) --- lib/pleroma/application.ex | 1 + lib/pleroma/captcha.ex | 68 ++++++++++++++++++++++ lib/pleroma/web/router.ex | 1 + .../web/twitter_api/controllers/util_controller.ex | 4 ++ lib/pleroma/web/twitter_api/twitter_api.ex | 47 +++++++++------ 5 files changed, 102 insertions(+), 19 deletions(-) create mode 100644 lib/pleroma/captcha.ex (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 8705395a4..e15991957 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -24,6 +24,7 @@ defmodule Pleroma.Application do # Start the Ecto repository supervisor(Pleroma.Repo, []), worker(Pleroma.Emoji, []), + worker(Pleroma.Captcha, []), worker( Cachex, [ diff --git a/lib/pleroma/captcha.ex b/lib/pleroma/captcha.ex new file mode 100644 index 000000000..31f3bc797 --- /dev/null +++ b/lib/pleroma/captcha.ex @@ -0,0 +1,68 @@ +defmodule Pleroma.Captcha do + use GenServer + + @ets __MODULE__.Ets + @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}] + + + @doc false + def start_link() do + GenServer.start_link(__MODULE__, [], name: __MODULE__) + end + + + @doc false + def init(_) do + @ets = :ets.new(@ets, @ets_options) + + {:ok, nil} + end + + def new() do + GenServer.call(__MODULE__, :new) + end + + def validate(token, captcha) do + GenServer.call(__MODULE__, {:validate, token, captcha}) + end + + @doc false + def handle_call(:new, _from, state) do + method = Pleroma.Config.get!([__MODULE__, :method]) + + case method do + __MODULE__.Kocaptcha -> + endpoint = Pleroma.Config.get!([method, :endpoint]) + case HTTPoison.get(endpoint <> "/new") do + {:error, _} -> + %{error: "Kocaptcha service unavailable"} + {:ok, res} -> + json_resp = Poison.decode!(res.body) + + token = json_resp["token"] + + true = :ets.insert(@ets, {token, json_resp["md5"]}) + + { + :reply, + %{type: :kocaptcha, token: token, url: endpoint <> json_resp["url"]}, + state + } + end + end + end + + @doc false + def handle_call({:validate, token, captcha}, _from, state) do + with false <- is_nil(captcha), + [{^token, saved_md5}] <- :ets.lookup(@ets, token), + true <- (:crypto.hash(:md5, captcha) |> Base.encode16) == String.upcase(saved_md5) do + # Clear the saved value + :ets.delete(@ets, token) + + {:reply, true, state} + else + e -> IO.inspect(e); {:reply, false, state} + end + end +end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index daff3362c..60342cfb4 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -99,6 +99,7 @@ defmodule Pleroma.Web.Router do get("/password_reset/:token", UtilController, :show_password_reset) post("/password_reset", UtilController, :password_reset) get("/emoji", UtilController, :emoji) + get("/captcha", UtilController, :captcha) end scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 2f2b69623..38653f0b8 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -284,4 +284,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do json(conn, %{error: msg}) end end + + def captcha(conn, _params) do + json(conn, Pleroma.Captcha.new()) + end end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 1e764f24a..c9e8fbcbb 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -132,38 +132,47 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do bio: User.parse_bio(params["bio"]), email: params["email"], password: params["password"], - password_confirmation: params["confirm"] + password_confirmation: params["confirm"], + captcha_solution: params["captcha_solution"], + captcha_token: params["captcha_token"] } - registrations_open = Pleroma.Config.get([:instance, :registrations_open]) + # Captcha invalid + if not Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution]) do + # I have no idea how this error handling works + {:error, %{error: Jason.encode!(%{captcha: ["Invalid CAPTCHA"]})}} + else + registrations_open = Pleroma.Config.get([:instance, :registrations_open]) - # no need to query DB if registration is open - token = - unless registrations_open || is_nil(tokenString) do + # no need to query DB if registration is open + token = + unless registrations_open || is_nil(tokenString) do Repo.get_by(UserInviteToken, %{token: tokenString}) end - cond do - registrations_open || (!is_nil(token) && !token.used) -> - changeset = User.register_changeset(%User{info: %{}}, params) + cond do + registrations_open || (!is_nil(token) && !token.used) -> + changeset = User.register_changeset(%User{info: %{}}, params) - with {:ok, user} <- Repo.insert(changeset) do - !registrations_open && UserInviteToken.mark_as_used(token.token) - {:ok, user} - else - {:error, changeset} -> - errors = + with {:ok, user} <- Repo.insert(changeset) do + !registrations_open && UserInviteToken.mark_as_used(token.token) + {:ok, user} + else + {:error, changeset} -> + errors = Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end) |> Jason.encode!() {:error, %{error: errors}} - end + end + - !registrations_open && is_nil(token) -> - {:error, "Invalid token"} + !registrations_open && is_nil(token) -> + {:error, "Invalid token"} - !registrations_open && token.used -> - {:error, "Expired token"} + !registrations_open && token.used -> + {:error, "Expired token"} + end end end -- cgit v1.2.3 From 28c43a417e89ad68674f6e60d7d3025fbb4655ff Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sat, 15 Dec 2018 02:00:00 +0300 Subject: Add an ability to disabled captcha --- lib/pleroma/captcha.ex | 52 ++++++++++++++++++------------ lib/pleroma/web/twitter_api/twitter_api.ex | 10 +++++- 2 files changed, 40 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/captcha.ex b/lib/pleroma/captcha.ex index 31f3bc797..ffa5640ea 100644 --- a/lib/pleroma/captcha.ex +++ b/lib/pleroma/captcha.ex @@ -28,27 +28,37 @@ defmodule Pleroma.Captcha do @doc false def handle_call(:new, _from, state) do - method = Pleroma.Config.get!([__MODULE__, :method]) - - case method do - __MODULE__.Kocaptcha -> - endpoint = Pleroma.Config.get!([method, :endpoint]) - case HTTPoison.get(endpoint <> "/new") do - {:error, _} -> - %{error: "Kocaptcha service unavailable"} - {:ok, res} -> - json_resp = Poison.decode!(res.body) - - token = json_resp["token"] - - true = :ets.insert(@ets, {token, json_resp["md5"]}) - - { - :reply, - %{type: :kocaptcha, token: token, url: endpoint <> json_resp["url"]}, - state - } - end + enabled = Pleroma.Config.get([__MODULE__, :enabled]) + + if !enabled do + { + :reply, + %{type: :none}, + state + } + else + method = Pleroma.Config.get!([__MODULE__, :method]) + + case method do + __MODULE__.Kocaptcha -> + endpoint = Pleroma.Config.get!([method, :endpoint]) + case HTTPoison.get(endpoint <> "/new") do + {:error, _} -> + %{error: "Kocaptcha service unavailable"} + {:ok, res} -> + json_resp = Poison.decode!(res.body) + + token = json_resp["token"] + + true = :ets.insert(@ets, {token, json_resp["md5"]}) + + { + :reply, + %{type: :kocaptcha, token: token, url: endpoint <> json_resp["url"]}, + state + } + end + end end end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index c9e8fbcbb..9f98c43c9 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -137,8 +137,16 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do captcha_token: params["captcha_token"] } + captcha_enabled = Pleroma.Config.get([Pleroma.Captcha, :enabled]) + # true if captcha is disabled or enabled and valid, false otherwise + captcha_ok = if !captcha_enabled do + true + else + Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution]) + end + # Captcha invalid - if not Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution]) do + if not captcha_ok do # I have no idea how this error handling works {:error, %{error: Jason.encode!(%{captcha: ["Invalid CAPTCHA"]})}} else -- cgit v1.2.3 From 4a895a46d111286e5c6cf923b9fdb4e50115104a Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sat, 15 Dec 2018 11:00:54 +0100 Subject: Allow port specification in instance.ex --- lib/mix/tasks/pleroma/instance.ex | 16 ++++++++++------ lib/mix/tasks/pleroma/sample_config.eex | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 3be856115..02e1ce27d 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -58,12 +58,15 @@ defmodule Mix.Tasks.Pleroma.Instance do proceed? = Enum.empty?(will_overwrite) or Keyword.get(options, :force, false) unless not proceed? do - domain = - Common.get_option( - options, - :domain, - "What domain will your instance use? (e.g pleroma.soykaf.com)" - ) + [domain, port | _] = + String.split( + Common.get_option( + options, + :domain, + "What domain will your instance use? (e.g pleroma.soykaf.com)" + ), + ":" + ) ++ [443] name = Common.get_option( @@ -104,6 +107,7 @@ defmodule Mix.Tasks.Pleroma.Instance do EEx.eval_file( "sample_config.eex" |> Path.expand(__DIR__), domain: domain, + port: port, email: email, name: name, dbhost: dbhost, diff --git a/lib/mix/tasks/pleroma/sample_config.eex b/lib/mix/tasks/pleroma/sample_config.eex index 0cd572797..740b9f8d1 100644 --- a/lib/mix/tasks/pleroma/sample_config.eex +++ b/lib/mix/tasks/pleroma/sample_config.eex @@ -6,7 +6,7 @@ use Mix.Config config :pleroma, Pleroma.Web.Endpoint, - url: [host: "<%= domain %>", scheme: "https", port: 443], + url: [host: "<%= domain %>", scheme: "https", port: <%= port %>], secret_key_base: "<%= secret %>" config :pleroma, :instance, -- cgit v1.2.3 From cddab5700b4903ba280fada57a79b8efe10f0bf6 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 15 Dec 2018 17:34:37 +0100 Subject: WebFinger: Sends a 400 when resource param is missing, fix XRD typo in test --- lib/pleroma/web/web_finger/web_finger_controller.ex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/web_finger/web_finger_controller.ex b/lib/pleroma/web/web_finger/web_finger_controller.ex index 002353166..8c60300a4 100644 --- a/lib/pleroma/web/web_finger/web_finger_controller.ex +++ b/lib/pleroma/web/web_finger/web_finger_controller.ex @@ -35,4 +35,8 @@ defmodule Pleroma.Web.WebFinger.WebFingerController do send_resp(conn, 404, "Unsupported format") end end + + def webfinger(conn, _params) do + send_resp(conn, 400, "Bad Request") + end end -- cgit v1.2.3 From b5518da90468ab1cde40593695d75f3d72d66783 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sat, 15 Dec 2018 22:06:44 +0300 Subject: Separate captcha implementation into a behaviour and use it --- lib/pleroma/captcha.ex | 78 ---------------------------------- lib/pleroma/captcha/captcha.ex | 51 ++++++++++++++++++++++ lib/pleroma/captcha/captcha_service.ex | 24 +++++++++++ lib/pleroma/captcha/kocaptcha.ex | 37 ++++++++++++++++ 4 files changed, 112 insertions(+), 78 deletions(-) delete mode 100644 lib/pleroma/captcha.ex create mode 100644 lib/pleroma/captcha/captcha.ex create mode 100644 lib/pleroma/captcha/captcha_service.ex create mode 100644 lib/pleroma/captcha/kocaptcha.ex (limited to 'lib') diff --git a/lib/pleroma/captcha.ex b/lib/pleroma/captcha.ex deleted file mode 100644 index ffa5640ea..000000000 --- a/lib/pleroma/captcha.ex +++ /dev/null @@ -1,78 +0,0 @@ -defmodule Pleroma.Captcha do - use GenServer - - @ets __MODULE__.Ets - @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}] - - - @doc false - def start_link() do - GenServer.start_link(__MODULE__, [], name: __MODULE__) - end - - - @doc false - def init(_) do - @ets = :ets.new(@ets, @ets_options) - - {:ok, nil} - end - - def new() do - GenServer.call(__MODULE__, :new) - end - - def validate(token, captcha) do - GenServer.call(__MODULE__, {:validate, token, captcha}) - end - - @doc false - def handle_call(:new, _from, state) do - enabled = Pleroma.Config.get([__MODULE__, :enabled]) - - if !enabled do - { - :reply, - %{type: :none}, - state - } - else - method = Pleroma.Config.get!([__MODULE__, :method]) - - case method do - __MODULE__.Kocaptcha -> - endpoint = Pleroma.Config.get!([method, :endpoint]) - case HTTPoison.get(endpoint <> "/new") do - {:error, _} -> - %{error: "Kocaptcha service unavailable"} - {:ok, res} -> - json_resp = Poison.decode!(res.body) - - token = json_resp["token"] - - true = :ets.insert(@ets, {token, json_resp["md5"]}) - - { - :reply, - %{type: :kocaptcha, token: token, url: endpoint <> json_resp["url"]}, - state - } - end - end - end - end - - @doc false - def handle_call({:validate, token, captcha}, _from, state) do - with false <- is_nil(captcha), - [{^token, saved_md5}] <- :ets.lookup(@ets, token), - true <- (:crypto.hash(:md5, captcha) |> Base.encode16) == String.upcase(saved_md5) do - # Clear the saved value - :ets.delete(@ets, token) - - {:reply, true, state} - else - e -> IO.inspect(e); {:reply, false, state} - end - end -end diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex new file mode 100644 index 000000000..df33406ee --- /dev/null +++ b/lib/pleroma/captcha/captcha.ex @@ -0,0 +1,51 @@ +defmodule Pleroma.Captcha do + use GenServer + + @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}] + + @doc false + def start_link() do + GenServer.start_link(__MODULE__, [], name: __MODULE__) + end + + @doc false + def init(_) do + # Create a ETS table to store captchas + ets_name = Module.concat(method(), Ets) + ^ets_name = :ets.new(Module.concat(method(), Ets), @ets_options) + + {:ok, nil} + end + + @doc """ + Ask the configured captcha service for a new captcha + """ + def new() do + GenServer.call(__MODULE__, :new) + end + + @doc """ + Ask the configured captcha service to validate the captcha + """ + def validate(token, captcha) do + GenServer.call(__MODULE__, {:validate, token, captcha}) + end + + @doc false + def handle_call(:new, _from, state) do + enabled = Pleroma.Config.get([__MODULE__, :enabled]) + + if !enabled do + {:reply, %{type: :none}, state} + else + {:reply, method().new(), state} + end + end + + @doc false + def handle_call({:validate, token, captcha}, _from, state) do + {:reply, method().validate(token, captcha), state} + end + + defp method, do: Pleroma.Config.get!([__MODULE__, :method]) +end diff --git a/lib/pleroma/captcha/captcha_service.ex b/lib/pleroma/captcha/captcha_service.ex new file mode 100644 index 000000000..ae1d6e7c7 --- /dev/null +++ b/lib/pleroma/captcha/captcha_service.ex @@ -0,0 +1,24 @@ +defmodule Pleroma.Captcha.Service do + + @doc """ + Request new captcha from a captcha service. + + Returns: + + Service-specific data for using the newly created captcha + """ + @callback new() :: map + + @doc """ + Validated the provided captcha solution. + + Arguments: + * `token` the captcha is associated with + * `captcha` solution of the captcha to validate + + Returns: + + `true` if captcha is valid, `false` if not + """ + @callback validate(token :: String.t, captcha :: String.t) :: boolean +end diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex new file mode 100644 index 000000000..abccbf6d3 --- /dev/null +++ b/lib/pleroma/captcha/kocaptcha.ex @@ -0,0 +1,37 @@ +defmodule Pleroma.Captcha.Kocaptcha do + alias Pleroma.Captcha.Service + @behaviour Service + + @ets __MODULE__.Ets + + @impl Service + def new() do + endpoint = Pleroma.Config.get!([__MODULE__, :endpoint]) + case HTTPoison.get(endpoint <> "/new") do + {:error, _} -> + %{error: "Kocaptcha service unavailable"} + {:ok, res} -> + json_resp = Poison.decode!(res.body) + + token = json_resp["token"] + + true = :ets.insert(@ets, {token, json_resp["md5"]}) + + %{type: :kocaptcha, token: token, url: endpoint <> json_resp["url"]} + end + end + + @impl Service + def validate(token, captcha) do + with false <- is_nil(captcha), + [{^token, saved_md5}] <- :ets.lookup(@ets, token), + true <- (:crypto.hash(:md5, captcha) |> Base.encode16) == String.upcase(saved_md5) do + # Clear the saved value + :ets.delete(@ets, token) + + true + else + _ -> false + end + end +end -- cgit v1.2.3 From 23549d39521386f217a57ef1aeb3d660eff06860 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sat, 15 Dec 2018 22:08:26 +0300 Subject: Formatting fixes --- lib/pleroma/captcha/captcha_service.ex | 3 +-- lib/pleroma/captcha/kocaptcha.ex | 4 +++- lib/pleroma/web/twitter_api/twitter_api.ex | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/captcha/captcha_service.ex b/lib/pleroma/captcha/captcha_service.ex index ae1d6e7c7..907a73ad0 100644 --- a/lib/pleroma/captcha/captcha_service.ex +++ b/lib/pleroma/captcha/captcha_service.ex @@ -1,5 +1,4 @@ defmodule Pleroma.Captcha.Service do - @doc """ Request new captcha from a captcha service. @@ -20,5 +19,5 @@ defmodule Pleroma.Captcha.Service do `true` if captcha is valid, `false` if not """ - @callback validate(token :: String.t, captcha :: String.t) :: boolean + @callback validate(token :: String.t(), captcha :: String.t()) :: boolean end diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex index abccbf6d3..173ce17f7 100644 --- a/lib/pleroma/captcha/kocaptcha.ex +++ b/lib/pleroma/captcha/kocaptcha.ex @@ -7,9 +7,11 @@ defmodule Pleroma.Captcha.Kocaptcha do @impl Service def new() do endpoint = Pleroma.Config.get!([__MODULE__, :endpoint]) + case HTTPoison.get(endpoint <> "/new") do {:error, _} -> %{error: "Kocaptcha service unavailable"} + {:ok, res} -> json_resp = Poison.decode!(res.body) @@ -25,7 +27,7 @@ defmodule Pleroma.Captcha.Kocaptcha do def validate(token, captcha) do with false <- is_nil(captcha), [{^token, saved_md5}] <- :ets.lookup(@ets, token), - true <- (:crypto.hash(:md5, captcha) |> Base.encode16) == String.upcase(saved_md5) do + true <- :crypto.hash(:md5, captcha) |> Base.encode16() == String.upcase(saved_md5) do # Clear the saved value :ets.delete(@ets, token) diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 9f98c43c9..90b8345c5 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -139,11 +139,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do captcha_enabled = Pleroma.Config.get([Pleroma.Captcha, :enabled]) # true if captcha is disabled or enabled and valid, false otherwise - captcha_ok = if !captcha_enabled do - true - else - Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution]) - end + captcha_ok = + if !captcha_enabled do + true + else + Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution]) + end # Captcha invalid if not captcha_ok do @@ -155,8 +156,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do # no need to query DB if registration is open token = unless registrations_open || is_nil(tokenString) do - Repo.get_by(UserInviteToken, %{token: tokenString}) - end + Repo.get_by(UserInviteToken, %{token: tokenString}) + end cond do registrations_open || (!is_nil(token) && !token.used) -> @@ -168,18 +169,17 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do else {:error, changeset} -> errors = - Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end) - |> Jason.encode!() + Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end) + |> Jason.encode!() - {:error, %{error: errors}} + {:error, %{error: errors}} end - !registrations_open && is_nil(token) -> - {:error, "Invalid token"} + {:error, "Invalid token"} !registrations_open && token.used -> - {:error, "Expired token"} + {:error, "Expired token"} end end end -- cgit v1.2.3 From 8d55a549e678daa057fce81d1d2ee46b2f8c5545 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sat, 15 Dec 2018 22:43:28 +0300 Subject: Replace HTTPoison with Tesla for kocaptha --- lib/pleroma/captcha/kocaptcha.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex index 173ce17f7..4ecd1a81f 100644 --- a/lib/pleroma/captcha/kocaptcha.ex +++ b/lib/pleroma/captcha/kocaptcha.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Captcha.Kocaptcha do def new() do endpoint = Pleroma.Config.get!([__MODULE__, :endpoint]) - case HTTPoison.get(endpoint <> "/new") do + case Tesla.get(endpoint <> "/new") do {:error, _} -> %{error: "Kocaptcha service unavailable"} -- cgit v1.2.3 From 4c783e35c09c74097257ce56fde74025db0024c6 Mon Sep 17 00:00:00 2001 From: eal Date: Sun, 16 Dec 2018 13:15:34 +0200 Subject: Mastodon API: Fix PUT /api/web/settings --- lib/pleroma/user/info.ex | 5 ++++- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index d81b45b8d..a3785447c 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -149,9 +149,12 @@ defmodule Pleroma.User.Info do ]) end - def mastodon_settings_update(info, params) do + def mastodon_settings_update(info, settings) do + params = %{settings: settings} + info |> cast(params, [:settings]) + |> validate_required([:settings]) end def set_source_data(info, source_data) do diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 5c8602322..a46e1878f 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -929,7 +929,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do ] }, settings: - Map.get(user.info, :settings) || + user.info.settings || %{ onboarded: true, home: %{ @@ -978,13 +978,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do info_cng = User.Info.mastodon_settings_update(user.info, settings) - with changeset <- User.update_changeset(user), + with changeset <- Ecto.Changeset.change(user), changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng), {:ok, _user} <- User.update_and_set_cache(changeset) do json(conn, %{}) else e -> - json(conn, %{error: inspect(e)}) + conn + |> put_resp_content_type("application/json") + |> send_resp(500, Jason.encode!(%{"error" => inspect(e)})) end end -- cgit v1.2.3 From f672555ad347861617c9b9b2c323b5044e840649 Mon Sep 17 00:00:00 2001 From: href Date: Sun, 16 Dec 2018 17:15:07 +0100 Subject: Upgrade to Phoenix 1.4 --- lib/pleroma/web/channels/user_socket.ex | 4 - lib/pleroma/web/endpoint.ex | 2 +- lib/pleroma/web/mastodon_api/mastodon_socket.ex | 7 -- .../web/twitter_api/twitter_api_controller.ex | 126 +++++++++++++++------ 4 files changed, 92 insertions(+), 47 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/channels/user_socket.ex b/lib/pleroma/web/channels/user_socket.ex index 07ddee169..9918d3b49 100644 --- a/lib/pleroma/web/channels/user_socket.ex +++ b/lib/pleroma/web/channels/user_socket.ex @@ -6,10 +6,6 @@ defmodule Pleroma.Web.UserSocket do # channel "room:*", Pleroma.Web.RoomChannel channel("chat:*", Pleroma.Web.ChatChannel) - ## Transports - transport(:websocket, Phoenix.Transports.WebSocket) - # transport :longpoll, Phoenix.Transports.LongPoll - # Socket params are passed from the client and can # be used to verify and authenticate a user. After # verification, you can put default assigns into diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index c5f9d51d9..aacc88195 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -3,7 +3,7 @@ defmodule Pleroma.Web.Endpoint do socket("/socket", Pleroma.Web.UserSocket) - socket("/api/v1", Pleroma.Web.MastodonAPI.MastodonSocket) + socket("/api/v1", Pleroma.Web.MastodonAPI.MastodonSocket, websocket: [path: "/streaming"]) # Serve at "/" the static files from "priv/static" directory. # diff --git a/lib/pleroma/web/mastodon_api/mastodon_socket.ex b/lib/pleroma/web/mastodon_api/mastodon_socket.ex index 755ac5730..1b75897b5 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_socket.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_socket.ex @@ -4,13 +4,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket do alias Pleroma.Web.OAuth.Token alias Pleroma.{User, Repo} - transport( - :websocket, - Phoenix.Transports.WebSocket.Raw, - # We never receive data. - timeout: :infinity - ) - @spec connect(params :: map(), Phoenix.Socket.t()) :: {:ok, Phoenix.Socket.t()} | :error def connect(%{"access_token" => token} = params, socket) do with %Token{user_id: user_id} <- Repo.get_by(Token, token: token), diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 38eff8191..327620302 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -17,7 +17,10 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def verify_credentials(%{assigns: %{user: user}} = conn, _params) do token = Phoenix.Token.sign(conn, "user socket", user.id) - render(conn, UserView, "show.json", %{user: user, token: token}) + + conn + |> put_view(UserView) + |> render("show.json", %{user: user, token: token}) end def status_update(%{assigns: %{user: user}} = conn, %{"status" => _} = status_data) do @@ -58,7 +61,8 @@ defmodule Pleroma.Web.TwitterAPI.Controller do activities = ActivityPub.fetch_public_activities(params) conn - |> render(ActivityView, "index.json", %{activities: activities, for: user}) + |> put_view(ActivityView) + |> render("index.json", %{activities: activities, for: user}) end def public_timeline(%{assigns: %{user: user}} = conn, params) do @@ -71,7 +75,8 @@ defmodule Pleroma.Web.TwitterAPI.Controller do activities = ActivityPub.fetch_public_activities(params) conn - |> render(ActivityView, "index.json", %{activities: activities, for: user}) + |> put_view(ActivityView) + |> render("index.json", %{activities: activities, for: user}) end def friends_timeline(%{assigns: %{user: user}} = conn, params) do @@ -86,16 +91,22 @@ defmodule Pleroma.Web.TwitterAPI.Controller do |> ActivityPub.contain_timeline(user) conn - |> render(ActivityView, "index.json", %{activities: activities, for: user}) + |> put_view(ActivityView) + |> render("index.json", %{activities: activities, for: user}) end def show_user(conn, params) do with {:ok, shown} <- TwitterAPI.get_user(params) do - if user = conn.assigns.user do - render(conn, UserView, "show.json", %{user: shown, for: user}) - else - render(conn, UserView, "show.json", %{user: shown}) - end + params = + if user = conn.assigns.user do + %{user: shown, for: user} + else + %{user: shown} + end + + conn + |> put_view(UserView) + |> render("show.json", params) else {:error, msg} -> bad_request_reply(conn, msg) @@ -108,7 +119,8 @@ defmodule Pleroma.Web.TwitterAPI.Controller do activities = ActivityPub.fetch_user_activities(target_user, user, params) conn - |> render(ActivityView, "index.json", %{activities: activities, for: user}) + |> put_view(ActivityView) + |> render("index.json", %{activities: activities, for: user}) {:error, msg} -> bad_request_reply(conn, msg) @@ -124,7 +136,8 @@ defmodule Pleroma.Web.TwitterAPI.Controller do activities = ActivityPub.fetch_activities([user.ap_id], params) conn - |> render(ActivityView, "index.json", %{activities: activities, for: user}) + |> put_view(ActivityView) + |> render("index.json", %{activities: activities, for: user}) end def dm_timeline(%{assigns: %{user: user}} = conn, params) do @@ -137,14 +150,16 @@ defmodule Pleroma.Web.TwitterAPI.Controller do activities = Repo.all(query) conn - |> render(ActivityView, "index.json", %{activities: activities, for: user}) + |> put_view(ActivityView) + |> render("index.json", %{activities: activities, for: user}) end def notifications(%{assigns: %{user: user}} = conn, params) do notifications = Notification.for_user(user, params) conn - |> render(NotificationView, "notification.json", %{notifications: notifications, for: user}) + |> put_view(NotificationView) + |> render("notification.json", %{notifications: notifications, for: user}) end def notifications_read(%{assigns: %{user: user}} = conn, %{"latest_id" => latest_id} = params) do @@ -153,7 +168,8 @@ defmodule Pleroma.Web.TwitterAPI.Controller do notifications = Notification.for_user(user, params) conn - |> render(NotificationView, "notification.json", %{notifications: notifications, for: user}) + |> put_view(NotificationView) + |> render("notification.json", %{notifications: notifications, for: user}) end def notifications_read(%{assigns: %{user: _user}} = conn, _) do @@ -163,7 +179,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def follow(%{assigns: %{user: user}} = conn, params) do case TwitterAPI.follow(user, params) do {:ok, user, followed, _activity} -> - render(conn, UserView, "show.json", %{user: followed, for: user}) + conn + |> put_view(UserView) + |> render("show.json", %{user: followed, for: user}) {:error, msg} -> forbidden_json_reply(conn, msg) @@ -173,7 +191,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def block(%{assigns: %{user: user}} = conn, params) do case TwitterAPI.block(user, params) do {:ok, user, blocked} -> - render(conn, UserView, "show.json", %{user: blocked, for: user}) + conn + |> put_view(UserView) + |> render("show.json", %{user: blocked, for: user}) {:error, msg} -> forbidden_json_reply(conn, msg) @@ -183,7 +203,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def unblock(%{assigns: %{user: user}} = conn, params) do case TwitterAPI.unblock(user, params) do {:ok, user, blocked} -> - render(conn, UserView, "show.json", %{user: blocked, for: user}) + conn + |> put_view(UserView) + |> render("show.json", %{user: blocked, for: user}) {:error, msg} -> forbidden_json_reply(conn, msg) @@ -192,14 +214,18 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def delete_post(%{assigns: %{user: user}} = conn, %{"id" => id}) do with {:ok, activity} <- TwitterAPI.delete(user, id) do - render(conn, ActivityView, "activity.json", %{activity: activity, for: user}) + conn + |> put_view(ActivityView) + |> render("activity.json", %{activity: activity, for: user}) end end def unfollow(%{assigns: %{user: user}} = conn, params) do case TwitterAPI.unfollow(user, params) do {:ok, user, unfollowed} -> - render(conn, UserView, "show.json", %{user: unfollowed, for: user}) + conn + |> put_view(UserView) + |> render("show.json", %{user: unfollowed, for: user}) {:error, msg} -> forbidden_json_reply(conn, msg) @@ -209,7 +235,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def fetch_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do with %Activity{} = activity <- Repo.get(Activity, id), true <- ActivityPub.visible_for_user?(activity, user) do - render(conn, ActivityView, "activity.json", %{activity: activity, for: user}) + conn + |> put_view(ActivityView) + |> render("activity.json", %{activity: activity, for: user}) end end @@ -223,7 +251,8 @@ defmodule Pleroma.Web.TwitterAPI.Controller do "user" => user }) do conn - |> render(ActivityView, "index.json", %{activities: activities, for: user}) + |> put_view(ActivityView) + |> render("index.json", %{activities: activities, for: user}) end end @@ -290,34 +319,44 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def favorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, {:ok, activity} <- TwitterAPI.fav(user, id) do - render(conn, ActivityView, "activity.json", %{activity: activity, for: user}) + conn + |> put_view(ActivityView) + |> render("activity.json", %{activity: activity, for: user}) end end def unfavorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, {:ok, activity} <- TwitterAPI.unfav(user, id) do - render(conn, ActivityView, "activity.json", %{activity: activity, for: user}) + conn + |> put_view(ActivityView) + |> render("activity.json", %{activity: activity, for: user}) end end def retweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, {:ok, activity} <- TwitterAPI.repeat(user, id) do - render(conn, ActivityView, "activity.json", %{activity: activity, for: user}) + conn + |> put_view(ActivityView) + |> render("activity.json", %{activity: activity, for: user}) end end def unretweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, {:ok, activity} <- TwitterAPI.unrepeat(user, id) do - render(conn, ActivityView, "activity.json", %{activity: activity, for: user}) + conn + |> put_view(ActivityView) + |> render("activity.json", %{activity: activity, for: user}) end end def register(conn, params) do with {:ok, user} <- TwitterAPI.register_user(params) do - render(conn, UserView, "show.json", %{user: user}) + conn + |> put_view(UserView) + |> render("show.json", %{user: user}) else {:error, errors} -> conn @@ -339,7 +378,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do {:ok, user} = User.update_and_set_cache(change) CommonAPI.update(user) - render(conn, UserView, "show.json", %{user: user, for: user}) + conn + |> put_view(UserView) + |> render("show.json", %{user: user, for: user}) end def update_banner(%{assigns: %{user: user}} = conn, params) do @@ -394,7 +435,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do true -> followers end - render(conn, UserView, "index.json", %{users: followers, for: conn.assigns[:user]}) + conn + |> put_view(UserView) + |> render("index.json", %{users: followers, for: conn.assigns[:user]}) else _e -> bad_request_reply(conn, "Can't get followers") end @@ -410,7 +453,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do true -> friends end - render(conn, UserView, "index.json", %{users: friends, for: conn.assigns[:user]}) + conn + |> put_view(UserView) + |> render("index.json", %{users: friends, for: conn.assigns[:user]}) else _e -> bad_request_reply(conn, "Can't get friends") end @@ -419,7 +464,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def friend_requests(conn, params) do with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params), {:ok, friend_requests} <- User.get_follow_requests(user) do - render(conn, UserView, "index.json", %{users: friend_requests, for: conn.assigns[:user]}) + conn + |> put_view(UserView) + |> render("index.json", %{users: friend_requests, for: conn.assigns[:user]}) else _e -> bad_request_reply(conn, "Can't get friend requests") end @@ -439,7 +486,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do object: follow_activity.data["id"], type: "Accept" }) do - render(conn, UserView, "show.json", %{user: follower, for: followed}) + conn + |> put_view(UserView) + |> render("show.json", %{user: follower, for: followed}) else e -> bad_request_reply(conn, "Can't approve user: #{inspect(e)}") end @@ -458,7 +507,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do object: follow_activity.data["id"], type: "Reject" }) do - render(conn, UserView, "show.json", %{user: follower, for: followed}) + conn + |> put_view(UserView) + |> render("show.json", %{user: follower, for: followed}) else e -> bad_request_reply(conn, "Can't deny user: #{inspect(e)}") end @@ -522,7 +573,10 @@ defmodule Pleroma.Web.TwitterAPI.Controller do changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng), {:ok, user} <- User.update_and_set_cache(changeset) do CommonAPI.update(user) - render(conn, UserView, "user.json", %{user: user, for: user}) + + conn + |> put_view(UserView) + |> render("user.json", %{user: user, for: user}) else error -> Logger.debug("Can't update user: #{inspect(error)}") @@ -534,14 +588,16 @@ defmodule Pleroma.Web.TwitterAPI.Controller do activities = TwitterAPI.search(user, params) conn - |> render(ActivityView, "index.json", %{activities: activities, for: user}) + |> put_view(ActivityView) + |> render("index.json", %{activities: activities, for: user}) end def search_user(%{assigns: %{user: user}} = conn, %{"query" => query}) do users = User.search(query, true) conn - |> render(UserView, "index.json", %{users: users, for: user}) + |> put_view(UserView) + |> render("index.json", %{users: users, for: user}) end defp bad_request_reply(conn, error_message) do -- cgit v1.2.3 From 22d483d4f74ff404fd6ae0cd88d2e5bcc7cceaf6 Mon Sep 17 00:00:00 2001 From: link0ff Date: Sun, 16 Dec 2018 18:25:31 +0200 Subject: Use bindings dbuser and dbname in sample_psql.eex --- lib/mix/tasks/pleroma/sample_psql.eex | 6 +++--- lib/mix/tasks/pleroma/user.ex | 18 ++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/sample_psql.eex b/lib/mix/tasks/pleroma/sample_psql.eex index c89b34ef2..f0ac05e57 100644 --- a/lib/mix/tasks/pleroma/sample_psql.eex +++ b/lib/mix/tasks/pleroma/sample_psql.eex @@ -1,6 +1,6 @@ -CREATE USER pleroma WITH ENCRYPTED PASSWORD '<%= dbpass %>'; -CREATE DATABASE pleroma_dev OWNER pleroma; -\c pleroma_dev; +CREATE USER <%= dbuser %> WITH ENCRYPTED PASSWORD '<%= dbpass %>'; +CREATE DATABASE <%= dbname %> OWNER <%= dbuser %>; +\c <%= dbname %>; --Extensions made by ecto.migrate that need superuser access CREATE EXTENSION IF NOT EXISTS citext; CREATE EXTENSION IF NOT EXISTS pg_trgm; diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index fe6e6935f..3d30e3a81 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -94,16 +94,14 @@ defmodule Mix.Tasks.Pleroma.User do unless not proceed? do Common.start_pleroma() - params = - %{ - nickname: nickname, - email: email, - password: password, - password_confirmation: password, - name: name, - bio: bio - } - |> IO.inspect() + params = %{ + nickname: nickname, + email: email, + password: password, + password_confirmation: password, + name: name, + bio: bio + } user = User.register_changeset(%User{}, params) Repo.insert!(user) -- cgit v1.2.3 From 5dcb7aeceacc61beb99466c086ea26b5ae8d947a Mon Sep 17 00:00:00 2001 From: href Date: Sun, 16 Dec 2018 17:49:42 +0100 Subject: More put_view. --- lib/pleroma/plugs/federating_plug.ex | 3 +- .../web/mastodon_api/mastodon_api_controller.ex | 127 +++++++++++++++------ 2 files changed, 95 insertions(+), 35 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/plugs/federating_plug.ex b/lib/pleroma/plugs/federating_plug.ex index f0442ca15..b5326d97b 100644 --- a/lib/pleroma/plugs/federating_plug.ex +++ b/lib/pleroma/plugs/federating_plug.ex @@ -11,7 +11,8 @@ defmodule Pleroma.Web.FederatingPlug do else conn |> put_status(404) - |> Phoenix.Controller.render(Pleroma.Web.ErrorView, "404.json") + |> Phoenix.Controller.put_view(Pleroma.Web.ErrorView) + |> Phoenix.Controller.render("404.json") |> halt() end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 726807f0a..665b75437 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -226,7 +226,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do conn |> add_link_headers(:home_timeline, activities) - |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) + |> put_view(StatusView) + |> render("index.json", %{activities: activities, for: user, as: :activity}) end def public_timeline(%{assigns: %{user: user}} = conn, params) do @@ -244,7 +245,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do conn |> add_link_headers(:public_timeline, activities, false, %{"local" => local_only}) - |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) + |> put_view(StatusView) + |> render("index.json", %{activities: activities, for: user, as: :activity}) end def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do @@ -259,7 +261,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do conn |> add_link_headers(:user_statuses, activities, params["id"]) - |> render(StatusView, "index.json", %{ + |> put_view(StatusView) + |> render("index.json", %{ activities: activities, for: reading_user, as: :activity @@ -278,13 +281,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do conn |> add_link_headers(:dm_timeline, activities) - |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) + |> put_view(StatusView) + |> render("index.json", %{activities: activities, for: user, as: :activity}) end def get_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do with %Activity{} = activity <- Repo.get(Activity, id), true <- ActivityPub.visible_for_user?(activity, user) do - try_render(conn, StatusView, "status.json", %{activity: activity, for: user}) + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user}) end end @@ -347,7 +353,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do {:ok, activity} = Cachex.fetch!(:idempotency_cache, idempotency_key, fn _ -> CommonAPI.post(user, params) end) - try_render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity}) + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) end def delete_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do @@ -363,28 +371,36 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def reblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do with {:ok, announce, _activity} <- CommonAPI.repeat(ap_id_or_id, user) do - try_render(conn, StatusView, "status.json", %{activity: announce, for: user, as: :activity}) + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: announce, for: user, as: :activity}) end end def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do with {:ok, _unannounce, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do - try_render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity}) + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) end end def fav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do with {:ok, _fav, %{data: %{"id" => id}}} <- CommonAPI.favorite(ap_id_or_id, user), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do - try_render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity}) + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) end end def unfav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do with {:ok, _, _, %{data: %{"id" => id}}} <- CommonAPI.unfavorite(ap_id_or_id, user), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do - try_render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity}) + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) end end @@ -433,7 +449,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do id = List.wrap(id) q = from(u in User, where: u.id in ^id) targets = Repo.all(q) - render(conn, AccountView, "relationships.json", %{user: user, targets: targets}) + + conn + |> put_view(AccountView) + |> render("relationships.json", %{user: user, targets: targets}) end # Instead of returning a 400 when no "id" params is present, Mastodon returns an empty array. @@ -452,7 +471,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> Repo.update() attachment_data = Map.put(new_data, "id", object.id) - render(conn, StatusView, "attachment.json", %{attachment: attachment_data}) + + conn + |> put_view(StatusView) + |> render("attachment.json", %{attachment: attachment_data}) end end @@ -463,7 +485,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do description: Map.get(data, "description") ) do attachment_data = Map.put(object.data, "id", object.id) - render(conn, StatusView, "attachment.json", %{attachment: attachment_data}) + + conn + |> put_view(StatusView) + |> render("attachment.json", %{attachment: attachment_data}) end end @@ -471,7 +496,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do with %Activity{data: %{"object" => %{"likes" => likes}}} <- Repo.get(Activity, id) do q = from(u in User, where: u.ap_id in ^likes) users = Repo.all(q) - render(conn, AccountView, "accounts.json", %{users: users, as: :user}) + + conn + |> put_view(AccountView) + |> render(AccountView, "accounts.json", %{users: users, as: :user}) else _ -> json(conn, []) end @@ -481,7 +509,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do with %Activity{data: %{"object" => %{"announcements" => announces}}} <- Repo.get(Activity, id) do q = from(u in User, where: u.ap_id in ^announces) users = Repo.all(q) - render(conn, AccountView, "accounts.json", %{users: users, as: :user}) + + conn + |> put_view(AccountView) + |> render("accounts.json", %{users: users, as: :user}) else _ -> json(conn, []) end @@ -503,7 +534,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do conn |> add_link_headers(:hashtag_timeline, activities, params["tag"], %{"local" => local_only}) - |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) + |> put_view(StatusView) + |> render("index.json", %{activities: activities, for: user, as: :activity}) end def followers(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do @@ -516,7 +548,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do true -> followers end - render(conn, AccountView, "accounts.json", %{users: followers, as: :user}) + conn + |> put_view(AccountView) + |> render("accounts.json", %{users: followers, as: :user}) end end @@ -530,13 +564,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do true -> followers end - render(conn, AccountView, "accounts.json", %{users: followers, as: :user}) + conn + |> put_view(AccountView) + |> render("accounts.json", %{users: followers, as: :user}) end end def follow_requests(%{assigns: %{user: followed}} = conn, _params) do with {:ok, follow_requests} <- User.get_follow_requests(followed) do - render(conn, AccountView, "accounts.json", %{users: follow_requests, as: :user}) + conn + |> put_view(AccountView) + |> render("accounts.json", %{users: follow_requests, as: :user}) end end @@ -552,7 +590,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do object: follow_activity.data["id"], type: "Accept" }) do - render(conn, AccountView, "relationship.json", %{user: followed, target: follower}) + conn + |> put_view(AccountView) + |> render("relationship.json", %{user: followed, target: follower}) else {:error, message} -> conn @@ -572,7 +612,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do object: follow_activity.data["id"], type: "Reject" }) do - render(conn, AccountView, "relationship.json", %{user: followed, target: follower}) + conn + |> put_view(AccountView) + |> render("relationship.json", %{user: followed, target: follower}) else {:error, message} -> conn @@ -591,7 +633,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do follower, followed ) do - render(conn, AccountView, "relationship.json", %{user: follower, target: followed}) + conn + |> put_view(AccountView) + |> render("relationship.json", %{user: follower, target: followed}) else {:error, message} -> conn @@ -604,7 +648,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do with %User{} = followed <- Repo.get_by(User, nickname: uri), {:ok, follower} <- User.maybe_direct_follow(follower, followed), {:ok, _activity} <- ActivityPub.follow(follower, followed) do - render(conn, AccountView, "account.json", %{user: followed, for: follower}) + conn + |> put_view(AccountView) + |> render("account.json", %{user: followed, for: follower}) else {:error, message} -> conn @@ -617,7 +663,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do with %User{} = followed <- Repo.get(User, id), {:ok, _activity} <- ActivityPub.unfollow(follower, followed), {:ok, follower, _} <- User.unfollow(follower, followed) do - render(conn, AccountView, "relationship.json", %{user: follower, target: followed}) + conn + |> put_view(AccountView) + |> render("relationship.json", %{user: follower, target: followed}) end end @@ -625,7 +673,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do with %User{} = blocked <- Repo.get(User, id), {:ok, blocker} <- User.block(blocker, blocked), {:ok, _activity} <- ActivityPub.block(blocker, blocked) do - render(conn, AccountView, "relationship.json", %{user: blocker, target: blocked}) + conn + |> put_view(AccountView) + |> render("relationship.json", %{user: blocker, target: blocked}) else {:error, message} -> conn @@ -638,7 +688,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do with %User{} = blocked <- Repo.get(User, id), {:ok, blocker} <- User.unblock(blocker, blocked), {:ok, _activity} <- ActivityPub.unblock(blocker, blocked) do - render(conn, AccountView, "relationship.json", %{user: blocker, target: blocked}) + conn + |> put_view(AccountView) + |> render("relationship.json", %{user: blocker, target: blocked}) else {:error, message} -> conn @@ -763,7 +815,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> Enum.reverse() conn - |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) + |> put_view(StatusView) + |> render("index.json", %{activities: activities, for: user, as: :activity}) end def get_lists(%{assigns: %{user: user}} = conn, opts) do @@ -831,7 +884,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def list_accounts(%{assigns: %{user: user}} = conn, %{"id" => id}) do with %Pleroma.List{} = list <- Pleroma.List.get(id, user), {:ok, users} = Pleroma.List.get_following(list) do - render(conn, AccountView, "accounts.json", %{users: users, as: :user}) + conn + |> put_view(AccountView) + |> render("accounts.json", %{users: users, as: :user}) end end @@ -864,7 +919,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> Enum.reverse() conn - |> render(StatusView, "index.json", %{activities: activities, for: user, as: :activity}) + |> put_view(StatusView) + |> render("index.json", %{activities: activities, for: user, as: :activity}) else _e -> conn @@ -968,7 +1024,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do conn |> put_layout(false) - |> render(MastodonView, "index.html", %{initial_state: initial_state}) + |> put_view(MastodonView) + |> render("index.html", %{initial_state: initial_state}) else conn |> redirect(to: "/web/login") @@ -1041,7 +1098,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do Logger.debug("Unimplemented, returning unmodified relationship") with %User{} = target <- Repo.get(User, id) do - render(conn, AccountView, "relationship.json", %{user: user, target: target}) + conn + |> put_view(AccountView) + |> render("relationship.json", %{user: user, target: target}) end end @@ -1242,9 +1301,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end - def try_render(conn, renderer, target, params) + def try_render(conn, target, params) when is_binary(target) do - res = render(conn, renderer, target, params) + res = render(conn, target, params) if res == nil do conn @@ -1255,7 +1314,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end - def try_render(conn, _, _, _) do + def try_render(conn, _, _) do conn |> put_status(501) |> json(%{error: "Can't display this activity"}) -- cgit v1.2.3 From 6062885df6178c09544b6a0b5b731a554786397e Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sun, 16 Dec 2018 22:04:43 +0300 Subject: Add a configurable auto-cleanup for captchas --- lib/pleroma/captcha/captcha.ex | 15 ++++++++++++++- lib/pleroma/captcha/captcha_service.ex | 5 +++++ lib/pleroma/captcha/kocaptcha.ex | 11 ++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index df33406ee..2dcbc4717 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -38,7 +38,13 @@ defmodule Pleroma.Captcha do if !enabled do {:reply, %{type: :none}, state} else - {:reply, method().new(), state} + new_captcha = method().new() + + minutes_retained = Pleroma.Config.get!([__MODULE__, :minutes_retained]) + # Wait several minutes and if the captcha is still there, delete it + Process.send_after(self(), {:cleanup, new_captcha.token}, 1000 * 60 * minutes_retained) + + {:reply, new_captcha, state} end end @@ -47,5 +53,12 @@ defmodule Pleroma.Captcha do {:reply, method().validate(token, captcha), state} end + @doc false + def handle_info({:cleanup, token}, state) do + method().cleanup(token) + + {:noreply, state} + end + defp method, do: Pleroma.Config.get!([__MODULE__, :method]) end diff --git a/lib/pleroma/captcha/captcha_service.ex b/lib/pleroma/captcha/captcha_service.ex index 907a73ad0..fe5a6bf66 100644 --- a/lib/pleroma/captcha/captcha_service.ex +++ b/lib/pleroma/captcha/captcha_service.ex @@ -20,4 +20,9 @@ defmodule Pleroma.Captcha.Service do `true` if captcha is valid, `false` if not """ @callback validate(token :: String.t(), captcha :: String.t()) :: boolean + + @doc """ + This function is called periodically to clean up old captchas + """ + @callback cleanup(token :: String.t()) :: :ok end diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex index 4ecd1a81f..9891d4031 100644 --- a/lib/pleroma/captcha/kocaptcha.ex +++ b/lib/pleroma/captcha/kocaptcha.ex @@ -29,11 +29,20 @@ defmodule Pleroma.Captcha.Kocaptcha do [{^token, saved_md5}] <- :ets.lookup(@ets, token), true <- :crypto.hash(:md5, captcha) |> Base.encode16() == String.upcase(saved_md5) do # Clear the saved value - :ets.delete(@ets, token) + cleanup(token) true else _ -> false end end + + @impl Service + def cleanup(token) do + # Only delete the entry if it exists in the table, because ets:delete raises an exception if it does not + case :ets.lookup(@ets, token) do + [{^token, _}] -> :ets.delete(@ets, token) + _ -> true + end + end end -- cgit v1.2.3 From 3a31fdaf0668b4fb4d05c3087674c2b32b6afbe9 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sun, 16 Dec 2018 22:40:44 +0300 Subject: Change minutes_retained config to seconds_retained --- lib/pleroma/captcha/captcha.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index 2dcbc4717..26477a214 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -40,9 +40,9 @@ defmodule Pleroma.Captcha do else new_captcha = method().new() - minutes_retained = Pleroma.Config.get!([__MODULE__, :minutes_retained]) + seconds_retained = Pleroma.Config.get!([__MODULE__, :seconds_retained]) # Wait several minutes and if the captcha is still there, delete it - Process.send_after(self(), {:cleanup, new_captcha.token}, 1000 * 60 * minutes_retained) + Process.send_after(self(), {:cleanup, new_captcha.token}, 1000 * seconds_retained) {:reply, new_captcha, state} end -- cgit v1.2.3 From ef6829382aa32c03cf8536422537a9c219bd0035 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sun, 16 Dec 2018 23:41:11 +0300 Subject: Clean captchas up periodically, not schedule it after theyre created --- lib/pleroma/captcha/captcha.ex | 20 +++++++++++--------- lib/pleroma/captcha/captcha_service.ex | 2 +- lib/pleroma/captcha/kocaptcha.ex | 26 +++++++++++++++++--------- 3 files changed, 29 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index 26477a214..5630f6b57 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -14,6 +14,10 @@ defmodule Pleroma.Captcha do ets_name = Module.concat(method(), Ets) ^ets_name = :ets.new(Module.concat(method(), Ets), @ets_options) + # Clean up old captchas every few minutes + seconds_retained = Pleroma.Config.get!([__MODULE__, :seconds_retained]) + Process.send_after(self(), :cleanup, 1000 * seconds_retained) + {:ok, nil} end @@ -38,13 +42,7 @@ defmodule Pleroma.Captcha do if !enabled do {:reply, %{type: :none}, state} else - new_captcha = method().new() - - seconds_retained = Pleroma.Config.get!([__MODULE__, :seconds_retained]) - # Wait several minutes and if the captcha is still there, delete it - Process.send_after(self(), {:cleanup, new_captcha.token}, 1000 * seconds_retained) - - {:reply, new_captcha, state} + {:reply, method().new(), state} end end @@ -54,8 +52,12 @@ defmodule Pleroma.Captcha do end @doc false - def handle_info({:cleanup, token}, state) do - method().cleanup(token) + def handle_info(:cleanup, state) do + :ok = method().cleanup() + + seconds_retained = Pleroma.Config.get!([__MODULE__, :seconds_retained]) + # Schedule the next clenup + Process.send_after(self(), :cleanup, 1000 * seconds_retained) {:noreply, state} end diff --git a/lib/pleroma/captcha/captcha_service.ex b/lib/pleroma/captcha/captcha_service.ex index fe5a6bf66..8d0b76f86 100644 --- a/lib/pleroma/captcha/captcha_service.ex +++ b/lib/pleroma/captcha/captcha_service.ex @@ -24,5 +24,5 @@ defmodule Pleroma.Captcha.Service do @doc """ This function is called periodically to clean up old captchas """ - @callback cleanup(token :: String.t()) :: :ok + @callback cleanup() :: :ok end diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex index 9891d4031..7f9637ad0 100644 --- a/lib/pleroma/captcha/kocaptcha.ex +++ b/lib/pleroma/captcha/kocaptcha.ex @@ -1,4 +1,6 @@ defmodule Pleroma.Captcha.Kocaptcha do + alias Calendar.DateTime + alias Pleroma.Captcha.Service @behaviour Service @@ -17,7 +19,7 @@ defmodule Pleroma.Captcha.Kocaptcha do token = json_resp["token"] - true = :ets.insert(@ets, {token, json_resp["md5"]}) + true = :ets.insert(@ets, {token, json_resp["md5"], DateTime.now_utc()}) %{type: :kocaptcha, token: token, url: endpoint <> json_resp["url"]} end @@ -26,10 +28,10 @@ defmodule Pleroma.Captcha.Kocaptcha do @impl Service def validate(token, captcha) do with false <- is_nil(captcha), - [{^token, saved_md5}] <- :ets.lookup(@ets, token), + [{^token, saved_md5, _}] <- :ets.lookup(@ets, token), true <- :crypto.hash(:md5, captcha) |> Base.encode16() == String.upcase(saved_md5) do # Clear the saved value - cleanup(token) + :ets.delete(@ets, token) true else @@ -38,11 +40,17 @@ defmodule Pleroma.Captcha.Kocaptcha do end @impl Service - def cleanup(token) do - # Only delete the entry if it exists in the table, because ets:delete raises an exception if it does not - case :ets.lookup(@ets, token) do - [{^token, _}] -> :ets.delete(@ets, token) - _ -> true - end + def cleanup() do + seconds_retained = Pleroma.Config.get!([Pleroma.Captcha, :seconds_retained]) + + # Go through captchas and remove expired ones + :ets.tab2list(@ets) + |> Enum.each(fn {token, _, time_inserted} -> + # time created + expiration time = time when the captcha should be removed + remove_time = DateTime.add!(time_inserted, seconds_retained) + if DateTime.after?(DateTime.now_utc(), remove_time), do: :ets.delete(@ets, token) + end) + + :ok end end -- cgit v1.2.3 From cc878804880137740afc37a0c5d3f7e4d64d014a Mon Sep 17 00:00:00 2001 From: raeno Date: Mon, 17 Dec 2018 16:02:26 +0100 Subject: Support both OAuth token record and token string in UserView --- lib/pleroma/web/twitter_api/views/user_view.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index b3459af9a..8a88d72b1 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -86,7 +86,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do } if assigns[:token] do - Map.put(data, "token", assigns[:token]) + Map.put(data, "token", token_string(assigns[:token])) else data end @@ -111,4 +111,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do defp image_url(%{"url" => [%{"href" => href} | _]}), do: href defp image_url(_), do: nil + + defp token_string(%Pleroma.Web.OAuth.Token{token: token_str}), do: token_str + defp token_string(token), do: token end -- cgit v1.2.3 From 77b5154c825e2ff5996f170c03657eaadcef4680 Mon Sep 17 00:00:00 2001 From: href Date: Mon, 17 Dec 2018 14:39:59 +0100 Subject: Cowboy handler for Mastodon WebSocket --- lib/pleroma/web/endpoint.ex | 2 - lib/pleroma/web/mastodon_api/mastodon_socket.ex | 74 ------------- lib/pleroma/web/mastodon_api/websocket_handler.ex | 120 ++++++++++++++++++++++ lib/pleroma/web/streamer.ex | 22 ++-- 4 files changed, 132 insertions(+), 86 deletions(-) delete mode 100644 lib/pleroma/web/mastodon_api/mastodon_socket.ex create mode 100644 lib/pleroma/web/mastodon_api/websocket_handler.ex (limited to 'lib') diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index aacc88195..e52667c72 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -3,8 +3,6 @@ defmodule Pleroma.Web.Endpoint do socket("/socket", Pleroma.Web.UserSocket) - socket("/api/v1", Pleroma.Web.MastodonAPI.MastodonSocket, websocket: [path: "/streaming"]) - # Serve at "/" the static files from "priv/static" directory. # # You should set gzip to true if you are running phoenix.digest diff --git a/lib/pleroma/web/mastodon_api/mastodon_socket.ex b/lib/pleroma/web/mastodon_api/mastodon_socket.ex deleted file mode 100644 index 1b75897b5..000000000 --- a/lib/pleroma/web/mastodon_api/mastodon_socket.ex +++ /dev/null @@ -1,74 +0,0 @@ -defmodule Pleroma.Web.MastodonAPI.MastodonSocket do - use Phoenix.Socket - - alias Pleroma.Web.OAuth.Token - alias Pleroma.{User, Repo} - - @spec connect(params :: map(), Phoenix.Socket.t()) :: {:ok, Phoenix.Socket.t()} | :error - def connect(%{"access_token" => token} = params, socket) do - with %Token{user_id: user_id} <- Repo.get_by(Token, token: token), - %User{} = user <- Repo.get(User, user_id), - stream - when stream in [ - "public", - "public:local", - "public:media", - "public:local:media", - "user", - "direct", - "list", - "hashtag" - ] <- params["stream"] do - topic = - case stream do - "hashtag" -> "hashtag:#{params["tag"]}" - "list" -> "list:#{params["list"]}" - _ -> stream - end - - socket = - socket - |> assign(:topic, topic) - |> assign(:user, user) - - Pleroma.Web.Streamer.add_socket(topic, socket) - {:ok, socket} - else - _e -> :error - end - end - - def connect(%{"stream" => stream} = params, socket) - when stream in ["public", "public:local", "hashtag"] do - topic = - case stream do - "hashtag" -> "hashtag:#{params["tag"]}" - _ -> stream - end - - socket = - socket - |> assign(:topic, topic) - - Pleroma.Web.Streamer.add_socket(topic, socket) - {:ok, socket} - end - - def connect(_params, _socket), do: :error - - def id(_), do: nil - - def handle(:text, message, _state) do - # | :ok - # | state - # | {:text, message} - # | {:text, message, state} - # | {:close, "Goodbye!"} - {:text, message} - end - - def handle(:closed, _, %{socket: socket}) do - topic = socket.assigns[:topic] - Pleroma.Web.Streamer.remove_socket(topic, socket) - end -end diff --git a/lib/pleroma/web/mastodon_api/websocket_handler.ex b/lib/pleroma/web/mastodon_api/websocket_handler.ex new file mode 100644 index 000000000..11e0e1696 --- /dev/null +++ b/lib/pleroma/web/mastodon_api/websocket_handler.ex @@ -0,0 +1,120 @@ +defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do + require Logger + + alias Pleroma.Web.OAuth.Token + alias Pleroma.{User, Repo} + + @behaviour :cowboy_websocket_handler + + @streams [ + "public", + "public:local", + "public:media", + "public:local:media", + "user", + "direct", + "list", + "hashtag" + ] + @anonymous_streams ["public", "public:local", "hashtag"] + + # Handled by periodic keepalive in Pleroma.Web.Streamer. + @timeout :infinity + + def init(_type, _req, _opts) do + {:upgrade, :protocol, :cowboy_websocket} + end + + def websocket_init(_type, req, _opts) do + with {qs, req} <- :cowboy_req.qs(req), + params <- :cow_qs.parse_qs(qs), + access_token <- List.keyfind(params, "access_token", 0), + {_, stream} <- List.keyfind(params, "stream", 0), + {:ok, user} <- allow_request(stream, access_token), + topic when is_binary(topic) <- expand_topic(stream, params) do + send(self(), :subscribe) + {:ok, req, %{user: user, topic: topic}, @timeout} + else + {:error, code} -> + Logger.debug("#{__MODULE__} denied connection: #{inspect(code)} - #{inspect(req)}") + {:ok, req} = :cowboy_req.reply(code, req) + {:shutdown, req} + + error -> + Logger.debug("#{__MODULE__} denied connection: #{inspect(error)} - #{inspect(req)}") + {:shutdown, req} + end + end + + # We never receive messages. + def websocket_handle(_frame, req, state) do + {:ok, req, state} + end + + def websocket_info(:subscribe, req, state) do + Logger.debug( + "#{__MODULE__} accepted websocket connection for user #{ + (state.user || %{id: "anonymous"}).id + }, topic #{state.topic}" + ) + + Pleroma.Web.Streamer.add_socket(state.topic, streamer_socket(state)) + {:ok, req, state} + end + + def websocket_info({:text, message}, req, state) do + {:reply, {:text, message}, req, state} + end + + def websocket_terminate(reason, _req, state) do + Logger.debug( + "#{__MODULE__} terminating websocket connection for user #{ + (state.user || %{id: "anonymous"}).id + }, topic #{state.topic || "?"}: #{inspect(reason)}" + ) + + Pleroma.Web.Streamer.remove_socket(state.topic, streamer_socket(state)) + :ok + end + + # Public streams without authentication. + defp allow_request(stream, nil) when stream in @anonymous_streams do + {:ok, nil} + end + + # Authenticated streams. + defp allow_request(stream, {"access_token", access_token}) when stream in @streams do + with %Token{user_id: user_id} <- Repo.get_by(Token, token: access_token), + user = %User{} <- Repo.get(User, user_id) do + {:ok, user} + else + _ -> {:error, 403} + end + end + + # Not authenticated. + defp allow_request(stream, _) when stream in @streams, do: {:error, 403} + + # No matching stream. + defp allow_request(_, _), do: {:error, 404} + + defp expand_topic("hashtag", params) do + case List.keyfind(params, "tag", 0) do + {_, tag} -> "hashtag:#{tag}" + _ -> nil + end + end + + defp expand_topic("list", params) do + case List.keyfind(params, "list", 0) do + {_, list} -> "list:#{list}" + _ -> nil + end + end + + defp expand_topic(topic, _), do: topic + + defp streamer_socket(state) do + %{transport_pid: self(), assigns: state} + end +end diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index 29c44e9d5..e1eecba4d 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -4,17 +4,9 @@ defmodule Pleroma.Web.Streamer do alias Pleroma.{User, Notification, Activity, Object, Repo} alias Pleroma.Web.ActivityPub.ActivityPub - def init(args) do - {:ok, args} - end + @keepalive_interval :timer.seconds(30) def start_link do - spawn(fn -> - # 30 seconds - Process.sleep(1000 * 30) - GenServer.cast(__MODULE__, %{action: :ping}) - end) - GenServer.start_link(__MODULE__, %{}, name: __MODULE__) end @@ -30,6 +22,16 @@ defmodule Pleroma.Web.Streamer do GenServer.cast(__MODULE__, %{action: :stream, topic: topic, item: item}) end + def init(args) do + spawn(fn -> + # 30 seconds + Process.sleep(@keepalive_interval) + GenServer.cast(__MODULE__, %{action: :ping}) + end) + + {:ok, args} + end + def handle_cast(%{action: :ping}, topics) do Map.values(topics) |> List.flatten() @@ -40,7 +42,7 @@ defmodule Pleroma.Web.Streamer do spawn(fn -> # 30 seconds - Process.sleep(1000 * 30) + Process.sleep(@keepalive_interval) GenServer.cast(__MODULE__, %{action: :ping}) end) -- cgit v1.2.3 From 35522fef0958c2843107a6c9cce546e7e0dfcd44 Mon Sep 17 00:00:00 2001 From: vaartis Date: Mon, 17 Dec 2018 17:19:28 +0300 Subject: Use :ets.match_delete to delete old captchas --- lib/pleroma/captcha/kocaptcha.ex | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex index 7f9637ad0..51900d123 100644 --- a/lib/pleroma/captcha/kocaptcha.ex +++ b/lib/pleroma/captcha/kocaptcha.ex @@ -19,7 +19,11 @@ defmodule Pleroma.Captcha.Kocaptcha do token = json_resp["token"] - true = :ets.insert(@ets, {token, json_resp["md5"], DateTime.now_utc()}) + true = + :ets.insert( + @ets, + {token, json_resp["md5"], DateTime.now_utc() |> DateTime.Format.unix()} + ) %{type: :kocaptcha, token: token, url: endpoint <> json_resp["url"]} end @@ -42,14 +46,21 @@ defmodule Pleroma.Captcha.Kocaptcha do @impl Service def cleanup() do seconds_retained = Pleroma.Config.get!([Pleroma.Captcha, :seconds_retained]) + # If the time in ETS is less than current_time - seconds_retained, then the time has + # already passed + delete_after = + DateTime.subtract!(DateTime.now_utc(), seconds_retained) |> DateTime.Format.unix() - # Go through captchas and remove expired ones - :ets.tab2list(@ets) - |> Enum.each(fn {token, _, time_inserted} -> - # time created + expiration time = time when the captcha should be removed - remove_time = DateTime.add!(time_inserted, seconds_retained) - if DateTime.after?(DateTime.now_utc(), remove_time), do: :ets.delete(@ets, token) - end) + :ets.select_delete( + @ets, + [ + { + {:_, :_, :"$1"}, + [{:<, :"$1", {:const, delete_after}}], + [true] + } + ] + ) :ok end -- cgit v1.2.3 From e4763cd459d36b2fcd22e2e4abd3a2a326a21f5f Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 17 Dec 2018 20:12:01 +0100 Subject: Fix tagging problems for existing instances. --- lib/pleroma/user.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 49928bc13..3ad1ab87a 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -838,7 +838,7 @@ defmodule Pleroma.User do do: tag(User.get_by_nickname(nickname), tags) def tag(%User{} = user, tags), - do: update_tags(user, Enum.uniq(user.tags ++ normalize_tags(tags))) + do: update_tags(user, Enum.uniq((user.tags || []) ++ normalize_tags(tags))) def untag(user_identifiers, tags) when is_list(user_identifiers) do Repo.transaction(fn -> @@ -849,7 +849,8 @@ defmodule Pleroma.User do def untag(nickname, tags) when is_binary(nickname), do: untag(User.get_by_nickname(nickname), tags) - def untag(%User{} = user, tags), do: update_tags(user, user.tags -- normalize_tags(tags)) + def untag(%User{} = user, tags), + do: update_tags(user, (user.tags || []) -- normalize_tags(tags)) defp update_tags(%User{} = user, new_tags) do {:ok, updated_user} = -- cgit v1.2.3 From 92a5133c42f62685007877eeaa26e4d61230d995 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Mon, 17 Dec 2018 22:41:36 +0300 Subject: fix text field --- lib/pleroma/web/twitter_api/views/activity_view.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 0699bf1da..91d086740 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -244,6 +244,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do |> HTML.filter_tags(User.html_filter_policy(opts[:for])) |> Formatter.emojify(object["emoji"]) + text = + content + |> String.replace(~r//, "\n") + |> HTML.strip_tags() + reply_parent = Activity.get_in_reply_to_activity(activity) reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor) @@ -253,7 +258,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do "uri" => activity.data["object"]["id"], "user" => UserView.render("show.json", %{user: user, for: opts[:for]}), "statusnet_html" => html, - "text" => HTML.strip_tags(content), + "text" => text, "is_local" => activity.local, "is_post_verb" => true, "created_at" => created_at, -- cgit v1.2.3 From b1860fe85af1d32de937f466ba65d03614952e31 Mon Sep 17 00:00:00 2001 From: href Date: Mon, 17 Dec 2018 22:50:59 +0100 Subject: Instance/Static runtime plug This allows to set-up an arbitrary directory which overrides most of the static files: index.html static/ emoji/ packs/ sounds/ images/ instance/ favicon.png. If the files are not present in the directory, the bundled ones in priv/static will be used. --- lib/pleroma/plugs/instance_static.ex | 54 +++++++++++++++++++++++++++ lib/pleroma/web/endpoint.ex | 4 ++ lib/pleroma/web/ostatus/ostatus_controller.ex | 2 +- lib/pleroma/web/router.ex | 2 +- 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 lib/pleroma/plugs/instance_static.ex (limited to 'lib') diff --git a/lib/pleroma/plugs/instance_static.ex b/lib/pleroma/plugs/instance_static.ex new file mode 100644 index 000000000..46ee77e11 --- /dev/null +++ b/lib/pleroma/plugs/instance_static.ex @@ -0,0 +1,54 @@ +defmodule Pleroma.Plugs.InstanceStatic do + @moduledoc """ + This is a shim to call `Plug.Static` but with runtime `from` configuration. + + Mountpoints are defined directly in the module to avoid calling the configuration for every request including non-static ones. + """ + @behaviour Plug + + def file_path(path) do + instance_path = + Path.join(Pleroma.Config.get([:instance, :static_dir], "instance/static/"), path) + + if File.exists?(instance_path) do + instance_path + else + Path.join(Application.app_dir(:pleroma, "priv/static/"), path) + end + end + + @only ~w(index.html static emoji packs sounds images instance favicon.png) + + def init(opts) do + opts + |> Keyword.put(:from, "__unconfigured_instance_static_plug") + |> Keyword.put(:at, "/__unconfigured_instance_static_plug") + |> Plug.Static.init() + end + + for only <- @only do + at = Plug.Router.Utils.split("/") + + def call(conn = %{request_path: "/" <> unquote(only) <> _}, opts) do + call_static( + conn, + opts, + unquote(at), + Pleroma.Config.get([:instance, :static_dir], "instance/static") + ) + end + end + + def call(conn, _) do + conn + end + + defp call_static(conn, opts, at, from) do + opts = + opts + |> Map.put(:from, from) + |> Map.put(:at, at) + + Plug.Static.call(conn, opts) + end +end diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index e52667c72..d79f61b2e 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -12,6 +12,10 @@ defmodule Pleroma.Web.Endpoint do plug(Pleroma.Plugs.UploadedMedia) + # InstanceStatic needs to be before Plug.Static to be able to override shipped-static files + # If you're adding new paths to `only:` you'll need to configure them in InstanceStatic as well + plug(Pleroma.Plugs.InstanceStatic, at: "/") + plug( Plug.Static, at: "/", diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 9dfcf0f95..6005eadb2 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -136,7 +136,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do "html" -> conn |> put_resp_content_type("text/html") - |> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html")) + |> send_file(200, Pleroma.Plugs.InstanceStatic.file_path("index.html")) _ -> represent_activity(conn, format, activity, user) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 60342cfb4..dd1985d6e 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -459,7 +459,7 @@ defmodule Fallback.RedirectController do def redirector(conn, _params) do conn |> put_resp_content_type("text/html") - |> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html")) + |> send_file(200, Pleroma.Plugs.InstanceStatic.file_path("index.html")) end def registration_page(conn, params) do -- cgit v1.2.3 From a05cb10a95901ff0daacfc17a7709f3a277f1cd4 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 14 Dec 2018 16:38:56 +0300 Subject: [#114] Email confirmation route, action, node setting, User.Info fields. --- lib/pleroma/user.ex | 4 ++++ lib/pleroma/user/info.ex | 6 ++++++ lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 1 + lib/pleroma/web/router.ex | 1 + lib/pleroma/web/twitter_api/twitter_api_controller.ex | 13 +++++++++++++ 5 files changed, 25 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 3ad1ab87a..ee0a0dfb9 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -364,6 +364,10 @@ defmodule Pleroma.User do end end + def get_by_confirmation_token(token) do + Repo.one(from(u in User, where: fragment("? ->> 'confirmation_token' = ?", u.info, ^token))) + end + def get_followers_query(%User{id: id, follower_address: follower_address}) do from( u in User, diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index a3785447c..f75984038 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -9,6 +9,8 @@ defmodule Pleroma.User.Info do field(:note_count, :integer, default: 0) field(:follower_count, :integer, default: 0) field(:locked, :boolean, default: false) + field(:confirmation_pending, :boolean, default: false) + field(:confirmation_token, :string, default: nil) field(:default_scope, :string, default: "public") field(:blocks, {:array, :string}, default: []) field(:domain_blocks, {:array, :string}, default: []) @@ -141,6 +143,10 @@ defmodule Pleroma.User.Info do ]) end + def confirmation_update(info, params) do + cast(info, params, [:confirmation_pending, :confirmation_token]) + end + def mastodon_profile_update(info, params) do info |> cast(params, [ diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 44c11f40a..70921605d 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -132,6 +132,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do banner: Keyword.get(instance, :banner_upload_limit), background: Keyword.get(instance, :background_upload_limit) }, + accountActivationRequired: Keyword.get(instance, :account_activation_required, false), invitesEnabled: Keyword.get(instance, :invites_enabled, false), features: features } diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index dd1985d6e..b2fbc088d 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -281,6 +281,7 @@ defmodule Pleroma.Web.Router do post("/account/register", TwitterAPI.Controller, :register) post("/account/password_reset", TwitterAPI.Controller, :password_reset) + get("/account/confirm_email/:token", TwitterAPI.Controller, :confirm_email) get("/search", TwitterAPI.Controller, :search) get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 327620302..2680be25f 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -372,6 +372,19 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def confirm_email(conn, %{"token" => token}) do + with %User{} = user <- User.get_by_confirmation_token(token), + true <- user.local, + new_info_fields <- %{confirmation_pending: false, confirmation_token: nil}, + info_change <- User.Info.confirmation_update(user.info, new_info_fields), + changeset <- Changeset.change(user) |> Changeset.put_embed(:info, info_change), + {:ok, _} <- User.update_and_set_cache(changeset) do + conn + |> put_flash(:info, "Email confirmed. Please sign in.") + |> redirect(to: "/") + end + end + def update_avatar(%{assigns: %{user: user}} = conn, params) do {:ok, object} = ActivityPub.upload(params, type: :avatar) change = Changeset.change(user, %{avatar: object.data}) -- cgit v1.2.3 From 1de0aa2f1025d4a860a11e658ce5fed26fe1c4ad Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Mon, 17 Dec 2018 17:28:58 +0300 Subject: [#114] Account confirmation email, registration as unconfirmed (config-based), auth prevention for unconfirmed. --- lib/pleroma/emails/user_email.ex | 24 +++++++++++++++++++++- lib/pleroma/user.ex | 2 ++ lib/pleroma/user/info.ex | 14 +++++++++++++ lib/pleroma/web/oauth/oauth_controller.ex | 2 ++ lib/pleroma/web/router.ex | 3 ++- .../web/twitter_api/controllers/util_controller.ex | 2 ++ lib/pleroma/web/twitter_api/twitter_api.ex | 22 ++++++++++++++++++-- .../web/twitter_api/twitter_api_controller.ex | 4 ++-- 8 files changed, 67 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index 7e3e9b020..856816386 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -15,6 +15,7 @@ defmodule Pleroma.UserEmail do defp recipient(email, nil), do: email defp recipient(email, name), do: {name, email} + defp recipient(%Pleroma.User{} = user), do: recipient(user.email, user.name) def password_reset_email(user, password_reset_token) when is_binary(password_reset_token) do password_reset_url = @@ -32,7 +33,7 @@ defmodule Pleroma.UserEmail do """ new() - |> to(recipient(user.email, user.name)) + |> to(recipient(user)) |> from(sender()) |> subject("Password reset") |> html_body(html_body) @@ -63,4 +64,25 @@ defmodule Pleroma.UserEmail do |> subject("Invitation to #{instance_name()}") |> html_body(html_body) end + + def account_confirmation_email(user) do + confirmation_url = + Router.Helpers.confirm_email_url( + Endpoint, + :confirm_email, + to_string(user.info.confirmation_token) + ) + + html_body = """ +

Welcome to #{instance_name()}!

+

Email confirmation is required to activate the account.

+

Click the following link to proceed: activate your account.

+ """ + + new() + |> to(recipient(user)) + |> from(sender()) + |> subject("#{instance_name()} account confirmation") + |> html_body(html_body) + end end diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index ee0a0dfb9..a38ead81a 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -38,6 +38,8 @@ defmodule Pleroma.User do timestamps() end + def auth_active?(user), do: user.info && !user.info.confirmation_pending + def avatar_url(user) do case user.avatar do %{"url" => [%{"href" => href} | _]} -> href diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index f75984038..9ce9129cd 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -143,6 +143,20 @@ defmodule Pleroma.User.Info do ]) end + def confirmation_update(info, :confirmed) do + confirmation_update(info, %{ + confirmation_pending: false, + confirmation_token: nil + }) + end + + def confirmation_update(info, :unconfirmed) do + confirmation_update(info, %{ + confirmation_pending: true, + confirmation_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64() + }) + end + def confirmation_update(info, params) do cast(info, params, [:confirmation_pending, :confirmation_token]) end diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 20c2e799b..10158f07e 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -31,6 +31,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do }) do with %User{} = user <- User.get_by_nickname_or_email(name), true <- Pbkdf2.checkpw(password, user.password_hash), + true <- User.auth_active?(user), %App{} = app <- Repo.get_by(App, client_id: client_id), {:ok, auth} <- Authorization.create_authorization(app, user) do # Special case: Local MastodonFE. @@ -101,6 +102,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do with %App{} = app <- get_app_from_request(conn, params), %User{} = user <- User.get_by_nickname_or_email(name), true <- Pbkdf2.checkpw(password, user.password_hash), + true <- User.auth_active?(user), {:ok, auth} <- Authorization.create_authorization(app, user), {:ok, token} <- Token.exchange_token(app, auth) do response = %{ diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index b2fbc088d..0e4589116 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -281,7 +281,8 @@ defmodule Pleroma.Web.Router do post("/account/register", TwitterAPI.Controller, :register) post("/account/password_reset", TwitterAPI.Controller, :password_reset) - get("/account/confirm_email/:token", TwitterAPI.Controller, :confirm_email) + + get("/account/confirm_email/:token", TwitterAPI.Controller, :confirm_email, as: :confirm_email) get("/search", TwitterAPI.Controller, :search) get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 38653f0b8..3baeba619 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -174,6 +174,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do closed: if(Keyword.get(instance, :registrations_open), do: "0", else: "1"), private: if(Keyword.get(instance, :public, true), do: "0", else: "1"), vapidPublicKey: vapid_public_key, + accountActivationRequired: + if(Keyword.get(instance, :account_activation_required, false), do: "1", else: "0"), invitesEnabled: if(Keyword.get(instance, :invites_enabled, false), do: "1", else: "0") } diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 90b8345c5..b77761aa4 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -1,8 +1,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do alias Pleroma.{UserInviteToken, User, Activity, Repo, Object} + alias Pleroma.{UserEmail, Mailer} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.CommonAPI + import Ecto.Query def create_status(%User{} = user, %{"status" => _} = data) do @@ -165,6 +167,22 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do with {:ok, user} <- Repo.insert(changeset) do !registrations_open && UserInviteToken.mark_as_used(token.token) + + if Pleroma.Config.get([:instance, :account_activation_required]) do + info_change = User.Info.confirmation_update(user.info, :unconfirmed) + + {:ok, unconfirmed_user} = + user + |> Ecto.Changeset.change() + |> Ecto.Changeset.put_embed(:info, info_change) + |> Repo.update() + + {:ok, _} = + unconfirmed_user + |> UserEmail.account_confirmation_email() + |> Mailer.deliver() + end + {:ok, user} else {:error, changeset} -> @@ -189,8 +207,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do %User{local: true} = user <- User.get_by_nickname_or_email(nickname_or_email), {:ok, token_record} <- Pleroma.PasswordResetToken.create_token(user) do user - |> Pleroma.UserEmail.password_reset_email(token_record.token) - |> Pleroma.Mailer.deliver() + |> UserEmail.password_reset_email(token_record.token) + |> Mailer.deliver() else false -> {:error, "bad user identifier"} diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 2680be25f..e8a3150e9 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -13,6 +13,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do require Logger plug(:only_if_public_instance when action in [:public_timeline, :public_and_external_timeline]) + plug(:fetch_flash when action in [:confirm_email]) action_fallback(:errors) def verify_credentials(%{assigns: %{user: user}} = conn, _params) do @@ -375,8 +376,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def confirm_email(conn, %{"token" => token}) do with %User{} = user <- User.get_by_confirmation_token(token), true <- user.local, - new_info_fields <- %{confirmation_pending: false, confirmation_token: nil}, - info_change <- User.Info.confirmation_update(user.info, new_info_fields), + info_change <- User.Info.confirmation_update(user.info, :confirmed), changeset <- Changeset.change(user) |> Changeset.put_embed(:info, info_change), {:ok, _} <- User.update_and_set_cache(changeset) do conn -- cgit v1.2.3 From b86057cc7f45c79767ff5b83730c2c15ad6bb3bd Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 18 Dec 2018 13:13:57 +0300 Subject: [#114] Refactored User.register_changeset to init confirmation data. Introduced User.register/1 to encapsulate User record creation and post-registration actions. --- lib/pleroma/user.ex | 25 ++++++++++++-- lib/pleroma/web/admin_api/admin_api_controller.ex | 10 +++--- lib/pleroma/web/twitter_api/twitter_api.ex | 41 +++++++---------------- 3 files changed, 41 insertions(+), 35 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index a38ead81a..234617574 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -170,7 +170,14 @@ defmodule Pleroma.User do update_and_set_cache(password_update_changeset(user, data)) end - def register_changeset(struct, params \\ %{}) do + def register_changeset(struct, params \\ %{}, opts \\ []) do + confirmation_status = + if opts[:confirmed] || !Pleroma.Config.get([:instance, :account_activation_required]) do + :confirmed + else + :unconfirmed + end + changeset = struct |> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation]) @@ -182,7 +189,7 @@ defmodule Pleroma.User do |> validate_format(:email, @email_regex) |> validate_length(:bio, max: 1000) |> validate_length(:name, min: 1, max: 100) - |> put_change(:info, %Pleroma.User.Info{}) + |> put_change(:info, User.Info.confirmation_update(%User.Info{}, confirmation_status)) if changeset.valid? do hashed = Pbkdf2.hashpwsalt(changeset.changes[:password]) @@ -199,6 +206,20 @@ defmodule Pleroma.User do end end + @doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)" + def register(%Ecto.Changeset{} = changeset) do + with {:ok, user} <- Repo.insert(changeset) do + if user.info.confirmation_pending do + {:ok, _} = + user + |> Pleroma.UserEmail.account_confirmation_email() + |> Pleroma.Mailer.deliver() + end + + {:ok, user} + end + end + def needs_update?(%User{local: true}), do: false def needs_update?(%User{local: false, last_refreshed_at: nil}), do: true diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 4d73cf219..683310168 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -1,6 +1,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do use Pleroma.Web, :controller - alias Pleroma.{User, Repo} + alias Pleroma.User alias Pleroma.Web.ActivityPub.Relay import Pleroma.Web.ControllerHelper, only: [json_response: 3] @@ -26,7 +26,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do conn, %{"nickname" => nickname, "email" => email, "password" => password} ) do - new_user = %{ + user_data = %{ nickname: nickname, name: nickname, email: email, @@ -35,11 +35,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do bio: "." } - User.register_changeset(%User{}, new_user) - |> Repo.insert!() + changeset = User.register_changeset(%User{}, user_data, confirmed: true) + {:ok, user} = User.register(changeset) conn - |> json(new_user.nickname) + |> json(user.nickname) end def tag_users(conn, %{"nicknames" => nicknames, "tags" => tags}) do diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index b77761aa4..d8dd7dfa8 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -161,34 +161,19 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do Repo.get_by(UserInviteToken, %{token: tokenString}) end - cond do - registrations_open || (!is_nil(token) && !token.used) -> - changeset = User.register_changeset(%User{info: %{}}, params) - - with {:ok, user} <- Repo.insert(changeset) do - !registrations_open && UserInviteToken.mark_as_used(token.token) - - if Pleroma.Config.get([:instance, :account_activation_required]) do - info_change = User.Info.confirmation_update(user.info, :unconfirmed) - - {:ok, unconfirmed_user} = - user - |> Ecto.Changeset.change() - |> Ecto.Changeset.put_embed(:info, info_change) - |> Repo.update() - - {:ok, _} = - unconfirmed_user - |> UserEmail.account_confirmation_email() - |> Mailer.deliver() - end - - {:ok, user} - else - {:error, changeset} -> - errors = - Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end) - |> Jason.encode!() + cond do + registrations_open || (!is_nil(token) && !token.used) -> + changeset = User.register_changeset(%User{}, params) + + with {:ok, user} <- User.register(changeset) do + !registrations_open && UserInviteToken.mark_as_used(token.token) + + {:ok, user} + else + {:error, changeset} -> + errors = + Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end) + |> Jason.encode!() {:error, %{error: errors}} end -- cgit v1.2.3 From aed0f902871524ecc1db0d8c088ce5939e7c685a Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 18 Dec 2018 14:07:05 +0300 Subject: [#114] Added `pleroma.confirmation_pending` to user views, adjusted view tests. --- lib/pleroma/web/mastodon_api/views/account_view.ex | 1 + lib/pleroma/web/twitter_api/views/user_view.ex | 1 + 2 files changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index ebcf9230b..50df88aca 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -62,6 +62,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do # Pleroma extension pleroma: %{ + confirmation_pending: user_info.confirmation_pending, tags: user.tags } } diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 8a88d72b1..45b893eda 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -81,6 +81,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do # Pleroma extension "pleroma" => %{ + "confirmation_pending" => user_info.confirmation_pending, "tags" => user.tags } } -- cgit v1.2.3 From b096e30cffc79a4adf12be88da412a290cd0d190 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 18 Dec 2018 17:13:52 +0300 Subject: [#114] Added email confirmation resend action. Added tests for registration, authentication, email confirmation, confirmation resending. Made admin methods create confirmed users. --- lib/mix/tasks/pleroma/user.ex | 4 ++-- lib/pleroma/user.ex | 28 +++++++++++++--------- lib/pleroma/web/oauth/oauth_controller.ex | 18 ++++++++++++-- lib/pleroma/web/router.ex | 2 ++ .../web/twitter_api/twitter_api_controller.ex | 13 +++++++++- 5 files changed, 49 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 3d30e3a81..51086a443 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -103,8 +103,8 @@ defmodule Mix.Tasks.Pleroma.User do bio: bio } - user = User.register_changeset(%User{}, params) - Repo.insert!(user) + changeset = User.register_changeset(%User{}, params, confirmed: true) + {:ok, _user} = User.register(changeset) Mix.shell().info("User #{nickname} created") diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 234617574..0cd7bc463 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -74,13 +74,15 @@ defmodule Pleroma.User do def user_info(%User{} = user) do oneself = if user.local, do: 1, else: 0 + user_info = user.info %{ following_count: length(user.following) - oneself, - note_count: user.info.note_count, - follower_count: user.info.follower_count, - locked: user.info.locked, - default_scope: user.info.default_scope + note_count: user_info.note_count, + follower_count: user_info.follower_count, + locked: user_info.locked, + confirmation_pending: user_info.confirmation_pending, + default_scope: user_info.default_scope } end @@ -209,17 +211,21 @@ defmodule Pleroma.User do @doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)" def register(%Ecto.Changeset{} = changeset) do with {:ok, user} <- Repo.insert(changeset) do - if user.info.confirmation_pending do - {:ok, _} = - user - |> Pleroma.UserEmail.account_confirmation_email() - |> Pleroma.Mailer.deliver() - end - + {:ok, _} = try_send_confirmation_email(user) {:ok, user} end end + def try_send_confirmation_email(%User{} = user) do + if user.info.confirmation_pending do + user + |> Pleroma.UserEmail.account_confirmation_email() + |> Pleroma.Mailer.deliver() + else + {:ok, :noop} + end + end + def needs_update?(%User{local: true}), do: false def needs_update?(%User{local: false, last_refreshed_at: nil}), do: true diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 10158f07e..9a972ee47 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -31,7 +31,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do }) do with %User{} = user <- User.get_by_nickname_or_email(name), true <- Pbkdf2.checkpw(password, user.password_hash), - true <- User.auth_active?(user), + {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, %App{} = app <- Repo.get_by(App, client_id: client_id), {:ok, auth} <- Authorization.create_authorization(app, user) do # Special case: Local MastodonFE. @@ -64,6 +64,15 @@ defmodule Pleroma.Web.OAuth.OAuthController do redirect(conn, external: url) end + else + {:auth_active, false} -> + conn + |> put_flash(:error, "Account confirmation pending") + |> put_status(:forbidden) + |> authorize(params) + + error -> + error end end @@ -102,7 +111,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do with %App{} = app <- get_app_from_request(conn, params), %User{} = user <- User.get_by_nickname_or_email(name), true <- Pbkdf2.checkpw(password, user.password_hash), - true <- User.auth_active?(user), + {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, {:ok, auth} <- Authorization.create_authorization(app, user), {:ok, token} <- Token.exchange_token(app, auth) do response = %{ @@ -115,6 +124,11 @@ defmodule Pleroma.Web.OAuth.OAuthController do json(conn, response) else + {:auth_active, false} -> + conn + |> put_status(:forbidden) + |> json(%{error: "Account confirmation pending"}) + _error -> put_status(conn, 400) |> json(%{error: "Invalid credentials"}) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 0e4589116..ca069ab99 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -284,6 +284,8 @@ defmodule Pleroma.Web.Router do get("/account/confirm_email/:token", TwitterAPI.Controller, :confirm_email, as: :confirm_email) + post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email) + get("/search", TwitterAPI.Controller, :search) get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline) end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index e8a3150e9..7286c153b 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -13,7 +13,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do require Logger plug(:only_if_public_instance when action in [:public_timeline, :public_and_external_timeline]) - plug(:fetch_flash when action in [:confirm_email]) + plug(:fetch_flash when action in [:confirm_email, :resend_confirmation_email]) action_fallback(:errors) def verify_credentials(%{assigns: %{user: user}} = conn, _params) do @@ -385,6 +385,17 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def resend_confirmation_email(conn, params) do + nickname_or_email = params["email"] || params["nickname"] + + with %User{} = user <- User.get_by_nickname_or_email(nickname_or_email), + {:ok, _} <- User.try_send_confirmation_email(user) do + conn + |> put_flash(:info, "Email confirmation has been sent.") + |> json_response(:no_content, "") + end + end + def update_avatar(%{assigns: %{user: user}} = conn, params) do {:ok, object} = ActivityPub.upload(params, type: :avatar) change = Changeset.change(user, %{avatar: object.data}) -- cgit v1.2.3 From 3371a45884b5d80ff4e8178ea921fe6f6c8d174d Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 18 Dec 2018 17:30:30 +0300 Subject: [#114] Formatting fix. --- lib/pleroma/web/twitter_api/twitter_api.ex | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index d8dd7dfa8..d816dc3bc 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -161,19 +161,19 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do Repo.get_by(UserInviteToken, %{token: tokenString}) end - cond do - registrations_open || (!is_nil(token) && !token.used) -> - changeset = User.register_changeset(%User{}, params) - - with {:ok, user} <- User.register(changeset) do - !registrations_open && UserInviteToken.mark_as_used(token.token) - - {:ok, user} - else - {:error, changeset} -> - errors = - Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end) - |> Jason.encode!() + cond do + registrations_open || (!is_nil(token) && !token.used) -> + changeset = User.register_changeset(%User{}, params) + + with {:ok, user} <- User.register(changeset) do + !registrations_open && UserInviteToken.mark_as_used(token.token) + + {:ok, user} + else + {:error, changeset} -> + errors = + Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end) + |> Jason.encode!() {:error, %{error: errors}} end -- cgit v1.2.3 From f58f20abbb761f652dbc6b44d213ebe90e305899 Mon Sep 17 00:00:00 2001 From: href Date: Tue, 18 Dec 2018 15:32:41 +0100 Subject: Twitter ActivityView: fix crash when activity content is nil --- lib/pleroma/web/twitter_api/views/activity_view.ex | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 91d086740..bc90a1cd4 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -245,9 +245,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do |> Formatter.emojify(object["emoji"]) text = - content - |> String.replace(~r//, "\n") - |> HTML.strip_tags() + if content do + content + |> String.replace(~r//, "\n") + |> HTML.strip_tags() + end reply_parent = Activity.get_in_reply_to_activity(activity) -- cgit v1.2.3 From a6dfe1fc6b65ec406159a2e068ab598de2cc13e0 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 18 Dec 2018 17:05:36 +0100 Subject: Documentation: Move generated files to priv/static/doc, add it to endpoint.ex --- lib/pleroma/web/endpoint.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index d79f61b2e..564fc2c1d 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -21,7 +21,7 @@ defmodule Pleroma.Web.Endpoint do at: "/", from: :pleroma, only: - ~w(index.html static finmoji emoji packs sounds images instance sw.js favicon.png schemas) + ~w(index.html static finmoji emoji packs sounds images instance sw.js favicon.png schemas doc) ) # Code reloading can be explicitly enabled under the -- cgit v1.2.3 From 059dd6f681caf14ee9d288ec14b82132be29ae2c Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 18 Dec 2018 21:38:15 +0300 Subject: Ignore HTML characters in formatter.ex --- lib/pleroma/formatter.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 46d0d926a..9401689cb 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -4,12 +4,12 @@ defmodule Pleroma.Formatter do alias Pleroma.HTML alias Pleroma.Emoji - @tag_regex ~r/\#\w+/u + @tag_regex ~r/((?<=[^&])|\A)(\#)(\w+)/u @markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/ def parse_tags(text, data \\ %{}) do Regex.scan(@tag_regex, text) - |> Enum.map(fn ["#" <> tag = full_tag] -> {full_tag, String.downcase(tag)} end) + |> Enum.map(fn ["#" <> tag = full_tag | _] -> {full_tag, String.downcase(tag)} end) |> (fn map -> if data["sensitive"] in [true, "True", "true", "1"], do: [{"#nsfw", "nsfw"}] ++ map, @@ -155,7 +155,7 @@ defmodule Pleroma.Formatter do uuid_text = tags |> Enum.reduce(text, fn {match, _short, uuid}, text -> - String.replace(text, match, uuid) + String.replace(text, ~r/((?<=[^&])|(\A))#{match}/, uuid) end) subs = -- cgit v1.2.3 From f3eb414e282dd0e3bd5c60838e45c69cf21541e4 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 18 Dec 2018 21:08:52 +0100 Subject: Add a way to use the admin api without a user. --- .../plugs/admin_secret_authentication_plug.ex | 25 ++++++++++++++++++++++ lib/pleroma/web/router.ex | 1 + 2 files changed, 26 insertions(+) create mode 100644 lib/pleroma/plugs/admin_secret_authentication_plug.ex (limited to 'lib') diff --git a/lib/pleroma/plugs/admin_secret_authentication_plug.ex b/lib/pleroma/plugs/admin_secret_authentication_plug.ex new file mode 100644 index 000000000..f61a6ee24 --- /dev/null +++ b/lib/pleroma/plugs/admin_secret_authentication_plug.ex @@ -0,0 +1,25 @@ +defmodule Pleroma.Plugs.AdminSecretAuthenticationPlug do + import Plug.Conn + alias Pleroma.User + + def init(options) do + options + end + + def secret_token do + Pleroma.Config.get(:admin_token) + end + + def call(%{assigns: %{user: %User{}}} = conn, _), do: conn + + def call(%{params: %{"admin_token" => admin_token}} = conn, _) do + if secret_token() && admin_token == secret_token() do + conn + |> assign(:user, %User{info: %{is_admin: true}}) + else + conn + end + end + + def call(conn, _), do: conn +end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index dd1985d6e..e988f1088 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -38,6 +38,7 @@ defmodule Pleroma.Web.Router do plug(Pleroma.Plugs.SessionAuthenticationPlug) plug(Pleroma.Plugs.LegacyAuthenticationPlug) plug(Pleroma.Plugs.AuthenticationPlug) + plug(Pleroma.Plugs.AdminSecretAuthenticationPlug) plug(Pleroma.Plugs.UserEnabledPlug) plug(Pleroma.Plugs.SetUserSessionIdPlug) plug(Pleroma.Plugs.EnsureAuthenticatedPlug) -- cgit v1.2.3 From 59fc5d15dfde0120fb10ec14631ad1115a6087a9 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 19 Dec 2018 16:27:16 +0300 Subject: [#114] User.Info: renamed `confirmation_update` to `confirmation_change`. --- lib/pleroma/user.ex | 2 +- lib/pleroma/user/info.ex | 10 +++++----- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 0cd7bc463..41d01cbf5 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -191,7 +191,7 @@ defmodule Pleroma.User do |> validate_format(:email, @email_regex) |> validate_length(:bio, max: 1000) |> validate_length(:name, min: 1, max: 100) - |> put_change(:info, User.Info.confirmation_update(%User.Info{}, confirmation_status)) + |> put_change(:info, User.Info.confirmation_change(%User.Info{}, confirmation_status)) if changeset.valid? do hashed = Pbkdf2.hashpwsalt(changeset.changes[:password]) diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 9ce9129cd..2800e9cff 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -143,21 +143,21 @@ defmodule Pleroma.User.Info do ]) end - def confirmation_update(info, :confirmed) do - confirmation_update(info, %{ + def confirmation_change(info, :confirmed) do + confirmation_change(info, %{ confirmation_pending: false, confirmation_token: nil }) end - def confirmation_update(info, :unconfirmed) do - confirmation_update(info, %{ + def confirmation_change(info, :unconfirmed) do + confirmation_change(info, %{ confirmation_pending: true, confirmation_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64() }) end - def confirmation_update(info, params) do + def confirmation_change(info, params) do cast(info, params, [:confirmation_pending, :confirmation_token]) end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 7286c153b..4bd729b77 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -376,7 +376,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def confirm_email(conn, %{"token" => token}) do with %User{} = user <- User.get_by_confirmation_token(token), true <- user.local, - info_change <- User.Info.confirmation_update(user.info, :confirmed), + info_change <- User.Info.confirmation_change(user.info, :confirmed), changeset <- Changeset.change(user) |> Changeset.put_embed(:info, info_change), {:ok, _} <- User.update_and_set_cache(changeset) do conn -- cgit v1.2.3 From 968d7490b689ba501a64f350841dc8f9b33b5244 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 19 Dec 2018 16:27:16 +0300 Subject: [#114] User.Info: renamed `confirmation_update` to `confirmation_changeset`. --- lib/pleroma/user.ex | 2 +- lib/pleroma/user/info.ex | 10 +++++----- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 41d01cbf5..4e227b08d 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -191,7 +191,7 @@ defmodule Pleroma.User do |> validate_format(:email, @email_regex) |> validate_length(:bio, max: 1000) |> validate_length(:name, min: 1, max: 100) - |> put_change(:info, User.Info.confirmation_change(%User.Info{}, confirmation_status)) + |> put_change(:info, User.Info.confirmation_changeset(%User.Info{}, confirmation_status)) if changeset.valid? do hashed = Pbkdf2.hashpwsalt(changeset.changes[:password]) diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 2800e9cff..ad9fe1bbe 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -143,21 +143,21 @@ defmodule Pleroma.User.Info do ]) end - def confirmation_change(info, :confirmed) do - confirmation_change(info, %{ + def confirmation_changeset(info, :confirmed) do + confirmation_changeset(info, %{ confirmation_pending: false, confirmation_token: nil }) end - def confirmation_change(info, :unconfirmed) do - confirmation_change(info, %{ + def confirmation_changeset(info, :unconfirmed) do + confirmation_changeset(info, %{ confirmation_pending: true, confirmation_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64() }) end - def confirmation_change(info, params) do + def confirmation_changeset(info, params) do cast(info, params, [:confirmation_pending, :confirmation_token]) end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 4bd729b77..b362f3946 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -376,7 +376,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def confirm_email(conn, %{"token" => token}) do with %User{} = user <- User.get_by_confirmation_token(token), true <- user.local, - info_change <- User.Info.confirmation_change(user.info, :confirmed), + info_change <- User.Info.confirmation_changeset(user.info, :confirmed), changeset <- Changeset.change(user) |> Changeset.put_embed(:info, info_change), {:ok, _} <- User.update_and_set_cache(changeset) do conn -- cgit v1.2.3 From a532ad5d720cbbe3ef58e09f8ad209bfe15b43c9 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 19 Dec 2018 17:24:55 +0300 Subject: [#114] User.register/1 tweak. --- lib/pleroma/user.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 4e227b08d..4b8caf65c 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -210,8 +210,8 @@ defmodule Pleroma.User do @doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)" def register(%Ecto.Changeset{} = changeset) do - with {:ok, user} <- Repo.insert(changeset) do - {:ok, _} = try_send_confirmation_email(user) + with {:ok, user} <- Repo.insert(changeset), + {:ok, _} = try_send_confirmation_email(user) do {:ok, user} end end -- cgit v1.2.3 From 279096228c8b0113a8ea63a73e011934a3226df7 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 19 Dec 2018 18:56:52 +0300 Subject: [#114] Made MastodonAPI and TwitterAPI user show actions return 404 for auth-inactive users unless requested by admin or moderator. --- lib/pleroma/user.ex | 4 +++- lib/pleroma/user/info.ex | 2 ++ lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 3 ++- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 14 +++++++++++--- 4 files changed, 18 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 4b8caf65c..7e792cb0c 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -38,7 +38,9 @@ defmodule Pleroma.User do timestamps() end - def auth_active?(user), do: user.info && !user.info.confirmation_pending + def auth_active?(%User{} = user), do: user.info && !user.info.confirmation_pending + + def superuser?(%User{} = user), do: user.info && User.Info.superuser?(user.info) def avatar_url(user) do case user.avatar do diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index ad9fe1bbe..3de4af56c 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -37,6 +37,8 @@ defmodule Pleroma.User.Info do # subject _> Where is this used? end + def superuser?(info), do: info.is_admin || info.is_moderator + def set_activation_status(info, deactivated) do params = %{deactivated: deactivated} diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 665b75437..c6db89442 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -110,7 +110,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def user(%{assigns: %{user: for_user}} = conn, %{"id" => id}) do - with %User{} = user <- Repo.get(User, id) do + with %User{} = user <- Repo.get(User, id), + true <- User.auth_active?(user) || user.id == for_user.id || User.superuser?(for_user) do account = AccountView.render("account.json", %{user: user, for: for_user}) json(conn, account) else diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index b362f3946..e047ed0ad 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -97,10 +97,13 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def show_user(conn, params) do - with {:ok, shown} <- TwitterAPI.get_user(params) do + for_user = conn.assigns.user + + with {:ok, shown} <- TwitterAPI.get_user(params), + true <- User.auth_active?(shown) || for_user && (for_user.id == shown.id || User.superuser?(for_user)) do params = - if user = conn.assigns.user do - %{user: shown, for: user} + if for_user do + %{user: shown, for: for_user} else %{user: shown} end @@ -111,6 +114,11 @@ defmodule Pleroma.Web.TwitterAPI.Controller do else {:error, msg} -> bad_request_reply(conn, msg) + + false -> + conn + |> put_status(404) + |> json(%{error: "Unconfirmed user"}) end end -- cgit v1.2.3 From b520d44b58db3bac7a883c2220d83d05b07784d0 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 19 Dec 2018 19:03:39 +0300 Subject: [#114] `mix format` --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index e047ed0ad..2b0f7135a 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -100,7 +100,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do for_user = conn.assigns.user with {:ok, shown} <- TwitterAPI.get_user(params), - true <- User.auth_active?(shown) || for_user && (for_user.id == shown.id || User.superuser?(for_user)) do + true <- + User.auth_active?(shown) || + (for_user && (for_user.id == shown.id || User.superuser?(for_user))) do params = if for_user do %{user: shown, for: for_user} -- cgit v1.2.3 From 652f49d176b12618c7f537885c0cb1767121acf0 Mon Sep 17 00:00:00 2001 From: raeno Date: Wed, 19 Dec 2018 23:06:10 +0400 Subject: Remove extra bracket --- lib/pleroma/web/router.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index e28055d2a..59784549d 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -485,7 +485,7 @@ defmodule Fallback.RedirectController do end def index_file_path do - Pleroma.Plugs.InstanceStatic.file_path("index.html")) + Pleroma.Plugs.InstanceStatic.file_path("index.html") end def registration_page(conn, params) do -- cgit v1.2.3 From f1b93b5be761826af9b833411689e9e0c086b815 Mon Sep 17 00:00:00 2001 From: Maksim Date: Thu, 20 Dec 2018 09:35:01 +0000 Subject: [#413] fix parse mentions --- lib/pleroma/formatter.ex | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 9401689cb..72fe9640b 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -7,6 +7,9 @@ defmodule Pleroma.Formatter do @tag_regex ~r/((?<=[^&])|\A)(\#)(\w+)/u @markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/ + # Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address + @mentions_regex ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]*@?[a-zA-Z0-9_-](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u + def parse_tags(text, data \\ %{}) do Regex.scan(@tag_regex, text) |> Enum.map(fn ["#" <> tag = full_tag | _] -> {full_tag, String.downcase(tag)} end) @@ -17,16 +20,15 @@ defmodule Pleroma.Formatter do end).() end + @doc "Parses mentions text and returns list {nickname, user}." + @spec parse_mentions(binary()) :: list({binary(), User.t()}) def parse_mentions(text) do - # Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address - regex = - ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]*@?[a-zA-Z0-9_-](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u - - Regex.scan(regex, text) + Regex.scan(@mentions_regex, text) |> List.flatten() |> Enum.uniq() - |> Enum.map(fn "@" <> match = full_match -> - {full_match, User.get_cached_by_nickname(match)} + |> Enum.map(fn nickname -> + with nickname <- String.trim_leading(nickname, "@"), + do: {"@" <> nickname, User.get_cached_by_nickname(nickname)} end) |> Enum.filter(fn {_match, user} -> user end) end -- cgit v1.2.3 From 501ce34d7fbb74f91e8afcaa491625c5a0152597 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 20 Dec 2018 12:55:12 +0300 Subject: [#114] Stylistic adjustments. --- lib/pleroma/user.ex | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 7e792cb0c..7e3a342f1 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -76,15 +76,14 @@ defmodule Pleroma.User do def user_info(%User{} = user) do oneself = if user.local, do: 1, else: 0 - user_info = user.info %{ following_count: length(user.following) - oneself, - note_count: user_info.note_count, - follower_count: user_info.follower_count, - locked: user_info.locked, - confirmation_pending: user_info.confirmation_pending, - default_scope: user_info.default_scope + note_count: user.info.note_count, + follower_count: user.info.follower_count, + locked: user.info.locked, + confirmation_pending: user.info.confirmation_pending, + default_scope: user.info.default_scope } end @@ -182,6 +181,8 @@ defmodule Pleroma.User do :unconfirmed end + info_change = User.Info.confirmation_changeset(%User.Info{}, confirmation_status) + changeset = struct |> cast(params, [:bio, :email, :name, :nickname, :password, :password_confirmation]) @@ -193,7 +194,7 @@ defmodule Pleroma.User do |> validate_format(:email, @email_regex) |> validate_length(:bio, max: 1000) |> validate_length(:name, min: 1, max: 100) - |> put_change(:info, User.Info.confirmation_changeset(%User.Info{}, confirmation_status)) + |> put_change(:info, info_change) if changeset.valid? do hashed = Pbkdf2.hashpwsalt(changeset.changes[:password]) -- cgit v1.2.3 From 8adcd1e80f78cdacd245e9b6aacea4b05cb1a880 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 20 Dec 2018 13:05:42 +0300 Subject: [#114] Removed flash messages rendering on redirects. --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 2b0f7135a..46dc9b12c 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -13,7 +13,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do require Logger plug(:only_if_public_instance when action in [:public_timeline, :public_and_external_timeline]) - plug(:fetch_flash when action in [:confirm_email, :resend_confirmation_email]) action_fallback(:errors) def verify_credentials(%{assigns: %{user: user}} = conn, _params) do @@ -390,7 +389,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do changeset <- Changeset.change(user) |> Changeset.put_embed(:info, info_change), {:ok, _} <- User.update_and_set_cache(changeset) do conn - |> put_flash(:info, "Email confirmed. Please sign in.") |> redirect(to: "/") end end @@ -401,7 +399,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do with %User{} = user <- User.get_by_nickname_or_email(nickname_or_email), {:ok, _} <- User.try_send_confirmation_email(user) do conn - |> put_flash(:info, "Email confirmation has been sent.") |> json_response(:no_content, "") end end -- cgit v1.2.3 From f69cbf4755b974de0303731327180bb51ed244fc Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 20 Dec 2018 13:41:30 +0300 Subject: [#114] Added :user_id component to email confirmation path to improve the security. Added tests for `confirm_email` action. --- lib/pleroma/emails/user_email.ex | 1 + lib/pleroma/user.ex | 4 ---- lib/pleroma/web/router.ex | 7 ++++++- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 6 ++++-- 4 files changed, 11 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index 856816386..8f916f470 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -70,6 +70,7 @@ defmodule Pleroma.UserEmail do Router.Helpers.confirm_email_url( Endpoint, :confirm_email, + user.id, to_string(user.info.confirmation_token) ) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 7e3a342f1..ad50cf558 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -396,10 +396,6 @@ defmodule Pleroma.User do end end - def get_by_confirmation_token(token) do - Repo.one(from(u in User, where: fragment("? ->> 'confirmation_token' = ?", u.info, ^token))) - end - def get_followers_query(%User{id: id, follower_address: follower_address}) do from( u in User, diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index ca069ab99..d1c3b34f6 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -282,7 +282,12 @@ defmodule Pleroma.Web.Router do post("/account/register", TwitterAPI.Controller, :register) post("/account/password_reset", TwitterAPI.Controller, :password_reset) - get("/account/confirm_email/:token", TwitterAPI.Controller, :confirm_email, as: :confirm_email) + get( + "/account/confirm_email/:user_id/:token", + TwitterAPI.Controller, + :confirm_email, + as: :confirm_email + ) post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 46dc9b12c..c644681b0 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -382,9 +382,11 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end - def confirm_email(conn, %{"token" => token}) do - with %User{} = user <- User.get_by_confirmation_token(token), + def confirm_email(conn, %{"user_id" => uid, "token" => token}) do + with %User{} = user <- Repo.get(User, uid), true <- user.local, + true <- user.info.confirmation_pending, + true <- user.info.confirmation_token == token, info_change <- User.Info.confirmation_changeset(user.info, :confirmed), changeset <- Changeset.change(user) |> Changeset.put_embed(:info, info_change), {:ok, _} <- User.update_and_set_cache(changeset) do -- cgit v1.2.3 From 7cab7de9ff0432a582cfca0852a4b66fdd124c41 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 20 Dec 2018 14:48:48 +0300 Subject: [#114] Allowed unconfirmed users to authenticate if :account_activation_required is disabled prior to confirmation. Ensured that no confirmation emails are sent if :account_activation_required is not true. Adjusted tests. --- lib/pleroma/user.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index ad50cf558..f8827abec 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -38,7 +38,10 @@ defmodule Pleroma.User do timestamps() end - def auth_active?(%User{} = user), do: user.info && !user.info.confirmation_pending + def auth_active?(%User{} = user) do + (user.info && !user.info.confirmation_pending) || + !Pleroma.Config.get([:instance, :account_activation_required]) + end def superuser?(%User{} = user), do: user.info && User.Info.superuser?(user.info) @@ -220,7 +223,8 @@ defmodule Pleroma.User do end def try_send_confirmation_email(%User{} = user) do - if user.info.confirmation_pending do + if user.info.confirmation_pending && + Pleroma.Config.get([:instance, :account_activation_required]) do user |> Pleroma.UserEmail.account_confirmation_email() |> Pleroma.Mailer.deliver() -- cgit v1.2.3 From 336e37d98f1b86c0332c9f260e27455a14714fa6 Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Fri, 21 Dec 2018 00:32:37 +0300 Subject: Make captcha (kocaptcha) stateless Also rename seconds_retained to seconds_valid since that's how it is now. Put it down from 180 to 20 seconds. The answer data is now stored in an encrypted text transfered to the client and back, so no ETS is needed --- lib/pleroma/captcha/captcha.ex | 29 ++--------- lib/pleroma/captcha/captcha_service.ex | 12 ++--- lib/pleroma/captcha/kocaptcha.ex | 82 ++++++++++++++++-------------- lib/pleroma/web/twitter_api/twitter_api.ex | 16 ++++-- 4 files changed, 65 insertions(+), 74 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index 5630f6b57..61a0f907f 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -1,8 +1,6 @@ defmodule Pleroma.Captcha do use GenServer - @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}] - @doc false def start_link() do GenServer.start_link(__MODULE__, [], name: __MODULE__) @@ -10,14 +8,6 @@ defmodule Pleroma.Captcha do @doc false def init(_) do - # Create a ETS table to store captchas - ets_name = Module.concat(method(), Ets) - ^ets_name = :ets.new(Module.concat(method(), Ets), @ets_options) - - # Clean up old captchas every few minutes - seconds_retained = Pleroma.Config.get!([__MODULE__, :seconds_retained]) - Process.send_after(self(), :cleanup, 1000 * seconds_retained) - {:ok, nil} end @@ -31,8 +21,8 @@ defmodule Pleroma.Captcha do @doc """ Ask the configured captcha service to validate the captcha """ - def validate(token, captcha) do - GenServer.call(__MODULE__, {:validate, token, captcha}) + def validate(token, captcha, answer_data) do + GenServer.call(__MODULE__, {:validate, token, captcha, answer_data}) end @doc false @@ -47,19 +37,8 @@ defmodule Pleroma.Captcha do end @doc false - def handle_call({:validate, token, captcha}, _from, state) do - {:reply, method().validate(token, captcha), state} - end - - @doc false - def handle_info(:cleanup, state) do - :ok = method().cleanup() - - seconds_retained = Pleroma.Config.get!([__MODULE__, :seconds_retained]) - # Schedule the next clenup - Process.send_after(self(), :cleanup, 1000 * seconds_retained) - - {:noreply, state} + def handle_call({:validate, token, captcha, answer_data}, _from, state) do + {:reply, method().validate(token, captcha, answer_data), state} end defp method, do: Pleroma.Config.get!([__MODULE__, :method]) diff --git a/lib/pleroma/captcha/captcha_service.ex b/lib/pleroma/captcha/captcha_service.ex index 8d0b76f86..6f36d29b0 100644 --- a/lib/pleroma/captcha/captcha_service.ex +++ b/lib/pleroma/captcha/captcha_service.ex @@ -14,15 +14,15 @@ defmodule Pleroma.Captcha.Service do Arguments: * `token` the captcha is associated with * `captcha` solution of the captcha to validate + * `answer_data` is the data needed to validate the answer (presumably encrypted) Returns: `true` if captcha is valid, `false` if not """ - @callback validate(token :: String.t(), captcha :: String.t()) :: boolean - - @doc """ - This function is called periodically to clean up old captchas - """ - @callback cleanup() :: :ok + @callback validate( + token :: String.t(), + captcha :: String.t(), + answer_data :: String.t() + ) :: :ok | {:error, String.t()} end diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex index 51900d123..f881c7b65 100644 --- a/lib/pleroma/captcha/kocaptcha.ex +++ b/lib/pleroma/captcha/kocaptcha.ex @@ -1,11 +1,11 @@ defmodule Pleroma.Captcha.Kocaptcha do + alias Plug.Crypto.KeyGenerator + alias Plug.Crypto.MessageEncryptor alias Calendar.DateTime alias Pleroma.Captcha.Service @behaviour Service - @ets __MODULE__.Ets - @impl Service def new() do endpoint = Pleroma.Config.get!([__MODULE__, :endpoint]) @@ -18,50 +18,56 @@ defmodule Pleroma.Captcha.Kocaptcha do json_resp = Poison.decode!(res.body) token = json_resp["token"] + answer_md5 = json_resp["md5"] - true = - :ets.insert( - @ets, - {token, json_resp["md5"], DateTime.now_utc() |> DateTime.Format.unix()} - ) + secret_key_base = Pleroma.Config.get!([Pleroma.Web.Endpoint, :secret_key_base]) - %{type: :kocaptcha, token: token, url: endpoint <> json_resp["url"]} - end - end - - @impl Service - def validate(token, captcha) do - with false <- is_nil(captcha), - [{^token, saved_md5, _}] <- :ets.lookup(@ets, token), - true <- :crypto.hash(:md5, captcha) |> Base.encode16() == String.upcase(saved_md5) do - # Clear the saved value - :ets.delete(@ets, token) + # This make salt a little different for two keys + secret = KeyGenerator.generate(secret_key_base, token <> "_encrypt") + sign_secret = KeyGenerator.generate(secret_key_base, token <> "_sign") + # Basicallty copy what Phoenix.Token does here, add the time to + # the actual data and make it a binary to then encrypt it + encrypted_captcha_answer = + %{ + at: DateTime.now_utc(), + answer_md5: answer_md5 + } + |> :erlang.term_to_binary() + |> MessageEncryptor.encrypt(secret, sign_secret) - true - else - _ -> false + %{ + type: :kocaptcha, + token: token, + url: endpoint <> json_resp["url"], + answer_data: encrypted_captcha_answer + } end end @impl Service - def cleanup() do - seconds_retained = Pleroma.Config.get!([Pleroma.Captcha, :seconds_retained]) - # If the time in ETS is less than current_time - seconds_retained, then the time has - # already passed - delete_after = - DateTime.subtract!(DateTime.now_utc(), seconds_retained) |> DateTime.Format.unix() + def validate(token, captcha, answer_data) do + secret_key_base = Pleroma.Config.get!([Pleroma.Web.Endpoint, :secret_key_base]) + secret = KeyGenerator.generate(secret_key_base, token <> "_encrypt") + sign_secret = KeyGenerator.generate(secret_key_base, token <> "_sign") - :ets.select_delete( - @ets, - [ - { - {:_, :_, :"$1"}, - [{:<, :"$1", {:const, delete_after}}], - [true] - } - ] - ) + # If the time found is less than (current_time - seconds_valid), then the time has already passed. + # Later we check that the time found is more than the presumed invalidatation time, that means + # that the data is still valid and the captcha can be checked + seconds_valid = Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]) + valid_if_after = DateTime.subtract!(DateTime.now_utc(), seconds_valid) - :ok + with {:ok, data} <- MessageEncryptor.decrypt(answer_data, secret, sign_secret), + %{at: at, answer_md5: answer_md5} <- :erlang.binary_to_term(data) do + if DateTime.after?(at, valid_if_after) do + if not is_nil(captcha) and + :crypto.hash(:md5, captcha) |> Base.encode16() == String.upcase(answer_md5), + do: :ok, + else: {:error, "Invalid CAPTCHA"} + else + {:error, "CAPTCHA expired"} + end + else + _ -> {:error, "Invalid answer data"} + end end end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index d816dc3bc..9e15f2c33 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -136,22 +136,28 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do password: params["password"], password_confirmation: params["confirm"], captcha_solution: params["captcha_solution"], - captcha_token: params["captcha_token"] + captcha_token: params["captcha_token"], + captcha_answer_data: params["captcha_answer_data"] } captcha_enabled = Pleroma.Config.get([Pleroma.Captcha, :enabled]) # true if captcha is disabled or enabled and valid, false otherwise captcha_ok = if !captcha_enabled do - true + :ok else - Pleroma.Captcha.validate(params[:captcha_token], params[:captcha_solution]) + Pleroma.Captcha.validate( + params[:captcha_token], + params[:captcha_solution], + params[:captcha_answer_data] + ) end # Captcha invalid - if not captcha_ok do + if captcha_ok != :ok do + {:error, error} = captcha_ok # I have no idea how this error handling works - {:error, %{error: Jason.encode!(%{captcha: ["Invalid CAPTCHA"]})}} + {:error, %{error: Jason.encode!(%{captcha: [error]})}} else registrations_open = Pleroma.Config.get([:instance, :registrations_open]) -- cgit v1.2.3 From b386e560ba22ca93b56ba74ffc134fe7e6de8b2d Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Sat, 22 Dec 2018 22:39:08 +0300 Subject: Move the encryption out of kocaptcha into general captcha module That way there won't be a need to reimplement it for other captcha services --- lib/pleroma/captcha/captcha.ex | 53 ++++++++++++++++++++++++++++++-- lib/pleroma/captcha/captcha_service.ex | 11 +++++-- lib/pleroma/captcha/kocaptcha.ex | 56 +++++----------------------------- 3 files changed, 67 insertions(+), 53 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index 61a0f907f..04769d4b2 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -1,4 +1,8 @@ defmodule Pleroma.Captcha do + alias Plug.Crypto.KeyGenerator + alias Plug.Crypto.MessageEncryptor + alias Calendar.DateTime + use GenServer @doc false @@ -32,13 +36,58 @@ defmodule Pleroma.Captcha do if !enabled do {:reply, %{type: :none}, state} else - {:reply, method().new(), state} + new_captcha = method().new() + + secret_key_base = Pleroma.Config.get!([Pleroma.Web.Endpoint, :secret_key_base]) + + # This make salt a little different for two keys + token = new_captcha[:token] + secret = KeyGenerator.generate(secret_key_base, token <> "_encrypt") + sign_secret = KeyGenerator.generate(secret_key_base, token <> "_sign") + # Basicallty copy what Phoenix.Token does here, add the time to + # the actual data and make it a binary to then encrypt it + encrypted_captcha_answer = + %{ + at: DateTime.now_utc(), + answer_data: new_captcha[:answer_data] + } + |> :erlang.term_to_binary() + |> MessageEncryptor.encrypt(secret, sign_secret) + + IO.inspect(%{new_captcha | answer_data: encrypted_captcha_answer}) + + { + :reply, + # Repalce the answer with the encrypted answer + %{new_captcha | answer_data: encrypted_captcha_answer}, + state + } end end @doc false def handle_call({:validate, token, captcha, answer_data}, _from, state) do - {:reply, method().validate(token, captcha, answer_data), state} + secret_key_base = Pleroma.Config.get!([Pleroma.Web.Endpoint, :secret_key_base]) + secret = KeyGenerator.generate(secret_key_base, token <> "_encrypt") + sign_secret = KeyGenerator.generate(secret_key_base, token <> "_sign") + + # If the time found is less than (current_time - seconds_valid), then the time has already passed. + # Later we check that the time found is more than the presumed invalidatation time, that means + # that the data is still valid and the captcha can be checked + seconds_valid = Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]) + valid_if_after = DateTime.subtract!(DateTime.now_utc(), seconds_valid) + + result = + with {:ok, data} <- MessageEncryptor.decrypt(answer_data, secret, sign_secret), + %{at: at, answer_data: answer_md5} <- :erlang.binary_to_term(data) do + if DateTime.after?(at, valid_if_after), + do: method().validate(token, captcha, answer_md5), + else: {:error, "CAPTCHA expired"} + else + _ -> {:error, "Invalid answer data"} + end + + {:reply, result, state} end defp method, do: Pleroma.Config.get!([__MODULE__, :method]) diff --git a/lib/pleroma/captcha/captcha_service.ex b/lib/pleroma/captcha/captcha_service.ex index 6f36d29b0..6c5ab6c36 100644 --- a/lib/pleroma/captcha/captcha_service.ex +++ b/lib/pleroma/captcha/captcha_service.ex @@ -4,9 +4,14 @@ defmodule Pleroma.Captcha.Service do Returns: - Service-specific data for using the newly created captcha + Type/Name of the service, the token to identify the captcha, + the data of the answer and service-specific data to use the newly created captcha """ - @callback new() :: map + @callback new() :: %{ + type: atom(), + token: String.t(), + answer_data: any() + } @doc """ Validated the provided captcha solution. @@ -23,6 +28,6 @@ defmodule Pleroma.Captcha.Service do @callback validate( token :: String.t(), captcha :: String.t(), - answer_data :: String.t() + answer_data :: any() ) :: :ok | {:error, String.t()} end diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex index f881c7b65..cd0eb6f21 100644 --- a/lib/pleroma/captcha/kocaptcha.ex +++ b/lib/pleroma/captcha/kocaptcha.ex @@ -1,8 +1,4 @@ defmodule Pleroma.Captcha.Kocaptcha do - alias Plug.Crypto.KeyGenerator - alias Plug.Crypto.MessageEncryptor - alias Calendar.DateTime - alias Pleroma.Captcha.Service @behaviour Service @@ -17,57 +13,21 @@ defmodule Pleroma.Captcha.Kocaptcha do {:ok, res} -> json_resp = Poison.decode!(res.body) - token = json_resp["token"] - answer_md5 = json_resp["md5"] - - secret_key_base = Pleroma.Config.get!([Pleroma.Web.Endpoint, :secret_key_base]) - - # This make salt a little different for two keys - secret = KeyGenerator.generate(secret_key_base, token <> "_encrypt") - sign_secret = KeyGenerator.generate(secret_key_base, token <> "_sign") - # Basicallty copy what Phoenix.Token does here, add the time to - # the actual data and make it a binary to then encrypt it - encrypted_captcha_answer = - %{ - at: DateTime.now_utc(), - answer_md5: answer_md5 - } - |> :erlang.term_to_binary() - |> MessageEncryptor.encrypt(secret, sign_secret) - %{ type: :kocaptcha, - token: token, + token: json_resp["token"], url: endpoint <> json_resp["url"], - answer_data: encrypted_captcha_answer + answer_data: json_resp["md5"] } end end @impl Service - def validate(token, captcha, answer_data) do - secret_key_base = Pleroma.Config.get!([Pleroma.Web.Endpoint, :secret_key_base]) - secret = KeyGenerator.generate(secret_key_base, token <> "_encrypt") - sign_secret = KeyGenerator.generate(secret_key_base, token <> "_sign") - - # If the time found is less than (current_time - seconds_valid), then the time has already passed. - # Later we check that the time found is more than the presumed invalidatation time, that means - # that the data is still valid and the captcha can be checked - seconds_valid = Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]) - valid_if_after = DateTime.subtract!(DateTime.now_utc(), seconds_valid) - - with {:ok, data} <- MessageEncryptor.decrypt(answer_data, secret, sign_secret), - %{at: at, answer_md5: answer_md5} <- :erlang.binary_to_term(data) do - if DateTime.after?(at, valid_if_after) do - if not is_nil(captcha) and - :crypto.hash(:md5, captcha) |> Base.encode16() == String.upcase(answer_md5), - do: :ok, - else: {:error, "Invalid CAPTCHA"} - else - {:error, "CAPTCHA expired"} - end - else - _ -> {:error, "Invalid answer data"} - end + def validate(_token, captcha, answer_data) do + # Here the token is unsed, because the unencrypted captcha answer is just passed to method + if not is_nil(captcha) and + :crypto.hash(:md5, captcha) |> Base.encode16() == String.upcase(answer_data), + do: :ok, + else: {:error, "Invalid CAPTCHA"} end end -- cgit v1.2.3 From 92362e1e22a3debfaf3275822519417ee8755a7a Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 22 Dec 2018 23:18:31 +0100 Subject: Implement large thread filter --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex new file mode 100644 index 000000000..0e0918126 --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -0,0 +1,15 @@ +defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do + @behaviour Pleroma.Web.ActivityPub.MRF + + @impl true + def filter(object) do + + policy = Pleroma.Config.get(:mrf_hellthreadmitigation) + + if (length(object["to"]) + length(object["cc"])) > Keyword.get(policy, :threshold) do + {:reject, nil} + else + {:ok, object} + end + end +end \ No newline at end of file -- cgit v1.2.3 From 409ff60bf87d40919ec8cfcbe054cb66b87ca972 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 22 Dec 2018 23:32:38 +0100 Subject: Fix formatting --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 0e0918126..edcbc5219 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -3,13 +3,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do @impl true def filter(object) do - policy = Pleroma.Config.get(:mrf_hellthreadmitigation) - if (length(object["to"]) + length(object["cc"])) > Keyword.get(policy, :threshold) do + if length(object["to"]) + length(object["cc"]) > Keyword.get(policy, :threshold) do {:reject, nil} else {:ok, object} end end -end \ No newline at end of file +end -- cgit v1.2.3 From c76179419d5d4bb2423496856ad931974b56d6d5 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sun, 23 Dec 2018 11:14:29 +0100 Subject: Renamed the things --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index edcbc5219..d5aa2b988 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -3,7 +3,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do @impl true def filter(object) do - policy = Pleroma.Config.get(:mrf_hellthreadmitigation) + policy = Pleroma.Config.get(:mrf_hellthread) if length(object["to"]) + length(object["cc"]) > Keyword.get(policy, :threshold) do {:reject, nil} -- cgit v1.2.3 From a7f07bb6e56ad5173b9c2063d7f920cd102b4f2d Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sun, 23 Dec 2018 12:24:53 +0100 Subject: Implement kaniini's tweaks --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index d5aa2b988..55d6ff3f0 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -2,13 +2,17 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do @behaviour Pleroma.Web.ActivityPub.MRF @impl true - def filter(object) do - policy = Pleroma.Config.get(:mrf_hellthread) + def filter(%{"type" => "Create"} = object) do + threshold = Pleroma.Config.get([:mrf_hellthread, :threshold]) + recipients = (object["to"] || []) ++ (object["cc"] || []) - if length(object["to"]) + length(object["cc"]) > Keyword.get(policy, :threshold) do + if length(recipients) > threshold do {:reject, nil} else {:ok, object} end end + + @impl true + def filter(object), do: {:ok, object} end -- cgit v1.2.3 From 3aff8067e4b65962fe65812807cbb52bd971ddd8 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 17 Nov 2018 18:34:45 +0100 Subject: =?UTF-8?q?transmogrifier:=20When=20it=E2=80=99s=20a=20Video=20mov?= =?UTF-8?q?e=20"url"=20to=20"attachment"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/web/activity_pub/transmogrifier.ex | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index e6af4b211..d5cc82918 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -69,8 +69,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do def fix_object(object) do object |> fix_actor - |> fix_attachments |> fix_url + |> fix_attachments |> fix_context |> fix_in_reply_to |> fix_emoji @@ -200,8 +200,14 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do true -> "" end - object - |> Map.put("url", url_string) + if Map.get(object, "type") == "Video" do + object + |> Map.delete("url") + |> Map.put("attachment", url_string) + else + object + |> Map.put("url", url_string) + end end def fix_url(object), do: object -- cgit v1.2.3 From 71f6d9f418087a16ff266ef380b3290088e0d301 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 13:28:17 +0000 Subject: transmogrifier: significantly rework handling of peertube videos, add test --- lib/pleroma/web/activity_pub/transmogrifier.ex | 37 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index d5cc82918..4bc96b00d 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -170,8 +170,14 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do attachments = attachment |> Enum.map(fn data -> - url = [%{"type" => "Link", "mediaType" => data["mediaType"], "href" => data["url"]}] - Map.put(data, "url", url) + media_type = data["mediaType"] || data["mimeType"] + href = data["url"] || data["href"] + + url = [%{"type" => "Link", "mediaType" => media_type, "href" => href}] + + data + |> Map.put("mediaType", media_type) + |> Map.put("url", url) end) object @@ -190,7 +196,22 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do |> Map.put("url", url["href"]) end - def fix_url(%{"url" => url} = object) when is_list(url) do + def fix_url(%{"type" => "Video", "url" => url} = object) when is_list(url) do + first_element = Enum.at(url, 0) + + link_element = + url + |> Enum.filter(fn x -> is_map(x) end) + |> Enum.filter(fn x -> x["mimeType"] == "text/html" end) + |> Enum.at(0) + + object + |> Map.put("attachment", [first_element]) + |> Map.put("url", link_element["href"]) + end + + def fix_url(%{"type" => object_type, "url" => url} = object) + when object_type != "Video" and is_list(url) do first_element = Enum.at(url, 0) url_string = @@ -200,14 +221,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do true -> "" end - if Map.get(object, "type") == "Video" do - object - |> Map.delete("url") - |> Map.put("attachment", url_string) - else - object - |> Map.put("url", url_string) - end + object + |> Map.put("url", url_string) end def fix_url(object), do: object -- cgit v1.2.3 From 32dfc1d12a29004ef3d90c8405d25e49e74c80ab Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 13:40:33 +0000 Subject: mastodon api: status view: remove obsolete peertube hack --- lib/pleroma/web/mastodon_api/views/status_view.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 46c559e3a..d06da812c 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -106,7 +106,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || []) attachment_data = object["attachment"] || [] - attachment_data = attachment_data ++ if object["type"] == "Video", do: [object], else: [] attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment) created_at = Utils.to_masto_date(object["published"]) -- cgit v1.2.3 From 79b51a97fe9479948d429f095c5b07bc78ab5edf Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 13:53:25 +0000 Subject: twitter api: activity representer: remove peertube hack --- lib/pleroma/web/twitter_api/representers/activity_representer.ex | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 2808192b0..d9dd352be 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -171,14 +171,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do HTML.filter_tags(content, User.html_filter_policy(opts[:for])) |> Formatter.emojify(object["emoji"]) - video = - if object["type"] == "Video" do - [object] - else - [] - end - - attachments = (object["attachment"] || []) ++ video + attachments = object["attachment"] || [] reply_parent = Activity.get_in_reply_to_activity(activity) -- cgit v1.2.3 From 34a4ed22c4904270b1c5c2acab09e995d9a8d6dd Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 13:58:45 +0000 Subject: twitter api: add "Video" to supported activity types list --- lib/pleroma/web/twitter_api/views/activity_view.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 91d086740..c37d5486a 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -301,7 +301,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do {summary, content} end - def render_content(%{"type" => object_type} = object) when object_type in ["Article", "Page"] do + def render_content(%{"type" => object_type} = object) + when object_type in ["Article", "Page", "Video"] do summary = object["name"] || object["summary"] content = -- cgit v1.2.3 From 2791ce9a1ff2365ac7256f5e1dc2324dee2f82c9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 20:04:54 +0000 Subject: add license boilerplate to pleroma core --- lib/pleroma/PasswordResetToken.ex | 4 ++++ lib/pleroma/activity.ex | 4 ++++ lib/pleroma/application.ex | 4 ++++ lib/pleroma/captcha/captcha.ex | 4 ++++ lib/pleroma/captcha/captcha_service.ex | 4 ++++ lib/pleroma/captcha/kocaptcha.ex | 4 ++++ lib/pleroma/config.ex | 4 ++++ lib/pleroma/emails/mailer.ex | 4 ++++ lib/pleroma/emails/user_email.ex | 4 ++++ lib/pleroma/emoji.ex | 4 ++++ lib/pleroma/filter.ex | 4 ++++ lib/pleroma/formatter.ex | 4 ++++ lib/pleroma/gopher/server.ex | 4 ++++ lib/pleroma/html.ex | 4 ++++ lib/pleroma/http/connection.ex | 4 ++++ lib/pleroma/http/http.ex | 4 ++++ lib/pleroma/http/request_builder.ex | 4 ++++ lib/pleroma/list.ex | 4 ++++ lib/pleroma/mime.ex | 4 ++++ lib/pleroma/notification.ex | 4 ++++ lib/pleroma/object.ex | 4 ++++ lib/pleroma/plugs/admin_secret_authentication_plug.ex | 4 ++++ lib/pleroma/plugs/authentication_plug.ex | 4 ++++ lib/pleroma/plugs/basic_auth_decoder_plug.ex | 4 ++++ lib/pleroma/plugs/digest.ex | 4 ++++ lib/pleroma/plugs/ensure_authenticated_plug.ex | 4 ++++ lib/pleroma/plugs/ensure_user_key_plug.ex | 4 ++++ lib/pleroma/plugs/federating_plug.ex | 4 ++++ lib/pleroma/plugs/http_security_plug.ex | 4 ++++ lib/pleroma/plugs/http_signature.ex | 4 ++++ lib/pleroma/plugs/instance_static.ex | 4 ++++ lib/pleroma/plugs/legacy_authentication_plug.ex | 4 ++++ lib/pleroma/plugs/oauth_plug.ex | 4 ++++ lib/pleroma/plugs/session_authentication_plug.ex | 4 ++++ lib/pleroma/plugs/set_user_session_id_plug.ex | 4 ++++ lib/pleroma/plugs/uploaded_media.ex | 4 ++++ lib/pleroma/plugs/user_enabled_plug.ex | 4 ++++ lib/pleroma/plugs/user_fetcher_plug.ex | 4 ++++ lib/pleroma/plugs/user_is_admin_plug.ex | 4 ++++ lib/pleroma/repo.ex | 4 ++++ lib/pleroma/reverse_proxy.ex | 4 ++++ lib/pleroma/stats.ex | 4 ++++ lib/pleroma/upload.ex | 4 ++++ lib/pleroma/upload/filter.ex | 4 ++++ lib/pleroma/upload/filter/anonymize_filename.ex | 4 ++++ lib/pleroma/upload/filter/dedupe.ex | 4 ++++ lib/pleroma/upload/filter/mogrifun.ex | 4 ++++ lib/pleroma/upload/filter/mogrify.ex | 4 ++++ lib/pleroma/uploaders/local.ex | 4 ++++ lib/pleroma/uploaders/mdii.ex | 4 ++++ lib/pleroma/uploaders/s3.ex | 4 ++++ lib/pleroma/uploaders/swift/keystone.ex | 4 ++++ lib/pleroma/uploaders/swift/swift.ex | 4 ++++ lib/pleroma/uploaders/swift/uploader.ex | 4 ++++ lib/pleroma/uploaders/uploader.ex | 4 ++++ lib/pleroma/user.ex | 4 ++++ lib/pleroma/user/info.ex | 4 ++++ lib/pleroma/user_invite_token.ex | 4 ++++ lib/pleroma/web/activity_pub/activity_pub.ex | 4 ++++ lib/pleroma/web/activity_pub/activity_pub_controller.ex | 4 ++++ lib/pleroma/web/activity_pub/mrf.ex | 4 ++++ lib/pleroma/web/activity_pub/mrf/drop_policy.ex | 4 ++++ lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex | 4 ++++ lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 4 ++++ lib/pleroma/web/activity_pub/mrf/noop_policy.ex | 4 ++++ lib/pleroma/web/activity_pub/mrf/normalize_markup.ex | 4 ++++ lib/pleroma/web/activity_pub/mrf/reject_non_public.ex | 4 ++++ lib/pleroma/web/activity_pub/mrf/simple_policy.ex | 4 ++++ lib/pleroma/web/activity_pub/mrf/user_allowlist.ex | 4 ++++ lib/pleroma/web/activity_pub/relay.ex | 4 ++++ lib/pleroma/web/activity_pub/transmogrifier.ex | 4 ++++ lib/pleroma/web/activity_pub/utils.ex | 4 ++++ lib/pleroma/web/activity_pub/views/object_view.ex | 4 ++++ lib/pleroma/web/activity_pub/views/user_view.ex | 4 ++++ lib/pleroma/web/admin_api/admin_api_controller.ex | 4 ++++ lib/pleroma/web/channels/user_socket.ex | 4 ++++ lib/pleroma/web/chat_channel.ex | 4 ++++ lib/pleroma/web/common_api/common_api.ex | 4 ++++ lib/pleroma/web/common_api/utils.ex | 4 ++++ lib/pleroma/web/controller_helper.ex | 4 ++++ lib/pleroma/web/endpoint.ex | 4 ++++ lib/pleroma/web/federator/federator.ex | 4 ++++ lib/pleroma/web/federator/retry_queue.ex | 4 ++++ lib/pleroma/web/gettext.ex | 4 ++++ lib/pleroma/web/http_signatures/http_signatures.ex | 4 ++++ lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 4 ++++ lib/pleroma/web/mastodon_api/views/account_view.ex | 4 ++++ lib/pleroma/web/mastodon_api/views/filter_view.ex | 4 ++++ lib/pleroma/web/mastodon_api/views/list_view.ex | 4 ++++ lib/pleroma/web/mastodon_api/views/mastodon_view.ex | 4 ++++ lib/pleroma/web/mastodon_api/views/push_subscription_view.ex | 4 ++++ lib/pleroma/web/mastodon_api/views/status_view.ex | 4 ++++ lib/pleroma/web/mastodon_api/websocket_handler.ex | 4 ++++ lib/pleroma/web/media_proxy/controller.ex | 4 ++++ lib/pleroma/web/media_proxy/media_proxy.ex | 4 ++++ lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 4 ++++ lib/pleroma/web/oauth/app.ex | 4 ++++ lib/pleroma/web/oauth/authorization.ex | 4 ++++ lib/pleroma/web/oauth/fallback_controller.ex | 4 ++++ lib/pleroma/web/oauth/oauth_controller.ex | 4 ++++ lib/pleroma/web/oauth/oauth_view.ex | 4 ++++ lib/pleroma/web/oauth/token.ex | 4 ++++ lib/pleroma/web/ostatus/activity_representer.ex | 4 ++++ lib/pleroma/web/ostatus/feed_representer.ex | 4 ++++ lib/pleroma/web/ostatus/handlers/delete_handler.ex | 4 ++++ lib/pleroma/web/ostatus/handlers/follow_handler.ex | 4 ++++ lib/pleroma/web/ostatus/handlers/note_handler.ex | 4 ++++ lib/pleroma/web/ostatus/handlers/unfollow_handler.ex | 4 ++++ lib/pleroma/web/ostatus/ostatus.ex | 4 ++++ lib/pleroma/web/ostatus/ostatus_controller.ex | 4 ++++ lib/pleroma/web/ostatus/user_representer.ex | 4 ++++ lib/pleroma/web/push/push.ex | 4 ++++ lib/pleroma/web/push/subscription.ex | 4 ++++ lib/pleroma/web/router.ex | 4 ++++ lib/pleroma/web/salmon/salmon.ex | 4 ++++ lib/pleroma/web/streamer.ex | 4 ++++ lib/pleroma/web/twitter_api/controllers/util_controller.ex | 4 ++++ lib/pleroma/web/twitter_api/representers/activity_representer.ex | 4 ++++ lib/pleroma/web/twitter_api/representers/base_representer.ex | 4 ++++ lib/pleroma/web/twitter_api/representers/object_representer.ex | 4 ++++ lib/pleroma/web/twitter_api/twitter_api.ex | 4 ++++ lib/pleroma/web/twitter_api/twitter_api_controller.ex | 4 ++++ lib/pleroma/web/twitter_api/views/activity_view.ex | 4 ++++ lib/pleroma/web/twitter_api/views/notification_view.ex | 4 ++++ lib/pleroma/web/twitter_api/views/user_view.ex | 4 ++++ lib/pleroma/web/twitter_api/views/util_view.ex | 4 ++++ lib/pleroma/web/views/error_helpers.ex | 4 ++++ lib/pleroma/web/views/error_view.ex | 4 ++++ lib/pleroma/web/views/layout_view.ex | 4 ++++ lib/pleroma/web/web.ex | 4 ++++ lib/pleroma/web/web_finger/web_finger.ex | 4 ++++ lib/pleroma/web/web_finger/web_finger_controller.ex | 4 ++++ lib/pleroma/web/websub/websub.ex | 4 ++++ lib/pleroma/web/websub/websub_client_subscription.ex | 4 ++++ lib/pleroma/web/websub/websub_controller.ex | 4 ++++ lib/pleroma/web/websub/websub_server_subscription.ex | 4 ++++ lib/pleroma/web/xml/xml.ex | 4 ++++ 137 files changed, 548 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/PasswordResetToken.ex b/lib/pleroma/PasswordResetToken.ex index 15750565b..57e3b7ef0 100644 --- a/lib/pleroma/PasswordResetToken.ex +++ b/lib/pleroma/PasswordResetToken.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.PasswordResetToken do use Ecto.Schema diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 200addd6e..34b665765 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Activity do use Ecto.Schema alias Pleroma.{Repo, Activity, Notification} diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index e15991957..36a3694f2 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Application do use Application import Supervisor.Spec diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index 5630f6b57..f80946c8b 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Captcha do use GenServer diff --git a/lib/pleroma/captcha/captcha_service.ex b/lib/pleroma/captcha/captcha_service.ex index 8d0b76f86..6037b7087 100644 --- a/lib/pleroma/captcha/captcha_service.ex +++ b/lib/pleroma/captcha/captcha_service.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Captcha.Service do @doc """ Request new captcha from a captcha service. diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex index 51900d123..54f4c8bcd 100644 --- a/lib/pleroma/captcha/kocaptcha.ex +++ b/lib/pleroma/captcha/kocaptcha.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Captcha.Kocaptcha do alias Calendar.DateTime diff --git a/lib/pleroma/config.ex b/lib/pleroma/config.ex index 3876ddf1f..6b1598d66 100644 --- a/lib/pleroma/config.ex +++ b/lib/pleroma/config.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Config do defmodule Error do defexception [:message] diff --git a/lib/pleroma/emails/mailer.ex b/lib/pleroma/emails/mailer.ex index 14ed32ea8..a8bd70b6e 100644 --- a/lib/pleroma/emails/mailer.ex +++ b/lib/pleroma/emails/mailer.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Mailer do use Swoosh.Mailer, otp_app: :pleroma end diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index 8f916f470..688b0cd1c 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.UserEmail do @moduledoc "User emails" diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex index bedad99d6..b5e0a83d8 100644 --- a/lib/pleroma/emoji.ex +++ b/lib/pleroma/emoji.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Emoji do @moduledoc """ The emojis are loaded from: diff --git a/lib/pleroma/filter.ex b/lib/pleroma/filter.ex index c57bd3bf8..9ddc5fd6c 100644 --- a/lib/pleroma/filter.ex +++ b/lib/pleroma/filter.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Filter do use Ecto.Schema import Ecto.{Changeset, Query} diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 72fe9640b..49a9913dc 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Formatter do alias Pleroma.User alias Pleroma.Web.MediaProxy diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index 4d582ef25..fee7156d3 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Gopher.Server do use GenServer require Logger diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 583f05aeb..a0473676b 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.HTML do alias HtmlSanitizeEx.Scrubber diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index 7b11060b2..35c1490da 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.HTTP.Connection do @moduledoc """ Connection for http-requests. diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex index 3c0256575..e572dfedf 100644 --- a/lib/pleroma/http/http.ex +++ b/lib/pleroma/http/http.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.HTTP do @moduledoc """ diff --git a/lib/pleroma/http/request_builder.ex b/lib/pleroma/http/request_builder.ex index 5aee2b8ae..54569c6f7 100644 --- a/lib/pleroma/http/request_builder.ex +++ b/lib/pleroma/http/request_builder.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.HTTP.RequestBuilder do @moduledoc """ Helper functions for building Tesla requests diff --git a/lib/pleroma/list.ex b/lib/pleroma/list.ex index c5bf3e083..2c799bc33 100644 --- a/lib/pleroma/list.ex +++ b/lib/pleroma/list.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.List do use Ecto.Schema import Ecto.{Changeset, Query} diff --git a/lib/pleroma/mime.ex b/lib/pleroma/mime.ex index 2cb3d8bd1..e3a389749 100644 --- a/lib/pleroma/mime.ex +++ b/lib/pleroma/mime.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.MIME do @moduledoc """ Returns the mime-type of a binary and optionally a normalized file-name. diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 47f6b6ee7..301cfd134 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Notification do use Ecto.Schema alias Pleroma.{User, Activity, Notification, Repo, Object} diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 31c8dd5bd..cc4a2181a 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Object do use Ecto.Schema alias Pleroma.{Repo, Object, User, Activity} diff --git a/lib/pleroma/plugs/admin_secret_authentication_plug.ex b/lib/pleroma/plugs/admin_secret_authentication_plug.ex index f61a6ee24..2c9348715 100644 --- a/lib/pleroma/plugs/admin_secret_authentication_plug.ex +++ b/lib/pleroma/plugs/admin_secret_authentication_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.AdminSecretAuthenticationPlug do import Plug.Conn alias Pleroma.User diff --git a/lib/pleroma/plugs/authentication_plug.ex b/lib/pleroma/plugs/authentication_plug.ex index b240ff29f..6b8d51300 100644 --- a/lib/pleroma/plugs/authentication_plug.ex +++ b/lib/pleroma/plugs/authentication_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.AuthenticationPlug do alias Comeonin.Pbkdf2 import Plug.Conn diff --git a/lib/pleroma/plugs/basic_auth_decoder_plug.ex b/lib/pleroma/plugs/basic_auth_decoder_plug.ex index f7ebf7db2..0690f4bea 100644 --- a/lib/pleroma/plugs/basic_auth_decoder_plug.ex +++ b/lib/pleroma/plugs/basic_auth_decoder_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.BasicAuthDecoderPlug do import Plug.Conn diff --git a/lib/pleroma/plugs/digest.ex b/lib/pleroma/plugs/digest.ex index 9d6bbb085..27b206965 100644 --- a/lib/pleroma/plugs/digest.ex +++ b/lib/pleroma/plugs/digest.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Plugs.DigestPlug do alias Plug.Conn require Logger diff --git a/lib/pleroma/plugs/ensure_authenticated_plug.ex b/lib/pleroma/plugs/ensure_authenticated_plug.ex index bca44eb2c..f18653f41 100644 --- a/lib/pleroma/plugs/ensure_authenticated_plug.ex +++ b/lib/pleroma/plugs/ensure_authenticated_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.EnsureAuthenticatedPlug do import Plug.Conn alias Pleroma.User diff --git a/lib/pleroma/plugs/ensure_user_key_plug.ex b/lib/pleroma/plugs/ensure_user_key_plug.ex index 05a567757..db3da228d 100644 --- a/lib/pleroma/plugs/ensure_user_key_plug.ex +++ b/lib/pleroma/plugs/ensure_user_key_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.EnsureUserKeyPlug do import Plug.Conn diff --git a/lib/pleroma/plugs/federating_plug.ex b/lib/pleroma/plugs/federating_plug.ex index b5326d97b..e7dfda295 100644 --- a/lib/pleroma/plugs/federating_plug.ex +++ b/lib/pleroma/plugs/federating_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.FederatingPlug do import Plug.Conn diff --git a/lib/pleroma/plugs/http_security_plug.ex b/lib/pleroma/plugs/http_security_plug.ex index f34f2364b..11bceafd4 100644 --- a/lib/pleroma/plugs/http_security_plug.ex +++ b/lib/pleroma/plugs/http_security_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.HTTPSecurityPlug do alias Pleroma.Config import Plug.Conn diff --git a/lib/pleroma/plugs/http_signature.ex b/lib/pleroma/plugs/http_signature.ex index 9e53371b7..33fbba840 100644 --- a/lib/pleroma/plugs/http_signature.ex +++ b/lib/pleroma/plugs/http_signature.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do alias Pleroma.Web.HTTPSignatures alias Pleroma.Web.ActivityPub.Utils diff --git a/lib/pleroma/plugs/instance_static.ex b/lib/pleroma/plugs/instance_static.ex index 46ee77e11..02ee99e0f 100644 --- a/lib/pleroma/plugs/instance_static.ex +++ b/lib/pleroma/plugs/instance_static.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.InstanceStatic do @moduledoc """ This is a shim to call `Plug.Static` but with runtime `from` configuration. diff --git a/lib/pleroma/plugs/legacy_authentication_plug.ex b/lib/pleroma/plugs/legacy_authentication_plug.ex index d22c1a647..3cb3fdf4b 100644 --- a/lib/pleroma/plugs/legacy_authentication_plug.ex +++ b/lib/pleroma/plugs/legacy_authentication_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.LegacyAuthenticationPlug do import Plug.Conn alias Pleroma.User diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 13c914c1b..7c3541197 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.OAuthPlug do import Plug.Conn import Ecto.Query diff --git a/lib/pleroma/plugs/session_authentication_plug.ex b/lib/pleroma/plugs/session_authentication_plug.ex index aed619432..413bdcf2c 100644 --- a/lib/pleroma/plugs/session_authentication_plug.ex +++ b/lib/pleroma/plugs/session_authentication_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.SessionAuthenticationPlug do import Plug.Conn diff --git a/lib/pleroma/plugs/set_user_session_id_plug.ex b/lib/pleroma/plugs/set_user_session_id_plug.ex index adc0a42b5..9fad6dfee 100644 --- a/lib/pleroma/plugs/set_user_session_id_plug.ex +++ b/lib/pleroma/plugs/set_user_session_id_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.SetUserSessionIdPlug do import Plug.Conn alias Pleroma.User diff --git a/lib/pleroma/plugs/uploaded_media.ex b/lib/pleroma/plugs/uploaded_media.ex index 7e1e84126..f998293e8 100644 --- a/lib/pleroma/plugs/uploaded_media.ex +++ b/lib/pleroma/plugs/uploaded_media.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.UploadedMedia do @moduledoc """ """ diff --git a/lib/pleroma/plugs/user_enabled_plug.ex b/lib/pleroma/plugs/user_enabled_plug.ex index 01482f47d..79d6a9b99 100644 --- a/lib/pleroma/plugs/user_enabled_plug.ex +++ b/lib/pleroma/plugs/user_enabled_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.UserEnabledPlug do import Plug.Conn alias Pleroma.User diff --git a/lib/pleroma/plugs/user_fetcher_plug.ex b/lib/pleroma/plugs/user_fetcher_plug.ex index e24785ad1..04957148b 100644 --- a/lib/pleroma/plugs/user_fetcher_plug.ex +++ b/lib/pleroma/plugs/user_fetcher_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.UserFetcherPlug do import Plug.Conn alias Pleroma.Repo diff --git a/lib/pleroma/plugs/user_is_admin_plug.ex b/lib/pleroma/plugs/user_is_admin_plug.ex index cf22ce5d0..a98c2c853 100644 --- a/lib/pleroma/plugs/user_is_admin_plug.ex +++ b/lib/pleroma/plugs/user_is_admin_plug.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Plugs.UserIsAdminPlug do import Plug.Conn alias Pleroma.User diff --git a/lib/pleroma/repo.ex b/lib/pleroma/repo.ex index 7cecd7b38..0b49f7712 100644 --- a/lib/pleroma/repo.ex +++ b/lib/pleroma/repo.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Repo do use Ecto.Repo, otp_app: :pleroma diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index 7f328d00d..c9d6f0d2c 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.ReverseProxy do @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since if-none-match if-range range) @resp_cache_headers ~w(etag date last-modified cache-control) diff --git a/lib/pleroma/stats.ex b/lib/pleroma/stats.ex index 8478fe4ce..c48184ed3 100644 --- a/lib/pleroma/stats.ex +++ b/lib/pleroma/stats.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Stats do import Ecto.Query alias Pleroma.{User, Repo} diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 07031ac58..744abec56 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Upload do @moduledoc """ # Upload diff --git a/lib/pleroma/upload/filter.ex b/lib/pleroma/upload/filter.ex index d1384ddad..f7257be65 100644 --- a/lib/pleroma/upload/filter.ex +++ b/lib/pleroma/upload/filter.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Upload.Filter do @moduledoc """ Upload Filter behaviour diff --git a/lib/pleroma/upload/filter/anonymize_filename.ex b/lib/pleroma/upload/filter/anonymize_filename.ex index 39eed7af3..c26e4f32c 100644 --- a/lib/pleroma/upload/filter/anonymize_filename.ex +++ b/lib/pleroma/upload/filter/anonymize_filename.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Upload.Filter.AnonymizeFilename do @moduledoc """ Replaces the original filename with a pre-defined text or randomly generated string. diff --git a/lib/pleroma/upload/filter/dedupe.ex b/lib/pleroma/upload/filter/dedupe.ex index 0657b2c8d..2d1ddab7f 100644 --- a/lib/pleroma/upload/filter/dedupe.ex +++ b/lib/pleroma/upload/filter/dedupe.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Upload.Filter.Dedupe do @behaviour Pleroma.Upload.Filter alias Pleroma.Upload diff --git a/lib/pleroma/upload/filter/mogrifun.ex b/lib/pleroma/upload/filter/mogrifun.ex index 4d4f0b401..f8920d31b 100644 --- a/lib/pleroma/upload/filter/mogrifun.ex +++ b/lib/pleroma/upload/filter/mogrifun.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Upload.Filter.Mogrifun do @behaviour Pleroma.Upload.Filter diff --git a/lib/pleroma/upload/filter/mogrify.ex b/lib/pleroma/upload/filter/mogrify.ex index f106bd4b1..7331c2bd9 100644 --- a/lib/pleroma/upload/filter/mogrify.ex +++ b/lib/pleroma/upload/filter/mogrify.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Upload.Filter.Mogrify do @behaviour Pleroma.Upload.Filter diff --git a/lib/pleroma/uploaders/local.ex b/lib/pleroma/uploaders/local.ex index 2994bcd51..de50a13c1 100644 --- a/lib/pleroma/uploaders/local.ex +++ b/lib/pleroma/uploaders/local.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Uploaders.Local do @behaviour Pleroma.Uploaders.Uploader diff --git a/lib/pleroma/uploaders/mdii.ex b/lib/pleroma/uploaders/mdii.ex index f06755056..b16782fbb 100644 --- a/lib/pleroma/uploaders/mdii.ex +++ b/lib/pleroma/uploaders/mdii.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Uploaders.MDII do alias Pleroma.Config diff --git a/lib/pleroma/uploaders/s3.ex b/lib/pleroma/uploaders/s3.ex index 19832a7ec..db5e8b75e 100644 --- a/lib/pleroma/uploaders/s3.ex +++ b/lib/pleroma/uploaders/s3.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Uploaders.S3 do @behaviour Pleroma.Uploaders.Uploader require Logger diff --git a/lib/pleroma/uploaders/swift/keystone.ex b/lib/pleroma/uploaders/swift/keystone.ex index 4aed977b1..f10361b19 100644 --- a/lib/pleroma/uploaders/swift/keystone.ex +++ b/lib/pleroma/uploaders/swift/keystone.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Uploaders.Swift.Keystone do use HTTPoison.Base diff --git a/lib/pleroma/uploaders/swift/swift.ex b/lib/pleroma/uploaders/swift/swift.ex index d4e758bbb..fef426b42 100644 --- a/lib/pleroma/uploaders/swift/swift.ex +++ b/lib/pleroma/uploaders/swift/swift.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Uploaders.Swift.Client do use HTTPoison.Base diff --git a/lib/pleroma/uploaders/swift/uploader.ex b/lib/pleroma/uploaders/swift/uploader.ex index b35b9807b..d359ff8f8 100644 --- a/lib/pleroma/uploaders/swift/uploader.ex +++ b/lib/pleroma/uploaders/swift/uploader.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Uploaders.Swift do @behaviour Pleroma.Uploaders.Uploader diff --git a/lib/pleroma/uploaders/uploader.ex b/lib/pleroma/uploaders/uploader.ex index afda5609e..49da6e9a9 100644 --- a/lib/pleroma/uploaders/uploader.ex +++ b/lib/pleroma/uploaders/uploader.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Uploaders.Uploader do @moduledoc """ Defines the contract to put and get an uploaded file to any backend. diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index f8827abec..1f930479d 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.User do use Ecto.Schema diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 3de4af56c..71848d91e 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.User.Info do use Ecto.Schema import Ecto.Changeset diff --git a/lib/pleroma/user_invite_token.ex b/lib/pleroma/user_invite_token.ex index ce804f78e..65ffe149c 100644 --- a/lib/pleroma/user_invite_token.ex +++ b/lib/pleroma/user_invite_token.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.UserInviteToken do use Ecto.Schema diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 31455343c..188060780 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.ActivityPub do alias Pleroma.{Activity, Repo, Object, Upload, User, Notification} alias Pleroma.Web.ActivityPub.{Transmogrifier, MRF} diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 0317f3c8c..7fd6a45f5 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.ActivityPubController do use Pleroma.Web, :controller alias Pleroma.{User, Object} diff --git a/lib/pleroma/web/activity_pub/mrf.ex b/lib/pleroma/web/activity_pub/mrf.ex index 0a4e2bf80..00919a5f6 100644 --- a/lib/pleroma/web/activity_pub/mrf.ex +++ b/lib/pleroma/web/activity_pub/mrf.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.MRF do @callback filter(Map.t()) :: {:ok | :reject, Map.t()} diff --git a/lib/pleroma/web/activity_pub/mrf/drop_policy.ex b/lib/pleroma/web/activity_pub/mrf/drop_policy.ex index 811947943..6ac7b0ec1 100644 --- a/lib/pleroma/web/activity_pub/mrf/drop_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/drop_policy.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do require Logger @behaviour Pleroma.Web.ActivityPub.MRF diff --git a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex index 6fa48454a..ca3ee8a0d 100644 --- a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex +++ b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do alias Pleroma.Object diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 55d6ff3f0..e4fb0b5b0 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do @behaviour Pleroma.Web.ActivityPub.MRF diff --git a/lib/pleroma/web/activity_pub/mrf/noop_policy.ex b/lib/pleroma/web/activity_pub/mrf/noop_policy.ex index e26f60d26..8eacc62bc 100644 --- a/lib/pleroma/web/activity_pub/mrf/noop_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/noop_policy.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do @behaviour Pleroma.Web.ActivityPub.MRF diff --git a/lib/pleroma/web/activity_pub/mrf/normalize_markup.ex b/lib/pleroma/web/activity_pub/mrf/normalize_markup.ex index c53cb1ad2..6cfd43974 100644 --- a/lib/pleroma/web/activity_pub/mrf/normalize_markup.ex +++ b/lib/pleroma/web/activity_pub/mrf/normalize_markup.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do alias Pleroma.HTML diff --git a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex index 627284083..07d739437 100644 --- a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex +++ b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do alias Pleroma.User @behaviour Pleroma.Web.ActivityPub.MRF diff --git a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex index 12fc3b181..9ced1e620 100644 --- a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do alias Pleroma.User @behaviour Pleroma.Web.ActivityPub.MRF diff --git a/lib/pleroma/web/activity_pub/mrf/user_allowlist.ex b/lib/pleroma/web/activity_pub/mrf/user_allowlist.ex index 3503d8692..7a78c50bf 100644 --- a/lib/pleroma/web/activity_pub/mrf/user_allowlist.ex +++ b/lib/pleroma/web/activity_pub/mrf/user_allowlist.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy do alias Pleroma.Config diff --git a/lib/pleroma/web/activity_pub/relay.ex b/lib/pleroma/web/activity_pub/relay.ex index fcdc6b1c0..d0a866589 100644 --- a/lib/pleroma/web/activity_pub/relay.ex +++ b/lib/pleroma/web/activity_pub/relay.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.Relay do alias Pleroma.{User, Object, Activity} alias Pleroma.Web.ActivityPub.ActivityPub diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 4bc96b00d..315571e1a 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.Transmogrifier do @moduledoc """ A module to handle coding from internal to wire ActivityPub and back. diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 074622f2b..59cf6abfc 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.Utils do alias Pleroma.{Repo, Web, Object, Activity, User, Notification} alias Pleroma.Web.Router.Helpers diff --git a/lib/pleroma/web/activity_pub/views/object_view.ex b/lib/pleroma/web/activity_pub/views/object_view.ex index ff664636c..efe16b2bf 100644 --- a/lib/pleroma/web/activity_pub/views/object_view.ex +++ b/lib/pleroma/web/activity_pub/views/object_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.ObjectView do use Pleroma.Web, :view alias Pleroma.{Object, Activity} diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 869934172..f0c268755 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ActivityPub.UserView do use Pleroma.Web, :view alias Pleroma.Web.Salmon diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 683310168..49d237661 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.AdminAPI.AdminAPIController do use Pleroma.Web, :controller alias Pleroma.User diff --git a/lib/pleroma/web/channels/user_socket.ex b/lib/pleroma/web/channels/user_socket.ex index 9918d3b49..23ba5a381 100644 --- a/lib/pleroma/web/channels/user_socket.ex +++ b/lib/pleroma/web/channels/user_socket.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.UserSocket do use Phoenix.Socket alias Pleroma.User diff --git a/lib/pleroma/web/chat_channel.ex b/lib/pleroma/web/chat_channel.ex index 37eba8c3f..ac28f300b 100644 --- a/lib/pleroma/web/chat_channel.ex +++ b/lib/pleroma/web/chat_channel.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ChatChannel do use Phoenix.Channel alias Pleroma.Web.ChatChannel.ChatChannelState diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index f01d36370..5e5821561 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.CommonAPI do alias Pleroma.{User, Repo, Activity, Object} alias Pleroma.Web.ActivityPub.ActivityPub diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 142283684..b91cfc4bb 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.CommonAPI.Utils do alias Calendar.Strftime alias Comeonin.Pbkdf2 diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index ddf958811..cb0463eeb 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ControllerHelper do use Pleroma.Web, :controller diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index 564fc2c1d..e994f8f37 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Endpoint do use Phoenix.Endpoint, otp_app: :pleroma diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index a9c7aecd5..3aec55274 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Federator do use GenServer alias Pleroma.User diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex index 510b4315d..5f1d43008 100644 --- a/lib/pleroma/web/federator/retry_queue.ex +++ b/lib/pleroma/web/federator/retry_queue.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Federator.RetryQueue do use GenServer diff --git a/lib/pleroma/web/gettext.ex b/lib/pleroma/web/gettext.ex index 501545581..f40fd04c0 100644 --- a/lib/pleroma/web/gettext.ex +++ b/lib/pleroma/web/gettext.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Gettext do @moduledoc """ A module providing Internationalization with a gettext-based API. diff --git a/lib/pleroma/web/http_signatures/http_signatures.ex b/lib/pleroma/web/http_signatures/http_signatures.ex index 0e54debd5..0e4f8f14b 100644 --- a/lib/pleroma/web/http_signatures/http_signatures.ex +++ b/lib/pleroma/web/http_signatures/http_signatures.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + # https://tools.ietf.org/html/draft-cavage-http-signatures-08 defmodule Pleroma.Web.HTTPSignatures do alias Pleroma.User diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index c6db89442..22715bb76 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do use Pleroma.Web, :controller alias Pleroma.{Repo, Object, Activity, User, Notification, Stats} diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 50df88aca..aaaae2035 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.MastodonAPI.AccountView do use Pleroma.Web, :view alias Pleroma.User diff --git a/lib/pleroma/web/mastodon_api/views/filter_view.ex b/lib/pleroma/web/mastodon_api/views/filter_view.ex index 6bd687d46..ffbd830e1 100644 --- a/lib/pleroma/web/mastodon_api/views/filter_view.ex +++ b/lib/pleroma/web/mastodon_api/views/filter_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.MastodonAPI.FilterView do use Pleroma.Web, :view alias Pleroma.Web.MastodonAPI.FilterView diff --git a/lib/pleroma/web/mastodon_api/views/list_view.ex b/lib/pleroma/web/mastodon_api/views/list_view.ex index 1a1b7430b..dd0121f7a 100644 --- a/lib/pleroma/web/mastodon_api/views/list_view.ex +++ b/lib/pleroma/web/mastodon_api/views/list_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.MastodonAPI.ListView do use Pleroma.Web, :view alias Pleroma.Web.MastodonAPI.ListView diff --git a/lib/pleroma/web/mastodon_api/views/mastodon_view.ex b/lib/pleroma/web/mastodon_api/views/mastodon_view.ex index 1fd05d9f1..a3adabc50 100644 --- a/lib/pleroma/web/mastodon_api/views/mastodon_view.ex +++ b/lib/pleroma/web/mastodon_api/views/mastodon_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.MastodonAPI.MastodonView do use Pleroma.Web, :view import Phoenix.HTML diff --git a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex index 67e86294e..7970bcd47 100644 --- a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex +++ b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.MastodonAPI.PushSubscriptionView do use Pleroma.Web, :view diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index d06da812c..4d4681da8 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.MastodonAPI.StatusView do use Pleroma.Web, :view diff --git a/lib/pleroma/web/mastodon_api/websocket_handler.ex b/lib/pleroma/web/mastodon_api/websocket_handler.ex index 11e0e1696..7b90649ad 100644 --- a/lib/pleroma/web/mastodon_api/websocket_handler.ex +++ b/lib/pleroma/web/mastodon_api/websocket_handler.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do require Logger diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex index 63140feb9..8c82b4176 100644 --- a/lib/pleroma/web/media_proxy/controller.ex +++ b/lib/pleroma/web/media_proxy/controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.MediaProxy.MediaProxyController do use Pleroma.Web, :controller alias Pleroma.{Web.MediaProxy, ReverseProxy} diff --git a/lib/pleroma/web/media_proxy/media_proxy.ex b/lib/pleroma/web/media_proxy/media_proxy.ex index 902ab1b77..a61726b3e 100644 --- a/lib/pleroma/web/media_proxy/media_proxy.ex +++ b/lib/pleroma/web/media_proxy/media_proxy.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.MediaProxy do @base64_opts [padding: false] diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 70921605d..1265d81c5 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Nodeinfo.NodeinfoController do use Pleroma.Web, :controller diff --git a/lib/pleroma/web/oauth/app.ex b/lib/pleroma/web/oauth/app.ex index b3273bc6e..c18e9da8c 100644 --- a/lib/pleroma/web/oauth/app.ex +++ b/lib/pleroma/web/oauth/app.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OAuth.App do use Ecto.Schema import Ecto.{Changeset} diff --git a/lib/pleroma/web/oauth/authorization.ex b/lib/pleroma/web/oauth/authorization.ex index 2cad4550a..7e75d71b3 100644 --- a/lib/pleroma/web/oauth/authorization.ex +++ b/lib/pleroma/web/oauth/authorization.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OAuth.Authorization do use Ecto.Schema diff --git a/lib/pleroma/web/oauth/fallback_controller.ex b/lib/pleroma/web/oauth/fallback_controller.ex index 3927cdb64..e1d91dc80 100644 --- a/lib/pleroma/web/oauth/fallback_controller.ex +++ b/lib/pleroma/web/oauth/fallback_controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OAuth.FallbackController do use Pleroma.Web, :controller alias Pleroma.Web.OAuth.OAuthController diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 9a972ee47..41b0f253d 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OAuth.OAuthController do use Pleroma.Web, :controller diff --git a/lib/pleroma/web/oauth/oauth_view.ex b/lib/pleroma/web/oauth/oauth_view.ex index b3923fcf5..da6f72433 100644 --- a/lib/pleroma/web/oauth/oauth_view.ex +++ b/lib/pleroma/web/oauth/oauth_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OAuth.OAuthView do use Pleroma.Web, :view import Phoenix.HTML.Form diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index a77d5af35..aa3610bb3 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OAuth.Token do use Ecto.Schema diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 537bd9f77..bd05c671b 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OStatus.ActivityRepresenter do alias Pleroma.{Activity, User, Object} alias Pleroma.Web.OStatus.UserRepresenter diff --git a/lib/pleroma/web/ostatus/feed_representer.ex b/lib/pleroma/web/ostatus/feed_representer.ex index 279672673..2c2157173 100644 --- a/lib/pleroma/web/ostatus/feed_representer.ex +++ b/lib/pleroma/web/ostatus/feed_representer.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OStatus.FeedRepresenter do alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus.{UserRepresenter, ActivityRepresenter} diff --git a/lib/pleroma/web/ostatus/handlers/delete_handler.ex b/lib/pleroma/web/ostatus/handlers/delete_handler.ex index 6330d7f64..e7cf4cb54 100644 --- a/lib/pleroma/web/ostatus/handlers/delete_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/delete_handler.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OStatus.DeleteHandler do require Logger alias Pleroma.Web.XML diff --git a/lib/pleroma/web/ostatus/handlers/follow_handler.ex b/lib/pleroma/web/ostatus/handlers/follow_handler.ex index 162407e04..aef450935 100644 --- a/lib/pleroma/web/ostatus/handlers/follow_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/follow_handler.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OStatus.FollowHandler do alias Pleroma.Web.{XML, OStatus} alias Pleroma.Web.ActivityPub.ActivityPub diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex index 0d4080291..7fd364b45 100644 --- a/lib/pleroma/web/ostatus/handlers/note_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OStatus.NoteHandler do require Logger alias Pleroma.Web.{XML, OStatus} diff --git a/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex b/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex index a115bf4c8..bd86a54c7 100644 --- a/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OStatus.UnfollowHandler do alias Pleroma.Web.{XML, OStatus} alias Pleroma.Web.ActivityPub.ActivityPub diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index c6440c20e..cd5493e16 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OStatus do @httpoison Application.get_env(:pleroma, :httpoison) diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 6005eadb2..9ad702dd4 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OStatus.OStatusController do use Pleroma.Web, :controller diff --git a/lib/pleroma/web/ostatus/user_representer.ex b/lib/pleroma/web/ostatus/user_representer.ex index 2e696506e..ef8371a2c 100644 --- a/lib/pleroma/web/ostatus/user_representer.ex +++ b/lib/pleroma/web/ostatus/user_representer.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OStatus.UserRepresenter do alias Pleroma.User diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index 477943450..6459d4543 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Push do use GenServer diff --git a/lib/pleroma/web/push/subscription.ex b/lib/pleroma/web/push/subscription.ex index 1ad405daf..65d28fee9 100644 --- a/lib/pleroma/web/push/subscription.ex +++ b/lib/pleroma/web/push/subscription.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Push.Subscription do use Ecto.Schema import Ecto.Changeset diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 2c62cdf2f..7ec0cabb3 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Router do use Pleroma.Web, :router diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index b67b1333f..1dc514976 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Salmon do @httpoison Application.get_env(:pleroma, :httpoison) diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index e1eecba4d..05f877438 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Streamer do use GenServer require Logger diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 3baeba619..c872aec2b 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.UtilController do use Pleroma.Web, :controller require Logger diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index d9dd352be..489a55b6c 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + # THIS MODULE IS DEPRECATED! DON'T USE IT! # USE THE Pleroma.Web.TwitterAPI.Views.ActivityView MODULE! defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do diff --git a/lib/pleroma/web/twitter_api/representers/base_representer.ex b/lib/pleroma/web/twitter_api/representers/base_representer.ex index f32a21d47..28a59205d 100644 --- a/lib/pleroma/web/twitter_api/representers/base_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/base_representer.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.Representers.BaseRepresenter do defmacro __using__(_opts) do quote do diff --git a/lib/pleroma/web/twitter_api/representers/object_representer.ex b/lib/pleroma/web/twitter_api/representers/object_representer.ex index d5291a397..2f33e7af4 100644 --- a/lib/pleroma/web/twitter_api/representers/object_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/object_representer.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter do use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter alias Pleroma.Object diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index d816dc3bc..e2b1e0a8e 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.TwitterAPI do alias Pleroma.{UserInviteToken, User, Activity, Repo, Object} alias Pleroma.{UserEmail, Mailer} diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index c644681b0..c25cb0876 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.Controller do use Pleroma.Web, :controller diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index df93ceb6c..592cf622f 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.ActivityView do use Pleroma.Web, :view alias Pleroma.Web.CommonAPI.Utils diff --git a/lib/pleroma/web/twitter_api/views/notification_view.ex b/lib/pleroma/web/twitter_api/views/notification_view.ex index 9eeb3afdc..d889038a2 100644 --- a/lib/pleroma/web/twitter_api/views/notification_view.ex +++ b/lib/pleroma/web/twitter_api/views/notification_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.NotificationView do use Pleroma.Web, :view alias Pleroma.{Notification, User} diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 45b893eda..6e489624f 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.UserView do use Pleroma.Web, :view alias Pleroma.User diff --git a/lib/pleroma/web/twitter_api/views/util_view.ex b/lib/pleroma/web/twitter_api/views/util_view.ex index 71b04e6cc..aa5f842ac 100644 --- a/lib/pleroma/web/twitter_api/views/util_view.ex +++ b/lib/pleroma/web/twitter_api/views/util_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.UtilView do use Pleroma.Web, :view import Phoenix.HTML.Form diff --git a/lib/pleroma/web/views/error_helpers.ex b/lib/pleroma/web/views/error_helpers.ex index 3981b270d..df1e0d437 100644 --- a/lib/pleroma/web/views/error_helpers.ex +++ b/lib/pleroma/web/views/error_helpers.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ErrorHelpers do @moduledoc """ Conveniences for translating and building error messages. diff --git a/lib/pleroma/web/views/error_view.ex b/lib/pleroma/web/views/error_view.ex index 7106031ae..d8158edb4 100644 --- a/lib/pleroma/web/views/error_view.ex +++ b/lib/pleroma/web/views/error_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.ErrorView do use Pleroma.Web, :view diff --git a/lib/pleroma/web/views/layout_view.ex b/lib/pleroma/web/views/layout_view.ex index d4d4c3bd3..ba94b9def 100644 --- a/lib/pleroma/web/views/layout_view.ex +++ b/lib/pleroma/web/views/layout_view.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.LayoutView do use Pleroma.Web, :view end diff --git a/lib/pleroma/web/web.ex b/lib/pleroma/web/web.ex index b82242a78..1aa86f645 100644 --- a/lib/pleroma/web/web.ex +++ b/lib/pleroma/web/web.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web do @moduledoc """ A module that keeps using definitions for controllers, diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 47c733da2..3cc90d5dd 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.WebFinger do @httpoison Application.get_env(:pleroma, :httpoison) diff --git a/lib/pleroma/web/web_finger/web_finger_controller.ex b/lib/pleroma/web/web_finger/web_finger_controller.ex index 8c60300a4..66d5a880d 100644 --- a/lib/pleroma/web/web_finger/web_finger_controller.ex +++ b/lib/pleroma/web/web_finger/web_finger_controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.WebFinger.WebFingerController do use Pleroma.Web, :controller diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 8cb07006f..628ec38c5 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Websub do alias Ecto.Changeset alias Pleroma.Repo diff --git a/lib/pleroma/web/websub/websub_client_subscription.ex b/lib/pleroma/web/websub/websub_client_subscription.ex index 8cea02939..2f511cd5b 100644 --- a/lib/pleroma/web/websub/websub_client_subscription.ex +++ b/lib/pleroma/web/websub/websub_client_subscription.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Websub.WebsubClientSubscription do use Ecto.Schema alias Pleroma.User diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex index c1934ba92..c38a03808 100644 --- a/lib/pleroma/web/websub/websub_controller.ex +++ b/lib/pleroma/web/websub/websub_controller.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Websub.WebsubController do use Pleroma.Web, :controller alias Pleroma.{Repo, User} diff --git a/lib/pleroma/web/websub/websub_server_subscription.ex b/lib/pleroma/web/websub/websub_server_subscription.ex index 0e5248a73..81a2d7f07 100644 --- a/lib/pleroma/web/websub/websub_server_subscription.ex +++ b/lib/pleroma/web/websub/websub_server_subscription.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Websub.WebsubServerSubscription do use Ecto.Schema diff --git a/lib/pleroma/web/xml/xml.ex b/lib/pleroma/web/xml/xml.ex index b3ccf4a55..fa6dcd424 100644 --- a/lib/pleroma/web/xml/xml.ex +++ b/lib/pleroma/web/xml/xml.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.XML do require Logger -- cgit v1.2.3 From 69ad1039ba6cb94ea0f6c9d2c7171bdab789651f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 20:05:55 +0000 Subject: mix tasks: add legal boilerplate --- lib/mix/tasks/pleroma/common.ex | 4 ++++ lib/mix/tasks/pleroma/instance.ex | 4 ++++ lib/mix/tasks/pleroma/relay.ex | 4 ++++ lib/mix/tasks/pleroma/uploads.ex | 4 ++++ lib/mix/tasks/pleroma/user.ex | 4 ++++ 5 files changed, 20 insertions(+) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/common.ex b/lib/mix/tasks/pleroma/common.ex index 36432c291..48c0c1346 100644 --- a/lib/mix/tasks/pleroma/common.ex +++ b/lib/mix/tasks/pleroma/common.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Mix.Tasks.Pleroma.Common do @doc "Common functions to be reused in mix tasks" def start_pleroma do diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 02e1ce27d..1ef40671c 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Mix.Tasks.Pleroma.Instance do use Mix.Task alias Mix.Tasks.Pleroma.Common diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index 03586d6c3..cbe23f82e 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Mix.Tasks.Pleroma.Relay do use Mix.Task alias Pleroma.Web.ActivityPub.Relay diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index 63299b2ae..f0eb13e1a 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Mix.Tasks.Pleroma.Uploads do use Mix.Task alias Pleroma.{Upload, Uploaders.Local} diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 51086a443..217a52fdd 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Mix.Tasks.Pleroma.User do use Mix.Task import Ecto.Changeset -- cgit v1.2.3 From 0f412cf6e68fcebda3e94b71b7f182af689748bf Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Mon, 24 Dec 2018 02:25:36 +0300 Subject: Create tombstone instead of object deletion --- lib/pleroma/activity.ex | 20 +++++++++++++++++++- lib/pleroma/object.ex | 22 ++++++++++++++++++++-- lib/pleroma/web/common_api/utils.ex | 7 ++++++- 3 files changed, 45 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 200addd6e..0845233ee 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -1,7 +1,7 @@ defmodule Pleroma.Activity do use Ecto.Schema alias Pleroma.{Repo, Activity, Notification} - import Ecto.Query + import Ecto.{Query, Changeset} # https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19 @mastodon_notification_types %{ @@ -103,4 +103,22 @@ defmodule Pleroma.Activity do end def mastodon_notification_type(%Activity{}), do: nil + + def get_tombstone(%Activity{data: data}, deleted \\ DateTime.utc_now()) do + %{ + id: data["id"], + context: data["context"], + type: "tombstone", + published: data["published"], + deleted: deleted + } + end + + def swap_data_with_tombstone(activity) do + tombstone = get_tombstone(activity) + + activity + |> change(%{data: tombstone}) + |> Repo.update() + end end diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 31c8dd5bd..436cf6d5d 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -62,9 +62,27 @@ defmodule Pleroma.Object do Object.change(%Object{}, %{data: %{"id" => context}}) end + def get_tombstone(%Object{data: data}, deleted \\ DateTime.utc_now()) do + %{ + id: data["id"], + type: "tombstone", + deleted: deleted + } + end + + def swap_data_with_tombstone(object) do + tombstone = get_tombstone(object) + + object + |> Object.change(%{data: tombstone}) + |> Repo.update() + end + def delete(%Object{data: %{"id" => id}} = object) do - with Repo.delete(object), - Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)), + with swap_data_with_tombstone(object), + Activity.all_non_create_by_object_ap_id_q(id) + |> Repo.all() + |> Enum.each(&Activity.swap_data_with_tombstone/1), {:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do {:ok, object} end diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 142283684..d25fef6bc 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -69,7 +69,12 @@ defmodule Pleroma.Web.CommonAPI.Utils do mentioned_users = Enum.map(mentions, fn {_, %{ap_id: ap_id}} -> ap_id end) if inReplyTo do - {Enum.uniq([inReplyTo.data["actor"] | mentioned_users]), []} + to = + [inReplyTo.data["actor"] | mentioned_users] + |> Enum.uniq() + |> Enum.reject(&is_nil/1) + + {to, []} else {mentioned_users, []} end -- cgit v1.2.3 From 18a4cbb244dbc188f5a391626fb98e3a53571318 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Mon, 24 Dec 2018 20:09:18 +0300 Subject: Capitalize "tombstone" --- lib/pleroma/object.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 436cf6d5d..31f206c39 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -65,7 +65,7 @@ defmodule Pleroma.Object do def get_tombstone(%Object{data: data}, deleted \\ DateTime.utc_now()) do %{ id: data["id"], - type: "tombstone", + type: "Tombstone", deleted: deleted } end -- cgit v1.2.3 From 2bbec33c7112ede3f93a7d35e9d5f3ac5a31ce05 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Tue, 25 Dec 2018 00:29:13 +0300 Subject: Fix failing tests --- lib/pleroma/activity.ex | 15 +++++++++------ lib/pleroma/notification.ex | 10 +++++++--- lib/pleroma/web/activity_pub/transmogrifier.ex | 3 ++- 3 files changed, 18 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 0845233ee..be04363aa 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -108,17 +108,20 @@ defmodule Pleroma.Activity do %{ id: data["id"], context: data["context"], - type: "tombstone", + type: "Tombstone", published: data["published"], deleted: deleted } end def swap_data_with_tombstone(activity) do - tombstone = get_tombstone(activity) - - activity - |> change(%{data: tombstone}) - |> Repo.update() + with tombstone = get_tombstone(activity), + Notification.clear(activity), + {:ok, changed_activity} = + activity + |> change(%{data: tombstone}) + |> Repo.update() do + {:ok, changed_activity} + end end end diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 47f6b6ee7..457cba935 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -75,10 +75,14 @@ defmodule Pleroma.Notification do end end - def clear(user) do - query = from(n in Notification, where: n.user_id == ^user.id) + def clear(%User{} = user) do + from(n in Notification, where: n.user_id == ^user.id) + |> Repo.delete_all() + end - Repo.delete_all(query) + def clear(%Activity{} = activity) do + from(n in Notification, where: n.activity_id == ^activity.id) + |> Repo.delete_all() end def dismiss(%{id: user_id} = _user, id) do diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index e6af4b211..87514870d 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -586,7 +586,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do end def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) do - with false <- String.starts_with?(inReplyTo, "http"), + with false <- is_nil(inReplyTo), + false <- String.starts_with?(inReplyTo, "http"), {:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo) else -- cgit v1.2.3 From f75f707f6cf07c66a23ddbbe80a9b782a1ecb6f8 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Tue, 25 Dec 2018 03:00:06 +0300 Subject: Revert Activity tombstones, add ObjectTombstone struct --- lib/pleroma/activity.ex | 23 +---------------------- lib/pleroma/object.ex | 21 ++++++++++----------- lib/pleroma/object_tombstone.ex | 4 ++++ 3 files changed, 15 insertions(+), 33 deletions(-) create mode 100644 lib/pleroma/object_tombstone.ex (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index be04363aa..200addd6e 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -1,7 +1,7 @@ defmodule Pleroma.Activity do use Ecto.Schema alias Pleroma.{Repo, Activity, Notification} - import Ecto.{Query, Changeset} + import Ecto.Query # https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19 @mastodon_notification_types %{ @@ -103,25 +103,4 @@ defmodule Pleroma.Activity do end def mastodon_notification_type(%Activity{}), do: nil - - def get_tombstone(%Activity{data: data}, deleted \\ DateTime.utc_now()) do - %{ - id: data["id"], - context: data["context"], - type: "Tombstone", - published: data["published"], - deleted: deleted - } - end - - def swap_data_with_tombstone(activity) do - with tombstone = get_tombstone(activity), - Notification.clear(activity), - {:ok, changed_activity} = - activity - |> change(%{data: tombstone}) - |> Repo.update() do - {:ok, changed_activity} - end - end end diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 31f206c39..5b1347b37 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -1,6 +1,6 @@ defmodule Pleroma.Object do use Ecto.Schema - alias Pleroma.{Repo, Object, User, Activity} + alias Pleroma.{Repo, Object, User, Activity, ObjectTombstone} import Ecto.{Query, Changeset} schema "objects" do @@ -62,16 +62,17 @@ defmodule Pleroma.Object do Object.change(%Object{}, %{data: %{"id" => context}}) end - def get_tombstone(%Object{data: data}, deleted \\ DateTime.utc_now()) do - %{ - id: data["id"], - type: "Tombstone", + def make_tombstone(%Object{data: %{"id" => id, "type" => type}}, deleted \\ DateTime.utc_now()) do + %ObjectTombstone{ + id: id, + formerType: type, deleted: deleted } + |> Map.from_struct() end - def swap_data_with_tombstone(object) do - tombstone = get_tombstone(object) + def swap_object_with_tombstone(object) do + tombstone = make_tombstone(object) object |> Object.change(%{data: tombstone}) @@ -79,10 +80,8 @@ defmodule Pleroma.Object do end def delete(%Object{data: %{"id" => id}} = object) do - with swap_data_with_tombstone(object), - Activity.all_non_create_by_object_ap_id_q(id) - |> Repo.all() - |> Enum.each(&Activity.swap_data_with_tombstone/1), + with {:ok, _obj} = swap_object_with_tombstone(object), + Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)), {:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do {:ok, object} end diff --git a/lib/pleroma/object_tombstone.ex b/lib/pleroma/object_tombstone.ex new file mode 100644 index 000000000..64d836d3e --- /dev/null +++ b/lib/pleroma/object_tombstone.ex @@ -0,0 +1,4 @@ +defmodule Pleroma.ObjectTombstone do + @enforce_keys [:id, :formerType, :deleted] + defstruct [:id, :formerType, :deleted, type: "Tombstone"] +end -- cgit v1.2.3 From ca2e9ce9cc98f046ea2be0a9051cdf06d253d7f6 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Tue, 25 Dec 2018 03:44:48 +0300 Subject: Revert unneeded changes --- lib/pleroma/notification.ex | 7 +------ lib/pleroma/web/activity_pub/transmogrifier.ex | 3 +-- lib/pleroma/web/common_api/utils.ex | 7 +------ 3 files changed, 3 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 457cba935..47578d60e 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -75,16 +75,11 @@ defmodule Pleroma.Notification do end end - def clear(%User{} = user) do + def clear(user) do from(n in Notification, where: n.user_id == ^user.id) |> Repo.delete_all() end - def clear(%Activity{} = activity) do - from(n in Notification, where: n.activity_id == ^activity.id) - |> Repo.delete_all() - end - def dismiss(%{id: user_id} = _user, id) do notification = Repo.get(Notification, id) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 87514870d..e6af4b211 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -586,8 +586,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do end def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) do - with false <- is_nil(inReplyTo), - false <- String.starts_with?(inReplyTo, "http"), + with false <- String.starts_with?(inReplyTo, "http"), {:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo) else diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index d25fef6bc..142283684 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -69,12 +69,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do mentioned_users = Enum.map(mentions, fn {_, %{ap_id: ap_id}} -> ap_id end) if inReplyTo do - to = - [inReplyTo.data["actor"] | mentioned_users] - |> Enum.uniq() - |> Enum.reject(&is_nil/1) - - {to, []} + {Enum.uniq([inReplyTo.data["actor"] | mentioned_users]), []} else {mentioned_users, []} end -- cgit v1.2.3 From 91724d160acc39585c37742204c59b91e59df569 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 25 Dec 2018 20:09:27 +0100 Subject: Reserve a few user names These are all names that are used for domain.com/:route routes or projected to be. --- lib/pleroma/user.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1f930479d..33f5e43fc 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -197,6 +197,7 @@ defmodule Pleroma.User do |> validate_confirmation(:password) |> unique_constraint(:email) |> unique_constraint(:nickname) + |> validate_exclusion(:nickname, Pleroma.Config.get([Pleroma.User, :restricted_nicknames])) |> validate_format(:nickname, local_nickname_regex()) |> validate_format(:email, @email_regex) |> validate_length(:bio, max: 1000) -- cgit v1.2.3 From 5811e65e67591b06238de66470c03744e0d83e2d Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 26 Dec 2018 12:39:35 +0100 Subject: Add some hard limits on inserted activities. --- lib/pleroma/web/activity_pub/activity_pub.ex | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 188060780..8b2f764e4 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -56,10 +56,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end + defp check_remote_limit(%{"object" => %{"content" => content}}) do + limit = Pleroma.Config.get([:instance, :remote_limit]) + String.length(content) <= limit + end + + defp check_remote_limit(_), do: true + def insert(map, local \\ true) when is_map(map) do with nil <- Activity.normalize(map), map <- lazy_put_activity_defaults(map), :ok <- check_actor_is_active(map["actor"]), + {_, true} <- {:remote_limit_error, check_remote_limit(map)}, {:ok, map} <- MRF.filter(map), :ok <- insert_full_object(map) do {recipients, _, _} = get_recipients(map) -- cgit v1.2.3 From 551d80cc0186424d2c1653f917749adea16d9963 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 26 Dec 2018 12:46:16 +0100 Subject: Expose restricted names in nodeinfo. --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 1265d81c5..a992f75f6 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -138,7 +138,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do }, accountActivationRequired: Keyword.get(instance, :account_activation_required, false), invitesEnabled: Keyword.get(instance, :invites_enabled, false), - features: features + features: features, + restrictedNicknames: Pleroma.Config.get([Pleroma.User, :restricted_nicknames]) } } -- cgit v1.2.3 From 448af3601a365e4f24a2db54af366d075af7e90f Mon Sep 17 00:00:00 2001 From: Ekaterina Vaartis Date: Thu, 27 Dec 2018 00:12:20 +0300 Subject: Up captcha timer to 60 secs again, save used captchas in cachex --- lib/pleroma/application.ex | 10 ++++++++++ lib/pleroma/captcha/captcha.ex | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index e15991957..bdd0ee26f 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -25,6 +25,16 @@ defmodule Pleroma.Application do supervisor(Pleroma.Repo, []), worker(Pleroma.Emoji, []), worker(Pleroma.Captcha, []), + worker( + Cachex, + [ + :used_captcha_cache, + [ + ttl_interval: :timer.seconds(60 * 2) + ] + ], + id: :cachex_used_captcha_cache + ), worker( Cachex, [ diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index 04769d4b2..c7abafeb1 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -80,9 +80,24 @@ defmodule Pleroma.Captcha do result = with {:ok, data} <- MessageEncryptor.decrypt(answer_data, secret, sign_secret), %{at: at, answer_data: answer_md5} <- :erlang.binary_to_term(data) do - if DateTime.after?(at, valid_if_after), - do: method().validate(token, captcha, answer_md5), - else: {:error, "CAPTCHA expired"} + try do + if DateTime.before?(at, valid_if_after), do: throw({:error, "CAPTCHA expired"}) + + if not is_nil(Cachex.get!(:used_captcha_cache, token)), + do: throw({:error, "CAPTCHA already used"}) + + res = method().validate(token, captcha, answer_md5) + # Throw if an error occurs + if res != :ok, do: throw(res) + + # Mark this captcha as used + {:ok, _} = + Cachex.put(:used_captcha_cache, token, true, ttl: :timer.seconds(seconds_valid)) + + :ok + catch + :throw, e -> e + end else _ -> {:error, "Invalid answer data"} end -- cgit v1.2.3 From 838c0242316545afa42384b8e50a401e54ad1405 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 27 Dec 2018 02:39:41 +0300 Subject: Treat any present value in "no_attachment_links" as true --- lib/pleroma/web/common_api/utils.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index b91cfc4bb..d9cc52e26 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -89,7 +89,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do ) do status |> format_input(mentions, tags, content_type) - |> maybe_add_attachments(attachments, no_attachment_links) + |> maybe_add_attachments(attachments, !!no_attachment_links) end def make_context(%Activity{data: %{"context" => context}}), do: context -- cgit v1.2.3 From e4562105e77dd2d580921a07f05907a63da1d826 Mon Sep 17 00:00:00 2001 From: Vyr Cossont <600-VyrCossont@users.noreply.git.pleroma.social> Date: Wed, 26 Dec 2018 21:30:01 -0800 Subject: Implement exclude_reblogs and include_rts --- lib/pleroma/web/activity_pub/activity_pub.ex | 7 +++++++ lib/pleroma/web/twitter_api/twitter_api_controller.ex | 9 +++++++++ 2 files changed, 16 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 188060780..2d4cc9f68 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -503,6 +503,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_replies(query, _), do: query + defp restrict_reblogs(query, %{"exclude_reblogs" => val}) when val == "true" or val == "1" do + from(activity in query, where: fragment("?->>'type' != 'Announce'", activity.data)) + end + + defp restrict_reblogs(query, _), do: query + # Only search through last 100_000 activities by default defp restrict_recent(query, %{"whole_db" => true}), do: query @@ -561,6 +567,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do |> restrict_media(opts) |> restrict_visibility(opts) |> restrict_replies(opts) + |> restrict_reblogs(opts) end def fetch_activities(recipients, opts \\ %{}) do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index c25cb0876..7ae850d71 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -130,6 +130,15 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def user_timeline(%{assigns: %{user: user}} = conn, params) do case TwitterAPI.get_user(user, params) do {:ok, target_user} -> + # Twitter and ActivityPub use a different name and sense for this parameter. + {include_rts, params} = Map.pop(params, "include_rts") + + params = + case include_rts do + x when x == "false" or x == "0" -> Map.put(params, "exclude_reblogs", "true") + _ -> params + end + activities = ActivityPub.fetch_user_activities(target_user, user, params) conn -- cgit v1.2.3 From 708a22891921d54c9c716ac250e75ae6a889eb7b Mon Sep 17 00:00:00 2001 From: vaartis Date: Thu, 27 Dec 2018 07:42:03 +0000 Subject: Set ttl_interval to the seconds_valid time --- lib/pleroma/application.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index bdd0ee26f..8dbacf258 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -30,7 +30,7 @@ defmodule Pleroma.Application do [ :used_captcha_cache, [ - ttl_interval: :timer.seconds(60 * 2) + ttl_interval: :timer.seconds(Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid])) ] ], id: :cachex_used_captcha_cache -- cgit v1.2.3 From be70272ab08356353ff3c2685dbb639477c2cdf4 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 27 Dec 2018 13:21:04 +0300 Subject: Treat only true and "true" as true --- lib/pleroma/web/common_api/common_api.ex | 2 +- lib/pleroma/web/common_api/utils.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 5e5821561..085a95172 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -102,7 +102,7 @@ defmodule Pleroma.Web.CommonAPI do attachments, tags, get_content_type(data["content_type"]), - data["no_attachment_links"] + Enum.member?([true, "true"], data["no_attachment_links"]) ), context <- make_context(inReplyTo), cw <- data["spoiler_text"], diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index d9cc52e26..b91cfc4bb 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -89,7 +89,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do ) do status |> format_input(mentions, tags, content_type) - |> maybe_add_attachments(attachments, !!no_attachment_links) + |> maybe_add_attachments(attachments, no_attachment_links) end def make_context(%Activity{data: %{"context" => context}}), do: context -- cgit v1.2.3 From e6aeb1d4a5c0e0e0e5e1e744b4062f7392ed0722 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 27 Dec 2018 15:46:18 +0300 Subject: [#471] Prevented rendering of inactive local accounts. --- lib/pleroma/user.ex | 2 ++ lib/pleroma/web/mastodon_api/views/account_view.ex | 22 ++++++++++++++- lib/pleroma/web/twitter_api/views/user_view.ex | 33 ++++++++++++++++++---- 3 files changed, 50 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1f930479d..b8a7a3fae 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -47,6 +47,8 @@ defmodule Pleroma.User do !Pleroma.Config.get([:instance, :account_activation_required]) end + def remote_or_auth_active?(%User{} = user), do: !user.local || auth_active?(user) + def superuser?(%User{} = user), do: user.info && User.Info.superuser?(user.info) def avatar_url(user) do diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index aaaae2035..ba72e3a10 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -11,10 +11,30 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do alias Pleroma.HTML def render("accounts.json", %{users: users} = opts) do - render_many(users, AccountView, "account.json", opts) + users + |> render_many(AccountView, "account.json", opts) + |> Enum.filter(&Enum.any?/1) end def render("account.json", %{user: user} = opts) do + for_user = opts[:for] + + allow_render = + User.remote_or_auth_active?(user) || + (for_user && (for_user.id == user.id || User.superuser?(for_user))) + + if allow_render do + render("valid_account.json", opts) + else + render("invalid_account.json", opts) + end + end + + def render("invalid_account.json", _opts) do + %{} + end + + def render("valid_account.json", %{user: user} = opts) do image = User.avatar_url(user) |> MediaProxy.url() header = User.banner_url(user) |> MediaProxy.url() user_info = User.user_info(user) diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 6e489624f..41825f8f6 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -15,18 +15,39 @@ defmodule Pleroma.Web.TwitterAPI.UserView do end def render("index.json", %{users: users, for: user}) do - render_many(users, Pleroma.Web.TwitterAPI.UserView, "user.json", for: user) + users + |> render_many(Pleroma.Web.TwitterAPI.UserView, "user.json", for: user) + |> Enum.filter(&Enum.any?/1) end def render("user.json", %{user: user = %User{}} = assigns) do + for_user = assigns[:for] + + allow_render = + User.remote_or_auth_active?(user) || + (for_user && (for_user.id == user.id || User.superuser?(for_user))) + + if allow_render do + render("valid_user.json", assigns) + else + render("invalid_user.json", assigns) + end + end + + def render("invalid_user.json", _assigns) do + %{} + end + + def render("valid_user.json", %{user: user = %User{}} = assigns) do + for_user = assigns[:for] image = User.avatar_url(user) |> MediaProxy.url() {following, follows_you, statusnet_blocking} = - if assigns[:for] do + if for_user do { - User.following?(assigns[:for], user), - User.following?(user, assigns[:for]), - User.blocks?(assigns[:for], user) + User.following?(for_user, user), + User.following?(user, for_user), + User.blocks?(for_user, user) } else {false, false, false} @@ -51,7 +72,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do data = %{ "created_at" => user.inserted_at |> Utils.format_naive_asctime(), "description" => HTML.strip_tags((user.bio || "") |> String.replace("
", "\n")), - "description_html" => HTML.filter_tags(user.bio, User.html_filter_policy(assigns[:for])), + "description_html" => HTML.filter_tags(user.bio, User.html_filter_policy(for_user)), "favourites_count" => 0, "followers_count" => user_info[:follower_count], "following" => following, -- cgit v1.2.3 From d8cc96cb1f9e2a4e736f6830529e8aa9a5d289d8 Mon Sep 17 00:00:00 2001 From: Vyr Cossont <600-VyrCossont@users.noreply.git.pleroma.social> Date: Thu, 27 Dec 2018 22:43:40 -0800 Subject: Fix Twitter timelines for private instances --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 7ae850d71..92b7386da 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -662,7 +662,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do json_reply(conn, 403, json) end - def only_if_public_instance(conn = %{conn: %{assigns: %{user: _user}}}, _), do: conn + def only_if_public_instance(%{assigns: %{user: %User{}}} = conn, _), do: conn def only_if_public_instance(conn, _) do if Keyword.get(Application.get_env(:pleroma, :instance), :public) do -- cgit v1.2.3 From 0d1788ce44cf7bf50aa40e56988be0d2e315d2e1 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 28 Dec 2018 14:35:25 +0300 Subject: [#471] Factored out User.visible_for?/2. --- lib/pleroma/user.ex | 6 ++++++ lib/pleroma/web/mastodon_api/views/account_view.ex | 14 +++----------- lib/pleroma/web/twitter_api/views/user_view.ex | 14 +++----------- 3 files changed, 12 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index b8a7a3fae..7d97bf7e5 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -49,6 +49,12 @@ defmodule Pleroma.User do def remote_or_auth_active?(%User{} = user), do: !user.local || auth_active?(user) + def visible_for?(%User{} = user, for_user \\ nil) do + User.remote_or_auth_active?(user) || (for_user && for_user.id == user.id) || + User.superuser?(for_user) + end + + def superuser?(nil), do: false def superuser?(%User{} = user), do: user.info && User.Info.superuser?(user.info) def avatar_url(user) do diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index ba72e3a10..32cb1ac60 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -17,17 +17,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do end def render("account.json", %{user: user} = opts) do - for_user = opts[:for] - - allow_render = - User.remote_or_auth_active?(user) || - (for_user && (for_user.id == user.id || User.superuser?(for_user))) - - if allow_render do - render("valid_account.json", opts) - else - render("invalid_account.json", opts) - end + if User.visible_for?(user, opts[:for]), + do: render("valid_account.json", opts), + else: render("invalid_account.json", opts) end def render("invalid_account.json", _opts) do diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 41825f8f6..890d4234e 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -21,17 +21,9 @@ defmodule Pleroma.Web.TwitterAPI.UserView do end def render("user.json", %{user: user = %User{}} = assigns) do - for_user = assigns[:for] - - allow_render = - User.remote_or_auth_active?(user) || - (for_user && (for_user.id == user.id || User.superuser?(for_user))) - - if allow_render do - render("valid_user.json", assigns) - else - render("invalid_user.json", assigns) - end + if User.visible_for?(user, assigns[:for]), + do: render("valid_user.json", assigns), + else: render("invalid_user.json", assigns) end def render("invalid_user.json", _assigns) do -- cgit v1.2.3 From b43d630f307110b5fa552c28c9fa0ebae09e85f2 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 23 Dec 2018 18:31:37 +0100 Subject: Web.TwitterAPI.UserView: Add rights.admin --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 3 ++- lib/pleroma/web/twitter_api/views/user_view.ex | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 22715bb76..a4b17e4f8 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -966,7 +966,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do max_toot_chars: limit }, rights: %{ - delete_others_notice: !!user.info.is_moderator + delete_others_notice: !!user.info.is_moderator, + admin: !!user.info.is_admin }, compose: %{ me: "#{user.id}", diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 6e489624f..c04d143c8 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -70,7 +70,8 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "profile_image_url_profile_size" => image, "profile_image_url_original" => image, "rights" => %{ - "delete_others_notice" => !!user.info.is_moderator + "delete_others_notice" => !!user.info.is_moderator, + "admin" => !!user.info.is_admin }, "screen_name" => user.nickname, "statuses_count" => user_info[:note_count], -- cgit v1.2.3 From 6e9a15b181fcca9e7485a61b1cce2e4ec6d46b78 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 28 Dec 2018 21:08:07 +0300 Subject: [#483] Blocked users export for TwitterAPI. --- lib/pleroma/user.ex | 3 +++ lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 6 ++---- lib/pleroma/web/router.ex | 1 + lib/pleroma/web/twitter_api/twitter_api_controller.ex | 8 ++++++++ 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 33f5e43fc..b64ed74c4 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -649,6 +649,9 @@ defmodule Pleroma.User do end) end + def blocked_users(user), + do: Repo.all(from(u in User, where: u.ap_id in ^user.info.blocks)) + def block_domain(user, domain) do info_cng = user.info diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 22715bb76..663a0fa08 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -704,11 +704,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end - # TODO: Use proper query def blocks(%{assigns: %{user: user}} = conn, _) do - with blocked_users <- user.info.blocks || [], - accounts <- Enum.map(blocked_users, fn ap_id -> User.get_cached_by_ap_id(ap_id) end) do - res = AccountView.render("accounts.json", users: accounts, for: user, as: :user) + with blocked_accounts <- User.blocked_users(user) do + res = AccountView.render("accounts.json", users: blocked_accounts, for: user, as: :user) json(conn, res) end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 7ec0cabb3..a7f78ba81 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -281,6 +281,7 @@ defmodule Pleroma.Web.Router do get("/statuses/followers", TwitterAPI.Controller, :followers) get("/statuses/friends", TwitterAPI.Controller, :friends) + get("/statuses/blocks", TwitterAPI.Controller, :blocks) get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status) get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 7ae850d71..c11824afc 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -507,6 +507,14 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def blocks(%{assigns: %{user: user}} = conn, _params) do + with blocked_users <- User.blocked_users(user) do + conn + |> put_view(UserView) + |> render("index.json", %{users: blocked_users, for: user}) + end + end + def friend_requests(conn, params) do with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params), {:ok, friend_requests} <- User.get_follow_requests(user) do -- cgit v1.2.3 From 0a41786624454d26fd966748735a8f2333bf4012 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 28 Dec 2018 22:47:42 +0300 Subject: [#467] Refactored valid / invalid user rendering. --- lib/pleroma/web/mastodon_api/views/account_view.ex | 80 ++++++++++------------ lib/pleroma/web/twitter_api/views/user_view.ex | 40 +++++------ 2 files changed, 56 insertions(+), 64 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 32cb1ac60..555383503 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -18,15 +18,48 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do def render("account.json", %{user: user} = opts) do if User.visible_for?(user, opts[:for]), - do: render("valid_account.json", opts), - else: render("invalid_account.json", opts) + do: do_render("account.json", opts), + else: %{} end - def render("invalid_account.json", _opts) do - %{} + def render("mention.json", %{user: user}) do + %{ + id: to_string(user.id), + acct: user.nickname, + username: username_from_nickname(user.nickname), + url: user.ap_id + } + end + + def render("relationship.json", %{user: user, target: target}) do + follow_activity = Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(user, target) + + requested = + if follow_activity do + follow_activity.data["state"] == "pending" + else + false + end + + %{ + id: to_string(target.id), + following: User.following?(user, target), + followed_by: User.following?(target, user), + blocking: User.blocks?(user, target), + muting: false, + muting_notifications: false, + requested: requested, + domain_blocking: false, + showing_reblogs: false, + endorsed: false + } end - def render("valid_account.json", %{user: user} = opts) do + def render("relationships.json", %{user: user, targets: targets}) do + render_many(targets, AccountView, "relationship.json", user: user, as: :target) + end + + defp do_render("account.json", %{user: user} = opts) do image = User.avatar_url(user) |> MediaProxy.url() header = User.banner_url(user) |> MediaProxy.url() user_info = User.user_info(user) @@ -84,43 +117,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do } end - def render("mention.json", %{user: user}) do - %{ - id: to_string(user.id), - acct: user.nickname, - username: username_from_nickname(user.nickname), - url: user.ap_id - } - end - - def render("relationship.json", %{user: user, target: target}) do - follow_activity = Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(user, target) - - requested = - if follow_activity do - follow_activity.data["state"] == "pending" - else - false - end - - %{ - id: to_string(target.id), - following: User.following?(user, target), - followed_by: User.following?(target, user), - blocking: User.blocks?(user, target), - muting: false, - muting_notifications: false, - requested: requested, - domain_blocking: false, - showing_reblogs: false, - endorsed: false - } - end - - def render("relationships.json", %{user: user, targets: targets}) do - render_many(targets, AccountView, "relationship.json", user: user, as: :target) - end - defp username_from_nickname(string) when is_binary(string) do hd(String.split(string, "@")) end diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 890d4234e..ede3c0d25 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -22,15 +22,28 @@ defmodule Pleroma.Web.TwitterAPI.UserView do def render("user.json", %{user: user = %User{}} = assigns) do if User.visible_for?(user, assigns[:for]), - do: render("valid_user.json", assigns), - else: render("invalid_user.json", assigns) + do: do_render("user.json", assigns), + else: %{} end - def render("invalid_user.json", _assigns) do - %{} + def render("short.json", %{ + user: %User{ + nickname: nickname, + id: id, + ap_id: ap_id, + name: name + } + }) do + %{ + "fullname" => name, + "id" => id, + "ostatus_uri" => ap_id, + "profile_url" => ap_id, + "screen_name" => nickname + } end - def render("valid_user.json", %{user: user = %User{}} = assigns) do + defp do_render("user.json", %{user: user = %User{}} = assigns) do for_user = assigns[:for] image = User.avatar_url(user) |> MediaProxy.url() @@ -110,23 +123,6 @@ defmodule Pleroma.Web.TwitterAPI.UserView do end end - def render("short.json", %{ - user: %User{ - nickname: nickname, - id: id, - ap_id: ap_id, - name: name - } - }) do - %{ - "fullname" => name, - "id" => id, - "ostatus_uri" => ap_id, - "profile_url" => ap_id, - "screen_name" => nickname - } - end - defp image_url(%{"url" => [%{"href" => href} | _]}), do: href defp image_url(_), do: nil -- cgit v1.2.3 From 700661b761117e6673ad254877ebba902b9d751b Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 28 Dec 2018 23:01:03 +0300 Subject: [#483] Blocked users list import (TwitterAPI). --- lib/pleroma/web/router.ex | 1 + .../web/twitter_api/controllers/util_controller.ex | 31 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index a7f78ba81..43b04e508 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -137,6 +137,7 @@ defmodule Pleroma.Web.Router do scope "/api/pleroma", Pleroma.Web.TwitterAPI do pipe_through(:authenticated_api) + post("/blocks_import", UtilController, :blocks_import) post("/follow_import", UtilController, :follow_import) post("/change_password", UtilController, :change_password) post("/delete_account", UtilController, :delete_account) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index c872aec2b..6a9325afe 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -242,9 +242,12 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do def follow_import(%{assigns: %{user: user}} = conn, %{"list" => list}) do Task.start(fn -> - String.split(list) + follower = User.get_cached_by_ap_id(user.ap_id) + + list + |> String.split() |> Enum.map(fn account -> - with %User{} = follower <- User.get_cached_by_ap_id(user.ap_id), + with %User{} <- follower, %User{} = followed <- User.get_or_fetch(account), {:ok, follower} <- User.maybe_direct_follow(follower, followed) do ActivityPub.follow(follower, followed) @@ -257,6 +260,30 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do json(conn, "job started") end + def blocks_import(conn, %{"list" => %Plug.Upload{} = listfile}) do + blocks_import(conn, %{"list" => File.read!(listfile.path)}) + end + + def blocks_import(%{assigns: %{user: user}} = conn, %{"list" => list}) do + Task.start(fn -> + blocker = User.get_cached_by_ap_id(user.ap_id) + + list + |> String.split() + |> Enum.map(fn account -> + with %User{} <- blocker, + %User{} = blocked <- User.get_or_fetch(account), + {:ok, blocker} <- User.block(blocker, blocked) do + ActivityPub.block(blocker, blocked) + else + err -> Logger.debug("blocks_import: blocking #{account} failed with #{inspect(err)}") + end + end) + end) + + json(conn, "job started") + end + def change_password(%{assigns: %{user: user}} = conn, params) do case CommonAPI.Utils.confirm_current_password(user, params["password"]) do {:ok, user} -> -- cgit v1.2.3 From 67b4297f4d4010ee1b66452af4cea094d2cab2c4 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sat, 29 Dec 2018 12:02:37 +0300 Subject: [#483] Refactored blocks and follows import, added tests. --- lib/pleroma/user.ex | 37 +++++++++++++++++ .../web/twitter_api/controllers/util_controller.ex | 46 +++++----------------- 2 files changed, 47 insertions(+), 36 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index b64ed74c4..558014760 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -13,6 +13,8 @@ defmodule Pleroma.User do alias Pleroma.Web.{OStatus, Websub, OAuth} alias Pleroma.Web.ActivityPub.{Utils, ActivityPub} + require Logger + @type t :: %__MODULE__{} @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ @@ -331,6 +333,24 @@ defmodule Pleroma.User do Enum.member?(follower.following, followed.follower_address) end + def follow_import(%User{} = follower, followed_identifiers) + when is_list(followed_identifiers) do + Enum.map( + followed_identifiers, + fn followed_identifier -> + with %User{} = followed <- get_or_fetch(followed_identifier), + {:ok, follower} <- maybe_direct_follow(follower, followed), + {:ok, _} <- ActivityPub.follow(follower, followed) do + followed + else + err -> + Logger.debug("follow_import failed for #{followed_identifier} with: #{inspect(err)}") + err + end + end + ) + end + def locked?(%User{} = user) do user.info.locked || false end @@ -596,6 +616,23 @@ defmodule Pleroma.User do Repo.all(q) end + def blocks_import(%User{} = blocker, blocked_identifiers) when is_list(blocked_identifiers) do + Enum.map( + blocked_identifiers, + fn blocked_identifier -> + with %User{} = blocked <- get_or_fetch(blocked_identifier), + {:ok, blocker} <- block(blocker, blocked), + {:ok, _} <- ActivityPub.block(blocker, blocked) do + blocked + else + err -> + Logger.debug("blocks_import failed for #{blocked_identifier} with: #{inspect(err)}") + err + end + end + ) + end + def block(blocker, %User{ap_id: ap_id} = blocked) do # sever any follow relationships to prevent leaks per activitypub (Pleroma issue #213) blocker = diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 6a9325afe..87b8b71ba 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -240,48 +240,22 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do follow_import(conn, %{"list" => File.read!(listfile.path)}) end - def follow_import(%{assigns: %{user: user}} = conn, %{"list" => list}) do - Task.start(fn -> - follower = User.get_cached_by_ap_id(user.ap_id) - - list - |> String.split() - |> Enum.map(fn account -> - with %User{} <- follower, - %User{} = followed <- User.get_or_fetch(account), - {:ok, follower} <- User.maybe_direct_follow(follower, followed) do - ActivityPub.follow(follower, followed) - else - err -> Logger.debug("follow_import: following #{account} failed with #{inspect(err)}") - end - end) - end) - - json(conn, "job started") + def follow_import(%{assigns: %{user: follower}} = conn, %{"list" => list}) do + with followed_identifiers <- String.split(list), + {:ok, _} = Task.start(fn -> User.follow_import(follower, followed_identifiers) end) do + json(conn, "job started") + end end def blocks_import(conn, %{"list" => %Plug.Upload{} = listfile}) do blocks_import(conn, %{"list" => File.read!(listfile.path)}) end - def blocks_import(%{assigns: %{user: user}} = conn, %{"list" => list}) do - Task.start(fn -> - blocker = User.get_cached_by_ap_id(user.ap_id) - - list - |> String.split() - |> Enum.map(fn account -> - with %User{} <- blocker, - %User{} = blocked <- User.get_or_fetch(account), - {:ok, blocker} <- User.block(blocker, blocked) do - ActivityPub.block(blocker, blocked) - else - err -> Logger.debug("blocks_import: blocking #{account} failed with #{inspect(err)}") - end - end) - end) - - json(conn, "job started") + def blocks_import(%{assigns: %{user: blocker}} = conn, %{"list" => list}) do + with blocked_identifiers <- String.split(list), + {:ok, _} = Task.start(fn -> User.blocks_import(blocker, blocked_identifiers) end) do + json(conn, "job started") + end end def change_password(%{assigns: %{user: user}} = conn, params) do -- cgit v1.2.3 From b3574dccbbb9d24ed90f0a82627d18428aaa7a16 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sat, 29 Dec 2018 12:15:46 +0300 Subject: [#483] User.get_by_nickname/1: allowed retrieving user by fully-qualified local nickname (@). --- lib/pleroma/user.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 558014760..d4a6b13fb 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -387,7 +387,11 @@ defmodule Pleroma.User do end def get_by_nickname(nickname) do - Repo.get_by(User, nickname: nickname) + Repo.get_by(User, nickname: nickname) || + if String.ends_with?(nickname, "@" <> Pleroma.Web.Endpoint.host()) do + [local_nickname, _] = String.split(nickname, "@") + Repo.get_by(User, nickname: local_nickname) + end end def get_by_nickname_or_email(nickname_or_email) do -- cgit v1.2.3 From 7bd49a32222045c34098f925fbd494461ab67ccd Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sat, 29 Dec 2018 12:26:23 +0300 Subject: [#483] User.get_by_nickname/1: ensured case-insensitive matching for local FQN. Added tests. --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index d4a6b13fb..1f6d4cc5e 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -388,7 +388,7 @@ defmodule Pleroma.User do def get_by_nickname(nickname) do Repo.get_by(User, nickname: nickname) || - if String.ends_with?(nickname, "@" <> Pleroma.Web.Endpoint.host()) do + if Regex.match?(~r(@#{Pleroma.Web.Endpoint.host()})i, nickname) do [local_nickname, _] = String.split(nickname, "@") Repo.get_by(User, nickname: local_nickname) end -- cgit v1.2.3 From 523848d1fd94cfefa0a81e585d5891135982f8c2 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sat, 29 Dec 2018 12:48:54 +0300 Subject: Salmon# fixed publish an activity to remote accounts --- lib/pleroma/activity.ex | 2 ++ lib/pleroma/http/http.ex | 2 ++ lib/pleroma/web/salmon/salmon.ex | 18 ++++++++++++++---- 3 files changed, 18 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 34b665765..a14d1e8c6 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -7,6 +7,8 @@ defmodule Pleroma.Activity do alias Pleroma.{Repo, Activity, Notification} import Ecto.Query + @type t :: %__MODULE__{} + # https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19 @mastodon_notification_types %{ "Create" => "mention", diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex index e572dfedf..32d9cf5aa 100644 --- a/lib/pleroma/http/http.ex +++ b/lib/pleroma/http/http.ex @@ -10,6 +10,8 @@ defmodule Pleroma.HTTP do alias Pleroma.HTTP.Connection alias Pleroma.HTTP.RequestBuilder, as: Builder + @type t :: __MODULE__ + @doc """ Builds and perform http request. diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 1dc514976..f7d2257eb 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -161,16 +161,21 @@ defmodule Pleroma.Web.Salmon do |> Enum.filter(fn user -> user && !user.local end) end - defp send_to_user(%{info: %{salmon: salmon}}, feed, poster) do + # push an activity to remote accounts + # + defp send_to_user(%{info: %{salmon: salmon}}, feed, poster), + do: send_to_user(salmon, feed, poster) + + defp send_to_user(url, feed, poster) when is_binary(url) do with {:ok, %{status: code}} <- poster.( - salmon, + url, feed, [{"Content-Type", "application/magic-envelope+xml"}] ) do - Logger.debug(fn -> "Pushed to #{salmon}, code #{code}" end) + Logger.debug(fn -> "Pushed to #{url}, code #{code}" end) else - e -> Logger.debug(fn -> "Pushing Salmon to #{salmon} failed, #{inspect(e)}" end) + e -> Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end) end end @@ -184,6 +189,11 @@ defmodule Pleroma.Web.Salmon do "Undo", "Delete" ] + + @doc """ + Publishes an activity to remote accounts + """ + @spec publish(User.t(), Pleroma.Activity.t(), Pleroma.HTTP.t()) :: none def publish(user, activity, poster \\ &@httpoison.post/3) def publish(%{info: %{keys: keys}} = user, %{data: %{"type" => type}} = activity, poster) -- cgit v1.2.3 From ab9cda315f2ee7b0a2a6e505eface5d7c65d50b4 Mon Sep 17 00:00:00 2001 From: spctrl Date: Sat, 29 Dec 2018 12:43:54 +0100 Subject: Change 'name' to 'instance_name' so option is used when running non-interactive --- lib/mix/tasks/pleroma/instance.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 1ef40671c..0a2c891c0 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -75,7 +75,7 @@ defmodule Mix.Tasks.Pleroma.Instance do name = Common.get_option( options, - :name, + :instance_name, "What is the name of your instance? (e.g. Pleroma/Soykaf)" ) -- cgit v1.2.3 From 19f9889fbe9d120acfaed2a5aedb4032d56eb217 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sat, 29 Dec 2018 17:45:50 +0100 Subject: I am not sure what's going on anymore so I'll just commit and reset all the other files to HEAD --- lib/pleroma/html.ex | 26 ++++----- lib/pleroma/user.ex | 4 +- lib/pleroma/web/common_api/common_api.ex | 3 +- lib/pleroma/web/common_api/utils.ex | 61 +++++++++++++++++++++- lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- lib/pleroma/web/twitter_api/views/activity_view.ex | 2 +- 6 files changed, 81 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index a0473676b..169394af9 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -5,18 +5,8 @@ defmodule Pleroma.HTML do alias HtmlSanitizeEx.Scrubber - defp get_scrubbers(scrubber) when is_atom(scrubber), do: [scrubber] - defp get_scrubbers(scrubbers) when is_list(scrubbers), do: scrubbers - defp get_scrubbers(_), do: [Pleroma.HTML.Scrubber.Default] - - def get_scrubbers() do - Pleroma.Config.get([:markup, :scrub_policy]) - |> get_scrubbers - end - - def filter_tags(html, nil) do - get_scrubbers() - |> Enum.reduce(html, fn scrubber, html -> + def filter_tags(html, scrubbers) when is_list(scrubbers) do + Enum.reduce(scrubbers, html, fn scrubber, html -> filter_tags(html, scrubber) end) end @@ -39,6 +29,10 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do require HtmlSanitizeEx.Scrubber.Meta alias HtmlSanitizeEx.Scrubber.Meta + def version do + 0 + end + Meta.remove_cdata_sections_before_scrub() Meta.strip_comments() @@ -77,6 +71,10 @@ defmodule Pleroma.HTML.Scrubber.Default do require HtmlSanitizeEx.Scrubber.Meta alias HtmlSanitizeEx.Scrubber.Meta + def version do + 0 + end + @markup Application.get_env(:pleroma, :markup) @uri_schemes Application.get_env(:pleroma, :uri_schemes, []) @valid_schemes Keyword.get(@uri_schemes, :valid_schemes, []) @@ -152,6 +150,10 @@ end defmodule Pleroma.HTML.Transform.MediaProxy do @moduledoc "Transforms inline image URIs to use MediaProxy." + def version do + 0 + end + alias Pleroma.Web.MediaProxy def before_scrub(html), do: html diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1f930479d..b0b65cbe2 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -733,7 +733,9 @@ defmodule Pleroma.User do Pleroma.HTML.Scrubber.TwitterText end - def html_filter_policy(_), do: nil + @default_scrubbers Pleroma.Config.get([:markup, :scrub_policy]) + + def html_filter_policy(_), do: @default_scrubbers def get_or_fetch_by_ap_id(ap_id) do user = get_by_ap_id(ap_id) diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 5e5821561..06d44451e 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -128,7 +128,8 @@ defmodule Pleroma.Web.CommonAPI do |> Enum.reduce(%{}, fn {name, file}, acc -> Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}") end) - ) do + ), + object <- Map.put(object, "scrubber_cache", %{}) do res = ActivityPub.create(%{ to: to, diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index b91cfc4bb..5c37fd671 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do alias Calendar.Strftime alias Comeonin.Pbkdf2 - alias Pleroma.{Activity, Formatter, Object, Repo} + alias Pleroma.{Activity, Formatter, Object, Repo, HTML} alias Pleroma.User alias Pleroma.Web alias Pleroma.Web.ActivityPub.Utils @@ -261,4 +261,63 @@ defmodule Pleroma.Web.CommonAPI.Utils do } end) end + + @doc """ + Get sanitized HTML from cache, or scrub it and save to cache. + """ + def get_scrubbed_html( + content, + scrubbers, + %{data: %{"object" => object}} = activity + ) do + scrubber_cache = + if object["scrubber_cache"] != nil and is_list(object["scrubber_cache"]) do + object["scrubber_cache"] + else + [] + end + + key = generate_scrubber_key(scrubbers) + + {new_scrubber_cache, scrubbed_html} = + Enum.map_reduce(scrubber_cache, nil, fn %{ + :scrubbers => current_key, + :content => current_content + }, + _ -> + if Map.keys(current_key) == Map.keys(key) do + if scrubbers == key do + {current_key, current_content} + else + # Remove the entry if scrubber version is outdated + {nil, nil} + end + end + end) + + new_scrubber_cache = Enum.reject(new_scrubber_cache, &is_nil/1) + + if !(new_scrubber_cache == scrubber_cache) or scrubbed_html == nil do + scrubbed_html = HTML.filter_tags(content, scrubbers) + new_scrubber_cache = [%{:scrubbers => key, :content => scrubbed_html} | new_scrubber_cache] + + activity = + Map.merge(activity, %{ + data: %{"object" => %{"scrubber_cache" => new_scrubber_cache}} + }) + + cng = Ecto.Changeset.change(activity) + Repo.update(cng) + scrubbed_html + else + IO.puts("got the post from cache") + scrubbed_html + end + end + + defp generate_scrubber_key(scrubbers) do + Enum.reduce(scrubbers, %{}, fn scrubber, acc -> + Map.put(acc, to_string(scrubber), scrubber.version) + end) + end end diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 4d4681da8..8fa3798a6 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -120,7 +120,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do content = object |> render_content() - |> HTML.filter_tags(User.html_filter_policy(opts[:for])) + |> Utils.get_scrubbed_html(User.html_filter_policy(opts[:for]), activity) %{ id: to_string(activity.id), diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 592cf622f..adac1dfe9 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -245,7 +245,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do html = content - |> HTML.filter_tags(User.html_filter_policy(opts[:for])) + |> Utils.get_scrubbed_html(User.html_filter_policy(opts[:for]), activity) |> Formatter.emojify(object["emoji"]) text = -- cgit v1.2.3 From 816db3f494c6fcc60d0a700dfc473a9cc49c84a0 Mon Sep 17 00:00:00 2001 From: vaartis Date: Sat, 29 Dec 2018 17:44:26 +0000 Subject: Remove the debugging IO.inspect --- lib/pleroma/captcha/captcha.ex | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index c7abafeb1..424ad4add 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -54,8 +54,6 @@ defmodule Pleroma.Captcha do |> :erlang.term_to_binary() |> MessageEncryptor.encrypt(secret, sign_secret) - IO.inspect(%{new_captcha | answer_data: encrypted_captcha_answer}) - { :reply, # Repalce the answer with the encrypted answer -- cgit v1.2.3 From 9a0163db53580182599a9358bd0197ee0c61779d Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sat, 29 Dec 2018 21:50:34 +0100 Subject: use Kernel.put_in instead of Map.merge --- lib/pleroma/web/common_api/utils.ex | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 5c37fd671..7b11bc3ed 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -300,17 +300,19 @@ defmodule Pleroma.Web.CommonAPI.Utils do if !(new_scrubber_cache == scrubber_cache) or scrubbed_html == nil do scrubbed_html = HTML.filter_tags(content, scrubbers) new_scrubber_cache = [%{:scrubbers => key, :content => scrubbed_html} | new_scrubber_cache] + IO.puts(activity) activity = - Map.merge(activity, %{ - data: %{"object" => %{"scrubber_cache" => new_scrubber_cache}} - }) + Map.put( + activity, + :data, + Kernel.put_in(activity.data, ["object", "scrubber_cache"], new_scrubber_cache) + ) cng = Ecto.Changeset.change(activity) Repo.update(cng) scrubbed_html else - IO.puts("got the post from cache") scrubbed_html end end -- cgit v1.2.3 From aa082ca7b6a64f6cfd509118f76a5c18492e07b9 Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Sat, 29 Dec 2018 18:01:15 +0100 Subject: Wire up stub routes for client calls of activitypub inbox/outbox Code style: remove wrapping function of outbox --- .../web/activity_pub/activity_pub_controller.ex | 36 ++++++++++++++++++---- lib/pleroma/web/router.ex | 21 +++++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 7fd6a45f5..dfa7eb94b 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -93,19 +93,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do end end - def outbox(conn, %{"nickname" => nickname, "max_id" => max_id}) do + def outbox(conn, %{"nickname" => nickname} = params) do with %User{} = user <- User.get_cached_by_nickname(nickname), {:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do conn |> put_resp_header("content-type", "application/activity+json") - |> json(UserView.render("outbox.json", %{user: user, max_id: max_id})) + |> json(UserView.render("outbox.json", %{user: user, max_id: params["max_id"]})) end end - def outbox(conn, %{"nickname" => nickname}) do - outbox(conn, %{"nickname" => nickname, "max_id" => nil}) - end - def inbox(%{assigns: %{valid_signature: true}} = conn, %{"nickname" => nickname} = params) do with %User{} = user <- User.get_cached_by_nickname(nickname), true <- Utils.recipient_in_message(user.ap_id, params), @@ -156,6 +152,34 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do end end + def read_inbox(%{assigns: %{user: user}} = conn, %{"nickname" => nickname} = params) do + if nickname == user.nickname do + Logger.info("read inbox #{inspect(params)}") + + conn + |> put_resp_header("content-type", "application/activity+json") + |> json("ok!") + else + conn + |> put_status(:forbidden) + |> json("can't read inbox of #{nickname} as #{user.nickname}") + end + end + + def update_outbox(%{assigns: %{user: user}} = conn, %{"nickname" => nickname} = params) do + if nickname == user.nickname do + Logger.info("update outbox #{inspect(params)}") + + conn + |> put_status(:created) + |> json("ok!") + else + conn + |> put_status(:forbidden) + |> json("can't update outbox of #{nickname} as #{user.nickname}") + end + end + def errors(conn, {:error, :not_found}) do conn |> put_status(404) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 43b04e508..33c573d46 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -412,6 +412,27 @@ defmodule Pleroma.Web.Router do get("/users/:nickname/outbox", ActivityPubController, :outbox) end + pipeline :activitypub_client do + plug(:accepts, ["activity+json"]) + plug(:fetch_session) + plug(Pleroma.Plugs.OAuthPlug) + plug(Pleroma.Plugs.BasicAuthDecoderPlug) + plug(Pleroma.Plugs.UserFetcherPlug) + plug(Pleroma.Plugs.SessionAuthenticationPlug) + plug(Pleroma.Plugs.LegacyAuthenticationPlug) + plug(Pleroma.Plugs.AuthenticationPlug) + plug(Pleroma.Plugs.UserEnabledPlug) + plug(Pleroma.Plugs.SetUserSessionIdPlug) + plug(Pleroma.Plugs.EnsureUserKeyPlug) + end + + scope "/", Pleroma.Web.ActivityPub do + pipe_through([:activitypub_client]) + + get("/users/:nickname/inbox", ActivityPubController, :read_inbox) + post("/users/:nickname/outbox", ActivityPubController, :update_outbox) + end + scope "/relay", Pleroma.Web.ActivityPub do pipe_through(:ap_relay) get("/", ActivityPubController, :relay) -- cgit v1.2.3 From a32e23905aa24335215f04fd56e33b663af54321 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 30 Dec 2018 11:08:19 +0100 Subject: Use Object.change instead of Ecto.Changeset.change --- lib/pleroma/web/common_api/utils.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 7b11bc3ed..593404e4d 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -300,7 +300,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do if !(new_scrubber_cache == scrubber_cache) or scrubbed_html == nil do scrubbed_html = HTML.filter_tags(content, scrubbers) new_scrubber_cache = [%{:scrubbers => key, :content => scrubbed_html} | new_scrubber_cache] - IO.puts(activity) activity = Map.put( @@ -309,7 +308,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do Kernel.put_in(activity.data, ["object", "scrubber_cache"], new_scrubber_cache) ) - cng = Ecto.Changeset.change(activity) + cng = Object.change(activity) Repo.update(cng) scrubbed_html else -- cgit v1.2.3 From 26dc2dddab6103a3e6e44a3c7ba097283302fc2a Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Sat, 29 Dec 2018 18:15:28 +0100 Subject: Implement ActivityPub inbox view More or less verbatim copied from the outbox template with only changes to the activities fetched and url reported --- .../web/activity_pub/activity_pub_controller.ex | 4 +- lib/pleroma/web/activity_pub/views/user_view.ex | 47 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index dfa7eb94b..9f083d0a5 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -154,11 +154,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do def read_inbox(%{assigns: %{user: user}} = conn, %{"nickname" => nickname} = params) do if nickname == user.nickname do - Logger.info("read inbox #{inspect(params)}") - conn |> put_resp_header("content-type", "application/activity+json") - |> json("ok!") + |> json(UserView.render("inbox.json", %{user: user, max_id: params["max_id"]})) else conn |> put_status(:forbidden) diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index f0c268755..439d834e4 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -176,6 +176,53 @@ defmodule Pleroma.Web.ActivityPub.UserView do end end + def render("inbox.json", %{user: user, max_id: max_qid}) do + params = %{ + "limit" => "10" + } + + params = + if max_qid != nil do + Map.put(params, "max_id", max_qid) + else + params + end + + activities = ActivityPub.fetch_activities([user.ap_id | user.following], params) + + min_id = Enum.at(Enum.reverse(activities), 0).id + max_id = Enum.at(activities, 0).id + + collection = + Enum.map(activities, fn act -> + {:ok, data} = Transmogrifier.prepare_outgoing(act.data) + data + end) + + iri = "#{user.ap_id}/inbox" + + page = %{ + "id" => "#{iri}?max_id=#{max_id}", + "type" => "OrderedCollectionPage", + "partOf" => iri, + "totalItems" => -1, + "orderedItems" => collection, + "next" => "#{iri}?max_id=#{min_id - 1}" + } + + if max_qid == nil do + %{ + "id" => iri, + "type" => "OrderedCollection", + "totalItems" => -1, + "first" => page + } + |> Map.merge(Utils.make_json_ld_header()) + else + page |> Map.merge(Utils.make_json_ld_header()) + end + end + def collection(collection, iri, page, show_items \\ true, total \\ nil) do offset = (page - 1) * 10 items = Enum.slice(collection, offset, 10) -- cgit v1.2.3 From 569bad821006add1719123f6e2830f23542921d2 Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Sat, 29 Dec 2018 18:21:45 +0100 Subject: Create activity when client posts to outbox --- .../web/activity_pub/activity_pub_controller.ex | 35 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 9f083d0a5..dca74db73 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -4,11 +4,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do use Pleroma.Web, :controller - alias Pleroma.{User, Object} + alias Pleroma.{Activity, User, Object} alias Pleroma.Web.ActivityPub.{ObjectView, UserView} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Relay alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.Federator require Logger @@ -166,11 +167,33 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do def update_outbox(%{assigns: %{user: user}} = conn, %{"nickname" => nickname} = params) do if nickname == user.nickname do - Logger.info("update outbox #{inspect(params)}") - - conn - |> put_status(:created) - |> json("ok!") + actor = user.ap_id() + + params = + params + |> Map.drop(["id"]) + |> Map.put("actor", actor) + |> Transmogrifier.fix_addressing() + + object = + params["object"] + |> Map.merge(Map.take(params, ["to", "cc"])) + |> Map.put("attributedTo", actor) + |> Transmogrifier.fix_object() + + with {:ok, %Activity{} = activity} <- + ActivityPub.create(%{ + to: params["to"], + actor: user, + context: object["context"], + object: object, + additional: Map.take(params, ["cc"]) + }) do + conn + |> put_status(:created) + |> put_resp_header("location", activity.data["id"]) + |> json(%{"id" => activity.data["id"]}) + end else conn |> put_status(:forbidden) -- cgit v1.2.3 From 1e781715c8a9c7f6e24838a5522b960250cffc1b Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Sat, 29 Dec 2018 18:22:40 +0100 Subject: Limit activity types accepted to outbox to only 'Create' --- lib/pleroma/web/activity_pub/activity_pub_controller.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index dca74db73..f90132b4d 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -165,7 +165,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do end end - def update_outbox(%{assigns: %{user: user}} = conn, %{"nickname" => nickname} = params) do + def update_outbox( + %{assigns: %{user: user}} = conn, + %{"nickname" => nickname, "type" => "Create"} = params + ) do if nickname == user.nickname do actor = user.ap_id() -- cgit v1.2.3 From f40562b4e1ff213b88c8b6edf57431bfb1b804ac Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Sun, 30 Dec 2018 11:19:53 +0100 Subject: Respond with full activity to outbox post --- lib/pleroma/web/activity_pub/activity_pub_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index f90132b4d..e41b14afc 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -195,7 +195,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do conn |> put_status(:created) |> put_resp_header("location", activity.data["id"]) - |> json(%{"id" => activity.data["id"]}) + |> json(activity.data) end else conn -- cgit v1.2.3 From 66d1c31461826b34d5c907dc3a91e86cce808c3e Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 30 Dec 2018 13:51:01 +0100 Subject: Fix some stupid typos --- lib/pleroma/web/common_api/utils.ex | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 593404e4d..1aedbf962 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -281,35 +281,25 @@ defmodule Pleroma.Web.CommonAPI.Utils do {new_scrubber_cache, scrubbed_html} = Enum.map_reduce(scrubber_cache, nil, fn %{ - :scrubbers => current_key, - :content => current_content - }, - _ -> + "scrubbers" => current_key, + "content" => current_content + } = current_element, + _content -> if Map.keys(current_key) == Map.keys(key) do - if scrubbers == key do - {current_key, current_content} + if current_key == key do + {current_element, current_content} else # Remove the entry if scrubber version is outdated {nil, nil} end end end) - + new_scrubber_cache = Enum.reject(new_scrubber_cache, &is_nil/1) - - if !(new_scrubber_cache == scrubber_cache) or scrubbed_html == nil do + if scrubbed_html == nil or new_scrubber_cache != scrubber_cache do scrubbed_html = HTML.filter_tags(content, scrubbers) new_scrubber_cache = [%{:scrubbers => key, :content => scrubbed_html} | new_scrubber_cache] - - activity = - Map.put( - activity, - :data, - Kernel.put_in(activity.data, ["object", "scrubber_cache"], new_scrubber_cache) - ) - - cng = Object.change(activity) - Repo.update(cng) + update_scrubber_cache(activity, new_scrubber_cache) scrubbed_html else scrubbed_html @@ -321,4 +311,9 @@ defmodule Pleroma.Web.CommonAPI.Utils do Map.put(acc, to_string(scrubber), scrubber.version) end) end + + defp update_scrubber_cache(activity, scrubber_cache) do + cng = Object.change(activity, %{data: Kernel.put_in(activity.data, ["object", "scrubber_cache"], scrubber_cache)}) + {:ok, _struct} = Repo.update(cng) + end end -- cgit v1.2.3 From bce152aba000e9b59562bf95f3a6df8540686317 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 30 Dec 2018 15:58:19 +0100 Subject: Tidy up the code. Rename key to signature --- lib/pleroma/web/common_api/utils.ex | 53 +++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 1aedbf962..d4c169ad9 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -271,49 +271,50 @@ defmodule Pleroma.Web.CommonAPI.Utils do %{data: %{"object" => object}} = activity ) do scrubber_cache = - if object["scrubber_cache"] != nil and is_list(object["scrubber_cache"]) do + if is_list(object["scrubber_cache"]) do object["scrubber_cache"] else [] end - key = generate_scrubber_key(scrubbers) + signature = generate_scrubber_signature(scrubbers) {new_scrubber_cache, scrubbed_html} = - Enum.map_reduce(scrubber_cache, nil, fn %{ - "scrubbers" => current_key, - "content" => current_content - } = current_element, - _content -> - if Map.keys(current_key) == Map.keys(key) do - if current_key == key do - {current_element, current_content} - else - # Remove the entry if scrubber version is outdated - {nil, nil} + Enum.map_reduce(scrubber_cache, nil, fn + entry, _content -> + if Map.keys(entry["scrubbers"]) == Map.keys(signature) do + if entry["scrubbers"] == signature do + {entry, entry["content"]} + else + # Remove the entry if scrubber version is outdated + {nil, nil} + end end - end end) - + + # Remove nil objects new_scrubber_cache = Enum.reject(new_scrubber_cache, &is_nil/1) + if scrubbed_html == nil or new_scrubber_cache != scrubber_cache do scrubbed_html = HTML.filter_tags(content, scrubbers) - new_scrubber_cache = [%{:scrubbers => key, :content => scrubbed_html} | new_scrubber_cache] + new_scrubber_cache = [%{:scrubbers => signature, :content => scrubbed_html} | new_scrubber_cache] update_scrubber_cache(activity, new_scrubber_cache) - scrubbed_html - else - scrubbed_html end + scrubbed_html end - defp generate_scrubber_key(scrubbers) do - Enum.reduce(scrubbers, %{}, fn scrubber, acc -> - Map.put(acc, to_string(scrubber), scrubber.version) + defp generate_scrubber_signature(scrubbers) do + Enum.reduce(scrubbers, %{}, fn scrubber, signature -> + Map.put(signature, to_string(scrubber), scrubber.version) end) end - defp update_scrubber_cache(activity, scrubber_cache) do - cng = Object.change(activity, %{data: Kernel.put_in(activity.data, ["object", "scrubber_cache"], scrubber_cache)}) - {:ok, _struct} = Repo.update(cng) - end + defp update_scrubber_cache(activity, scrubber_cache) do + cng = + Object.change(activity, %{ + data: Kernel.put_in(activity.data, ["object", "scrubber_cache"], scrubber_cache) + }) + + {:ok, _struct} = Repo.update(cng) + end end -- cgit v1.2.3 From cb286fdeba1782b75d1d7bca484d80e3cd499a98 Mon Sep 17 00:00:00 2001 From: Michael Loftis Date: Sun, 30 Dec 2018 15:16:26 +0000 Subject: Improves RetryQueue behavior reduces to one single timer firing once a second switches to a parallel worker model --- lib/pleroma/web/federator/retry_queue.ex | 195 ++++++++++++++++++++++++++++--- 1 file changed, 180 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex index 5f1d43008..e4340af7c 100644 --- a/lib/pleroma/web/federator/retry_queue.ex +++ b/lib/pleroma/web/federator/retry_queue.ex @@ -7,20 +7,34 @@ defmodule Pleroma.Web.Federator.RetryQueue do require Logger - # initial timeout, 5 min - @initial_timeout 30_000 + # seconds + @initial_timeout 30 @max_retries 5 + @max_jobs 20 + def init(args) do - {:ok, args} + queue_table = :ets.new(:pleroma_retry_queue, [:bag, :protected]) + + {:ok, %{args | queue_table: queue_table, running_jobs: :sets.new()}} end def start_link() do - enabled = Pleroma.Config.get([:retry_queue, :enabled], false) + enabled = + if Mix.env() == :test, do: true, else: Pleroma.Config.get([:retry_queue, :enabled], false) if enabled do Logger.info("Starting retry queue") - GenServer.start_link(__MODULE__, %{delivered: 0, dropped: 0}, name: __MODULE__) + + linkres = + GenServer.start_link( + __MODULE__, + %{delivered: 0, dropped: 0, queue_table: nil, running_jobs: nil}, + name: __MODULE__ + ) + + maybe_kickoff_timer() + linkres else Logger.info("Retry queue disabled") :ignore @@ -31,6 +45,14 @@ defmodule Pleroma.Web.Federator.RetryQueue do GenServer.cast(__MODULE__, {:maybe_enqueue, data, transport, retries + 1}) end + def get_stats() do + GenServer.call(__MODULE__, :get_stats) + end + + def reset_stats() do + GenServer.call(__MODULE__, :reset_stats) + end + def get_retry_params(retries) do if retries > @max_retries do {:drop, "Max retries reached"} @@ -39,16 +61,118 @@ defmodule Pleroma.Web.Federator.RetryQueue do end end - def handle_cast({:maybe_enqueue, data, transport, retries}, %{dropped: drop_count} = state) do + def get_retry_timer_interval() do + Pleroma.Config.get([:retry_queue, :interval], 1000) + end + + defp ets_count_expires(table, current_time) do + :ets.select_count( + table, + [ + { + {:"$1", :"$2"}, + [{:"=<", :"$1", {:const, current_time}}], + [true] + } + ] + ) + end + + defp ets_pop_n_expired(table, current_time, desired) do + {popped, _continuation} = + :ets.select( + table, + [ + { + {:"$1", :"$2"}, + [{:"=<", :"$1", {:const, current_time}}], + [:"$_"] + } + ], + desired + ) + + popped + |> List.foldl(true, fn e, acc -> + :ets.delete_object(table, e) + acc + end) + + popped + end + + def maybe_start_job(running_jobs, queue_table) do + # we don't want to hit the ets or the DateTime more times than we have to + # could optimize slightly further by not using the count, and instead grabbing + # up to N objects early... + current_time = DateTime.to_unix(DateTime.utc_now()) + n_running_jobs = :sets.size(running_jobs) + + if n_running_jobs < @max_jobs do + n_ready_jobs = ets_count_expires(queue_table, current_time) + + if n_ready_jobs > 0 do + # figure out how many we could start + available_job_slots = @max_jobs - n_running_jobs + start_n_jobs(running_jobs, queue_table, current_time, available_job_slots) + else + running_jobs + end + else + running_jobs + end + end + + defp start_n_jobs(running_jobs, _queue_table, _current_time, 0) do + running_jobs + end + + defp start_n_jobs(running_jobs, queue_table, current_time, available_job_slots) + when available_job_slots > 0 do + candidates = ets_pop_n_expired(queue_table, current_time, available_job_slots) + + candidates + |> List.foldl(running_jobs, fn {_, e}, rj -> + {:ok, pid} = Task.start(fn -> worker(e) end) + mref = Process.monitor(pid) + :sets.add_element(mref, rj) + end) + end + + def worker({:send, data, transport, retries}) do + case transport.publish_one(data) do + {:ok, _} -> + GenServer.cast(__MODULE__, :inc_delivered) + :delivered + + {:error, _reason} -> + enqueue(data, transport, retries) + :retry + end + end + + def handle_call(:get_stats, _from, %{delivered: delivery_count, dropped: drop_count} = state) do + {:reply, %{delivered: delivery_count, dropped: drop_count}, state} + end + + def handle_call(:reset_stats, _from, %{delivered: delivery_count, dropped: drop_count} = state) do + {:reply, %{delivered: delivery_count, dropped: drop_count}, + %{state | delivered: 0, dropped: 0}} + end + + def handle_cast(:reset_stats, state) do + {:noreply, %{state | delivered: 0, dropped: 0}} + end + + def handle_cast( + {:maybe_enqueue, data, transport, retries}, + %{dropped: drop_count, queue_table: queue_table, running_jobs: running_jobs} = state + ) do case get_retry_params(retries) do {:retry, timeout} -> - Process.send_after( - __MODULE__, - {:send, data, transport, retries}, - timeout - ) - - {:noreply, state} + :ets.insert(queue_table, {timeout, {:send, data, transport, retries}}) + running_jobs = maybe_start_job(running_jobs, queue_table) + {:noreply, %{state | running_jobs: running_jobs}} {:drop, message} -> Logger.debug(message) @@ -56,6 +180,20 @@ defmodule Pleroma.Web.Federator.RetryQueue do end end + def handle_cast(:kickoff_timer, state) do + retry_interval = get_retry_timer_interval() + Process.send_after(__MODULE__, :retry_timer_run, retry_interval) + {:noreply, state} + end + + def handle_cast(:inc_delivered, %{delivered: delivery_count} = state) do + {:noreply, %{state | delivered: delivery_count + 1}} + end + + def handle_cast(:inc_dropped, %{dropped: drop_count} = state) do + {:noreply, %{state | dropped: drop_count + 1}} + end + def handle_info({:send, data, transport, retries}, %{delivered: delivery_count} = state) do case transport.publish_one(data) do {:ok, _} -> @@ -67,12 +205,39 @@ defmodule Pleroma.Web.Federator.RetryQueue do end end + def handle_info( + :retry_timer_run, + %{queue_table: queue_table, running_jobs: running_jobs} = state + ) do + maybe_kickoff_timer() + running_jobs = maybe_start_job(running_jobs, queue_table) + {:noreply, %{state | running_jobs: running_jobs}} + end + + def handle_info({:DOWN, ref, :process, _pid, _reason}, state) do + %{running_jobs: running_jobs, queue_table: queue_table} = state + running_jobs = :sets.del_element(ref, running_jobs) + running_jobs = maybe_start_job(running_jobs, queue_table) + {:noreply, %{state | running_jobs: running_jobs}} + end + def handle_info(unknown, state) do Logger.debug("RetryQueue: don't know what to do with #{inspect(unknown)}, ignoring") {:noreply, state} end - defp growth_function(retries) do - round(@initial_timeout * :math.pow(retries, 3)) + if Mix.env() == :test do + defp growth_function(_retries) do + _shutit = @initial_timeout + DateTime.to_unix(DateTime.utc_now()) - 1 + end + else + defp growth_function(retries) do + round(@initial_timeout * :math.pow(retries, 3)) + DateTime.to_unix(DateTime.utc_now()) + end + end + + defp maybe_kickoff_timer() do + GenServer.cast(__MODULE__, :kickoff_timer) end end -- cgit v1.2.3 From d9f40b05b30dd735d0dc87f8268db842bf8ad1f0 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 30 Dec 2018 16:51:16 +0100 Subject: Added get_stripped_html_for_object. Renamed a few things --- lib/pleroma/web/common_api/utils.ex | 34 ++++++++++++++++++---- lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- lib/pleroma/web/twitter_api/views/activity_view.ex | 5 ++-- 3 files changed, 32 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index d4c169ad9..759bd62af 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -262,10 +262,13 @@ defmodule Pleroma.Web.CommonAPI.Utils do end) end + def get_scrubbed_html_for_object(content, scrubber, activity) when is_atom(scrubber) do + get_scrubbed_html_for_object(content, [scrubber], activity) + end @doc """ Get sanitized HTML from cache, or scrub it and save to cache. """ - def get_scrubbed_html( + def get_scrubbed_html_for_object( content, scrubbers, %{data: %{"object" => object}} = activity @@ -281,7 +284,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do {new_scrubber_cache, scrubbed_html} = Enum.map_reduce(scrubber_cache, nil, fn - entry, _content -> + entry, content -> if Map.keys(entry["scrubbers"]) == Map.keys(signature) do if entry["scrubbers"] == signature do {entry, entry["content"]} @@ -289,6 +292,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do # Remove the entry if scrubber version is outdated {nil, nil} end + else + {entry, content} end end) @@ -297,15 +302,30 @@ defmodule Pleroma.Web.CommonAPI.Utils do if scrubbed_html == nil or new_scrubber_cache != scrubber_cache do scrubbed_html = HTML.filter_tags(content, scrubbers) - new_scrubber_cache = [%{:scrubbers => signature, :content => scrubbed_html} | new_scrubber_cache] + + new_scrubber_cache = [ + %{:scrubbers => signature, :content => scrubbed_html} | new_scrubber_cache + ] + update_scrubber_cache(activity, new_scrubber_cache) + scrubbed_html + else + scrubbed_html end - scrubbed_html end defp generate_scrubber_signature(scrubbers) do Enum.reduce(scrubbers, %{}, fn scrubber, signature -> - Map.put(signature, to_string(scrubber), scrubber.version) + Map.put( + signature, + to_string(scrubber), + # If a scrubber does not have a version(e.g HtmlSanitizeEx.Scrubber) it is assumed it is always 0) + if Kernel.function_exported?(scrubber, :version, 0) do + scrubber.version + else + 0 + end + ) end) end @@ -317,4 +337,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do {:ok, _struct} = Repo.update(cng) end + + def get_stripped_html_for_object(content, activity) do + get_scrubbed_html_for_object(content, [HtmlSanitizeEx.Scrubber.StripTags], activity) + end end diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 8fa3798a6..05ed602d5 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -120,7 +120,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do content = object |> render_content() - |> Utils.get_scrubbed_html(User.html_filter_policy(opts[:for]), activity) + |> Utils.get_scrubbed_html_for_object(User.html_filter_policy(opts[:for]), activity) %{ id: to_string(activity.id), diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index adac1dfe9..7d0dea8c2 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -15,7 +15,6 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do alias Pleroma.User alias Pleroma.Repo alias Pleroma.Formatter - alias Pleroma.HTML import Ecto.Query require Logger @@ -245,14 +244,14 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do html = content - |> Utils.get_scrubbed_html(User.html_filter_policy(opts[:for]), activity) + |> Utils.get_scrubbed_html_for_object(User.html_filter_policy(opts[:for]), activity) |> Formatter.emojify(object["emoji"]) text = if content do content |> String.replace(~r//, "\n") - |> HTML.strip_tags() + |> Utils.get_stripped_html_for_object(activity) end reply_parent = Activity.get_in_reply_to_activity(activity) -- cgit v1.2.3 From 535fddd2864f3ed8eebc24cbaf0e5b04ec6f4dbe Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 30 Dec 2018 19:33:36 +0100 Subject: Friendship ended with Postgresql now Cachex is my best friend --- lib/pleroma/application.ex | 10 +++ lib/pleroma/object.ex | 34 ++++++++- lib/pleroma/web/common_api/common_api.ex | 3 +- lib/pleroma/web/common_api/utils.ex | 81 +--------------------- lib/pleroma/web/mastodon_api/views/status_view.ex | 3 +- lib/pleroma/web/twitter_api/views/activity_view.ex | 4 +- 6 files changed, 49 insertions(+), 86 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 36a3694f2..4b997c048 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -53,6 +53,16 @@ defmodule Pleroma.Application do ], id: :cachex_object ), + worker( + Cachex, + [ + :scrubber_cache, + [ + limit: 2500 + ] + ], + id: :cachex_scrubber + ), worker( Cachex, [ diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index cc4a2181a..e148c1d75 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -4,7 +4,7 @@ defmodule Pleroma.Object do use Ecto.Schema - alias Pleroma.{Repo, Object, User, Activity} + alias Pleroma.{Repo, Object, User, Activity, HTML} import Ecto.{Query, Changeset} schema "objects" do @@ -73,4 +73,36 @@ defmodule Pleroma.Object do {:ok, object} end end + + def get_cached_scrubbed_html(content, scrubbers, object) do + key = "#{generate_scrubber_signature(scrubbers)}|#{object.id}" + Cachex.fetch!(:scrubber_cache, key, fn(_key) -> ensure_scrubbed_html(content, scrubbers) end ) + end + + def get_cached_stripped_html(content, object) do + get_cached_scrubbed_html(content, HtmlSanitizeEx.Scrubber.StripTags, object) + end + + def ensure_scrubbed_html( + content, + scrubbers + ) do + {:commit, HTML.filter_tags(content, scrubbers)} + end + + defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do + generate_scrubber_signature([scrubber]) + end + + defp generate_scrubber_signature(scrubbers) do + Enum.reduce(scrubbers, "", fn scrubber, signature -> + # If a scrubber does not have a version(e.g HtmlSanitizeEx.Scrubber) it is assumed it is always 0) + version = if Kernel.function_exported?(scrubber, :version, 0) do + scrubber.version + else + 0 + end + "#{signature}#{to_string(scrubber)}#{version}" + end) + end end diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 06d44451e..5e5821561 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -128,8 +128,7 @@ defmodule Pleroma.Web.CommonAPI do |> Enum.reduce(%{}, fn {name, file}, acc -> Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}") end) - ), - object <- Map.put(object, "scrubber_cache", %{}) do + ) do res = ActivityPub.create(%{ to: to, diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 759bd62af..813eb4093 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do alias Calendar.Strftime alias Comeonin.Pbkdf2 - alias Pleroma.{Activity, Formatter, Object, Repo, HTML} + alias Pleroma.{Activity, Formatter, Object, Repo} alias Pleroma.User alias Pleroma.Web alias Pleroma.Web.ActivityPub.Utils @@ -262,83 +262,4 @@ defmodule Pleroma.Web.CommonAPI.Utils do end) end - def get_scrubbed_html_for_object(content, scrubber, activity) when is_atom(scrubber) do - get_scrubbed_html_for_object(content, [scrubber], activity) - end - @doc """ - Get sanitized HTML from cache, or scrub it and save to cache. - """ - def get_scrubbed_html_for_object( - content, - scrubbers, - %{data: %{"object" => object}} = activity - ) do - scrubber_cache = - if is_list(object["scrubber_cache"]) do - object["scrubber_cache"] - else - [] - end - - signature = generate_scrubber_signature(scrubbers) - - {new_scrubber_cache, scrubbed_html} = - Enum.map_reduce(scrubber_cache, nil, fn - entry, content -> - if Map.keys(entry["scrubbers"]) == Map.keys(signature) do - if entry["scrubbers"] == signature do - {entry, entry["content"]} - else - # Remove the entry if scrubber version is outdated - {nil, nil} - end - else - {entry, content} - end - end) - - # Remove nil objects - new_scrubber_cache = Enum.reject(new_scrubber_cache, &is_nil/1) - - if scrubbed_html == nil or new_scrubber_cache != scrubber_cache do - scrubbed_html = HTML.filter_tags(content, scrubbers) - - new_scrubber_cache = [ - %{:scrubbers => signature, :content => scrubbed_html} | new_scrubber_cache - ] - - update_scrubber_cache(activity, new_scrubber_cache) - scrubbed_html - else - scrubbed_html - end - end - - defp generate_scrubber_signature(scrubbers) do - Enum.reduce(scrubbers, %{}, fn scrubber, signature -> - Map.put( - signature, - to_string(scrubber), - # If a scrubber does not have a version(e.g HtmlSanitizeEx.Scrubber) it is assumed it is always 0) - if Kernel.function_exported?(scrubber, :version, 0) do - scrubber.version - else - 0 - end - ) - end) - end - - defp update_scrubber_cache(activity, scrubber_cache) do - cng = - Object.change(activity, %{ - data: Kernel.put_in(activity.data, ["object", "scrubber_cache"], scrubber_cache) - }) - - {:ok, _struct} = Repo.update(cng) - end - - def get_stripped_html_for_object(content, activity) do - get_scrubbed_html_for_object(content, [HtmlSanitizeEx.Scrubber.StripTags], activity) - end end diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 05ed602d5..8a57a233a 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -9,6 +9,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do alias Pleroma.HTML alias Pleroma.Repo alias Pleroma.User + alias Pleroma.Object alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MediaProxy alias Pleroma.Web.MastodonAPI.AccountView @@ -120,7 +121,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do content = object |> render_content() - |> Utils.get_scrubbed_html_for_object(User.html_filter_policy(opts[:for]), activity) + |> Object.get_cached_scrubbed_html(User.html_filter_policy(opts[:for]), activity) %{ id: to_string(activity.id), diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 7d0dea8c2..4c29e03ce 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -244,14 +244,14 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do html = content - |> Utils.get_scrubbed_html_for_object(User.html_filter_policy(opts[:for]), activity) + |> Object.get_cached_scrubbed_html(User.html_filter_policy(opts[:for]), activity) |> Formatter.emojify(object["emoji"]) text = if content do content |> String.replace(~r//, "\n") - |> Utils.get_stripped_html_for_object(activity) + |> Object.get_cached_stripped_html(activity) end reply_parent = Activity.get_in_reply_to_activity(activity) -- cgit v1.2.3 From c119ea3a5727d521c36d60eca22fa3f20d507b63 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 30 Dec 2018 20:00:01 +0100 Subject: Friendship ended with Postgresql now Cachex is my best friend --- lib/pleroma/object.ex | 16 +++++++++------- lib/pleroma/web/common_api/utils.ex | 1 - 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index e148c1d75..d9f0e91b0 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -73,10 +73,10 @@ defmodule Pleroma.Object do {:ok, object} end end - + def get_cached_scrubbed_html(content, scrubbers, object) do key = "#{generate_scrubber_signature(scrubbers)}|#{object.id}" - Cachex.fetch!(:scrubber_cache, key, fn(_key) -> ensure_scrubbed_html(content, scrubbers) end ) + Cachex.fetch!(:scrubber_cache, key, fn _key -> ensure_scrubbed_html(content, scrubbers) end) end def get_cached_stripped_html(content, object) do @@ -87,22 +87,24 @@ defmodule Pleroma.Object do content, scrubbers ) do - {:commit, HTML.filter_tags(content, scrubbers)} + {:commit, HTML.filter_tags(content, scrubbers)} end - + defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do generate_scrubber_signature([scrubber]) end defp generate_scrubber_signature(scrubbers) do Enum.reduce(scrubbers, "", fn scrubber, signature -> - # If a scrubber does not have a version(e.g HtmlSanitizeEx.Scrubber) it is assumed it is always 0) - version = if Kernel.function_exported?(scrubber, :version, 0) do + # If a scrubber does not have a version(e.g HtmlSanitizeEx.Scrubber) it is assumed it is always 0) + version = + if Kernel.function_exported?(scrubber, :version, 0) do scrubber.version else 0 end - "#{signature}#{to_string(scrubber)}#{version}" + + "#{signature}#{to_string(scrubber)}#{version}" end) end end diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 813eb4093..b91cfc4bb 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -261,5 +261,4 @@ defmodule Pleroma.Web.CommonAPI.Utils do } end) end - end -- cgit v1.2.3 From 62af23bd26d370ecc38159a8a3803562514596f4 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 30 Dec 2018 20:12:12 +0100 Subject: Revert some changes in html.ex --- lib/pleroma/html.ex | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 169394af9..f363ed85c 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -5,8 +5,18 @@ defmodule Pleroma.HTML do alias HtmlSanitizeEx.Scrubber - def filter_tags(html, scrubbers) when is_list(scrubbers) do - Enum.reduce(scrubbers, html, fn scrubber, html -> + defp get_scrubbers(scrubber) when is_atom(scrubber), do: [scrubber] + defp get_scrubbers(scrubbers) when is_list(scrubbers), do: scrubbers + defp get_scrubbers(_), do: [Pleroma.HTML.Scrubber.Default] + + def get_scrubbers() do + Pleroma.Config.get([:markup, :scrub_policy]) + |> get_scrubbers + end + + def filter_tags(html, nil) do + get_scrubbers() + |> Enum.reduce(html, fn scrubber, html -> filter_tags(html, scrubber) end) end @@ -28,11 +38,8 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do require HtmlSanitizeEx.Scrubber.Meta alias HtmlSanitizeEx.Scrubber.Meta - - def version do - 0 - end - + + def version do 0 end Meta.remove_cdata_sections_before_scrub() Meta.strip_comments() @@ -70,11 +77,7 @@ defmodule Pleroma.HTML.Scrubber.Default do require HtmlSanitizeEx.Scrubber.Meta alias HtmlSanitizeEx.Scrubber.Meta - - def version do - 0 - end - + def version do 0 end @markup Application.get_env(:pleroma, :markup) @uri_schemes Application.get_env(:pleroma, :uri_schemes, []) @valid_schemes Keyword.get(@uri_schemes, :valid_schemes, []) @@ -150,12 +153,9 @@ end defmodule Pleroma.HTML.Transform.MediaProxy do @moduledoc "Transforms inline image URIs to use MediaProxy." - def version do - 0 - end - alias Pleroma.Web.MediaProxy - + + def version do 0 end def before_scrub(html), do: html def scrub_attribute("img", {"src", "http" <> target}) do -- cgit v1.2.3 From 3f9da55adc9798bd66749dcdbd02fded8494fda3 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 30 Dec 2018 20:16:42 +0100 Subject: Fix formating. Aparently my pre-commit hook broke. --- lib/pleroma/html.ex | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index f363ed85c..44b6776f9 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -38,8 +38,11 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do require HtmlSanitizeEx.Scrubber.Meta alias HtmlSanitizeEx.Scrubber.Meta - - def version do 0 end + + def version do + 0 + end + Meta.remove_cdata_sections_before_scrub() Meta.strip_comments() @@ -77,7 +80,11 @@ defmodule Pleroma.HTML.Scrubber.Default do require HtmlSanitizeEx.Scrubber.Meta alias HtmlSanitizeEx.Scrubber.Meta - def version do 0 end + + def version do + 0 + end + @markup Application.get_env(:pleroma, :markup) @uri_schemes Application.get_env(:pleroma, :uri_schemes, []) @valid_schemes Keyword.get(@uri_schemes, :valid_schemes, []) @@ -154,8 +161,11 @@ defmodule Pleroma.HTML.Transform.MediaProxy do @moduledoc "Transforms inline image URIs to use MediaProxy." alias Pleroma.Web.MediaProxy - - def version do 0 end + + def version do + 0 + end + def before_scrub(html), do: html def scrub_attribute("img", {"src", "http" <> target}) do -- cgit v1.2.3 From c50353e6aef5ec482a427298fb20b1b75c208bca Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 30 Dec 2018 20:44:17 +0100 Subject: shame on me for not testing after revert --- lib/pleroma/html.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 44b6776f9..5e1f5bf96 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -15,8 +15,11 @@ defmodule Pleroma.HTML do end def filter_tags(html, nil) do - get_scrubbers() - |> Enum.reduce(html, fn scrubber, html -> + filter_tags(html, get_scrubbers()) + end + + def filter_tags(html, scrubbers) when is_list(scrubbers) do + Enum.reduce(scrubbers, html, fn scrubber, html -> filter_tags(html, scrubber) end) end -- cgit v1.2.3 From ab3089d6a718d4a70b0d702307d41e64e17bc505 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sun, 30 Dec 2018 20:51:31 +0100 Subject: Fix comment in object.ex --- lib/pleroma/object.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index d9f0e91b0..99c836309 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -96,7 +96,7 @@ defmodule Pleroma.Object do defp generate_scrubber_signature(scrubbers) do Enum.reduce(scrubbers, "", fn scrubber, signature -> - # If a scrubber does not have a version(e.g HtmlSanitizeEx.Scrubber) it is assumed it is always 0) + # If a scrubber does not have a version(e.g HtmlSanitizeEx.Scrubber.StripTags) it is assumed it is always 0) version = if Kernel.function_exported?(scrubber, :version, 0) do scrubber.version -- cgit v1.2.3 From 7e09c2bd7d4e22eff75037d8ac1252347a404aea Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Mon, 31 Dec 2018 08:19:48 +0100 Subject: Move scrubber cache-related functions to Pleroma.HTML --- lib/pleroma/html.ex | 34 ++++++++++++++++++++++ lib/pleroma/object.ex | 34 ---------------------- lib/pleroma/web/mastodon_api/views/status_view.ex | 3 +- lib/pleroma/web/twitter_api/views/activity_view.ex | 5 ++-- 4 files changed, 38 insertions(+), 38 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 5e1f5bf96..eb31f131e 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -27,6 +27,40 @@ defmodule Pleroma.HTML do def filter_tags(html, scrubber), do: Scrubber.scrub(html, scrubber) def filter_tags(html), do: filter_tags(html, nil) def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags) + + def get_cached_scrubbed_html_for_object(content, scrubbers, object) do + key = "#{generate_scrubber_signature(scrubbers)}|#{object.id}" + Cachex.fetch!(:scrubber_cache, key, fn _key -> ensure_scrubbed_html(content, scrubbers) end) + end + + def get_cached_stripped_html_for_object(content, object) do + get_cached_scrubbed_html_for_object(content, HtmlSanitizeEx.Scrubber.StripTags, object) + end + + def ensure_scrubbed_html( + content, + scrubbers + ) do + {:commit, filter_tags(content, scrubbers)} + end + + defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do + generate_scrubber_signature([scrubber]) + end + + defp generate_scrubber_signature(scrubbers) do + Enum.reduce(scrubbers, "", fn scrubber, signature -> + # If a scrubber does not have a version(e.g HtmlSanitizeEx.Scrubber.StripTags) it is assumed it is always 0) + version = + if Kernel.function_exported?(scrubber, :version, 0) do + scrubber.version + else + 0 + end + + "#{signature}#{to_string(scrubber)}#{version}" + end) + end end defmodule Pleroma.HTML.Scrubber.TwitterText do diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 9a6c256df..5241f00ae 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -4,7 +4,6 @@ defmodule Pleroma.Object do use Ecto.Schema - alias Pleroma.{Repo, Object, User, Activity, HTML, ObjectTombstone} alias Pleroma.{Repo, Object, User, Activity, ObjectTombstone} import Ecto.{Query, Changeset} @@ -92,37 +91,4 @@ defmodule Pleroma.Object do end end - def get_cached_scrubbed_html(content, scrubbers, object) do - key = "#{generate_scrubber_signature(scrubbers)}|#{object.id}" - Cachex.fetch!(:scrubber_cache, key, fn _key -> ensure_scrubbed_html(content, scrubbers) end) - end - - def get_cached_stripped_html(content, object) do - get_cached_scrubbed_html(content, HtmlSanitizeEx.Scrubber.StripTags, object) - end - - def ensure_scrubbed_html( - content, - scrubbers - ) do - {:commit, HTML.filter_tags(content, scrubbers)} - end - - defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do - generate_scrubber_signature([scrubber]) - end - - defp generate_scrubber_signature(scrubbers) do - Enum.reduce(scrubbers, "", fn scrubber, signature -> - # If a scrubber does not have a version(e.g HtmlSanitizeEx.Scrubber.StripTags) it is assumed it is always 0) - version = - if Kernel.function_exported?(scrubber, :version, 0) do - scrubber.version - else - 0 - end - - "#{signature}#{to_string(scrubber)}#{version}" - end) - end end diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 8a57a233a..da61bbd86 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -9,7 +9,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do alias Pleroma.HTML alias Pleroma.Repo alias Pleroma.User - alias Pleroma.Object alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MediaProxy alias Pleroma.Web.MastodonAPI.AccountView @@ -121,7 +120,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do content = object |> render_content() - |> Object.get_cached_scrubbed_html(User.html_filter_policy(opts[:for]), activity) + |> HTML.get_cached_scrubbed_html_for_object(User.html_filter_policy(opts[:for]), activity) %{ id: to_string(activity.id), diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 4c29e03ce..469f780c7 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -11,6 +11,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter alias Pleroma.Activity + alias Pleroma.HTML alias Pleroma.Object alias Pleroma.User alias Pleroma.Repo @@ -244,14 +245,14 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do html = content - |> Object.get_cached_scrubbed_html(User.html_filter_policy(opts[:for]), activity) + |> HTML.get_cached_scrubbed_html_for_object(User.html_filter_policy(opts[:for]), activity) |> Formatter.emojify(object["emoji"]) text = if content do content |> String.replace(~r//, "\n") - |> Object.get_cached_stripped_html(activity) + |> HTML.get_cached_stripped_html_for_object(activity) end reply_parent = Activity.get_in_reply_to_activity(activity) -- cgit v1.2.3 From 6ed9b31a5fea055aad7d390d50ead4cdfd6b7378 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Mon, 31 Dec 2018 08:25:48 +0100 Subject: Eh? --- lib/pleroma/object.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 5241f00ae..e2b648727 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -90,5 +90,4 @@ defmodule Pleroma.Object do {:ok, object} end end - end -- cgit v1.2.3 From 980b5288ed119a3579afe632dff3391528ff399c Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 31 Dec 2018 15:41:47 +0000 Subject: update copyright years to 2019 --- lib/pleroma/PasswordResetToken.ex | 2 +- lib/pleroma/activity.ex | 2 +- lib/pleroma/application.ex | 2 +- lib/pleroma/captcha/captcha.ex | 2 +- lib/pleroma/captcha/captcha_service.ex | 2 +- lib/pleroma/captcha/kocaptcha.ex | 2 +- lib/pleroma/config.ex | 2 +- lib/pleroma/emails/mailer.ex | 2 +- lib/pleroma/emails/user_email.ex | 2 +- lib/pleroma/emoji.ex | 2 +- lib/pleroma/filter.ex | 2 +- lib/pleroma/formatter.ex | 2 +- lib/pleroma/gopher/server.ex | 2 +- lib/pleroma/html.ex | 2 +- lib/pleroma/http/connection.ex | 2 +- lib/pleroma/http/http.ex | 2 +- lib/pleroma/http/request_builder.ex | 2 +- lib/pleroma/list.ex | 2 +- lib/pleroma/mime.ex | 2 +- lib/pleroma/notification.ex | 2 +- lib/pleroma/object.ex | 2 +- lib/pleroma/plugs/admin_secret_authentication_plug.ex | 2 +- lib/pleroma/plugs/authentication_plug.ex | 2 +- lib/pleroma/plugs/basic_auth_decoder_plug.ex | 2 +- lib/pleroma/plugs/digest.ex | 2 +- lib/pleroma/plugs/ensure_authenticated_plug.ex | 2 +- lib/pleroma/plugs/ensure_user_key_plug.ex | 2 +- lib/pleroma/plugs/federating_plug.ex | 2 +- lib/pleroma/plugs/http_security_plug.ex | 2 +- lib/pleroma/plugs/http_signature.ex | 2 +- lib/pleroma/plugs/instance_static.ex | 2 +- lib/pleroma/plugs/legacy_authentication_plug.ex | 2 +- lib/pleroma/plugs/oauth_plug.ex | 2 +- lib/pleroma/plugs/session_authentication_plug.ex | 2 +- lib/pleroma/plugs/set_user_session_id_plug.ex | 2 +- lib/pleroma/plugs/uploaded_media.ex | 2 +- lib/pleroma/plugs/user_enabled_plug.ex | 2 +- lib/pleroma/plugs/user_fetcher_plug.ex | 2 +- lib/pleroma/plugs/user_is_admin_plug.ex | 2 +- lib/pleroma/repo.ex | 2 +- lib/pleroma/reverse_proxy.ex | 2 +- lib/pleroma/stats.ex | 2 +- lib/pleroma/upload.ex | 2 +- lib/pleroma/upload/filter.ex | 2 +- lib/pleroma/upload/filter/anonymize_filename.ex | 2 +- lib/pleroma/upload/filter/dedupe.ex | 2 +- lib/pleroma/upload/filter/mogrifun.ex | 2 +- lib/pleroma/upload/filter/mogrify.ex | 2 +- lib/pleroma/uploaders/local.ex | 2 +- lib/pleroma/uploaders/mdii.ex | 2 +- lib/pleroma/uploaders/s3.ex | 2 +- lib/pleroma/uploaders/swift/keystone.ex | 2 +- lib/pleroma/uploaders/swift/swift.ex | 2 +- lib/pleroma/uploaders/swift/uploader.ex | 2 +- lib/pleroma/uploaders/uploader.ex | 2 +- lib/pleroma/user.ex | 2 +- lib/pleroma/user/info.ex | 2 +- lib/pleroma/user_invite_token.ex | 2 +- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/activity_pub/activity_pub_controller.ex | 2 +- lib/pleroma/web/activity_pub/mrf.ex | 2 +- lib/pleroma/web/activity_pub/mrf/drop_policy.ex | 2 +- lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex | 2 +- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 2 +- lib/pleroma/web/activity_pub/mrf/noop_policy.ex | 2 +- lib/pleroma/web/activity_pub/mrf/normalize_markup.ex | 2 +- lib/pleroma/web/activity_pub/mrf/reject_non_public.ex | 2 +- lib/pleroma/web/activity_pub/mrf/simple_policy.ex | 2 +- lib/pleroma/web/activity_pub/mrf/user_allowlist.ex | 2 +- lib/pleroma/web/activity_pub/relay.ex | 2 +- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- lib/pleroma/web/activity_pub/utils.ex | 2 +- lib/pleroma/web/activity_pub/views/object_view.ex | 2 +- lib/pleroma/web/activity_pub/views/user_view.ex | 2 +- lib/pleroma/web/admin_api/admin_api_controller.ex | 2 +- lib/pleroma/web/channels/user_socket.ex | 2 +- lib/pleroma/web/chat_channel.ex | 2 +- lib/pleroma/web/common_api/common_api.ex | 2 +- lib/pleroma/web/common_api/utils.ex | 2 +- lib/pleroma/web/controller_helper.ex | 2 +- lib/pleroma/web/endpoint.ex | 2 +- lib/pleroma/web/federator/federator.ex | 2 +- lib/pleroma/web/federator/retry_queue.ex | 2 +- lib/pleroma/web/gettext.ex | 2 +- lib/pleroma/web/http_signatures/http_signatures.ex | 2 +- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +- lib/pleroma/web/mastodon_api/views/account_view.ex | 2 +- lib/pleroma/web/mastodon_api/views/filter_view.ex | 2 +- lib/pleroma/web/mastodon_api/views/list_view.ex | 2 +- lib/pleroma/web/mastodon_api/views/mastodon_view.ex | 2 +- lib/pleroma/web/mastodon_api/views/push_subscription_view.ex | 2 +- lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- lib/pleroma/web/mastodon_api/websocket_handler.ex | 2 +- lib/pleroma/web/media_proxy/controller.ex | 2 +- lib/pleroma/web/media_proxy/media_proxy.ex | 2 +- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 2 +- lib/pleroma/web/oauth/app.ex | 2 +- lib/pleroma/web/oauth/authorization.ex | 2 +- lib/pleroma/web/oauth/fallback_controller.ex | 2 +- lib/pleroma/web/oauth/oauth_controller.ex | 2 +- lib/pleroma/web/oauth/oauth_view.ex | 2 +- lib/pleroma/web/oauth/token.ex | 2 +- lib/pleroma/web/ostatus/activity_representer.ex | 2 +- lib/pleroma/web/ostatus/feed_representer.ex | 2 +- lib/pleroma/web/ostatus/handlers/delete_handler.ex | 2 +- lib/pleroma/web/ostatus/handlers/follow_handler.ex | 2 +- lib/pleroma/web/ostatus/handlers/note_handler.ex | 2 +- lib/pleroma/web/ostatus/handlers/unfollow_handler.ex | 2 +- lib/pleroma/web/ostatus/ostatus.ex | 2 +- lib/pleroma/web/ostatus/ostatus_controller.ex | 2 +- lib/pleroma/web/ostatus/user_representer.ex | 2 +- lib/pleroma/web/push/push.ex | 2 +- lib/pleroma/web/push/subscription.ex | 2 +- lib/pleroma/web/router.ex | 2 +- lib/pleroma/web/salmon/salmon.ex | 2 +- lib/pleroma/web/streamer.ex | 2 +- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 2 +- lib/pleroma/web/twitter_api/representers/activity_representer.ex | 2 +- lib/pleroma/web/twitter_api/representers/base_representer.ex | 2 +- lib/pleroma/web/twitter_api/representers/object_representer.ex | 2 +- lib/pleroma/web/twitter_api/twitter_api.ex | 2 +- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 2 +- lib/pleroma/web/twitter_api/views/activity_view.ex | 2 +- lib/pleroma/web/twitter_api/views/notification_view.ex | 2 +- lib/pleroma/web/twitter_api/views/user_view.ex | 2 +- lib/pleroma/web/twitter_api/views/util_view.ex | 2 +- lib/pleroma/web/views/error_helpers.ex | 2 +- lib/pleroma/web/views/error_view.ex | 2 +- lib/pleroma/web/views/layout_view.ex | 2 +- lib/pleroma/web/web.ex | 2 +- lib/pleroma/web/web_finger/web_finger.ex | 2 +- lib/pleroma/web/web_finger/web_finger_controller.ex | 2 +- lib/pleroma/web/websub/websub.ex | 2 +- lib/pleroma/web/websub/websub_client_subscription.ex | 2 +- lib/pleroma/web/websub/websub_controller.ex | 2 +- lib/pleroma/web/websub/websub_server_subscription.ex | 2 +- lib/pleroma/web/xml/xml.ex | 2 +- 137 files changed, 137 insertions(+), 137 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/PasswordResetToken.ex b/lib/pleroma/PasswordResetToken.ex index 57e3b7ef0..1dccdadae 100644 --- a/lib/pleroma/PasswordResetToken.ex +++ b/lib/pleroma/PasswordResetToken.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.PasswordResetToken do diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index a14d1e8c6..353f9f6cd 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Activity do diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 4b997c048..4542ed623 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Application do diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index f80946c8b..133a9fd68 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Captcha do diff --git a/lib/pleroma/captcha/captcha_service.ex b/lib/pleroma/captcha/captcha_service.ex index 6037b7087..a820751a8 100644 --- a/lib/pleroma/captcha/captcha_service.ex +++ b/lib/pleroma/captcha/captcha_service.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Captcha.Service do diff --git a/lib/pleroma/captcha/kocaptcha.ex b/lib/pleroma/captcha/kocaptcha.ex index 54f4c8bcd..66f9ce754 100644 --- a/lib/pleroma/captcha/kocaptcha.ex +++ b/lib/pleroma/captcha/kocaptcha.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Captcha.Kocaptcha do diff --git a/lib/pleroma/config.ex b/lib/pleroma/config.ex index 6b1598d66..21507cd38 100644 --- a/lib/pleroma/config.ex +++ b/lib/pleroma/config.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Config do diff --git a/lib/pleroma/emails/mailer.ex b/lib/pleroma/emails/mailer.ex index a8bd70b6e..8d12641f2 100644 --- a/lib/pleroma/emails/mailer.ex +++ b/lib/pleroma/emails/mailer.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Mailer do diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index 688b0cd1c..c42c53c99 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.UserEmail do diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex index b5e0a83d8..bb3190e08 100644 --- a/lib/pleroma/emoji.ex +++ b/lib/pleroma/emoji.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Emoji do diff --git a/lib/pleroma/filter.ex b/lib/pleroma/filter.ex index 9ddc5fd6c..df5374a5c 100644 --- a/lib/pleroma/filter.ex +++ b/lib/pleroma/filter.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Filter do diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 49a9913dc..d80ae6576 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Formatter do diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index fee7156d3..336142e9b 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Gopher.Server do diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index eb31f131e..71db516e6 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.HTML do diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index 35c1490da..1c3187768 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.HTTP.Connection do diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex index 32d9cf5aa..f12f33566 100644 --- a/lib/pleroma/http/http.ex +++ b/lib/pleroma/http/http.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.HTTP do diff --git a/lib/pleroma/http/request_builder.ex b/lib/pleroma/http/request_builder.ex index 54569c6f7..bffc7c6fe 100644 --- a/lib/pleroma/http/request_builder.ex +++ b/lib/pleroma/http/request_builder.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.HTTP.RequestBuilder do diff --git a/lib/pleroma/list.ex b/lib/pleroma/list.ex index 2c799bc33..a75dc006e 100644 --- a/lib/pleroma/list.ex +++ b/lib/pleroma/list.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.List do diff --git a/lib/pleroma/mime.ex b/lib/pleroma/mime.ex index e3a389749..84fb536e0 100644 --- a/lib/pleroma/mime.ex +++ b/lib/pleroma/mime.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.MIME do diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index b5aadfd17..51d59870c 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Notification do diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index e2b648727..ff5eb9b27 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Object do diff --git a/lib/pleroma/plugs/admin_secret_authentication_plug.ex b/lib/pleroma/plugs/admin_secret_authentication_plug.ex index 2c9348715..5baf8a691 100644 --- a/lib/pleroma/plugs/admin_secret_authentication_plug.ex +++ b/lib/pleroma/plugs/admin_secret_authentication_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.AdminSecretAuthenticationPlug do diff --git a/lib/pleroma/plugs/authentication_plug.ex b/lib/pleroma/plugs/authentication_plug.ex index 6b8d51300..da4ed4226 100644 --- a/lib/pleroma/plugs/authentication_plug.ex +++ b/lib/pleroma/plugs/authentication_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.AuthenticationPlug do diff --git a/lib/pleroma/plugs/basic_auth_decoder_plug.ex b/lib/pleroma/plugs/basic_auth_decoder_plug.ex index 0690f4bea..7eeeb1e5d 100644 --- a/lib/pleroma/plugs/basic_auth_decoder_plug.ex +++ b/lib/pleroma/plugs/basic_auth_decoder_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.BasicAuthDecoderPlug do diff --git a/lib/pleroma/plugs/digest.ex b/lib/pleroma/plugs/digest.ex index 27b206965..0ba00845a 100644 --- a/lib/pleroma/plugs/digest.ex +++ b/lib/pleroma/plugs/digest.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Plugs.DigestPlug do diff --git a/lib/pleroma/plugs/ensure_authenticated_plug.ex b/lib/pleroma/plugs/ensure_authenticated_plug.ex index f18653f41..11c4342c4 100644 --- a/lib/pleroma/plugs/ensure_authenticated_plug.ex +++ b/lib/pleroma/plugs/ensure_authenticated_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.EnsureAuthenticatedPlug do diff --git a/lib/pleroma/plugs/ensure_user_key_plug.ex b/lib/pleroma/plugs/ensure_user_key_plug.ex index db3da228d..c88ebfb3f 100644 --- a/lib/pleroma/plugs/ensure_user_key_plug.ex +++ b/lib/pleroma/plugs/ensure_user_key_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.EnsureUserKeyPlug do diff --git a/lib/pleroma/plugs/federating_plug.ex b/lib/pleroma/plugs/federating_plug.ex index e7dfda295..effc154bf 100644 --- a/lib/pleroma/plugs/federating_plug.ex +++ b/lib/pleroma/plugs/federating_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.FederatingPlug do diff --git a/lib/pleroma/plugs/http_security_plug.ex b/lib/pleroma/plugs/http_security_plug.ex index 11bceafd4..2a266c407 100644 --- a/lib/pleroma/plugs/http_security_plug.ex +++ b/lib/pleroma/plugs/http_security_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.HTTPSecurityPlug do diff --git a/lib/pleroma/plugs/http_signature.ex b/lib/pleroma/plugs/http_signature.ex index 33fbba840..51bec910e 100644 --- a/lib/pleroma/plugs/http_signature.ex +++ b/lib/pleroma/plugs/http_signature.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do diff --git a/lib/pleroma/plugs/instance_static.ex b/lib/pleroma/plugs/instance_static.ex index 02ee99e0f..af2f6f331 100644 --- a/lib/pleroma/plugs/instance_static.ex +++ b/lib/pleroma/plugs/instance_static.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.InstanceStatic do diff --git a/lib/pleroma/plugs/legacy_authentication_plug.ex b/lib/pleroma/plugs/legacy_authentication_plug.ex index 3cb3fdf4b..78b7e388f 100644 --- a/lib/pleroma/plugs/legacy_authentication_plug.ex +++ b/lib/pleroma/plugs/legacy_authentication_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.LegacyAuthenticationPlug do diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 7c3541197..437aa95b3 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.OAuthPlug do diff --git a/lib/pleroma/plugs/session_authentication_plug.ex b/lib/pleroma/plugs/session_authentication_plug.ex index 413bdcf2c..a08484b65 100644 --- a/lib/pleroma/plugs/session_authentication_plug.ex +++ b/lib/pleroma/plugs/session_authentication_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.SessionAuthenticationPlug do diff --git a/lib/pleroma/plugs/set_user_session_id_plug.ex b/lib/pleroma/plugs/set_user_session_id_plug.ex index 9fad6dfee..9265cc116 100644 --- a/lib/pleroma/plugs/set_user_session_id_plug.ex +++ b/lib/pleroma/plugs/set_user_session_id_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.SetUserSessionIdPlug do diff --git a/lib/pleroma/plugs/uploaded_media.ex b/lib/pleroma/plugs/uploaded_media.ex index f998293e8..be53ac00c 100644 --- a/lib/pleroma/plugs/uploaded_media.ex +++ b/lib/pleroma/plugs/uploaded_media.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.UploadedMedia do diff --git a/lib/pleroma/plugs/user_enabled_plug.ex b/lib/pleroma/plugs/user_enabled_plug.ex index 79d6a9b99..da892c28b 100644 --- a/lib/pleroma/plugs/user_enabled_plug.ex +++ b/lib/pleroma/plugs/user_enabled_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.UserEnabledPlug do diff --git a/lib/pleroma/plugs/user_fetcher_plug.ex b/lib/pleroma/plugs/user_fetcher_plug.ex index 04957148b..f874e2f95 100644 --- a/lib/pleroma/plugs/user_fetcher_plug.ex +++ b/lib/pleroma/plugs/user_fetcher_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.UserFetcherPlug do diff --git a/lib/pleroma/plugs/user_is_admin_plug.ex b/lib/pleroma/plugs/user_is_admin_plug.ex index a98c2c853..04329e919 100644 --- a/lib/pleroma/plugs/user_is_admin_plug.ex +++ b/lib/pleroma/plugs/user_is_admin_plug.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.UserIsAdminPlug do diff --git a/lib/pleroma/repo.ex b/lib/pleroma/repo.ex index 0b49f7712..e6a51b19e 100644 --- a/lib/pleroma/repo.ex +++ b/lib/pleroma/repo.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Repo do diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index c9d6f0d2c..a3846c3bb 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.ReverseProxy do diff --git a/lib/pleroma/stats.ex b/lib/pleroma/stats.ex index c48184ed3..8a030ecd0 100644 --- a/lib/pleroma/stats.ex +++ b/lib/pleroma/stats.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Stats do diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 744abec56..0b1bdeec4 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Upload do diff --git a/lib/pleroma/upload/filter.ex b/lib/pleroma/upload/filter.ex index f7257be65..fa02a55de 100644 --- a/lib/pleroma/upload/filter.ex +++ b/lib/pleroma/upload/filter.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Upload.Filter do diff --git a/lib/pleroma/upload/filter/anonymize_filename.ex b/lib/pleroma/upload/filter/anonymize_filename.ex index c26e4f32c..5ca53a79b 100644 --- a/lib/pleroma/upload/filter/anonymize_filename.ex +++ b/lib/pleroma/upload/filter/anonymize_filename.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Upload.Filter.AnonymizeFilename do diff --git a/lib/pleroma/upload/filter/dedupe.ex b/lib/pleroma/upload/filter/dedupe.ex index 2d1ddab7f..8fcce320f 100644 --- a/lib/pleroma/upload/filter/dedupe.ex +++ b/lib/pleroma/upload/filter/dedupe.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Upload.Filter.Dedupe do diff --git a/lib/pleroma/upload/filter/mogrifun.ex b/lib/pleroma/upload/filter/mogrifun.ex index f8920d31b..35a5a1381 100644 --- a/lib/pleroma/upload/filter/mogrifun.ex +++ b/lib/pleroma/upload/filter/mogrifun.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Upload.Filter.Mogrifun do diff --git a/lib/pleroma/upload/filter/mogrify.ex b/lib/pleroma/upload/filter/mogrify.ex index 7331c2bd9..f459eeecb 100644 --- a/lib/pleroma/upload/filter/mogrify.ex +++ b/lib/pleroma/upload/filter/mogrify.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Upload.Filter.Mogrify do diff --git a/lib/pleroma/uploaders/local.ex b/lib/pleroma/uploaders/local.ex index de50a13c1..fc533da23 100644 --- a/lib/pleroma/uploaders/local.ex +++ b/lib/pleroma/uploaders/local.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Uploaders.Local do diff --git a/lib/pleroma/uploaders/mdii.ex b/lib/pleroma/uploaders/mdii.ex index b16782fbb..530b34362 100644 --- a/lib/pleroma/uploaders/mdii.ex +++ b/lib/pleroma/uploaders/mdii.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Uploaders.MDII do diff --git a/lib/pleroma/uploaders/s3.ex b/lib/pleroma/uploaders/s3.ex index db5e8b75e..108cf06b5 100644 --- a/lib/pleroma/uploaders/s3.ex +++ b/lib/pleroma/uploaders/s3.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Uploaders.S3 do diff --git a/lib/pleroma/uploaders/swift/keystone.ex b/lib/pleroma/uploaders/swift/keystone.ex index f10361b19..b4f250f9d 100644 --- a/lib/pleroma/uploaders/swift/keystone.ex +++ b/lib/pleroma/uploaders/swift/keystone.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Uploaders.Swift.Keystone do diff --git a/lib/pleroma/uploaders/swift/swift.ex b/lib/pleroma/uploaders/swift/swift.ex index fef426b42..2b0f2ad04 100644 --- a/lib/pleroma/uploaders/swift/swift.ex +++ b/lib/pleroma/uploaders/swift/swift.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Uploaders.Swift.Client do diff --git a/lib/pleroma/uploaders/swift/uploader.ex b/lib/pleroma/uploaders/swift/uploader.ex index d359ff8f8..d122b09e7 100644 --- a/lib/pleroma/uploaders/swift/uploader.ex +++ b/lib/pleroma/uploaders/swift/uploader.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Uploaders.Swift do diff --git a/lib/pleroma/uploaders/uploader.ex b/lib/pleroma/uploaders/uploader.ex index 49da6e9a9..0959d7a3e 100644 --- a/lib/pleroma/uploaders/uploader.ex +++ b/lib/pleroma/uploaders/uploader.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Uploaders.Uploader do diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index b90a3efae..892f4e483 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.User do diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 71848d91e..2f419a5a2 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.User.Info do diff --git a/lib/pleroma/user_invite_token.ex b/lib/pleroma/user_invite_token.ex index 65ffe149c..5a448114c 100644 --- a/lib/pleroma/user_invite_token.ex +++ b/lib/pleroma/user_invite_token.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.UserInviteToken do diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 167471b7b..b9b95a0e9 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ActivityPub do diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index e41b14afc..fc7972eaf 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ActivityPubController do diff --git a/lib/pleroma/web/activity_pub/mrf.ex b/lib/pleroma/web/activity_pub/mrf.ex index 00919a5f6..eebea207c 100644 --- a/lib/pleroma/web/activity_pub/mrf.ex +++ b/lib/pleroma/web/activity_pub/mrf.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF do diff --git a/lib/pleroma/web/activity_pub/mrf/drop_policy.ex b/lib/pleroma/web/activity_pub/mrf/drop_policy.ex index 6ac7b0ec1..a93ccf386 100644 --- a/lib/pleroma/web/activity_pub/mrf/drop_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/drop_policy.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do diff --git a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex index ca3ee8a0d..895376c9d 100644 --- a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex +++ b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrepended do diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index e4fb0b5b0..a3f516ae7 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do diff --git a/lib/pleroma/web/activity_pub/mrf/noop_policy.ex b/lib/pleroma/web/activity_pub/mrf/noop_policy.ex index 8eacc62bc..40f37bdb1 100644 --- a/lib/pleroma/web/activity_pub/mrf/noop_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/noop_policy.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do diff --git a/lib/pleroma/web/activity_pub/mrf/normalize_markup.ex b/lib/pleroma/web/activity_pub/mrf/normalize_markup.ex index 6cfd43974..3d13cdb32 100644 --- a/lib/pleroma/web/activity_pub/mrf/normalize_markup.ex +++ b/lib/pleroma/web/activity_pub/mrf/normalize_markup.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do diff --git a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex index 07d739437..4197be847 100644 --- a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex +++ b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do diff --git a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex index 9ced1e620..798ba9687 100644 --- a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do diff --git a/lib/pleroma/web/activity_pub/mrf/user_allowlist.ex b/lib/pleroma/web/activity_pub/mrf/user_allowlist.ex index 7a78c50bf..a3b1f8aa0 100644 --- a/lib/pleroma/web/activity_pub/mrf/user_allowlist.ex +++ b/lib/pleroma/web/activity_pub/mrf/user_allowlist.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy do diff --git a/lib/pleroma/web/activity_pub/relay.ex b/lib/pleroma/web/activity_pub/relay.ex index d0a866589..abddbc790 100644 --- a/lib/pleroma/web/activity_pub/relay.ex +++ b/lib/pleroma/web/activity_pub/relay.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Relay do diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 315571e1a..87b7fc07f 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Transmogrifier do diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 59cf6abfc..b313996db 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Utils do diff --git a/lib/pleroma/web/activity_pub/views/object_view.ex b/lib/pleroma/web/activity_pub/views/object_view.ex index efe16b2bf..b5c9bf8d0 100644 --- a/lib/pleroma/web/activity_pub/views/object_view.ex +++ b/lib/pleroma/web/activity_pub/views/object_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectView do diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 439d834e4..fe8248107 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.UserView do diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 49d237661..f6d90b552 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.AdminAPI.AdminAPIController do diff --git a/lib/pleroma/web/channels/user_socket.ex b/lib/pleroma/web/channels/user_socket.ex index 23ba5a381..aed8475fd 100644 --- a/lib/pleroma/web/channels/user_socket.ex +++ b/lib/pleroma/web/channels/user_socket.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.UserSocket do diff --git a/lib/pleroma/web/chat_channel.ex b/lib/pleroma/web/chat_channel.ex index ac28f300b..fe63ede66 100644 --- a/lib/pleroma/web/chat_channel.ex +++ b/lib/pleroma/web/chat_channel.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ChatChannel do diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 085a95172..e474653ff 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPI do diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index b91cfc4bb..3ff9f9452 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPI.Utils do diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index cb0463eeb..14e3d19fd 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ControllerHelper do diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index e994f8f37..0b4ce9cc4 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Endpoint do diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index 3aec55274..d25bfc0c1 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Federator do diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex index e4340af7c..c57bbb77c 100644 --- a/lib/pleroma/web/federator/retry_queue.ex +++ b/lib/pleroma/web/federator/retry_queue.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Federator.RetryQueue do diff --git a/lib/pleroma/web/gettext.ex b/lib/pleroma/web/gettext.ex index f40fd04c0..1328b46cc 100644 --- a/lib/pleroma/web/gettext.ex +++ b/lib/pleroma/web/gettext.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Gettext do diff --git a/lib/pleroma/web/http_signatures/http_signatures.ex b/lib/pleroma/web/http_signatures/http_signatures.ex index 0e4f8f14b..e81f9e27a 100644 --- a/lib/pleroma/web/http_signatures/http_signatures.ex +++ b/lib/pleroma/web/http_signatures/http_signatures.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only # https://tools.ietf.org/html/draft-cavage-http-signatures-08 diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 663a0fa08..11fcd1c11 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 555383503..bfd6b8b22 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.AccountView do diff --git a/lib/pleroma/web/mastodon_api/views/filter_view.ex b/lib/pleroma/web/mastodon_api/views/filter_view.ex index ffbd830e1..1052a449d 100644 --- a/lib/pleroma/web/mastodon_api/views/filter_view.ex +++ b/lib/pleroma/web/mastodon_api/views/filter_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.FilterView do diff --git a/lib/pleroma/web/mastodon_api/views/list_view.ex b/lib/pleroma/web/mastodon_api/views/list_view.ex index dd0121f7a..0f86e2512 100644 --- a/lib/pleroma/web/mastodon_api/views/list_view.ex +++ b/lib/pleroma/web/mastodon_api/views/list_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.ListView do diff --git a/lib/pleroma/web/mastodon_api/views/mastodon_view.ex b/lib/pleroma/web/mastodon_api/views/mastodon_view.ex index a3adabc50..33b9a74be 100644 --- a/lib/pleroma/web/mastodon_api/views/mastodon_view.ex +++ b/lib/pleroma/web/mastodon_api/views/mastodon_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.MastodonView do diff --git a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex index 7970bcd47..e86b789c5 100644 --- a/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex +++ b/lib/pleroma/web/mastodon_api/views/push_subscription_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.PushSubscriptionView do diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index da61bbd86..477ab3b5f 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.StatusView do diff --git a/lib/pleroma/web/mastodon_api/websocket_handler.ex b/lib/pleroma/web/mastodon_api/websocket_handler.ex index 7b90649ad..c0254c8e6 100644 --- a/lib/pleroma/web/mastodon_api/websocket_handler.ex +++ b/lib/pleroma/web/mastodon_api/websocket_handler.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex index 8c82b4176..de79cad73 100644 --- a/lib/pleroma/web/media_proxy/controller.ex +++ b/lib/pleroma/web/media_proxy/controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MediaProxy.MediaProxyController do diff --git a/lib/pleroma/web/media_proxy/media_proxy.ex b/lib/pleroma/web/media_proxy/media_proxy.ex index a61726b3e..e1eb1472d 100644 --- a/lib/pleroma/web/media_proxy/media_proxy.ex +++ b/lib/pleroma/web/media_proxy/media_proxy.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MediaProxy do diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index a992f75f6..11b97164d 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Nodeinfo.NodeinfoController do diff --git a/lib/pleroma/web/oauth/app.ex b/lib/pleroma/web/oauth/app.ex index c18e9da8c..967ac04b5 100644 --- a/lib/pleroma/web/oauth/app.ex +++ b/lib/pleroma/web/oauth/app.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth.App do diff --git a/lib/pleroma/web/oauth/authorization.ex b/lib/pleroma/web/oauth/authorization.ex index 7e75d71b3..cc4b74bc5 100644 --- a/lib/pleroma/web/oauth/authorization.ex +++ b/lib/pleroma/web/oauth/authorization.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth.Authorization do diff --git a/lib/pleroma/web/oauth/fallback_controller.ex b/lib/pleroma/web/oauth/fallback_controller.ex index e1d91dc80..1eeda3d24 100644 --- a/lib/pleroma/web/oauth/fallback_controller.ex +++ b/lib/pleroma/web/oauth/fallback_controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth.FallbackController do diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 41b0f253d..4d4e85836 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth.OAuthController do diff --git a/lib/pleroma/web/oauth/oauth_view.ex b/lib/pleroma/web/oauth/oauth_view.ex index da6f72433..9b37a91c5 100644 --- a/lib/pleroma/web/oauth/oauth_view.ex +++ b/lib/pleroma/web/oauth/oauth_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth.OAuthView do diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index aa3610bb3..f0ebc63f6 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth.Token do diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index bd05c671b..94b1a7ad1 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.ActivityRepresenter do diff --git a/lib/pleroma/web/ostatus/feed_representer.ex b/lib/pleroma/web/ostatus/feed_representer.ex index 2c2157173..934d4042f 100644 --- a/lib/pleroma/web/ostatus/feed_representer.ex +++ b/lib/pleroma/web/ostatus/feed_representer.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.FeedRepresenter do diff --git a/lib/pleroma/web/ostatus/handlers/delete_handler.ex b/lib/pleroma/web/ostatus/handlers/delete_handler.ex index e7cf4cb54..01b52f08f 100644 --- a/lib/pleroma/web/ostatus/handlers/delete_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/delete_handler.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.DeleteHandler do diff --git a/lib/pleroma/web/ostatus/handlers/follow_handler.ex b/lib/pleroma/web/ostatus/handlers/follow_handler.ex index aef450935..becdf2fbf 100644 --- a/lib/pleroma/web/ostatus/handlers/follow_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/follow_handler.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.FollowHandler do diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex index 7fd364b45..5aeed46f0 100644 --- a/lib/pleroma/web/ostatus/handlers/note_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.NoteHandler do diff --git a/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex b/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex index bd86a54c7..1c64f3c3d 100644 --- a/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.UnfollowHandler do diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index cd5493e16..bb28cd786 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus do diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 9ad702dd4..9b600737f 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.OStatusController do diff --git a/lib/pleroma/web/ostatus/user_representer.ex b/lib/pleroma/web/ostatus/user_representer.ex index ef8371a2c..852be6eb4 100644 --- a/lib/pleroma/web/ostatus/user_representer.ex +++ b/lib/pleroma/web/ostatus/user_representer.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.UserRepresenter do diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index 6459d4543..ffd2aac91 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Push do diff --git a/lib/pleroma/web/push/subscription.ex b/lib/pleroma/web/push/subscription.ex index 65d28fee9..82b30950c 100644 --- a/lib/pleroma/web/push/subscription.ex +++ b/lib/pleroma/web/push/subscription.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Push.Subscription do diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 33c573d46..1f929ee21 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Router do diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index f7d2257eb..e41657da1 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Salmon do diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index 05f877438..3136b1b9d 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Streamer do diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 87b8b71ba..a79072f3d 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.UtilController do diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 489a55b6c..2a221cc66 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only # THIS MODULE IS DEPRECATED! DON'T USE IT! diff --git a/lib/pleroma/web/twitter_api/representers/base_representer.ex b/lib/pleroma/web/twitter_api/representers/base_representer.ex index 28a59205d..3d31e6079 100644 --- a/lib/pleroma/web/twitter_api/representers/base_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/base_representer.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.Representers.BaseRepresenter do diff --git a/lib/pleroma/web/twitter_api/representers/object_representer.ex b/lib/pleroma/web/twitter_api/representers/object_representer.ex index 2f33e7af4..47130ba06 100644 --- a/lib/pleroma/web/twitter_api/representers/object_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/object_representer.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter do diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index e2b1e0a8e..0aa4a8d23 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.TwitterAPI do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index aebc3bff4..1e04b8c4b 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.Controller do diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 469f780c7..84f35ebf9 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.ActivityView do diff --git a/lib/pleroma/web/twitter_api/views/notification_view.ex b/lib/pleroma/web/twitter_api/views/notification_view.ex index d889038a2..d6a1c0a4d 100644 --- a/lib/pleroma/web/twitter_api/views/notification_view.ex +++ b/lib/pleroma/web/twitter_api/views/notification_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.NotificationView do diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index ede3c0d25..40db0b117 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.UserView do diff --git a/lib/pleroma/web/twitter_api/views/util_view.ex b/lib/pleroma/web/twitter_api/views/util_view.ex index aa5f842ac..f4050650e 100644 --- a/lib/pleroma/web/twitter_api/views/util_view.ex +++ b/lib/pleroma/web/twitter_api/views/util_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.UtilView do diff --git a/lib/pleroma/web/views/error_helpers.ex b/lib/pleroma/web/views/error_helpers.ex index df1e0d437..bc08e60e4 100644 --- a/lib/pleroma/web/views/error_helpers.ex +++ b/lib/pleroma/web/views/error_helpers.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ErrorHelpers do diff --git a/lib/pleroma/web/views/error_view.ex b/lib/pleroma/web/views/error_view.ex index d8158edb4..86a1744b7 100644 --- a/lib/pleroma/web/views/error_view.ex +++ b/lib/pleroma/web/views/error_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ErrorView do diff --git a/lib/pleroma/web/views/layout_view.ex b/lib/pleroma/web/views/layout_view.ex index ba94b9def..e5183701d 100644 --- a/lib/pleroma/web/views/layout_view.ex +++ b/lib/pleroma/web/views/layout_view.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.LayoutView do diff --git a/lib/pleroma/web/web.ex b/lib/pleroma/web/web.ex index 1aa86f645..74b13f929 100644 --- a/lib/pleroma/web/web.ex +++ b/lib/pleroma/web/web.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web do diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 3cc90d5dd..0a6338312 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.WebFinger do diff --git a/lib/pleroma/web/web_finger/web_finger_controller.ex b/lib/pleroma/web/web_finger/web_finger_controller.ex index 66d5a880d..b77c75ec5 100644 --- a/lib/pleroma/web/web_finger/web_finger_controller.ex +++ b/lib/pleroma/web/web_finger/web_finger_controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.WebFinger.WebFingerController do diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 628ec38c5..3a287edd9 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Websub do diff --git a/lib/pleroma/web/websub/websub_client_subscription.ex b/lib/pleroma/web/websub/websub_client_subscription.ex index 2f511cd5b..105b0069f 100644 --- a/lib/pleroma/web/websub/websub_client_subscription.ex +++ b/lib/pleroma/web/websub/websub_client_subscription.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Websub.WebsubClientSubscription do diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex index c38a03808..27304d988 100644 --- a/lib/pleroma/web/websub/websub_controller.ex +++ b/lib/pleroma/web/websub/websub_controller.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Websub.WebsubController do diff --git a/lib/pleroma/web/websub/websub_server_subscription.ex b/lib/pleroma/web/websub/websub_server_subscription.ex index 81a2d7f07..d0ef548da 100644 --- a/lib/pleroma/web/websub/websub_server_subscription.ex +++ b/lib/pleroma/web/websub/websub_server_subscription.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Websub.WebsubServerSubscription do diff --git a/lib/pleroma/web/xml/xml.ex b/lib/pleroma/web/xml/xml.ex index fa6dcd424..df50aac9c 100644 --- a/lib/pleroma/web/xml/xml.ex +++ b/lib/pleroma/web/xml/xml.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.XML do -- cgit v1.2.3 From 1e6c102bfcfe0e4835a48f2483f2376f9bf86a20 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 31 Dec 2018 12:18:59 +0100 Subject: Web.AdminAPI.AdminAPIController: Remove a useless if in user_delete --- lib/pleroma/web/admin_api/admin_api_controller.ex | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 49d237661..2b66a1848 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -14,13 +14,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do action_fallback(:errors) def user_delete(conn, %{"nickname" => nickname}) do - user = User.get_by_nickname(nickname) - - if user.local == true do - User.delete(user) - else - User.delete(user) - end + User.get_by_nickname(nickname) + |> User.delete() conn |> json(nickname) -- cgit v1.2.3 From d4799e0dc23605563a29d14ad4657183174b55f9 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 1 Jan 2019 13:49:24 +0100 Subject: Remove default pool, it's used automatically anyway. --- lib/pleroma/http/connection.ex | 1 - lib/pleroma/http/http.ex | 1 - lib/pleroma/web/activity_pub/activity_pub.ex | 3 +-- 3 files changed, 1 insertion(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index 35c1490da..e2e92857f 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -8,7 +8,6 @@ defmodule Pleroma.HTTP.Connection do """ @hackney_options [ - pool: :default, timeout: 10000, recv_timeout: 20000, follow_redirect: true diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex index 32d9cf5aa..0a46c11b5 100644 --- a/lib/pleroma/http/http.ex +++ b/lib/pleroma/http/http.ex @@ -56,7 +56,6 @@ defmodule Pleroma.HTTP do def process_request_options(options) do config = Application.get_env(:pleroma, :http, []) proxy = Keyword.get(config, :proxy_url, nil) - options = options ++ [adapter: [pool: :default]] case proxy do nil -> options diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 167471b7b..c8c2905a7 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -741,8 +741,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {"Content-Type", "application/activity+json"}, {"signature", signature}, {"digest", digest} - ], - hackney: [pool: :default] + ] ) end -- cgit v1.2.3 From 400337b0a78150704de650d62a499464e895816c Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 1 Jan 2019 14:46:55 +0100 Subject: Make Federator options configurable. --- lib/pleroma/web/federator/federator.ex | 3 +-- lib/pleroma/web/federator/retry_queue.ex | 19 +++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index d25bfc0c1..f3a0e18b8 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -17,7 +17,6 @@ defmodule Pleroma.Web.Federator do @websub Application.get_env(:pleroma, :websub) @ostatus Application.get_env(:pleroma, :ostatus) - @max_jobs 20 def init(args) do {:ok, args} @@ -168,7 +167,7 @@ defmodule Pleroma.Web.Federator do end def maybe_start_job(running_jobs, queue) do - if :sets.size(running_jobs) < @max_jobs && queue != [] do + if :sets.size(running_jobs) < Pleroma.Config.get([__MODULE__, :max_jobs]) && queue != [] do {{type, payload}, queue} = queue_pop(queue) {:ok, pid} = Task.start(fn -> handle(type, payload) end) mref = Process.monitor(pid) diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex index c57bbb77c..230a2c939 100644 --- a/lib/pleroma/web/federator/retry_queue.ex +++ b/lib/pleroma/web/federator/retry_queue.ex @@ -7,12 +7,6 @@ defmodule Pleroma.Web.Federator.RetryQueue do require Logger - # seconds - @initial_timeout 30 - @max_retries 5 - - @max_jobs 20 - def init(args) do queue_table = :ets.new(:pleroma_retry_queue, [:bag, :protected]) @@ -21,7 +15,7 @@ defmodule Pleroma.Web.Federator.RetryQueue do def start_link() do enabled = - if Mix.env() == :test, do: true, else: Pleroma.Config.get([:retry_queue, :enabled], false) + if Mix.env() == :test, do: true, else: Pleroma.Config.get([__MODULE__, :enabled], false) if enabled do Logger.info("Starting retry queue") @@ -54,7 +48,7 @@ defmodule Pleroma.Web.Federator.RetryQueue do end def get_retry_params(retries) do - if retries > @max_retries do + if retries > Pleroma.Config.get([__MODULE__, :max_retries]) do {:drop, "Max retries reached"} else {:retry, growth_function(retries)} @@ -108,12 +102,12 @@ defmodule Pleroma.Web.Federator.RetryQueue do current_time = DateTime.to_unix(DateTime.utc_now()) n_running_jobs = :sets.size(running_jobs) - if n_running_jobs < @max_jobs do + if n_running_jobs < Pleroma.Config.get([__MODULE__, :max_jobs]) do n_ready_jobs = ets_count_expires(queue_table, current_time) if n_ready_jobs > 0 do # figure out how many we could start - available_job_slots = @max_jobs - n_running_jobs + available_job_slots = Pleroma.Config.get([__MODULE__, :max_jobs]) - n_running_jobs start_n_jobs(running_jobs, queue_table, current_time, available_job_slots) else running_jobs @@ -228,12 +222,13 @@ defmodule Pleroma.Web.Federator.RetryQueue do if Mix.env() == :test do defp growth_function(_retries) do - _shutit = @initial_timeout + _shutit = Pleroma.Config.get([__MODULE__, :initial_timeout]) DateTime.to_unix(DateTime.utc_now()) - 1 end else defp growth_function(retries) do - round(@initial_timeout * :math.pow(retries, 3)) + DateTime.to_unix(DateTime.utc_now()) + round(Pleroma.Config.get([__MODULE__, :initial_timeout]) * :math.pow(retries, 3)) + + DateTime.to_unix(DateTime.utc_now()) end end -- cgit v1.2.3 From 2aab4e03c3a2867abd4555dc776eebc8b0dba176 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Tue, 1 Jan 2019 23:26:40 +0300 Subject: Add OGP parser --- lib/pleroma/web/rich_media/data.ex | 3 +++ lib/pleroma/web/rich_media/parser.ex | 14 ++++++++++++++ lib/pleroma/web/rich_media/parsers/ogp.ex | 30 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 lib/pleroma/web/rich_media/data.ex create mode 100644 lib/pleroma/web/rich_media/parser.ex create mode 100644 lib/pleroma/web/rich_media/parsers/ogp.ex (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/data.ex b/lib/pleroma/web/rich_media/data.ex new file mode 100644 index 000000000..403d1d341 --- /dev/null +++ b/lib/pleroma/web/rich_media/data.ex @@ -0,0 +1,3 @@ +defmodule Pleroma.Web.RichMedia.Data do + defstruct [:title, :type, :image, :url, :description] +end diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex new file mode 100644 index 000000000..d9c1684d5 --- /dev/null +++ b/lib/pleroma/web/rich_media/parser.ex @@ -0,0 +1,14 @@ +defmodule Pleroma.Web.RichMedia.Parser do + @parsers [Pleroma.Web.RichMedia.Parsers.OGP] + + def parse(url) do + {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url) + + Enum.reduce_while(@parsers, %Pleroma.Web.RichMedia.Data{}, fn parser, acc -> + case parser.parse(html, acc) do + {:ok, data} -> {:halt, data} + {:error, _msg} -> {:cont, acc} + end + end) + end +end diff --git a/lib/pleroma/web/rich_media/parsers/ogp.ex b/lib/pleroma/web/rich_media/parsers/ogp.ex new file mode 100644 index 000000000..75084c7ee --- /dev/null +++ b/lib/pleroma/web/rich_media/parsers/ogp.ex @@ -0,0 +1,30 @@ +defmodule Pleroma.Web.RichMedia.Parsers.OGP do + def parse(html, data) do + with elements = [_ | _] <- get_elements(html), + ogp_data = + Enum.reduce(elements, data, fn el, acc -> + attributes = normalize_attributes(el) + + Map.merge(acc, attributes) + end) do + {:ok, ogp_data} + else + _e -> {:error, "No OGP metadata found"} + end + end + + defp get_elements(html) do + html |> Floki.find("meta[property^='og:']") + end + + defp normalize_attributes(tuple) do + {_tag, attributes, _children} = tuple + + data = + Enum.into(attributes, %{}, fn {name, value} -> + {name, String.trim_leading(value, "og:")} + end) + + %{String.to_atom(data["property"]) => data["content"]} + end +end -- cgit v1.2.3 From 917d48d09bad573260bc816310ee2c75d4db84a8 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Tue, 1 Jan 2019 23:29:47 +0300 Subject: Better variable name --- lib/pleroma/web/rich_media/parsers/ogp.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parsers/ogp.ex b/lib/pleroma/web/rich_media/parsers/ogp.ex index 75084c7ee..5773a5263 100644 --- a/lib/pleroma/web/rich_media/parsers/ogp.ex +++ b/lib/pleroma/web/rich_media/parsers/ogp.ex @@ -17,8 +17,8 @@ defmodule Pleroma.Web.RichMedia.Parsers.OGP do html |> Floki.find("meta[property^='og:']") end - defp normalize_attributes(tuple) do - {_tag, attributes, _children} = tuple + defp normalize_attributes(html_node) do + {_tag, attributes, _children} = html_node data = Enum.into(attributes, %{}, fn {name, value} -> -- cgit v1.2.3 From 551c3d9391c0eeb282d750979b8eef5025c41482 Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Tue, 1 Jan 2019 22:16:46 +0100 Subject: Split create activity specifics from update_outbox --- .../web/activity_pub/activity_pub_controller.ex | 42 ++++++++++++++-------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index fc7972eaf..d23c54933 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -165,9 +165,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do end end + def handle_user_activity(user, %{"type" => "Create"} = params) do + object = + params["object"] + |> Map.merge(Map.take(params, ["to", "cc"])) + |> Map.put("attributedTo", user.ap_id()) + |> Transmogrifier.fix_object() + + ActivityPub.create(%{ + to: params["to"], + actor: user, + context: object["context"], + object: object, + additional: Map.take(params, ["cc"]) + }) + end + + def handle_user_activity(_, _) do + {:error, "Unhandled activity type"} + end + def update_outbox( %{assigns: %{user: user}} = conn, - %{"nickname" => nickname, "type" => "Create"} = params + %{"nickname" => nickname} = params ) do if nickname == user.nickname do actor = user.ap_id() @@ -178,24 +198,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do |> Map.put("actor", actor) |> Transmogrifier.fix_addressing() - object = - params["object"] - |> Map.merge(Map.take(params, ["to", "cc"])) - |> Map.put("attributedTo", actor) - |> Transmogrifier.fix_object() - - with {:ok, %Activity{} = activity} <- - ActivityPub.create(%{ - to: params["to"], - actor: user, - context: object["context"], - object: object, - additional: Map.take(params, ["cc"]) - }) do + with {:ok, %Activity{} = activity} <- handle_user_activity(user, params) do conn |> put_status(:created) |> put_resp_header("location", activity.data["id"]) |> json(activity.data) + else + {:error, message} -> + conn + |> put_status(:bad_request) + |> json(message) end else conn -- cgit v1.2.3 From 4e1cc2bab6ec76af1b6de986561a82887d18f366 Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Tue, 1 Jan 2019 23:19:40 +0100 Subject: Implement delete activity --- lib/pleroma/web/activity_pub/activity_pub_controller.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index d23c54933..a3f736fee 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -181,6 +181,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do }) end + def handle_user_activity(user, %{"type" => "Delete"} = params) do + with %Object{} = object <- Object.normalize(params["object"]), + true <- user.info.is_moderator || user.ap_id == object.data["actor"], + {:ok, delete} <- ActivityPub.delete(object) do + {:ok, delete} + else + _ -> {:error, "Can't delete object"} + end + end + def handle_user_activity(_, _) do {:error, "Unhandled activity type"} end -- cgit v1.2.3 From 48e81d3d40d334bccb8438c61ab6b307ddb1392f Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Wed, 2 Jan 2019 17:02:50 +0300 Subject: Add RichMediaController and tests --- .../web/rich_media/controllers/rich_media_controller.ex | 17 +++++++++++++++++ lib/pleroma/web/rich_media/data.ex | 3 --- lib/pleroma/web/rich_media/parser.ex | 14 +++++++++++++- lib/pleroma/web/router.ex | 6 ++++++ 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 lib/pleroma/web/rich_media/controllers/rich_media_controller.ex delete mode 100644 lib/pleroma/web/rich_media/data.ex (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/controllers/rich_media_controller.ex b/lib/pleroma/web/rich_media/controllers/rich_media_controller.ex new file mode 100644 index 000000000..91019961d --- /dev/null +++ b/lib/pleroma/web/rich_media/controllers/rich_media_controller.ex @@ -0,0 +1,17 @@ +defmodule Pleroma.Web.RichMedia.RichMediaController do + use Pleroma.Web, :controller + + import Pleroma.Web.ControllerHelper, only: [json_response: 3] + + def parse(conn, %{"url" => url}) do + case Pleroma.Web.RichMedia.Parser.parse(url) do + {:ok, data} -> + conn + |> json_response(200, data) + + {:error, msg} -> + conn + |> json_response(404, msg) + end + end +end diff --git a/lib/pleroma/web/rich_media/data.ex b/lib/pleroma/web/rich_media/data.ex deleted file mode 100644 index 403d1d341..000000000 --- a/lib/pleroma/web/rich_media/data.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule Pleroma.Web.RichMedia.Data do - defstruct [:title, :type, :image, :url, :description] -end diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index d9c1684d5..477a38196 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -4,11 +4,23 @@ defmodule Pleroma.Web.RichMedia.Parser do def parse(url) do {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url) - Enum.reduce_while(@parsers, %Pleroma.Web.RichMedia.Data{}, fn parser, acc -> + html |> maybe_parse() |> get_parsed_data() + end + + defp maybe_parse(html) do + Enum.reduce_while(@parsers, %{}, fn parser, acc -> case parser.parse(html, acc) do {:ok, data} -> {:halt, data} {:error, _msg} -> {:cont, acc} end end) end + + defp get_parsed_data(data) when data == %{} do + {:error, "No metadata found"} + end + + defp get_parsed_data(data) do + {:ok, data} + end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 1f929ee21..8df45bf4d 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -232,6 +232,12 @@ defmodule Pleroma.Web.Router do put("/settings", MastodonAPIController, :put_settings) end + scope "/api", Pleroma.Web.RichMedia do + pipe_through(:authenticated_api) + + get("/rich_media/parse", RichMediaController, :parse) + end + scope "/api/v1", Pleroma.Web.MastodonAPI do pipe_through(:api) get("/instance", MastodonAPIController, :masto_instance) -- cgit v1.2.3 From 943211b035ccedb4889c5d0a55f68acf8117c163 Mon Sep 17 00:00:00 2001 From: Michael Loftis Date: Tue, 1 Jan 2019 15:40:57 +0000 Subject: rewrites List.foldl to Enum.each --- lib/pleroma/web/federator/retry_queue.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/federator/retry_queue.ex b/lib/pleroma/web/federator/retry_queue.ex index 230a2c939..e0ce251d2 100644 --- a/lib/pleroma/web/federator/retry_queue.ex +++ b/lib/pleroma/web/federator/retry_queue.ex @@ -87,9 +87,8 @@ defmodule Pleroma.Web.Federator.RetryQueue do ) popped - |> List.foldl(true, fn e, acc -> + |> Enum.each(fn e -> :ets.delete_object(table, e) - acc end) popped -- cgit v1.2.3 From eb1a18d22f0284cfee571e6a83d4ddf69042dba0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 2 Jan 2019 22:47:12 +0000 Subject: user: check that the follow request actually has an active account associated with it because of user refetch, accounts can stop existing (get_from_ap_id() can fail), accordingly filter the follow requests for these failures. --- lib/pleroma/user.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 892f4e483..1edded415 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -495,6 +495,7 @@ defmodule Pleroma.User do Enum.map(reqs, fn req -> req.actor end) |> Enum.uniq() |> Enum.map(fn ap_id -> get_by_ap_id(ap_id) end) + |> Enum.filter(fn u -> !is_nil(u) end) |> Enum.filter(fn u -> !following?(u, user) end) {:ok, users} -- cgit v1.2.3 From 5b23dfa1c5e6a3ec30fc6dc32761f27968eabf2f Mon Sep 17 00:00:00 2001 From: cascode Date: Fri, 4 Jan 2019 01:35:26 -0800 Subject: handle null --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1edded415..0e5e2d943 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -610,7 +610,7 @@ defmodule Pleroma.User do select_merge: %{ search_distance: fragment( - "? <-> (? || ?)", + "? <-> (? || coalesce(?, ''))", ^query, u.nickname, u.name -- cgit v1.2.3 From fe2dceb66d056809d9a145773a8053ac9fb02658 Mon Sep 17 00:00:00 2001 From: Wim Vanderbauwhede Date: Fri, 4 Jan 2019 15:22:02 +0000 Subject: Patch to support image descriptions in Pleroma FE --- lib/pleroma/web/common_api/utils.ex | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 3ff9f9452..51e74ac8f 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -1,8 +1,9 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2018 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPI.Utils do + require Logger alias Calendar.Strftime alias Comeonin.Pbkdf2 alias Pleroma.{Activity, Formatter, Object, Repo} @@ -32,9 +33,11 @@ defmodule Pleroma.Web.CommonAPI.Utils do def get_replied_to_activity(_), do: nil - def attachments_from_ids(ids) do - Enum.map(ids || [], fn media_id -> + def attachments_from_ids(ids, descs) do + Enum.map(ids || [], fn media_id -> do + Logger.warn(descs[media_id]) Repo.get(Object, media_id).data + end end) end -- cgit v1.2.3 From 4c95545d194e8a807e9e3514ed75347d78ec0856 Mon Sep 17 00:00:00 2001 From: Wim Vanderbauwhede Date: Fri, 4 Jan 2019 15:35:41 +0000 Subject: Patch to support image descriptions in Pleroma FE --- lib/pleroma/web/common_api/common_api.ex | 2 +- lib/pleroma/web/common_api/utils.ex | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index e474653ff..50074b8b0 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -90,7 +90,7 @@ defmodule Pleroma.Web.CommonAPI do limit = Pleroma.Config.get([:instance, :limit]) with status <- String.trim(status), - attachments <- attachments_from_ids(data["media_ids"]), + attachments <- attachments_from_ids(data["media_ids"], data["descriptions"]), mentions <- Formatter.parse_mentions(status), inReplyTo <- get_replied_to_activity(data["in_reply_to_status_id"]), {to, cc} <- to_for_user_and_mentions(user, mentions, inReplyTo, visibility), diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 51e74ac8f..5fe21fb99 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -1,9 +1,8 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPI.Utils do - require Logger alias Calendar.Strftime alias Comeonin.Pbkdf2 alias Pleroma.{Activity, Formatter, Object, Repo} @@ -33,11 +32,11 @@ defmodule Pleroma.Web.CommonAPI.Utils do def get_replied_to_activity(_), do: nil - def attachments_from_ids(ids, descs) do - Enum.map(ids || [], fn media_id -> do - Logger.warn(descs[media_id]) - Repo.get(Object, media_id).data - end + def attachments_from_ids(ids, descs_str) do + {_, descs} = Jason.decode(descs_str) + + Enum.map(ids || [], fn media_id -> + Map.put(Repo.get(Object, media_id).data, "name", descs[media_id]) end) end -- cgit v1.2.3 From ba93396649f65a1f32eeedfd9ccd32cf308e7210 Mon Sep 17 00:00:00 2001 From: Wim Vanderbauwhede Date: Fri, 4 Jan 2019 16:27:46 +0000 Subject: Patch to support image descriptions in Pleroma FE --- lib/pleroma/web/common_api/common_api.ex | 2 +- lib/pleroma/web/common_api/utils.ex | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 50074b8b0..ef79b9c5d 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -90,7 +90,7 @@ defmodule Pleroma.Web.CommonAPI do limit = Pleroma.Config.get([:instance, :limit]) with status <- String.trim(status), - attachments <- attachments_from_ids(data["media_ids"], data["descriptions"]), + attachments <- attachments_from_ids(data), mentions <- Formatter.parse_mentions(status), inReplyTo <- get_replied_to_activity(data["in_reply_to_status_id"]), {to, cc} <- to_for_user_and_mentions(user, mentions, inReplyTo, visibility), diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 5fe21fb99..59df48ed6 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -32,7 +32,21 @@ defmodule Pleroma.Web.CommonAPI.Utils do def get_replied_to_activity(_), do: nil - def attachments_from_ids(ids, descs_str) do + def attachments_from_ids(data) do + if Map.has_key?(data, "descriptions") do + attachments_from_ids_descs(data["media_ids"], data["descriptions"]) + else + attachments_from_ids_no_descs(data["media_ids"]) + end + end + + def attachments_from_ids_no_descs(ids) do + Enum.map(ids || [], fn media_id -> + Repo.get(Object, media_id).data + end) + end + + def attachments_from_ids_descs(ids, descs_str) do {_, descs} = Jason.decode(descs_str) Enum.map(ids || [], fn media_id -> -- cgit v1.2.3 From 4aa977d3b3ad731465f83f2d382fe9d856995e90 Mon Sep 17 00:00:00 2001 From: spctrl Date: Fri, 4 Jan 2019 22:11:46 +0100 Subject: fix 486: Add option --assume-yes to allow it to work non-interactive --- lib/mix/tasks/pleroma/user.ex | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 217a52fdd..c311d48e0 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -22,6 +22,7 @@ defmodule Mix.Tasks.Pleroma.User do - `--password PASSWORD` - the user's password - `--moderator`/`--no-moderator` - whether the user is a moderator - `--admin`/`--no-admin` - whether the user is an admin + - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions ## Generate an invite link. @@ -61,7 +62,11 @@ defmodule Mix.Tasks.Pleroma.User do bio: :string, password: :string, moderator: :boolean, - admin: :boolean + admin: :boolean, + assume_yes: :boolean + ], + aliases: [ + y: :assume_yes ] ) @@ -79,6 +84,7 @@ defmodule Mix.Tasks.Pleroma.User do moderator? = Keyword.get(options, :moderator, false) admin? = Keyword.get(options, :admin, false) + assume_yes? = Keyword.get(options, :assume_yes, false) Mix.shell().info(""" A user will be created with the following information: @@ -93,7 +99,7 @@ defmodule Mix.Tasks.Pleroma.User do - admin: #{if(admin?, do: "true", else: "false")} """) - proceed? = Mix.shell().yes?("Continue?") + proceed? = assume_yes? or Mix.shell().yes?("Continue?") unless not proceed? do Common.start_pleroma() -- cgit v1.2.3 From 846082e54fcb9dceda476282c54d8cd36986203c Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sat, 5 Jan 2019 00:19:46 +0100 Subject: Different caches based on the module. Remove scrubber version since it is not relevant anymore --- lib/pleroma/html.ex | 30 ++++------------------ lib/pleroma/web/mastodon_api/views/status_view.ex | 6 ++++- lib/pleroma/web/twitter_api/views/activity_view.ex | 8 ++++-- 3 files changed, 16 insertions(+), 28 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 71db516e6..41d41e535 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -28,13 +28,13 @@ defmodule Pleroma.HTML do def filter_tags(html), do: filter_tags(html, nil) def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags) - def get_cached_scrubbed_html_for_object(content, scrubbers, object) do - key = "#{generate_scrubber_signature(scrubbers)}|#{object.id}" + def get_cached_scrubbed_html_for_object(content, scrubbers, object, module) do + key = "#{module}#{generate_scrubber_signature(scrubbers)}|#{object.id}" Cachex.fetch!(:scrubber_cache, key, fn _key -> ensure_scrubbed_html(content, scrubbers) end) end - def get_cached_stripped_html_for_object(content, object) do - get_cached_scrubbed_html_for_object(content, HtmlSanitizeEx.Scrubber.StripTags, object) + def get_cached_stripped_html_for_object(content, object, module) do + get_cached_scrubbed_html_for_object(content, HtmlSanitizeEx.Scrubber.StripTags, object, module) end def ensure_scrubbed_html( @@ -50,15 +50,7 @@ defmodule Pleroma.HTML do defp generate_scrubber_signature(scrubbers) do Enum.reduce(scrubbers, "", fn scrubber, signature -> - # If a scrubber does not have a version(e.g HtmlSanitizeEx.Scrubber.StripTags) it is assumed it is always 0) - version = - if Kernel.function_exported?(scrubber, :version, 0) do - scrubber.version - else - 0 - end - - "#{signature}#{to_string(scrubber)}#{version}" + "#{signature}#{to_string(scrubber)}" end) end end @@ -76,10 +68,6 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do require HtmlSanitizeEx.Scrubber.Meta alias HtmlSanitizeEx.Scrubber.Meta - def version do - 0 - end - Meta.remove_cdata_sections_before_scrub() Meta.strip_comments() @@ -118,10 +106,6 @@ defmodule Pleroma.HTML.Scrubber.Default do require HtmlSanitizeEx.Scrubber.Meta alias HtmlSanitizeEx.Scrubber.Meta - def version do - 0 - end - @markup Application.get_env(:pleroma, :markup) @uri_schemes Application.get_env(:pleroma, :uri_schemes, []) @valid_schemes Keyword.get(@uri_schemes, :valid_schemes, []) @@ -199,10 +183,6 @@ defmodule Pleroma.HTML.Transform.MediaProxy do alias Pleroma.Web.MediaProxy - def version do - 0 - end - def before_scrub(html), do: html def scrub_attribute("img", {"src", "http" <> target}) do diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 477ab3b5f..8e8fa8121 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -120,7 +120,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do content = object |> render_content() - |> HTML.get_cached_scrubbed_html_for_object(User.html_filter_policy(opts[:for]), activity) + |> HTML.get_cached_scrubbed_html_for_object( + User.html_filter_policy(opts[:for]), + activity, + __MODULE__ + ) %{ id: to_string(activity.id), diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 84f35ebf9..a0be5cfc5 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -245,14 +245,18 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do html = content - |> HTML.get_cached_scrubbed_html_for_object(User.html_filter_policy(opts[:for]), activity) + |> HTML.get_cached_scrubbed_html_for_object( + User.html_filter_policy(opts[:for]), + activity, + __MODULE__ + ) |> Formatter.emojify(object["emoji"]) text = if content do content |> String.replace(~r//, "\n") - |> HTML.get_cached_stripped_html_for_object(activity) + |> HTML.get_cached_stripped_html_for_object(activity, __MODULE__) end reply_parent = Activity.get_in_reply_to_activity(activity) -- cgit v1.2.3 From 1e2d58982ee6a74a249fc92fa2711f678a9f7464 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Sat, 5 Jan 2019 00:25:31 +0100 Subject: oopsies --- lib/pleroma/html.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 41d41e535..0c5b0f03f 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -34,7 +34,12 @@ defmodule Pleroma.HTML do end def get_cached_stripped_html_for_object(content, object, module) do - get_cached_scrubbed_html_for_object(content, HtmlSanitizeEx.Scrubber.StripTags, object, module) + get_cached_scrubbed_html_for_object( + content, + HtmlSanitizeEx.Scrubber.StripTags, + object, + module + ) end def ensure_scrubbed_html( -- cgit v1.2.3 From 0964c207eb184696355a2d8efd9d671dcc23ce66 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 4 Jan 2019 23:23:47 +0000 Subject: rich media: use cachex to avoid flooding remote servers --- lib/pleroma/application.ex | 11 +++++++++++ lib/pleroma/web/rich_media/parser.ex | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index cb3e6b69b..ad2797209 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -63,6 +63,17 @@ defmodule Pleroma.Application do ], id: :cachex_object ), + worker( + Cachex, + [ + :rich_media_cache, + [ + default_ttl: :timer.minutes(120), + limit: 5000 + ] + ], + id: :cachex_rich_media + ), worker( Cachex, [ diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 477a38196..b88ed5371 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -2,9 +2,13 @@ defmodule Pleroma.Web.RichMedia.Parser do @parsers [Pleroma.Web.RichMedia.Parsers.OGP] def parse(url) do - {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url) + Cachex.fetch!(:rich_media_cache, url, fn _ -> + {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url) - html |> maybe_parse() |> get_parsed_data() + result = html |> maybe_parse() |> get_parsed_data() + + {:commit, result} + end) end defp maybe_parse(html) do -- cgit v1.2.3 From 487c00d36dee1b975ffc8fca8f0a5bb5510f71a3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 4 Jan 2019 23:50:54 +0000 Subject: rich media: disable cachex in test mode --- lib/pleroma/web/rich_media/parser.ex | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index b88ed5371..3746feaf6 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -1,14 +1,17 @@ defmodule Pleroma.Web.RichMedia.Parser do @parsers [Pleroma.Web.RichMedia.Parsers.OGP] - def parse(url) do - Cachex.fetch!(:rich_media_cache, url, fn _ -> - {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url) + if Mix.env() == :test do + def parse(url), do: parse_url(url) + else + def parse(url), + do: {:commit, Cachex.fetch!(:rich_media_cache, url, fn _ -> parse_url(url) end)} + end - result = html |> maybe_parse() |> get_parsed_data() + defp parse_url(url) do + {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url) - {:commit, result} - end) + html |> maybe_parse() |> get_parsed_data() end defp maybe_parse(html) do -- cgit v1.2.3 From 2d7da5f4375164aa78e221ab054529a04d09e819 Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Sat, 5 Jan 2019 10:38:38 +0100 Subject: Don't crash on AP request for tombstone Because tombstone objects has no addressing the is_public?-predicate would cause an error that propagated as a 500 error in the api --- lib/pleroma/web/activity_pub/activity_pub.ex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 4d754de13..4685f6d95 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -801,6 +801,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end + def is_public?(%Object{data: %{"type" => "Tombstone"}}) do + false + end + def is_public?(activity) do "https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++ (activity.data["cc"] || [])) -- cgit v1.2.3 From 0787f0dfbe8daad53617217617fbc8784e45898f Mon Sep 17 00:00:00 2001 From: scarlett Date: Sat, 5 Jan 2019 17:28:47 +0000 Subject: Strip HTML in and allow emoji in summaries. --- lib/pleroma/web/common_api/common_api.ex | 2 +- lib/pleroma/web/twitter_api/views/activity_view.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index e474653ff..a20b854df 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -124,7 +124,7 @@ defmodule Pleroma.Web.CommonAPI do Map.put( object, "emoji", - Formatter.get_emoji(status) + Formatter.get_emoji(status) ++ Formatter.get_emoji(data["spoiler_text"]) |> Enum.reduce(%{}, fn {name, file}, acc -> Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}") end) diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 84f35ebf9..9ba347d12 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -285,7 +285,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do "activity_type" => "post", "possibly_sensitive" => possibly_sensitive, "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), - "summary" => summary + "summary" => HTML.strip_tags(summary) |> Formatter.emojify(object["emoji"]) } end -- cgit v1.2.3 From 3c86d907d4d298b8a54d5292ff85107a1ada3bd5 Mon Sep 17 00:00:00 2001 From: scarlett Date: Sat, 5 Jan 2019 17:35:39 +0000 Subject: add some brakets to the emoji list. --- lib/pleroma/web/common_api/common_api.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index a20b854df..bb3c38f00 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -124,7 +124,7 @@ defmodule Pleroma.Web.CommonAPI do Map.put( object, "emoji", - Formatter.get_emoji(status) ++ Formatter.get_emoji(data["spoiler_text"]) + (Formatter.get_emoji(status) ++ Formatter.get_emoji(data["spoiler_text"])) |> Enum.reduce(%{}, fn {name, file}, acc -> Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}") end) -- cgit v1.2.3 From 6556be344de981272b9c14faf5fb9837c1ea0da6 Mon Sep 17 00:00:00 2001 From: scarlett Date: Sat, 5 Jan 2019 18:20:42 +0000 Subject: Resolve some test failures. --- lib/pleroma/web/twitter_api/representers/activity_representer.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 2a221cc66..245cd52fd 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -207,7 +207,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do "activity_type" => "post", "possibly_sensitive" => possibly_sensitive, "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), - "summary" => object["summary"] + "summary" => HTML.strip_tags(object["summary"]) |> Formatter.emojify(object["emoji"]) } end -- cgit v1.2.3 From 042852ecf344b4ede15a22ea0279fff8a67b75f0 Mon Sep 17 00:00:00 2001 From: Sadposter Date: Sat, 5 Jan 2019 22:54:25 +0000 Subject: Add check to prevent multiple follow notifications from the same user --- lib/pleroma/notification.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 51d59870c..c7d01f63b 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -109,7 +109,12 @@ defmodule Pleroma.Notification do # TODO move to sql, too. def create_notification(%Activity{} = activity, %User{} = user) do unless User.blocks?(user, %{ap_id: activity.data["actor"]}) or - user.ap_id == activity.data["actor"] do + user.ap_id == activity.data["actor"] or + (activity.data["type"] == "Follow" and + Enum.any?(Notification.for_user(user), fn notif -> + notif.activity.data["type"] == "Follow" and + notif.activity.data["actor"] == activity.data["actor"] + end)) do notification = %Notification{user_id: user.id, activity: activity} {:ok, notification} = Repo.insert(notification) Pleroma.Web.Streamer.stream("user", notification) -- cgit v1.2.3 From 52493467ac314ec58ed6123d3581428a82ec170c Mon Sep 17 00:00:00 2001 From: scarlett Date: Sun, 6 Jan 2019 10:16:40 +0000 Subject: Twitter API: Add a summary_html field. The intention here is to allow proper subject copying when it contains emoji, obviously this will require minor frontend changes, though. --- lib/pleroma/web/twitter_api/representers/activity_representer.ex | 5 ++++- lib/pleroma/web/twitter_api/views/activity_view.ex | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 245cd52fd..47154829d 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -181,6 +181,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor) + summary = HTML.strip_tags(object["summary"]) + %{ "id" => activity.id, "uri" => activity.data["object"]["id"], @@ -207,7 +209,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do "activity_type" => "post", "possibly_sensitive" => possibly_sensitive, "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), - "summary" => HTML.strip_tags(object["summary"]) |> Formatter.emojify(object["emoji"]) + "summary" => summary, + "summary_html" => summary |> Formatter.emojify(object["emoji"]) } end diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index ad0cc76ed..61c617e87 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -263,6 +263,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor) + summary = HTML.strip_tags(summary) + %{ "id" => activity.id, "uri" => activity.data["object"]["id"], @@ -289,7 +291,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do "activity_type" => "post", "possibly_sensitive" => possibly_sensitive, "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), - "summary" => HTML.strip_tags(summary) |> Formatter.emojify(object["emoji"]) + "summary" => summary, + "summary_html" => summary |> Formatter.emojify(object["emoji"]) } end -- cgit v1.2.3 From 36fa5e8802b45bdaee048dd63065d8e73142e52b Mon Sep 17 00:00:00 2001 From: scarlett Date: Mon, 7 Jan 2019 10:30:30 +0000 Subject: Check visible_for_user when performing a search using a direct link. --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 95d0f849c..f739e8f7d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -725,11 +725,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json(conn, %{}) end - def status_search(query) do + def status_search(user, query) do fetched = if Regex.match?(~r/https?:/, query) do - with {:ok, object} <- ActivityPub.fetch_object_from_id(query) do - [Activity.get_create_activity_by_object_ap_id(object.data["id"])] + with {:ok, object} <- ActivityPub.fetch_object_from_id(query), + %Activity{} = activity <- + Activity.get_create_activity_by_object_ap_id(object.data["id"]), + true <- ActivityPub.visible_for_user?(activity, user) do + [activity] else _e -> [] end @@ -756,7 +759,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def search2(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do accounts = User.search(query, params["resolve"] == "true") - statuses = status_search(query) + statuses = status_search(user, query) tags_path = Web.base_url() <> "/tag/" @@ -780,7 +783,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do accounts = User.search(query, params["resolve"] == "true") - statuses = status_search(query) + statuses = status_search(user, query) tags = String.split(query) -- cgit v1.2.3 From 7382adf407301945e30ee38aa4efe28a819fcf44 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 7 Jan 2019 12:41:31 +0100 Subject: Make TwAPI UserView more resilient to issues. Will work for missing users and badly migrated users. --- lib/pleroma/user.ex | 9 +++++++++ lib/pleroma/web/twitter_api/views/activity_view.ex | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 0e5e2d943..85d0f9fce 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -367,6 +367,15 @@ defmodule Pleroma.User do Repo.get_by(User, ap_id: ap_id) end + # This is mostly an SPC migration fix. This guesses the user nickname (by taking the last part of the ap_id and the domain) and tries to get that user + def get_by_guessed_nickname(ap_id) do + domain = URI.parse(ap_id).host + name = List.last(String.split(ap_id, "/")) + nickname = "#{name}@#{domain}" + + get_by_nickname(nickname) + end + def update_and_set_cache(changeset) do with {:ok, user} <- Repo.update(changeset) do Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user) diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index ad0cc76ed..0bae3d06f 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -94,11 +94,25 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do ap_id == "https://www.w3.org/ns/activitystreams#Public" -> nil + user = User.get_cached_by_ap_id(ap_id) -> + user + + user = User.get_by_guessed_nickname(ap_id) -> + user + true -> - User.get_cached_by_ap_id(ap_id) + error_user() end end + defp error_user do + %User{ + info: %User.Info{}, + nickname: "erroruser@example.com", + inserted_at: NaiveDateTime.utc_now() + } + end + def render("index.json", opts) do context_ids = collect_context_ids(opts.activities) users = collect_users(opts.activities) -- cgit v1.2.3 From 380e9fba21123467b41629828f97d5f2c257a128 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Mon, 7 Jan 2019 20:45:33 +0700 Subject: add pinned posts --- lib/pleroma/user/info.ex | 23 +++++++++++++++ lib/pleroma/web/activity_pub/activity_pub.ex | 8 +++++ lib/pleroma/web/common_api/common_api.ex | 34 ++++++++++++++++++++++ .../web/mastodon_api/mastodon_api_controller.ex | 29 +++++++++++++----- lib/pleroma/web/router.ex | 2 ++ 5 files changed, 89 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 2f419a5a2..ffb800177 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -31,6 +31,7 @@ defmodule Pleroma.User.Info do field(:hub, :string, default: nil) field(:salmon, :string, default: nil) field(:hide_network, :boolean, default: false) + field(:pinned_activities, {:array, :integer}, default: []) # Found in the wild # ap_id -> Where is this used? @@ -198,4 +199,26 @@ defmodule Pleroma.User.Info do :is_admin ]) end + + def add_pinnned_activity(info, %Pleroma.Activity{id: id}) do + if id not in info.pinned_activities do + max_pinned_posts = Pleroma.Config.get([:instance, :max_pinned_posts], 0) + params = %{pinned_activities: info.pinned_activities ++ [id]} + + info + |> cast(params, [:pinned_activities]) + |> validate_length(:pinned_activities, + max: max_pinned_posts, + message: "You have already pinned the maximum number of toots" + ) + else + change(info) + end + end + + def remove_pinnned_activity(info, %Pleroma.Activity{id: id}) do + params = %{pinned_activities: List.delete(info.pinned_activities, id)} + + cast(info, params, [:pinned_activities]) + end end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 4685f6d95..c5f62c4f8 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -394,6 +394,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do |> Map.put("type", ["Create", "Announce"]) |> Map.put("actor_id", user.ap_id) |> Map.put("whole_db", true) + |> Map.put("pinned_activity_ids", user.info.pinned_activities) recipients = if reading_user do @@ -552,6 +553,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do ) end + defp restrict_pinned(query, %{"pinned" => "true", "pinned_activity_ids" => ids}) do + from(activity in query, where: activity.id in ^ids) + end + + defp restrict_pinned(query, _), do: query + def fetch_activities_query(recipients, opts \\ %{}) do base_query = from( @@ -576,6 +583,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do |> restrict_visibility(opts) |> restrict_replies(opts) |> restrict_reblogs(opts) + |> restrict_pinned(opts) end def fetch_activities(recipients, opts \\ %{}) do diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index bb3c38f00..6d22813b2 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -164,4 +164,38 @@ defmodule Pleroma.Web.CommonAPI do object: Pleroma.Web.ActivityPub.UserView.render("user.json", %{user: user}) }) end + + def pin(id_or_ap_id, user) do + with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id), + %{valid?: true} = info_changeset <- + Pleroma.User.Info.add_pinnned_activity(user.info, activity), + changeset <- + Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_changeset), + {:ok, _user} <- User.update_and_set_cache(changeset) do + {:ok, activity} + else + %{errors: [pinned_activities: {err, _}]} -> + {:error, err} + + _ -> + {:error, "Could not pin"} + end + end + + def unpin(id_or_ap_id, user) do + with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id), + %{valid?: true} = info_changeset <- + Pleroma.User.Info.remove_pinnned_activity(user.info, activity), + changeset <- + Ecto.Changeset.change(user) |> Ecto.Changeset.put_embed(:info, info_changeset), + {:ok, _user} <- User.update_and_set_cache(changeset) do + {:ok, activity} + else + %{errors: [pinned_activities: {err, _}]} -> + {:error, err} + + _ -> + {:error, "Could not unpin"} + end + end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 95d0f849c..2fb2943f1 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -256,13 +256,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do with %User{} = user <- Repo.get(User, params["id"]) do - # Since Pleroma has no "pinned" posts feature, we'll just set an empty list here - activities = - if params["pinned"] == "true" do - [] - else - ActivityPub.fetch_user_activities(user, reading_user, params) - end + activities = ActivityPub.fetch_user_activities(user, reading_user, params) conn |> add_link_headers(:user_statuses, activities, params["id"]) @@ -409,6 +403,27 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end + def pin_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do + with {:ok, activity} <- CommonAPI.pin(ap_id_or_id, user) do + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) + else + {:error, reason} -> + conn + |> put_resp_content_type("application/json") + |> send_resp(:bad_request, Jason.encode!(%{"error" => reason})) + end + end + + def unpin_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do + with {:ok, activity} <- CommonAPI.unpin(ap_id_or_id, user) do + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) + end + end + def notifications(%{assigns: %{user: user}} = conn, params) do notifications = Notification.for_user(user, params) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 8df45bf4d..ad73d8867 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -188,6 +188,8 @@ defmodule Pleroma.Web.Router do post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status) post("/statuses/:id/favourite", MastodonAPIController, :fav_status) post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status) + post("/statuses/:id/pin", MastodonAPIController, :pin_status) + post("/statuses/:id/unpin", MastodonAPIController, :unpin_status) post("/notifications/clear", MastodonAPIController, :clear_notifications) post("/notifications/dismiss", MastodonAPIController, :dismiss_notification) -- cgit v1.2.3 From a16b17cc61a57d1adbc6f10f16fc36e8238c6c2a Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 7 Jan 2019 20:59:30 +0100 Subject: Actually put some onformation in the error user, make it actually properly parse in conversations. --- lib/pleroma/web/twitter_api/views/activity_view.ex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 0bae3d06f..25e1486c1 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -101,12 +101,14 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do user true -> - error_user() + error_user(ap_id) end end - defp error_user do + defp error_user(ap_id) do %User{ + name: ap_id, + ap_id: ap_id, info: %User.Info{}, nickname: "erroruser@example.com", inserted_at: NaiveDateTime.utc_now() -- cgit v1.2.3 From 63dbd875684b192e57d356a194c5d07ad98bd810 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 8 Jan 2019 15:25:50 +0700 Subject: rename `post` to `status` --- lib/pleroma/user/info.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index ffb800177..8ac50540d 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -202,14 +202,14 @@ defmodule Pleroma.User.Info do def add_pinnned_activity(info, %Pleroma.Activity{id: id}) do if id not in info.pinned_activities do - max_pinned_posts = Pleroma.Config.get([:instance, :max_pinned_posts], 0) + max_pinned_statuses = Pleroma.Config.get([:instance, :max_pinned_statuses], 0) params = %{pinned_activities: info.pinned_activities ++ [id]} info |> cast(params, [:pinned_activities]) |> validate_length(:pinned_activities, - max: max_pinned_posts, - message: "You have already pinned the maximum number of toots" + max: max_pinned_statuses, + message: "You have already pinned the maximum number of statuses" ) else change(info) -- cgit v1.2.3 From e679da4c34194b366624e31356d534ab73b11d2d Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 8 Jan 2019 15:27:02 +0700 Subject: add `pinned` property to `StatusView` --- lib/pleroma/web/mastodon_api/views/status_view.ex | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 8e8fa8121..db543ffe5 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -76,6 +76,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do reblogged: false, favourited: false, muted: false, + pinned: pinned?(activity, user), sensitive: false, spoiler_text: "", visibility: "public", @@ -142,6 +143,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do reblogged: present?(repeated), favourited: present?(favorited), muted: false, + pinned: pinned?(activity, user), sensitive: sensitive, spoiler_text: object["summary"] || "", visibility: get_visibility(object), @@ -295,4 +297,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do defp present?(nil), do: false defp present?(false), do: false defp present?(_), do: true + + defp pinned?(%Activity{id: id}, %User{info: %{pinned_activities: pinned_activities}}), + do: id in pinned_activities end -- cgit v1.2.3 From 0fae04c4e3961baf1f31ae664e5a7fa5de19158e Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 8 Jan 2019 09:55:33 +0100 Subject: Add a setting for users to autofollow on sign up. --- lib/pleroma/user.ex | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 85d0f9fce..8edf1c730 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -229,10 +229,27 @@ defmodule Pleroma.User do end end + defp autofollow_users(user) do + candidates = Pleroma.Config.get([:instance, :autofollowed_nicknames]) + + autofollowed_users = + from(u in User, + where: u.local == true, + where: u.nickname in ^candidates + ) + |> Repo.all() + + autofollowed_users + |> Enum.reduce({:ok, user}, fn other_user, {:ok, user} -> + follow(user, other_user) + end) + end + @doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)" def register(%Ecto.Changeset{} = changeset) do with {:ok, user} <- Repo.insert(changeset), - {:ok, _} = try_send_confirmation_email(user) do + {:ok, _} <- try_send_confirmation_email(user), + {:ok, user} <- autofollow_users(user) do {:ok, user} end end -- cgit v1.2.3 From 6428ef77adef6aa3fca1fbcdcfffc5db5fc953d5 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 8 Jan 2019 16:11:03 +0700 Subject: add default configuration for the pinned statuses and some doc --- lib/mix/tasks/pleroma/sample_config.eex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/sample_config.eex b/lib/mix/tasks/pleroma/sample_config.eex index 740b9f8d1..59c2c4fba 100644 --- a/lib/mix/tasks/pleroma/sample_config.eex +++ b/lib/mix/tasks/pleroma/sample_config.eex @@ -14,7 +14,8 @@ config :pleroma, :instance, email: "<%= email %>", limit: 5000, registrations_open: true, - dedupe_media: false + dedupe_media: false, + max_pinned_statuses: 1 config :pleroma, :media_proxy, enabled: false, -- cgit v1.2.3 From 595a970493a9bae0dcc4b84de338766c2cc61a75 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 9 Jan 2019 04:46:03 +0000 Subject: user: use pattern matching to determine if user is local or remote instead of the previous hairy logic --- lib/pleroma/user.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 85d0f9fce..ce909601d 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -49,7 +49,8 @@ defmodule Pleroma.User do !Pleroma.Config.get([:instance, :account_activation_required]) end - def remote_or_auth_active?(%User{} = user), do: !user.local || auth_active?(user) + def remote_or_auth_active?(%User{local: false}), do: true + def remote_or_auth_active?(%User{local: true} = user), do: auth_active?(user) def visible_for?(%User{} = user, for_user \\ nil) do User.remote_or_auth_active?(user) || (for_user && for_user.id == user.id) || -- cgit v1.2.3 From 2af67353c5014edcc24bf2ec27b2bc871bd80eb7 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 9 Jan 2019 06:21:21 +0000 Subject: user: harden auth_active?/1, superuser?/1, visible_for?/1 --- lib/pleroma/user.ex | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index ce909601d..5491e8b9a 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -44,21 +44,28 @@ defmodule Pleroma.User do timestamps() end - def auth_active?(%User{} = user) do - (user.info && !user.info.confirmation_pending) || - !Pleroma.Config.get([:instance, :account_activation_required]) - end + def auth_active?(%User{info: %User.Info{confirmation_pending: false}}), do: true + + def auth_active?(%User{info: %User.Info{confirmation_pending: true}}), + do: !Pleroma.Config.get([:instance, :account_activation_required]) + + def auth_active?(_), do: false def remote_or_auth_active?(%User{local: false}), do: true def remote_or_auth_active?(%User{local: true} = user), do: auth_active?(user) - def visible_for?(%User{} = user, for_user \\ nil) do - User.remote_or_auth_active?(user) || (for_user && for_user.id == user.id) || - User.superuser?(for_user) + def visible_for?(user, for_user \\ nil) + + def visible_for?(%User{id: user_id}, %User{id: for_id}) when user_id == for_id, do: true + + def visible_for?(%User{} = user, for_user) do + remote_or_auth_active?(user) || superuser?(for_user) end - def superuser?(nil), do: false - def superuser?(%User{} = user), do: user.info && User.Info.superuser?(user.info) + def visible_for?(_, _), do: false + + def superuser?(%User{info: %User.Info{} = info}), do: User.Info.superuser?(info) + def superuser?(_), do: false def avatar_url(user) do case user.avatar do -- cgit v1.2.3 From 74f48beec3bf78cd94cb6db5cbdb937505891eab Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 9 Jan 2019 06:36:50 +0000 Subject: user: remove entirely redundant remote_or_auth_active?/1. auth_active?/1 can check remote users and return true directly. --- lib/pleroma/user.ex | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 5491e8b9a..636c56312 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -44,6 +44,8 @@ defmodule Pleroma.User do timestamps() end + def auth_active?(%User{local: false}), do: false + def auth_active?(%User{info: %User.Info{confirmation_pending: false}}), do: true def auth_active?(%User{info: %User.Info{confirmation_pending: true}}), @@ -51,15 +53,12 @@ defmodule Pleroma.User do def auth_active?(_), do: false - def remote_or_auth_active?(%User{local: false}), do: true - def remote_or_auth_active?(%User{local: true} = user), do: auth_active?(user) - def visible_for?(user, for_user \\ nil) def visible_for?(%User{id: user_id}, %User{id: for_id}) when user_id == for_id, do: true def visible_for?(%User{} = user, for_user) do - remote_or_auth_active?(user) || superuser?(for_user) + auth_active?(user) || superuser?(for_user) end def visible_for?(_, _), do: false -- cgit v1.2.3 From 0015d43e13508155462a9e5d18f19725fadd8931 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 9 Jan 2019 06:41:25 +0000 Subject: user: factor out illogical User.Info.superuser?/1. any actual callee will be dealing with a User struct to begin with, so just check the child struct inside User.superuser?/1 with pattern matching. --- lib/pleroma/user.ex | 3 ++- lib/pleroma/user/info.ex | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 636c56312..4d0f68cd6 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -63,7 +63,8 @@ defmodule Pleroma.User do def visible_for?(_, _), do: false - def superuser?(%User{info: %User.Info{} = info}), do: User.Info.superuser?(info) + def superuser?(%User{local: true, info: %User.Info{is_admin: true}}), do: true + def superuser?(%User{local: true, info: %User.Info{is_moderator: true}}), do: true def superuser?(_), do: false def avatar_url(user) do diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 2f419a5a2..7c79dfcff 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -41,8 +41,6 @@ defmodule Pleroma.User.Info do # subject _> Where is this used? end - def superuser?(info), do: info.is_admin || info.is_moderator - def set_activation_status(info, deactivated) do params = %{deactivated: deactivated} -- cgit v1.2.3 From f15183178c15bb01f6cd49f28f2177bfd26bdac8 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 9 Jan 2019 06:45:17 +0000 Subject: user: fix auth_active?/1 for remote users --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 4d0f68cd6..06049dc62 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -44,7 +44,7 @@ defmodule Pleroma.User do timestamps() end - def auth_active?(%User{local: false}), do: false + def auth_active?(%User{local: false}), do: true def auth_active?(%User{info: %User.Info{confirmation_pending: false}}), do: true -- cgit v1.2.3 From 20c0dd1e24b128e0be51197ac2d150052817c219 Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Tue, 8 Jan 2019 23:22:15 +0100 Subject: Support activity+json request for activity --- .../web/activity_pub/activity_pub_controller.ex | 13 +++++++++ lib/pleroma/web/ostatus/ostatus_controller.ex | 32 ++++++++++++---------- 2 files changed, 31 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index a3f736fee..73ca07e84 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -54,6 +54,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do end end + def activity(conn, %{"uuid" => uuid}) do + with ap_id <- o_status_url(conn, :activity, uuid), + %Activity{} = activity <- Activity.normalize(ap_id), + {_, true} <- {:public?, ActivityPub.is_public?(activity)} do + conn + |> put_resp_header("content-type", "application/activity+json") + |> json(ObjectView.render("object.json", %{object: activity})) + else + {:public?, false} -> + {:error, :not_found} + end + end + def following(conn, %{"nickname" => nickname, "page" => page}) do with %User{} = user <- User.get_cached_by_nickname(nickname), {:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 9b600737f..332cbef0e 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -112,23 +112,27 @@ defmodule Pleroma.Web.OStatus.OStatusController do end def activity(conn, %{"uuid" => uuid}) do - with id <- o_status_url(conn, :activity, uuid), - {_, %Activity{} = activity} <- {:activity, Activity.normalize(id)}, - {_, true} <- {:public?, ActivityPub.is_public?(activity)}, - %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do - case format = get_format(conn) do - "html" -> redirect(conn, to: "/notice/#{activity.id}") - _ -> represent_activity(conn, format, activity, user) - end + if get_format(conn) == "activity+json" do + ActivityPubController.call(conn, :activity) else - {:public?, false} -> - {:error, :not_found} + with id <- o_status_url(conn, :activity, uuid), + {_, %Activity{} = activity} <- {:activity, Activity.normalize(id)}, + {_, true} <- {:public?, ActivityPub.is_public?(activity)}, + %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do + case format = get_format(conn) do + "html" -> redirect(conn, to: "/notice/#{activity.id}") + _ -> represent_activity(conn, format, activity, user) + end + else + {:public?, false} -> + {:error, :not_found} - {:activity, nil} -> - {:error, :not_found} + {:activity, nil} -> + {:error, :not_found} - e -> - e + e -> + e + end end end -- cgit v1.2.3 From 28afcb7c31a357e05c6cb23645539389f37a15f4 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Wed, 9 Jan 2019 17:02:30 +0700 Subject: move defaults from sample_config.exs to config.exs --- lib/mix/tasks/pleroma/sample_config.eex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/sample_config.eex b/lib/mix/tasks/pleroma/sample_config.eex index 59c2c4fba..740b9f8d1 100644 --- a/lib/mix/tasks/pleroma/sample_config.eex +++ b/lib/mix/tasks/pleroma/sample_config.eex @@ -14,8 +14,7 @@ config :pleroma, :instance, email: "<%= email %>", limit: 5000, registrations_open: true, - dedupe_media: false, - max_pinned_statuses: 1 + dedupe_media: false config :pleroma, :media_proxy, enabled: false, -- cgit v1.2.3 From 26938d65fd5d59e6f50150f4e2bc924429d7733e Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 9 Jan 2019 11:35:23 +0100 Subject: Add User mass following function. --- lib/pleroma/user.ex | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 7c2849ce2..916b14350 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -307,6 +307,25 @@ defmodule Pleroma.User do end end + @doc "A mass follow for local users. Ignores blocks and has no side effects" + @spec follow_all(User.t(), list(User.t())) :: {atom(), User.t()} + def follow_all(follower, followeds) do + following = + (follower.following ++ Enum.map(followeds, fn %{follower_address: fa} -> fa end)) + |> Enum.uniq() + + {:ok, follower} = + follower + |> follow_changeset(%{following: following}) + |> update_and_set_cache + + Enum.each(followeds, fn followed -> + update_follower_count(followed) + end) + + {:ok, follower} + end + def follow(%User{} = follower, %User{info: info} = followed) do user_config = Application.get_env(:pleroma, :user) deny_follow_blocked = Keyword.get(user_config, :deny_follow_blocked) -- cgit v1.2.3 From 65fc2df7ccc85f07ea64b0f7340b98d5615bb1a3 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 9 Jan 2019 11:38:45 +0100 Subject: Use follow_all in autofollow. --- lib/pleroma/user.ex | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 916b14350..a49fa3fcd 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -247,10 +247,7 @@ defmodule Pleroma.User do ) |> Repo.all() - autofollowed_users - |> Enum.reduce({:ok, user}, fn other_user, {:ok, user} -> - follow(user, other_user) - end) + follow_all(user, autofollowed_users) end @doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)" -- cgit v1.2.3 From 1b06e6fdf3d879422d6cb0fe57cfcef223b54196 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Wed, 9 Jan 2019 17:40:15 +0700 Subject: only non-reblogs, self-authored, public statuses can be pinned --- lib/pleroma/web/common_api/common_api.ex | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 6d22813b2..7ec6aa0ea 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -165,8 +165,18 @@ defmodule Pleroma.Web.CommonAPI do }) end - def pin(id_or_ap_id, user) do - with %Activity{} = activity <- get_by_id_or_ap_id(id_or_ap_id), + def pin(id_or_ap_id, %{ap_id: user_ap_id} = user) do + with %Activity{ + actor: ^user_ap_id, + data: %{ + "type" => "Create", + "object" => %{ + "to" => object_to, + "type" => "Note" + } + } + } = activity <- get_by_id_or_ap_id(id_or_ap_id), + true <- Enum.member?(object_to, "https://www.w3.org/ns/activitystreams#Public"), %{valid?: true} = info_changeset <- Pleroma.User.Info.add_pinnned_activity(user.info, activity), changeset <- -- cgit v1.2.3 From 9854978b8bc3c3e4326b6dde9758dd276cd36e1c Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 9 Jan 2019 12:38:23 +0100 Subject: Remove recent activity restriction. This should be fine now, everything should be covered by indices. --- lib/pleroma/web/activity_pub/activity_pub.ex | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 4685f6d95..ea65538b6 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -517,15 +517,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_reblogs(query, _), do: query - # Only search through last 100_000 activities by default - defp restrict_recent(query, %{"whole_db" => true}), do: query - - defp restrict_recent(query, _) do - since = (Repo.aggregate(Activity, :max, :id) || 0) - 100_000 - - from(activity in query, where: activity.id > ^since) - end - defp restrict_blocked(query, %{"blocking_user" => %User{info: info}}) do blocks = info.blocks || [] domain_blocks = info.domain_blocks || [] @@ -570,7 +561,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do |> restrict_actor(opts) |> restrict_type(opts) |> restrict_favorited_by(opts) - |> restrict_recent(opts) |> restrict_blocked(opts) |> restrict_media(opts) |> restrict_visibility(opts) -- cgit v1.2.3 From 44a1e6948488d9a96ed684f0a7855fe2fce02ed4 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Wed, 9 Jan 2019 19:54:19 +0700 Subject: Add Twitter API for the pinned statuses ``` # Only return statuses that have been pinned GET /api/statuses/user_timeline.json?pinned=true # Pin POST /api/statuses/pin/:id # Unpin POST /api/statuses/unpin/:id ``` --- lib/pleroma/web/router.ex | 3 +++ .../representers/activity_representer.ex | 2 ++ lib/pleroma/web/twitter_api/twitter_api.ex | 8 ++++++++ .../web/twitter_api/twitter_api_controller.ex | 24 ++++++++++++++++++++++ lib/pleroma/web/twitter_api/views/activity_view.ex | 2 ++ 5 files changed, 39 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index ad73d8867..a5f4d8126 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -355,6 +355,9 @@ defmodule Pleroma.Web.Router do post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet) post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post) + post("/statuses/pin/:id", TwitterAPI.Controller, :pin) + post("/statuses/unpin/:id", TwitterAPI.Controller, :unpin) + get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests) post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request) post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request) diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 245cd52fd..64f7c00c7 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -153,6 +153,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do announcement_count = object["announcement_count"] || 0 favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || []) repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || []) + pinned = activity.id in user.info.pinned_activities mentions = opts[:mentioned] || [] @@ -202,6 +203,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do "repeat_num" => announcement_count, "favorited" => to_boolean(favorited), "repeated" => to_boolean(repeated), + "pinned" => pinned, "external_url" => object["external_url"] || object["id"], "tags" => tags, "activity_type" => "post", diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index ecf81d492..7a63724f1 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -82,6 +82,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do end end + def pin(%User{} = user, ap_id_or_id) do + CommonAPI.pin(ap_id_or_id, user) + end + + def unpin(%User{} = user, ap_id_or_id) do + CommonAPI.unpin(ap_id_or_id, user) + end + def fav(%User{} = user, ap_id_or_id) do with {:ok, _fav, %{data: %{"id" => id}}} <- CommonAPI.favorite(ap_id_or_id, user), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 1e04b8c4b..d5b9d2fb8 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -375,6 +375,30 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def pin(%{assigns: %{user: user}} = conn, %{"id" => id}) do + with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, + {:ok, activity} <- TwitterAPI.pin(user, id) do + conn + |> put_view(ActivityView) + |> render("activity.json", %{activity: activity, for: user}) + else + {:error, message} -> bad_request_reply(conn, message) + err -> err + end + end + + def unpin(%{assigns: %{user: user}} = conn, %{"id" => id}) do + with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, + {:ok, activity} <- TwitterAPI.unpin(user, id) do + conn + |> put_view(ActivityView) + |> render("activity.json", %{activity: activity, for: user}) + else + {:error, message} -> bad_request_reply(conn, message) + err -> err + end + end + def register(conn, params) do with {:ok, user} <- TwitterAPI.register_user(params) do conn diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 25e1486c1..425df8672 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -243,6 +243,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do announcement_count = object["announcement_count"] || 0 favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || []) repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || []) + pinned = activity.id in user.info.pinned_activities attentions = activity.recipients @@ -300,6 +301,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do "repeat_num" => announcement_count, "favorited" => !!favorited, "repeated" => !!repeated, + "pinned" => pinned, "external_url" => object["external_url"] || object["id"], "tags" => tags, "activity_type" => "post", -- cgit v1.2.3 From 5027f82cdef52391e408428ecc8013b1c4847b6b Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 9 Jan 2019 16:45:09 +0100 Subject: Add activity visibility index. --- lib/pleroma/web/activity_pub/activity_pub.ex | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 4685f6d95..b8141146f 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -364,21 +364,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do @valid_visibilities ~w[direct unlisted public private] - defp restrict_visibility(query, %{visibility: "direct"}) do - public = "https://www.w3.org/ns/activitystreams#Public" + defp restrict_visibility(query, %{visibility: visibility}) + when visibility in @valid_visibilities do + query = + from( + a in query, + where: + fragment("activity_visibility(?, ?, ?) = ?", a.actor, a.recipients, a.data, ^visibility) + ) - from( - activity in query, - join: sender in User, - on: sender.ap_id == activity.actor, - # Are non-direct statuses with no to/cc possible? - where: - fragment( - "not (? && ?)", - [^public, sender.follower_address], - activity.recipients - ) - ) + Ecto.Adapters.SQL.to_sql(:all, Repo, query) + + query end defp restrict_visibility(_query, %{visibility: visibility}) -- cgit v1.2.3 From 7ac152ed38267bde3e318fab82db7d7d610cdbbb Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 9 Jan 2019 18:14:32 +0100 Subject: TwitterAPI: Add follower/following pagination. --- lib/pleroma/user.ex | 32 ++++++++++++++++++---- .../web/twitter_api/twitter_api_controller.ex | 8 ++++-- 2 files changed, 32 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 7c2849ce2..f5f5dea1c 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -471,7 +471,7 @@ defmodule Pleroma.User do end end - def get_followers_query(%User{id: id, follower_address: follower_address}) do + def get_followers_query(%User{id: id, follower_address: follower_address}, nil) do from( u in User, where: fragment("? <@ ?", ^[follower_address], u.following), @@ -479,13 +479,23 @@ defmodule Pleroma.User do ) end - def get_followers(user) do - q = get_followers_query(user) + def get_followers_query(user, page) do + from( + u in get_followers_query(user, nil), + limit: 20, + offset: ^((page - 1) * 20) + ) + end + + def get_followers_query(user), do: get_followers_query(user, nil) + + def get_followers(user, page \\ nil) do + q = get_followers_query(user, page) {:ok, Repo.all(q)} end - def get_friends_query(%User{id: id, following: following}) do + def get_friends_query(%User{id: id, following: following}, nil) do from( u in User, where: u.follower_address in ^following, @@ -493,8 +503,18 @@ defmodule Pleroma.User do ) end - def get_friends(user) do - q = get_friends_query(user) + def get_friends_query(user, page) do + from( + u in get_friends_query(user, nil), + limit: 20, + offset: ^((page - 1) * 20) + ) + end + + def get_friends_query(user), do: get_friends_query(user, nil) + + def get_friends(user, page \\ nil) do + q = get_friends_query(user, page) {:ok, Repo.all(q)} end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 1e04b8c4b..0653acebe 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -472,8 +472,10 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def followers(%{assigns: %{user: for_user}} = conn, params) do + page = params["page"] || 1 + with {:ok, user} <- TwitterAPI.get_user(for_user, params), - {:ok, followers} <- User.get_followers(user) do + {:ok, followers} <- User.get_followers(user, page) do followers = cond do for_user && user.id == for_user.id -> followers @@ -490,8 +492,10 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def friends(%{assigns: %{user: for_user}} = conn, params) do + page = params["page"] || 1 + with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params), - {:ok, friends} <- User.get_friends(user) do + {:ok, friends} <- User.get_friends(user, page) do friends = cond do for_user && user.id == for_user.id -> friends -- cgit v1.2.3 From a99e156f2c0e3d2e5b5dec167efb29be1e429542 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 9 Jan 2019 18:17:23 +0100 Subject: Add integer casts. --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 0653acebe..a44c8c50a 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -472,7 +472,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def followers(%{assigns: %{user: for_user}} = conn, params) do - page = params["page"] || 1 + {:ok, page} = Ecto.Type.cast(:integer, params["page"] || 1) with {:ok, user} <- TwitterAPI.get_user(for_user, params), {:ok, followers} <- User.get_followers(user, page) do @@ -492,7 +492,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def friends(%{assigns: %{user: for_user}} = conn, params) do - page = params["page"] || 1 + {:ok, page} = Ecto.Type.cast(:integer, params["page"] || 1) with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params), {:ok, friends} <- User.get_friends(user, page) do -- cgit v1.2.3 From a2d7f0e0e9aaf03798b11d5c158c9382eaf698a1 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 9 Jan 2019 21:35:01 +0300 Subject: Remove :commit since a tuple is already returned --- lib/pleroma/web/rich_media/parser.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 3746feaf6..18d9e2df5 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.RichMedia.Parser do def parse(url), do: parse_url(url) else def parse(url), - do: {:commit, Cachex.fetch!(:rich_media_cache, url, fn _ -> parse_url(url) end)} + do: Cachex.fetch!(:rich_media_cache, url, fn _ -> parse_url(url) end) end defp parse_url(url) do -- cgit v1.2.3 From 2ecf81f10c1ebc01d21b4183f6cd248ce5cfbd6a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 10 Jan 2019 02:22:11 +0000 Subject: common api: fix newlines in markdown code blocks --- lib/pleroma/web/common_api/utils.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 3ff9f9452..187e908ce 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -150,7 +150,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do |> Formatter.mentions_escape(mentions) |> Earmark.as_html!() |> Formatter.html_escape("text/html") - |> String.replace(~r/\r?\n/, "") |> (&{[], &1}).() |> Formatter.add_user_links(mentions) |> Formatter.add_hashtag_links(tags) -- cgit v1.2.3 From 0bdbd4f968b20a508f9433480c7e358428dc55d7 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 10 Jan 2019 03:45:58 +0000 Subject: common api: utils: remove newline to
conversion from bare HTML to be consistent with markdown ok @lanodan --- lib/pleroma/web/common_api/utils.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 187e908ce..7e30d224c 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -136,7 +136,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do def format_input(text, mentions, _tags, "text/html") do text |> Formatter.html_escape("text/html") - |> String.replace(~r/\r?\n/, "
") |> (&{[], &1}).() |> Formatter.add_user_links(mentions) |> Formatter.finalize() -- cgit v1.2.3 From 1f851a07232e510e82e7b13400dfcb31cca555bb Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 10 Jan 2019 18:09:56 +0000 Subject: Add Twitter Card parser --- lib/pleroma/web/rich_media/parser.ex | 2 +- .../web/rich_media/parsers/meta_tags_parser.ex | 30 ++++++++++++++++++++ lib/pleroma/web/rich_media/parsers/ogp.ex | 33 +++++----------------- lib/pleroma/web/rich_media/parsers/twitter_card.ex | 11 ++++++++ 4 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 lib/pleroma/web/rich_media/parsers/meta_tags_parser.ex create mode 100644 lib/pleroma/web/rich_media/parsers/twitter_card.ex (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 18d9e2df5..fe092bf19 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -1,5 +1,5 @@ defmodule Pleroma.Web.RichMedia.Parser do - @parsers [Pleroma.Web.RichMedia.Parsers.OGP] + @parsers [Pleroma.Web.RichMedia.Parsers.OGP, Pleroma.Web.RichMedia.Parsers.TwitterCard] if Mix.env() == :test do def parse(url), do: parse_url(url) diff --git a/lib/pleroma/web/rich_media/parsers/meta_tags_parser.ex b/lib/pleroma/web/rich_media/parsers/meta_tags_parser.ex new file mode 100644 index 000000000..4a7c5eae0 --- /dev/null +++ b/lib/pleroma/web/rich_media/parsers/meta_tags_parser.ex @@ -0,0 +1,30 @@ +defmodule Pleroma.Web.RichMedia.Parsers.MetaTagsParser do + def parse(html, data, prefix, error_message, key_name, value_name \\ "content") do + with elements = [_ | _] <- get_elements(html, key_name, prefix), + meta_data = + Enum.reduce(elements, data, fn el, acc -> + attributes = normalize_attributes(el, prefix, key_name, value_name) + + Map.merge(acc, attributes) + end) do + {:ok, meta_data} + else + _e -> {:error, error_message} + end + end + + defp get_elements(html, key_name, prefix) do + html |> Floki.find("meta[#{key_name}^='#{prefix}:']") + end + + defp normalize_attributes(html_node, prefix, key_name, value_name) do + {_tag, attributes, _children} = html_node + + data = + Enum.into(attributes, %{}, fn {name, value} -> + {name, String.trim_leading(value, "#{prefix}:")} + end) + + %{String.to_atom(data[key_name]) => data[value_name]} + end +end diff --git a/lib/pleroma/web/rich_media/parsers/ogp.ex b/lib/pleroma/web/rich_media/parsers/ogp.ex index 5773a5263..0e1a0e719 100644 --- a/lib/pleroma/web/rich_media/parsers/ogp.ex +++ b/lib/pleroma/web/rich_media/parsers/ogp.ex @@ -1,30 +1,11 @@ defmodule Pleroma.Web.RichMedia.Parsers.OGP do def parse(html, data) do - with elements = [_ | _] <- get_elements(html), - ogp_data = - Enum.reduce(elements, data, fn el, acc -> - attributes = normalize_attributes(el) - - Map.merge(acc, attributes) - end) do - {:ok, ogp_data} - else - _e -> {:error, "No OGP metadata found"} - end - end - - defp get_elements(html) do - html |> Floki.find("meta[property^='og:']") - end - - defp normalize_attributes(html_node) do - {_tag, attributes, _children} = html_node - - data = - Enum.into(attributes, %{}, fn {name, value} -> - {name, String.trim_leading(value, "og:")} - end) - - %{String.to_atom(data["property"]) => data["content"]} + Pleroma.Web.RichMedia.Parsers.MetaTagsParser.parse( + html, + data, + "og", + "No OGP metadata found", + "property" + ) end end diff --git a/lib/pleroma/web/rich_media/parsers/twitter_card.ex b/lib/pleroma/web/rich_media/parsers/twitter_card.ex new file mode 100644 index 000000000..a317c3e78 --- /dev/null +++ b/lib/pleroma/web/rich_media/parsers/twitter_card.ex @@ -0,0 +1,11 @@ +defmodule Pleroma.Web.RichMedia.Parsers.TwitterCard do + def parse(html, data) do + Pleroma.Web.RichMedia.Parsers.MetaTagsParser.parse( + html, + data, + "twitter", + "No twitter card metadata found", + "name" + ) + end +end -- cgit v1.2.3 From b594a54d0caf0f91dd9188157cb34e01ee9ea794 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Fri, 11 Jan 2019 12:31:31 +0700 Subject: unpin when deleting a status --- lib/pleroma/web/common_api/common_api.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 7ec6aa0ea..2902905fd 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -14,6 +14,7 @@ defmodule Pleroma.Web.CommonAPI do with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id), %Object{} = object <- Object.normalize(object_id), true <- user.info.is_moderator || user.ap_id == object.data["actor"], + {:ok, _} <- unpin(activity_id, user), {:ok, delete} <- ActivityPub.delete(object) do {:ok, delete} end -- cgit v1.2.3 From 144b48da95867b33315c6a0e6e865c457d89452b Mon Sep 17 00:00:00 2001 From: Sadposter Date: Sat, 12 Jan 2019 14:03:35 +0000 Subject: Add link headers to MastoAPI /favourites As documented at https://docs.joinmastodon.org/api/rest/favourites/ --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index e00a3fb87..b83539bad 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -836,6 +836,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> Enum.reverse() conn + |> add_link_headers(:favourites, activities) |> put_view(StatusView) |> render("index.json", %{activities: activities, for: user, as: :activity}) end -- cgit v1.2.3 From 9daf16246121f3d5eeb4d6caeffc237cd5526546 Mon Sep 17 00:00:00 2001 From: Sadposter Date: Sat, 12 Jan 2019 14:42:52 +0000 Subject: Honour parameters on MastoAPI /favourites --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index b83539bad..a8fe9d708 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -824,9 +824,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do json(conn, res) end - def favourites(%{assigns: %{user: user}} = conn, _) do + def favourites(%{assigns: %{user: user}} = conn, params) do params = - %{} + params |> Map.put("type", "Create") |> Map.put("favorited_by", user.ap_id) |> Map.put("blocking_user", user) -- cgit v1.2.3 From 1eb7318831e7239ec929457f6298fb05cb461b43 Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Sat, 12 Jan 2019 17:52:30 +0100 Subject: Prepare all types objects before serialising Activities returned from inbox can include other types of objects like Article --- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 87b7fc07f..b0f8c59cc 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -641,7 +641,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do # internal -> Mastodon # """ - def prepare_outgoing(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do + def prepare_outgoing(%{"type" => "Create", "object" => object} = data) do object = object |> prepare_object -- cgit v1.2.3 From 36711e1c83bb24a2b104c4a8f384c475c1583638 Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Tue, 8 Jan 2019 19:22:26 +0100 Subject: Handle client submitted activitypub like activity --- lib/pleroma/web/activity_pub/activity_pub_controller.ex | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 73ca07e84..6bc8b7195 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -204,6 +204,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do end end + def handle_user_activity(user, %{"type" => "Like"} = params) do + with %Object{} = object <- Object.normalize(params["object"]), + {:ok, activity, _object} <- ActivityPub.like(user, object) do + {:ok, activity} + else + _ -> {:error, "Can't like object"} + end + end + def handle_user_activity(_, _) do {:error, "Unhandled activity type"} end -- cgit v1.2.3 From 581edd5a91189e6fb2a94a277b96f9c8197617b8 Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Fri, 11 Jan 2019 23:34:32 +0100 Subject: Add route to get object like activities --- .../web/activity_pub/activity_pub_controller.ex | 30 +++++++++++++++++++ lib/pleroma/web/activity_pub/utils.ex | 21 +++++++++++++ lib/pleroma/web/activity_pub/views/object_view.ex | 34 ++++++++++++++++++++++ lib/pleroma/web/router.ex | 1 + 4 files changed, 86 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 6bc8b7195..7eed0a600 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -54,6 +54,36 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do end end + def object_likes(conn, %{"uuid" => uuid, "page" => page}) do + with ap_id <- o_status_url(conn, :object, uuid), + %Object{} = object <- Object.get_cached_by_ap_id(ap_id), + {_, true} <- {:public?, ActivityPub.is_public?(object)}, + likes <- Utils.get_object_likes(object) do + {page, _} = Integer.parse(page) + + conn + |> put_resp_header("content-type", "application/activity+json") + |> json(ObjectView.render("likes.json", ap_id, likes, page)) + else + {:public?, false} -> + {:error, :not_found} + end + end + + def object_likes(conn, %{"uuid" => uuid}) do + with ap_id <- o_status_url(conn, :object, uuid), + %Object{} = object <- Object.get_cached_by_ap_id(ap_id), + {_, true} <- {:public?, ActivityPub.is_public?(object)}, + likes <- Utils.get_object_likes(object) do + conn + |> put_resp_header("content-type", "application/activity+json") + |> json(ObjectView.render("likes.json", ap_id, likes)) + else + {:public?, false} -> + {:error, :not_found} + end + end + def activity(conn, %{"uuid" => uuid}) do with ap_id <- o_status_url(conn, :activity, uuid), %Activity{} = activity <- Activity.normalize(ap_id), diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index b313996db..6ecab773c 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -231,6 +231,27 @@ defmodule Pleroma.Web.ActivityPub.Utils do Repo.one(query) end + @doc """ + Returns like activities targeting an object + """ + def get_object_likes(%{data: %{"id" => id}}) do + query = + from( + activity in Activity, + # this is to use the index + where: + fragment( + "coalesce((?)->'object'->>'id', (?)->>'object') = ?", + activity.data, + activity.data, + ^id + ), + where: fragment("(?)->>'type' = 'Like'", activity.data) + ) + + Repo.all(query) + end + def make_like_data(%User{ap_id: ap_id} = actor, %{data: %{"id" => id}} = object, activity_id) do data = %{ "type" => "Like", diff --git a/lib/pleroma/web/activity_pub/views/object_view.ex b/lib/pleroma/web/activity_pub/views/object_view.ex index b5c9bf8d0..193042056 100644 --- a/lib/pleroma/web/activity_pub/views/object_view.ex +++ b/lib/pleroma/web/activity_pub/views/object_view.ex @@ -35,4 +35,38 @@ defmodule Pleroma.Web.ActivityPub.ObjectView do Map.merge(base, additional) end + + def render("likes.json", ap_id, likes, page) do + collection(likes, "#{ap_id}/likes", page) + |> Map.merge(Pleroma.Web.ActivityPub.Utils.make_json_ld_header()) + end + + def render("likes.json", ap_id, likes) do + %{ + "id" => "#{ap_id}/likes", + "type" => "OrderedCollection", + "totalItems" => length(likes), + "first" => collection(likes, "#{ap_id}/followers", 1) + } + |> Map.merge(Pleroma.Web.ActivityPub.Utils.make_json_ld_header()) + end + + def collection(collection, iri, page) do + offset = (page - 1) * 10 + items = Enum.slice(collection, offset, 10) + items = Enum.map(items, fn object -> Transmogrifier.prepare_object(object.data) end) + total = length(collection) + + map = %{ + "id" => "#{iri}?page=#{page}", + "type" => "OrderedCollectionPage", + "partOf" => iri, + "totalItems" => total, + "orderedItems" => items + } + + if offset < total do + Map.put(map, "next", "#{iri}?page=#{page + 1}") + end + end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index a5f4d8126..7a0c9fd25 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -421,6 +421,7 @@ defmodule Pleroma.Web.Router do get("/users/:nickname/followers", ActivityPubController, :followers) get("/users/:nickname/following", ActivityPubController, :following) get("/users/:nickname/outbox", ActivityPubController, :outbox) + get("/objects/:uuid/likes", ActivityPubController, :object_likes) end pipeline :activitypub_client do -- cgit v1.2.3 From 868034375c5122175f872967e49559dafed9403c Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Wed, 9 Jan 2019 09:22:00 +0100 Subject: Add likes to activitypub object representation Top level of the likes OrderedCollection is inlined to get immediate access to totalItems. Because the count can be returned without scanning the database for like activities the extra query is saved when the client only wants to display the total. --- lib/pleroma/web/activity_pub/transmogrifier.ex | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index b0f8c59cc..86d11c874 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -629,6 +629,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do |> add_mention_tags |> add_emoji_tags |> add_attributed_to + |> add_likes |> prepare_attachments |> set_conversation |> set_reply_to_uri @@ -788,6 +789,22 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do |> Map.put("attributedTo", attributedTo) end + def add_likes(%{"id" => id, "like_count" => likes} = object) do + likes = %{ + "id" => "#{id}/likes", + "first" => "#{id}/likes?page=1", + "type" => "OrderedCollection", + "totalItems" => likes + } + + object + |> Map.put("likes", likes) + end + + def add_likes(object) do + object + end + def prepare_attachments(object) do attachments = (object["attachment"] || []) @@ -803,7 +820,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do defp strip_internal_fields(object) do object |> Map.drop([ - "likes", "like_count", "announcements", "announcement_count", -- cgit v1.2.3 From b8a77c5d704a4a76f227854c1cab560eb98a7382 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Sun, 13 Jan 2019 02:06:50 +0200 Subject: Add OEmbed parser --- lib/pleroma/web/rich_media/parser.ex | 6 ++++- .../web/rich_media/parsers/oembed_parser.ex | 27 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 lib/pleroma/web/rich_media/parsers/oembed_parser.ex (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index fe092bf19..6da83c6e4 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -1,5 +1,9 @@ defmodule Pleroma.Web.RichMedia.Parser do - @parsers [Pleroma.Web.RichMedia.Parsers.OGP, Pleroma.Web.RichMedia.Parsers.TwitterCard] + @parsers [ + Pleroma.Web.RichMedia.Parsers.OGP, + Pleroma.Web.RichMedia.Parsers.TwitterCard, + Pleroma.Web.RichMedia.Parsers.OEmbed + ] if Mix.env() == :test do def parse(url), do: parse_url(url) diff --git a/lib/pleroma/web/rich_media/parsers/oembed_parser.ex b/lib/pleroma/web/rich_media/parsers/oembed_parser.ex new file mode 100644 index 000000000..ca7226faf --- /dev/null +++ b/lib/pleroma/web/rich_media/parsers/oembed_parser.ex @@ -0,0 +1,27 @@ +defmodule Pleroma.Web.RichMedia.Parsers.OEmbed do + def parse(html, _data) do + with elements = [_ | _] <- get_discovery_data(html), + {:ok, oembed_url} <- get_oembed_url(elements), + {:ok, oembed_data} <- get_oembed_data(oembed_url) do + {:ok, oembed_data} + else + _e -> {:error, "No OEmbed data found"} + end + end + + defp get_discovery_data(html) do + html |> Floki.find("link[type='application/json+oembed']") + end + + defp get_oembed_url(nodes) do + {"link", attributes, _children} = nodes |> hd() + + {:ok, Enum.into(attributes, %{})["href"]} + end + + defp get_oembed_data(url) do + {:ok, %Tesla.Env{body: json}} = Pleroma.HTTP.get(url) + + {:ok, Poison.decode!(json)} + end +end -- cgit v1.2.3 From 6e5b0406b9f2eda5c78148837927d89aa9b2d6f9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 14 Jan 2019 05:31:57 +0000 Subject: mrf: add no placeholder-text policy, strips pointless "." content from posts with images --- .../activity_pub/mrf/no_placeholder_text_policy.ex | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/pleroma/web/activity_pub/mrf/no_placeholder_text_policy.ex (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/no_placeholder_text_policy.ex b/lib/pleroma/web/activity_pub/mrf/no_placeholder_text_policy.ex new file mode 100644 index 000000000..081456046 --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/no_placeholder_text_policy.ex @@ -0,0 +1,29 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy do + @behaviour Pleroma.Web.ActivityPub.MRF + + @impl true + def filter( + %{ + "type" => "Create", + "object" => %{"content" => content, "attachment" => _attachment} = child_object + } = object + ) + when content in [".", "

.

"] do + child_object = + child_object + |> Map.put("content", "") + + object = + object + |> Map.put("object", child_object) + + {:ok, object} + end + + @impl true + def filter(object), do: {:ok, object} +end -- cgit v1.2.3 From 5f9786288d0ebc13240f55caa7ae4578d386d843 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 14 Jan 2019 09:52:52 +0300 Subject: Prefer ids to usernames --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 3120b13b6..26cef53ee 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -454,7 +454,7 @@ defmodule Pleroma.User do end def get_cached_by_nickname_or_id(nickname_or_id) do - get_cached_by_nickname(nickname_or_id) || get_cached_by_id(nickname_or_id) + get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id) end def get_by_nickname(nickname) do -- cgit v1.2.3 From 42b7584068e51a58d2bfe76729fe039fe7f6a7cf Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 14 Jan 2019 11:31:44 -0500 Subject: URI escape file upload URLs --- lib/pleroma/upload.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 0b1bdeec4..185ba25fa 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -215,7 +215,7 @@ defmodule Pleroma.Upload do end defp url_from_spec(base_url, {:file, path}) do - [base_url, "media", path] + [base_url, "media", URI.encode(path)] |> Path.join() end -- cgit v1.2.3 From dc45ec62c2f5dfcc895854dfbddf6fe9621d3072 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Mon, 14 Jan 2019 20:04:45 +0300 Subject: [#477] User search improvements: tsquery search with field weights, friends & followers boosting. --- lib/pleroma/user.ex | 75 +++++++++++++++++++--- .../web/mastodon_api/mastodon_api_controller.ex | 6 +- .../web/twitter_api/twitter_api_controller.ex | 2 +- 3 files changed, 70 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 681280539..52638b446 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -35,7 +35,7 @@ defmodule Pleroma.User do field(:avatar, :map) field(:local, :boolean, default: true) field(:follower_address, :string) - field(:search_distance, :float, virtual: true) + field(:search_rank, :float, virtual: true) field(:tags, {:array, :string}, default: []) field(:last_refreshed_at, :naive_datetime) has_many(:notifications, Notification) @@ -511,6 +511,12 @@ defmodule Pleroma.User do {:ok, Repo.all(q)} end + def get_followers_ids(user, page \\ nil) do + q = get_followers_query(user, page) + + Repo.all(from(u in q, select: u.id)) + end + def get_friends_query(%User{id: id, following: following}, nil) do from( u in User, @@ -535,6 +541,12 @@ defmodule Pleroma.User do {:ok, Repo.all(q)} end + def get_friends_ids(user, page \\ nil) do + q = get_friends_query(user, page) + + Repo.all(from(u in q, select: u.id)) + end + def get_follow_requests_query(%User{} = user) do from( a in Activity, @@ -666,7 +678,7 @@ defmodule Pleroma.User do Repo.all(query) end - def search(query, resolve \\ false) do + def search(query, resolve \\ false, for_user \\ nil) do # strip the beginning @ off if there is a query query = String.trim_leading(query, "@") @@ -674,16 +686,28 @@ defmodule Pleroma.User do User.get_or_fetch_by_nickname(query) end + processed_query = + query + |> String.replace(~r/\W+/, " ") + |> String.trim() + |> String.split() + |> Enum.map(&(&1 <> ":*")) + |> Enum.join(" | ") + inner = from( u in User, select_merge: %{ - search_distance: + search_rank: fragment( - "? <-> (? || coalesce(?, ''))", - ^query, - u.nickname, - u.name + """ + ts_rank_cd( + setweight(to_tsvector('simple', regexp_replace(nickname, '\\W', ' ', 'g')), 'A') || + setweight(to_tsvector('simple', regexp_replace(coalesce(name, ''), '\\W', ' ', 'g')), 'B'), + to_tsquery('simple', ?) + ) + """, + ^processed_query ) }, where: not is_nil(u.nickname) @@ -692,11 +716,44 @@ defmodule Pleroma.User do q = from( s in subquery(inner), - order_by: s.search_distance, + order_by: [desc: s.search_rank], limit: 20 ) - Repo.all(q) + results = + q + |> Repo.all() + |> Enum.filter(&(&1.search_rank > 0)) + + weighted_results = + if for_user do + friends_ids = get_friends_ids(for_user) + followers_ids = get_followers_ids(for_user) + + Enum.map( + results, + fn u -> + search_rank_coef = + cond do + u.id in friends_ids -> + 1.2 + + u.id in followers_ids -> + 1.1 + + true -> + 1 + end + + Map.put(u, :search_rank, u.search_rank * search_rank_coef) + end + ) + |> Enum.sort_by(&(-&1.search_rank)) + else + results + end + + weighted_results end def blocks_import(%User{} = blocker, blocked_identifiers) when is_list(blocked_identifiers) do diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index a8fe9d708..54367f586 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -772,7 +772,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def search2(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do - accounts = User.search(query, params["resolve"] == "true") + accounts = User.search(query, params["resolve"] == "true", user) statuses = status_search(user, query) @@ -796,7 +796,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do - accounts = User.search(query, params["resolve"] == "true") + accounts = User.search(query, params["resolve"] == "true", user) statuses = status_search(user, query) @@ -817,7 +817,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def account_search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do - accounts = User.search(query, params["resolve"] == "true") + accounts = User.search(query, params["resolve"] == "true", user) res = AccountView.render("accounts.json", users: accounts, for: user, as: :user) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 1c728166c..ede079963 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -675,7 +675,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def search_user(%{assigns: %{user: user}} = conn, %{"query" => query}) do - users = User.search(query, true) + users = User.search(query, true, user) conn |> put_view(UserView) -- cgit v1.2.3 From e8eff9fe03faa1922357d438ed973f5b83605aab Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Tue, 15 Jan 2019 02:58:48 +0200 Subject: Fix Elixir 1.8 type annotation issue --- lib/pleroma/upload.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 185ba25fa..2a48331d7 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -34,8 +34,9 @@ defmodule Pleroma.Upload do require Logger @type source :: - Plug.Upload.t() | data_uri_string :: - String.t() | {:from_local, name :: String.t(), id :: String.t(), path :: String.t()} + Plug.Upload.t() + | (data_uri_string :: String.t()) + | {:from_local, name :: String.t(), id :: String.t(), path :: String.t()} @type option :: {:type, :avatar | :banner | :background} -- cgit v1.2.3 From e3eb75bd234c8e21ff937d4f9b2a4a1328007e32 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 15 Jan 2019 07:40:00 +0100 Subject: Upload: Fix uploading with a ? in the filename --- lib/pleroma/upload.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 185ba25fa..1d8b073af 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -215,7 +215,12 @@ defmodule Pleroma.Upload do end defp url_from_spec(base_url, {:file, path}) do - [base_url, "media", URI.encode(path)] + path = + path + |> URI.encode() + |> String.replace("?", "%3F") + + [base_url, "media", path] |> Path.join() end -- cgit v1.2.3 From 9fcdca1bdca04bdb52b7ac9a0d69e0886b12cb87 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 15 Jan 2019 07:57:48 +0100 Subject: Upload: Fix uploading with a : in the filename --- lib/pleroma/upload.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 1d8b073af..b19920dff 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -219,6 +219,7 @@ defmodule Pleroma.Upload do path |> URI.encode() |> String.replace("?", "%3F") + |> String.replace(":", "%3A") [base_url, "media", path] |> Path.join() -- cgit v1.2.3 From 4656f433f94f132449df019beae1013f71728d0e Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 11:00:17 +0300 Subject: Move metadata.ex out of ostatus --- lib/pleroma/web/metadata.ex | 82 +++++++++++++++++++++++++++++++++++++ lib/pleroma/web/ostatus/metadata.ex | 82 ------------------------------------- 2 files changed, 82 insertions(+), 82 deletions(-) create mode 100644 lib/pleroma/web/metadata.ex delete mode 100644 lib/pleroma/web/ostatus/metadata.ex (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex new file mode 100644 index 000000000..9935726fc --- /dev/null +++ b/lib/pleroma/web/metadata.ex @@ -0,0 +1,82 @@ +defmodule Pleroma.Web.Metadata do + alias Phoenix.HTML + alias Pleroma.{Formatter, User} + alias Pleroma.Web.MediaProxy + + def build_tags(params) do + if(meta_enabled?(:opengraph), do: opengraph_tags(params), else: []) + |> Enum.map(&to_tag/1) + |> Enum.map(&HTML.safe_to_string/1) + |> Enum.join("\n") + end + + def meta_enabled?(type) do + Pleroma.Config.get([:metadata, type], false) + end + + # opengraph for single status + defp opengraph_tags(%{activity: activity, user: user}) do + with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do + [ + {:meta, + [ + property: "og:title", + content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) post ##{activity.id}" + ], []}, + {:meta, [property: "og:url", content: activity.data["id"]], []}, + {:meta, [property: "og:description", content: truncated_content], []}, + {:meta, [property: "og:image", content: user_avatar_url(user)], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []}, + {:meta, [property: "twitter:card", content: "summary"], []} + ] + end + end + + # opengraph for user card + defp opengraph_tags(%{user: user}) do + with truncated_bio = scrub_html_and_truncate(user.bio) do + [ + {:meta, + [ + property: "og:title", + content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) profile" + ], []}, + {:meta, [property: "og:url", content: User.profile_url(user)], []}, + {:meta, [property: "og:description", content: truncated_bio], []}, + {:meta, [property: "og:image", content: user_avatar_url(user)], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []}, + {:meta, [property: "twitter:card", content: "summary"], []} + ] + end + end + + def to_tag(data) do + with {name, attrs, _content = []} <- data do + HTML.Tag.tag(name, attrs) + else + {name, attrs, content} -> + HTML.Tag.content_tag(name, content, attrs) + + _ -> + raise ArgumentError, message: "make_tag invalid args" + end + end + + defp scrub_html_and_truncate(content) do + content + # html content comes from DB already encoded, decode first and scrub after + |> HtmlEntities.decode() + |> Pleroma.HTML.strip_tags() + |> Formatter.truncate() + end + + defp user_avatar_url(user) do + User.avatar_url(user) |> MediaProxy.url() + end + + def pleroma_domain do + Pleroma.Web.Endpoint.host() + end +end diff --git a/lib/pleroma/web/ostatus/metadata.ex b/lib/pleroma/web/ostatus/metadata.ex deleted file mode 100644 index 9935726fc..000000000 --- a/lib/pleroma/web/ostatus/metadata.ex +++ /dev/null @@ -1,82 +0,0 @@ -defmodule Pleroma.Web.Metadata do - alias Phoenix.HTML - alias Pleroma.{Formatter, User} - alias Pleroma.Web.MediaProxy - - def build_tags(params) do - if(meta_enabled?(:opengraph), do: opengraph_tags(params), else: []) - |> Enum.map(&to_tag/1) - |> Enum.map(&HTML.safe_to_string/1) - |> Enum.join("\n") - end - - def meta_enabled?(type) do - Pleroma.Config.get([:metadata, type], false) - end - - # opengraph for single status - defp opengraph_tags(%{activity: activity, user: user}) do - with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do - [ - {:meta, - [ - property: "og:title", - content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) post ##{activity.id}" - ], []}, - {:meta, [property: "og:url", content: activity.data["id"]], []}, - {:meta, [property: "og:description", content: truncated_content], []}, - {:meta, [property: "og:image", content: user_avatar_url(user)], []}, - {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []}, - {:meta, [property: "twitter:card", content: "summary"], []} - ] - end - end - - # opengraph for user card - defp opengraph_tags(%{user: user}) do - with truncated_bio = scrub_html_and_truncate(user.bio) do - [ - {:meta, - [ - property: "og:title", - content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) profile" - ], []}, - {:meta, [property: "og:url", content: User.profile_url(user)], []}, - {:meta, [property: "og:description", content: truncated_bio], []}, - {:meta, [property: "og:image", content: user_avatar_url(user)], []}, - {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []}, - {:meta, [property: "twitter:card", content: "summary"], []} - ] - end - end - - def to_tag(data) do - with {name, attrs, _content = []} <- data do - HTML.Tag.tag(name, attrs) - else - {name, attrs, content} -> - HTML.Tag.content_tag(name, content, attrs) - - _ -> - raise ArgumentError, message: "make_tag invalid args" - end - end - - defp scrub_html_and_truncate(content) do - content - # html content comes from DB already encoded, decode first and scrub after - |> HtmlEntities.decode() - |> Pleroma.HTML.strip_tags() - |> Formatter.truncate() - end - - defp user_avatar_url(user) do - User.avatar_url(user) |> MediaProxy.url() - end - - def pleroma_domain do - Pleroma.Web.Endpoint.host() - end -end -- cgit v1.2.3 From ce15e0659e63217d482ef0448ef7629c76755c46 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 11:56:35 +0300 Subject: Fix some edge cases [nervous laughter] --- lib/pleroma/user.ex | 15 ++++++++++++++- lib/pleroma/web/metadata.ex | 10 ++++++++-- lib/pleroma/web/router.ex | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 26cef53ee..0e828a99e 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -454,7 +454,20 @@ defmodule Pleroma.User do end def get_cached_by_nickname_or_id(nickname_or_id) do - get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id) + try do + # TODO: convert to UUIDs when !654 is merged + maybe_id = String.to_integer(nickname_or_id) + user = get_cached_by_id(maybe_id) + + if user == nil do + raise ArgumentError, message: "invalid argument foo" + else + user + end + rescue + _ in ArgumentError -> + get_cached_by_nickname(nickname_or_id) + end end def get_by_nickname(nickname) do diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index 9935726fc..b7052eec1 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -21,7 +21,13 @@ defmodule Pleroma.Web.Metadata do {:meta, [ property: "og:title", - content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) post ##{activity.id}" + content: + "#{user.name}" <> + if user.local do + "(@#{user.nickname}@{pleroma_domain})" + else + "(@#{user.nickname})" + end ], []}, {:meta, [property: "og:url", content: activity.data["id"]], []}, {:meta, [property: "og:description", content: truncated_content], []}, @@ -35,7 +41,7 @@ defmodule Pleroma.Web.Metadata do # opengraph for user card defp opengraph_tags(%{user: user}) do - with truncated_bio = scrub_html_and_truncate(user.bio) do + with truncated_bio = scrub_html_and_truncate(user.bio || "") do [ {:meta, [ diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 5ef99bec5..6cf689ce2 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -505,7 +505,7 @@ defmodule Pleroma.Web.Router do scope "/", Fallback do get("/registration/:token", RedirectController, :registration_page) - get("/*path", RedirectController, :redirector) + get("/*path", RedirectController, :redirector_with_meta) options("/*path", RedirectController, :empty) end -- cgit v1.2.3 From 4587a5712adcd5d71aaca70de1d895d2e6505382 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 11:59:05 +0300 Subject: cringe --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 0e828a99e..19759acec 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -460,7 +460,7 @@ defmodule Pleroma.User do user = get_cached_by_id(maybe_id) if user == nil do - raise ArgumentError, message: "invalid argument foo" + raise ArgumentError, message: "No such user id" else user end -- cgit v1.2.3 From 6f23139864936c8e61cdc278c55b3d8f725e892d Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 12:02:55 +0300 Subject: please don't bully me for this --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 19759acec..5707ba7a2 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -465,7 +465,7 @@ defmodule Pleroma.User do user end rescue - _ in ArgumentError -> + ArgumentError -> get_cached_by_nickname(nickname_or_id) end end -- cgit v1.2.3 From 2858fd2da217e172dcc0f664f21bfc8d81dce452 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 12:11:07 +0300 Subject: add a fallback function --- lib/pleroma/web/metadata.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index b7052eec1..8591db6b5 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -57,7 +57,9 @@ defmodule Pleroma.Web.Metadata do ] end end - + defp opengraph_tags(_) do + [] + end def to_tag(data) do with {name, attrs, _content = []} <- data do HTML.Tag.tag(name, attrs) -- cgit v1.2.3 From 5b8f9ff8c14b5992e3db7a0c890ca5539e6a0086 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 15 Jan 2019 13:05:25 +0300 Subject: [#477] User search tests. Normalized search rank in User.search. --- lib/pleroma/user.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 52638b446..2488697bb 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -704,7 +704,8 @@ defmodule Pleroma.User do ts_rank_cd( setweight(to_tsvector('simple', regexp_replace(nickname, '\\W', ' ', 'g')), 'A') || setweight(to_tsvector('simple', regexp_replace(coalesce(name, ''), '\\W', ' ', 'g')), 'B'), - to_tsquery('simple', ?) + to_tsquery('simple', ?), + 32 ) """, ^processed_query -- cgit v1.2.3 From 8745c8c9908ab21ee68e176ab085219df0d49d7b Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 18:34:47 +0300 Subject: remove useless newlines after every tag. Make domain.com/username provide opengraph too --- lib/pleroma/web/metadata.ex | 4 +++- lib/pleroma/web/router.ex | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index 8591db6b5..f8906e03f 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -7,7 +7,7 @@ defmodule Pleroma.Web.Metadata do if(meta_enabled?(:opengraph), do: opengraph_tags(params), else: []) |> Enum.map(&to_tag/1) |> Enum.map(&HTML.safe_to_string/1) - |> Enum.join("\n") + |> Enum.join() end def meta_enabled?(type) do @@ -57,9 +57,11 @@ defmodule Pleroma.Web.Metadata do ] end end + defp opengraph_tags(_) do [] end + def to_tag(data) do with {name, attrs, _content = []} <- data do HTML.Tag.tag(name, attrs) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 6cf689ce2..25e866c48 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -505,7 +505,8 @@ defmodule Pleroma.Web.Router do scope "/", Fallback do get("/registration/:token", RedirectController, :registration_page) - get("/*path", RedirectController, :redirector_with_meta) + get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta) + get("/*path", RedirectController, :redirector) options("/*path", RedirectController, :empty) end @@ -514,6 +515,7 @@ end defmodule Fallback.RedirectController do use Pleroma.Web, :controller alias Pleroma.Web.Metadata + alias Pleroma.User def redirector(conn, _params) do conn @@ -521,6 +523,15 @@ defmodule Fallback.RedirectController do |> send_file(200, index_file_path()) end + def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do + with %User{} = user <- User.get_cached_by_nickname_or_id(maybe_nickname_or_id) do + redirector_with_meta(conn, %{user: user}) + else + nil -> + redirector(conn, params) + end + end + def redirector_with_meta(conn, params) do {:ok, index_content} = File.read(index_file_path()) tags = Metadata.build_tags(params) -- cgit v1.2.3 From 850912b06b64818c069b8f169242f0106b73bbfe Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 19:43:52 +0300 Subject: refactor opengraph to a different module with a behaviour --- lib/pleroma/web/metadata.ex | 83 +++++------------------------------ lib/pleroma/web/metadata/opengraph.ex | 66 ++++++++++++++++++++++++++++ lib/pleroma/web/metadata/provider.ex | 3 ++ 3 files changed, 79 insertions(+), 73 deletions(-) create mode 100644 lib/pleroma/web/metadata/opengraph.ex create mode 100644 lib/pleroma/web/metadata/provider.ex (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index f8906e03f..cf2b86aaa 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -1,65 +1,18 @@ defmodule Pleroma.Web.Metadata do alias Phoenix.HTML - alias Pleroma.{Formatter, User} - alias Pleroma.Web.MediaProxy + @parsers Pleroma.Config.get([:metadata, :providers], []) def build_tags(params) do - if(meta_enabled?(:opengraph), do: opengraph_tags(params), else: []) - |> Enum.map(&to_tag/1) - |> Enum.map(&HTML.safe_to_string/1) - |> Enum.join() - end - - def meta_enabled?(type) do - Pleroma.Config.get([:metadata, type], false) - end - - # opengraph for single status - defp opengraph_tags(%{activity: activity, user: user}) do - with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do - [ - {:meta, - [ - property: "og:title", - content: - "#{user.name}" <> - if user.local do - "(@#{user.nickname}@{pleroma_domain})" - else - "(@#{user.nickname})" - end - ], []}, - {:meta, [property: "og:url", content: activity.data["id"]], []}, - {:meta, [property: "og:description", content: truncated_content], []}, - {:meta, [property: "og:image", content: user_avatar_url(user)], []}, - {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []}, - {:meta, [property: "twitter:card", content: "summary"], []} - ] - end - end + Enum.reduce(@parsers, "", fn parser, acc -> + rendered_html = + params + |> parser.build_tags() + |> Enum.map(&to_tag/1) + |> Enum.map(&HTML.safe_to_string/1) + |> Enum.join() - # opengraph for user card - defp opengraph_tags(%{user: user}) do - with truncated_bio = scrub_html_and_truncate(user.bio || "") do - [ - {:meta, - [ - property: "og:title", - content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) profile" - ], []}, - {:meta, [property: "og:url", content: User.profile_url(user)], []}, - {:meta, [property: "og:description", content: truncated_bio], []}, - {:meta, [property: "og:image", content: user_avatar_url(user)], []}, - {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []}, - {:meta, [property: "twitter:card", content: "summary"], []} - ] - end - end - - defp opengraph_tags(_) do - [] + acc <> rendered_html + end) end def to_tag(data) do @@ -73,20 +26,4 @@ defmodule Pleroma.Web.Metadata do raise ArgumentError, message: "make_tag invalid args" end end - - defp scrub_html_and_truncate(content) do - content - # html content comes from DB already encoded, decode first and scrub after - |> HtmlEntities.decode() - |> Pleroma.HTML.strip_tags() - |> Formatter.truncate() - end - - defp user_avatar_url(user) do - User.avatar_url(user) |> MediaProxy.url() - end - - def pleroma_domain do - Pleroma.Web.Endpoint.host() - end end diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex new file mode 100644 index 000000000..5f8bed2fb --- /dev/null +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -0,0 +1,66 @@ +defmodule Pleroma.Web.Metadata.Providers.OpenGraph do + alias Pleroma.Web.Metadata.Providers.Provider + alias Pleroma.{HTML, Formatter, User} + alias Pleroma.Web.MediaProxy + + @behaviour Provider + + @impl Provider + def build_tags(%{activity: activity, user: user}) do + with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do + [ + {:meta, + [ + property: "og:title", + content: user_name_string(user) + ], []}, + {:meta, [property: "og:url", content: activity.data["id"]], []}, + {:meta, [property: "og:description", content: truncated_content], []}, + {:meta, [property: "og:image", content: user_avatar_url(user)], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []}, + {:meta, [property: "twitter:card", content: "summary"], []} + ] + end + end + + @impl Provider + def build_tags(%{user: user}) do + with truncated_bio = scrub_html_and_truncate(user.bio || "") do + [ + {:meta, + [ + property: "og:title", + content: user_name_string(user) + ], []}, + {:meta, [property: "og:url", content: User.profile_url(user)], []}, + {:meta, [property: "og:description", content: truncated_bio], []}, + {:meta, [property: "og:image", content: user_avatar_url(user)], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []}, + {:meta, [property: "twitter:card", content: "summary"], []} + ] + end + end + + defp scrub_html_and_truncate(content) do + content + # html content comes from DB already encoded, decode first and scrub after + |> HtmlEntities.decode() + |> HTML.strip_tags() + |> Formatter.truncate() + end + + defp user_avatar_url(user) do + User.avatar_url(user) |> MediaProxy.url() + end + + defp user_name_string(user) do + "#{user.name}" <> + if user.local do + "(@#{user.nickname}@#{Pleroma.Web.Endpoint.host()})" + else + "(@#{user.nickname})" + end + end +end diff --git a/lib/pleroma/web/metadata/provider.ex b/lib/pleroma/web/metadata/provider.ex new file mode 100644 index 000000000..f64810fad --- /dev/null +++ b/lib/pleroma/web/metadata/provider.ex @@ -0,0 +1,3 @@ +defmodule Pleroma.Web.Metadata.Providers.Provider do + @callback build_tags(map()) :: list() +end -- cgit v1.2.3 From ff6c9a5c961647b64c3c9fcc05932093595e9588 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 20:00:21 +0300 Subject: Introduce get_by_id in Activity, replace newlines with spaces --- lib/pleroma/activity.ex | 5 ++++- lib/pleroma/web/metadata/opengraph.ex | 1 + lib/pleroma/web/ostatus/ostatus_controller.ex | 3 +-- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 353f9f6cd..47562306d 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -35,7 +35,10 @@ defmodule Pleroma.Activity do ) ) end - + + def get_by_id(id) do + Repo.get(Activity, id) + end # TODO: # Go through these and fix them everywhere. # Wrong name, only returns create activities diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 5f8bed2fb..6d86c0ee6 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -47,6 +47,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do content # html content comes from DB already encoded, decode first and scrub after |> HtmlEntities.decode() + |> String.replace(~r//, " ") |> HTML.strip_tags() |> Formatter.truncate() end diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index be648a6ee..2a47519d1 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -7,7 +7,6 @@ defmodule Pleroma.Web.OStatus.OStatusController do alias Pleroma.{User, Activity, Object} alias Pleroma.Web.OStatus.{FeedRepresenter, ActivityRepresenter} - alias Pleroma.Repo alias Pleroma.Web.{OStatus, Federator} alias Pleroma.Web.XML alias Pleroma.Web.ActivityPub.ObjectView @@ -141,7 +140,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do end def notice(conn, %{"id" => id}) do - with {_, %Activity{} = activity} <- {:activity, Repo.get(Activity, id)}, + with {_, %Activity{} = activity} <- {:activity, Activity.get_by_id(id)}, {_, true} <- {:public?, ActivityPub.is_public?(activity)}, %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do case format = get_format(conn) do -- cgit v1.2.3 From 17da432dbbf5f5f9afc09e6b92ec51a368c30abb Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 15 Jan 2019 18:00:20 +0000 Subject: websub: improve error handling --- lib/pleroma/web/websub/websub.ex | 6 ++++++ lib/pleroma/web/websub/websub_controller.ex | 7 +++++++ 2 files changed, 13 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 3a287edd9..7ca62c83b 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -121,6 +121,12 @@ defmodule Pleroma.Web.Websub do end end + def incoming_subscription_request(user, params) do + Logger.info("Unhandled WebSub request for #{user.nickname}: #{inspect(params)}") + + {:error, "Invalid WebSub request"} + end + defp get_subscription(topic, callback) do Repo.get_by(WebsubServerSubscription, topic: topic, callback: callback) || %WebsubServerSubscription{} diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex index 27304d988..e58f144e5 100644 --- a/lib/pleroma/web/websub/websub_controller.ex +++ b/lib/pleroma/web/websub/websub_controller.ex @@ -67,6 +67,13 @@ defmodule Pleroma.Web.Websub.WebsubController do end end + def websub_subscription_confirmation(conn, params) do + Logger.info("Invalid WebSub confirmation request: #{inspect(params)}") + + conn + |> send_resp(500, "Invalid parameters") + end + def websub_incoming(conn, %{"id" => id}) do with "sha1=" <> signature <- hd(get_req_header(conn, "x-hub-signature")), signature <- String.downcase(signature), -- cgit v1.2.3 From 410fd9d774fb3437a38adfe405ff45d4950b51a9 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 21:17:56 +0300 Subject: Attach attachments --- lib/pleroma/activity.ex | 3 ++- lib/pleroma/web/metadata/opengraph.ex | 36 ++++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 47562306d..8fd0311d2 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -35,10 +35,11 @@ defmodule Pleroma.Activity do ) ) end - + def get_by_id(id) do Repo.get(Activity, id) end + # TODO: # Go through these and fix them everywhere. # Wrong name, only returns create activities diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 6d86c0ee6..2eac04ae7 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -8,6 +8,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do @impl Provider def build_tags(%{activity: activity, user: user}) do with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do + attachments = build_attachments(activity) [ {:meta, [ @@ -16,11 +17,11 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do ], []}, {:meta, [property: "og:url", content: activity.data["id"]], []}, {:meta, [property: "og:description", content: truncated_content], []}, - {:meta, [property: "og:image", content: user_avatar_url(user)], []}, - {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []}, {:meta, [property: "twitter:card", content: "summary"], []} - ] + ] ++ if attachments == [] do [ + {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []} ] else attachments end end end @@ -35,7 +36,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do ], []}, {:meta, [property: "og:url", content: User.profile_url(user)], []}, {:meta, [property: "og:description", content: truncated_bio], []}, - {:meta, [property: "og:image", content: user_avatar_url(user)], []}, + {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, {:meta, [property: "og:image:width", content: 120], []}, {:meta, [property: "og:image:height", content: 120], []}, {:meta, [property: "twitter:card", content: "summary"], []} @@ -43,6 +44,27 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do end end + defp build_attachments(activity) do + Enum.reduce(activity.data["object"]["attachment"], [], fn attachment, acc -> + rendered_tags = + Enum.map(attachment["url"], fn url -> + media_type = + Enum.find(["image", "audio", "video"], fn media_type -> + String.starts_with?(url["mediaType"], media_type) + end) + + if media_type do + {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []} + else + nil + end + end) + + Enum.reject(rendered_tags, &is_nil/1) + acc ++ rendered_tags + end) + end + defp scrub_html_and_truncate(content) do content # html content comes from DB already encoded, decode first and scrub after @@ -52,8 +74,8 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do |> Formatter.truncate() end - defp user_avatar_url(user) do - User.avatar_url(user) |> MediaProxy.url() + defp attachment_url(url) do + MediaProxy.url(url) end defp user_name_string(user) do -- cgit v1.2.3 From e8eecd61b4714406501fa0c5335ba53e19ee0bae Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 21:20:27 +0300 Subject: Formating --- lib/pleroma/web/metadata/opengraph.ex | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 2eac04ae7..be7b155d5 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -9,6 +9,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do def build_tags(%{activity: activity, user: user}) do with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do attachments = build_attachments(activity) + [ {:meta, [ @@ -18,10 +19,16 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do {:meta, [property: "og:url", content: activity.data["id"]], []}, {:meta, [property: "og:description", content: truncated_content], []}, {:meta, [property: "twitter:card", content: "summary"], []} - ] ++ if attachments == [] do [ - {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, - {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []} ] else attachments end + ] ++ + if attachments == [] do + [ + {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []} + ] + else + attachments + end end end -- cgit v1.2.3 From 70f140681f90d92169b9774ad048100a003fd5a0 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 21:47:45 +0300 Subject: Add space between name and nickname --- lib/pleroma/web/metadata/opengraph.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index be7b155d5..8046c13ba 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -86,7 +86,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do end defp user_name_string(user) do - "#{user.name}" <> + "#{user.name} " <> if user.local do "(@#{user.nickname}@#{Pleroma.Web.Endpoint.host()})" else -- cgit v1.2.3 From 2d3241753f57ef1364370128dbf0c6489e978b41 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 15 Jan 2019 19:31:13 +0000 Subject: http: add support for query parameters, use Jason for JSON encoding instead of Poison like everywhere else --- lib/pleroma/http/http.ex | 3 +++ lib/pleroma/http/request_builder.ex | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/http/http.ex b/lib/pleroma/http/http.ex index b8103cef6..75c58e6c9 100644 --- a/lib/pleroma/http/http.ex +++ b/lib/pleroma/http/http.ex @@ -31,12 +31,15 @@ defmodule Pleroma.HTTP do process_request_options(options) |> process_sni_options(url) + params = Keyword.get(options, :params, []) + %{} |> Builder.method(method) |> Builder.headers(headers) |> Builder.opts(options) |> Builder.url(url) |> Builder.add_param(:body, :body, body) + |> Builder.add_param(:query, :query, params) |> Enum.into([]) |> (&Tesla.request(Connection.new(), &1)).() end diff --git a/lib/pleroma/http/request_builder.ex b/lib/pleroma/http/request_builder.ex index bffc7c6fe..5f2cff2c0 100644 --- a/lib/pleroma/http/request_builder.ex +++ b/lib/pleroma/http/request_builder.ex @@ -100,6 +100,8 @@ defmodule Pleroma.HTTP.RequestBuilder do Map """ @spec add_param(map(), atom, atom, any()) :: map() + def add_param(request, :query, :query, values), do: Map.put(request, :query, values) + def add_param(request, :body, :body, value), do: Map.put(request, :body, value) def add_param(request, :body, key, value) do @@ -107,7 +109,10 @@ defmodule Pleroma.HTTP.RequestBuilder do |> Map.put_new_lazy(:body, &Tesla.Multipart.new/0) |> Map.update!( :body, - &Tesla.Multipart.add_field(&1, key, Poison.encode!(value), + &Tesla.Multipart.add_field( + &1, + key, + Jason.encode!(value), headers: [{:"Content-Type", "application/json"}] ) ) -- cgit v1.2.3 From 2e630bea0da6452d3342a335da3ca642dc61c1b3 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 23:00:22 +0300 Subject: Add twitter card, filter nsfw --- lib/pleroma/web/metadata/opengraph.ex | 8 +++---- lib/pleroma/web/metadata/twitter_card.ex | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 lib/pleroma/web/metadata/twitter_card.ex (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 8046c13ba..fcc960311 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -17,10 +17,9 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do content: user_name_string(user) ], []}, {:meta, [property: "og:url", content: activity.data["id"]], []}, - {:meta, [property: "og:description", content: truncated_content], []}, - {:meta, [property: "twitter:card", content: "summary"], []} + {:meta, [property: "og:description", content: truncated_content], []} ] ++ - if attachments == [] do + if attachments == [] or Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) do [ {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, {:meta, [property: "og:image:width", content: 120], []}, @@ -45,8 +44,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do {:meta, [property: "og:description", content: truncated_bio], []}, {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []}, - {:meta, [property: "twitter:card", content: "summary"], []} + {:meta, [property: "og:image:height", content: 120], []} ] end end diff --git a/lib/pleroma/web/metadata/twitter_card.ex b/lib/pleroma/web/metadata/twitter_card.ex new file mode 100644 index 000000000..6424f84b3 --- /dev/null +++ b/lib/pleroma/web/metadata/twitter_card.ex @@ -0,0 +1,36 @@ +defmodule Pleroma.Web.Metadata.Providers.TwitterCard do + def build_tags(%{activity: activity}) do + if Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) or + activity.data["object"]["attachment"] == [] do + build_tags(nil) + else + case find_first_acceptable_media_type(activity) do + "image" -> + [{:meta, [property: "twitter:card", content: "summary_large_image"], []}] + + "audio" -> + [{:meta, [property: "twitter:card", content: "player"], []}] + + "video" -> + [{:meta, [property: "twitter:card", content: "player"], []}] + + _ -> + build_tags(nil) + end + end + end + + def build_tags(_) do + [{:meta, [property: "twitter:card", content: "summary"], []}] + end + + def find_first_acceptable_media_type(%{data: %{"object" => %{"attachment" => attachment}}}) do + Enum.find_value(attachment, fn attachment -> + Enum.find_value(attachment["url"], fn url -> + Enum.find(["image", "audio", "video"], fn media_type -> + String.starts_with?(url["mediaType"], media_type) + end) + end) + end) + end +end -- cgit v1.2.3 From 9aa69e12b87a892d33d1bf4f0d556752391b465a Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 23:25:28 +0300 Subject: Add behaviours to TwitterCard, remove some dumb stuff in Formatter.truncate --- lib/pleroma/formatter.ex | 21 ++++++--------------- lib/pleroma/web/metadata/opengraph.ex | 3 ++- lib/pleroma/web/metadata/twitter_card.ex | 6 ++++++ 3 files changed, 14 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 49f7075e6..63e0acb21 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -184,21 +184,12 @@ defmodule Pleroma.Formatter do end) end - def truncate(text, opts \\ []) do - max_length = opts[:max_length] || 200 - omission = opts[:omission] || "..." - - cond do - not String.valid?(text) -> - text - - String.length(text) < max_length -> - text - - true -> - length_with_omission = max_length - String.length(omission) - - "#{String.slice(text, 0, length_with_omission)}#{omission}" + def truncate(text, max_length \\ 200, omission \\ "...") do + if String.length(text) < max_length do + text + else + length_with_omission = max_length - String.length(omission) + String.slice(text, 0, length_with_omission) <> omission end end end diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index fcc960311..1e3af947d 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -19,7 +19,8 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do {:meta, [property: "og:url", content: activity.data["id"]], []}, {:meta, [property: "og:description", content: truncated_content], []} ] ++ - if attachments == [] or Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) do + if attachments == [] or + Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) do [ {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, {:meta, [property: "og:image:width", content: 120], []}, diff --git a/lib/pleroma/web/metadata/twitter_card.ex b/lib/pleroma/web/metadata/twitter_card.ex index 6424f84b3..3094e61fd 100644 --- a/lib/pleroma/web/metadata/twitter_card.ex +++ b/lib/pleroma/web/metadata/twitter_card.ex @@ -1,4 +1,9 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do + alias Pleroma.Web.Metadata.Providers.Provider + + @behaviour Provider + + @impl Provider def build_tags(%{activity: activity}) do if Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) or activity.data["object"]["attachment"] == [] do @@ -20,6 +25,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do end end + @impl Provider def build_tags(_) do [{:meta, [property: "twitter:card", content: "summary"], []}] end -- cgit v1.2.3 From 565caff3f4f8b21b4bae9fb20732688389b4d829 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 00:07:28 +0300 Subject: cache HTML in OGP --- lib/pleroma/web/metadata/opengraph.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 1e3af947d..33ff075c6 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -7,7 +7,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do @impl Provider def build_tags(%{activity: activity, user: user}) do - with truncated_content = scrub_html_and_truncate(activity.data["object"]["content"]) do + with truncated_content = scrub_html_and_truncate(activity) do attachments = build_attachments(activity) [ @@ -71,6 +71,15 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do end) end + defp scrub_html_and_truncate(%{data: %{ "object" => %{ "content" => content}}} = activity) do + content + # html content comes from DB already encoded, decode first and scrub after + |> HtmlEntities.decode() + |> String.replace(~r//, " ") + |> HTML.get_cached_stripped_html_for_object(activity, __MODULE__) + |> Formatter.truncate() + end + defp scrub_html_and_truncate(content) do content # html content comes from DB already encoded, decode first and scrub after @@ -79,7 +88,6 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do |> HTML.strip_tags() |> Formatter.truncate() end - defp attachment_url(url) do MediaProxy.url(url) end -- cgit v1.2.3 From 1ddab78247c541eb3895042a40a2ffcbcc2d751f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 16 Jan 2019 03:48:43 +0000 Subject: html: allow microformats-related markup through the html filter --- lib/pleroma/html.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 0c5b0f03f..f5c6e5033 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -78,14 +78,14 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do # links Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes) - Meta.allow_tag_with_these_attributes("a", ["name", "title"]) + Meta.allow_tag_with_these_attributes("a", ["name", "title", "class"]) # paragraphs and linebreaks Meta.allow_tag_with_these_attributes("br", []) Meta.allow_tag_with_these_attributes("p", []) # microformats - Meta.allow_tag_with_these_attributes("span", []) + Meta.allow_tag_with_these_attributes("span", ["class"]) # allow inline images for custom emoji @allow_inline_images Keyword.get(@markup, :allow_inline_images) @@ -119,7 +119,7 @@ defmodule Pleroma.HTML.Scrubber.Default do Meta.strip_comments() Meta.allow_tag_with_uri_attributes("a", ["href", "data-user", "data-tag"], @valid_schemes) - Meta.allow_tag_with_these_attributes("a", ["name", "title"]) + Meta.allow_tag_with_these_attributes("a", ["name", "title", "class"]) Meta.allow_tag_with_these_attributes("abbr", ["title"]) @@ -134,7 +134,7 @@ defmodule Pleroma.HTML.Scrubber.Default do Meta.allow_tag_with_these_attributes("ol", []) Meta.allow_tag_with_these_attributes("p", []) Meta.allow_tag_with_these_attributes("pre", []) - Meta.allow_tag_with_these_attributes("span", []) + Meta.allow_tag_with_these_attributes("span", ["class"]) Meta.allow_tag_with_these_attributes("strong", []) Meta.allow_tag_with_these_attributes("u", []) Meta.allow_tag_with_these_attributes("ul", []) -- cgit v1.2.3 From 461ab9489db63d375f0d604ad9288e8e916d0beb Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 16 Jan 2019 03:53:36 +0000 Subject: formatter: improve microformats markup --- lib/pleroma/formatter.ex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index d80ae6576..4149265a2 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -145,7 +145,9 @@ defmodule Pleroma.Formatter do short_match = String.split(match, "@") |> tl() |> hd() {uuid, - "@#{short_match}"} + "@#{ + short_match + }"} end) {subs, uuid_text} @@ -168,7 +170,7 @@ defmodule Pleroma.Formatter do subs ++ Enum.map(tags, fn {tag_text, tag, uuid} -> url = - "" -- cgit v1.2.3 From dd1432d6955a72b8483717978d61a505e0608bbc Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 09:42:24 +0300 Subject: Disable previews for any activity, but create --- lib/pleroma/web/metadata/opengraph.ex | 5 +++-- lib/pleroma/web/ostatus/ostatus_controller.ex | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 33ff075c6..b15856974 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -71,7 +71,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do end) end - defp scrub_html_and_truncate(%{data: %{ "object" => %{ "content" => content}}} = activity) do + defp scrub_html_and_truncate(%{data: %{"object" => %{"content" => content}}} = activity) do content # html content comes from DB already encoded, decode first and scrub after |> HtmlEntities.decode() @@ -80,7 +80,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do |> Formatter.truncate() end - defp scrub_html_and_truncate(content) do + defp scrub_html_and_truncate(content) when is_binary(content) do content # html content comes from DB already encoded, decode first and scrub after |> HtmlEntities.decode() @@ -88,6 +88,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do |> HTML.strip_tags() |> Formatter.truncate() end + defp attachment_url(url) do MediaProxy.url(url) end diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 2a47519d1..f7ba57389 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -145,7 +145,15 @@ defmodule Pleroma.Web.OStatus.OStatusController do %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do case format = get_format(conn) do "html" -> - Fallback.RedirectController.redirector_with_meta(conn, %{activity: activity, user: user}) + # Only Create actvities have a map at object + if is_map(activity.data["object"]) do + Fallback.RedirectController.redirector_with_meta(conn, %{ + activity: activity, + user: user + }) + else + Fallback.RedirectController.redirector(conn, nil) + end _ -> represent_activity(conn, format, activity, user) -- cgit v1.2.3 From 70b2bb6eded5597bd768d7dc8754c2c994561aee Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 10:26:01 +0300 Subject: add caching --- lib/pleroma/application.ex | 11 +++++++++++ lib/pleroma/web/metadata.ex | 10 ++++++++++ lib/pleroma/web/router.ex | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index ad2797209..5f9518914 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -84,6 +84,17 @@ defmodule Pleroma.Application do ], id: :cachex_scrubber ), + worker( + Cachex, + [ + :metadata_cache, + [ + limit: 2500, + default_ttl: :timer.minutes(15) + ] + ], + id: :cachex_metadata + ), worker( Cachex, [ diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index cf2b86aaa..a5a706b8f 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -2,6 +2,16 @@ defmodule Pleroma.Web.Metadata do alias Phoenix.HTML @parsers Pleroma.Config.get([:metadata, :providers], []) + + def get_cached_tags(params) do + # I am unsure how well ETS works with big keys + key = :erlang.term_to_binary(params) + + Cachex.fetch!(:metadata_cache, key, fn _key -> + {:commit, build_tags(params)} + end) + end + def build_tags(params) do Enum.reduce(@parsers, "", fn parser, acc -> rendered_html = diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 25e866c48..1ecd4aee1 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -534,7 +534,7 @@ defmodule Fallback.RedirectController do def redirector_with_meta(conn, params) do {:ok, index_content} = File.read(index_file_path()) - tags = Metadata.build_tags(params) + tags = Metadata.get_cached_tags(params) response = String.replace(index_content, "", tags) conn -- cgit v1.2.3 From 0039d45b5b695a28660dd56ff74fa45414c92e47 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 10:30:47 +0300 Subject: No need to use activity in the key --- lib/pleroma/web/metadata.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index a5a706b8f..890367152 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -3,9 +3,10 @@ defmodule Pleroma.Web.Metadata do @parsers Pleroma.Config.get([:metadata, :providers], []) - def get_cached_tags(params) do + def get_cached_tags(%{user: user} = params) do # I am unsure how well ETS works with big keys - key = :erlang.term_to_binary(params) + # We don't need to use the both activity and a user since the object can't change it's content + key = :erlang.term_to_binary(user) Cachex.fetch!(:metadata_cache, key, fn _key -> {:commit, build_tags(params)} -- cgit v1.2.3 From a76793006bb64723b4fe0aa054765edadc65905c Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 10:35:06 +0300 Subject: Thanks you rinpatch, very cool --- lib/pleroma/web/metadata.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index 890367152..bc0f3beed 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -2,10 +2,17 @@ defmodule Pleroma.Web.Metadata do alias Phoenix.HTML @parsers Pleroma.Config.get([:metadata, :providers], []) + def get_cached_tags(%{activity: activity, user: user} = params) do + # We don't need to use the both activity and a user since the object can't change it's content + key = "#{:erlang.term_to_binary(user)}#{activity.data["id"]}" + + Cachex.fetch!(:metadata_cache, key, fn _key -> + {:commit, build_tags(params)} + end) + end def get_cached_tags(%{user: user} = params) do # I am unsure how well ETS works with big keys - # We don't need to use the both activity and a user since the object can't change it's content key = :erlang.term_to_binary(user) Cachex.fetch!(:metadata_cache, key, fn _key -> -- cgit v1.2.3 From a9c27e137d992c991827417af40fe49fafa34be2 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 10:38:42 +0300 Subject: Add a fallback function to handle generic params, just in case --- lib/pleroma/web/metadata.ex | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index bc0f3beed..23f152e06 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -20,6 +20,14 @@ defmodule Pleroma.Web.Metadata do end) end + def get_cached_tags(params) do + key = :erlang.term_to_binary(params) + + Cachex.fetch!(:metadata_cache, key, fn _key -> + {:commit, build_tags(params)} + end) + end + def build_tags(params) do Enum.reduce(@parsers, "", fn parser, acc -> rendered_html = -- cgit v1.2.3 From 0bc6d30f7dfe53be588329e48f1255b5eef18a2a Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 16 Jan 2019 10:44:32 +0300 Subject: [#477] Minor refactoring (user search query). --- lib/pleroma/user.ex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 2488697bb..8ae36416a 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -702,12 +702,14 @@ defmodule Pleroma.User do fragment( """ ts_rank_cd( - setweight(to_tsvector('simple', regexp_replace(nickname, '\\W', ' ', 'g')), 'A') || - setweight(to_tsvector('simple', regexp_replace(coalesce(name, ''), '\\W', ' ', 'g')), 'B'), + setweight(to_tsvector('simple', regexp_replace(?, '\\W', ' ', 'g')), 'A') || + setweight(to_tsvector('simple', regexp_replace(coalesce(?, ''), '\\W', ' ', 'g')), 'B'), to_tsquery('simple', ?), 32 ) """, + u.nickname, + u.name, ^processed_query ) }, -- cgit v1.2.3 From bfe2a11a6b64b868d18727359b83edc51ce5bb80 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 10:45:56 +0300 Subject: Add config doc --- lib/pleroma/web/metadata.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index 23f152e06..ddc74fb0d 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -1,7 +1,7 @@ defmodule Pleroma.Web.Metadata do alias Phoenix.HTML - @parsers Pleroma.Config.get([:metadata, :providers], []) + @providers Pleroma.Config.get([__MODULE__, :providers], []) def get_cached_tags(%{activity: activity, user: user} = params) do # We don't need to use the both activity and a user since the object can't change it's content key = "#{:erlang.term_to_binary(user)}#{activity.data["id"]}" @@ -29,7 +29,7 @@ defmodule Pleroma.Web.Metadata do end def build_tags(params) do - Enum.reduce(@parsers, "", fn parser, acc -> + Enum.reduce(@providers, "", fn parser, acc -> rendered_html = params |> parser.build_tags() -- cgit v1.2.3 From 90433b988e4d9519e0d2368452aefdb0dc565b52 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 16 Jan 2019 11:07:46 +0300 Subject: [#518] Fixed /api/v1/instance ("domain_count" value) and /api/v1/instance/peers responses. --- lib/pleroma/stats.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/stats.ex b/lib/pleroma/stats.ex index 8a030ecd0..65a6d58b5 100644 --- a/lib/pleroma/stats.ex +++ b/lib/pleroma/stats.ex @@ -34,10 +34,11 @@ defmodule Pleroma.Stats do peers = from( u in Pleroma.User, - select: fragment("distinct ?->'host'", u.info), + select: fragment("distinct split_part(?, '@', 2)", u.nickname), where: u.local != ^true ) |> Repo.all() + |> Enum.filter(& &1) domain_count = Enum.count(peers) -- cgit v1.2.3 From ff01fd3c4fe1edb45098a7730b97b9424b1222cc Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 11:18:25 +0300 Subject: Remove caching because it does not affect performance and may be even worse in some cases --- lib/pleroma/web/metadata.ex | 25 ------------------------- lib/pleroma/web/router.ex | 2 +- 2 files changed, 1 insertion(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index ddc74fb0d..d859dfd8b 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -2,31 +2,6 @@ defmodule Pleroma.Web.Metadata do alias Phoenix.HTML @providers Pleroma.Config.get([__MODULE__, :providers], []) - def get_cached_tags(%{activity: activity, user: user} = params) do - # We don't need to use the both activity and a user since the object can't change it's content - key = "#{:erlang.term_to_binary(user)}#{activity.data["id"]}" - - Cachex.fetch!(:metadata_cache, key, fn _key -> - {:commit, build_tags(params)} - end) - end - - def get_cached_tags(%{user: user} = params) do - # I am unsure how well ETS works with big keys - key = :erlang.term_to_binary(user) - - Cachex.fetch!(:metadata_cache, key, fn _key -> - {:commit, build_tags(params)} - end) - end - - def get_cached_tags(params) do - key = :erlang.term_to_binary(params) - - Cachex.fetch!(:metadata_cache, key, fn _key -> - {:commit, build_tags(params)} - end) - end def build_tags(params) do Enum.reduce(@providers, "", fn parser, acc -> diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 1ecd4aee1..25e866c48 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -534,7 +534,7 @@ defmodule Fallback.RedirectController do def redirector_with_meta(conn, params) do {:ok, index_content} = File.read(index_file_path()) - tags = Metadata.get_cached_tags(params) + tags = Metadata.build_tags(params) response = String.replace(index_content, "", tags) conn -- cgit v1.2.3 From b44995866ba49d2c9ea53082deadb6b72acf53e3 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 16:52:01 +0300 Subject: Replace map with reduce to remove nils --- lib/pleroma/web/metadata/opengraph.ex | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index b15856974..f6a1f3023 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -50,23 +50,25 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do end end - defp build_attachments(activity) do - Enum.reduce(activity.data["object"]["attachment"], [], fn attachment, acc -> + defp build_attachments(%{data: %{"object" => %{"attachment" => attachments}}} = _activity) do + Enum.reduce(attachments, [], fn attachment, acc -> rendered_tags = - Enum.map(attachment["url"], fn url -> + Enum.reduce(attachment["url"], [], fn url, acc -> media_type = Enum.find(["image", "audio", "video"], fn media_type -> String.starts_with?(url["mediaType"], media_type) end) if media_type do - {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []} + [ + {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []} + | acc + ] else - nil + acc end end) - Enum.reject(rendered_tags, &is_nil/1) acc ++ rendered_tags end) end -- cgit v1.2.3 From 943324b66158d1bd2449894ec41bc544c56058a7 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 16 Jan 2019 15:13:09 +0100 Subject: MastoAPI: Don't break on missing users. --- lib/pleroma/user.ex | 10 ++++++++++ lib/pleroma/web/mastodon_api/views/status_view.ex | 19 ++++++++++++++++--- lib/pleroma/web/twitter_api/views/activity_view.ex | 12 +----------- 3 files changed, 27 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 681280539..a52e536d3 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1040,4 +1040,14 @@ defmodule Pleroma.User do @strict_local_nickname_regex end end + + def error_user(ap_id) do + %User{ + name: ap_id, + ap_id: ap_id, + info: %User.Info{}, + nickname: "erroruser@example.com", + inserted_at: NaiveDateTime.utc_now() + } + end end diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index db543ffe5..7f5a52ea3 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -32,6 +32,19 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do end) end + defp get_user(ap_id) do + cond do + user = User.get_cached_by_ap_id(ap_id) -> + user + + user = User.get_by_guessed_nickname(ap_id) -> + user + + true -> + User.error_user(ap_id) + end + end + def render("index.json", opts) do replied_to_activities = get_replied_to_activities(opts.activities) @@ -48,7 +61,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do "status.json", %{activity: %{data: %{"type" => "Announce", "object" => object}} = activity} = opts ) do - user = User.get_cached_by_ap_id(activity.data["actor"]) + user = get_user(activity.data["actor"]) created_at = Utils.to_masto_date(activity.data["published"]) reblogged = Activity.get_create_activity_by_object_ap_id(object) @@ -93,7 +106,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do end def render("status.json", %{activity: %{data: %{"object" => object}} = activity} = opts) do - user = User.get_cached_by_ap_id(activity.data["actor"]) + user = get_user(activity.data["actor"]) like_count = object["like_count"] || 0 announcement_count = object["announcement_count"] || 0 @@ -116,7 +129,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do created_at = Utils.to_masto_date(object["published"]) reply_to = get_reply_to(activity, opts) - reply_to_user = reply_to && User.get_cached_by_ap_id(reply_to.data["actor"]) + reply_to_user = reply_to && get_user(reply_to.data["actor"]) content = object diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 108e7bfc5..03708d84c 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -101,20 +101,10 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do user true -> - error_user(ap_id) + User.error_user(ap_id) end end - defp error_user(ap_id) do - %User{ - name: ap_id, - ap_id: ap_id, - info: %User.Info{}, - nickname: "erroruser@example.com", - inserted_at: NaiveDateTime.utc_now() - } - end - def render("index.json", opts) do context_ids = collect_context_ids(opts.activities) users = collect_users(opts.activities) -- cgit v1.2.3 From 293f6a8b712246d0580f9eb113c798ae1ea3b634 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 17:15:13 +0300 Subject: join us now and share the software~. Also tests --- lib/pleroma/web/metadata.ex | 3 +++ lib/pleroma/web/metadata/opengraph.ex | 3 +++ lib/pleroma/web/metadata/provider.ex | 3 +++ lib/pleroma/web/metadata/twitter_card.ex | 3 +++ 4 files changed, 12 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index d859dfd8b..8793fc265 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -1,3 +1,6 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata do alias Phoenix.HTML diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index f6a1f3023..b7c5dc64e 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -1,3 +1,6 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.OpenGraph do alias Pleroma.Web.Metadata.Providers.Provider alias Pleroma.{HTML, Formatter, User} diff --git a/lib/pleroma/web/metadata/provider.ex b/lib/pleroma/web/metadata/provider.ex index f64810fad..a39008bcc 100644 --- a/lib/pleroma/web/metadata/provider.ex +++ b/lib/pleroma/web/metadata/provider.ex @@ -1,3 +1,6 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.Provider do @callback build_tags(map()) :: list() end diff --git a/lib/pleroma/web/metadata/twitter_card.ex b/lib/pleroma/web/metadata/twitter_card.ex index 3094e61fd..853776611 100644 --- a/lib/pleroma/web/metadata/twitter_card.ex +++ b/lib/pleroma/web/metadata/twitter_card.ex @@ -1,3 +1,6 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.TwitterCard do alias Pleroma.Web.Metadata.Providers.Provider -- cgit v1.2.3 From 82cf9b97510acb261c805f098043471d9a588e2b Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 17:16:28 +0300 Subject: forgot to remove this thing --- lib/pleroma/application.ex | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 5f9518914..ad2797209 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -84,17 +84,6 @@ defmodule Pleroma.Application do ], id: :cachex_scrubber ), - worker( - Cachex, - [ - :metadata_cache, - [ - limit: 2500, - default_ttl: :timer.minutes(15) - ] - ], - id: :cachex_metadata - ), worker( Cachex, [ -- cgit v1.2.3 From 5a08dee37905c576da3289d7d69e9b114f202634 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 17:44:08 +0300 Subject: cache ap_id in id instead of caching user two times --- lib/pleroma/user.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 5707ba7a2..3becd545c 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -445,7 +445,15 @@ defmodule Pleroma.User do def get_cached_by_id(id) do key = "id:#{id}" - Cachex.fetch!(:user_cache, key, fn _ -> get_by_id(id) end) + + ap_id = + Cachex.fetch!(:user_cache, key, fn _ -> + user = get_by_id(id) + Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user) + {:commit, user.ap_id} + end) + + get_cached_by_ap_id(ap_id) end def get_cached_by_nickname(nickname) do -- cgit v1.2.3 From 8a9f089812295ef5087864e852ad9550ee00ce76 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 17:58:11 +0300 Subject: remove id cast --- lib/pleroma/user.ex | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 3becd545c..fdc552f75 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -462,19 +462,7 @@ defmodule Pleroma.User do end def get_cached_by_nickname_or_id(nickname_or_id) do - try do - # TODO: convert to UUIDs when !654 is merged - maybe_id = String.to_integer(nickname_or_id) - user = get_cached_by_id(maybe_id) - - if user == nil do - raise ArgumentError, message: "No such user id" - else - user - end - rescue - ArgumentError -> - get_cached_by_nickname(nickname_or_id) + get_cached_by_id(maybe_id) || get_cached_by_nickname(nickname_or_id) end end -- cgit v1.2.3 From 9a90b5d91a7a5a40d0e90d3112faea65b6e332ad Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 18:01:17 +0300 Subject: oof --- lib/pleroma/user.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index fdc552f75..96160094a 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -463,7 +463,6 @@ defmodule Pleroma.User do def get_cached_by_nickname_or_id(nickname_or_id) do get_cached_by_id(maybe_id) || get_cached_by_nickname(nickname_or_id) - end end def get_by_nickname(nickname) do -- cgit v1.2.3 From bb43f4cee94dfd6a71105fb31f10c4b0188a4bf2 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 18:02:46 +0300 Subject: Remove useless with in opengraph.ex --- lib/pleroma/user.ex | 2 +- lib/pleroma/web/metadata/opengraph.ex | 42 +++++++++++++++++------------------ 2 files changed, 21 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 96160094a..f6c0f36e4 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -462,7 +462,7 @@ defmodule Pleroma.User do end def get_cached_by_nickname_or_id(nickname_or_id) do - get_cached_by_id(maybe_id) || get_cached_by_nickname(nickname_or_id) + get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id) end def get_by_nickname(nickname) do diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index b7c5dc64e..6f88e9bb4 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -10,29 +10,27 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do @impl Provider def build_tags(%{activity: activity, user: user}) do - with truncated_content = scrub_html_and_truncate(activity) do - attachments = build_attachments(activity) + attachments = build_attachments(activity) - [ - {:meta, - [ - property: "og:title", - content: user_name_string(user) - ], []}, - {:meta, [property: "og:url", content: activity.data["id"]], []}, - {:meta, [property: "og:description", content: truncated_content], []} - ] ++ - if attachments == [] or - Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) do - [ - {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, - {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []} - ] - else - attachments - end - end + [ + {:meta, + [ + property: "og:title", + content: user_name_string(user) + ], []}, + {:meta, [property: "og:url", content: activity.data["id"]], []}, + {:meta, [property: "og:description", content: scrub_html_and_truncate(activity)], []} + ] ++ + if attachments == [] or + Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) do + [ + {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []} + ] + else + attachments + end end @impl Provider -- cgit v1.2.3 From 5fa508cc2be6a8e5b4d6522687708c6c269803a3 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 16 Jan 2019 18:04:41 +0300 Subject: Remove @providers and call Pleroma.config on runtime --- lib/pleroma/user.ex | 2 +- lib/pleroma/web/metadata.ex | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index f6c0f36e4..180ef180c 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -462,7 +462,7 @@ defmodule Pleroma.User do end def get_cached_by_nickname_or_id(nickname_or_id) do - get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id) + get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id) end def get_by_nickname(nickname) do diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index 8793fc265..2164b0fe8 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -4,10 +4,8 @@ defmodule Pleroma.Web.Metadata do alias Phoenix.HTML - @providers Pleroma.Config.get([__MODULE__, :providers], []) - def build_tags(params) do - Enum.reduce(@providers, "", fn parser, acc -> + Enum.reduce(Pleroma.Config.get([__MODULE__, :providers], []), "", fn parser, acc -> rendered_html = params |> parser.build_tags() -- cgit v1.2.3 From fd3a558230c48ee291b956f52e3b07492cbad36c Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 17 Jan 2019 09:18:46 +0300 Subject: Apply feld's patch --- lib/pleroma/web/metadata/opengraph.ex | 73 +++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 6f88e9bb4..f95e2442a 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.OpenGraph do alias Pleroma.Web.Metadata.Providers.Provider - alias Pleroma.{HTML, Formatter, User} + alias Pleroma.{HTML, Formatter, User, Web} alias Pleroma.Web.MediaProxy @behaviour Provider @@ -12,21 +12,39 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do def build_tags(%{activity: activity, user: user}) do attachments = build_attachments(activity) + # Most previews only show og:title which is inconvenient. Instagram + # hacks this by putting the description in the title and making the + # description longer prefixed by how many likes and shares the post + # has. Here we use the descriptive nickname in the title, and expand + # the full account & nickname in the description. We also use the cute^Wevil + # smart quotes around the status text like Instagram, too. [ {:meta, [ property: "og:title", - content: user_name_string(user) + content: + "#{user.name}: " <> + "“" <> + scrub_html_and_truncate(activity) <> + "”" ], []}, - {:meta, [property: "og:url", content: activity.data["id"]], []}, - {:meta, [property: "og:description", content: scrub_html_and_truncate(activity)], []} + {:meta, [property: "og:url", content: "#{Web.base_url()}/notice/#{activity.id}"], []}, + {:meta, + [ + property: "og:description", + content: + "#{user_name_string(user)}: " <> + "“" <> + scrub_html_and_truncate(activity) <> + "”" + ], []}, + {:meta, [property: "og:type", content: "website"], []} ] ++ - if attachments == [] or - Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) do + if attachments == [] do [ {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, - {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []} + {:meta, [property: "og:image:width", content: 150], []}, + {:meta, [property: "og:image:height", content: 150], []} ] else attachments @@ -44,9 +62,10 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do ], []}, {:meta, [property: "og:url", content: User.profile_url(user)], []}, {:meta, [property: "og:description", content: truncated_bio], []}, + {:meta, [property: "og:type", content: "website"], []}, {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, - {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []} + {:meta, [property: "og:image:width", content: 150], []}, + {:meta, [property: "og:image:height", content: 150], []} ] end end @@ -60,13 +79,33 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do String.starts_with?(url["mediaType"], media_type) end) - if media_type do - [ - {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []} - | acc - ] - else - acc + # TODO: Add additional properties to objects when we have the data available. + # Also, Whatsapp only wants JPEG or PNGs. It seems that if we add a second og:image + # object when a Video or GIF is attached it will display that in the Whatsapp Rich Preview. + case media_type do + "audio" -> + [ + {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []} + | acc + ] + + "image" -> + [ + {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], + []}, + {:meta, [property: "og:image:width", content: 150], []}, + {:meta, [property: "og:image:height", content: 150], []} + | acc + ] + + "video" -> + [ + {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []} + | acc + ] + + _ -> + acc end end) -- cgit v1.2.3 From 0256bd2f1dfb121a4d751906a202e3db482500a6 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 17 Jan 2019 10:34:19 +0300 Subject: Use object url instead of a hack --- lib/pleroma/web/metadata/opengraph.ex | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index f95e2442a..a48788969 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -3,13 +3,13 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.OpenGraph do alias Pleroma.Web.Metadata.Providers.Provider - alias Pleroma.{HTML, Formatter, User, Web} + alias Pleroma.{HTML, Formatter, User} alias Pleroma.Web.MediaProxy @behaviour Provider @impl Provider - def build_tags(%{activity: activity, user: user}) do + def build_tags(%{activity: %{data: %{"object" => %{"id" => object_id}}} = activity, user: user}) do attachments = build_attachments(activity) # Most previews only show og:title which is inconvenient. Instagram @@ -22,21 +22,13 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do {:meta, [ property: "og:title", - content: - "#{user.name}: " <> - "“" <> - scrub_html_and_truncate(activity) <> - "”" + content: "#{user.name}: " <> "“" <> scrub_html_and_truncate(activity) <> "”" ], []}, - {:meta, [property: "og:url", content: "#{Web.base_url()}/notice/#{activity.id}"], []}, + {:meta, [property: "og:url", content: object_id], []}, {:meta, [ property: "og:description", - content: - "#{user_name_string(user)}: " <> - "“" <> - scrub_html_and_truncate(activity) <> - "”" + content: "#{user_name_string(user)}: " <> "“" <> scrub_html_and_truncate(activity) <> "”" ], []}, {:meta, [property: "og:type", content: "website"], []} ] ++ -- cgit v1.2.3 From 4d5f15cd422abd3a2dce6f6022c75014c18c73cf Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 17 Jan 2019 11:00:02 +0300 Subject: Introduce optional unfurling of nsfw content --- lib/pleroma/web/metadata.ex | 8 ++++++++ lib/pleroma/web/metadata/opengraph.ex | 3 ++- lib/pleroma/web/metadata/twitter_card.ex | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index 2164b0fe8..be3c384ae 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -28,4 +28,12 @@ defmodule Pleroma.Web.Metadata do raise ArgumentError, message: "make_tag invalid args" end end + + def activity_nsfw?(%{data: %{"object" => %{"tag" => tags}}}) do + if(Pleroma.Config.get([__MODULE__, :unfurl_nsfw], false) == false) do + Enum.any?(tags, fn tag -> tag == "nsfw" end) + else + false + end + end end diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index a48788969..2f27a5300 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -3,6 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.OpenGraph do alias Pleroma.Web.Metadata.Providers.Provider + alias Pleroma.Web.Metadata alias Pleroma.{HTML, Formatter, User} alias Pleroma.Web.MediaProxy @@ -32,7 +33,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do ], []}, {:meta, [property: "og:type", content: "website"], []} ] ++ - if attachments == [] do + if attachments == [] or Metadata.activity_nsfw?(activity) do [ {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, {:meta, [property: "og:image:width", content: 150], []}, diff --git a/lib/pleroma/web/metadata/twitter_card.ex b/lib/pleroma/web/metadata/twitter_card.ex index 853776611..9a1245e59 100644 --- a/lib/pleroma/web/metadata/twitter_card.ex +++ b/lib/pleroma/web/metadata/twitter_card.ex @@ -3,13 +3,13 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.TwitterCard do alias Pleroma.Web.Metadata.Providers.Provider + alias Pleroma.Web.Metadata @behaviour Provider @impl Provider def build_tags(%{activity: activity}) do - if Enum.any?(activity.data["object"]["tag"], fn tag -> tag == "nsfw" end) or - activity.data["object"]["attachment"] == [] do + if Metadata.activity_nsfw?(activity) or activity.data["object"]["attachment"] == [] do build_tags(nil) else case find_first_acceptable_media_type(activity) do -- cgit v1.2.3 From 2bfae25a1ff735499e15cb431314503f34097a6b Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 17 Jan 2019 18:03:49 +0300 Subject: [#491] Made user bio preserve full nicknames (nick@host). --- lib/pleroma/formatter.ex | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 4149265a2..024c6e117 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -142,12 +142,11 @@ defmodule Pleroma.Formatter do ap_id end - short_match = String.split(match, "@") |> tl() |> hd() + full_match = String.trim_leading(match, "@") {uuid, - "@#{ - short_match - }"} + "" <> + "@#{full_match}"} end) {subs, uuid_text} -- cgit v1.2.3 From 8c368d42a20ea21d5d382838843ca1c57a86e882 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 17 Jan 2019 15:48:14 +0000 Subject: Make attachment links configurable Thanks @href! --- lib/pleroma/web/common_api/common_api.ex | 2 +- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 2902905fd..7d2ac3b0f 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -103,7 +103,7 @@ defmodule Pleroma.Web.CommonAPI do attachments, tags, get_content_type(data["content_type"]), - Enum.member?([true, "true"], data["no_attachment_links"]) + Enum.member?([true, "true"], Map.get(data, "no_attachment_links", Pleroma.Config.get([:instance, :no_attachment_links], true))) ), context <- make_context(inReplyTo), cw <- data["spoiler_text"], diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index a8fe9d708..daad89185 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -341,7 +341,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do params = params |> Map.put("in_reply_to_status_id", params["in_reply_to_id"]) - |> Map.put("no_attachment_links", true) idempotency_key = case get_req_header(conn, "idempotency-key") do -- cgit v1.2.3 From 388ceb6a7de4a17d695b40152b5dcbfadc2eef84 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 17 Jan 2019 19:00:08 +0300 Subject: Fix the issue with get_by_nickname never being called --- lib/pleroma/user.ex | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 180ef180c..13a476fd2 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -449,8 +449,13 @@ defmodule Pleroma.User do ap_id = Cachex.fetch!(:user_cache, key, fn _ -> user = get_by_id(id) - Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user) - {:commit, user.ap_id} + + if user do + Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user) + {:commit, user.ap_id} + else + {:ignore, ""} + end end) get_cached_by_ap_id(ap_id) -- cgit v1.2.3 From 6bc9a641ba77146815f3bf6dddab751c1cce1637 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 17 Jan 2019 16:01:25 +0000 Subject: Default to disabled in the code in case the setting is absent from config.exs --- lib/pleroma/web/common_api/common_api.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 7d2ac3b0f..782e7da8f 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -103,7 +103,7 @@ defmodule Pleroma.Web.CommonAPI do attachments, tags, get_content_type(data["content_type"]), - Enum.member?([true, "true"], Map.get(data, "no_attachment_links", Pleroma.Config.get([:instance, :no_attachment_links], true))) + Enum.member?([true, "true"], Map.get(data, "no_attachment_links", Pleroma.Config.get([:instance, :no_attachment_links], false))) ), context <- make_context(inReplyTo), cw <- data["spoiler_text"], -- cgit v1.2.3 From 849c83ed464e8cbf57c727da8e7b4f8e7daf8fef Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 17 Jan 2019 16:10:26 +0000 Subject: formatting --- lib/pleroma/web/common_api/common_api.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 782e7da8f..504670439 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -103,7 +103,14 @@ defmodule Pleroma.Web.CommonAPI do attachments, tags, get_content_type(data["content_type"]), - Enum.member?([true, "true"], Map.get(data, "no_attachment_links", Pleroma.Config.get([:instance, :no_attachment_links], false))) + Enum.member?( + [true, "true"], + Map.get( + data, + "no_attachment_links", + Pleroma.Config.get([:instance, :no_attachment_links], false) + ) + ) ), context <- make_context(inReplyTo), cw <- data["spoiler_text"], -- cgit v1.2.3 From 954dc4a4ad8a387ca7b18bb7d0ed32456491daec Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 17 Jan 2019 19:16:02 +0300 Subject: [#502] Fixed `user_count` in `/api/v1/instance` to include only active local users. --- lib/pleroma/stats.ex | 2 +- lib/pleroma/user.ex | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/stats.ex b/lib/pleroma/stats.ex index 65a6d58b5..b3566ceb6 100644 --- a/lib/pleroma/stats.ex +++ b/lib/pleroma/stats.ex @@ -46,7 +46,7 @@ defmodule Pleroma.Stats do from(u in User.local_user_query(), select: fragment("sum((?->>'note_count')::int)", u.info)) status_count = Repo.one(status_query) - user_count = Repo.aggregate(User.local_user_query(), :count, :id) + user_count = Repo.aggregate(User.active_local_user_query(), :count, :id) Agent.update(__MODULE__, fn _ -> {peers, %{domain_count: domain_count, status_count: status_count, user_count: user_count}} diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index a52e536d3..c91f2d31a 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -796,7 +796,7 @@ defmodule Pleroma.User do update_and_set_cache(cng) end - def local_user_query() do + def local_user_query do from( u in User, where: u.local == true, @@ -804,7 +804,14 @@ defmodule Pleroma.User do ) end - def moderator_user_query() do + def active_local_user_query do + from( + u in local_user_query(), + where: fragment("?->'deactivated' @> 'false'", u.info) + ) + end + + def moderator_user_query do from( u in User, where: u.local == true, -- cgit v1.2.3 From a95d5da607f92faa1bc05f9d284086071a0a9d48 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 17 Jan 2019 20:18:28 +0300 Subject: Don't show content if empty or zero width space --- lib/pleroma/web/metadata/opengraph.ex | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 2f27a5300..cbd0b7d1b 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -10,8 +10,19 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do @behaviour Provider @impl Provider - def build_tags(%{activity: %{data: %{"object" => %{"id" => object_id}}} = activity, user: user}) do + def build_tags(%{ + activity: %{data: %{"object" => %{"id" => object_id}}} = activity, + user: user + }) do attachments = build_attachments(activity) + scrubbed_content = scrub_html_and_truncate(activity) + # Zero width space + content = + if scrubbed_content != "" and scrubbed_content != "\u200B" do + ": “" <> scrubbed_content <> "”" + else + "" + end # Most previews only show og:title which is inconvenient. Instagram # hacks this by putting the description in the title and making the @@ -23,13 +34,13 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do {:meta, [ property: "og:title", - content: "#{user.name}: " <> "“" <> scrub_html_and_truncate(activity) <> "”" + content: "#{user.name}" <> content ], []}, {:meta, [property: "og:url", content: object_id], []}, {:meta, [ property: "og:description", - content: "#{user_name_string(user)}: " <> "“" <> scrub_html_and_truncate(activity) <> "”" + content: "#{user_name_string(user)}" <> content ], []}, {:meta, [property: "og:type", content: "website"], []} ] ++ -- cgit v1.2.3 From 948fba6f7663119ac4e0458aa803612ee1a2c1ca Mon Sep 17 00:00:00 2001 From: sxsdv1 Date: Thu, 17 Jan 2019 18:21:43 +0100 Subject: Fix bad link in likes collection Don't copy and paste, mkay --- lib/pleroma/web/activity_pub/views/object_view.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/views/object_view.ex b/lib/pleroma/web/activity_pub/views/object_view.ex index 193042056..394d82fbc 100644 --- a/lib/pleroma/web/activity_pub/views/object_view.ex +++ b/lib/pleroma/web/activity_pub/views/object_view.ex @@ -46,7 +46,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectView do "id" => "#{ap_id}/likes", "type" => "OrderedCollection", "totalItems" => length(likes), - "first" => collection(likes, "#{ap_id}/followers", 1) + "first" => collection(likes, "#{ap_id}/likes", 1) } |> Map.merge(Pleroma.Web.ActivityPub.Utils.make_json_ld_header()) end -- cgit v1.2.3 From 2479e88815480a6417a16541c5e6da149e2e7ff9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 17 Jan 2019 23:12:42 +0000 Subject: activitypub: announce: add new public parameter --- lib/pleroma/web/activity_pub/activity_pub.ex | 5 +++-- lib/pleroma/web/activity_pub/utils.ex | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 5b87f7462..8c852edbd 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -224,10 +224,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do %User{ap_id: _} = user, %Object{data: %{"id" => _}} = object, activity_id \\ nil, - local \\ true + local \\ true, + public \\ true ) do with true <- is_public?(object), - announce_data <- make_announce_data(user, object, activity_id), + announce_data <- make_announce_data(user, object, activity_id, public), {:ok, activity} <- insert(announce_data, local), {:ok, object} <- add_announce_to_object(activity, object), :ok <- maybe_federate(activity) do diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 6ecab773c..d2e457a68 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -386,9 +386,10 @@ defmodule Pleroma.Web.ActivityPub.Utils do """ # for relayed messages, we only want to send to subscribers def make_announce_data( - %User{ap_id: ap_id, nickname: nil} = user, + %User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, - activity_id + activity_id, + false ) do data = %{ "type" => "Announce", @@ -405,7 +406,8 @@ defmodule Pleroma.Web.ActivityPub.Utils do def make_announce_data( %User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, - activity_id + activity_id, + true ) do data = %{ "type" => "Announce", -- cgit v1.2.3 From 8e9f1d55876a282aa9f6f5358dc2db8715c13bff Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 17 Jan 2019 23:13:54 +0000 Subject: activitypub: relay: chase selective public announce changes --- lib/pleroma/web/activity_pub/relay.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/relay.ex b/lib/pleroma/web/activity_pub/relay.ex index abddbc790..c0a52e349 100644 --- a/lib/pleroma/web/activity_pub/relay.ex +++ b/lib/pleroma/web/activity_pub/relay.ex @@ -40,7 +40,7 @@ defmodule Pleroma.Web.ActivityPub.Relay do def publish(%Activity{data: %{"type" => "Create"}} = activity) do with %User{} = user <- get_actor(), %Object{} = object <- Object.normalize(activity.data["object"]["id"]) do - ActivityPub.announce(user, object) + ActivityPub.announce(user, object, nil, true, false) else e -> Logger.error("error: #{inspect(e)}") end -- cgit v1.2.3 From 33b473cc021d2d027c11021178af90298230e06e Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 17 Jan 2019 23:17:59 +0000 Subject: activitypub: allow is_public?() to work on any type of map representing an AS2 object --- lib/pleroma/web/activity_pub/activity_pub.ex | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 8c852edbd..92c5ce2ae 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -797,13 +797,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end - def is_public?(%Object{data: %{"type" => "Tombstone"}}) do - false - end + def is_public?(%Object{data: %{"type" => "Tombstone"}}), do: false + def is_public?(%Activity{data: data}), do: is_public?(data) - def is_public?(activity) do - "https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++ - (activity.data["cc"] || [])) + def is_public?(data) do + "https://www.w3.org/ns/activitystreams#Public" in (data["to"] ++ (data["cc"] || [])) end def visible_for_user?(activity, nil) do -- cgit v1.2.3 From dbc4e92509594139a906ce9546f442b531430c57 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 17 Jan 2019 23:19:15 +0000 Subject: activitypub: transmogrifier: do not clobber the addressing on relayed announcements --- lib/pleroma/web/activity_pub/transmogrifier.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 86d11c874..fa3abe3d8 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -451,7 +451,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do with actor <- get_actor(data), %User{} = actor <- User.get_or_fetch_by_ap_id(actor), {:ok, object} <- get_obj_helper(object_id) || fetch_obj_helper(object_id), - {:ok, activity, _object} <- ActivityPub.announce(actor, object, id, false) do + public <- ActivityPub.is_public?(data), + {:ok, activity, _object} <- ActivityPub.announce(actor, object, id, false, public) do {:ok, activity} else _e -> :error -- cgit v1.2.3 From 75a9b2a851eceb5308dbc9f1767d4bf37dcd8f77 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 17 Jan 2019 23:32:16 +0000 Subject: activitypub: add a match clause for objects, not just activities --- lib/pleroma/web/activity_pub/activity_pub.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 92c5ce2ae..130c06028 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -798,6 +798,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end def is_public?(%Object{data: %{"type" => "Tombstone"}}), do: false + def is_public?(%Object{data: data}), do: is_public?(data) def is_public?(%Activity{data: data}), do: is_public?(data) def is_public?(data) do -- cgit v1.2.3 From 65bb9b2fba7560df7331645db9839305c47dad11 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 18 Jan 2019 09:30:16 +0300 Subject: [#491] Made full nicknames be preserved in user links text only in Bio. --- lib/pleroma/formatter.ex | 11 ++++++++--- lib/pleroma/user.ex | 15 ++++++++++++--- lib/pleroma/web/common_api/utils.ex | 14 ++++++++------ 3 files changed, 28 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 024c6e117..37737853a 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -120,7 +120,7 @@ defmodule Pleroma.Formatter do end @doc "Adds the links to mentioned users" - def add_user_links({subs, text}, mentions) do + def add_user_links({subs, text}, mentions, options \\ []) do mentions = mentions |> Enum.sort_by(fn {name, _} -> -String.length(name) end) @@ -142,11 +142,16 @@ defmodule Pleroma.Formatter do ap_id end - full_match = String.trim_leading(match, "@") + nickname = + if options[:format] == :full do + User.full_nickname(match) + else + User.local_nickname(match) + end {uuid, "" <> - "@#{full_match}"} + "@#{nickname}"} end) {subs, uuid_text} diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index a52e536d3..2dc3c8d56 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -447,8 +447,7 @@ defmodule Pleroma.User do def get_by_nickname(nickname) do Repo.get_by(User, nickname: nickname) || if Regex.match?(~r(@#{Pleroma.Web.Endpoint.host()})i, nickname) do - [local_nickname, _] = String.split(nickname, "@") - Repo.get_by(User, nickname: local_nickname) + Repo.get_by(User, nickname: local_nickname(nickname)) end end @@ -990,7 +989,7 @@ defmodule Pleroma.User do end) bio - |> CommonUtils.format_input(mentions, tags, "text/plain") + |> CommonUtils.format_input(mentions, tags, "text/plain", user_links: [format: :full]) |> Formatter.emojify(emoji) end @@ -1041,6 +1040,16 @@ defmodule Pleroma.User do end end + def local_nickname(nickname_or_mention) do + nickname_or_mention + |> full_nickname() + |> String.split("@") + |> hd() + end + + def full_nickname(nickname_or_mention), + do: String.trim_leading(nickname_or_mention, "@") + def error_user(ap_id) do %User{ name: ap_id, diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 7e30d224c..a36ab5c15 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -116,16 +116,18 @@ defmodule Pleroma.Web.CommonAPI.Utils do Enum.join([text | attachment_text], "
") end + def format_input(text, mentions, tags, format, options \\ []) + @doc """ Formatting text to plain text. """ - def format_input(text, mentions, tags, "text/plain") do + def format_input(text, mentions, tags, "text/plain", options) do text |> Formatter.html_escape("text/plain") |> String.replace(~r/\r?\n/, "
") |> (&{[], &1}).() |> Formatter.add_links() - |> Formatter.add_user_links(mentions) + |> Formatter.add_user_links(mentions, options[:user_links] || []) |> Formatter.add_hashtag_links(tags) |> Formatter.finalize() end @@ -133,24 +135,24 @@ defmodule Pleroma.Web.CommonAPI.Utils do @doc """ Formatting text to html. """ - def format_input(text, mentions, _tags, "text/html") do + def format_input(text, mentions, _tags, "text/html", options) do text |> Formatter.html_escape("text/html") |> (&{[], &1}).() - |> Formatter.add_user_links(mentions) + |> Formatter.add_user_links(mentions, options[:user_links] || []) |> Formatter.finalize() end @doc """ Formatting text to markdown. """ - def format_input(text, mentions, tags, "text/markdown") do + def format_input(text, mentions, tags, "text/markdown", options) do text |> Formatter.mentions_escape(mentions) |> Earmark.as_html!() |> Formatter.html_escape("text/html") |> (&{[], &1}).() - |> Formatter.add_user_links(mentions) + |> Formatter.add_user_links(mentions, options[:user_links] || []) |> Formatter.add_hashtag_links(tags) |> Formatter.finalize() end -- cgit v1.2.3 From 1b1af4798a74c4ab357140ef2c5928dd9ebd3221 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 18 Jan 2019 09:32:52 +0300 Subject: Use object instead of activity for metadata --- lib/pleroma/web/metadata.ex | 13 +++++++------ lib/pleroma/web/metadata/opengraph.ex | 17 +++++++++-------- lib/pleroma/web/metadata/provider.ex | 1 + lib/pleroma/web/metadata/twitter_card.ex | 9 +++++---- lib/pleroma/web/ostatus/ostatus_controller.ex | 7 ++++--- 5 files changed, 26 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index be3c384ae..8761260f2 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -1,6 +1,7 @@ # Pleroma: A lightweight social networking server # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Metadata do alias Phoenix.HTML @@ -29,11 +30,11 @@ defmodule Pleroma.Web.Metadata do end end - def activity_nsfw?(%{data: %{"object" => %{"tag" => tags}}}) do - if(Pleroma.Config.get([__MODULE__, :unfurl_nsfw], false) == false) do - Enum.any?(tags, fn tag -> tag == "nsfw" end) - else - false - end + def activity_nsfw?(%{data: %{"sensitive" => sensitive}}) do + Pleroma.Config.get([__MODULE__, :unfurl_nsfw], false) == false and sensitive + end + + def activity_nsfw?(_) do + false end end diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index cbd0b7d1b..43303859c 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -1,6 +1,7 @@ # Pleroma: A lightweight social networking server # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Metadata.Providers.OpenGraph do alias Pleroma.Web.Metadata.Providers.Provider alias Pleroma.Web.Metadata @@ -11,11 +12,11 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do @impl Provider def build_tags(%{ - activity: %{data: %{"object" => %{"id" => object_id}}} = activity, + object: object, user: user }) do - attachments = build_attachments(activity) - scrubbed_content = scrub_html_and_truncate(activity) + attachments = build_attachments(object) + scrubbed_content = scrub_html_and_truncate(object) # Zero width space content = if scrubbed_content != "" and scrubbed_content != "\u200B" do @@ -36,7 +37,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do property: "og:title", content: "#{user.name}" <> content ], []}, - {:meta, [property: "og:url", content: object_id], []}, + {:meta, [property: "og:url", content: object.data["id"]], []}, {:meta, [ property: "og:description", @@ -44,7 +45,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do ], []}, {:meta, [property: "og:type", content: "website"], []} ] ++ - if attachments == [] or Metadata.activity_nsfw?(activity) do + if attachments == [] or Metadata.activity_nsfw?(object) do [ {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, {:meta, [property: "og:image:width", content: 150], []}, @@ -74,7 +75,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do end end - defp build_attachments(%{data: %{"object" => %{"attachment" => attachments}}} = _activity) do + defp build_attachments(%{data: %{"attachment" => attachments}}) do Enum.reduce(attachments, [], fn attachment, acc -> rendered_tags = Enum.reduce(attachment["url"], [], fn url, acc -> @@ -117,12 +118,12 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do end) end - defp scrub_html_and_truncate(%{data: %{"object" => %{"content" => content}}} = activity) do + defp scrub_html_and_truncate(%{data: %{"content" => content}} = object) do content # html content comes from DB already encoded, decode first and scrub after |> HtmlEntities.decode() |> String.replace(~r//, " ") - |> HTML.get_cached_stripped_html_for_object(activity, __MODULE__) + |> HTML.get_cached_stripped_html_for_object(object, __MODULE__) |> Formatter.truncate() end diff --git a/lib/pleroma/web/metadata/provider.ex b/lib/pleroma/web/metadata/provider.ex index a39008bcc..197fb2a77 100644 --- a/lib/pleroma/web/metadata/provider.ex +++ b/lib/pleroma/web/metadata/provider.ex @@ -1,6 +1,7 @@ # Pleroma: A lightweight social networking server # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Metadata.Providers.Provider do @callback build_tags(map()) :: list() end diff --git a/lib/pleroma/web/metadata/twitter_card.ex b/lib/pleroma/web/metadata/twitter_card.ex index 9a1245e59..32b979357 100644 --- a/lib/pleroma/web/metadata/twitter_card.ex +++ b/lib/pleroma/web/metadata/twitter_card.ex @@ -1,6 +1,7 @@ # Pleroma: A lightweight social networking server # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Metadata.Providers.TwitterCard do alias Pleroma.Web.Metadata.Providers.Provider alias Pleroma.Web.Metadata @@ -8,11 +9,11 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do @behaviour Provider @impl Provider - def build_tags(%{activity: activity}) do - if Metadata.activity_nsfw?(activity) or activity.data["object"]["attachment"] == [] do + def build_tags(%{object: object}) do + if Metadata.activity_nsfw?(object) or object.data["attachment"] == [] do build_tags(nil) else - case find_first_acceptable_media_type(activity) do + case find_first_acceptable_media_type(object) do "image" -> [{:meta, [property: "twitter:card", content: "summary_large_image"], []}] @@ -33,7 +34,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do [{:meta, [property: "twitter:card", content: "summary"], []}] end - def find_first_acceptable_media_type(%{data: %{"object" => %{"attachment" => attachment}}}) do + def find_first_acceptable_media_type(%{data: %{"attachment" => attachment}}) do Enum.find_value(attachment, fn attachment -> Enum.find_value(attachment["url"], fn url -> Enum.find(["image", "audio", "video"], fn media_type -> diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index f7ba57389..4844b84ad 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -145,10 +145,11 @@ defmodule Pleroma.Web.OStatus.OStatusController do %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do case format = get_format(conn) do "html" -> - # Only Create actvities have a map at object - if is_map(activity.data["object"]) do + if activity.data["type"] == "Create" do + %Object{} = object = Object.normalize(activity.data["object"]) + Fallback.RedirectController.redirector_with_meta(conn, %{ - activity: activity, + object: object, user: user }) else -- cgit v1.2.3 From 997f4a5e09f8531f95ba3f13986b9dda583d046a Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 18 Jan 2019 10:28:19 +0300 Subject: Remove custom emojis and trailing whitespaces from previews --- lib/pleroma/formatter.ex | 21 +++++++++++++++++---- lib/pleroma/web/common_api/common_api.ex | 2 +- lib/pleroma/web/metadata/opengraph.ex | 2 ++ 3 files changed, 20 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 63e0acb21..2696f41c0 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -43,7 +43,7 @@ defmodule Pleroma.Formatter do def emojify(text, nil), do: text - def emojify(text, emoji) do + def emojify(text, emoji, strip \\ false) do Enum.reduce(emoji, text, fn {emoji, file}, text -> emoji = HTML.strip_tags(emoji) file = HTML.strip_tags(file) @@ -51,14 +51,24 @@ defmodule Pleroma.Formatter do String.replace( text, ":#{emoji}:", - "#{emoji}" + if not strip do + "#{emoji}" + else + "" + end ) |> HTML.filter_tags() end) end + def demojify(text) do + emojify(text, Emoji.get_all(), true) + end + + def demojify(text, nil), do: text + def get_emoji(text) when is_binary(text) do Enum.filter(Emoji.get_all(), fn {emoji, _} -> String.contains?(text, ":#{emoji}:") end) end @@ -185,6 +195,9 @@ defmodule Pleroma.Formatter do end def truncate(text, max_length \\ 200, omission \\ "...") do + # Remove trailing whitespace + text = Regex.replace(~r/([^ \t\r\n])([ \t]+$)/u, text, "\\g{1}") + if String.length(text) < max_length do text else diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 2902905fd..9a748d65e 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -103,7 +103,7 @@ defmodule Pleroma.Web.CommonAPI do attachments, tags, get_content_type(data["content_type"]), - Enum.member?([true, "true"], data["no_attachment_links"]) + true ), context <- make_context(inReplyTo), cw <- data["spoiler_text"], diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 43303859c..1028e35c2 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -124,6 +124,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do |> HtmlEntities.decode() |> String.replace(~r//, " ") |> HTML.get_cached_stripped_html_for_object(object, __MODULE__) + |> Formatter.demojify() |> Formatter.truncate() end @@ -133,6 +134,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do |> HtmlEntities.decode() |> String.replace(~r//, " ") |> HTML.strip_tags() + |> Formatter.demojify() |> Formatter.truncate() end -- cgit v1.2.3 From ed8f55ab8eb292903cec8f7699aa6775cc304458 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 18 Jan 2019 10:35:45 +0300 Subject: [#477] User: FTS and trigram search results mixing (to handle misspelled requests). --- lib/pleroma/user.ex | 136 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 79 insertions(+), 57 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 8ae36416a..1d0bf1edf 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -679,48 +679,24 @@ defmodule Pleroma.User do end def search(query, resolve \\ false, for_user \\ nil) do - # strip the beginning @ off if there is a query + # Strip the beginning @ off if there is a query query = String.trim_leading(query, "@") - if resolve do - User.get_or_fetch_by_nickname(query) - end + if resolve, do: User.get_or_fetch_by_nickname(query) - processed_query = - query - |> String.replace(~r/\W+/, " ") - |> String.trim() - |> String.split() - |> Enum.map(&(&1 <> ":*")) - |> Enum.join(" | ") + fts_results = do_search(fts_search_subquery(query), for_user) - inner = - from( - u in User, - select_merge: %{ - search_rank: - fragment( - """ - ts_rank_cd( - setweight(to_tsvector('simple', regexp_replace(?, '\\W', ' ', 'g')), 'A') || - setweight(to_tsvector('simple', regexp_replace(coalesce(?, ''), '\\W', ' ', 'g')), 'B'), - to_tsquery('simple', ?), - 32 - ) - """, - u.nickname, - u.name, - ^processed_query - ) - }, - where: not is_nil(u.nickname) - ) + trigram_results = do_search(trigram_search_subquery(query), for_user) + + Enum.uniq_by(fts_results ++ trigram_results, & &1.id) + end + defp do_search(subquery, for_user, options \\ []) do q = from( - s in subquery(inner), + s in subquery(subquery), order_by: [desc: s.search_rank], - limit: 20 + limit: ^(options[:limit] || 20) ) results = @@ -728,35 +704,81 @@ defmodule Pleroma.User do |> Repo.all() |> Enum.filter(&(&1.search_rank > 0)) - weighted_results = - if for_user do - friends_ids = get_friends_ids(for_user) - followers_ids = get_followers_ids(for_user) + boost_search_results(results, for_user) + end - Enum.map( - results, - fn u -> - search_rank_coef = - cond do - u.id in friends_ids -> - 1.2 + defp fts_search_subquery(query) do + processed_query = + query + |> String.replace(~r/\W+/, " ") + |> String.trim() + |> String.split() + |> Enum.map(&(&1 <> ":*")) + |> Enum.join(" | ") + + from( + u in User, + select_merge: %{ + search_rank: + fragment( + """ + ts_rank_cd( + setweight(to_tsvector('simple', regexp_replace(?, '\\W', ' ', 'g')), 'A') || + setweight(to_tsvector('simple', regexp_replace(coalesce(?, ''), '\\W', ' ', 'g')), 'B'), + to_tsquery('simple', ?), + 32 + ) + """, + u.nickname, + u.name, + ^processed_query + ) + }, + where: not is_nil(u.nickname) + ) + end + + defp trigram_search_subquery(query) do + from( + u in User, + select_merge: %{ + search_rank: + fragment( + "similarity(?, ? || ' ' || coalesce(?, ''))", + ^query, + u.nickname, + u.name + ) + }, + where: not is_nil(u.nickname) + ) + end - u.id in followers_ids -> - 1.1 + defp boost_search_results(results, nil), do: results - true -> - 1 - end + defp boost_search_results(results, for_user) do + friends_ids = get_friends_ids(for_user) + followers_ids = get_followers_ids(for_user) - Map.put(u, :search_rank, u.search_rank * search_rank_coef) + Enum.map( + results, + fn u -> + search_rank_coef = + cond do + u.id in friends_ids -> + 1.2 + + u.id in followers_ids -> + 1.1 + + true -> + 1 end - ) - |> Enum.sort_by(&(-&1.search_rank)) - else - results - end - weighted_results + Map.put(u, :search_rank, u.search_rank * search_rank_coef) + end + ) + |> Enum.sort_by(&(-&1.search_rank)) end def blocks_import(%User{} = blocker, blocked_identifiers) when is_list(blocked_identifiers) do -- cgit v1.2.3 From 79e44042bc08cf69274008e408cac912ae693afe Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 18 Jan 2019 10:57:42 +0300 Subject: [#477] User trigram index adjustment. --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1d0bf1edf..eb4218ebe 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -744,7 +744,7 @@ defmodule Pleroma.User do select_merge: %{ search_rank: fragment( - "similarity(?, ? || ' ' || coalesce(?, ''))", + "similarity(?, trim(? || ' ' || coalesce(?, '')))", ^query, u.nickname, u.name -- cgit v1.2.3 From 5d4d51e6dcbdff442e8bbc7cd3924b621d8f1783 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 18 Jan 2019 19:25:37 +0100 Subject: Add fixes for SPC users. --- lib/pleroma/spc_fixes/spc_fixes.ex | 64 ++ lib/pleroma/spc_fixes/users_conversion.txt | 1043 ++++++++++++++++++++++++++++ 2 files changed, 1107 insertions(+) create mode 100644 lib/pleroma/spc_fixes/spc_fixes.ex create mode 100644 lib/pleroma/spc_fixes/users_conversion.txt (limited to 'lib') diff --git a/lib/pleroma/spc_fixes/spc_fixes.ex b/lib/pleroma/spc_fixes/spc_fixes.ex new file mode 100644 index 000000000..aa4830b51 --- /dev/null +++ b/lib/pleroma/spc_fixes/spc_fixes.ex @@ -0,0 +1,64 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +alias Pleroma.Repo +alias Pleroma.User +# alias Pleroma.Web.ActivityPub.Transmogrifier +import Ecto.Query + +defmodule Pleroma.SpcFixes do + def upgrade_users do + query = + from(u in User, + where: fragment("? like ?", u.ap_id, "https://shitposter.club/user/%") + ) + + {:ok, file} = File.read("lib/pleroma/spc_fixes/users_conversion.txt") + + mapping = + file + |> String.trim() + |> String.split("\n") + |> Enum.map(fn line -> + line + |> String.split("\t") + end) + |> Enum.reduce(%{}, fn [_id, old_ap_id, new_ap_id], acc -> + Map.put(acc, old_ap_id, String.trim(new_ap_id)) + end) + + # First, refetch all the old users. + _old_users = + query + |> Repo.all() + |> Enum.each(fn user -> + with ap_id when is_binary(ap_id) <- mapping[user.ap_id] do + # This fetches and updates the user. + User.get_or_fetch_by_ap_id(ap_id) + end + end) + + # Now, fix follow relationships. + query = + from(u in User, + where: fragment("? like ?", u.ap_id, "https://shitposter.club/users/%") + ) + + query + |> Repo.all() + |> Enum.each(fn user -> + old_follower_address = User.ap_followers(user) + + query = + from(u in User, + where: ^old_follower_address in u.following, + update: [ + push: [following: ^user.follower_address] + ] + ) + + Repo.update_all(query, []) + end) + end +end diff --git a/lib/pleroma/spc_fixes/users_conversion.txt b/lib/pleroma/spc_fixes/users_conversion.txt new file mode 100644 index 000000000..0d0321e18 --- /dev/null +++ b/lib/pleroma/spc_fixes/users_conversion.txt @@ -0,0 +1,1043 @@ +1 https://shitposter.club/user/1 https://shitposter.club/users/moonman +2 https://shitposter.club/user/2 https://shitposter.club/users/sunman +45 https://shitposter.club/user/45 https://shitposter.club/users/chen +59 https://shitposter.club/user/59 https://shitposter.club/users/mona +63 https://shitposter.club/user/63 https://shitposter.club/users/wdgaster +64 https://shitposter.club/user/64 https://shitposter.club/users/waluigi +65 https://shitposter.club/user/65 https://shitposter.club/users/puke +66 https://shitposter.club/user/66 https://shitposter.club/users/sanstheskeleton +67 https://shitposter.club/user/67 https://shitposter.club/users/venus +68 https://shitposter.club/user/68 https://shitposter.club/users/noyoushutthefuckupdad +70 https://shitposter.club/user/70 https://shitposter.club/users/dualkeyblade +72 https://shitposter.club/user/72 https://shitposter.club/users/hyperbeam +74 https://shitposter.club/user/74 https://shitposter.club/users/chopperdave +75 https://shitposter.club/user/75 https://shitposter.club/users/itachi +78 https://shitposter.club/user/78 https://shitposter.club/users/gyro +80 https://shitposter.club/user/80 https://shitposter.club/users/drli +81 https://shitposter.club/user/81 https://shitposter.club/users/dril +82 https://shitposter.club/user/82 https://shitposter.club/users/bayonetta +83 https://shitposter.club/user/83 https://shitposter.club/users/imrc +91 https://shitposter.club/user/91 https://shitposter.club/users/hobi +95 https://shitposter.club/user/95 https://shitposter.club/users/houndoom +102 https://shitposter.club/user/102 https://shitposter.club/users/fuck +103 https://shitposter.club/user/103 https://shitposter.club/users/mh +114 https://shitposter.club/user/114 https://shitposter.club/users/strider +116 https://shitposter.club/user/116 https://shitposter.club/users/bunny +120 https://shitposter.club/user/120 https://shitposter.club/users/teddie +121 https://shitposter.club/user/121 https://shitposter.club/users/genesis +122 https://shitposter.club/user/122 https://shitposter.club/users/ninten +124 https://shitposter.club/user/124 https://shitposter.club/users/matsucest +125 https://shitposter.club/user/125 https://shitposter.club/users/yuri +126 https://shitposter.club/user/126 https://shitposter.club/users/yang +127 https://shitposter.club/user/127 https://shitposter.club/users/yokaiwatch +128 https://shitposter.club/user/128 https://shitposter.club/users/futo +129 https://shitposter.club/user/129 https://shitposter.club/users/captainfalcon +130 https://shitposter.club/user/130 https://shitposter.club/users/liquid +131 https://shitposter.club/user/131 https://shitposter.club/users/flonne +132 https://shitposter.club/user/132 https://shitposter.club/users/ryoubakura +133 https://shitposter.club/user/133 https://shitposter.club/users/kirisame +134 https://shitposter.club/user/134 https://shitposter.club/users/senyuu +135 https://shitposter.club/user/135 https://shitposter.club/users/protagonist +136 https://shitposter.club/user/136 https://shitposter.club/users/zelos +137 https://shitposter.club/user/137 https://shitposter.club/users/alba +138 https://shitposter.club/user/138 https://shitposter.club/users/yugo +139 https://shitposter.club/user/139 https://shitposter.club/users/vector +141 https://shitposter.club/user/141 https://shitposter.club/users/god +144 https://shitposter.club/user/144 https://shitposter.club/users/yuya +147 https://shitposter.club/user/147 https://shitposter.club/users/blmatsu +148 https://shitposter.club/user/148 https://shitposter.club/users/pain +149 https://shitposter.club/user/149 https://shitposter.club/users/bloodfalcon +150 https://shitposter.club/user/150 https://shitposter.club/users/yuzu +152 https://shitposter.club/user/152 https://shitposter.club/users/hex +153 https://shitposter.club/user/153 https://shitposter.club/users/coolcatlovesyou +154 https://shitposter.club/user/154 https://shitposter.club/users/cat +159 https://shitposter.club/user/159 https://shitposter.club/users/edna +162 https://shitposter.club/user/162 https://shitposter.club/users/uwu +163 https://shitposter.club/user/163 https://shitposter.club/users/onceler +164 https://shitposter.club/user/164 https://shitposter.club/users/swordofdoubt +168 https://shitposter.club/user/168 https://shitposter.club/users/komaeda +170 https://shitposter.club/user/170 https://shitposter.club/users/protoman +176 https://shitposter.club/user/176 https://shitposter.club/users/kiitanda +177 https://shitposter.club/user/177 https://shitposter.club/users/starscream +180 https://shitposter.club/user/180 https://shitposter.club/users/trishuna +183 https://shitposter.club/user/183 https://shitposter.club/users/milk +184 https://shitposter.club/user/184 https://shitposter.club/users/otacon +185 https://shitposter.club/user/185 https://shitposter.club/users/ragna +189 https://shitposter.club/user/189 https://shitposter.club/users/majintensei +193 https://shitposter.club/user/193 https://shitposter.club/users/deadpool +195 https://shitposter.club/user/195 https://shitposter.club/users/ramimalek +199 https://shitposter.club/user/199 https://shitposter.club/users/ritsu +200 https://shitposter.club/user/200 https://shitposter.club/users/alisha +201 https://shitposter.club/user/201 https://shitposter.club/users/naegi +202 https://shitposter.club/user/202 https://shitposter.club/users/shartmeister420 +203 https://shitposter.club/user/203 https://shitposter.club/users/lulz +204 https://shitposter.club/user/204 https://shitposter.club/users/youranonnews +208 https://shitposter.club/user/208 https://shitposter.club/users/haruna +209 https://shitposter.club/user/209 https://shitposter.club/users/bigboss +213 https://shitposter.club/user/213 https://shitposter.club/users/whisper +219 https://shitposter.club/user/219 https://shitposter.club/users/billfromnextdoor +228 https://shitposter.club/user/228 https://shitposter.club/users/cta +229 https://shitposter.club/user/229 https://shitposter.club/users/luketriton +230 https://shitposter.club/user/230 https://shitposter.club/users/striking +238 https://shitposter.club/user/238 https://shitposter.club/users/this +243 https://shitposter.club/user/243 https://shitposter.club/users/greed +244 https://shitposter.club/user/244 https://shitposter.club/users/quicksilver +246 https://shitposter.club/user/246 https://shitposter.club/users/zaveid +249 https://shitposter.club/user/249 https://shitposter.club/users/serena +263 https://shitposter.club/user/263 https://shitposter.club/users/compaq +264 https://shitposter.club/user/264 https://shitposter.club/users/squishy +265 https://shitposter.club/user/265 https://shitposter.club/users/furry +269 https://shitposter.club/user/269 https://shitposter.club/users/mikleo +270 https://shitposter.club/user/270 https://shitposter.club/users/ami +272 https://shitposter.club/user/272 https://shitposter.club/users/ruri +273 https://shitposter.club/user/273 https://shitposter.club/users/descole +292 https://shitposter.club/user/292 https://shitposter.club/users/shun +296 https://shitposter.club/user/296 https://shitposter.club/users/magician +297 https://shitposter.club/user/297 https://shitposter.club/users/pichan +301 https://shitposter.club/user/301 https://shitposter.club/users/scaryh +303 https://shitposter.club/user/303 https://shitposter.club/users/phz +349 https://shitposter.club/user/349 https://shitposter.club/users/star +350 https://shitposter.club/user/350 https://shitposter.club/users/pepe +351 https://shitposter.club/user/351 https://shitposter.club/users/disassemblyline +354 https://shitposter.club/user/354 https://shitposter.club/users/elrac +382 https://shitposter.club/user/382 https://shitposter.club/users/bigdinner +390 https://shitposter.club/user/390 https://shitposter.club/users/choromatsu +391 https://shitposter.club/user/391 https://shitposter.club/users/otasune +396 https://shitposter.club/user/396 https://shitposter.club/users/cavestoryost +415 https://shitposter.club/user/415 https://shitposter.club/users/hazama +453 https://shitposter.club/user/453 https://shitposter.club/users/mgs3 +479 https://shitposter.club/user/479 https://shitposter.club/users/kanarykrusade +486 https://shitposter.club/user/486 https://shitposter.club/users/yitzyy +495 https://shitposter.club/user/495 https://shitposter.club/users/frog +497 https://shitposter.club/user/497 https://shitposter.club/users/marik +498 https://shitposter.club/user/498 https://shitposter.club/users/cookboy +505 https://shitposter.club/user/505 https://shitposter.club/users/damnalex +511 https://shitposter.club/user/511 https://shitposter.club/users/asbellhant +512 https://shitposter.club/user/512 https://shitposter.club/users/hitler +515 https://shitposter.club/user/515 https://shitposter.club/users/zeloswilder +516 https://shitposter.club/user/516 https://shitposter.club/users/makotokikuchi +518 https://shitposter.club/user/518 https://shitposter.club/users/kaito +519 https://shitposter.club/user/519 https://shitposter.club/users/bluto +520 https://shitposter.club/user/520 https://shitposter.club/users/akuma +521 https://shitposter.club/user/521 https://shitposter.club/users/blythe +522 https://shitposter.club/user/522 https://shitposter.club/users/heavensfeel +523 https://shitposter.club/user/523 https://shitposter.club/users/sirscatters +524 https://shitposter.club/user/524 https://shitposter.club/users/gakupo +526 https://shitposter.club/user/526 https://shitposter.club/users/anntagonist +527 https://shitposter.club/user/527 https://shitposter.club/users/misscatling +529 https://shitposter.club/user/529 https://shitposter.club/users/misscatlin +532 https://shitposter.club/user/532 https://shitposter.club/users/rjohnlennon +533 https://shitposter.club/user/533 https://shitposter.club/users/randhask +535 https://shitposter.club/user/535 https://shitposter.club/users/zemichi +537 https://shitposter.club/user/537 https://shitposter.club/users/carol +539 https://shitposter.club/user/539 https://shitposter.club/users/catmeme +540 https://shitposter.club/user/540 https://shitposter.club/users/spikespiegel +542 https://shitposter.club/user/542 https://shitposter.club/users/marvinthemartian +545 https://shitposter.club/user/545 https://shitposter.club/users/androlphegax +547 https://shitposter.club/user/547 https://shitposter.club/users/atlfalconsfan +549 https://shitposter.club/user/549 https://shitposter.club/users/shaxpeer +550 https://shitposter.club/user/550 https://shitposter.club/users/toddkincannon +556 https://shitposter.club/user/556 https://shitposter.club/users/divider +557 https://shitposter.club/user/557 https://shitposter.club/users/rayogundead +558 https://shitposter.club/user/558 https://shitposter.club/users/breadgod +561 https://shitposter.club/user/561 https://shitposter.club/users/internetzenmaster +569 https://shitposter.club/user/569 https://shitposter.club/users/izzyjsmom +571 https://shitposter.club/user/571 https://shitposter.club/users/spb +573 https://shitposter.club/user/573 https://shitposter.club/users/necrofantasia +574 https://shitposter.club/user/574 https://shitposter.club/users/cvlztn +575 https://shitposter.club/user/575 https://shitposter.club/users/herbiemarcuse +577 https://shitposter.club/user/577 https://shitposter.club/users/simarilian +578 https://shitposter.club/user/578 https://shitposter.club/users/shingo +580 https://shitposter.club/user/580 https://shitposter.club/users/applebees +582 https://shitposter.club/user/582 https://shitposter.club/users/heechul +583 https://shitposter.club/user/583 https://shitposter.club/users/rin +584 https://shitposter.club/user/584 https://shitposter.club/users/killua +585 https://shitposter.club/user/585 https://shitposter.club/users/seamus +586 https://shitposter.club/user/586 https://shitposter.club/users/momoisatsuki +588 https://shitposter.club/user/588 https://shitposter.club/users/bs +589 https://shitposter.club/user/589 https://shitposter.club/users/nya +595 https://shitposter.club/user/595 https://shitposter.club/users/elfpietrok +598 https://shitposter.club/user/598 https://shitposter.club/users/cyc0 +600 https://shitposter.club/user/600 https://shitposter.club/users/9riest +601 https://shitposter.club/user/601 https://shitposter.club/users/bella +602 https://shitposter.club/user/602 https://shitposter.club/users/hopestillflies +604 https://shitposter.club/user/604 https://shitposter.club/users/mark +605 https://shitposter.club/user/605 https://shitposter.club/users/crappycoco +607 https://shitposter.club/user/607 https://shitposter.club/users/meme +609 https://shitposter.club/user/609 https://shitposter.club/users/raylan +610 https://shitposter.club/user/610 https://shitposter.club/users/berry +611 https://shitposter.club/user/611 https://shitposter.club/users/noobius +621 https://shitposter.club/user/621 https://shitposter.club/users/lit +622 https://shitposter.club/user/622 https://shitposter.club/users/thedominionofplumass +633 https://shitposter.club/user/633 https://shitposter.club/users/amish +640 https://shitposter.club/user/640 https://shitposter.club/users/yaoi +657 https://shitposter.club/user/657 https://shitposter.club/users/ayano +661 https://shitposter.club/user/661 https://shitposter.club/users/velvethammer +665 https://shitposter.club/user/665 https://shitposter.club/users/yushe +666 https://shitposter.club/user/666 https://shitposter.club/users/rw +684 https://shitposter.club/user/684 https://shitposter.club/users/justplainbill +685 https://shitposter.club/user/685 https://shitposter.club/users/bree +687 https://shitposter.club/user/687 https://shitposter.club/users/dinahlord +693 https://shitposter.club/user/693 https://shitposter.club/users/luna +694 https://shitposter.club/user/694 https://shitposter.club/users/winterjaeger +695 https://shitposter.club/user/695 https://shitposter.club/users/winterjaeger7 +696 https://shitposter.club/user/696 https://shitposter.club/users/vall +697 https://shitposter.club/user/697 https://shitposter.club/users/nsa +699 https://shitposter.club/user/699 https://shitposter.club/users/haolink +700 https://shitposter.club/user/700 https://shitposter.club/users/mrsaturday +711 https://shitposter.club/user/711 https://shitposter.club/users/ob +728 https://shitposter.club/user/728 https://shitposter.club/users/djormil +734 https://shitposter.club/user/734 https://shitposter.club/users/twittercoe +735 https://shitposter.club/user/735 https://shitposter.club/users/twitterceo +748 https://shitposter.club/user/748 https://shitposter.club/users/joeprich +751 https://shitposter.club/user/751 https://shitposter.club/users/cheeto +755 https://shitposter.club/user/755 https://shitposter.club/users/jojo +757 https://shitposter.club/user/757 https://shitposter.club/users/onet +759 https://shitposter.club/user/759 https://shitposter.club/users/hiredmind +769 https://shitposter.club/user/769 https://shitposter.club/users/bonzibuddy +771 https://shitposter.club/user/771 https://shitposter.club/users/six6six +772 https://shitposter.club/user/772 https://shitposter.club/users/grantweets2 +779 https://shitposter.club/user/779 https://shitposter.club/users/marcavis +783 https://shitposter.club/user/783 https://shitposter.club/users/wintergirl93 +785 https://shitposter.club/user/785 https://shitposter.club/users/moonmanmobile +795 https://shitposter.club/user/795 https://shitposter.club/users/oz +796 https://shitposter.club/user/796 https://shitposter.club/users/rei +797 https://shitposter.club/user/797 https://shitposter.club/users/luciela +798 https://shitposter.club/user/798 https://shitposter.club/users/nightray +799 https://shitposter.club/user/799 https://shitposter.club/users/sorey +800 https://shitposter.club/user/800 https://shitposter.club/users/jack +802 https://shitposter.club/user/802 https://shitposter.club/users/natsu +804 https://shitposter.club/user/804 https://shitposter.club/users/yuuya +805 https://shitposter.club/user/805 https://shitposter.club/users/leo +817 https://shitposter.club/user/817 https://shitposter.club/users/rottenleaf +831 https://shitposter.club/user/831 https://shitposter.club/users/aqua +832 https://shitposter.club/user/832 https://shitposter.club/users/jihadistjoe +833 https://shitposter.club/user/833 https://shitposter.club/users/comradegg +835 https://shitposter.club/user/835 https://shitposter.club/users/bossgod +836 https://shitposter.club/user/836 https://shitposter.club/users/realdonaldtrump +859 https://shitposter.club/user/859 https://shitposter.club/users/marufoi +862 https://shitposter.club/user/862 https://shitposter.club/users/buffdad +978 https://shitposter.club/user/978 https://shitposter.club/users/nonameko +979 https://shitposter.club/user/979 https://shitposter.club/users/ira +988 https://shitposter.club/user/988 https://shitposter.club/users/adrint +1001 https://shitposter.club/user/1001 https://shitposter.club/users/fajfus +1018 https://shitposter.club/user/1018 https://shitposter.club/users/jon +1019 https://shitposter.club/user/1019 https://shitposter.club/users/levo +1020 https://shitposter.club/user/1020 https://shitposter.club/users/bhm +1023 https://shitposter.club/user/1023 https://shitposter.club/users/librarian +1025 https://shitposter.club/user/1025 https://shitposter.club/users/conanedogawa +1027 https://shitposter.club/user/1027 https://shitposter.club/users/gentlefemdom +1029 https://shitposter.club/user/1029 https://shitposter.club/users/hentie +1030 https://shitposter.club/user/1030 https://shitposter.club/users/notaskeleton +1038 https://shitposter.club/user/1038 https://shitposter.club/users/succ +1061 https://shitposter.club/user/1061 https://shitposter.club/users/applepark +1110 https://shitposter.club/user/1110 https://shitposter.club/users/caraway +1115 https://shitposter.club/user/1115 https://shitposter.club/users/jump +1118 https://shitposter.club/user/1118 https://shitposter.club/users/test222 +1120 https://shitposter.club/user/1120 https://shitposter.club/users/lu +1127 https://shitposter.club/user/1127 https://shitposter.club/users/riocat5 +1130 https://shitposter.club/user/1130 https://shitposter.club/users/lovelive +1137 https://shitposter.club/user/1137 https://shitposter.club/users/johnsonmcfonson +1159 https://shitposter.club/user/1159 https://shitposter.club/users/j +1179 https://shitposter.club/user/1179 https://shitposter.club/users/kumatora +1180 https://shitposter.club/user/1180 https://shitposter.club/users/komasan +1181 https://shitposter.club/user/1181 https://shitposter.club/users/8xenon8 +1183 https://shitposter.club/user/1183 https://shitposter.club/users/lemon +1184 https://shitposter.club/user/1184 https://shitposter.club/users/osomatsu +1186 https://shitposter.club/user/1186 https://shitposter.club/users/anomalyuk +1188 https://shitposter.club/user/1188 https://shitposter.club/users/jelly +1195 https://shitposter.club/user/1195 https://shitposter.club/users/ultra +1196 https://shitposter.club/user/1196 https://shitposter.club/users/mrmichael +1198 https://shitposter.club/user/1198 https://shitposter.club/users/neue +1205 https://shitposter.club/user/1205 https://shitposter.club/users/tomasnau +1261 https://shitposter.club/user/1261 https://shitposter.club/users/aljam +1279 https://shitposter.club/user/1279 https://shitposter.club/users/pigeonburger +1315 https://shitposter.club/user/1315 https://shitposter.club/users/itsstillrealtomedamnit +1366 https://shitposter.club/user/1366 https://shitposter.club/users/pewdiepie +1608 https://shitposter.club/user/1608 https://shitposter.club/users/serrarreaver +1613 https://shitposter.club/user/1613 https://shitposter.club/users/furrystoat +1629 https://shitposter.club/user/1629 https://shitposter.club/users/lordkraftdinner +1670 https://shitposter.club/user/1670 https://shitposter.club/users/idiotska +1736 https://shitposter.club/user/1736 https://shitposter.club/users/rabit3a +1946 https://shitposter.club/user/1946 https://shitposter.club/users/tikiloungemahu +1977 https://shitposter.club/user/1977 https://shitposter.club/users/arashinarukami +2035 https://shitposter.club/user/2035 https://shitposter.club/users/spedru +2088 https://shitposter.club/user/2088 https://shitposter.club/users/idol +2175 https://shitposter.club/user/2175 https://shitposter.club/users/olmitch +2227 https://shitposter.club/user/2227 https://shitposter.club/users/dune +2322 https://shitposter.club/user/2322 https://shitposter.club/users/biwazimayui +2323 https://shitposter.club/user/2323 https://shitposter.club/users/cawfee +2325 https://shitposter.club/user/2325 https://shitposter.club/users/jimrusell +2329 https://shitposter.club/user/2329 https://shitposter.club/users/illya +2341 https://shitposter.club/user/2341 https://shitposter.club/users/apple +2357 https://shitposter.club/user/2357 https://shitposter.club/users/bear +2358 https://shitposter.club/user/2358 https://shitposter.club/users/goldburggoldenhour +2378 https://shitposter.club/user/2378 https://shitposter.club/users/b1940060 +2380 https://shitposter.club/user/2380 https://shitposter.club/users/garnerh42 +2388 https://shitposter.club/user/2388 https://shitposter.club/users/niceau +2389 https://shitposter.club/user/2389 https://shitposter.club/users/zekeyspaceylizard +2391 https://shitposter.club/user/2391 https://shitposter.club/users/fbi +2400 https://shitposter.club/user/2400 https://shitposter.club/users/miraculousladybug +2413 https://shitposter.club/user/2413 https://shitposter.club/users/maxauri +2450 https://shitposter.club/user/2450 https://shitposter.club/users/camedei456 +2466 https://shitposter.club/user/2466 https://shitposter.club/users/nurgledsatorin +2512 https://shitposter.club/user/2512 https://shitposter.club/users/conspiracy +2539 https://shitposter.club/user/2539 https://shitposter.club/users/dtluna +2542 https://shitposter.club/user/2542 https://shitposter.club/users/analepticalzabo +2573 https://shitposter.club/user/2573 https://shitposter.club/users/irregardlessly +2588 https://shitposter.club/user/2588 https://shitposter.club/users/chalt +2599 https://shitposter.club/user/2599 https://shitposter.club/users/shtposter +2639 https://shitposter.club/user/2639 https://shitposter.club/users/oogy +2647 https://shitposter.club/user/2647 https://shitposter.club/users/salad +2662 https://shitposter.club/user/2662 https://shitposter.club/users/godfather +2663 https://shitposter.club/user/2663 https://shitposter.club/users/good +2664 https://shitposter.club/user/2664 https://shitposter.club/users/mc +2672 https://shitposter.club/user/2672 https://shitposter.club/users/nilbo +2680 https://shitposter.club/user/2680 https://shitposter.club/users/ovrclockd +2687 https://shitposter.club/user/2687 https://shitposter.club/users/politics +2724 https://shitposter.club/user/2724 https://shitposter.club/users/soomeguy +2748 https://shitposter.club/user/2748 https://shitposter.club/users/lghb +2751 https://shitposter.club/user/2751 https://shitposter.club/users/imdarelzslimsha +2794 https://shitposter.club/user/2794 https://shitposter.club/users/robert +2795 https://shitposter.club/user/2795 https://shitposter.club/users/jani +2796 https://shitposter.club/user/2796 https://shitposter.club/users/richard +2797 https://shitposter.club/user/2797 https://shitposter.club/users/warmerbrudi +2798 https://shitposter.club/user/2798 https://shitposter.club/users/thomas +2800 https://shitposter.club/user/2800 https://shitposter.club/users/100days +2801 https://shitposter.club/user/2801 https://shitposter.club/users/christoffel +2814 https://shitposter.club/user/2814 https://shitposter.club/users/cmpunk +2841 https://shitposter.club/user/2841 https://shitposter.club/users/shit +2886 https://shitposter.club/user/2886 https://shitposter.club/users/bdf +2889 https://shitposter.club/user/2889 https://shitposter.club/users/memesbrasileiros +2909 https://shitposter.club/user/2909 https://shitposter.club/users/tiuluhen +2942 https://shitposter.club/user/2942 https://shitposter.club/users/wormhole +2947 https://shitposter.club/user/2947 https://shitposter.club/users/augustus +2954 https://shitposter.club/user/2954 https://shitposter.club/users/vaka +2974 https://shitposter.club/user/2974 https://shitposter.club/users/moonbot +2979 https://shitposter.club/user/2979 https://shitposter.club/users/fakedonaldtrump +3009 https://shitposter.club/user/3009 https://shitposter.club/users/r4 +3032 https://shitposter.club/user/3032 https://shitposter.club/users/delores +3127 https://shitposter.club/user/3127 https://shitposter.club/users/plusreed +3148 https://shitposter.club/user/3148 https://shitposter.club/users/deimos +3151 https://shitposter.club/user/3151 https://shitposter.club/users/memer69 +3162 https://shitposter.club/user/3162 https://shitposter.club/users/tyreese +3163 https://shitposter.club/user/3163 https://shitposter.club/users/glen +3167 https://shitposter.club/user/3167 https://shitposter.club/users/jonny +3171 https://shitposter.club/user/3171 https://shitposter.club/users/chrishansen +3174 https://shitposter.club/user/3174 https://shitposter.club/users/usindianaffairs +3175 https://shitposter.club/user/3175 https://shitposter.club/users/cia +3225 https://shitposter.club/user/3225 https://shitposter.club/users/baconbrain +3274 https://shitposter.club/user/3274 https://shitposter.club/users/jackmcbastard +3310 https://shitposter.club/user/3310 https://shitposter.club/users/lifeprotips +3321 https://shitposter.club/user/3321 https://shitposter.club/users/nerd +3322 https://shitposter.club/user/3322 https://shitposter.club/users/flandre +3324 https://shitposter.club/user/3324 https://shitposter.club/users/kingofmars +3365 https://shitposter.club/user/3365 https://shitposter.club/users/ben +3378 https://shitposter.club/user/3378 https://shitposter.club/users/staffanb +3387 https://shitposter.club/user/3387 https://shitposter.club/users/2321 +3391 https://shitposter.club/user/3391 https://shitposter.club/users/hydris +3393 https://shitposter.club/user/3393 https://shitposter.club/users/elj +3397 https://shitposter.club/user/3397 https://shitposter.club/users/yachise +3400 https://shitposter.club/user/3400 https://shitposter.club/users/robertomangueiragrossa +3408 https://shitposter.club/user/3408 https://shitposter.club/users/danclark +3409 https://shitposter.club/user/3409 https://shitposter.club/users/erm +3441 https://shitposter.club/user/3441 https://shitposter.club/users/govspiders +3466 https://shitposter.club/user/3466 https://shitposter.club/users/malduke +3543 https://shitposter.club/user/3543 https://shitposter.club/users/testslut +3568 https://shitposter.club/user/3568 https://shitposter.club/users/grimjim +3574 https://shitposter.club/user/3574 https://shitposter.club/users/dyingrectifrice +3642 https://shitposter.club/user/3642 https://shitposter.club/users/eyepie +3699 https://shitposter.club/user/3699 https://shitposter.club/users/emiko +3713 https://shitposter.club/user/3713 https://shitposter.club/users/dex +3767 https://shitposter.club/user/3767 https://shitposter.club/users/roi +3770 https://shitposter.club/user/3770 https://shitposter.club/users/jj +3814 https://shitposter.club/user/3814 https://shitposter.club/users/why +3820 https://shitposter.club/user/3820 https://shitposter.club/users/polstar +3854 https://shitposter.club/user/3854 https://shitposter.club/users/metalhead33 +3860 https://shitposter.club/user/3860 https://shitposter.club/users/valkitty +3891 https://shitposter.club/user/3891 https://shitposter.club/users/yata +3894 https://shitposter.club/user/3894 https://shitposter.club/users/oonska +3895 https://shitposter.club/user/3895 https://shitposter.club/users/1iceloops123 +3896 https://shitposter.club/user/3896 https://shitposter.club/users/69 +3897 https://shitposter.club/user/3897 https://shitposter.club/users/bitterandrew2 +3900 https://shitposter.club/user/3900 https://shitposter.club/users/neckbolt +3904 https://shitposter.club/user/3904 https://shitposter.club/users/kommentater +3909 https://shitposter.club/user/3909 https://shitposter.club/users/bae +3911 https://shitposter.club/user/3911 https://shitposter.club/users/eternalblizzard +3913 https://shitposter.club/user/3913 https://shitposter.club/users/trevgauntlet +3915 https://shitposter.club/user/3915 https://shitposter.club/users/vriska +3952 https://shitposter.club/user/3952 https://shitposter.club/users/gethn7 +3953 https://shitposter.club/user/3953 https://shitposter.club/users/mgd +4011 https://shitposter.club/user/4011 https://shitposter.club/users/dirds +4026 https://shitposter.club/user/4026 https://shitposter.club/users/panzervoulait +4027 https://shitposter.club/user/4027 https://shitposter.club/users/clublarsh +4046 https://shitposter.club/user/4046 https://shitposter.club/users/kaz +4047 https://shitposter.club/user/4047 https://shitposter.club/users/failure +4084 https://shitposter.club/user/4084 https://shitposter.club/users/oneiorosgrip +4095 https://shitposter.club/user/4095 https://shitposter.club/users/theraveduck +4106 https://shitposter.club/user/4106 https://shitposter.club/users/gothmatix +4133 https://shitposter.club/user/4133 https://shitposter.club/users/miserablesmileface +4164 https://shitposter.club/user/4164 https://shitposter.club/users/vektg +4166 https://shitposter.club/user/4166 https://shitposter.club/users/spectrum +4179 https://shitposter.club/user/4179 https://shitposter.club/users/powerclam +4186 https://shitposter.club/user/4186 https://shitposter.club/users/madcat +4230 https://shitposter.club/user/4230 https://shitposter.club/users/nbd +4231 https://shitposter.club/user/4231 https://shitposter.club/users/triodug +4350 https://shitposter.club/user/4350 https://shitposter.club/users/dog +4389 https://shitposter.club/user/4389 https://shitposter.club/users/reissdjo +4400 https://shitposter.club/user/4400 https://shitposter.club/users/daeavorn +4401 https://shitposter.club/user/4401 https://shitposter.club/users/yourgrandmother +4414 https://shitposter.club/user/4414 https://shitposter.club/users/harmlessduck +4416 https://shitposter.club/user/4416 https://shitposter.club/users/phoenixarised +4420 https://shitposter.club/user/4420 https://shitposter.club/users/maxmustermann +4423 https://shitposter.club/user/4423 https://shitposter.club/users/tomsequitur +4425 https://shitposter.club/user/4425 https://shitposter.club/users/suityourself +4434 https://shitposter.club/user/4434 https://shitposter.club/users/gibbfm +4436 https://shitposter.club/user/4436 https://shitposter.club/users/pcachu +4440 https://shitposter.club/user/4440 https://shitposter.club/users/misspixie345 +4443 https://shitposter.club/user/4443 https://shitposter.club/users/mosley +4444 https://shitposter.club/user/4444 https://shitposter.club/users/lonewolf031 +4450 https://shitposter.club/user/4450 https://shitposter.club/users/ajr +4451 https://shitposter.club/user/4451 https://shitposter.club/users/reno +4454 https://shitposter.club/user/4454 https://shitposter.club/users/panjoozek +4457 https://shitposter.club/user/4457 https://shitposter.club/users/realpennyfortheguy +4464 https://shitposter.club/user/4464 https://shitposter.club/users/thelogiconlyzone +4467 https://shitposter.club/user/4467 https://shitposter.club/users/craig +4496 https://shitposter.club/user/4496 https://shitposter.club/users/yuiiski +4506 https://shitposter.club/user/4506 https://shitposter.club/users/robot +4556 https://shitposter.club/user/4556 https://shitposter.club/users/boozearmada +4573 https://shitposter.club/user/4573 https://shitposter.club/users/combine +4605 https://shitposter.club/user/4605 https://shitposter.club/users/ultrapageup +4627 https://shitposter.club/user/4627 https://shitposter.club/users/eris +4633 https://shitposter.club/user/4633 https://shitposter.club/users/moethirteen +4636 https://shitposter.club/user/4636 https://shitposter.club/users/quuunno +4644 https://shitposter.club/user/4644 https://shitposter.club/users/moonatdefcon +4657 https://shitposter.club/user/4657 https://shitposter.club/users/lombon +4670 https://shitposter.club/user/4670 https://shitposter.club/users/mojadam +4686 https://shitposter.club/user/4686 https://shitposter.club/users/ghofan +4690 https://shitposter.club/user/4690 https://shitposter.club/users/cameron +4708 https://shitposter.club/user/4708 https://shitposter.club/users/thevortexcoalition +4713 https://shitposter.club/user/4713 https://shitposter.club/users/rosario +4724 https://shitposter.club/user/4724 https://shitposter.club/users/datass +4759 https://shitposter.club/user/4759 https://shitposter.club/users/melancholy +4770 https://shitposter.club/user/4770 https://shitposter.club/users/boris +4773 https://shitposter.club/user/4773 https://shitposter.club/users/2dollaslices +4793 https://shitposter.club/user/4793 https://shitposter.club/users/jesus +4814 https://shitposter.club/user/4814 https://shitposter.club/users/nils +4826 https://shitposter.club/user/4826 https://shitposter.club/users/netkitteh +4887 https://shitposter.club/user/4887 https://shitposter.club/users/birch +4924 https://shitposter.club/user/4924 https://shitposter.club/users/rt +4940 https://shitposter.club/user/4940 https://shitposter.club/users/comradeagle +4943 https://shitposter.club/user/4943 https://shitposter.club/users/luciel +4950 https://shitposter.club/user/4950 https://shitposter.club/users/rob +4952 https://shitposter.club/user/4952 https://shitposter.club/users/eros +4954 https://shitposter.club/user/4954 https://shitposter.club/users/smeagledorf +4962 https://shitposter.club/user/4962 https://shitposter.club/users/zep +4982 https://shitposter.club/user/4982 https://shitposter.club/users/furaffinity +4983 https://shitposter.club/user/4983 https://shitposter.club/users/gay +4988 https://shitposter.club/user/4988 https://shitposter.club/users/leny +5000 https://shitposter.club/user/5000 https://shitposter.club/users/mrmemetic +5002 https://shitposter.club/user/5002 https://shitposter.club/users/peggle +5381 https://shitposter.club/user/5381 https://shitposter.club/users/shpuld +5440 https://shitposter.club/user/5440 https://shitposter.club/users/diana +5461 https://shitposter.club/user/5461 https://shitposter.club/users/karkat +5462 https://shitposter.club/user/5462 https://shitposter.club/users/stagparty +5494 https://shitposter.club/user/5494 https://shitposter.club/users/davestrider +5495 https://shitposter.club/user/5495 https://shitposter.club/users/fursona +5524 https://shitposter.club/user/5524 https://shitposter.club/users/jerry +5618 https://shitposter.club/user/5618 https://shitposter.club/users/moonatwork +5640 https://shitposter.club/user/5640 https://shitposter.club/users/herberthreis +5660 https://shitposter.club/user/5660 https://shitposter.club/users/dg +5681 https://shitposter.club/user/5681 https://shitposter.club/users/wakarimasen +5693 https://shitposter.club/user/5693 https://shitposter.club/users/reposterclacke +5722 https://shitposter.club/user/5722 https://shitposter.club/users/moonoffsite +5774 https://shitposter.club/user/5774 https://shitposter.club/users/figuringshitout +5826 https://shitposter.club/user/5826 https://shitposter.club/users/hckr +5875 https://shitposter.club/user/5875 https://shitposter.club/users/zero +5905 https://shitposter.club/user/5905 https://shitposter.club/users/lawyerfortheguy +5921 https://shitposter.club/user/5921 https://shitposter.club/users/dimeforthedude +5922 https://shitposter.club/user/5922 https://shitposter.club/users/tiffany +5930 https://shitposter.club/user/5930 https://shitposter.club/users/rilut +5936 https://shitposter.club/user/5936 https://shitposter.club/users/rwdigest +5941 https://shitposter.club/user/5941 https://shitposter.club/users/voidexe +6002 https://shitposter.club/user/6002 https://shitposter.club/users/kaldonia +6030 https://shitposter.club/user/6030 https://shitposter.club/users/smokeyhills +6033 https://shitposter.club/user/6033 https://shitposter.club/users/pennyforthegoy +6053 https://shitposter.club/user/6053 https://shitposter.club/users/ninjabuttocks +6057 https://shitposter.club/user/6057 https://shitposter.club/users/mrmattimation +6076 https://shitposter.club/user/6076 https://shitposter.club/users/arachnidsgrip +6086 https://shitposter.club/user/6086 https://shitposter.club/users/bogs +6114 https://shitposter.club/user/6114 https://shitposter.club/users/homph +6143 https://shitposter.club/user/6143 https://shitposter.club/users/brassrod +6144 https://shitposter.club/user/6144 https://shitposter.club/users/abnoxio +6302 https://shitposter.club/user/6302 https://shitposter.club/users/hjkhan +6317 https://shitposter.club/user/6317 https://shitposter.club/users/tasmijn +6378 https://shitposter.club/user/6378 https://shitposter.club/users/cv +6394 https://shitposter.club/user/6394 https://shitposter.club/users/exceem +6531 https://shitposter.club/user/6531 https://shitposter.club/users/thot +6533 https://shitposter.club/user/6533 https://shitposter.club/users/zenburn +6534 https://shitposter.club/user/6534 https://shitposter.club/users/supermoon +6563 https://shitposter.club/user/6563 https://shitposter.club/users/lebronjames75 +6724 https://shitposter.club/user/6724 https://shitposter.club/users/dreya +6838 https://shitposter.club/user/6838 https://shitposter.club/users/blackhole +6840 https://shitposter.club/user/6840 https://shitposter.club/users/elgatoweebee +6908 https://shitposter.club/user/6908 https://shitposter.club/users/panzerklown +6960 https://shitposter.club/user/6960 https://shitposter.club/users/hitlertheanimation +7062 https://shitposter.club/user/7062 https://shitposter.club/users/lm9 +7063 https://shitposter.club/user/7063 https://shitposter.club/users/kbb +7064 https://shitposter.club/user/7064 https://shitposter.club/users/00 +7114 https://shitposter.club/user/7114 https://shitposter.club/users/sw0rn +7197 https://shitposter.club/user/7197 https://shitposter.club/users/skelepun +7204 https://shitposter.club/user/7204 https://shitposter.club/users/segata +7205 https://shitposter.club/user/7205 https://shitposter.club/users/niggerkiller6969 +7251 https://shitposter.club/user/7251 https://shitposter.club/users/kitredgrave +7261 https://shitposter.club/user/7261 https://shitposter.club/users/letters +7292 https://shitposter.club/user/7292 https://shitposter.club/users/goatholeonmy +7295 https://shitposter.club/user/7295 https://shitposter.club/users/varondus +7335 https://shitposter.club/user/7335 https://shitposter.club/users/arsaces +7339 https://shitposter.club/user/7339 https://shitposter.club/users/nixromina +7374 https://shitposter.club/user/7374 https://shitposter.club/users/vladdo +7436 https://shitposter.club/user/7436 https://shitposter.club/users/baery +7463 https://shitposter.club/user/7463 https://shitposter.club/users/bigdikk +7543 https://shitposter.club/user/7543 https://shitposter.club/users/bijorikoraku +7573 https://shitposter.club/user/7573 https://shitposter.club/users/mithras +7602 https://shitposter.club/user/7602 https://shitposter.club/users/timiddimwit +7614 https://shitposter.club/user/7614 https://shitposter.club/users/thricebitten003 +7640 https://shitposter.club/user/7640 https://shitposter.club/users/floopfloop +7664 https://shitposter.club/user/7664 https://shitposter.club/users/otakunopico +7686 https://shitposter.club/user/7686 https://shitposter.club/users/fashygoy +7703 https://shitposter.club/user/7703 https://shitposter.club/users/anonymous +7710 https://shitposter.club/user/7710 https://shitposter.club/users/wewlad +7720 https://shitposter.club/user/7720 https://shitposter.club/users/textophile +7732 https://shitposter.club/user/7732 https://shitposter.club/users/vetforumwars +7748 https://shitposter.club/user/7748 https://shitposter.club/users/chikimonki +7751 https://shitposter.club/user/7751 https://shitposter.club/users/s3krit +7752 https://shitposter.club/user/7752 https://shitposter.club/users/valka +7753 https://shitposter.club/user/7753 https://shitposter.club/users/notksj +7775 https://shitposter.club/user/7775 https://shitposter.club/users/femacampinmate +7777 https://shitposter.club/user/7777 https://shitposter.club/users/redbayp +7809 https://shitposter.club/user/7809 https://shitposter.club/users/wayy +7826 https://shitposter.club/user/7826 https://shitposter.club/users/eliotime3000 +8015 https://shitposter.club/user/8015 https://shitposter.club/users/beingham +8031 https://shitposter.club/user/8031 https://shitposter.club/users/cyberpotato +8058 https://shitposter.club/user/8058 https://shitposter.club/users/efina +8059 https://shitposter.club/user/8059 https://shitposter.club/users/milla +8060 https://shitposter.club/user/8060 https://shitposter.club/users/caden +8061 https://shitposter.club/user/8061 https://shitposter.club/users/tiz +8072 https://shitposter.club/user/8072 https://shitposter.club/users/mikemazzone +8079 https://shitposter.club/user/8079 https://shitposter.club/users/fraudexposer +8081 https://shitposter.club/user/8081 https://shitposter.club/users/redair +8084 https://shitposter.club/user/8084 https://shitposter.club/users/jmd +8093 https://shitposter.club/user/8093 https://shitposter.club/users/linkwood +8094 https://shitposter.club/user/8094 https://shitposter.club/users/stefan +8095 https://shitposter.club/user/8095 https://shitposter.club/users/perionic +8096 https://shitposter.club/user/8096 https://shitposter.club/users/retronet +8157 https://shitposter.club/user/8157 https://shitposter.club/users/culto +8181 https://shitposter.club/user/8181 https://shitposter.club/users/extrange +8194 https://shitposter.club/user/8194 https://shitposter.club/users/daniel197047 +8220 https://shitposter.club/user/8220 https://shitposter.club/users/schnapps +8227 https://shitposter.club/user/8227 https://shitposter.club/users/anonavenger +8256 https://shitposter.club/user/8256 https://shitposter.club/users/mikaela +8261 https://shitposter.club/user/8261 https://shitposter.club/users/loki +8330 https://shitposter.club/user/8330 https://shitposter.club/users/sloan +8337 https://shitposter.club/user/8337 https://shitposter.club/users/thehifman +8363 https://shitposter.club/user/8363 https://shitposter.club/users/threetoast +8410 https://shitposter.club/user/8410 https://shitposter.club/users/daphailwhale +8429 https://shitposter.club/user/8429 https://shitposter.club/users/jakob +8430 https://shitposter.club/user/8430 https://shitposter.club/users/stephenlynx +8433 https://shitposter.club/user/8433 https://shitposter.club/users/ayoholup +8463 https://shitposter.club/user/8463 https://shitposter.club/users/loltemp +8622 https://shitposter.club/user/8622 https://shitposter.club/users/chu +8635 https://shitposter.club/user/8635 https://shitposter.club/users/bilb +8639 https://shitposter.club/user/8639 https://shitposter.club/users/www +8644 https://shitposter.club/user/8644 https://shitposter.club/users/potus +8676 https://shitposter.club/user/8676 https://shitposter.club/users/testuser124578 +8716 https://shitposter.club/user/8716 https://shitposter.club/users/kentnelida +8853 https://shitposter.club/user/8853 https://shitposter.club/users/meff +8876 https://shitposter.club/user/8876 https://shitposter.club/users/liz +8896 https://shitposter.club/user/8896 https://shitposter.club/users/anonjustice +8974 https://shitposter.club/user/8974 https://shitposter.club/users/wintertsar +9052 https://shitposter.club/user/9052 https://shitposter.club/users/nerthos +9056 https://shitposter.club/user/9056 https://shitposter.club/users/mono +9089 https://shitposter.club/user/9089 https://shitposter.club/users/taeateh +9119 https://shitposter.club/user/9119 https://shitposter.club/users/twilly999 +9140 https://shitposter.club/user/9140 https://shitposter.club/users/poorlyreported +9157 https://shitposter.club/user/9157 https://shitposter.club/users/karabiner +9164 https://shitposter.club/user/9164 https://shitposter.club/users/spaceman +9176 https://shitposter.club/user/9176 https://shitposter.club/users/dbrz +9196 https://shitposter.club/user/9196 https://shitposter.club/users/meesa +9203 https://shitposter.club/user/9203 https://shitposter.club/users/tokage +9205 https://shitposter.club/user/9205 https://shitposter.club/users/adolfhitler +9223 https://shitposter.club/user/9223 https://shitposter.club/users/homotopy +9283 https://shitposter.club/user/9283 https://shitposter.club/users/alanman +9294 https://shitposter.club/user/9294 https://shitposter.club/users/posteur +9301 https://shitposter.club/user/9301 https://shitposter.club/users/mchnem +9329 https://shitposter.club/user/9329 https://shitposter.club/users/mm +9347 https://shitposter.club/user/9347 https://shitposter.club/users/caspermag +9348 https://shitposter.club/user/9348 https://shitposter.club/users/weimerica +9396 https://shitposter.club/user/9396 https://shitposter.club/users/fl1nt +9487 https://shitposter.club/user/9487 https://shitposter.club/users/heterowhiteman +9499 https://shitposter.club/user/9499 https://shitposter.club/users/bane +9521 https://shitposter.club/user/9521 https://shitposter.club/users/luke +9522 https://shitposter.club/user/9522 https://shitposter.club/users/friendlysmoker +9563 https://shitposter.club/user/9563 https://shitposter.club/users/momo +9565 https://shitposter.club/user/9565 https://shitposter.club/users/c1tyoffl1nt1 +9567 https://shitposter.club/user/9567 https://shitposter.club/users/takao +9568 https://shitposter.club/user/9568 https://shitposter.club/users/sim +9569 https://shitposter.club/user/9569 https://shitposter.club/users/sakuya +9572 https://shitposter.club/user/9572 https://shitposter.club/users/chiruno +9573 https://shitposter.club/user/9573 https://shitposter.club/users/usercorpse +9574 https://shitposter.club/user/9574 https://shitposter.club/users/yeetniqqa +9585 https://shitposter.club/user/9585 https://shitposter.club/users/subvert +9591 https://shitposter.club/user/9591 https://shitposter.club/users/hardbass2k8 +9620 https://shitposter.club/user/9620 https://shitposter.club/users/secretsquirrel +9654 https://shitposter.club/user/9654 https://shitposter.club/users/spacemandown +9655 https://shitposter.club/user/9655 https://shitposter.club/users/neimzr4luzerz +9664 https://shitposter.club/user/9664 https://shitposter.club/users/moontest +9695 https://shitposter.club/user/9695 https://shitposter.club/users/azurerose +9701 https://shitposter.club/user/9701 https://shitposter.club/users/leroilezard +9776 https://shitposter.club/user/9776 https://shitposter.club/users/awgeezrick +9879 https://shitposter.club/user/9879 https://shitposter.club/users/terezi +9885 https://shitposter.club/user/9885 https://shitposter.club/users/johnhenry +9968 https://shitposter.club/user/9968 https://shitposter.club/users/barf +10098 https://shitposter.club/user/10098 https://shitposter.club/users/mantis +10166 https://shitposter.club/user/10166 https://shitposter.club/users/anon +10260 https://shitposter.club/user/10260 https://shitposter.club/users/sonya +10394 https://shitposter.club/user/10394 https://shitposter.club/users/sarahjeong +10660 https://shitposter.club/user/10660 https://shitposter.club/users/kkitteh +10672 https://shitposter.club/user/10672 https://shitposter.club/users/data +10832 https://shitposter.club/user/10832 https://shitposter.club/users/marin +10963 https://shitposter.club/user/10963 https://shitposter.club/users/anthony +10986 https://shitposter.club/user/10986 https://shitposter.club/users/ashdroid +11068 https://shitposter.club/user/11068 https://shitposter.club/users/yair +11231 https://shitposter.club/user/11231 https://shitposter.club/users/dean +11262 https://shitposter.club/user/11262 https://shitposter.club/users/santiesteban +11401 https://shitposter.club/user/11401 https://shitposter.club/users/hughdarrow +11514 https://shitposter.club/user/11514 https://shitposter.club/users/mil +11604 https://shitposter.club/user/11604 https://shitposter.club/users/anime +11663 https://shitposter.club/user/11663 https://shitposter.club/users/jakk +11747 https://shitposter.club/user/11747 https://shitposter.club/users/buffyfan12 +11865 https://shitposter.club/user/11865 https://shitposter.club/users/thx2037 +11960 https://shitposter.club/user/11960 https://shitposter.club/users/gargron +12000 https://shitposter.club/user/12000 https://shitposter.club/users/chc4 +12046 https://shitposter.club/user/12046 https://shitposter.club/users/sergio +12115 https://shitposter.club/user/12115 https://shitposter.club/users/gooddoge +12235 https://shitposter.club/user/12235 https://shitposter.club/users/moonrise +12367 https://shitposter.club/user/12367 https://shitposter.club/users/0xdeadbabe +12519 https://shitposter.club/user/12519 https://shitposter.club/users/jesusaur +12577 https://shitposter.club/user/12577 https://shitposter.club/users/vpsorg +12693 https://shitposter.club/user/12693 https://shitposter.club/users/gnulibs +12695 https://shitposter.club/user/12695 https://shitposter.club/users/hydra +12699 https://shitposter.club/user/12699 https://shitposter.club/users/thegoldwater +12725 https://shitposter.club/user/12725 https://shitposter.club/users/pox +12820 https://shitposter.club/user/12820 https://shitposter.club/users/charafan +12822 https://shitposter.club/user/12822 https://shitposter.club/users/fly +12826 https://shitposter.club/user/12826 https://shitposter.club/users/jay +13068 https://shitposter.club/user/13068 https://shitposter.club/users/wannabe +13442 https://shitposter.club/user/13442 https://shitposter.club/users/twitter +13476 https://shitposter.club/user/13476 https://shitposter.club/users/huefee +13590 https://shitposter.club/user/13590 https://shitposter.club/users/d3wd +13712 https://shitposter.club/user/13712 https://shitposter.club/users/sacfly +13905 https://shitposter.club/user/13905 https://shitposter.club/users/athrygg +14115 https://shitposter.club/user/14115 https://shitposter.club/users/wolf +14145 https://shitposter.club/user/14145 https://shitposter.club/users/random +14158 https://shitposter.club/user/14158 https://shitposter.club/users/dm +14217 https://shitposter.club/user/14217 https://shitposter.club/users/okux +14533 https://shitposter.club/user/14533 https://shitposter.club/users/zeno +14612 https://shitposter.club/user/14612 https://shitposter.club/users/jk +14638 https://shitposter.club/user/14638 https://shitposter.club/users/grindecologist +14767 https://shitposter.club/user/14767 https://shitposter.club/users/skullum +14903 https://shitposter.club/user/14903 https://shitposter.club/users/tomey +14972 https://shitposter.club/user/14972 https://shitposter.club/users/uramekus +15044 https://shitposter.club/user/15044 https://shitposter.club/users/harlan +15118 https://shitposter.club/user/15118 https://shitposter.club/users/arash +15236 https://shitposter.club/user/15236 https://shitposter.club/users/coreilly +15371 https://shitposter.club/user/15371 https://shitposter.club/users/thisisnotanime +15416 https://shitposter.club/user/15416 https://shitposter.club/users/cg +15439 https://shitposter.club/user/15439 https://shitposter.club/users/wareya +15496 https://shitposter.club/user/15496 https://shitposter.club/users/auraninanettaadriana +15557 https://shitposter.club/user/15557 https://shitposter.club/users/dechi +15575 https://shitposter.club/user/15575 https://shitposter.club/users/vikohmeilaty +15578 https://shitposter.club/user/15578 https://shitposter.club/users/vikohsevmarmila +15581 https://shitposter.club/user/15581 https://shitposter.club/users/vikohalvianti +15587 https://shitposter.club/user/15587 https://shitposter.club/users/patriciamichelletangkangentot +15635 https://shitposter.club/user/15635 https://shitposter.club/users/novichok +16492 https://shitposter.club/user/16492 https://shitposter.club/users/oosh +16752 https://shitposter.club/user/16752 https://shitposter.club/users/floraplus +17083 https://shitposter.club/user/17083 https://shitposter.club/users/popeyethecunt +17319 https://shitposter.club/user/17319 https://shitposter.club/users/dctf +17581 https://shitposter.club/user/17581 https://shitposter.club/users/chriztheanvill +18540 https://shitposter.club/user/18540 https://shitposter.club/users/sabahsyria +18716 https://shitposter.club/user/18716 https://shitposter.club/users/dumbbabby +18855 https://shitposter.club/user/18855 https://shitposter.club/users/derpderpderp +19068 https://shitposter.club/user/19068 https://shitposter.club/users/ster +19095 https://shitposter.club/user/19095 https://shitposter.club/users/cajoh +19124 https://shitposter.club/user/19124 https://shitposter.club/users/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +19257 https://shitposter.club/user/19257 https://shitposter.club/users/friskan +19285 https://shitposter.club/user/19285 https://shitposter.club/users/zeo +19593 https://shitposter.club/user/19593 https://shitposter.club/users/akater +19649 https://shitposter.club/user/19649 https://shitposter.club/users/wololo +20046 https://shitposter.club/user/20046 https://shitposter.club/users/fujimura +20073 https://shitposter.club/user/20073 https://shitposter.club/users/jakethesnake +20267 https://shitposter.club/user/20267 https://shitposter.club/users/moontest2 +20426 https://shitposter.club/user/20426 https://shitposter.club/users/perspicacious01 +20651 https://shitposter.club/user/20651 https://shitposter.club/users/trivia +20686 https://shitposter.club/user/20686 https://shitposter.club/users/yovinnie +20759 https://shitposter.club/user/20759 https://shitposter.club/users/roytam +21026 https://shitposter.club/user/21026 https://shitposter.club/users/shakes31471 +21667 https://shitposter.club/user/21667 https://shitposter.club/users/bdjnk +21787 https://shitposter.club/user/21787 https://shitposter.club/users/cutscenes +21920 https://shitposter.club/user/21920 https://shitposter.club/users/rwdsaboo +21925 https://shitposter.club/user/21925 https://shitposter.club/users/mapomme +21934 https://shitposter.club/user/21934 https://shitposter.club/users/satori +22018 https://shitposter.club/user/22018 https://shitposter.club/users/vertu +22080 https://shitposter.club/user/22080 https://shitposter.club/users/raven +22177 https://shitposter.club/user/22177 https://shitposter.club/users/boa +22179 https://shitposter.club/user/22179 https://shitposter.club/users/tezcat +22230 https://shitposter.club/user/22230 https://shitposter.club/users/alex +22323 https://shitposter.club/user/22323 https://shitposter.club/users/tehsvin +22514 https://shitposter.club/user/22514 https://shitposter.club/users/shitehoney +22564 https://shitposter.club/user/22564 https://shitposter.club/users/becauseimgray +22706 https://shitposter.club/user/22706 https://shitposter.club/users/nimda +22883 https://shitposter.club/user/22883 https://shitposter.club/users/noflashfirm +22917 https://shitposter.club/user/22917 https://shitposter.club/users/silvertube +23288 https://shitposter.club/user/23288 https://shitposter.club/users/monad +23396 https://shitposter.club/user/23396 https://shitposter.club/users/mom +23576 https://shitposter.club/user/23576 https://shitposter.club/users/ntc +23735 https://shitposter.club/user/23735 https://shitposter.club/users/betobear730 +23872 https://shitposter.club/user/23872 https://shitposter.club/users/mackatron +23909 https://shitposter.club/user/23909 https://shitposter.club/users/johnnycumby +24048 https://shitposter.club/user/24048 https://shitposter.club/users/buttballoon +24247 https://shitposter.club/user/24247 https://shitposter.club/users/hoppeoffamychoppa +24370 https://shitposter.club/user/24370 https://shitposter.club/users/superjey +24519 https://shitposter.club/user/24519 https://shitposter.club/users/crufro +24550 https://shitposter.club/user/24550 https://shitposter.club/users/baseddrworm +24794 https://shitposter.club/user/24794 https://shitposter.club/users/marko +24893 https://shitposter.club/user/24893 https://shitposter.club/users/sweetnote +25222 https://shitposter.club/user/25222 https://shitposter.club/users/stiribune +25519 https://shitposter.club/user/25519 https://shitposter.club/users/taco +25726 https://shitposter.club/user/25726 https://shitposter.club/users/morbius +26103 https://shitposter.club/user/26103 https://shitposter.club/users/moonmanatgscon +26486 https://shitposter.club/user/26486 https://shitposter.club/users/lon +26603 https://shitposter.club/user/26603 https://shitposter.club/users/cj +26712 https://shitposter.club/user/26712 https://shitposter.club/users/existentialbro +26830 https://shitposter.club/user/26830 https://shitposter.club/users/weddingtorontolimo +26858 https://shitposter.club/user/26858 https://shitposter.club/users/hoskayne +27459 https://shitposter.club/user/27459 https://shitposter.club/users/dirb +27464 https://shitposter.club/user/27464 https://shitposter.club/users/assalchemy +27628 https://shitposter.club/user/27628 https://shitposter.club/users/walt1999walt +28122 https://shitposter.club/user/28122 https://shitposter.club/users/h8 +28526 https://shitposter.club/user/28526 https://shitposter.club/users/mariano +28601 https://shitposter.club/user/28601 https://shitposter.club/users/robofortune +28795 https://shitposter.club/user/28795 https://shitposter.club/users/falco +28892 https://shitposter.club/user/28892 https://shitposter.club/users/batemanboogers +28985 https://shitposter.club/user/28985 https://shitposter.club/users/pasty +28989 https://shitposter.club/user/28989 https://shitposter.club/users/podrickpaddington +29181 https://shitposter.club/user/29181 https://shitposter.club/users/ganix +29182 https://shitposter.club/user/29182 https://shitposter.club/users/marsprobe +29185 https://shitposter.club/user/29185 https://shitposter.club/users/tealdear +29251 https://shitposter.club/user/29251 https://shitposter.club/users/tico +29686 https://shitposter.club/user/29686 https://shitposter.club/users/pooryorick +29708 https://shitposter.club/user/29708 https://shitposter.club/users/vfp +29825 https://shitposter.club/user/29825 https://shitposter.club/users/camby +29856 https://shitposter.club/user/29856 https://shitposter.club/users/aqours +29857 https://shitposter.club/user/29857 https://shitposter.club/users/gaygrandma +29858 https://shitposter.club/user/29858 https://shitposter.club/users/zarya +29859 https://shitposter.club/user/29859 https://shitposter.club/users/ene +29969 https://shitposter.club/user/29969 https://shitposter.club/users/aw +30066 https://shitposter.club/user/30066 https://shitposter.club/users/oxenfree +30080 https://shitposter.club/user/30080 https://shitposter.club/users/roko +30202 https://shitposter.club/user/30202 https://shitposter.club/users/doingsomeposts +30241 https://shitposter.club/user/30241 https://shitposter.club/users/archaeme +30243 https://shitposter.club/user/30243 https://shitposter.club/users/zenpukku +30293 https://shitposter.club/user/30293 https://shitposter.club/users/styromaniac +30720 https://shitposter.club/user/30720 https://shitposter.club/users/thatbrickster +30748 https://shitposter.club/user/30748 https://shitposter.club/users/ryan +31040 https://shitposter.club/user/31040 https://shitposter.club/users/me +31101 https://shitposter.club/user/31101 https://shitposter.club/users/louiefillet +31132 https://shitposter.club/user/31132 https://shitposter.club/users/ok +31339 https://shitposter.club/user/31339 https://shitposter.club/users/alucard +31353 https://shitposter.club/user/31353 https://shitposter.club/users/spcnepfag +31536 https://shitposter.club/user/31536 https://shitposter.club/users/dmgctrl +31538 https://shitposter.club/user/31538 https://shitposter.club/users/lueyee +31714 https://shitposter.club/user/31714 https://shitposter.club/users/comstock +31832 https://shitposter.club/user/31832 https://shitposter.club/users/anotherwriter +31836 https://shitposter.club/user/31836 https://shitposter.club/users/luminous +31876 https://shitposter.club/user/31876 https://shitposter.club/users/toxic +31892 https://shitposter.club/user/31892 https://shitposter.club/users/soulkisser +31923 https://shitposter.club/user/31923 https://shitposter.club/users/piyush +31959 https://shitposter.club/user/31959 https://shitposter.club/users/lightlysalted +31973 https://shitposter.club/user/31973 https://shitposter.club/users/abr21 +31997 https://shitposter.club/user/31997 https://shitposter.club/users/demo +32079 https://shitposter.club/user/32079 https://shitposter.club/users/totallynotdogjaw +32123 https://shitposter.club/user/32123 https://shitposter.club/users/ctrlcreepbot +32158 https://shitposter.club/user/32158 https://shitposter.club/users/ben666 +32188 https://shitposter.club/user/32188 https://shitposter.club/users/polenstronkest +32201 https://shitposter.club/user/32201 https://shitposter.club/users/filthymcgarbage +32314 https://shitposter.club/user/32314 https://shitposter.club/users/notjeff +32324 https://shitposter.club/user/32324 https://shitposter.club/users/tanteifaust +32326 https://shitposter.club/user/32326 https://shitposter.club/users/vimtingu +32329 https://shitposter.club/user/32329 https://shitposter.club/users/dolus +32343 https://shitposter.club/user/32343 https://shitposter.club/users/sonicdreadzhog +32383 https://shitposter.club/user/32383 https://shitposter.club/users/nignog +32386 https://shitposter.club/user/32386 https://shitposter.club/users/owl +32390 https://shitposter.club/user/32390 https://shitposter.club/users/yoroshiku +32444 https://shitposter.club/user/32444 https://shitposter.club/users/chelzgrimace0 +32460 https://shitposter.club/user/32460 https://shitposter.club/users/mei +32466 https://shitposter.club/user/32466 https://shitposter.club/users/demigodloligagger +32690 https://shitposter.club/user/32690 https://shitposter.club/users/camoceltic +32736 https://shitposter.club/user/32736 https://shitposter.club/users/flamingkazin +33044 https://shitposter.club/user/33044 https://shitposter.club/users/root +33191 https://shitposter.club/user/33191 https://shitposter.club/users/949f45ac +33422 https://shitposter.club/user/33422 https://shitposter.club/users/surge +33683 https://shitposter.club/user/33683 https://shitposter.club/users/dielan +33789 https://shitposter.club/user/33789 https://shitposter.club/users/fickle +34011 https://shitposter.club/user/34011 https://shitposter.club/users/nurnymurse +34442 https://shitposter.club/user/34442 https://shitposter.club/users/ragecage +34659 https://shitposter.club/user/34659 https://shitposter.club/users/fuckinghackers +35102 https://shitposter.club/user/35102 https://shitposter.club/users/robotx +35167 https://shitposter.club/user/35167 https://shitposter.club/users/sojourner +35180 https://shitposter.club/user/35180 https://shitposter.club/users/dogjaw +35198 https://shitposter.club/user/35198 https://shitposter.club/users/radicooloperative +35340 https://shitposter.club/user/35340 https://shitposter.club/users/sn +35402 https://shitposter.club/user/35402 https://shitposter.club/users/demifiend +35510 https://shitposter.club/user/35510 https://shitposter.club/users/tempo +35623 https://shitposter.club/user/35623 https://shitposter.club/users/lphovercraft +35631 https://shitposter.club/user/35631 https://shitposter.club/users/realhitler +35775 https://shitposter.club/user/35775 https://shitposter.club/users/kian +35930 https://shitposter.club/user/35930 https://shitposter.club/users/jjcarter21r +36077 https://shitposter.club/user/36077 https://shitposter.club/users/wehateweebs +36115 https://shitposter.club/user/36115 https://shitposter.club/users/theplaguedr +36172 https://shitposter.club/user/36172 https://shitposter.club/users/surfinbird +36381 https://shitposter.club/user/36381 https://shitposter.club/users/sireebob +36384 https://shitposter.club/user/36384 https://shitposter.club/users/127001 +36717 https://shitposter.club/user/36717 https://shitposter.club/users/justaghost +36821 https://shitposter.club/user/36821 https://shitposter.club/users/shadow +36888 https://shitposter.club/user/36888 https://shitposter.club/users/moe +37046 https://shitposter.club/user/37046 https://shitposter.club/users/moe123 +37300 https://shitposter.club/user/37300 https://shitposter.club/users/lulinvega +37326 https://shitposter.club/user/37326 https://shitposter.club/users/haisenberg +37954 https://shitposter.club/user/37954 https://shitposter.club/users/kg +38017 https://shitposter.club/user/38017 https://shitposter.club/users/yvvu2 +38219 https://shitposter.club/user/38219 https://shitposter.club/users/spooks +38322 https://shitposter.club/user/38322 https://shitposter.club/users/invlpg +38364 https://shitposter.club/user/38364 https://shitposter.club/users/krochpuncher +38382 https://shitposter.club/user/38382 https://shitposter.club/users/artifaxxs +38482 https://shitposter.club/user/38482 https://shitposter.club/users/windclock +38491 https://shitposter.club/user/38491 https://shitposter.club/users/lobster +38618 https://shitposter.club/user/38618 https://shitposter.club/users/birdway +38733 https://shitposter.club/user/38733 https://shitposter.club/users/sulter +38796 https://shitposter.club/user/38796 https://shitposter.club/users/zika +38979 https://shitposter.club/user/38979 https://shitposter.club/users/manghoti +39546 https://shitposter.club/user/39546 https://shitposter.club/users/zlowiec +40673 https://shitposter.club/user/40673 https://shitposter.club/users/aaa +41496 https://shitposter.club/user/41496 https://shitposter.club/users/polywuf +41717 https://shitposter.club/user/41717 https://shitposter.club/users/shirtlords +41735 https://shitposter.club/user/41735 https://shitposter.club/users/vced01tbkrcy +41780 https://shitposter.club/user/41780 https://shitposter.club/users/reggiehathaway +41786 https://shitposter.club/user/41786 https://shitposter.club/users/parisc +41794 https://shitposter.club/user/41794 https://shitposter.club/users/nutjin +41801 https://shitposter.club/user/41801 https://shitposter.club/users/angelus +41836 https://shitposter.club/user/41836 https://shitposter.club/users/big +41985 https://shitposter.club/user/41985 https://shitposter.club/users/wario +42081 https://shitposter.club/user/42081 https://shitposter.club/users/animesniffer +42098 https://shitposter.club/user/42098 https://shitposter.club/users/yappariesaka +42115 https://shitposter.club/user/42115 https://shitposter.club/users/stjude +42120 https://shitposter.club/user/42120 https://shitposter.club/users/gaiusgermanicus +42260 https://shitposter.club/user/42260 https://shitposter.club/users/loveliestamie +42347 https://shitposter.club/user/42347 https://shitposter.club/users/ginz +42354 https://shitposter.club/user/42354 https://shitposter.club/users/antiracist +42363 https://shitposter.club/user/42363 https://shitposter.club/users/matthewmaci +42472 https://shitposter.club/user/42472 https://shitposter.club/users/rubberback +42927 https://shitposter.club/user/42927 https://shitposter.club/users/hatexgroup +42968 https://shitposter.club/user/42968 https://shitposter.club/users/gloriouscarwash +42997 https://shitposter.club/user/42997 https://shitposter.club/users/yayo +43012 https://shitposter.club/user/43012 https://shitposter.club/users/robloxhentie88 +43092 https://shitposter.club/user/43092 https://shitposter.club/users/haspop +43167 https://shitposter.club/user/43167 https://shitposter.club/users/walmartsupremacy +43268 https://shitposter.club/user/43268 https://shitposter.club/users/golpollo +43272 https://shitposter.club/user/43272 https://shitposter.club/users/rrx +43276 https://shitposter.club/user/43276 https://shitposter.club/users/rusty +43336 https://shitposter.club/user/43336 https://shitposter.club/users/caesarcrab +43384 https://shitposter.club/user/43384 https://shitposter.club/users/yap +43440 https://shitposter.club/user/43440 https://shitposter.club/users/triplekmafia +43443 https://shitposter.club/user/43443 https://shitposter.club/users/antonnizhny +43583 https://shitposter.club/user/43583 https://shitposter.club/users/cajon +43744 https://shitposter.club/user/43744 https://shitposter.club/users/dixieconstruct +43764 https://shitposter.club/user/43764 https://shitposter.club/users/pepsicanex +43776 https://shitposter.club/user/43776 https://shitposter.club/users/deraristokraut +43779 https://shitposter.club/user/43779 https://shitposter.club/users/red +43783 https://shitposter.club/user/43783 https://shitposter.club/users/boxiekun +43791 https://shitposter.club/user/43791 https://shitposter.club/users/emilia +43866 https://shitposter.club/user/43866 https://shitposter.club/users/qwerty +44035 https://shitposter.club/user/44035 https://shitposter.club/users/aspirator +44303 https://shitposter.club/user/44303 https://shitposter.club/users/cereal +44541 https://shitposter.club/user/44541 https://shitposter.club/users/animerapist +44666 https://shitposter.club/user/44666 https://shitposter.club/users/za +44681 https://shitposter.club/user/44681 https://shitposter.club/users/suicidal +44751 https://shitposter.club/user/44751 https://shitposter.club/users/illuminatoskeletono +45219 https://shitposter.club/user/45219 https://shitposter.club/users/sierrakilobravo +45312 https://shitposter.club/user/45312 https://shitposter.club/users/thufir +45467 https://shitposter.club/user/45467 https://shitposter.club/users/fermtnzheavy +45873 https://shitposter.club/user/45873 https://shitposter.club/users/jector +46020 https://shitposter.club/user/46020 https://shitposter.club/users/shitlordsupreme +46273 https://shitposter.club/user/46273 https://shitposter.club/users/y88 +46347 https://shitposter.club/user/46347 https://shitposter.club/users/catk111er +46752 https://shitposter.club/user/46752 https://shitposter.club/users/pr333 +46808 https://shitposter.club/user/46808 https://shitposter.club/users/catkittens +47284 https://shitposter.club/user/47284 https://shitposter.club/users/123lareputarana +47359 https://shitposter.club/user/47359 https://shitposter.club/users/traplordegen +47368 https://shitposter.club/user/47368 https://shitposter.club/users/norm +47569 https://shitposter.club/user/47569 https://shitposter.club/users/grass +47770 https://shitposter.club/user/47770 https://shitposter.club/users/realdavidreed +47943 https://shitposter.club/user/47943 https://shitposter.club/users/watch +48103 https://shitposter.club/user/48103 https://shitposter.club/users/bagel +48130 https://shitposter.club/user/48130 https://shitposter.club/users/stochastix +48329 https://shitposter.club/user/48329 https://shitposter.club/users/mewlan +48389 https://shitposter.club/user/48389 https://shitposter.club/users/andilinks +48440 https://shitposter.club/user/48440 https://shitposter.club/users/ao +48495 https://shitposter.club/user/48495 https://shitposter.club/users/futuredogefm +48496 https://shitposter.club/user/48496 https://shitposter.club/users/harold +48611 https://shitposter.club/user/48611 https://shitposter.club/users/hattiecat +48712 https://shitposter.club/user/48712 https://shitposter.club/users/mrmcmayhem +49233 https://shitposter.club/user/49233 https://shitposter.club/users/sushipantsu +49746 https://shitposter.club/user/49746 https://shitposter.club/users/siedge +49752 https://shitposter.club/user/49752 https://shitposter.club/users/honorrollcc +49829 https://shitposter.club/user/49829 https://shitposter.club/users/denza252 +49856 https://shitposter.club/user/49856 https://shitposter.club/users/web +49863 https://shitposter.club/user/49863 https://shitposter.club/users/donglord +49933 https://shitposter.club/user/49933 https://shitposter.club/users/chargedaffaires +50092 https://shitposter.club/user/50092 https://shitposter.club/users/joy +50183 https://shitposter.club/user/50183 https://shitposter.club/users/gravityfailsme +50216 https://shitposter.club/user/50216 https://shitposter.club/users/installgen2 +50331 https://shitposter.club/user/50331 https://shitposter.club/users/robbie +50332 https://shitposter.club/user/50332 https://shitposter.club/users/xirus11 +50339 https://shitposter.club/user/50339 https://shitposter.club/users/glendo +50340 https://shitposter.club/user/50340 https://shitposter.club/users/minus2 +51031 https://shitposter.club/user/51031 https://shitposter.club/users/kekmeister +51033 https://shitposter.club/user/51033 https://shitposter.club/users/akitosenshi +51037 https://shitposter.club/user/51037 https://shitposter.club/users/ganjabots +51337 https://shitposter.club/user/51337 https://shitposter.club/users/sadanimeman +51693 https://shitposter.club/user/51693 https://shitposter.club/users/iamfubar +51699 https://shitposter.club/user/51699 https://shitposter.club/users/honk +51732 https://shitposter.club/user/51732 https://shitposter.club/users/trash +51733 https://shitposter.club/user/51733 https://shitposter.club/users/normsndy +51827 https://shitposter.club/user/51827 https://shitposter.club/users/zeppy +52063 https://shitposter.club/user/52063 https://shitposter.club/users/anomaleon +52122 https://shitposter.club/user/52122 https://shitposter.club/users/huh +52172 https://shitposter.club/user/52172 https://shitposter.club/users/erzaknightfr +52276 https://shitposter.club/user/52276 https://shitposter.club/users/antasmeme +52457 https://shitposter.club/user/52457 https://shitposter.club/users/girl +52906 https://shitposter.club/user/52906 https://shitposter.club/users/threaddotrun +53474 https://shitposter.club/user/53474 https://shitposter.club/users/starz0r +53716 https://shitposter.club/user/53716 https://shitposter.club/users/yoyo +53967 https://shitposter.club/user/53967 https://shitposter.club/users/sebas +54382 https://shitposter.club/user/54382 https://shitposter.club/users/thndr +54503 https://shitposter.club/user/54503 https://shitposter.club/users/xenonman +54700 https://shitposter.club/user/54700 https://shitposter.club/users/crewofweebs +54831 https://shitposter.club/user/54831 https://shitposter.club/users/gutfuckllc +54859 https://shitposter.club/user/54859 https://shitposter.club/users/zeptat +54860 https://shitposter.club/user/54860 https://shitposter.club/users/zeptar +54876 https://shitposter.club/user/54876 https://shitposter.club/users/vf +55355 https://shitposter.club/user/55355 https://shitposter.club/users/arilando +55371 https://shitposter.club/user/55371 https://shitposter.club/users/deanberryministry +55616 https://shitposter.club/user/55616 https://shitposter.club/users/fatma +55866 https://shitposter.club/user/55866 https://shitposter.club/users/rice +56213 https://shitposter.club/user/56213 https://shitposter.club/users/atdirb +56789 https://shitposter.club/user/56789 https://shitposter.club/users/elshibes +57573 https://shitposter.club/user/57573 https://shitposter.club/users/cyberfreedom +57627 https://shitposter.club/user/57627 https://shitposter.club/users/asdf +57700 https://shitposter.club/user/57700 https://shitposter.club/users/awl +57958 https://shitposter.club/user/57958 https://shitposter.club/users/shitlord +58248 https://shitposter.club/user/58248 https://shitposter.club/users/johnnyneptune +58348 https://shitposter.club/user/58348 https://shitposter.club/users/littleman +58755 https://shitposter.club/user/58755 https://shitposter.club/users/loke +58802 https://shitposter.club/user/58802 https://shitposter.club/users/mysize69 +58859 https://shitposter.club/user/58859 https://shitposter.club/users/crablettes +58862 https://shitposter.club/user/58862 https://shitposter.club/users/fleshlightme +59088 https://shitposter.club/user/59088 https://shitposter.club/users/2rude +59930 https://shitposter.club/user/59930 https://shitposter.club/users/gonk +59955 https://shitposter.club/user/59955 https://shitposter.club/users/squidink +60066 https://shitposter.club/user/60066 https://shitposter.club/users/llxyo +60185 https://shitposter.club/user/60185 https://shitposter.club/users/scrawls +60544 https://shitposter.club/user/60544 https://shitposter.club/users/sigma +60790 https://shitposter.club/user/60790 https://shitposter.club/users/therealkayne +60794 https://shitposter.club/user/60794 https://shitposter.club/users/nanex +61124 https://shitposter.club/user/61124 https://shitposter.club/users/ejs +61307 https://shitposter.club/user/61307 https://shitposter.club/users/skeet +61456 https://shitposter.club/user/61456 https://shitposter.club/users/agentorange +61646 https://shitposter.club/user/61646 https://shitposter.club/users/toad +61652 https://shitposter.club/user/61652 https://shitposter.club/users/kuuomena +61767 https://shitposter.club/user/61767 https://shitposter.club/users/coolboymew +61770 https://shitposter.club/user/61770 https://shitposter.club/users/4fl0wn +61782 https://shitposter.club/user/61782 https://shitposter.club/users/borzoi +61839 https://shitposter.club/user/61839 https://shitposter.club/users/chazcon +61923 https://shitposter.club/user/61923 https://shitposter.club/users/tharsis +62000 https://shitposter.club/user/62000 https://shitposter.club/users/redboooook +62134 https://shitposter.club/user/62134 https://shitposter.club/users/aven +62194 https://shitposter.club/user/62194 https://shitposter.club/users/haydenjones +64293 https://shitposter.club/user/64293 https://shitposter.club/users/yoongi +64357 https://shitposter.club/user/64357 https://shitposter.club/users/cow2001 +64605 https://shitposter.club/user/64605 https://shitposter.club/users/tidux +64672 https://shitposter.club/user/64672 https://shitposter.club/users/d4klutz +64681 https://shitposter.club/user/64681 https://shitposter.club/users/nucleasthete +64727 https://shitposter.club/user/64727 https://shitposter.club/users/hurley +64748 https://shitposter.club/user/64748 https://shitposter.club/users/drgutfuckllc +64759 https://shitposter.club/user/64759 https://shitposter.club/users/0x68756973 +64882 https://shitposter.club/user/64882 https://shitposter.club/users/night +65019 https://shitposter.club/user/65019 https://shitposter.club/users/macgirvin +65080 https://shitposter.club/user/65080 https://shitposter.club/users/jeremiah +65083 https://shitposter.club/user/65083 https://shitposter.club/users/lawlcat +65087 https://shitposter.club/user/65087 https://shitposter.club/users/trippinkitty420 +65330 https://shitposter.club/user/65330 https://shitposter.club/users/leibwiht +65350 https://shitposter.club/user/65350 https://shitposter.club/users/nagiept +65532 https://shitposter.club/user/65532 https://shitposter.club/users/corzetan +66560 https://shitposter.club/user/66560 https://shitposter.club/users/footkage +66562 https://shitposter.club/user/66562 https://shitposter.club/users/pdpineapple +66709 https://shitposter.club/user/66709 https://shitposter.club/users/nigger +66897 https://shitposter.club/user/66897 https://shitposter.club/users/djzep +67554 https://shitposter.club/user/67554 https://shitposter.club/users/linuxsocist +68329 https://shitposter.club/user/68329 https://shitposter.club/users/fris +68895 https://shitposter.club/user/68895 https://shitposter.club/users/nobodyeverywhere +69714 https://shitposter.club/user/69714 https://shitposter.club/users/3000iq +69906 https://shitposter.club/user/69906 https://shitposter.club/users/trustandsaftey +70237 https://shitposter.club/user/70237 https://shitposter.club/users/pd +70249 https://shitposter.club/user/70249 https://shitposter.club/users/markm447 +70798 https://shitposter.club/user/70798 https://shitposter.club/users/sleepfight3r +71463 https://shitposter.club/user/71463 https://shitposter.club/users/jello +71487 https://shitposter.club/user/71487 https://shitposter.club/users/canonicalbrud +71511 https://shitposter.club/user/71511 https://shitposter.club/users/tahu +71605 https://shitposter.club/user/71605 https://shitposter.club/users/noisepollution +71642 https://shitposter.club/user/71642 https://shitposter.club/users/nekolover +72807 https://shitposter.club/user/72807 https://shitposter.club/users/hiddengabber +72824 https://shitposter.club/user/72824 https://shitposter.club/users/oversaturation +72842 https://shitposter.club/user/72842 https://shitposter.club/users/uh +72864 https://shitposter.club/user/72864 https://shitposter.club/users/iajasom +73079 https://shitposter.club/user/73079 https://shitposter.club/users/thunder +73228 https://shitposter.club/user/73228 https://shitposter.club/users/makin +73386 https://shitposter.club/user/73386 https://shitposter.club/users/nevergofullweev +73642 https://shitposter.club/user/73642 https://shitposter.club/users/uxredbyte +73920 https://shitposter.club/user/73920 https://shitposter.club/users/billadoid +73987 https://shitposter.club/user/73987 https://shitposter.club/users/tuturu +74440 https://shitposter.club/user/74440 https://shitposter.club/users/pennyfortheguy +74699 https://shitposter.club/user/74699 https://shitposter.club/users/pururu +74818 https://shitposter.club/user/74818 https://shitposter.club/users/mikem +74940 https://shitposter.club/user/74940 https://shitposter.club/users/undeadmockingbird +75019 https://shitposter.club/user/75019 https://shitposter.club/users/spot +75051 https://shitposter.club/user/75051 https://shitposter.club/users/veruune +75147 https://shitposter.club/user/75147 https://shitposter.club/users/millysoose +75390 https://shitposter.club/user/75390 https://shitposter.club/users/onyxxgoodmann +75534 https://shitposter.club/user/75534 https://shitposter.club/users/voxumbra +75823 https://shitposter.club/user/75823 https://shitposter.club/users/kvazarig +75893 https://shitposter.club/user/75893 https://shitposter.club/users/cobodo +76045 https://shitposter.club/user/76045 https://shitposter.club/users/enkidoodle +76090 https://shitposter.club/user/76090 https://shitposter.club/users/judasdervierte +76309 https://shitposter.club/user/76309 https://shitposter.club/users/itsale +76353 https://shitposter.club/user/76353 https://shitposter.club/users/drump +76858 https://shitposter.club/user/76858 https://shitposter.club/users/gudgames +76890 https://shitposter.club/user/76890 https://shitposter.club/users/yomama +77082 https://shitposter.club/user/77082 https://shitposter.club/users/nowayinhell +78315 https://shitposter.club/user/78315 https://shitposter.club/users/zp +78737 https://shitposter.club/user/78737 https://shitposter.club/users/fr +79635 https://shitposter.club/user/79635 https://shitposter.club/users/fl0wnspc +81502 https://shitposter.club/user/81502 https://shitposter.club/users/tester2 -- cgit v1.2.3 From bd6c12592e9ae9548172c605d00650d4d6b734dc Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 18 Jan 2019 19:35:47 +0100 Subject: Add migration to fix spc users. --- lib/pleroma/spc_fixes/spc_fixes.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/spc_fixes/spc_fixes.ex b/lib/pleroma/spc_fixes/spc_fixes.ex index aa4830b51..e937d5871 100644 --- a/lib/pleroma/spc_fixes/spc_fixes.ex +++ b/lib/pleroma/spc_fixes/spc_fixes.ex @@ -4,7 +4,6 @@ alias Pleroma.Repo alias Pleroma.User -# alias Pleroma.Web.ActivityPub.Transmogrifier import Ecto.Query defmodule Pleroma.SpcFixes do -- cgit v1.2.3 From e116e55cabb34d468866231d1690421792c27a0c Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Fri, 18 Jan 2019 22:40:52 +0300 Subject: Add actor to recipients --- lib/pleroma/web/activity_pub/activity_pub.ex | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 5b87f7462..487d4c84a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -36,6 +36,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {recipients, to, cc} end + defp get_recipients(%{"type" => "Create"} = data) do + to = data["to"] || [] + cc = data["cc"] || [] + actor = data["actor"] || [] + recipients = (to ++ cc ++ [actor]) |> Enum.uniq() + {recipients, to, cc} + end + defp get_recipients(data) do to = data["to"] || [] cc = data["cc"] || [] -- cgit v1.2.3 From 651a1d64b53db061cc6a24099e706a64cc6d6dd8 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Sat, 19 Jan 2019 04:25:15 +0300 Subject: Add current user to mentioned --- lib/pleroma/web/twitter_api/representers/activity_representer.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 4f8f228ab..0ddbef634 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -155,7 +155,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || []) pinned = activity.id in user.info.pinned_activities - mentions = opts[:mentioned] || [] + mentions = get_mentioned_users(opts[:mentioned] || [], user) attentions = activity.recipients @@ -224,6 +224,10 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do end end + defp get_mentioned_users(mentioned, user) do + mentioned ++ [user] + end + defp to_boolean(false) do false end -- cgit v1.2.3 From afd83db0d7be4890dd345ba1f78e46da8b74d449 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 19 Jan 2019 10:58:27 +0300 Subject: Provide local og:url for remote activities --- lib/pleroma/web/metadata/opengraph.ex | 3 ++- lib/pleroma/web/ostatus/ostatus_controller.ex | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 1028e35c2..30333785e 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -13,6 +13,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do @impl Provider def build_tags(%{ object: object, + url: url, user: user }) do attachments = build_attachments(object) @@ -37,7 +38,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do property: "og:title", content: "#{user.name}" <> content ], []}, - {:meta, [property: "og:url", content: object.data["id"]], []}, + {:meta, [property: "og:url", content: url], []}, {:meta, [ property: "og:description", diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 4844b84ad..f04754f08 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -150,6 +150,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do Fallback.RedirectController.redirector_with_meta(conn, %{ object: object, + url: Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity.id), user: user }) else -- cgit v1.2.3 From 44693fbf6e5c5ec5622207e263688e3af7d1a83a Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sun, 20 Jan 2019 01:28:46 +0300 Subject: Formating --- lib/pleroma/web/ostatus/ostatus_controller.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index f04754f08..e94c5415a 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -150,7 +150,12 @@ defmodule Pleroma.Web.OStatus.OStatusController do Fallback.RedirectController.redirector_with_meta(conn, %{ object: object, - url: Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity.id), + url: + Pleroma.Web.Router.Helpers.o_status_url( + Pleroma.Web.Endpoint, + :notice, + activity.id + ), user: user }) else -- cgit v1.2.3 From b108aeee082949e2e534f8bc406fdacb8924803d Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 20 Jan 2019 00:31:17 +0100 Subject: Make use of the indices. Indices in postgresql rely on operators, so they won't be used if you use only functions. --- lib/pleroma/user.ex | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index eb4218ebe..87815e11c 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -734,7 +734,16 @@ defmodule Pleroma.User do ^processed_query ) }, - where: not is_nil(u.nickname) + where: + fragment( + """ + (setweight(to_tsvector('simple', regexp_replace(?, '\\W', ' ', 'g')), 'A') || + setweight(to_tsvector('simple', regexp_replace(coalesce(?, ''), '\\W', ' ', 'g')), 'B')) @@ to_tsquery('simple', ?) + """, + u.nickname, + u.name, + ^processed_query + ) ) end @@ -750,7 +759,7 @@ defmodule Pleroma.User do u.name ) }, - where: not is_nil(u.nickname) + where: fragment("trim(? || ' ' || coalesce(?, '')) % ?", u.nickname, u.name, ^query) ) end -- cgit v1.2.3 From 8d06be35e0f1cb5caa2b638330c8bb03ad08a127 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 15:51:02 +0000 Subject: activitypub: utils: add determine_explicit_mentions() and tests --- lib/pleroma/web/activity_pub/utils.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index d2e457a68..d516818d9 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -25,6 +25,20 @@ defmodule Pleroma.Web.ActivityPub.Utils do Map.put(params, "actor", get_ap_id(params["actor"])) end + def determine_explicit_mentions(%{"tag" => tag} = _object) when is_list(tag) do + tag + |> Enum.filter(fn x -> is_map(x) end) + |> Enum.filter(fn x -> x["type"] == "Mention" end) + |> Enum.map(fn x -> x["href"] end) + end + + def determine_explicit_mentions(%{"tag" => tag} = object) when is_map(tag) do + Map.put(object, "tag", [tag]) + |> determine_explicit_mentions() + end + + def determine_explicit_mentions(_), do: [] + defp recipient_in_collection(ap_id, coll) when is_binary(coll), do: ap_id == coll defp recipient_in_collection(ap_id, coll) when is_list(coll), do: ap_id in coll defp recipient_in_collection(_, _), do: false -- cgit v1.2.3 From 681f40ee5c4de644c79f71bb6671c4c63b18e68a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 16:05:41 +0000 Subject: activitypub: transmogrifier: fix up to/cc addressing brain damage caused by mastodon-style explicit DMs --- lib/pleroma/web/activity_pub/transmogrifier.ex | 42 ++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index fa3abe3d8..e9a801cf5 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -93,12 +93,42 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do end end - def fix_addressing(map) do - map - |> fix_addressing_list("to") - |> fix_addressing_list("cc") - |> fix_addressing_list("bto") - |> fix_addressing_list("bcc") + def fix_explicit_addressing(%{"to" => to, "cc" => cc} = object, explicit_mentions) do + explicit_to = + to + |> Enum.filter(fn x -> x in explicit_mentions end) + + explicit_cc = + to + |> Enum.filter(fn x -> x not in explicit_mentions end) + + final_cc = + (cc ++ explicit_cc) + |> Enum.uniq() + + object + |> Map.put("to", explicit_to) + |> Map.put("cc", final_cc) + end + + def fix_explicit_addressing(object, _explicit_mentions), do: object + + def fix_addressing(object) do + object = + object + |> fix_addressing_list("to") + |> fix_addressing_list("cc") + |> fix_addressing_list("bto") + |> fix_addressing_list("bcc") + + explicit_mentions = + object + |> Utils.determine_explicit_mentions() + + explicit_mentions = explicit_mentions ++ ["https://www.w3.org/ns/activitystreams#Public"] + + object + |> fix_explicit_addressing(explicit_mentions) end def fix_actor(%{"attributedTo" => actor} = object) do -- cgit v1.2.3 From 75dfa1f0b07806908b11735afab3ba0dd3149659 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 16:30:44 +0000 Subject: mastodon api: get_visibility(): DMs never have a cc list. --- lib/pleroma/web/mastodon_api/views/status_view.ex | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 7f5a52ea3..feabf54c6 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -231,6 +231,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do Enum.any?(to, &String.contains?(&1, "/followers")) -> "private" + length(cc) > 0 -> + "private" + true -> "direct" end -- cgit v1.2.3 From 9adc80afff5ea42e1773c6ada5e078ec6c1cadc8 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 15:26:07 +0000 Subject: common api: set directMessage flag on our own posts --- lib/pleroma/web/common_api/common_api.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 504670439..7084da6de 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -143,7 +143,7 @@ defmodule Pleroma.Web.CommonAPI do actor: user, context: context, object: object, - additional: %{"cc" => cc} + additional: %{"cc" => cc, "directMessage" => visibility == "direct"} }) res -- cgit v1.2.3 From ddae43eb43c5c63eeb0e93e60917b99b3ffb41d0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 15:27:08 +0000 Subject: activitypub: add is_private?/is_direct? helpers --- lib/pleroma/web/activity_pub/activity_pub.ex | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 130c06028..1fedfa854 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -805,6 +805,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do "https://www.w3.org/ns/activitystreams#Public" in (data["to"] ++ (data["cc"] || [])) end + def is_private?(activity) do + !is_public?(activity) && Enum.any?(activity.data["to"], &String.contains?(&1, "/followers")) + end + + def is_direct?(activity) do + !is_public?(activity) && !is_private?(activity) + end + def visible_for_user?(activity, nil) do is_public?(activity) end -- cgit v1.2.3 From 420651157becb8fac62e651d14376b6334316121 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 15:35:49 +0000 Subject: transmogrifier: don't apply heuristics against messages which have `directMessage` set true --- lib/pleroma/web/activity_pub/transmogrifier.ex | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index e9a801cf5..5400aa657 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -113,14 +113,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do def fix_explicit_addressing(object, _explicit_mentions), do: object - def fix_addressing(object) do - object = - object - |> fix_addressing_list("to") - |> fix_addressing_list("cc") - |> fix_addressing_list("bto") - |> fix_addressing_list("bcc") + # if directMessage flag is set to true, leave the addressing alone + def fix_explicit_addressing(%{"directMessage" => true} = object), do: object + def fix_explicit_addressing(object) do explicit_mentions = object |> Utils.determine_explicit_mentions() @@ -131,6 +127,14 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do |> fix_explicit_addressing(explicit_mentions) end + def fix_addressing(object) do + object + |> fix_addressing_list("to") + |> fix_addressing_list("cc") + |> fix_addressing_list("bto") + |> fix_addressing_list("bcc") + end + def fix_actor(%{"attributedTo" => actor} = object) do object |> Map.put("actor", get_actor(%{"actor" => actor})) @@ -363,6 +367,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do data = Map.put(data, "actor", actor) |> fix_addressing + |> fix_explicit_addressing with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]), %User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do @@ -378,6 +383,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do additional: Map.take(data, [ "cc", + "directMessage", "id" ]) } -- cgit v1.2.3 From 7c9749f793aa0970a36742bf4177c1a9899b1ff4 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 15:44:26 +0000 Subject: transmogrifier: slightly clean up fix_explicit_addressing pipeline --- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 5400aa657..5d3feccfe 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -133,6 +133,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do |> fix_addressing_list("cc") |> fix_addressing_list("bto") |> fix_addressing_list("bcc") + |> fix_explicit_addressing end def fix_actor(%{"attributedTo" => actor} = object) do @@ -367,7 +368,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do data = Map.put(data, "actor", actor) |> fix_addressing - |> fix_explicit_addressing with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]), %User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do -- cgit v1.2.3 From aa37313416c155a37b40e09617eb2fe524edbf0b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 20 Jan 2019 02:30:29 +0000 Subject: activitypub: short-circuit is_public?() with directMessage flag check --- lib/pleroma/web/activity_pub/activity_pub.ex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 1fedfa854..68b684c4b 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -800,6 +800,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def is_public?(%Object{data: %{"type" => "Tombstone"}}), do: false def is_public?(%Object{data: data}), do: is_public?(data) def is_public?(%Activity{data: data}), do: is_public?(data) + def is_public?(%{"directMessage" => true}), do: false def is_public?(data) do "https://www.w3.org/ns/activitystreams#Public" in (data["to"] ++ (data["cc"] || [])) @@ -809,6 +810,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do !is_public?(activity) && Enum.any?(activity.data["to"], &String.contains?(&1, "/followers")) end + def is_direct?(%Activity{data: %{"directMessage" => true}}), do: true + def is_direct?(%Object{data: %{"directMessage" => true}}), do: true + def is_direct?(activity) do !is_public?(activity) && !is_private?(activity) end -- cgit v1.2.3 From 5834b08fe77250d1dad0f2f6cd148f2fd8f85c09 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 20 Jan 2019 10:57:49 +0100 Subject: Set custom similarity limit. --- lib/pleroma/user.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 87815e11c..955808e28 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -686,7 +686,11 @@ defmodule Pleroma.User do fts_results = do_search(fts_search_subquery(query), for_user) - trigram_results = do_search(trigram_search_subquery(query), for_user) + {:ok, trigram_results} = + Repo.transaction(fn -> + Ecto.Adapters.SQL.query(Repo, "select set_limit(0.25)", []) + do_search(trigram_search_subquery(query), for_user) + end) Enum.uniq_by(fts_results ++ trigram_results, & &1.id) end -- cgit v1.2.3 From cf1f35a93a096311dee62ee5ac142a1bb3cfb844 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 20 Jan 2019 13:00:46 +0100 Subject: Send delete event over Mastodon streaming api Closes #116 --- lib/pleroma/web/activity_pub/activity_pub.ex | 20 +++++++++++--------- lib/pleroma/web/streamer.ex | 9 +++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 130c06028..0431d62af 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -92,7 +92,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def stream_out(activity) do public = "https://www.w3.org/ns/activitystreams#Public" - if activity.data["type"] in ["Create", "Announce"] do + if activity.data["type"] in ["Create", "Announce", "Delete"] do Pleroma.Web.Streamer.stream("user", activity) Pleroma.Web.Streamer.stream("list", activity) @@ -103,16 +103,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do Pleroma.Web.Streamer.stream("public:local", activity) end - activity.data["object"] - |> Map.get("tag", []) - |> Enum.filter(fn tag -> is_bitstring(tag) end) - |> Enum.map(fn tag -> Pleroma.Web.Streamer.stream("hashtag:" <> tag, activity) end) + if activity.data["type"] in ["Create"] do + activity.data["object"] + |> Map.get("tag", []) + |> Enum.filter(fn tag -> is_bitstring(tag) end) + |> Enum.map(fn tag -> Pleroma.Web.Streamer.stream("hashtag:" <> tag, activity) end) - if activity.data["object"]["attachment"] != [] do - Pleroma.Web.Streamer.stream("public:media", activity) + if activity.data["object"]["attachment"] != [] do + Pleroma.Web.Streamer.stream("public:media", activity) - if activity.local do - Pleroma.Web.Streamer.stream("public:local:media", activity) + if activity.local do + Pleroma.Web.Streamer.stream("public:local:media", activity) + end end end else diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index 3136b1b9d..978c77e57 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -205,6 +205,15 @@ defmodule Pleroma.Web.Streamer do end) end + def push_to_socket(topics, topic, %Activity{id: id, data: %{"type" => "Delete"}}) do + Enum.each(topics[topic] || [], fn socket -> + send( + socket.transport_pid, + {:text, %{event: "delete", payload: to_string(id)} |> Jason.encode!()} + ) + end) + end + def push_to_socket(topics, topic, item) do Enum.each(topics[topic] || [], fn socket -> # Get the current user so we have up-to-date blocks etc. -- cgit v1.2.3 From f94cc6d824cb2bdf4a41bc800d2bfc7d4f4dc23d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 01:16:41 +0100 Subject: Mix.Tasks.Pleroma.Instance: Generate signing_salt Closes: https://git.pleroma.social/pleroma/pleroma/issues/533 --- lib/mix/tasks/pleroma/instance.ex | 2 ++ lib/mix/tasks/pleroma/sample_config.eex | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index 0a2c891c0..1ba452275 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -105,6 +105,7 @@ defmodule Mix.Tasks.Pleroma.Instance do ) secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) + signing_salt = :crypto.strong_rand_bytes(8) |> Base.encode64() |> binary_part(0, 8) {web_push_public_key, web_push_private_key} = :crypto.generate_key(:ecdh, :prime256v1) result_config = @@ -120,6 +121,7 @@ defmodule Mix.Tasks.Pleroma.Instance do dbpass: dbpass, version: Pleroma.Mixfile.project() |> Keyword.get(:version), secret: secret, + signing_salt: signing_salt, web_push_public_key: Base.url_encode64(web_push_public_key, padding: false), web_push_private_key: Base.url_encode64(web_push_private_key, padding: false) ) diff --git a/lib/mix/tasks/pleroma/sample_config.eex b/lib/mix/tasks/pleroma/sample_config.eex index 740b9f8d1..1c935c0d8 100644 --- a/lib/mix/tasks/pleroma/sample_config.eex +++ b/lib/mix/tasks/pleroma/sample_config.eex @@ -7,7 +7,8 @@ use Mix.Config config :pleroma, Pleroma.Web.Endpoint, url: [host: "<%= domain %>", scheme: "https", port: <%= port %>], - secret_key_base: "<%= secret %>" + secret_key_base: "<%= secret %>", + signing_salt: "<%= signing_salt %>" config :pleroma, :instance, name: "<%= name %>", -- cgit v1.2.3 From b82c6dc53685ebd26c276eccc5ed915ddf81afa6 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 06:29:05 +0100 Subject: =?UTF-8?q?Activity:=20all=5Fby=5Fobject=5Fap=5Fid/1=20=E2=86=92?= =?UTF-8?q?=20get=5Fall=5Fby=5Fobject=5Fap=5Fid/1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 3 +-- lib/pleroma/web/activity_pub/utils.ex | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 353f9f6cd..e3edec475 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -67,8 +67,7 @@ defmodule Pleroma.Activity do ) end - # Wrong name plz fix thx - def all_by_object_ap_id(ap_id) do + def get_all_by_object_ap_id(ap_id) do Repo.all(all_by_object_ap_id_q(ap_id)) end diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index d2e457a68..cfbe6c857 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -198,7 +198,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do # Update activities that already had this. Could be done in a seperate process. # Alternatively, just don't do this and fetch the current object each time. Most # could probably be taken from cache. - relevant_activities = Activity.all_by_object_ap_id(id) + relevant_activities = Activity.get_all_by_object_ap_id(id) Enum.map(relevant_activities, fn activity -> new_activity_data = activity.data |> Map.put("object", object.data) -- cgit v1.2.3 From 75e4c8f0b21323f072f06e25e10762339abc6e3b Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 06:15:05 +0100 Subject: =?UTF-8?q?Activity:=20all=5Fnon=5Fcreate=5Fby=5Fobject=5Fap=5Fid?= =?UTF-8?q?=5Fq=20=E2=86=92=20by=5Fobject=5Fap=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 3 +-- lib/pleroma/object.ex | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index e3edec475..3be6fb82b 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -53,8 +53,7 @@ defmodule Pleroma.Activity do ) end - # Wrong name, returns all. - def all_non_create_by_object_ap_id_q(ap_id) do + def by_object_ap_id(ap_id) do from( activity in Activity, where: diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index ff5eb9b27..707a61f14 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -85,7 +85,7 @@ defmodule Pleroma.Object do def delete(%Object{data: %{"id" => id}} = object) do with {:ok, _obj} = swap_object_with_tombstone(object), - Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)), + Repo.delete_all(Activity.by_object_ap_id(id)), {:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do {:ok, object} end -- cgit v1.2.3 From 4ad5a0abb99eb90b1b1bebbad79acc67c16cf945 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 06:39:00 +0100 Subject: =?UTF-8?q?Activity:=20all=5Fby=5Fobject=5Fap=5Fid=5Fq/1=20?= =?UTF-8?q?=E2=86=92=20create=5Fby=5Fobject=5Fap=5Fid/1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 3be6fb82b..588027de1 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -36,10 +36,7 @@ defmodule Pleroma.Activity do ) end - # TODO: - # Go through these and fix them everywhere. - # Wrong name, only returns create activities - def all_by_object_ap_id_q(ap_id) do + def create_by_object_ap_id(ap_id) do from( activity in Activity, where: @@ -67,7 +64,7 @@ defmodule Pleroma.Activity do end def get_all_by_object_ap_id(ap_id) do - Repo.all(all_by_object_ap_id_q(ap_id)) + Repo.all(create_by_object_ap_id(ap_id)) end def create_activity_by_object_id_query(ap_ids) do -- cgit v1.2.3 From f8ab1b7427e91ec1b7883e021836099226b56566 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 06:46:47 +0100 Subject: =?UTF-8?q?Activity:=20get=5Fall=5Fby=5Fobject=5Fap=5Fid/1=20?= =?UTF-8?q?=E2=86=92=20get=5Fall=5Fcreate=5Fby=5Fobject=5Fap=5Fid/1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 8 ++++---- lib/pleroma/web/activity_pub/utils.ex | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 588027de1..8c73d1fa0 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -63,10 +63,6 @@ defmodule Pleroma.Activity do ) end - def get_all_by_object_ap_id(ap_id) do - Repo.all(create_by_object_ap_id(ap_id)) - end - def create_activity_by_object_id_query(ap_ids) do from( activity in Activity, @@ -81,6 +77,10 @@ defmodule Pleroma.Activity do ) end + def get_all_create_by_object_ap_id(ap_id) do + Repo.all(create_by_object_ap_id(ap_id)) + end + def get_create_activity_by_object_ap_id(ap_id) when is_binary(ap_id) do create_activity_by_object_id_query([ap_id]) |> Repo.one() diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index cfbe6c857..4f4a54052 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -198,7 +198,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do # Update activities that already had this. Could be done in a seperate process. # Alternatively, just don't do this and fetch the current object each time. Most # could probably be taken from cache. - relevant_activities = Activity.get_all_by_object_ap_id(id) + relevant_activities = Activity.get_all_create_by_object_ap_id(id) Enum.map(relevant_activities, fn activity -> new_activity_data = activity.data |> Map.put("object", object.data) -- cgit v1.2.3 From 2fdbd4d137387d4d469d314b641070a9fdc0468c Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 07:07:54 +0100 Subject: =?UTF-8?q?Activity:=20create=5Factivity=5Fby=5Fobject=5Fid=5Fquer?= =?UTF-8?q?y/1=20=E2=86=92=20create=5Fby=5Fobject=5Fap=5Fid/1=20when=20is?= =?UTF-8?q?=5Flist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 4 ++-- lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 8c73d1fa0..5c3b8fcc5 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -63,7 +63,7 @@ defmodule Pleroma.Activity do ) end - def create_activity_by_object_id_query(ap_ids) do + def create_by_object_ap_id(ap_ids) when is_list(ap_ids) do from( activity in Activity, where: @@ -82,7 +82,7 @@ defmodule Pleroma.Activity do end def get_create_activity_by_object_ap_id(ap_id) when is_binary(ap_id) do - create_activity_by_object_id_query([ap_id]) + create_by_object_ap_id(ap_id) |> Repo.one() end diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 7f5a52ea3..5e9c5c533 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -25,7 +25,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do nil end) |> Enum.filter(& &1) - |> Activity.create_activity_by_object_id_query() + |> Activity.create_by_object_ap_id() |> Repo.all() |> Enum.reduce(%{}, fn activity, acc -> Map.put(acc, activity.data["object"]["id"], activity) -- cgit v1.2.3 From 98c8184c1fc013fbd48bd78a2603c8e560038081 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 07:14:20 +0100 Subject: =?UTF-8?q?Activity:=20get=5Fcreate=5Factivity=5Fby=5Fobject=5Fap?= =?UTF-8?q?=5Fid/1=20=E2=86=92=20get=5Fcreate=5Fby=5Fobject=5Fap=5Fid/1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pleroma/activity.ex | 27 +++++++++++----------- lib/pleroma/web/activity_pub/transmogrifier.ex | 4 ++-- lib/pleroma/web/common_api/utils.ex | 4 ++-- .../web/mastodon_api/mastodon_api_controller.ex | 11 ++++----- lib/pleroma/web/mastodon_api/views/status_view.ex | 4 ++-- lib/pleroma/web/ostatus/activity_representer.ex | 2 +- lib/pleroma/web/ostatus/handlers/note_handler.ex | 4 ++-- lib/pleroma/web/ostatus/ostatus.ex | 2 +- lib/pleroma/web/ostatus/ostatus_controller.ex | 3 +-- lib/pleroma/web/twitter_api/twitter_api.ex | 8 +++---- .../web/twitter_api/twitter_api_controller.ex | 4 ++-- lib/pleroma/web/twitter_api/views/activity_view.ex | 4 ++-- 12 files changed, 38 insertions(+), 39 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 5c3b8fcc5..81079ec3e 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -36,7 +36,7 @@ defmodule Pleroma.Activity do ) end - def create_by_object_ap_id(ap_id) do + def by_object_ap_id(ap_id) do from( activity in Activity, where: @@ -45,33 +45,34 @@ defmodule Pleroma.Activity do activity.data, activity.data, ^to_string(ap_id) - ), - where: fragment("(?)->>'type' = 'Create'", activity.data) + ) ) end - def by_object_ap_id(ap_id) do + + def create_by_object_ap_id(ap_ids) when is_list(ap_ids) do from( activity in Activity, where: fragment( - "coalesce((?)->'object'->>'id', (?)->>'object') = ?", + "coalesce((?)->'object'->>'id', (?)->>'object') = ANY(?)", activity.data, activity.data, - ^to_string(ap_id) - ) + ^ap_ids + ), + where: fragment("(?)->>'type' = 'Create'", activity.data) ) end - def create_by_object_ap_id(ap_ids) when is_list(ap_ids) do + def create_by_object_ap_id(ap_id) do from( activity in Activity, where: fragment( - "coalesce((?)->'object'->>'id', (?)->>'object') = ANY(?)", + "coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, - ^ap_ids + ^to_string(ap_id) ), where: fragment("(?)->>'type' = 'Create'", activity.data) ) @@ -81,19 +82,19 @@ defmodule Pleroma.Activity do Repo.all(create_by_object_ap_id(ap_id)) end - def get_create_activity_by_object_ap_id(ap_id) when is_binary(ap_id) do + def get_create_by_object_ap_id(ap_id) when is_binary(ap_id) do create_by_object_ap_id(ap_id) |> Repo.one() end - def get_create_activity_by_object_ap_id(_), do: nil + def get_create_by_object_ap_id(_), do: nil def normalize(obj) when is_map(obj), do: Activity.get_by_ap_id(obj["id"]) def normalize(ap_id) when is_binary(ap_id), do: Activity.get_by_ap_id(ap_id) def normalize(_), do: nil def get_in_reply_to_activity(%Activity{data: %{"object" => %{"inReplyTo" => ap_id}}}) do - get_create_activity_by_object_ap_id(ap_id) + get_create_by_object_ap_id(ap_id) end def get_in_reply_to_activity(_), do: nil diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index fa3abe3d8..699a8957e 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -141,7 +141,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do case fetch_obj_helper(in_reply_to_id) do {:ok, replied_object} -> with %Activity{} = activity <- - Activity.get_create_activity_by_object_ap_id(replied_object.data["id"]) do + Activity.get_create_by_object_ap_id(replied_object.data["id"]) do object |> Map.put("inReplyTo", replied_object.data["id"]) |> Map.put("inReplyToAtomUri", object["inReplyToAtomUri"] || in_reply_to_id) @@ -334,7 +334,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do Map.put(data, "actor", actor) |> fix_addressing - with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]), + with nil <- Activity.get_create_by_object_ap_id(object["id"]), %User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do object = fix_object(data["object"]) diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index a36ab5c15..a0f59d900 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -14,13 +14,13 @@ defmodule Pleroma.Web.CommonAPI.Utils do # This is a hack for twidere. def get_by_id_or_ap_id(id) do - activity = Repo.get(Activity, id) || Activity.get_create_activity_by_object_ap_id(id) + activity = Repo.get(Activity, id) || Activity.get_create_by_object_ap_id(id) activity && if activity.data["type"] == "Create" do activity else - Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + Activity.get_create_by_object_ap_id(activity.data["object"]) end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 882d336be..f4736fcb5 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -377,7 +377,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do with {:ok, _unannounce, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do conn |> put_view(StatusView) |> try_render("status.json", %{activity: activity, for: user, as: :activity}) @@ -386,7 +386,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def fav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do with {:ok, _fav, %{data: %{"id" => id}}} <- CommonAPI.favorite(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do conn |> put_view(StatusView) |> try_render("status.json", %{activity: activity, for: user, as: :activity}) @@ -395,7 +395,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def unfav_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do with {:ok, _, _, %{data: %{"id" => id}}} <- CommonAPI.unfavorite(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do conn |> put_view(StatusView) |> try_render("status.json", %{activity: activity, for: user, as: :activity}) @@ -743,8 +743,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do fetched = if Regex.match?(~r/https?:/, query) do with {:ok, object} <- ActivityPub.fetch_object_from_id(query), - %Activity{} = activity <- - Activity.get_create_activity_by_object_ap_id(object.data["id"]), + %Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]), true <- ActivityPub.visible_for_user?(activity, user) do [activity] else @@ -1138,7 +1137,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def render_notification(user, %{id: id, activity: activity, inserted_at: created_at} = _params) do actor = User.get_cached_by_ap_id(activity.data["actor"]) - parent_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + parent_activity = Activity.get_create_by_object_ap_id(activity.data["object"]) mastodon_type = Activity.mastodon_notification_type(activity) response = %{ diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 5e9c5c533..74c875c29 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -64,7 +64,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do user = get_user(activity.data["actor"]) created_at = Utils.to_masto_date(activity.data["published"]) - reblogged = Activity.get_create_activity_by_object_ap_id(object) + reblogged = Activity.get_create_by_object_ap_id(object) reblogged = render("status.json", Map.put(opts, :activity, reblogged)) mentions = @@ -209,7 +209,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do def get_reply_to(%{data: %{"object" => object}}, _) do if object["inReplyTo"] && object["inReplyTo"] != "" do - Activity.get_create_activity_by_object_ap_id(object["inReplyTo"]) + Activity.get_create_by_object_ap_id(object["inReplyTo"]) else nil end diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 94b1a7ad1..3d41fc708 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -183,7 +183,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do _in_reply_to = get_in_reply_to(activity.data) author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: [] - retweeted_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + retweeted_activity = Activity.get_create_by_object_ap_id(activity.data["object"]) retweeted_user = User.get_cached_by_ap_id(retweeted_activity.data["actor"]) retweeted_xml = to_simple_form(retweeted_activity, retweeted_user, true) diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex index 5aeed46f0..c5b3e8d97 100644 --- a/lib/pleroma/web/ostatus/handlers/note_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex @@ -86,7 +86,7 @@ defmodule Pleroma.Web.OStatus.NoteHandler do end def fetch_replied_to_activity(entry, inReplyTo) do - with %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(inReplyTo) do + with %Activity{} = activity <- Activity.get_create_by_object_ap_id(inReplyTo) do activity else _e -> @@ -103,7 +103,7 @@ defmodule Pleroma.Web.OStatus.NoteHandler do # TODO: Clean this up a bit. def handle_note(entry, doc \\ nil) do with id <- XML.string_from_xpath("//id", entry), - activity when is_nil(activity) <- Activity.get_create_activity_by_object_ap_id(id), + activity when is_nil(activity) <- Activity.get_create_by_object_ap_id(id), [author] <- :xmerl_xpath.string('//author[1]', doc), {:ok, actor} <- OStatus.find_make_or_update_user(author), content_html <- OStatus.get_content(entry), diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index bb28cd786..a3155b79d 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -148,7 +148,7 @@ defmodule Pleroma.Web.OStatus do Logger.debug("Trying to get entry from db") with id when not is_nil(id) <- string_from_xpath("//activity:object[1]/id", entry), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do {:ok, activity} else _ -> diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 332cbef0e..ce022bcc1 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -90,8 +90,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do ActivityPubController.call(conn, :object) else with id <- o_status_url(conn, :object, uuid), - {_, %Activity{} = activity} <- - {:activity, Activity.get_create_activity_by_object_ap_id(id)}, + {_, %Activity{} = activity} <- {:activity, Activity.get_create_by_object_ap_id(id)}, {_, true} <- {:public?, ActivityPub.is_public?(activity)}, %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do case get_format(conn) do diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 7a63724f1..7d00c01a1 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -70,14 +70,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do def repeat(%User{} = user, ap_id_or_id) do with {:ok, _announce, %{data: %{"id" => id}}} <- CommonAPI.repeat(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do {:ok, activity} end end def unrepeat(%User{} = user, ap_id_or_id) do with {:ok, _unannounce, %{data: %{"id" => id}}} <- CommonAPI.unrepeat(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do {:ok, activity} end end @@ -92,14 +92,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do def fav(%User{} = user, ap_id_or_id) do with {:ok, _fav, %{data: %{"id" => id}}} <- CommonAPI.favorite(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do {:ok, activity} end end def unfav(%User{} = user, ap_id_or_id) do with {:ok, _unfav, _fav, %{data: %{"id" => id}}} <- CommonAPI.unfavorite(ap_id_or_id, user), - %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do + %Activity{} = activity <- Activity.get_create_by_object_ap_id(id) do {:ok, activity} end end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index ede079963..8c9060cf2 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -330,12 +330,12 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def get_by_id_or_ap_id(id) do - activity = Repo.get(Activity, id) || Activity.get_create_activity_by_object_ap_id(id) + activity = Repo.get(Activity, id) || Activity.get_create_by_object_ap_id(id) if activity.data["type"] == "Create" do activity else - Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + Activity.get_create_by_object_ap_id(activity.data["object"]) end end diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 03708d84c..5eb06a26e 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -168,7 +168,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do def render("activity.json", %{activity: %{data: %{"type" => "Announce"}} = activity} = opts) do user = get_user(activity.data["actor"], opts) created_at = activity.data["published"] |> Utils.date_to_asctime() - announced_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + announced_activity = Activity.get_create_by_object_ap_id(activity.data["object"]) text = "#{user.nickname} retweeted a status." @@ -192,7 +192,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do def render("activity.json", %{activity: %{data: %{"type" => "Like"}} = activity} = opts) do user = get_user(activity.data["actor"], opts) - liked_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]) + liked_activity = Activity.get_create_by_object_ap_id(activity.data["object"]) liked_activity_id = if liked_activity, do: liked_activity.id, else: nil created_at = -- cgit v1.2.3 From 7390192c03248ff18eff19d555f28300a7b07e09 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 07:37:45 +0100 Subject: Activity: mix format (2 empty lines) --- lib/pleroma/activity.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 81079ec3e..fe017df3b 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -49,7 +49,6 @@ defmodule Pleroma.Activity do ) end - def create_by_object_ap_id(ap_ids) when is_list(ap_ids) do from( activity in Activity, -- cgit v1.2.3 From aa480f4a8b46f24a07491228462b4318ca25eda7 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Mon, 21 Jan 2019 14:16:51 +0300 Subject: [#530] Prevents user `info` from being overwritten because of race conditions and non-partial update of embed (in WebFinger.ensure_keys_present and other places). --- lib/pleroma/web/activity_pub/activity_pub.ex | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 0431d62af..32c08c9d2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -140,8 +140,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do additional ), {:ok, activity} <- insert(create_data, local), - :ok <- maybe_federate(activity), - {:ok, _actor} <- User.increase_note_count(actor) do + # Changing note count prior to federation in order not to reload `actor` (potentially updated by federator) + {:ok, _actor} <- User.increase_note_count(actor), + :ok <- maybe_federate(activity) do {:ok, activity} end end @@ -288,8 +289,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do with {:ok, _} <- Object.delete(object), {:ok, activity} <- insert(data, local), - :ok <- maybe_federate(activity), - {:ok, _actor} <- User.decrease_note_count(user) do + # Changing note count prior to federation in order not to reload `actor` (potentially updated by federator) + {:ok, _actor} <- User.decrease_note_count(user), + :ok <- maybe_federate(activity) do {:ok, activity} end end -- cgit v1.2.3 From a4d3fec8a71241d5c40fa76e33f15fa217154600 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Mon, 21 Jan 2019 14:52:41 +0300 Subject: [#502] Code comments update. --- lib/pleroma/web/activity_pub/activity_pub.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 32c08c9d2..fd026a047 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -140,7 +140,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do additional ), {:ok, activity} <- insert(create_data, local), - # Changing note count prior to federation in order not to reload `actor` (potentially updated by federator) + # Changing note count prior to enqueuing federation task in order to avoid race conditions on updating user.info {:ok, _actor} <- User.increase_note_count(actor), :ok <- maybe_federate(activity) do {:ok, activity} @@ -289,7 +289,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do with {:ok, _} <- Object.delete(object), {:ok, activity} <- insert(data, local), - # Changing note count prior to federation in order not to reload `actor` (potentially updated by federator) + # Changing note count prior to enqueuing federation task in order to avoid race conditions on updating user.info {:ok, _actor} <- User.decrease_note_count(user), :ok <- maybe_federate(activity) do {:ok, activity} -- cgit v1.2.3 From 97412d9f94ed55caecb7a35e1f95aef7bdf0db19 Mon Sep 17 00:00:00 2001 From: href Date: Mon, 21 Jan 2019 14:42:16 +0100 Subject: S3 Namespace --- lib/pleroma/uploaders/s3.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/uploaders/s3.ex b/lib/pleroma/uploaders/s3.ex index 108cf06b5..fbd89616c 100644 --- a/lib/pleroma/uploaders/s3.ex +++ b/lib/pleroma/uploaders/s3.ex @@ -9,12 +9,20 @@ defmodule Pleroma.Uploaders.S3 do # The file name is re-encoded with S3's constraints here to comply with previous links with less strict filenames def get_file(file) do config = Pleroma.Config.get([__MODULE__]) + bucket = Keyword.fetch!(config, :bucket) + + bucket_with_namespace = + if namespace = Keyword.get(config, :bucket_namespace) do + namespace <> ":" <> bucket + else + bucket + end {:ok, {:url, Path.join([ Keyword.fetch!(config, :public_endpoint), - Keyword.fetch!(config, :bucket), + bucket_with_namespace, strict_encode(URI.decode(file)) ])}} end -- cgit v1.2.3 From 99763999c19bfb2a5d8a10af98ff3c54d2c929ce Mon Sep 17 00:00:00 2001 From: href Date: Mon, 21 Jan 2019 15:17:24 +0100 Subject: reverse_proxy - always override plug's cache-control --- lib/pleroma/reverse_proxy.ex | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index a3846c3bb..a25b5ea4e 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -275,11 +275,24 @@ defmodule Pleroma.ReverseProxy do defp build_resp_cache_headers(headers, _opts) do has_cache? = Enum.any?(headers, fn {k, _} -> k in @resp_cache_headers end) - - if has_cache? do - headers - else - List.keystore(headers, "cache-control", 0, {"cache-control", @default_cache_control_header}) + has_cache_control? = List.keymember?(headers, "cache-control", 0) + + cond do + has_cache? && has_cache_control? -> + headers + + has_cache? -> + # There's caching header present but no cache-control -- we need to explicitely override it to public + # as Plug defaults to "max-age=0, private, must-revalidate" + List.keystore(headers, "cache-control", 0, {"cache-control", "public"}) + + true -> + List.keystore( + headers, + "cache-control", + 0, + {"cache-control", @default_cache_control_header} + ) end end -- cgit v1.2.3 From f9a326909979959d6cb43f66177045bb2adccbf4 Mon Sep 17 00:00:00 2001 From: href Date: Mon, 21 Jan 2019 22:44:14 +0100 Subject: Uploader callback controller --- lib/pleroma/uploaders/uploader.ex | 37 ++++++++++++++++++++++++++++++---- lib/pleroma/web/router.ex | 5 +++++ lib/pleroma/web/uploader_controller.ex | 25 +++++++++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 lib/pleroma/web/uploader_controller.ex (limited to 'lib') diff --git a/lib/pleroma/uploaders/uploader.ex b/lib/pleroma/uploaders/uploader.ex index 0959d7a3e..ce83cbbbc 100644 --- a/lib/pleroma/uploaders/uploader.ex +++ b/lib/pleroma/uploaders/uploader.ex @@ -27,18 +27,47 @@ defmodule Pleroma.Uploaders.Uploader do This allows to correctly proxy or redirect requests to the backend, while allowing to migrate backends without breaking any URL. * `{url, url :: String.t}` to bypass `get_file/2` and use the `url` directly in the activity. * `{:error, String.t}` error information if the file failed to be saved to the backend. + * `:wait_callback` will wait for an http post request at `/api/pleroma/upload_callback/:upload_path` and call the uploader's `http_callback/3` method. """ + @type file_spec :: {:file | :url, String.t()} @callback put_file(Pleroma.Upload.t()) :: - :ok | {:ok, {:file | :url, String.t()}} | {:error, String.t()} + :ok | {:ok, file_spec()} | {:error, String.t()} | :wait_callback + + @callback http_callback(Plug.Conn.t(), Map.t()) :: + {:ok, Plug.Conn.t()} + | {:ok, Plug.Conn.t(), file_spec()} + | {:error, Plug.Conn.t(), String.t()} + @optional_callbacks http_callback: 2 + + @spec put_file(module(), Pleroma.Upload.t()) :: {:ok, file_spec()} | {:error, String.t()} - @spec put_file(module(), Pleroma.Upload.t()) :: - {:ok, {:file | :url, String.t()}} | {:error, String.t()} def put_file(uploader, upload) do case uploader.put_file(upload) do :ok -> {:ok, {:file, upload.path}} - other -> other + :wait_callback -> handle_callback(uploader, upload) + {:ok, _} = ok -> ok + {:error, _} = error -> error + end + end + + defp handle_callback(uploader, upload) do + :global.register_name({__MODULE__, upload.path}, self()) + + receive do + {__MODULE__, pid, conn, params} -> + case uploader.http_callback(conn, params) do + {:ok, conn, ok} -> + send(pid, {__MODULE__, conn}) + {:ok, ok} + + {:error, conn, error} -> + send(pid, {__MODULE__, conn}) + {:error, error} + end + after + 30_000 -> {:error, "Uploader callback timeout"} end end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 7a0c9fd25..69ab58c6a 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -107,6 +107,11 @@ defmodule Pleroma.Web.Router do get("/captcha", UtilController, :captcha) end + scope "/api/pleroma", Pleroma.Web do + pipe_through(:pleroma_api) + post("/uploader_callback/:upload_path", UploaderController, :callback) + end + scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do pipe_through(:admin_api) delete("/user", AdminAPIController, :user_delete) diff --git a/lib/pleroma/web/uploader_controller.ex b/lib/pleroma/web/uploader_controller.ex new file mode 100644 index 000000000..6c28d1197 --- /dev/null +++ b/lib/pleroma/web/uploader_controller.ex @@ -0,0 +1,25 @@ +defmodule Pleroma.Web.UploaderController do + use Pleroma.Web, :controller + + alias Pleroma.Uploaders.Uploader + + def callback(conn, params = %{"upload_path" => upload_path}) do + process_callback(conn, :global.whereis_name({Uploader, upload_path}), params) + end + + def callbacks(conn, _) do + send_resp(conn, 400, "bad request") + end + + defp process_callback(conn, pid, params) when is_pid(pid) do + send(pid, {Uploader, self(), conn, params}) + + receive do + {Uploader, conn} -> conn + end + end + + defp process_callback(conn, _, _) do + send_resp(conn, 400, "bad request") + end +end -- cgit v1.2.3 From e460820fcfcdc68c3e2a43ee69d587ca261324f8 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 22 Jan 2019 10:54:11 +0300 Subject: Add get_by_id to activity.ex --- lib/pleroma/activity.ex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 353f9f6cd..8fd0311d2 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -36,6 +36,10 @@ defmodule Pleroma.Activity do ) end + def get_by_id(id) do + Repo.get(Activity, id) + end + # TODO: # Go through these and fix them everywhere. # Wrong name, only returns create activities -- cgit v1.2.3 From 34d59e40086ad8adc020bac6d23ab2aa835f267b Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 22 Jan 2019 17:12:53 +0300 Subject: [#502] Fixed User.active_local_user_query to return users with nil or missing `info.deactivated`. Adjusted test. --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 06084b117..18137106e 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -901,7 +901,7 @@ defmodule Pleroma.User do def active_local_user_query do from( u in local_user_query(), - where: fragment("?->'deactivated' @> 'false'", u.info) + where: fragment("not (?->'deactivated' @> 'true')", u.info) ) end -- cgit v1.2.3 From 28d77e373cbaf0908f86973a873c9bfd6c3221cb Mon Sep 17 00:00:00 2001 From: href Date: Wed, 9 Jan 2019 16:08:24 +0100 Subject: Flake Ids for Users and Activities --- lib/pleroma/PasswordResetToken.ex | 2 +- lib/pleroma/activity.ex | 1 + lib/pleroma/application.ex | 1 + lib/pleroma/filter.ex | 2 +- lib/pleroma/flake_id.ex | 181 +++++++++++++++++++++ lib/pleroma/list.ex | 2 +- lib/pleroma/notification.ex | 6 +- lib/pleroma/user.ex | 2 + lib/pleroma/web/activity_pub/transmogrifier.ex | 5 - lib/pleroma/web/activity_pub/views/user_view.ex | 4 +- lib/pleroma/web/oauth/authorization.ex | 2 +- lib/pleroma/web/oauth/token.ex | 2 +- lib/pleroma/web/push/subscription.ex | 2 +- .../web/twitter_api/twitter_api_controller.ex | 24 +-- .../web/websub/websub_client_subscription.ex | 2 +- 15 files changed, 209 insertions(+), 29 deletions(-) create mode 100644 lib/pleroma/flake_id.ex (limited to 'lib') diff --git a/lib/pleroma/PasswordResetToken.ex b/lib/pleroma/PasswordResetToken.ex index 1dccdadae..c3c0384d2 100644 --- a/lib/pleroma/PasswordResetToken.ex +++ b/lib/pleroma/PasswordResetToken.ex @@ -10,7 +10,7 @@ defmodule Pleroma.PasswordResetToken do alias Pleroma.{User, PasswordResetToken, Repo} schema "password_reset_tokens" do - belongs_to(:user, User) + belongs_to(:user, User, type: Pleroma.FlakeId) field(:token, :string) field(:used, :boolean, default: false) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 8fd0311d2..d907791b5 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -8,6 +8,7 @@ defmodule Pleroma.Activity do import Ecto.Query @type t :: %__MODULE__{} + @primary_key {:id, Pleroma.FlakeId, autogenerate: true} # https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19 @mastodon_notification_types %{ diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index ad2797209..47c0e5b68 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -99,6 +99,7 @@ defmodule Pleroma.Application do ], id: :cachex_idem ), + worker(Pleroma.FlakeId, []), worker(Pleroma.Web.Federator.RetryQueue, []), worker(Pleroma.Web.Federator, []), worker(Pleroma.Stats, []), diff --git a/lib/pleroma/filter.ex b/lib/pleroma/filter.ex index df5374a5c..308bd70e1 100644 --- a/lib/pleroma/filter.ex +++ b/lib/pleroma/filter.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Filter do alias Pleroma.{User, Repo} schema "filters" do - belongs_to(:user, User) + belongs_to(:user, User, type: Pleroma.FlakeId) field(:filter_id, :integer) field(:hide, :boolean, default: false) field(:whole_word, :boolean, default: true) diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex new file mode 100644 index 000000000..3c72807ca --- /dev/null +++ b/lib/pleroma/flake_id.ex @@ -0,0 +1,181 @@ +defmodule Pleroma.FlakeId do + @moduledoc """ + Flake is a decentralized, k-ordered id generation service. + + Adapted from: + + * [flaky](https://github.com/nirvana/flaky), released under the terms of the Truly Free License, + * [Flake](https://github.com/boundary/flake), Copyright 2012, Boundary, Apache License, Version 2.0 + """ + + @type t :: binary + + @behaviour Ecto.Type + use GenServer + require Logger + alias __MODULE__ + import Kernel, except: [to_string: 1] + + defstruct node: nil, time: 0, sq: 0 + + @doc "Converts a binary Flake to a String" + def to_string(<<0::integer-size(64), id::integer-size(64)>>) do + Kernel.to_string(id) + end + + def to_string(flake = <<_::integer-size(64), _::integer-size(48), _::integer-size(16)>>) do + encode_base62(flake) + end + + def to_string(s), do: s + + def from_string(<>) do + <<0::integer-size(64), id::integer-size(64)>> + end + + for i <- [-1, 0] do + def from_string(unquote(i)), do: <<0::integer-size(128)>> + def from_string(unquote(Kernel.to_string(i))), do: <<0::integer-size(128)>> + end + + def from_string(string) when is_binary(string) and byte_size(string) < 18 do + case Integer.parse(string) do + {id, _} -> <<0::integer-size(64), id::integer-size(64)>> + _ -> nil + end + end + + def from_string(string) do + string |> decode_base62 |> from_integer + end + + def to_integer(<>), do: integer + + def from_integer(integer) do + <<_time::integer-size(64), _node::integer-size(48), _seq::integer-size(16)>> = + <> + end + + @doc "Generates a Flake" + @spec get :: binary + def get, do: to_string(:gen_server.call(:flake, :get)) + + # -- Ecto.Type API + @impl Ecto.Type + def type, do: :uuid + + @impl Ecto.Type + def cast(value) do + {:ok, FlakeId.to_string(value)} + end + + @impl Ecto.Type + def load(value) do + {:ok, FlakeId.to_string(value)} + end + + @impl Ecto.Type + def dump(value) do + {:ok, FlakeId.from_string(value)} + end + + def autogenerate(), do: get() + + # -- GenServer API + def start_link do + :gen_server.start_link({:local, :flake}, __MODULE__, [], []) + end + + @impl GenServer + def init([]) do + {:ok, %FlakeId{node: mac(), time: time()}} + end + + @impl GenServer + def handle_call(:get, _from, state) do + {flake, new_state} = get(time(), state) + {:reply, flake, new_state} + end + + # Matches when the calling time is the same as the state time. Incr. sq + defp get(time, %FlakeId{time: time, node: node, sq: seq}) do + new_state = %FlakeId{time: time, node: node, sq: seq + 1} + {gen_flake(new_state), new_state} + end + + # Matches when the times are different, reset sq + defp get(newtime, %FlakeId{time: time, node: node}) when newtime > time do + new_state = %FlakeId{time: newtime, node: node, sq: 0} + {gen_flake(new_state), new_state} + end + + # Error when clock is running backwards + defp get(newtime, %FlakeId{time: time}) when newtime < time do + {:error, :clock_running_backwards} + end + + defp gen_flake(%FlakeId{time: time, node: node, sq: seq}) do + <> + end + + defp nthchar_base62(n) when n <= 9, do: ?0 + n + defp nthchar_base62(n) when n <= 35, do: ?A + n - 10 + defp nthchar_base62(n), do: ?a + n - 36 + + defp encode_base62(<>) do + integer + |> encode_base62([]) + |> List.to_string() + end + + defp encode_base62(int, acc) when int < 0, do: encode_base62(-int, acc) + defp encode_base62(int, []) when int == 0, do: '0' + defp encode_base62(int, acc) when int == 0, do: acc + + defp encode_base62(int, acc) do + r = rem(int, 62) + id = div(int, 62) + acc = [nthchar_base62(r) | acc] + encode_base62(id, acc) + end + + defp decode_base62(s) do + decode_base62(String.to_charlist(s), 0) + end + + defp decode_base62([c | cs], acc) when c >= ?0 and c <= ?9, + do: decode_base62(cs, 62 * acc + (c - ?0)) + + defp decode_base62([c | cs], acc) when c >= ?A and c <= ?Z, + do: decode_base62(cs, 62 * acc + (c - ?A + 10)) + + defp decode_base62([c | cs], acc) when c >= ?a and c <= ?z, + do: decode_base62(cs, 62 * acc + (c - ?a + 36)) + + defp decode_base62([], acc), do: acc + + defp time do + {mega_seconds, seconds, micro_seconds} = :erlang.timestamp() + 1_000_000_000 * mega_seconds + seconds * 1000 + :erlang.trunc(micro_seconds / 1000) + end + + defp mac do + {:ok, addresses} = :inet.getifaddrs() + + ifaces_with_mac = + Enum.reduce(addresses, [], fn {iface, attrs}, acc -> + if attrs[:hwaddr], do: [iface | acc], else: acc + end) + + iface = Enum.at(ifaces_with_mac, :rand.uniform(length(ifaces_with_mac)) - 1) + mac(iface) + end + + defp mac(name) do + {:ok, addresses} = :inet.getifaddrs() + proplist = :proplists.get_value(name, addresses) + hwaddr = Enum.take(:proplists.get_value(:hwaddr, proplist), 6) + <> = :binary.list_to_bin(hwaddr) + worker + end +end diff --git a/lib/pleroma/list.ex b/lib/pleroma/list.ex index a75dc006e..ca66c6916 100644 --- a/lib/pleroma/list.ex +++ b/lib/pleroma/list.ex @@ -8,7 +8,7 @@ defmodule Pleroma.List do alias Pleroma.{User, Repo, Activity} schema "lists" do - belongs_to(:user, Pleroma.User) + belongs_to(:user, User, type: Pleroma.FlakeId) field(:title, :string) field(:following, {:array, :string}, default: []) diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index c7d01f63b..2c8f60f19 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -9,8 +9,8 @@ defmodule Pleroma.Notification do schema "notifications" do field(:seen, :boolean, default: false) - belongs_to(:user, Pleroma.User) - belongs_to(:activity, Pleroma.Activity) + belongs_to(:user, User, type: Pleroma.FlakeId) + belongs_to(:activity, Activity, type: Pleroma.FlakeId) timestamps() end @@ -96,7 +96,7 @@ defmodule Pleroma.Notification do end end - def create_notifications(%Activity{id: _, data: %{"to" => _, "type" => type}} = activity) + def create_notifications(%Activity{data: %{"to" => _, "type" => type}} = activity) when type in ["Create", "Like", "Announce", "Follow"] do users = get_notified_from_activity(activity) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 18137106e..b006f9f19 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -17,6 +17,8 @@ defmodule Pleroma.User do @type t :: %__MODULE__{} + @primary_key {:id, Pleroma.FlakeId, autogenerate: true} + @email_regex ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ @strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/ diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 5d3feccfe..e646de608 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -900,15 +900,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do maybe_retire_websub(user.ap_id) - # Only do this for recent activties, don't go through the whole db. - # Only look at the last 1000 activities. - since = (Repo.aggregate(Activity, :max, :id) || 0) - 1_000 - q = from( a in Activity, where: ^old_follower_address in a.recipients, - where: a.id > ^since, update: [ set: [ recipients: diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index fe8248107..dcf681b6d 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -160,7 +160,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "partOf" => iri, "totalItems" => info.note_count, "orderedItems" => collection, - "next" => "#{iri}?max_id=#{min_id - 1}" + "next" => "#{iri}?max_id=#{min_id}" } if max_qid == nil do @@ -207,7 +207,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "partOf" => iri, "totalItems" => -1, "orderedItems" => collection, - "next" => "#{iri}?max_id=#{min_id - 1}" + "next" => "#{iri}?max_id=#{min_id}" } if max_qid == nil do diff --git a/lib/pleroma/web/oauth/authorization.ex b/lib/pleroma/web/oauth/authorization.ex index cc4b74bc5..f8c65602d 100644 --- a/lib/pleroma/web/oauth/authorization.ex +++ b/lib/pleroma/web/oauth/authorization.ex @@ -14,7 +14,7 @@ defmodule Pleroma.Web.OAuth.Authorization do field(:token, :string) field(:valid_until, :naive_datetime) field(:used, :boolean, default: false) - belongs_to(:user, Pleroma.User) + belongs_to(:user, Pleroma.User, type: Pleroma.FlakeId) belongs_to(:app, App) timestamps() diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index f0ebc63f6..4e01b123b 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -14,7 +14,7 @@ defmodule Pleroma.Web.OAuth.Token do field(:token, :string) field(:refresh_token, :string) field(:valid_until, :naive_datetime) - belongs_to(:user, Pleroma.User) + belongs_to(:user, Pleroma.User, type: Pleroma.FlakeId) belongs_to(:app, App) timestamps() diff --git a/lib/pleroma/web/push/subscription.ex b/lib/pleroma/web/push/subscription.ex index 82b30950c..bd9d9f3a7 100644 --- a/lib/pleroma/web/push/subscription.ex +++ b/lib/pleroma/web/push/subscription.ex @@ -10,7 +10,7 @@ defmodule Pleroma.Web.Push.Subscription do alias Pleroma.Web.Push.Subscription schema "push_subscriptions" do - belongs_to(:user, User) + belongs_to(:user, User, type: Pleroma.FlakeId) belongs_to(:token, Token) field(:endpoint, :string) field(:key_p256dh, :string) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index ede079963..43f8d64d0 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -265,8 +265,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def fetch_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do - id = String.to_integer(id) - with context when is_binary(context) <- TwitterAPI.conversation_id_to_context(id), activities <- ActivityPub.fetch_activities_for_context(context, %{ @@ -340,38 +338,42 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def favorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, - {:ok, activity} <- TwitterAPI.fav(user, id) do + with {:ok, activity} <- TwitterAPI.fav(user, id) do conn |> put_view(ActivityView) |> render("activity.json", %{activity: activity, for: user}) + else + _ -> json_reply(conn, 400, Jason.encode!(%{})) end end def unfavorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, - {:ok, activity} <- TwitterAPI.unfav(user, id) do + with {:ok, activity} <- TwitterAPI.unfav(user, id) do conn |> put_view(ActivityView) |> render("activity.json", %{activity: activity, for: user}) + else + _ -> json_reply(conn, 400, Jason.encode!(%{})) end end def retweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, - {:ok, activity} <- TwitterAPI.repeat(user, id) do + with {:ok, activity} <- TwitterAPI.repeat(user, id) do conn |> put_view(ActivityView) |> render("activity.json", %{activity: activity, for: user}) + else + _ -> json_reply(conn, 400, Jason.encode!(%{})) end end def unretweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, - {:ok, activity} <- TwitterAPI.unrepeat(user, id) do + with {:ok, activity} <- TwitterAPI.unrepeat(user, id) do conn |> put_view(ActivityView) |> render("activity.json", %{activity: activity, for: user}) + else + _ -> json_reply(conn, 400, Jason.encode!(%{})) end end @@ -556,7 +558,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def approve_friend_request(conn, %{"user_id" => uid} = _params) do with followed <- conn.assigns[:user], - uid when is_number(uid) <- String.to_integer(uid), %User{} = follower <- Repo.get(User, uid), {:ok, follower} <- User.maybe_follow(follower, followed), %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), @@ -578,7 +579,6 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def deny_friend_request(conn, %{"user_id" => uid} = _params) do with followed <- conn.assigns[:user], - uid when is_number(uid) <- String.to_integer(uid), %User{} = follower <- Repo.get(User, uid), %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"), diff --git a/lib/pleroma/web/websub/websub_client_subscription.ex b/lib/pleroma/web/websub/websub_client_subscription.ex index 105b0069f..969ee0684 100644 --- a/lib/pleroma/web/websub/websub_client_subscription.ex +++ b/lib/pleroma/web/websub/websub_client_subscription.ex @@ -13,7 +13,7 @@ defmodule Pleroma.Web.Websub.WebsubClientSubscription do field(:state, :string) field(:subscribers, {:array, :string}, default: []) field(:hub, :string) - belongs_to(:user, User) + belongs_to(:user, User, type: Pleroma.FlakeId) timestamps() end -- cgit v1.2.3 From 9d63b27dcd61dff61b77b6df0ef8a4cf8d7c87e3 Mon Sep 17 00:00:00 2001 From: href Date: Tue, 15 Jan 2019 16:18:18 +0100 Subject: Test FlakeID old id compat & Ecto type --- lib/pleroma/flake_id.ex | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex index 3c72807ca..f23c6d4b0 100644 --- a/lib/pleroma/flake_id.ex +++ b/lib/pleroma/flake_id.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.FlakeId do @moduledoc """ Flake is a decentralized, k-ordered id generation service. @@ -38,6 +42,8 @@ defmodule Pleroma.FlakeId do def from_string(unquote(Kernel.to_string(i))), do: <<0::integer-size(128)>> end + def from_string(flake = <<_::integer-size(128)>>), do: flake + def from_string(string) when is_binary(string) and byte_size(string) < 18 do case Integer.parse(string) do {id, _} -> <<0::integer-size(64), id::integer-size(64)>> -- cgit v1.2.3 From cdc5e6ff5ca97f9123998f8af5f7b9d89b485a0c Mon Sep 17 00:00:00 2001 From: href Date: Tue, 15 Jan 2019 16:39:23 +0100 Subject: ActivityPub: restrict_since/restrict_max: ignore empty param --- lib/pleroma/web/activity_pub/activity_pub.ex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 82fffd324..85fa83e2b 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -410,6 +410,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do |> Enum.reverse() end + defp restrict_since(query, %{"since_id" => ""}), do: query + defp restrict_since(query, %{"since_id" => since_id}) do from(activity in query, where: activity.id > ^since_id) end @@ -465,6 +467,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_local(query, _), do: query + defp restrict_max(query, %{"max_id" => ""}), do: query + defp restrict_max(query, %{"max_id" => max_id}) do from(activity in query, where: activity.id < ^max_id) end -- cgit v1.2.3 From 422e60ad7693ecc06f5fe6dfd65a61caf338e6b6 Mon Sep 17 00:00:00 2001 From: href Date: Tue, 15 Jan 2019 16:42:33 +0100 Subject: 2019 --- lib/pleroma/flake_id.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex index f23c6d4b0..af04fc6a4 100644 --- a/lib/pleroma/flake_id.ex +++ b/lib/pleroma/flake_id.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors +# Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.FlakeId do -- cgit v1.2.3 From e36a434b990cfdd650aed1710c55b1f62bd93ccb Mon Sep 17 00:00:00 2001 From: href Date: Wed, 16 Jan 2019 10:01:15 +0100 Subject: FlakeId.from_string/1: remove old, un-needed conversion --- lib/pleroma/flake_id.ex | 4 ---- 1 file changed, 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex index af04fc6a4..6b83ee890 100644 --- a/lib/pleroma/flake_id.ex +++ b/lib/pleroma/flake_id.ex @@ -33,10 +33,6 @@ defmodule Pleroma.FlakeId do def to_string(s), do: s - def from_string(<>) do - <<0::integer-size(64), id::integer-size(64)>> - end - for i <- [-1, 0] do def from_string(unquote(i)), do: <<0::integer-size(128)>> def from_string(unquote(Kernel.to_string(i))), do: <<0::integer-size(128)>> -- cgit v1.2.3 From 973c9eed18b2e69c6dd43eacaa040cfeabc772bc Mon Sep 17 00:00:00 2001 From: href Date: Wed, 16 Jan 2019 16:15:46 +0100 Subject: Treat User.Info pinned ids as strings --- lib/pleroma/user/info.ex | 2 +- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index fb1791c20..c6c923aac 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -31,7 +31,7 @@ defmodule Pleroma.User.Info do field(:hub, :string, default: nil) field(:salmon, :string, default: nil) field(:hide_network, :boolean, default: false) - field(:pinned_activities, {:array, :integer}, default: []) + field(:pinned_activities, {:array, :string}, default: []) # Found in the wild # ap_id -> Where is this used? diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 43f8d64d0..65ae7aabf 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -378,8 +378,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def pin(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, - {:ok, activity} <- TwitterAPI.pin(user, id) do + with {:ok, activity} <- TwitterAPI.pin(user, id) do conn |> put_view(ActivityView) |> render("activity.json", %{activity: activity, for: user}) @@ -390,8 +389,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end def unpin(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with {_, {:ok, id}} <- {:param_cast, Ecto.Type.cast(:integer, id)}, - {:ok, activity} <- TwitterAPI.unpin(user, id) do + with {:ok, activity} <- TwitterAPI.unpin(user, id) do conn |> put_view(ActivityView) |> render("activity.json", %{activity: activity, for: user}) -- cgit v1.2.3 From a92c43bc4be914ac9f8118cae18bc82e2b9d1664 Mon Sep 17 00:00:00 2001 From: href Date: Wed, 23 Jan 2019 11:21:52 +0100 Subject: Clippy! --- lib/pleroma/clippy.ex | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 lib/pleroma/clippy.ex (limited to 'lib') diff --git a/lib/pleroma/clippy.ex b/lib/pleroma/clippy.ex new file mode 100644 index 000000000..5e82ed8e2 --- /dev/null +++ b/lib/pleroma/clippy.ex @@ -0,0 +1,144 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Clippy do + @moduledoc false + # No software is complete until they have a Clippy implementation. + # A ballmer peak _may_ be required to change this module. + + def tip() do + tips() + |> Enum.random() + |> puts() + end + + def tips() do + host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host]) + + [ + "“πλήρωμα” is “pleroma” in greek", + "For an extended Pleroma Clippy Experience, use the “Redmond” themes in Pleroma FE settings", + "Staff accounts and MRF policies of Pleroma instances are disclosed on the NodeInfo endpoints for easy transparency!\n +- https://catgirl.science/misc/nodeinfo.lua?#{host} +- https://fediverse.network/#{host}/federation", + "Pleroma can federate to the Dark Web!\n +- Tor: https://git.pleroma.social/pleroma/pleroma/wikis/Easy%20Onion%20Federation%20(Tor) +- i2p: https://git.pleroma.social/pleroma/pleroma/wikis/I2p%20federation", + "Lists of Pleroma instances are available at:\n\n- http://distsn.org/pleroma-instances.html\n- https://fediverse.network/pleroma\n- https://the-federation.info/pleroma", + "Pleroma uses the LitePub protocol - https://litepub.social", + "To receive more federated posts, subscribe to relays!\n +- How-to: https://git.pleroma.social/pleroma/pleroma/wikis/Admin%20tasks#relay-managment +- Relays: https://fediverse.network/activityrelay" + ] + end + + @spec puts(String.t() | [[IO.ANSI.ansicode() | String.t(), ...], ...]) :: nil + def puts(text_or_lines) do + import IO.ANSI + + lines = + if is_binary(text_or_lines) do + String.split(text_or_lines, ~r/\n/) + else + text_or_lines + end + + longest_line_size = + lines + |> Enum.map(&charlist_count_text/1) + |> Enum.sort(&>=/2) + |> List.first() + + pad_text = longest_line_size + + pad = + for(_ <- 1..pad_text, do: "_") + |> Enum.join("") + + pad_spaces = + for(_ <- 1..pad_text, do: " ") + |> Enum.join("") + + spaces = " " + + pre_lines = [ + " / \\#{spaces} _#{pad}___", + " | |#{spaces} / #{pad_spaces} \\" + ] + + for l <- pre_lines do + IO.puts(l) + end + + clippy_lines = [ + " #{bright()}@ @#{reset()}#{spaces} ", + " || ||#{spaces}", + " || || <--", + " |\\_/| ", + " \\___/ " + ] + + noclippy_line = " " + + env = %{ + max_size: pad_text, + pad: pad, + pad_spaces: pad_spaces, + spaces: spaces, + pre_lines: pre_lines, + noclippy_line: noclippy_line + } + + clippy_line(lines, clippy_lines, env) + rescue + e -> + IO.puts("(Clippy crashed, sorry: #{inspect(e)})") + IO.puts(text_or_lines) + end + + defp clippy_line([line | lines], [prefix | clippy_lines], env) do + IO.puts([prefix <> "| ", rpad_line(line, env.max_size)]) + clippy_line(lines, clippy_lines, env) + end + + # more text lines but clippy's complete + defp clippy_line([line | lines], [], env) do + IO.puts([env.noclippy_line, "| ", rpad_line(line, env.max_size)]) + + if lines == [] do + IO.puts(env.noclippy_line <> "\\_#{env.pad}___/") + end + + clippy_line(lines, [], env) + end + + # no more text lines but clippy's not complete + defp clippy_line([], [clippy | clippy_lines], env) do + if env.pad do + IO.puts(clippy <> "\\_#{env.pad}___/") + clippy_line([], clippy_lines, %{env | pad: nil}) + else + IO.puts(clippy) + clippy_line([], clippy_lines, env) + end + end + + defp clippy_line(_, _, _) do + end + + defp rpad_line(line, max) do + pad = max - (charlist_count_text(line) - 2) + pads = Enum.join(for(_ <- 1..pad, do: " ")) + [IO.ANSI.format(line), pads <> " |"] + end + + defp charlist_count_text(line) do + if is_list(line) do + text = Enum.join(Enum.filter(line, &is_binary/1)) + String.length(text) + else + String.length(line) + end + end +end -- cgit v1.2.3 From e221c681dcd387aa445c35957a32fdc0189a0955 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 23 Jan 2019 12:40:57 +0100 Subject: New frontend configuration mechanism. --- lib/pleroma/web/router.ex | 1 + lib/pleroma/web/twitter_api/controllers/util_controller.ex | 8 ++++++++ 2 files changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 69ab58c6a..8ddc642ea 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -284,6 +284,7 @@ defmodule Pleroma.Web.Router do post("/help/test", TwitterAPI.UtilController, :help_test) get("/statusnet/config", TwitterAPI.UtilController, :config) get("/statusnet/version", TwitterAPI.UtilController, :version) + get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations) end scope "/api", Pleroma.Web do diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index a79072f3d..085642876 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -216,6 +216,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do end end + def frontend_configurations(conn, _params) do + config = + Pleroma.Config.get(:frontend_configurations, %{}) + |> Enum.into(%{}) + + json(conn, config) + end + def version(conn, _params) do version = Pleroma.Application.named_version() -- cgit v1.2.3 From f161a92cb1abd981e37367fcd5d315ac14510d12 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 23 Jan 2019 18:37:25 +0300 Subject: [#534] Initial implementation of unreachable federation targets retirement. --- lib/pleroma/instances.ex | 12 +++++ lib/pleroma/instances/instance.ex | 77 ++++++++++++++++++++++++++++ lib/pleroma/web/activity_pub/activity_pub.ex | 39 ++++++++++---- lib/pleroma/web/salmon/salmon.ex | 13 ++++- lib/pleroma/web/websub/websub.ex | 10 +++- 5 files changed, 137 insertions(+), 14 deletions(-) create mode 100644 lib/pleroma/instances.ex create mode 100644 lib/pleroma/instances/instance.ex (limited to 'lib') diff --git a/lib/pleroma/instances.ex b/lib/pleroma/instances.ex new file mode 100644 index 000000000..25b739520 --- /dev/null +++ b/lib/pleroma/instances.ex @@ -0,0 +1,12 @@ +defmodule Pleroma.Instances do + @moduledoc "Instances context." + + @adapter Pleroma.Instances.Instance + + defdelegate reachable?(url), to: @adapter + defdelegate set_reachable(url), to: @adapter + defdelegate set_unreachable(url, unreachable_since \\ nil), to: @adapter + + def reachability_time_threshold, + do: NaiveDateTime.add(NaiveDateTime.utc_now(), -30 * 24 * 3600, :second) +end diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex new file mode 100644 index 000000000..4507ef6d5 --- /dev/null +++ b/lib/pleroma/instances/instance.ex @@ -0,0 +1,77 @@ +defmodule Pleroma.Instances.Instance do + @moduledoc "Instance." + + alias Pleroma.Instances + alias Pleroma.Instances.Instance + + use Ecto.Schema + + import Ecto.{Query, Changeset} + + alias Pleroma.Repo + + schema "instances" do + field(:host, :string) + field(:unreachable_since, :naive_datetime) + field(:reachability_checked_at, :naive_datetime) + + timestamps() + end + + def update_changeset(struct, params \\ %{}) do + struct + |> cast(params, [:host, :unreachable_since, :reachability_checked_at]) + |> unique_constraint(:host) + end + + def reachable?(url) do + !Repo.one( + from(i in Instance, + where: + i.host == ^host(url) and i.unreachable_since <= ^Instances.reachability_time_threshold(), + select: true + ) + ) + end + + def set_reachable(url) do + Repo.update_all( + from(i in Instance, where: i.host == ^host(url)), + set: [ + unreachable_since: nil, + reachability_checked_at: DateTime.utc_now() + ] + ) + end + + def set_unreachable(url, unreachable_since \\ nil) do + unreachable_since = unreachable_since || DateTime.utc_now() + host = host(url) + existing_record = Repo.get_by(Instance, %{host: host}) + + changes = %{ + unreachable_since: unreachable_since, + reachability_checked_at: NaiveDateTime.utc_now() + } + + if existing_record do + update_changes = + if existing_record.unreachable_since && + NaiveDateTime.compare(existing_record.unreachable_since, unreachable_since) != :gt, + do: Map.delete(changes, :unreachable_since), + else: changes + + {:ok, _instance} = Repo.update(update_changeset(existing_record, update_changes)) + else + {:ok, _instance} = Repo.insert(update_changeset(%Instance{}, Map.put(changes, :host, host))) + end + end + + defp host(url_or_host) do + if url_or_host =~ ~r/^http/i do + URI.parse(url_or_host).host + else + url_or_host + end + end +end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 82fffd324..b14c91c18 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ActivityPub do - alias Pleroma.{Activity, Repo, Object, Upload, User, Notification} + alias Pleroma.{Activity, Repo, Object, Upload, User, Notification, Instances} alias Pleroma.Web.ActivityPub.{Transmogrifier, MRF} alias Pleroma.Web.WebFinger alias Pleroma.Web.Federator @@ -721,7 +721,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end) end - def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do + def publish_one(%{inbox: inbox} = activity) do + if Instances.reachable?(inbox) do + do_publish_one(activity) + else + {:error, :noop} + end + end + + defp do_publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do Logger.info("Federating #{id} to #{inbox}") host = URI.parse(inbox).host @@ -734,15 +742,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do digest: digest }) - @httpoison.post( - inbox, - json, - [ - {"Content-Type", "application/activity+json"}, - {"signature", signature}, - {"digest", digest} - ] - ) + with {:ok, _} <- + result = + @httpoison.post( + inbox, + json, + [ + {"Content-Type", "application/activity+json"}, + {"signature", signature}, + {"digest", digest} + ] + ) do + Instances.set_reachable(inbox) + result + else + e -> + Instances.set_unreachable(inbox) + e + end end # TODO: diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index e41657da1..0a0b91433 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -6,6 +6,7 @@ defmodule Pleroma.Web.Salmon do @httpoison Application.get_env(:pleroma, :httpoison) use Bitwise + alias Pleroma.Instances alias Pleroma.Web.XML alias Pleroma.Web.OStatus.ActivityRepresenter alias Pleroma.User @@ -167,15 +168,23 @@ defmodule Pleroma.Web.Salmon do do: send_to_user(salmon, feed, poster) defp send_to_user(url, feed, poster) when is_binary(url) do - with {:ok, %{status: code}} <- + with {:reachable, true} <- {:reachable, Instances.reachable?(url)}, + {:ok, %{status: code}} <- poster.( url, feed, [{"Content-Type", "application/magic-envelope+xml"}] ) do + Instances.set_reachable(url) Logger.debug(fn -> "Pushed to #{url}, code #{code}" end) else - e -> Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end) + {:reachable, false} -> + Logger.debug(fn -> "Pushing Salmon to #{url} skipped as marked unreachable)" end) + :noop + + e -> + Instances.set_unreachable(url) + Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end) end end diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 7ca62c83b..a6bbaef37 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -5,6 +5,7 @@ defmodule Pleroma.Web.Websub do alias Ecto.Changeset alias Pleroma.Repo + alias Pleroma.Instances alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription} alias Pleroma.Web.OStatus.FeedRepresenter alias Pleroma.Web.{XML, Endpoint, OStatus} @@ -267,7 +268,8 @@ defmodule Pleroma.Web.Websub do signature = sign(secret || "", xml) Logger.info(fn -> "Pushing #{topic} to #{callback}" end) - with {:ok, %{status: code}} <- + with {:reachable, true} <- {:reachable, Instances.reachable?(callback)}, + {:ok, %{status: code}} <- @httpoison.post( callback, xml, @@ -276,10 +278,16 @@ defmodule Pleroma.Web.Websub do {"X-Hub-Signature", "sha1=#{signature}"} ] ) do + Instances.set_reachable(callback) Logger.info(fn -> "Pushed to #{callback}, code #{code}" end) {:ok, code} else + {:reachable, false} -> + Logger.debug(fn -> "Pushing to #{callback} skipped as marked unreachable)" end) + {:error, :noop} + e -> + Instances.set_unreachable(callback) Logger.debug(fn -> "Couldn't push to #{callback}, #{inspect(e)}" end) {:error, e} end -- cgit v1.2.3 From 4333fea1dc2942526c78d97f3e8694fdc79b0575 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Wed, 23 Jan 2019 19:47:51 +0300 Subject: Send "hide_network" in user_view --- lib/pleroma/web/twitter_api/views/user_view.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index a8cf83613..15682db8f 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -108,6 +108,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "locked" => user.info.locked, "default_scope" => user.info.default_scope, "no_rich_text" => user.info.no_rich_text, + "hide_network" => user.info.hide_network, "fields" => fields, # Pleroma extension -- cgit v1.2.3 From 20b54366ee916677b3865acf36baeeb062dd550b Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 24 Jan 2019 11:54:52 +0300 Subject: [#534] Federation publish requests status control (enforced 2xx response code check). --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/salmon/salmon.ex | 2 +- lib/pleroma/web/websub/websub.ex | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index b14c91c18..10155ff5a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -742,7 +742,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do digest: digest }) - with {:ok, _} <- + with {:ok, %{status: code}} when code in 200..299 <- result = @httpoison.post( inbox, diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 0a0b91433..0423ccee0 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -169,7 +169,7 @@ defmodule Pleroma.Web.Salmon do defp send_to_user(url, feed, poster) when is_binary(url) do with {:reachable, true} <- {:reachable, Instances.reachable?(url)}, - {:ok, %{status: code}} <- + {:ok, %{status: code}} when code in 200..299 <- poster.( url, feed, diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index a6bbaef37..9ceb5fbf7 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -269,7 +269,7 @@ defmodule Pleroma.Web.Websub do Logger.info(fn -> "Pushing #{topic} to #{callback}" end) with {:reachable, true} <- {:reachable, Instances.reachable?(callback)}, - {:ok, %{status: code}} <- + {:ok, %{status: code}} when code in 200..299 <- @httpoison.post( callback, xml, -- cgit v1.2.3 From 54ec6d09b012e90cd42c00e218df4cc7b99410a4 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 24 Jan 2019 09:35:19 +0000 Subject: mrf: add anti-followbot policy --- .../web/activity_pub/mrf/anti_followbot_policy.ex | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex b/lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex new file mode 100644 index 000000000..7c6ad582a --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex @@ -0,0 +1,57 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do + alias Pleroma.User + + @behaviour Pleroma.Web.ActivityPub.MRF + + # XXX: this should become User.normalize_by_ap_id() or similar, really. + defp normalize_by_ap_id(%{"id" => id}), do: User.get_cached_by_ap_id(id) + defp normalize_by_ap_id(uri) when is_binary(uri), do: User.get_cached_by_ap_id(uri) + defp normalize_by_ap_id(_), do: nil + + defp score_nickname("followbot@" <> _), do: 1.0 + defp score_nickname("federationbot@" <> _), do: 1.0 + defp score_nickname("federation_bot@" <> _), do: 1.0 + defp score_nickname(_), do: 0.0 + + defp score_displayname("federation bot"), do: 1.0 + defp score_displayname("federationbot"), do: 1.0 + defp score_displayname("fedibot"), do: 1.0 + defp score_displayname(_), do: 0.0 + + defp determine_if_followbot(%User{nickname: nickname, name: displayname}) do + nick_score = + nickname + |> String.downcase() + |> score_nickname() + + name_score = + displayname + |> String.downcase() + |> score_displayname() + + nick_score + name_score + end + + defp determine_if_followbot(_), do: 0.0 + + @impl true + def filter(%{"type" => "Follow", "actor" => actor_id} = message) do + %User{} = actor = normalize_by_ap_id(actor_id) + + score = determine_if_followbot(actor) + + # TODO: scan biography data for keywords and score it somehow. + if score < 0.8 do + {:ok, message} + else + {:reject, nil} + end + end + + @impl true + def filter(message), do: {:ok, message} +end -- cgit v1.2.3 From be43aa2875e08cd48b10fc0157d71239f098d1e4 Mon Sep 17 00:00:00 2001 From: href Date: Thu, 24 Jan 2019 13:08:27 +0100 Subject: FlakeId: ignore null mac for workerid, use first mac --- lib/pleroma/flake_id.ex | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex index 6b83ee890..26399ae05 100644 --- a/lib/pleroma/flake_id.ex +++ b/lib/pleroma/flake_id.ex @@ -161,23 +161,23 @@ defmodule Pleroma.FlakeId do 1_000_000_000 * mega_seconds + seconds * 1000 + :erlang.trunc(micro_seconds / 1000) end - defp mac do + def mac do {:ok, addresses} = :inet.getifaddrs() - ifaces_with_mac = - Enum.reduce(addresses, [], fn {iface, attrs}, acc -> - if attrs[:hwaddr], do: [iface | acc], else: acc + macids = + Enum.reduce(addresses, [], fn {_iface, attrs}, acc -> + case attrs[:hwaddr] do + [0, 0, 0 | _] -> acc + mac when is_list(mac) -> [mac_to_worker_id(mac) | acc] + _ -> acc + end end) - iface = Enum.at(ifaces_with_mac, :rand.uniform(length(ifaces_with_mac)) - 1) - mac(iface) + List.first(macids) end - defp mac(name) do - {:ok, addresses} = :inet.getifaddrs() - proplist = :proplists.get_value(name, addresses) - hwaddr = Enum.take(:proplists.get_value(:hwaddr, proplist), 6) - <> = :binary.list_to_bin(hwaddr) + def mac_to_worker_id(mac) do + <> = :binary.list_to_bin(mac) worker end end -- cgit v1.2.3 From 8654a591f08c7d8d5d61f075906f0c6907e877bb Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 24 Jan 2019 17:37:23 +0300 Subject: [#534] Updating external instances reachability on incoming federation. --- lib/pleroma/instances/instance.ex | 14 +++++++++++--- lib/pleroma/reverse_proxy.ex | 3 ++- lib/pleroma/web/activity_pub/activity_pub.ex | 3 ++- lib/pleroma/web/activity_pub/activity_pub_controller.ex | 7 +++++++ lib/pleroma/web/controller_helper.ex | 5 +++++ lib/pleroma/web/ostatus/ostatus_controller.ex | 7 +++++++ lib/pleroma/web/salmon/salmon.ex | 5 ++++- lib/pleroma/web/websub/websub.ex | 3 ++- lib/pleroma/web/websub/websub_controller.ex | 9 +++++++++ 9 files changed, 49 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index 4507ef6d5..fe52331a3 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -24,7 +24,7 @@ defmodule Pleroma.Instances.Instance do |> unique_constraint(:host) end - def reachable?(url) do + def reachable?(url) when is_binary(url) do !Repo.one( from(i in Instance, where: @@ -34,7 +34,9 @@ defmodule Pleroma.Instances.Instance do ) end - def set_reachable(url) do + def reachable?(_), do: true + + def set_reachable(url) when is_binary(url) do Repo.update_all( from(i in Instance, where: i.host == ^host(url)), set: [ @@ -44,7 +46,11 @@ defmodule Pleroma.Instances.Instance do ) end - def set_unreachable(url, unreachable_since \\ nil) do + def set_reachable(_), do: {0, :noop} + + def set_unreachable(url, unreachable_since \\ nil) + + def set_unreachable(url, unreachable_since) when is_binary(url) do unreachable_since = unreachable_since || DateTime.utc_now() host = host(url) existing_record = Repo.get_by(Instance, %{host: host}) @@ -67,6 +73,8 @@ defmodule Pleroma.Instances.Instance do end end + def set_unreachable(_, _), do: {0, :noop} + defp host(url_or_host) do if url_or_host =~ ~r/^http/i do URI.parse(url_or_host).host diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index a25b5ea4e..d8b17212b 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -3,7 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.ReverseProxy do - @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since if-none-match if-range range) + @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since) ++ + ~w(if-none-match if-range range referer) @resp_cache_headers ~w(etag date last-modified cache-control) @keep_resp_headers @resp_cache_headers ++ ~w(content-type content-disposition content-encoding content-range accept-ranges vary) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 10155ff5a..44c295d65 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -750,7 +750,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do [ {"Content-Type", "application/activity+json"}, {"signature", signature}, - {"digest", digest} + {"digest", digest}, + {"referer", Pleroma.Web.Endpoint.url()} ] ) do Instances.set_reachable(inbox) diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 7eed0a600..dc353dff0 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -4,6 +4,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do use Pleroma.Web, :controller + alias Pleroma.{Activity, User, Object} alias Pleroma.Web.ActivityPub.{ObjectView, UserView} alias Pleroma.Web.ActivityPub.ActivityPub @@ -18,6 +19,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do plug(Pleroma.Web.FederatingPlug when action in [:inbox, :relay]) plug(:relay_active? when action in [:relay]) + plug(:set_requester_reachable when action in [:inbox]) def relay_active?(conn, _) do if Keyword.get(Application.get_env(:pleroma, :instance), :allow_relay) do @@ -289,4 +291,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do |> put_status(500) |> json("error") end + + defp set_requester_reachable(conn, _) do + Pleroma.Web.ControllerHelper.set_requester_reachable(conn) + conn + end end diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index 14e3d19fd..13cf1877f 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -10,4 +10,9 @@ defmodule Pleroma.Web.ControllerHelper do |> put_status(status) |> json(json) end + + def set_requester_reachable(conn) do + with [referer] <- get_req_header(conn, "referer"), + do: Pleroma.Instances.set_reachable(referer) + end end diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index ce022bcc1..a89f16b94 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -15,6 +15,8 @@ defmodule Pleroma.Web.OStatus.OStatusController do alias Pleroma.Web.ActivityPub.ActivityPub plug(Pleroma.Web.FederatingPlug when action in [:salmon_incoming]) + plug(:set_requester_reachable when action in [:salmon_incoming]) + action_fallback(:errors) def feed_redirect(conn, %{"nickname" => nickname}) do @@ -201,4 +203,9 @@ defmodule Pleroma.Web.OStatus.OStatusController do |> put_status(500) |> text("Something went wrong") end + + defp set_requester_reachable(conn, _) do + Pleroma.Web.ControllerHelper.set_requester_reachable(conn) + conn + end end diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 0423ccee0..e4d2d9517 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -173,7 +173,10 @@ defmodule Pleroma.Web.Salmon do poster.( url, feed, - [{"Content-Type", "application/magic-envelope+xml"}] + [ + {"Content-Type", "application/magic-envelope+xml"}, + {"referer", Pleroma.Web.Endpoint.url()} + ] ) do Instances.set_reachable(url) Logger.debug(fn -> "Pushed to #{url}, code #{code}" end) diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 9ceb5fbf7..ac8903913 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -275,7 +275,8 @@ defmodule Pleroma.Web.Websub do xml, [ {"Content-Type", "application/atom+xml"}, - {"X-Hub-Signature", "sha1=#{signature}"} + {"X-Hub-Signature", "sha1=#{signature}"}, + {"referer", Pleroma.Web.Endpoint.url()} ] ) do Instances.set_reachable(callback) diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex index e58f144e5..02fe075d7 100644 --- a/lib/pleroma/web/websub/websub_controller.ex +++ b/lib/pleroma/web/websub/websub_controller.ex @@ -4,9 +4,11 @@ defmodule Pleroma.Web.Websub.WebsubController do use Pleroma.Web, :controller + alias Pleroma.{Repo, User} alias Pleroma.Web.{Websub, Federator} alias Pleroma.Web.Websub.WebsubClientSubscription + require Logger plug( @@ -18,6 +20,8 @@ defmodule Pleroma.Web.Websub.WebsubController do ] ) + plug(:set_requester_reachable when action in [:websub_incoming]) + def websub_subscription_request(conn, %{"nickname" => nickname} = params) do user = User.get_cached_by_nickname(nickname) @@ -92,4 +96,9 @@ defmodule Pleroma.Web.Websub.WebsubController do |> send_resp(500, "Error") end end + + defp set_requester_reachable(conn, _) do + Pleroma.Web.ControllerHelper.set_requester_reachable(conn) + conn + end end -- cgit v1.2.3 From a3ba72d97849ba12a5ea4008bd0b97e80bdd588b Mon Sep 17 00:00:00 2001 From: href Date: Thu, 24 Jan 2019 16:15:13 +0100 Subject: Fix clippy with one/five lines --- lib/pleroma/clippy.ex | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/clippy.ex b/lib/pleroma/clippy.ex index 5e82ed8e2..4e9bdbe19 100644 --- a/lib/pleroma/clippy.ex +++ b/lib/pleroma/clippy.ex @@ -25,7 +25,7 @@ defmodule Pleroma.Clippy do "Pleroma can federate to the Dark Web!\n - Tor: https://git.pleroma.social/pleroma/pleroma/wikis/Easy%20Onion%20Federation%20(Tor) - i2p: https://git.pleroma.social/pleroma/pleroma/wikis/I2p%20federation", - "Lists of Pleroma instances are available at:\n\n- http://distsn.org/pleroma-instances.html\n- https://fediverse.network/pleroma\n- https://the-federation.info/pleroma", + "Lists of Pleroma instances:\n\n- http://distsn.org/pleroma-instances.html\n- https://fediverse.network/pleroma\n- https://the-federation.info/pleroma", "Pleroma uses the LitePub protocol - https://litepub.social", "To receive more federated posts, subscribe to relays!\n - How-to: https://git.pleroma.social/pleroma/pleroma/wikis/Admin%20tasks#relay-managment @@ -90,6 +90,17 @@ defmodule Pleroma.Clippy do noclippy_line: noclippy_line } + # surrond one/five line clippy with blank lines around to not fuck up the layout + # + # yes this fix sucks but it's good enough, have you ever seen a release of windows wihtout some butched + # features anyway? + lines = + if length(lines) == 1 or length(lines) == 5 do + [""] ++ lines ++ [""] + else + lines + end + clippy_line(lines, clippy_lines, env) rescue e -> -- cgit v1.2.3 From 3e9399ec0b498c0c9783ccb0fea9f682c8b9d0ca Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 24 Jan 2019 19:15:23 +0300 Subject: [#534] Optimized bulk publish ops to filter on reachability early. `Instance` refactoring. --- lib/pleroma/instances.ex | 9 +++++ lib/pleroma/instances/instance.ex | 57 +++++++++++++++++++--------- lib/pleroma/web/activity_pub/activity_pub.ex | 5 ++- lib/pleroma/web/salmon/salmon.ex | 8 +++- lib/pleroma/web/websub/websub.ex | 18 +++++---- 5 files changed, 69 insertions(+), 28 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/instances.ex b/lib/pleroma/instances.ex index 25b739520..6d445d6b3 100644 --- a/lib/pleroma/instances.ex +++ b/lib/pleroma/instances.ex @@ -3,10 +3,19 @@ defmodule Pleroma.Instances do @adapter Pleroma.Instances.Instance + defdelegate filter_reachable(urls), to: @adapter defdelegate reachable?(url), to: @adapter defdelegate set_reachable(url), to: @adapter defdelegate set_unreachable(url, unreachable_since \\ nil), to: @adapter def reachability_time_threshold, do: NaiveDateTime.add(NaiveDateTime.utc_now(), -30 * 24 * 3600, :second) + + def host(url_or_host) when is_binary(url_or_host) do + if url_or_host =~ ~r/^http/i do + URI.parse(url_or_host).host + else + url_or_host + end + end end diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index fe52331a3..a17c8dab1 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -18,12 +18,35 @@ defmodule Pleroma.Instances.Instance do timestamps() end - def update_changeset(struct, params \\ %{}) do + defdelegate host(url), to: Instances + + def changeset(struct, params \\ %{}) do struct |> cast(params, [:host, :unreachable_since, :reachability_checked_at]) + |> validate_required([:host]) |> unique_constraint(:host) end + def filter_reachable([]), do: [] + + def filter_reachable(urls) when is_list(urls) do + hosts = + urls + |> Enum.map(&(&1 && host(&1))) + |> Enum.filter(&(to_string(&1) != "")) + + unreachable_hosts = + Repo.all( + from(i in Instance, + where: + i.host in ^hosts and i.unreachable_since <= ^Instances.reachability_time_threshold(), + select: i.host + ) + ) + + Enum.filter(urls, &(&1 && host(&1) not in unreachable_hosts)) + end + def reachable?(url) when is_binary(url) do !Repo.one( from(i in Instance, @@ -37,13 +60,13 @@ defmodule Pleroma.Instances.Instance do def reachable?(_), do: true def set_reachable(url) when is_binary(url) do - Repo.update_all( - from(i in Instance, where: i.host == ^host(url)), - set: [ - unreachable_since: nil, - reachability_checked_at: DateTime.utc_now() - ] - ) + with host <- host(url), + %Instance{} = existing_record <- Repo.get_by(Instance, %{host: host}) do + {:ok, _instance} = + existing_record + |> changeset(%{unreachable_since: nil, reachability_checked_at: DateTime.utc_now()}) + |> Repo.update() + end end def set_reachable(_), do: {0, :noop} @@ -67,19 +90,17 @@ defmodule Pleroma.Instances.Instance do do: Map.delete(changes, :unreachable_since), else: changes - {:ok, _instance} = Repo.update(update_changeset(existing_record, update_changes)) + {:ok, _instance} = + existing_record + |> changeset(update_changes) + |> Repo.update() else - {:ok, _instance} = Repo.insert(update_changeset(%Instance{}, Map.put(changes, :host, host))) + {:ok, _instance} = + %Instance{} + |> changeset(Map.put(changes, :host, host)) + |> Repo.insert() end end def set_unreachable(_, _), do: {0, :noop} - - defp host(url_or_host) do - if url_or_host =~ ~r/^http/i do - URI.parse(url_or_host).host - else - url_or_host - end - end end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 44c295d65..4b34334a0 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -689,7 +689,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end def publish(actor, activity) do - followers = + remote_followers = if actor.follower_address in activity.recipients do {:ok, followers} = User.get_followers(actor) followers |> Enum.filter(&(!&1.local)) @@ -700,13 +700,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do public = is_public?(activity) remote_inboxes = - (Pleroma.Web.Salmon.remote_users(activity) ++ followers) + (Pleroma.Web.Salmon.remote_users(activity) ++ remote_followers) |> Enum.filter(fn user -> User.ap_enabled?(user) end) |> Enum.map(fn %{info: %{source_data: data}} -> (is_map(data["endpoints"]) && Map.get(data["endpoints"], "sharedInbox")) || data["inbox"] end) |> Enum.uniq() |> Enum.filter(fn inbox -> should_federate?(inbox, public) end) + |> Instances.filter_reachable() {:ok, data} = Transmogrifier.prepare_outgoing(activity.data) json = Jason.encode!(data) diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index e4d2d9517..848131d52 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -221,7 +221,13 @@ defmodule Pleroma.Web.Salmon do {:ok, private, _} = keys_from_pem(keys) {:ok, feed} = encode(private, feed) - remote_users(activity) + remote_users = remote_users(activity) + + salmon_urls = Enum.map(remote_users, & &1.info.salmon) + reachable_salmon_urls = Instances.filter_reachable(salmon_urls) + + remote_users + |> Enum.filter(&(&1.info.salmon in reachable_salmon_urls)) |> Enum.each(fn remote_user -> Task.start(fn -> Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end) diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index ac8903913..bb4442591 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -54,7 +54,12 @@ defmodule Pleroma.Web.Websub do ] def publish(topic, user, %{data: %{"type" => type}} = activity) when type in @supported_activities do - # TODO: Only send to still valid subscriptions. + response = + user + |> FeedRepresenter.to_simple_form([activity], [user]) + |> :xmerl.export_simple(:xmerl_xml) + |> to_string + query = from( sub in WebsubServerSubscription, @@ -64,13 +69,12 @@ defmodule Pleroma.Web.Websub do subscriptions = Repo.all(query) - Enum.each(subscriptions, fn sub -> - response = - user - |> FeedRepresenter.to_simple_form([activity], [user]) - |> :xmerl.export_simple(:xmerl_xml) - |> to_string + callbacks = Enum.map(subscriptions, & &1.callback) + reachable_callbacks = Instances.filter_reachable(callbacks) + subscriptions + |> Enum.filter(&(&1.callback in reachable_callbacks)) + |> Enum.each(fn sub -> data = %{ xml: response, topic: topic, -- cgit v1.2.3 From 9274cabe01977a3c2d35059d7889c63e2bd54de1 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 24 Jan 2019 23:30:43 +0300 Subject: Use correct logic to determine "attentions" list --- lib/pleroma/notification.ex | 49 ++-------------------- lib/pleroma/web/common_api/utils.ex | 42 +++++++++++++++++++ .../representers/activity_representer.ex | 10 ++--- lib/pleroma/web/twitter_api/views/activity_view.ex | 4 +- 4 files changed, 53 insertions(+), 52 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index c7d01f63b..4659e14ef 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -4,7 +4,8 @@ defmodule Pleroma.Notification do use Ecto.Schema - alias Pleroma.{User, Activity, Notification, Repo, Object} + alias Pleroma.{User, Activity, Notification, Repo} + alias Pleroma.Web.CommonAPI.Utils import Ecto.Query schema "notifications" do @@ -132,54 +133,12 @@ defmodule Pleroma.Notification do when type in ["Create", "Like", "Announce", "Follow"] do recipients = [] - |> maybe_notify_to_recipients(activity) - |> maybe_notify_mentioned_recipients(activity) + |> Utils.maybe_notify_to_recipients(activity) + |> Utils.maybe_notify_mentioned_recipients(activity) |> Enum.uniq() User.get_users_from_set(recipients, local_only) end def get_notified_from_activity(_, _local_only), do: [] - - defp maybe_notify_to_recipients( - recipients, - %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 - ) - when type == "Create" do - object = Object.normalize(data["object"]) - - object_data = - cond do - !is_nil(object) -> - object.data - - is_map(data["object"]) -> - data["object"] - - true -> - %{} - end - - tagged_mentions = maybe_extract_mentions(object_data) - - recipients ++ tagged_mentions - end - - defp maybe_notify_mentioned_recipients(recipients, _), do: recipients - - defp maybe_extract_mentions(%{"tag" => tag}) do - tag - |> Enum.filter(fn x -> is_map(x) end) - |> Enum.filter(fn x -> x["type"] == "Mention" end) - |> Enum.map(fn x -> x["href"] end) - end - - defp maybe_extract_mentions(_), do: [] end diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 7e30d224c..d36875705 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -259,4 +259,46 @@ defmodule Pleroma.Web.CommonAPI.Utils do } end) end + + def maybe_notify_to_recipients( + recipients, + %Activity{data: %{"to" => to, "type" => _type}} = _activity + ) do + recipients ++ to + end + + def maybe_notify_mentioned_recipients( + recipients, + %Activity{data: %{"to" => _to, "type" => type} = data} = _activity + ) + when type == "Create" do + object = Object.normalize(data["object"]) + + object_data = + cond do + !is_nil(object) -> + object.data + + is_map(data["object"]) -> + data["object"] + + true -> + %{} + end + + tagged_mentions = maybe_extract_mentions(object_data) + + recipients ++ tagged_mentions + end + + def maybe_notify_mentioned_recipients(recipients, _), do: recipients + + def maybe_extract_mentions(%{"tag" => tag}) do + tag + |> Enum.filter(fn x -> is_map(x) end) + |> Enum.filter(fn x -> x["type"] == "Mention" end) + |> Enum.map(fn x -> x["href"] end) + end + + def maybe_extract_mentions(_), do: [] end diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 0ddbef634..19b723586 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -155,10 +155,12 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || []) pinned = activity.id in user.info.pinned_activities - mentions = get_mentioned_users(opts[:mentioned] || [], user) + mentions = opts[:mentioned] || [] attentions = - activity.recipients + [] + |> Utils.maybe_notify_to_recipients(activity) + |> Utils.maybe_notify_mentioned_recipients(activity) |> Enum.map(fn ap_id -> Enum.find(mentions, fn user -> ap_id == user.ap_id end) end) |> Enum.filter(& &1) |> Enum.map(fn user -> UserView.render("show.json", %{user: user, for: opts[:for]}) end) @@ -224,10 +226,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do end end - defp get_mentioned_users(mentioned, user) do - mentioned ++ [user] - end - defp to_boolean(false) do false end diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 108e7bfc5..9ae7846c0 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -246,7 +246,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do pinned = activity.id in user.info.pinned_activities attentions = - activity.recipients + [] + |> Utils.maybe_notify_to_recipients(activity) + |> Utils.maybe_notify_mentioned_recipients(activity) |> Enum.map(fn ap_id -> get_user(ap_id, opts) end) |> Enum.filter(& &1) |> Enum.map(fn user -> UserView.render("show.json", %{user: user, for: opts[:for]}) end) -- cgit v1.2.3 From 656ed7c84a5d8e423999457f66d8259ec8aa9a44 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 25 Jan 2019 15:10:21 +0300 Subject: [#534] Configurable outgoing federation reachability timeout. --- lib/pleroma/instances.ex | 16 ++++++++++++++-- lib/pleroma/instances/instance.ex | 6 ++++-- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/instances.ex b/lib/pleroma/instances.ex index 6d445d6b3..0b08f0eb8 100644 --- a/lib/pleroma/instances.ex +++ b/lib/pleroma/instances.ex @@ -8,8 +8,20 @@ defmodule Pleroma.Instances do defdelegate set_reachable(url), to: @adapter defdelegate set_unreachable(url, unreachable_since \\ nil), to: @adapter - def reachability_time_threshold, - do: NaiveDateTime.add(NaiveDateTime.utc_now(), -30 * 24 * 3600, :second) + def reachability_datetime_threshold do + federation_reachability_timeout_days = + Pleroma.Config.get(:instance)[:federation_reachability_timeout_days] || 90 + + if federation_reachability_timeout_days > 0 do + NaiveDateTime.add( + NaiveDateTime.utc_now(), + -federation_reachability_timeout_days * 24 * 3600, + :second + ) + else + ~N[0000-01-01 00:00:00] + end + end def host(url_or_host) when is_binary(url_or_host) do if url_or_host =~ ~r/^http/i do diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index a17c8dab1..60e8d0e21 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -39,7 +39,8 @@ defmodule Pleroma.Instances.Instance do Repo.all( from(i in Instance, where: - i.host in ^hosts and i.unreachable_since <= ^Instances.reachability_time_threshold(), + i.host in ^hosts and + i.unreachable_since <= ^Instances.reachability_datetime_threshold(), select: i.host ) ) @@ -51,7 +52,8 @@ defmodule Pleroma.Instances.Instance do !Repo.one( from(i in Instance, where: - i.host == ^host(url) and i.unreachable_since <= ^Instances.reachability_time_threshold(), + i.host == ^host(url) and + i.unreachable_since <= ^Instances.reachability_datetime_threshold(), select: true ) ) -- cgit v1.2.3 From 465adedb7cc457303278444d0f56960f87fde1e9 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 25 Jan 2019 18:29:43 +0300 Subject: [#534] Websub fix: made SQL use UTC time zone when comparing with `valid_until` (instead of postgresql-server default time zone). --- lib/pleroma/web/websub/websub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index bb4442591..cbb7a5ac7 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -64,7 +64,7 @@ defmodule Pleroma.Web.Websub do from( sub in WebsubServerSubscription, where: sub.topic == ^topic and sub.state == "active", - where: fragment("? > NOW()", sub.valid_until) + where: fragment("? > (NOW() at time zone 'UTC')", sub.valid_until) ) subscriptions = Repo.all(query) -- cgit v1.2.3 From aa8ddfdbe2303375e3f019faca30a620bfc58fc7 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 25 Jan 2019 17:55:24 +0100 Subject: SPC fixes: Fix activities. --- lib/pleroma/spc_fixes/spc_fixes.ex | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/spc_fixes/spc_fixes.ex b/lib/pleroma/spc_fixes/spc_fixes.ex index e937d5871..41cf56fdd 100644 --- a/lib/pleroma/spc_fixes/spc_fixes.ex +++ b/lib/pleroma/spc_fixes/spc_fixes.ex @@ -4,6 +4,7 @@ alias Pleroma.Repo alias Pleroma.User +alias Pleroma.Activity import Ecto.Query defmodule Pleroma.SpcFixes do @@ -15,6 +16,7 @@ defmodule Pleroma.SpcFixes do {:ok, file} = File.read("lib/pleroma/spc_fixes/users_conversion.txt") + # Mapping of old ap_id to new ap_id and vice reversa mapping = file |> String.trim() @@ -24,7 +26,9 @@ defmodule Pleroma.SpcFixes do |> String.split("\t") end) |> Enum.reduce(%{}, fn [_id, old_ap_id, new_ap_id], acc -> - Map.put(acc, old_ap_id, String.trim(new_ap_id)) + acc + |> Map.put(String.trim(old_ap_id), String.trim(new_ap_id)) + |> Map.put(String.trim(new_ap_id), String.trim(old_ap_id)) end) # First, refetch all the old users. @@ -49,6 +53,7 @@ defmodule Pleroma.SpcFixes do |> Enum.each(fn user -> old_follower_address = User.ap_followers(user) + # Fix users query = from(u in User, where: ^old_follower_address in u.following, @@ -58,6 +63,30 @@ defmodule Pleroma.SpcFixes do ) Repo.update_all(query, []) + + # Fix activities + query = + from(a in Activity, + where: fragment("?->>'actor' = ?", a.data, ^mapping[user.ap_id]), + update: [ + set: [ + data: + fragment( + "jsonb_set(jsonb_set(?, '{actor}', ?), '{to}', (?->'to')::jsonb || ?)", + a.data, + ^user.ap_id, + a.data, + ^[user.follower_address] + ), + actor: ^user.ap_id + ], + push: [ + recipients: ^user.follower_address + ] + ] + ) + + Repo.update_all(query, []) end) end end -- cgit v1.2.3 From 060d280e64c201d3f8bec5615cc3b02cd460d3e1 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 25 Jan 2019 20:38:13 +0300 Subject: [#534] Made Salmon.send_to_user calls be handled through Federator.enqueue. --- lib/pleroma/web/federator/federator.ex | 6 +++++- lib/pleroma/web/salmon/salmon.ex | 14 +++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index f3a0e18b8..46f7a4973 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -6,7 +6,7 @@ defmodule Pleroma.Web.Federator do use GenServer alias Pleroma.User alias Pleroma.Activity - alias Pleroma.Web.{WebFinger, Websub} + alias Pleroma.Web.{WebFinger, Websub, Salmon} alias Pleroma.Web.Federator.RetryQueue alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Relay @@ -124,6 +124,10 @@ defmodule Pleroma.Web.Federator do end end + def handle(:publish_single_salmon, {user_or_url, feed, poster}) do + Salmon.send_to_user(user_or_url, feed, poster) + end + def handle(:publish_single_ap, params) do case ActivityPub.publish_one(params) do {:ok, _} -> diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 848131d52..17ca7a6e8 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -164,10 +164,10 @@ defmodule Pleroma.Web.Salmon do # push an activity to remote accounts # - defp send_to_user(%{info: %{salmon: salmon}}, feed, poster), + def send_to_user(%{info: %{salmon: salmon}}, feed, poster), do: send_to_user(salmon, feed, poster) - defp send_to_user(url, feed, poster) when is_binary(url) do + def send_to_user(url, feed, poster) when is_binary(url) do with {:reachable, true} <- {:reachable, Instances.reachable?(url)}, {:ok, %{status: code}} when code in 200..299 <- poster.( @@ -180,6 +180,7 @@ defmodule Pleroma.Web.Salmon do ) do Instances.set_reachable(url) Logger.debug(fn -> "Pushed to #{url}, code #{code}" end) + :ok else {:reachable, false} -> Logger.debug(fn -> "Pushing Salmon to #{url} skipped as marked unreachable)" end) @@ -188,10 +189,11 @@ defmodule Pleroma.Web.Salmon do e -> Instances.set_unreachable(url) Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end) + :error end end - defp send_to_user(_, _, _), do: nil + def send_to_user(_, _, _), do: :noop @supported_activities [ "Create", @@ -229,10 +231,8 @@ defmodule Pleroma.Web.Salmon do remote_users |> Enum.filter(&(&1.info.salmon in reachable_salmon_urls)) |> Enum.each(fn remote_user -> - Task.start(fn -> - Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end) - send_to_user(remote_user, feed, poster) - end) + Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end) + Pleroma.Web.Federator.enqueue(:publish_single_salmon, {remote_user, feed, poster}) end) end end -- cgit v1.2.3 From 15aa45ae8a2791a90a5832c1be28233959690987 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 26 Jan 2019 03:50:49 +0100 Subject: Web.ActivityPub.ActivityPub: Fix check_remote_limit/1 against activities with content: nil --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 6b4682e35..07779fa00 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -64,7 +64,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end - defp check_remote_limit(%{"object" => %{"content" => content}}) do + defp check_remote_limit(%{"object" => %{"content" => content}}) when not is_nil(content) do limit = Pleroma.Config.get([:instance, :remote_limit]) String.length(content) <= limit end -- cgit v1.2.3 From f9cae0d04fe4609f85d800351566080b5a4f34b7 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 19 Dec 2018 17:21:35 +0100 Subject: [WIP,MastoAPI] Multi-tag timelines --- lib/pleroma/web/activity_pub/activity_pub.ex | 10 +++++++++- .../web/mastodon_api/mastodon_api_controller.ex | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 6b4682e35..e0d020fab 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -426,10 +426,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_since(query, _), do: query + defp restrict_tag(query, %{"tag" => tag, "tag_reject" => tag_reject}) when tag_reject != [] do + from( + activity in query, + where: fragment("? <@ (? #> '{\"object\",\"tag\"}')", ^tag, activity.data), + where: fragment("? @> (? #> '{\"object\",\"tag\"}')", ^tag_reject, activity.data) + ) + end + defp restrict_tag(query, %{"tag" => tag}) do from( activity in query, - where: fragment("? <@ (? #> '{\"object\",\"tag\"}')", ^tag, activity.data) + where: fragment("? && jsonb_array_elements_text((? #> '{\"object\",\"tag\"}'))", ^tag, activity.data) ) end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index f4736fcb5..6811f827e 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -540,15 +540,27 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def hashtag_timeline(%{assigns: %{user: user}} = conn, params) do local_only = params["local"] in [true, "True", "true", "1"] - params = + tags = + ([params["tag"]] ++ (params["all"] || []) ++ (params["any"] || [])) + |> Enum.uniq() + |> Enum.filter(& &1) + |> Enum.map(&String.downcase(&1)) + + tag_reject = + params["none"] || + [] + |> Enum.map(&String.downcase(&1)) + + query_params = params |> Map.put("type", "Create") |> Map.put("local_only", local_only) |> Map.put("blocking_user", user) - |> Map.put("tag", String.downcase(params["tag"])) + |> Map.put("tag", tags) + |> Map.put("tag_reject", tag_reject) activities = - ActivityPub.fetch_public_activities(params) + ActivityPub.fetch_public_activities(query_params) |> Enum.reverse() conn -- cgit v1.2.3 From 1a9bb4daa0df06ac0f3d06ddacec71fa25f64db5 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 21 Dec 2018 18:24:13 +0100 Subject: [Web.ActivityPub.ActivityPub]: Fix restrict_tag() Thanks to Senko-san for the help on array-matching --- lib/pleroma/web/activity_pub/activity_pub.ex | 33 +++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index e0d020fab..d414ecc46 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -426,18 +426,41 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_since(query, _), do: query - defp restrict_tag(query, %{"tag" => tag, "tag_reject" => tag_reject}) when tag_reject != [] do + defp restrict_tag(query, %{"tag" => tag, "tag_reject" => tag_reject}) + when is_list(tag) and tag_reject != [] do from( activity in query, - where: fragment("? <@ (? #> '{\"object\",\"tag\"}')", ^tag, activity.data), - where: fragment("? @> (? #> '{\"object\",\"tag\"}')", ^tag_reject, activity.data) + where: + fragment( + "? && ARRAY(SELECT jsonb_array_elements_text((? #> '{\"object\",\"tag\"}')))", + ^tag, + activity.data + ), + where: + fragment( + "(not ? && ARRAY(SELECT jsonb_array_elements_text((? #> '{\"object\",\"tag\"}'))))", + ^tag_reject, + activity.data + ) + ) + end + + defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do + from( + activity in query, + where: + fragment( + "? && ARRAY(SELECT jsonb_array_elements_text((? #> '{\"object\",\"tag\"}')))", + ^tag, + activity.data + ) ) end - defp restrict_tag(query, %{"tag" => tag}) do + defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do from( activity in query, - where: fragment("? && jsonb_array_elements_text((? #> '{\"object\",\"tag\"}'))", ^tag, activity.data) + where: fragment("? <@ (? #> '{\"object\",\"tag\"}')", ^tag, activity.data) ) end -- cgit v1.2.3 From 4ad0ad14ed2d8a10bbf642fd989b3f7f55f9017d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 10 Jan 2019 16:07:32 +0100 Subject: Web.ActivityPub.ActivityPub: Simplify multi-hashtag, add tests --- lib/pleroma/web/activity_pub/activity_pub.ex | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index d414ecc46..62f4a33c8 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -430,30 +430,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do when is_list(tag) and tag_reject != [] do from( activity in query, - where: - fragment( - "? && ARRAY(SELECT jsonb_array_elements_text((? #> '{\"object\",\"tag\"}')))", - ^tag, - activity.data - ), - where: - fragment( - "(not ? && ARRAY(SELECT jsonb_array_elements_text((? #> '{\"object\",\"tag\"}'))))", - ^tag_reject, - activity.data - ) + where: fragment("(? #> '{\"object\",\"tag\"}') \\?| ?", activity.data, ^tag), + where: fragment("(not (? #> '{\"object\",\"tag\"}') \\?| ?)", activity.data, ^tag_reject) ) end defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do from( activity in query, - where: - fragment( - "? && ARRAY(SELECT jsonb_array_elements_text((? #> '{\"object\",\"tag\"}')))", - ^tag, - activity.data - ) + where: fragment("(? #> '{\"object\",\"tag\"}') \\?| ?", activity.data, ^tag) ) end -- cgit v1.2.3 From 5a84def6a6cd6ac782e16b2aace220a99c31ace7 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 10 Jan 2019 16:44:28 +0100 Subject: Fix the logic in multi-hashtag TLs --- lib/pleroma/web/activity_pub/activity_pub.ex | 19 ++++++++++++++++--- .../web/mastodon_api/mastodon_api_controller.ex | 8 +++++++- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 62f4a33c8..d94ad9748 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -426,15 +426,26 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_since(query, _), do: query - defp restrict_tag(query, %{"tag" => tag, "tag_reject" => tag_reject}) - when is_list(tag) and tag_reject != [] do + defp restrict_tag_reject(query, %{"tag_reject" => tag_reject}) + when is_list(tag_reject) and tag_reject != [] do from( activity in query, - where: fragment("(? #> '{\"object\",\"tag\"}') \\?| ?", activity.data, ^tag), where: fragment("(not (? #> '{\"object\",\"tag\"}') \\?| ?)", activity.data, ^tag_reject) ) end + defp restrict_tag_reject(query, _), do: query + + defp restrict_tag_all(query, %{"tag_all" => tag_all}) + when is_list(tag_all) and tag_all != [] do + from( + activity in query, + where: fragment("(? #> '{\"object\",\"tag\"}') \\?& ?", activity.data, ^tag_all) + ) + end + + defp restrict_tag_all(query, _), do: query + defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do from( activity in query, @@ -591,6 +602,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do base_query |> restrict_recipients(recipients, opts["user"]) |> restrict_tag(opts) + |> restrict_tag_reject(opts) + |> restrict_tag_all(opts) |> restrict_since(opts) |> restrict_local(opts) |> restrict_limit(opts) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 6811f827e..4c5f1e7a9 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -541,11 +541,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do local_only = params["local"] in [true, "True", "true", "1"] tags = - ([params["tag"]] ++ (params["all"] || []) ++ (params["any"] || [])) + ([params["tag"]] ++ (params["any"] || [])) |> Enum.uniq() |> Enum.filter(& &1) |> Enum.map(&String.downcase(&1)) + tag_all = + params["all"] || + [] + |> Enum.map(&String.downcase(&1)) + tag_reject = params["none"] || [] @@ -557,6 +562,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> Map.put("local_only", local_only) |> Map.put("blocking_user", user) |> Map.put("tag", tags) + |> Map.put("tag_all", tag_all) |> Map.put("tag_reject", tag_reject) activities = -- cgit v1.2.3 From 3f64379b1382f2e26cacd28da230c67bf68656a0 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 14 Jan 2019 00:06:55 +0100 Subject: Web.MastodonAPI.MastodonAPIController: Add Rich-Media support --- .../web/mastodon_api/mastodon_api_controller.ex | 23 ++++++++++++++++++++++ lib/pleroma/web/router.ex | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index f4736fcb5..86607e7af 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1322,6 +1322,29 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end + defp status_first_external_url(content) do + content + |> Floki.filter_out("a.mention") + |> Floki.attribute("a", "href") + |> Enum.at(0) + end + + def status_card(conn, %{"id" => status_id}) do + with %Activity{} = activity <- Repo.get(Activity, status_id), + true <- ActivityPub.is_public?(activity), + page_url <- status_first_external_url(activity.data["object"]["content"]), + {:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do + card = + rich_media + |> Map.take([:image, :title, :url, :description]) + |> Map.put(:type, "link") + + json(conn, card) + else + _ -> json(conn, %{}) + end + end + def try_render(conn, target, params) when is_binary(target) do res = render(conn, target, params) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index b83790858..e749aa834 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -258,7 +258,7 @@ defmodule Pleroma.Web.Router do get("/statuses/:id", MastodonAPIController, :get_status) get("/statuses/:id/context", MastodonAPIController, :get_context) - get("/statuses/:id/card", MastodonAPIController, :empty_object) + get("/statuses/:id/card", MastodonAPIController, :status_card) get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by) get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by) -- cgit v1.2.3 From 39863236ebba227d8e742680b739d18d2d211fb0 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 21 Jan 2019 00:53:41 +0100 Subject: Web.MastodonAPI.MastodonAPIController: generic get_status_card/1 function for MastoAPI 2.6.x Mastodon API 2.6.x added a card key to the Status object so the Card can be shown in the timeline without an extra request at each status. --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 86607e7af..9d3fa532d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1329,22 +1329,23 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> Enum.at(0) end - def status_card(conn, %{"id" => status_id}) do + def get_status_card(status_id) do with %Activity{} = activity <- Repo.get(Activity, status_id), true <- ActivityPub.is_public?(activity), page_url <- status_first_external_url(activity.data["object"]["content"]), {:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do - card = - rich_media - |> Map.take([:image, :title, :url, :description]) - |> Map.put(:type, "link") - - json(conn, card) + rich_media + |> Map.take([:image, :title, :url, :description]) + |> Map.put(:type, "link") else - _ -> json(conn, %{}) + _ -> %{} end end + def status_card(conn, %{"id" => status_id}) do + json(conn, get_status_card(status_id)) + end + def try_render(conn, target, params) when is_binary(target) do res = render(conn, target, params) -- cgit v1.2.3 From 78047d57bf52e53c5f073435928983922f9538f5 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 26 Jan 2019 14:47:32 +0000 Subject: mastodon api: provider_name setting is required too on the card --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 9d3fa532d..91cc76fe7 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1337,6 +1337,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do rich_media |> Map.take([:image, :title, :url, :description]) |> Map.put(:type, "link") + |> Map.put(:provider_name, rich_media.site_name) else _ -> %{} end -- cgit v1.2.3 From be9abb2cc5fc219ca49ac6b32afed3eac323bf7a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 26 Jan 2019 14:55:12 +0000 Subject: html: add utility function to extract first URL from an object and cache the result --- lib/pleroma/html.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index f5c6e5033..fb602d6b6 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -58,6 +58,20 @@ defmodule Pleroma.HTML do "#{signature}#{to_string(scrubber)}" end) end + + def extract_first_external_url(object, content) do + key = "URL|#{object.id}" + + Cachex.fetch!(:scrubber_cache, key, fn _key -> + result = + content + |> Floki.filter_out("a.mention") + |> Floki.attribute("a", "href") + |> Enum.at(0) + + {:commit, result} + end) + end end defmodule Pleroma.HTML.Scrubber.TwitterText do -- cgit v1.2.3 From 8018ae7ae5ab3747e5fefdc9a094fe4b3d90dbb6 Mon Sep 17 00:00:00 2001 From: href Date: Sat, 26 Jan 2019 15:55:53 +0100 Subject: Join on preloads to avoid N+1 queries --- lib/pleroma/notification.ex | 6 ++++-- lib/pleroma/plugs/oauth_plug.ex | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index e47145601..2364d36da 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -35,7 +35,8 @@ defmodule Pleroma.Notification do n in Notification, where: n.user_id == ^user.id, order_by: [desc: n.id], - preload: [:activity], + join: activity in assoc(n, :activity), + preload: [activity: activity], limit: 20 ) @@ -66,7 +67,8 @@ defmodule Pleroma.Notification do from( n in Notification, where: n.id == ^id, - preload: [:activity] + join: activity in assoc(n, :activity), + preload: [activity: activity] ) notification = Repo.one(query) diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 437aa95b3..945a1d49f 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -33,7 +33,12 @@ defmodule Pleroma.Plugs.OAuthPlug do # @spec fetch_user_and_token(String.t()) :: {:ok, User.t(), Token.t()} | nil defp fetch_user_and_token(token) do - query = from(q in Token, where: q.token == ^token, preload: [:user]) + query = + from(t in Token, + where: t.token == ^token, + join: user in assoc(t, :user), + preload: [user: user] + ) with %Token{user: %{info: %{deactivated: false} = _} = user} = token_record <- Repo.one(query) do {:ok, user, token_record} -- cgit v1.2.3 From 86037e9c3980fbab94935844c09bdd2f002140aa Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 26 Jan 2019 14:56:14 +0000 Subject: mastodon api: use HTML.extract_first_external_url() --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 91cc76fe7..ae744da60 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -6,6 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do use Pleroma.Web, :controller alias Pleroma.{Repo, Object, Activity, User, Notification, Stats} alias Pleroma.Web + alias Pleroma.HTML alias Pleroma.Web.MastodonAPI.{ StatusView, @@ -1322,22 +1323,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end - defp status_first_external_url(content) do - content - |> Floki.filter_out("a.mention") - |> Floki.attribute("a", "href") - |> Enum.at(0) - end - def get_status_card(status_id) do with %Activity{} = activity <- Repo.get(Activity, status_id), true <- ActivityPub.is_public?(activity), - page_url <- status_first_external_url(activity.data["object"]["content"]), + %Object{} = object <- Object.normalize(activity.data["object"]), + page_url <- HTML.extract_first_external_url(object, object.data["content"]), {:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do + site_name = rich_media[:site_name] || URI.parse(page_url).host + rich_media |> Map.take([:image, :title, :url, :description]) |> Map.put(:type, "link") - |> Map.put(:provider_name, rich_media.site_name) + |> Map.put(:provider_name, site_name) else _ -> %{} end -- cgit v1.2.3 From 1f7843b9b8afcb559c8ba59388724dbf4ef3e3c9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 26 Jan 2019 15:20:27 +0000 Subject: mastodon api: use OGP uri instead of page_url for deducing domain name, fix test --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index ae744da60..a60532b55 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1329,12 +1329,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do %Object{} = object <- Object.normalize(activity.data["object"]), page_url <- HTML.extract_first_external_url(object, object.data["content"]), {:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do + page_url = rich_media[:url] || page_url site_name = rich_media[:site_name] || URI.parse(page_url).host rich_media - |> Map.take([:image, :title, :url, :description]) + |> Map.take([:image, :title, :description]) |> Map.put(:type, "link") |> Map.put(:provider_name, site_name) + |> Map.put(:url, page_url) else _ -> %{} end -- cgit v1.2.3 From de956b9e04f9c3706d50522bf19a0fb6477feecc Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 26 Jan 2019 16:46:20 +0100 Subject: Web.MastodonAPI.MastodonAPIController: tag+any bookmark params in a array and flatten it --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 4c5f1e7a9..39e0f8492 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -541,7 +541,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do local_only = params["local"] in [true, "True", "true", "1"] tags = - ([params["tag"]] ++ (params["any"] || [])) + [params["tag"], params["any"]] + |> List.flatten() |> Enum.uniq() |> Enum.filter(& &1) |> Enum.map(&String.downcase(&1)) -- cgit v1.2.3 From d6015338c8fea62602e969a498b80c2a5b754909 Mon Sep 17 00:00:00 2001 From: href Date: Sat, 26 Jan 2019 16:58:23 +0100 Subject: Flake: support integers in from_string/1 Some previously issued stateless tokens have integer ids in them. --- lib/pleroma/flake_id.ex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex index 26399ae05..69482f69a 100644 --- a/lib/pleroma/flake_id.ex +++ b/lib/pleroma/flake_id.ex @@ -33,6 +33,10 @@ defmodule Pleroma.FlakeId do def to_string(s), do: s + def from_string(int) when is_integer(int) do + from_string(Kernel.to_string(int)) + end + for i <- [-1, 0] do def from_string(unquote(i)), do: <<0::integer-size(128)>> def from_string(unquote(Kernel.to_string(i))), do: <<0::integer-size(128)>> -- cgit v1.2.3 From 8f2f471e948160f96549ca9744cca56f940a8658 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 26 Jan 2019 16:26:11 +0000 Subject: rich media: gracefully handle fetching nil URIs --- lib/pleroma/web/rich_media/parser.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 6da83c6e4..947dc0c3c 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -5,11 +5,19 @@ defmodule Pleroma.Web.RichMedia.Parser do Pleroma.Web.RichMedia.Parsers.OEmbed ] + def parse(nil), do: {:error, "No URL provided"} + if Mix.env() == :test do def parse(url), do: parse_url(url) else - def parse(url), - do: Cachex.fetch!(:rich_media_cache, url, fn _ -> parse_url(url) end) + def parse(url) do + with {:ok, data} <- Cachex.fetch(:rich_media_cache, url, fn _ -> parse_url(url) end) do + data + else + _e -> + {:error, "Parsing error"} + end + end end defp parse_url(url) do -- cgit v1.2.3 From a65c18859307f4aacf42eb5dd14e63ad76747a6d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 27 Jan 2019 10:21:13 +0100 Subject: Web.MastodonAPI.AccountView: Add is_moderator and is_admin Closes: https://git.pleroma.social/pleroma/pleroma/issues/557 --- lib/pleroma/web/mastodon_api/views/account_view.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index bfd6b8b22..0ba4289da 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -112,7 +112,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do # Pleroma extension pleroma: %{ confirmation_pending: user_info.confirmation_pending, - tags: user.tags + tags: user.tags, + is_moderator: user.info.is_moderator, + is_admin: user.info.is_admin } } end -- cgit v1.2.3 From e0e0cc5ab044b64b83abf6382780ff1342025a43 Mon Sep 17 00:00:00 2001 From: href Date: Sun, 27 Jan 2019 16:04:36 +0100 Subject: Flake: random worker id --- lib/pleroma/flake_id.ex | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex index 26399ae05..3623ac597 100644 --- a/lib/pleroma/flake_id.ex +++ b/lib/pleroma/flake_id.ex @@ -90,7 +90,7 @@ defmodule Pleroma.FlakeId do @impl GenServer def init([]) do - {:ok, %FlakeId{node: mac(), time: time()}} + {:ok, %FlakeId{node: worker_id(), time: time()}} end @impl GenServer @@ -161,23 +161,8 @@ defmodule Pleroma.FlakeId do 1_000_000_000 * mega_seconds + seconds * 1000 + :erlang.trunc(micro_seconds / 1000) end - def mac do - {:ok, addresses} = :inet.getifaddrs() - - macids = - Enum.reduce(addresses, [], fn {_iface, attrs}, acc -> - case attrs[:hwaddr] do - [0, 0, 0 | _] -> acc - mac when is_list(mac) -> [mac_to_worker_id(mac) | acc] - _ -> acc - end - end) - - List.first(macids) - end - - def mac_to_worker_id(mac) do - <> = :binary.list_to_bin(mac) + defp worker_id() do + <> = :crypto.strong_rand_bytes(6) worker end end -- cgit v1.2.3 From f83bae7c2224edbaddc46fbc5468abbfeacc70bc Mon Sep 17 00:00:00 2001 From: href Date: Sun, 27 Jan 2019 19:15:35 +0100 Subject: Views: wrap activity rendering in a rescue this avoids complete timeline breakage when an activity fucks up rendering. --- lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- lib/pleroma/web/twitter_api/views/activity_view.ex | 2 +- lib/pleroma/web/web.ex | 27 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 7a384e941..0f2679444 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -49,7 +49,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do replied_to_activities = get_replied_to_activities(opts.activities) opts.activities - |> render_many( + |> safe_render_many( StatusView, "status.json", Map.put(opts, :replied_to_activities, replied_to_activities) diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index e0a52d94a..a01ee0010 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -114,7 +114,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do |> Map.put(:context_ids, context_ids) |> Map.put(:users, users) - render_many( + safe_render_many( opts.activities, ActivityView, "activity.json", diff --git a/lib/pleroma/web/web.ex b/lib/pleroma/web/web.ex index 74b13f929..30558e692 100644 --- a/lib/pleroma/web/web.ex +++ b/lib/pleroma/web/web.ex @@ -38,6 +38,33 @@ defmodule Pleroma.Web do import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1] import Pleroma.Web.{ErrorHelpers, Gettext, Router.Helpers} + + require Logger + + @doc "Same as `render/3` but wrapped in a rescue block" + def safe_render(view, template, assigns \\ %{}) do + Phoenix.View.render(view, template, assigns) + rescue + error -> + Logger.error( + "#{__MODULE__} failed to render #{inspect({view, template})}: #{inspect(error)}" + ) + + Logger.error(inspect(__STACKTRACE__)) + nil + end + + @doc """ + Same as `render_many/4` but wrapped in rescue block. + """ + def safe_render_many(collection, view, template, assigns \\ %{}) do + Enum.map(collection, fn resource -> + as = Map.get(assigns, :as) || view.__resource__ + assigns = Map.put(assigns, as, resource) + safe_render(view, template, assigns) + end) + |> Enum.filter(& &1) + end end end -- cgit v1.2.3 From 77f2137383a72aac7d0390ca3bff13b794dcc12c Mon Sep 17 00:00:00 2001 From: href Date: Sun, 27 Jan 2019 19:27:16 +0100 Subject: Transmogrifier: fix incoming objects with invalid likes --- lib/pleroma/web/activity_pub/transmogrifier.ex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 6656a11c6..c2ced51d8 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -141,11 +141,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do |> Map.put("actor", get_actor(%{"actor" => actor})) end - def fix_likes(%{"likes" => likes} = object) - when is_bitstring(likes) do - # Check for standardisation - # This is what Peertube does - # curl -H 'Accept: application/activity+json' $likes | jq .totalItems + # Check for standardisation + # This is what Peertube does + # curl -H 'Accept: application/activity+json' $likes | jq .totalItems + # Prismo returns only an integer (count) as "likes" + def fix_likes(%{"likes" => likes} = object) when not is_map(likes) do object |> Map.put("likes", []) |> Map.put("like_count", 0) -- cgit v1.2.3 From 2e277dd4ad96ef6f7ce3267eb05d0b84668df772 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 27 Jan 2019 21:03:15 +0100 Subject: Fix objects. --- lib/pleroma/spc_fixes/spc_fixes.ex | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/spc_fixes/spc_fixes.ex b/lib/pleroma/spc_fixes/spc_fixes.ex index 41cf56fdd..86bbb7f6f 100644 --- a/lib/pleroma/spc_fixes/spc_fixes.ex +++ b/lib/pleroma/spc_fixes/spc_fixes.ex @@ -5,6 +5,7 @@ alias Pleroma.Repo alias Pleroma.User alias Pleroma.Activity +alias Pleroma.Object import Ecto.Query defmodule Pleroma.SpcFixes do @@ -87,6 +88,26 @@ defmodule Pleroma.SpcFixes do ) Repo.update_all(query, []) + + # Fix objects + query = + from(a in Object, + where: fragment("?->>'actor' = ?", a.data, ^mapping[user.ap_id]), + update: [ + set: [ + data: + fragment( + "jsonb_set(jsonb_set(?, '{actor}', ?), '{to}', (?->'to')::jsonb || ?)", + a.data, + ^user.ap_id, + a.data, + ^[user.follower_address] + ) + ] + ] + ) + + Repo.update_all(query, []) end) end end -- cgit v1.2.3 From 71bb90073b773bad1e4783bb574902f7dc0b4976 Mon Sep 17 00:00:00 2001 From: href Date: Sun, 27 Jan 2019 22:51:50 +0100 Subject: /notice/:id - send the FE index even if 404 this allows to open private activities by URL when you are logged in, and to let the FE display a 404 page --- lib/pleroma/web/ostatus/ostatus_controller.ex | 7 +++++-- lib/pleroma/web/router.ex | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 823619edb..297aca2f9 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -166,10 +166,13 @@ defmodule Pleroma.Web.OStatus.OStatusController do end else {:public?, false} -> - {:error, :not_found} + conn + |> put_status(404) + |> Fallback.RedirectController.redirector(nil, 404) {:activity, nil} -> - {:error, :not_found} + conn + |> Fallback.RedirectController.redirector(nil, 404) e -> e diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index e749aa834..31f739738 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -523,10 +523,10 @@ defmodule Fallback.RedirectController do alias Pleroma.Web.Metadata alias Pleroma.User - def redirector(conn, _params) do + def redirector(conn, _params, code \\ 200) do conn |> put_resp_content_type("text/html") - |> send_file(200, index_file_path()) + |> send_file(code, index_file_path()) end def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do -- cgit v1.2.3 From 872241d7c50a5c92f7867b89672ca451b40d44da Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 19 Sep 2018 02:10:54 +0200 Subject: /web/index template: Modify for glitch-soc --- .../templates/mastodon_api/mastodon/index.html.eex | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex b/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex index 0862412ea..9a725e420 100644 --- a/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex +++ b/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex @@ -1,23 +1,28 @@ + + <%= Application.get_env(:pleroma, :instance)[:name] %> - - - - + + - - - - - - + + + + - + + + + + + + +
-- cgit v1.2.3 From cda1470e02100bfcdcbd128fd08d0af64dca7271 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 19 Sep 2018 02:04:56 +0200 Subject: [MastoAPI][GlitchAPI] Add bookmarks --- lib/pleroma/user.ex | 17 +++++++++++ .../web/mastodon_api/mastodon_api_controller.ex | 35 ++++++++++++++++++++++ lib/pleroma/web/mastodon_api/views/status_view.ex | 3 ++ lib/pleroma/web/router.ex | 3 ++ 4 files changed, 58 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1468cc133..aced21ece 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -39,6 +39,7 @@ defmodule Pleroma.User do field(:follower_address, :string) field(:search_rank, :float, virtual: true) field(:tags, {:array, :string}, default: []) + field(:bookmarks, {:array, :string}, default: []) field(:last_refreshed_at, :naive_datetime) has_many(:notifications, Notification) embeds_one(:info, Pleroma.User.Info) @@ -1156,6 +1157,22 @@ defmodule Pleroma.User do updated_user end + def bookmark(%User{} = user, status_id) do + bookmarks = Enum.uniq(user.bookmarks ++ [status_id]) + update_bookmarks(user, bookmarks) + end + + def unbookmark(%User{} = user, status_id) do + bookmarks = Enum.uniq(user.bookmarks -- [status_id]) + update_bookmarks(user, bookmarks) + end + + def update_bookmarks(%User{} = user, bookmarks) do + user + |> change(%{bookmarks: bookmarks}) + |> update_and_set_cache + end + defp normalize_tags(tags) do [tags] |> List.flatten() diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index a366a149f..2530b51d2 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -424,6 +424,28 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end + def bookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do + with %Activity{} = activity <- Repo.get(Activity, id), + %User{} = user <- User.get_by_nickname(user.nickname), + true <- ActivityPub.visible_for_user?(activity, user), + {:ok, user} <- User.bookmark(user, activity.data["object"]["id"]) do + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) + end + end + + def unbookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do + with %Activity{} = activity <- Repo.get(Activity, id), + %User{} = user <- User.get_by_nickname(user.nickname), + true <- ActivityPub.visible_for_user?(activity, user), + {:ok, user} <- User.unbookmark(user, activity.data["object"]["id"]) do + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) + end + end + def notifications(%{assigns: %{user: user}} = conn, params) do notifications = Notification.for_user(user, params) @@ -859,6 +881,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> render("index.json", %{activities: activities, for: user, as: :activity}) end + def bookmarks(%{assigns: %{user: user}} = conn, _) do + user = Repo.get(User, user.id) + + activities = + user.bookmarks + |> Enum.map(fn id -> Activity.get_create_by_object_ap_id(id) end) + |> Enum.reverse() + + conn + |> put_view(StatusView) + |> render("index.json", %{activities: activities, for: user, as: :activity}) + end + def get_lists(%{assigns: %{user: user}} = conn, opts) do lists = Pleroma.List.for_user(user, opts) res = ListView.render("lists.json", lists: lists) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 0f2679444..0b6a9d9fc 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -88,6 +88,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do favourites_count: 0, reblogged: false, favourited: false, + bookmarked: false, muted: false, pinned: pinned?(activity, user), sensitive: false, @@ -122,6 +123,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || []) favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || []) + bookmarked = opts[:for] && object["id"] in opts[:for].bookmarks attachment_data = object["attachment"] || [] attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment) @@ -155,6 +157,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do favourites_count: like_count, reblogged: present?(repeated), favourited: present?(favorited), + bookmarked: present?(bookmarked), muted: false, pinned: pinned?(activity, user), sensitive: sensitive, diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 31f739738..3d0227582 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -185,6 +185,7 @@ defmodule Pleroma.Web.Router do get("/timelines/direct", MastodonAPIController, :dm_timeline) get("/favourites", MastodonAPIController, :favourites) + get("/bookmarks", MastodonAPIController, :bookmarks) post("/statuses", MastodonAPIController, :post_status) delete("/statuses/:id", MastodonAPIController, :delete_status) @@ -195,6 +196,8 @@ defmodule Pleroma.Web.Router do post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status) post("/statuses/:id/pin", MastodonAPIController, :pin_status) post("/statuses/:id/unpin", MastodonAPIController, :unpin_status) + post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status) + post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status) post("/notifications/clear", MastodonAPIController, :clear_notifications) post("/notifications/dismiss", MastodonAPIController, :dismiss_notification) -- cgit v1.2.3 From 132d815f1f749cec4b54083fc46046c45e7d0d04 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 27 Jan 2019 09:37:11 +0000 Subject: mastodon api: factor out status card fetching, move status card rendering to statusview, add opengraph extended data --- lib/pleroma/web/mastodon_api/mastodon_api.ex | 19 ++++++++++++++++ .../web/mastodon_api/mastodon_api_controller.ex | 25 ++++------------------ lib/pleroma/web/mastodon_api/views/status_view.ex | 23 ++++++++++++++++++++ 3 files changed, 46 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api.ex b/lib/pleroma/web/mastodon_api/mastodon_api.ex index 8b1378917..9d1fb22ea 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api.ex @@ -1 +1,20 @@ +# Pleroma: A lightweight social networking server +# Copyright _ 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only +defmodule Pleroma.Web.MastodonAPI do + alias Pleroma.{Repo, Activity, Object, HTML} + alias Pleroma.Web.ActivityPub.ActivityPub + + def get_status_card(status_id) do + with %Activity{} = activity <- Repo.get(Activity, status_id), + true <- ActivityPub.is_public?(activity), + %Object{} = object <- Object.normalize(activity.data["object"]), + page_url <- HTML.extract_first_external_url(object, object.data["content"]), + {:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do + %{page_url: page_url, rich_media: rich_media} + else + _ -> %{} + end + end +end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index a366a149f..1cdb96989 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -6,8 +6,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do use Pleroma.Web, :controller alias Pleroma.{Repo, Object, Activity, User, Notification, Stats} alias Pleroma.Web - alias Pleroma.HTML + alias Pleroma.Web.MastodonAPI alias Pleroma.Web.MastodonAPI.{ StatusView, AccountView, @@ -1342,27 +1342,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end - def get_status_card(status_id) do - with %Activity{} = activity <- Repo.get(Activity, status_id), - true <- ActivityPub.is_public?(activity), - %Object{} = object <- Object.normalize(activity.data["object"]), - page_url <- HTML.extract_first_external_url(object, object.data["content"]), - {:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do - page_url = rich_media[:url] || page_url - site_name = rich_media[:site_name] || URI.parse(page_url).host - - rich_media - |> Map.take([:image, :title, :description]) - |> Map.put(:type, "link") - |> Map.put(:provider_name, site_name) - |> Map.put(:url, page_url) - else - _ -> %{} - end - end - def status_card(conn, %{"id" => status_id}) do - json(conn, get_status_card(status_id)) + data = StatusView.render("card.json", MastodonAPI.get_status_card(status_id)) + + json(conn, data) end def try_render(conn, target, params) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 0f2679444..a9e1e03ba 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -176,6 +176,29 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do nil end + def render("card.json", %{rich_media: rich_media, page_url: page_url}) do + page_url = rich_media[:url] || page_url + page_url_data = URI.parse(page_url) + site_name = rich_media[:site_name] || page_url_data.host + + %{ + type: "link", + provider_name: site_name, + provider_url: page_url_data.scheme <> "://" <> page_url_data.host, + url: page_url, + image: rich_media[:image], + title: rich_media[:title], + description: rich_media[:description], + pleroma: %{ + opengraph: rich_media + } + } + end + + def render("card.json", _) do + nil + end + def render("attachment.json", %{attachment: attachment}) do [attachment_url | _] = attachment["url"] media_type = attachment_url["mediaType"] || attachment_url["mimeType"] || "image" -- cgit v1.2.3 From 5a37ddc2dc9c2d1dcecafa8cefbb679da58e6371 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 27 Jan 2019 12:15:41 +0000 Subject: mastodon api: embed card in status object --- lib/pleroma/web/mastodon_api/views/status_view.ex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index a9e1e03ba..ccc954985 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -11,6 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do alias Pleroma.User alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MediaProxy + alias Pleroma.Web.MastodonAPI alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MastodonAPI.StatusView @@ -140,6 +141,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do __MODULE__ ) + card = render("card.json", MastodonAPI.get_status_card(activity.id)) + %{ id: to_string(activity.id), uri: object["id"], @@ -148,6 +151,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do in_reply_to_id: reply_to && to_string(reply_to.id), in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id), reblog: nil, + card: card, content: content, created_at: created_at, reblogs_count: announcement_count, -- cgit v1.2.3 From 5d895093fd26ce0884957664c1214a66f5a36195 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 27 Jan 2019 12:16:08 +0000 Subject: twitter api: embed card in twitterapi posts --- lib/pleroma/web/twitter_api/views/activity_view.ex | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index a01ee0010..77e9af348 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -10,6 +10,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do alias Pleroma.Web.TwitterAPI.ActivityView alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter + alias Pleroma.Web.MastodonAPI + alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.Activity alias Pleroma.HTML alias Pleroma.Object @@ -274,6 +276,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do summary = HTML.strip_tags(summary) + card = StatusView.render("card.json", MastodonAPI.get_status_card(activity.id)) + %{ "id" => activity.id, "uri" => activity.data["object"]["id"], @@ -300,9 +304,10 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do "tags" => tags, "activity_type" => "post", "possibly_sensitive" => possibly_sensitive, - "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), + "visibility" => StatusView.get_visibility(object), "summary" => summary, - "summary_html" => summary |> Formatter.emojify(object["emoji"]) + "summary_html" => summary |> Formatter.emojify(object["emoji"]), + "card" => card } end -- cgit v1.2.3 From de42646634e65a5216efe2f353352575b97b6390 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 27 Jan 2019 12:21:05 +0000 Subject: rich media: add try/rescue to ensure we catch parsing and fetching failures --- lib/pleroma/web/rich_media/parser.ex | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 947dc0c3c..7787bf954 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -21,9 +21,14 @@ defmodule Pleroma.Web.RichMedia.Parser do end defp parse_url(url) do - {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url) + try do + {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url) - html |> maybe_parse() |> get_parsed_data() + html |> maybe_parse() |> get_parsed_data() + rescue + _e -> + {:error, "Parsing error"} + end end defp maybe_parse(html) do -- cgit v1.2.3 From 07a9a891ad93d7fb21d596deb5211b4570cf1acb Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 27 Jan 2019 12:27:37 +0000 Subject: twitter api: fix up activity representer --- lib/pleroma/web/twitter_api/representers/activity_representer.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 19b723586..364aa7af3 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -12,6 +12,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Formatter alias Pleroma.HTML + alias Pleroma.Web.MastodonAPI + alias Pleroma.Web.MastodonAPI.StatusView defp user_by_ap_id(user_list, ap_id) do Enum.find(user_list, fn %{ap_id: user_id} -> ap_id == user_id end) @@ -186,6 +188,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do summary = HTML.strip_tags(object["summary"]) + card = StatusView.render("card.json", MastodonAPI.get_status_card(activity.id)) + %{ "id" => activity.id, "uri" => activity.data["object"]["id"], @@ -214,7 +218,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do "possibly_sensitive" => possibly_sensitive, "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), "summary" => summary, - "summary_html" => summary |> Formatter.emojify(object["emoji"]) + "summary_html" => summary |> Formatter.emojify(object["emoji"]), + "card" => card } end -- cgit v1.2.3 From 6096846f5f33e1e81ef72c0f97b30c2745426c5d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 27 Jan 2019 12:34:49 +0000 Subject: API: kill /api/rich_media/parse endpoint --- .../web/rich_media/controllers/rich_media_controller.ex | 17 ----------------- lib/pleroma/web/router.ex | 6 ------ 2 files changed, 23 deletions(-) delete mode 100644 lib/pleroma/web/rich_media/controllers/rich_media_controller.ex (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/controllers/rich_media_controller.ex b/lib/pleroma/web/rich_media/controllers/rich_media_controller.ex deleted file mode 100644 index 91019961d..000000000 --- a/lib/pleroma/web/rich_media/controllers/rich_media_controller.ex +++ /dev/null @@ -1,17 +0,0 @@ -defmodule Pleroma.Web.RichMedia.RichMediaController do - use Pleroma.Web, :controller - - import Pleroma.Web.ControllerHelper, only: [json_response: 3] - - def parse(conn, %{"url" => url}) do - case Pleroma.Web.RichMedia.Parser.parse(url) do - {:ok, data} -> - conn - |> json_response(200, data) - - {:error, msg} -> - conn - |> json_response(404, msg) - end - end -end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 31f739738..68e7a44b6 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -239,12 +239,6 @@ defmodule Pleroma.Web.Router do put("/settings", MastodonAPIController, :put_settings) end - scope "/api", Pleroma.Web.RichMedia do - pipe_through(:authenticated_api) - - get("/rich_media/parse", RichMediaController, :parse) - end - scope "/api/v1", Pleroma.Web.MastodonAPI do pipe_through(:api) get("/instance", MastodonAPIController, :masto_instance) -- cgit v1.2.3 From 24a103a1fe199a559a22ddb55c747a89f5576e55 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 27 Jan 2019 12:39:20 +0000 Subject: mastodon api: formatting --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 1cdb96989..b5231a326 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -8,6 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do alias Pleroma.Web alias Pleroma.Web.MastodonAPI + alias Pleroma.Web.MastodonAPI.{ StatusView, AccountView, @@ -500,7 +501,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def upload(%{assigns: %{user: user}} = conn, %{"file" => file} = data) do with {:ok, object} <- - ActivityPub.upload(file, + ActivityPub.upload( + file, actor: User.ap_id(user), description: Map.get(data, "description") ) do @@ -1101,7 +1103,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def login(conn, _) do with {:ok, app} <- get_or_make_app() do path = - o_auth_path(conn, :authorize, + o_auth_path( + conn, + :authorize, response_type: "code", client_id: app.client_id, redirect_uri: ".", -- cgit v1.2.3 From 8e42251e064b4de6f1d767f28c79d64ca74dc245 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 28 Jan 2019 06:04:54 +0000 Subject: rich media: add helpers module, use instead of MastodonAPI module --- lib/pleroma/web/mastodon_api/mastodon_api.ex | 19 ------------------- .../web/mastodon_api/mastodon_api_controller.ex | 16 ++++++++++++---- lib/pleroma/web/mastodon_api/views/status_view.ex | 3 +-- lib/pleroma/web/rich_media/helpers.ex | 18 ++++++++++++++++++ .../twitter_api/representers/activity_representer.ex | 7 +++++-- lib/pleroma/web/twitter_api/views/activity_view.ex | 7 +++++-- 6 files changed, 41 insertions(+), 29 deletions(-) create mode 100644 lib/pleroma/web/rich_media/helpers.ex (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api.ex b/lib/pleroma/web/mastodon_api/mastodon_api.ex index 9d1fb22ea..8b1378917 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api.ex @@ -1,20 +1 @@ -# Pleroma: A lightweight social networking server -# Copyright _ 2017-2019 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Web.MastodonAPI do - alias Pleroma.{Repo, Activity, Object, HTML} - alias Pleroma.Web.ActivityPub.ActivityPub - - def get_status_card(status_id) do - with %Activity{} = activity <- Repo.get(Activity, status_id), - true <- ActivityPub.is_public?(activity), - %Object{} = object <- Object.normalize(activity.data["object"]), - page_url <- HTML.extract_first_external_url(object, object.data["content"]), - {:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do - %{page_url: page_url, rich_media: rich_media} - else - _ -> %{} - end - end -end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index b5231a326..65b612026 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -7,8 +7,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do alias Pleroma.{Repo, Object, Activity, User, Notification, Stats} alias Pleroma.Web - alias Pleroma.Web.MastodonAPI - alias Pleroma.Web.MastodonAPI.{ StatusView, AccountView, @@ -1347,9 +1345,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def status_card(conn, %{"id" => status_id}) do - data = StatusView.render("card.json", MastodonAPI.get_status_card(status_id)) + with %Activity{} = activity <- Repo.get(Activity, status_id), + true <- ActivityPub.is_public?(activity) do + data = + StatusView.render( + "card.json", + Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) + ) - json(conn, data) + json(conn, data) + else + _e -> + %{} + end end def try_render(conn, target, params) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index ccc954985..68df1623e 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -11,7 +11,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do alias Pleroma.User alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MediaProxy - alias Pleroma.Web.MastodonAPI alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MastodonAPI.StatusView @@ -141,7 +140,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do __MODULE__ ) - card = render("card.json", MastodonAPI.get_status_card(activity.id)) + card = render("card.json", Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)) %{ id: to_string(activity.id), diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex new file mode 100644 index 000000000..e90e35180 --- /dev/null +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -0,0 +1,18 @@ +# Pleroma: A lightweight social networking server +# Copyright _ 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.RichMedia.Helpers do + alias Pleroma.{Repo, Activity, Object, HTML} + alias Pleroma.Web.RichMedia.Parser + + def fetch_data_for_activity(%Activity{} = activity) do + with %Object{} = object <- Object.normalize(activity.data["object"]), + page_url <- HTML.extract_first_external_url(object, object.data["content"]), + {:ok, rich_media} <- Parser.parse(page_url) do + %{page_url: page_url, rich_media: rich_media} + else + _ -> %{} + end + end +end diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 364aa7af3..c4025cbd7 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -12,7 +12,6 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Formatter alias Pleroma.HTML - alias Pleroma.Web.MastodonAPI alias Pleroma.Web.MastodonAPI.StatusView defp user_by_ap_id(user_list, ap_id) do @@ -188,7 +187,11 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do summary = HTML.strip_tags(object["summary"]) - card = StatusView.render("card.json", MastodonAPI.get_status_card(activity.id)) + card = + StatusView.render( + "card.json", + Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) + ) %{ "id" => activity.id, diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 77e9af348..d0d1221c3 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -10,7 +10,6 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do alias Pleroma.Web.TwitterAPI.ActivityView alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter - alias Pleroma.Web.MastodonAPI alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.Activity alias Pleroma.HTML @@ -276,7 +275,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do summary = HTML.strip_tags(summary) - card = StatusView.render("card.json", MastodonAPI.get_status_card(activity.id)) + card = + StatusView.render( + "card.json", + Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) + ) %{ "id" => activity.id, -- cgit v1.2.3 From 91ef64a1ece210d86ad970cd751b5c7fe36df41b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 28 Jan 2019 06:07:18 +0000 Subject: activitypub: prime OGP crawler cache when new messages are inserted into the database --- lib/pleroma/web/activity_pub/activity_pub.ex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index feff22400..0199ac9e7 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -88,6 +88,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do recipients: recipients }) + Task.start(fn -> + Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) + end) + Notification.create_notifications(activity) stream_out(activity) {:ok, activity} -- cgit v1.2.3 From ebeabdcc72dffb0a7f66133a511a19025888cfdc Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 28 Jan 2019 06:10:25 +0000 Subject: rich media: helpers: clean up unused aliases --- lib/pleroma/web/rich_media/helpers.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index e90e35180..91c27f9e0 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.RichMedia.Helpers do - alias Pleroma.{Repo, Activity, Object, HTML} + alias Pleroma.{Activity, Object, HTML} alias Pleroma.Web.RichMedia.Parser def fetch_data_for_activity(%Activity{} = activity) do -- cgit v1.2.3 From ddc7ae2c1a4e21c5e89a283951ba53e7ab6322ad Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 28 Jan 2019 06:42:27 +0000 Subject: mastodon api: card: force OGP images through mediaproxy --- lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 68df1623e..d3e30b656 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -189,7 +189,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do provider_name: site_name, provider_url: page_url_data.scheme <> "://" <> page_url_data.host, url: page_url, - image: rich_media[:image], + image: rich_media[:image] |> MediaProxy.url(), title: rich_media[:title], description: rich_media[:description], pleroma: %{ -- cgit v1.2.3 From 9560abea102b8cd4927c9350bbd0a1a2f1800ea6 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Mon, 28 Jan 2019 11:03:52 +0300 Subject: [#534] Refactoring / tweaks per MR review. --- lib/pleroma/instances/instance.ex | 34 +++++++++------------- lib/pleroma/plugs/set_requester_reachable_plug.ex | 16 ++++++++++ lib/pleroma/web/activity_pub/activity_pub.ex | 10 +------ .../web/activity_pub/activity_pub_controller.ex | 7 +---- lib/pleroma/web/controller_helper.ex | 5 ---- lib/pleroma/web/ostatus/ostatus_controller.ex | 7 +---- lib/pleroma/web/salmon/salmon.ex | 3 +- lib/pleroma/web/websub/websub.ex | 3 +- lib/pleroma/web/websub/websub_controller.ex | 7 +---- 9 files changed, 36 insertions(+), 56 deletions(-) create mode 100644 lib/pleroma/plugs/set_requester_reachable_plug.ex (limited to 'lib') diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index 60e8d0e21..e3af4a8a7 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -13,7 +13,6 @@ defmodule Pleroma.Instances.Instance do schema "instances" do field(:host, :string) field(:unreachable_since, :naive_datetime) - field(:reachability_checked_at, :naive_datetime) timestamps() end @@ -22,7 +21,7 @@ defmodule Pleroma.Instances.Instance do def changeset(struct, params \\ %{}) do struct - |> cast(params, [:host, :unreachable_since, :reachability_checked_at]) + |> cast(params, [:host, :unreachable_since]) |> validate_required([:host]) |> unique_constraint(:host) end @@ -66,7 +65,7 @@ defmodule Pleroma.Instances.Instance do %Instance{} = existing_record <- Repo.get_by(Instance, %{host: host}) do {:ok, _instance} = existing_record - |> changeset(%{unreachable_since: nil, reachability_checked_at: DateTime.utc_now()}) + |> changeset(%{unreachable_since: nil}) |> Repo.update() end end @@ -80,27 +79,22 @@ defmodule Pleroma.Instances.Instance do host = host(url) existing_record = Repo.get_by(Instance, %{host: host}) - changes = %{ - unreachable_since: unreachable_since, - reachability_checked_at: NaiveDateTime.utc_now() - } + changes = %{unreachable_since: unreachable_since} - if existing_record do - update_changes = - if existing_record.unreachable_since && - NaiveDateTime.compare(existing_record.unreachable_since, unreachable_since) != :gt, - do: Map.delete(changes, :unreachable_since), - else: changes - - {:ok, _instance} = - existing_record - |> changeset(update_changes) - |> Repo.update() - else - {:ok, _instance} = + cond do + is_nil(existing_record) -> %Instance{} |> changeset(Map.put(changes, :host, host)) |> Repo.insert() + + existing_record.unreachable_since && + NaiveDateTime.compare(existing_record.unreachable_since, unreachable_since) != :gt -> + {:noop, existing_record} + + true -> + existing_record + |> changeset(changes) + |> Repo.update() end end diff --git a/lib/pleroma/plugs/set_requester_reachable_plug.ex b/lib/pleroma/plugs/set_requester_reachable_plug.ex new file mode 100644 index 000000000..88551be70 --- /dev/null +++ b/lib/pleroma/plugs/set_requester_reachable_plug.ex @@ -0,0 +1,16 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Plugs.SetRequesterReachablePlug do + import Plug.Conn + + def init(_), do: [] + + def call(%Plug.Conn{} = conn, _) do + with [referer] <- get_req_header(conn, "referer"), + do: Pleroma.Instances.set_reachable(referer) + + conn + end +end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 4b34334a0..4232d6c0a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -722,15 +722,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end) end - def publish_one(%{inbox: inbox} = activity) do - if Instances.reachable?(inbox) do - do_publish_one(activity) - else - {:error, :noop} - end - end - - defp do_publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do + def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do Logger.info("Federating #{id} to #{inbox}") host = URI.parse(inbox).host diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index dc353dff0..fadb038a2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -18,8 +18,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do action_fallback(:errors) plug(Pleroma.Web.FederatingPlug when action in [:inbox, :relay]) + plug(Pleroma.Web.Plugs.SetRequesterReachablePlug when action in [:inbox]) plug(:relay_active? when action in [:relay]) - plug(:set_requester_reachable when action in [:inbox]) def relay_active?(conn, _) do if Keyword.get(Application.get_env(:pleroma, :instance), :allow_relay) do @@ -291,9 +291,4 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do |> put_status(500) |> json("error") end - - defp set_requester_reachable(conn, _) do - Pleroma.Web.ControllerHelper.set_requester_reachable(conn) - conn - end end diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index 13cf1877f..14e3d19fd 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -10,9 +10,4 @@ defmodule Pleroma.Web.ControllerHelper do |> put_status(status) |> json(json) end - - def set_requester_reachable(conn) do - with [referer] <- get_req_header(conn, "referer"), - do: Pleroma.Instances.set_reachable(referer) - end end diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index a89f16b94..e483447ed 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -15,7 +15,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do alias Pleroma.Web.ActivityPub.ActivityPub plug(Pleroma.Web.FederatingPlug when action in [:salmon_incoming]) - plug(:set_requester_reachable when action in [:salmon_incoming]) + plug(Pleroma.Web.Plugs.SetRequesterReachablePlug when action in [:salmon_incoming]) action_fallback(:errors) @@ -203,9 +203,4 @@ defmodule Pleroma.Web.OStatus.OStatusController do |> put_status(500) |> text("Something went wrong") end - - defp set_requester_reachable(conn, _) do - Pleroma.Web.ControllerHelper.set_requester_reachable(conn) - conn - end end diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 17ca7a6e8..80023127c 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -168,8 +168,7 @@ defmodule Pleroma.Web.Salmon do do: send_to_user(salmon, feed, poster) def send_to_user(url, feed, poster) when is_binary(url) do - with {:reachable, true} <- {:reachable, Instances.reachable?(url)}, - {:ok, %{status: code}} when code in 200..299 <- + with {:ok, %{status: code}} when code in 200..299 <- poster.( url, feed, diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index cbb7a5ac7..64eba7221 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -272,8 +272,7 @@ defmodule Pleroma.Web.Websub do signature = sign(secret || "", xml) Logger.info(fn -> "Pushing #{topic} to #{callback}" end) - with {:reachable, true} <- {:reachable, Instances.reachable?(callback)}, - {:ok, %{status: code}} when code in 200..299 <- + with {:ok, %{status: code}} when code in 200..299 <- @httpoison.post( callback, xml, diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex index 02fe075d7..9da7e70a1 100644 --- a/lib/pleroma/web/websub/websub_controller.ex +++ b/lib/pleroma/web/websub/websub_controller.ex @@ -20,7 +20,7 @@ defmodule Pleroma.Web.Websub.WebsubController do ] ) - plug(:set_requester_reachable when action in [:websub_incoming]) + plug(Pleroma.Web.Plugs.SetRequesterReachablePlug when action in [:websub_incoming]) def websub_subscription_request(conn, %{"nickname" => nickname} = params) do user = User.get_cached_by_nickname(nickname) @@ -96,9 +96,4 @@ defmodule Pleroma.Web.Websub.WebsubController do |> send_resp(500, "Error") end end - - defp set_requester_reachable(conn, _) do - Pleroma.Web.ControllerHelper.set_requester_reachable(conn) - conn - end end -- cgit v1.2.3 From 1825118fd46883cb2a9132b039925c160ad7e57b Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 11:41:47 +0100 Subject: Correctly handle invalid credentials on auth login. Closes #407 --- lib/pleroma/web/oauth/fallback_controller.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/oauth/fallback_controller.ex b/lib/pleroma/web/oauth/fallback_controller.ex index 1eeda3d24..f0fe3b578 100644 --- a/lib/pleroma/web/oauth/fallback_controller.ex +++ b/lib/pleroma/web/oauth/fallback_controller.ex @@ -9,7 +9,8 @@ defmodule Pleroma.Web.OAuth.FallbackController do # No user/password def call(conn, _) do conn + |> put_status(:unauthorized) |> put_flash(:error, "Invalid Username/Password") - |> OAuthController.authorize(conn.params) + |> OAuthController.authorize(conn.params["authorization"]) end end -- cgit v1.2.3 From f231313b709cef32611927cabd8cadb5b0787dc5 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 12:09:41 +0100 Subject: Add deprecation warning mechanism. --- lib/pleroma/application.ex | 2 ++ lib/pleroma/deprecation_warnings.ex | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 lib/pleroma/deprecation_warnings.ex (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index ad2797209..f63477934 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -22,6 +22,8 @@ defmodule Pleroma.Application do def start(_type, _args) do import Cachex.Spec + Task.start(&Pleroma.DeprecationWarnings.warn/0) + # Define workers and child supervisors to be supervised children = [ diff --git a/lib/pleroma/deprecation_warnings.ex b/lib/pleroma/deprecation_warnings.ex new file mode 100644 index 000000000..abb649919 --- /dev/null +++ b/lib/pleroma/deprecation_warnings.ex @@ -0,0 +1,20 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.DeprecationWarnings do + require Logger + + def check_frontend_config_mechanism() do + if Pleroma.Config.get(:fe) do + Logger.warn(""" + !!!DEPRECATION WARNING!!! + You are using the old configuration mechanism for the frontend. Please check config.md. + """) + end + end + + def warn do + check_frontend_config_mechanism() + end +end -- cgit v1.2.3 From df2f7b39dd4e4879976fb40b67fa3087e828a6ce Mon Sep 17 00:00:00 2001 From: href Date: Mon, 28 Jan 2019 12:24:14 +0100 Subject: re f83bae7c: remove unnecessary filter --- lib/pleroma/web/mastodon_api/views/status_view.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 0f2679444..ddfe6788c 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -54,7 +54,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do "status.json", Map.put(opts, :replied_to_activities, replied_to_activities) ) - |> Enum.filter(fn x -> not is_nil(x) end) end def render( -- cgit v1.2.3 From f1d58c5c494d66f89573e2787935ee9f50f18c31 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 13:05:17 +0100 Subject: Don't run warnings in a task. --- lib/pleroma/application.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index f63477934..aa46bcbc4 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -22,7 +22,7 @@ defmodule Pleroma.Application do def start(_type, _args) do import Cachex.Spec - Task.start(&Pleroma.DeprecationWarnings.warn/0) + Pleroma.DeprecationWarnings.warn() # Define workers and child supervisors to be supervised children = -- cgit v1.2.3 From 8e8a1e1ba8a08bc297884fe085b4542a052d6d01 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 13:07:12 +0100 Subject: Return new-style config if old-style config is set to false. This is in preparation for 1.0. We'll be able to switch the config to the new mechanism on PleromaFE then as well. --- .../web/twitter_api/controllers/util_controller.ex | 44 ++++++++++++---------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 085642876..b347faa71 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -183,25 +183,31 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do invitesEnabled: if(Keyword.get(instance, :invites_enabled, false), do: "1", else: "0") } - pleroma_fe = %{ - theme: Keyword.get(instance_fe, :theme), - background: Keyword.get(instance_fe, :background), - logo: Keyword.get(instance_fe, :logo), - logoMask: Keyword.get(instance_fe, :logo_mask), - logoMargin: Keyword.get(instance_fe, :logo_margin), - redirectRootNoLogin: Keyword.get(instance_fe, :redirect_root_no_login), - redirectRootLogin: Keyword.get(instance_fe, :redirect_root_login), - chatDisabled: !Keyword.get(instance_chat, :enabled), - showInstanceSpecificPanel: Keyword.get(instance_fe, :show_instance_panel), - scopeOptionsEnabled: Keyword.get(instance_fe, :scope_options_enabled), - formattingOptionsEnabled: Keyword.get(instance_fe, :formatting_options_enabled), - collapseMessageWithSubject: Keyword.get(instance_fe, :collapse_message_with_subject), - hidePostStats: Keyword.get(instance_fe, :hide_post_stats), - hideUserStats: Keyword.get(instance_fe, :hide_user_stats), - scopeCopy: Keyword.get(instance_fe, :scope_copy), - subjectLineBehavior: Keyword.get(instance_fe, :subject_line_behavior), - alwaysShowSubjectInput: Keyword.get(instance_fe, :always_show_subject_input) - } + pleroma_fe = + if instance_fe do + %{ + theme: Keyword.get(instance_fe, :theme), + background: Keyword.get(instance_fe, :background), + logo: Keyword.get(instance_fe, :logo), + logoMask: Keyword.get(instance_fe, :logo_mask), + logoMargin: Keyword.get(instance_fe, :logo_margin), + redirectRootNoLogin: Keyword.get(instance_fe, :redirect_root_no_login), + redirectRootLogin: Keyword.get(instance_fe, :redirect_root_login), + chatDisabled: !Keyword.get(instance_chat, :enabled), + showInstanceSpecificPanel: Keyword.get(instance_fe, :show_instance_panel), + scopeOptionsEnabled: Keyword.get(instance_fe, :scope_options_enabled), + formattingOptionsEnabled: Keyword.get(instance_fe, :formatting_options_enabled), + collapseMessageWithSubject: + Keyword.get(instance_fe, :collapse_message_with_subject), + hidePostStats: Keyword.get(instance_fe, :hide_post_stats), + hideUserStats: Keyword.get(instance_fe, :hide_user_stats), + scopeCopy: Keyword.get(instance_fe, :scope_copy), + subjectLineBehavior: Keyword.get(instance_fe, :subject_line_behavior), + alwaysShowSubjectInput: Keyword.get(instance_fe, :always_show_subject_input) + } + else + Pleroma.Config.get([:frontend_configurations, :pleroma_fe]) + end managed_config = Keyword.get(instance, :managed_config) -- cgit v1.2.3 From 1d2f41642cfec5710055bcf8409778bb362beecb Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Mon, 28 Jan 2019 15:25:06 +0300 Subject: [#534] Various tweaks. Tests for Instances and Instance. --- lib/pleroma/instances.ex | 13 ++++++++----- lib/pleroma/instances/instance.ex | 28 ++++++++++++++-------------- lib/pleroma/web/activity_pub/activity_pub.ex | 4 ++-- lib/pleroma/web/salmon/salmon.ex | 4 ---- lib/pleroma/web/websub/websub.ex | 10 +++------- 5 files changed, 27 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/instances.ex b/lib/pleroma/instances.ex index 0b08f0eb8..5e107f4c9 100644 --- a/lib/pleroma/instances.ex +++ b/lib/pleroma/instances.ex @@ -3,14 +3,17 @@ defmodule Pleroma.Instances do @adapter Pleroma.Instances.Instance - defdelegate filter_reachable(urls), to: @adapter - defdelegate reachable?(url), to: @adapter - defdelegate set_reachable(url), to: @adapter - defdelegate set_unreachable(url, unreachable_since \\ nil), to: @adapter + defdelegate filter_reachable(urls_or_hosts), to: @adapter + defdelegate reachable?(url_or_host), to: @adapter + defdelegate set_reachable(url_or_host), to: @adapter + defdelegate set_unreachable(url_or_host, unreachable_since \\ nil), to: @adapter + + def set_consistently_unreachable(url_or_host), + do: set_unreachable(url_or_host, reachability_datetime_threshold()) def reachability_datetime_threshold do federation_reachability_timeout_days = - Pleroma.Config.get(:instance)[:federation_reachability_timeout_days] || 90 + Pleroma.Config.get(:instance)[:federation_reachability_timeout_days] || 0 if federation_reachability_timeout_days > 0 do NaiveDateTime.add( diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index e3af4a8a7..a87590d8b 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -17,7 +17,7 @@ defmodule Pleroma.Instances.Instance do timestamps() end - defdelegate host(url), to: Instances + defdelegate host(url_or_host), to: Instances def changeset(struct, params \\ %{}) do struct @@ -28,9 +28,9 @@ defmodule Pleroma.Instances.Instance do def filter_reachable([]), do: [] - def filter_reachable(urls) when is_list(urls) do + def filter_reachable(urls_or_hosts) when is_list(urls_or_hosts) do hosts = - urls + urls_or_hosts |> Enum.map(&(&1 && host(&1))) |> Enum.filter(&(to_string(&1) != "")) @@ -44,14 +44,14 @@ defmodule Pleroma.Instances.Instance do ) ) - Enum.filter(urls, &(&1 && host(&1) not in unreachable_hosts)) + Enum.filter(urls_or_hosts, &(&1 && host(&1) not in unreachable_hosts)) end - def reachable?(url) when is_binary(url) do + def reachable?(url_or_host) when is_binary(url_or_host) do !Repo.one( from(i in Instance, where: - i.host == ^host(url) and + i.host == ^host(url_or_host) and i.unreachable_since <= ^Instances.reachability_datetime_threshold(), select: true ) @@ -60,8 +60,8 @@ defmodule Pleroma.Instances.Instance do def reachable?(_), do: true - def set_reachable(url) when is_binary(url) do - with host <- host(url), + def set_reachable(url_or_host) when is_binary(url_or_host) do + with host <- host(url_or_host), %Instance{} = existing_record <- Repo.get_by(Instance, %{host: host}) do {:ok, _instance} = existing_record @@ -70,13 +70,13 @@ defmodule Pleroma.Instances.Instance do end end - def set_reachable(_), do: {0, :noop} + def set_reachable(_), do: {:error, nil} - def set_unreachable(url, unreachable_since \\ nil) + def set_unreachable(url_or_host, unreachable_since \\ nil) - def set_unreachable(url, unreachable_since) when is_binary(url) do + def set_unreachable(url_or_host, unreachable_since) when is_binary(url_or_host) do unreachable_since = unreachable_since || DateTime.utc_now() - host = host(url) + host = host(url_or_host) existing_record = Repo.get_by(Instance, %{host: host}) changes = %{unreachable_since: unreachable_since} @@ -89,7 +89,7 @@ defmodule Pleroma.Instances.Instance do existing_record.unreachable_since && NaiveDateTime.compare(existing_record.unreachable_since, unreachable_since) != :gt -> - {:noop, existing_record} + {:ok, existing_record} true -> existing_record @@ -98,5 +98,5 @@ defmodule Pleroma.Instances.Instance do end end - def set_unreachable(_, _), do: {0, :noop} + def set_unreachable(_, _), do: {:error, nil} end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 4232d6c0a..6cad02da6 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -750,9 +750,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do Instances.set_reachable(inbox) result else - e -> + {_post_result, response} -> Instances.set_unreachable(inbox) - e + {:error, response} end end diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 80023127c..e96455423 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -181,10 +181,6 @@ defmodule Pleroma.Web.Salmon do Logger.debug(fn -> "Pushed to #{url}, code #{code}" end) :ok else - {:reachable, false} -> - Logger.debug(fn -> "Pushing Salmon to #{url} skipped as marked unreachable)" end) - :noop - e -> Instances.set_unreachable(url) Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end) diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 64eba7221..abe148270 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -286,14 +286,10 @@ defmodule Pleroma.Web.Websub do Logger.info(fn -> "Pushed to #{callback}, code #{code}" end) {:ok, code} else - {:reachable, false} -> - Logger.debug(fn -> "Pushing to #{callback} skipped as marked unreachable)" end) - {:error, :noop} - - e -> + {_post_result, response} -> Instances.set_unreachable(callback) - Logger.debug(fn -> "Couldn't push to #{callback}, #{inspect(e)}" end) - {:error, e} + Logger.debug(fn -> "Couldn't push to #{callback}, #{inspect(response)}" end) + {:error, response} end end end -- cgit v1.2.3 From f53d464db0194eb66557b00c7d92b9df8c798ada Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 28 Jan 2019 14:39:54 +0100 Subject: Put deprecation warnings undre Pleroma.Config. --- lib/pleroma/application.ex | 2 +- lib/pleroma/config/deprecation_warnings.ex | 20 ++++++++++++++++++++ lib/pleroma/deprecation_warnings.ex | 20 -------------------- 3 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 lib/pleroma/config/deprecation_warnings.ex delete mode 100644 lib/pleroma/deprecation_warnings.ex (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index aa46bcbc4..31f2605b8 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -22,7 +22,7 @@ defmodule Pleroma.Application do def start(_type, _args) do import Cachex.Spec - Pleroma.DeprecationWarnings.warn() + Pleroma.Config.DeprecationWarnings.warn() # Define workers and child supervisors to be supervised children = diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex new file mode 100644 index 000000000..dc50682ee --- /dev/null +++ b/lib/pleroma/config/deprecation_warnings.ex @@ -0,0 +1,20 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Config.DeprecationWarnings do + require Logger + + def check_frontend_config_mechanism() do + if Pleroma.Config.get(:fe) do + Logger.warn(""" + !!!DEPRECATION WARNING!!! + You are using the old configuration mechanism for the frontend. Please check config.md. + """) + end + end + + def warn do + check_frontend_config_mechanism() + end +end diff --git a/lib/pleroma/deprecation_warnings.ex b/lib/pleroma/deprecation_warnings.ex deleted file mode 100644 index abb649919..000000000 --- a/lib/pleroma/deprecation_warnings.ex +++ /dev/null @@ -1,20 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.DeprecationWarnings do - require Logger - - def check_frontend_config_mechanism() do - if Pleroma.Config.get(:fe) do - Logger.warn(""" - !!!DEPRECATION WARNING!!! - You are using the old configuration mechanism for the frontend. Please check config.md. - """) - end - end - - def warn do - check_frontend_config_mechanism() - end -end -- cgit v1.2.3 From 55affbca7fcb214c71b3f8378b0de869c4d4d072 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Mon, 28 Jan 2019 22:17:17 +0700 Subject: add a job queue --- lib/pleroma/application.ex | 5 +- lib/pleroma/jobs.ex | 153 +++++++++++++++++++++ lib/pleroma/web/activity_pub/activity_pub.ex | 20 ++- .../web/activity_pub/activity_pub_controller.ex | 4 +- lib/pleroma/web/activity_pub/utils.ex | 2 +- lib/pleroma/web/federator/federator.ex | 139 +++++++------------ lib/pleroma/web/ostatus/ostatus_controller.ex | 2 +- lib/pleroma/web/websub/websub.ex | 8 +- lib/pleroma/web/websub/websub_controller.ex | 2 +- 9 files changed, 222 insertions(+), 113 deletions(-) create mode 100644 lib/pleroma/jobs.ex (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 47c0e5b68..60cba1580 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -101,9 +101,10 @@ defmodule Pleroma.Application do ), worker(Pleroma.FlakeId, []), worker(Pleroma.Web.Federator.RetryQueue, []), - worker(Pleroma.Web.Federator, []), worker(Pleroma.Stats, []), - worker(Pleroma.Web.Push, []) + worker(Pleroma.Web.Push, []), + worker(Pleroma.Jobs, []), + worker(Task, [&Pleroma.Web.Federator.init/0], restart: :temporary) ] ++ streamer_child() ++ chat_child() ++ diff --git a/lib/pleroma/jobs.ex b/lib/pleroma/jobs.ex new file mode 100644 index 000000000..dff0f2197 --- /dev/null +++ b/lib/pleroma/jobs.ex @@ -0,0 +1,153 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Jobs do + @moduledoc """ + A basic job queue + """ + use GenServer + + require Logger + + def init(args) do + {:ok, args} + end + + def start_link do + queues = + Pleroma.Config.get(Pleroma.Jobs) + |> Enum.map(fn {name, _} -> create_queue(name) end) + |> Enum.into(%{}) + + state = %{ + queues: queues, + refs: %{} + } + + GenServer.start_link(__MODULE__, state, name: __MODULE__) + end + + def create_queue(name) do + {name, {:sets.new(), []}} + end + + @doc """ + Enqueues a job. + + Returns `:ok`. + + ## Arguments + + - `queue_name` - a queue name(must be specified in the config). + - `mod` - a worker module, must have `perform` function. + - `args` - a list of arguments for the `perform` function of the worker module. + - `priority` - a job priority (`0` by default). + + ## Examples + + Enqueue `Module.perform/0` with `priority=1`: + + iex> Pleroma.Jobs.enqueue(:example_queue, Module, []) + :ok + + Enqueue `Module.perform(:job_name)` with `priority=5`: + + iex> Pleroma.Jobs.enqueue(:example_queue, Module, [:job_name], 5) + :ok + + Enqueue `Module.perform(:another_job, data)` with `priority=1`: + + iex> data = "foobar" + iex> Pleroma.Jobs.enqueue(:example_queue, Module, [:another_job, data]) + :ok + + Enqueue `Module.perform(:foobar_job, :foo, :bar, 42)` with `priority=1`: + + iex> Pleroma.Jobs.enqueue(:example_queue, Module, [:foobar_job, :foo, :bar, 42]) + :ok + + """ + + def enqueue(queue_name, mod, args, priority \\ 1) + + if Mix.env() == :test do + def enqueue(_queue_name, mod, args, _priority) do + apply(mod, :perform, args) + end + else + @spec enqueue(atom(), atom(), [any()], integer()) :: :ok + def enqueue(queue_name, mod, args, priority \\ 1) do + GenServer.cast(__MODULE__, {:enqueue, queue_name, mod, args, priority}) + end + end + + def handle_cast({:enqueue, queue_name, mod, args, priority}, state) do + {running_jobs, queue} = state[:queues][queue_name] + + queue = enqueue_sorted(queue, {mod, args}, priority) + + state = + state + |> update_queue(queue_name, {running_jobs, queue}) + |> maybe_start_job(queue_name, running_jobs, queue) + + {:noreply, state} + end + + def handle_cast(m, state) do + IO.inspect("Unknown: #{inspect(m)}, #{inspect(state)}") + {:noreply, state} + end + + def handle_info({:DOWN, ref, :process, _pid, _reason}, state) do + queue_name = state.refs[ref] + + {running_jobs, queue} = state[:queues][queue_name] + + running_jobs = :sets.del_element(ref, running_jobs) + + state = state |> remove_ref(ref) |> maybe_start_job(queue_name, running_jobs, queue) + + {:noreply, state} + end + + def maybe_start_job(state, queue_name, running_jobs, queue) do + if :sets.size(running_jobs) < Pleroma.Config.get([__MODULE__, queue_name, :max_jobs]) && + queue != [] do + {{mod, args}, queue} = queue_pop(queue) + {:ok, pid} = Task.start(fn -> apply(mod, :perform, args) end) + mref = Process.monitor(pid) + + state + |> add_ref(queue_name, mref) + |> update_queue(queue_name, {:sets.add_element(mref, running_jobs), queue}) + else + update_queue(state, queue_name, {running_jobs, queue}) + end + end + + def enqueue_sorted(queue, element, priority) do + [%{item: element, priority: priority} | queue] + |> Enum.sort_by(fn %{priority: priority} -> priority end) + end + + def queue_pop([%{item: element} | queue]) do + {element, queue} + end + + defp add_ref(state, queue_name, ref) do + refs = Map.put(state[:refs], ref, queue_name) + Map.put(state, :refs, refs) + end + + defp remove_ref(state, ref) do + refs = Map.delete(state[:refs], ref) + Map.put(state, :refs, refs) + end + + defp update_queue(state, queue_name, data) do + queues = Map.put(state[:queues], queue_name, data) + Map.put(state, :queues, queues) + end +end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 6b4682e35..5be359887 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -711,20 +711,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do public = is_public?(activity) - remote_inboxes = - (Pleroma.Web.Salmon.remote_users(activity) ++ followers) - |> Enum.filter(fn user -> User.ap_enabled?(user) end) - |> Enum.map(fn %{info: %{source_data: data}} -> - (is_map(data["endpoints"]) && Map.get(data["endpoints"], "sharedInbox")) || data["inbox"] - end) - |> Enum.uniq() - |> Enum.filter(fn inbox -> should_federate?(inbox, public) end) - {:ok, data} = Transmogrifier.prepare_outgoing(activity.data) json = Jason.encode!(data) - Enum.each(remote_inboxes, fn inbox -> - Federator.enqueue(:publish_single_ap, %{ + (Pleroma.Web.Salmon.remote_users(activity) ++ followers) + |> Enum.filter(fn user -> User.ap_enabled?(user) end) + |> Enum.map(fn %{info: %{source_data: data}} -> + (is_map(data["endpoints"]) && Map.get(data["endpoints"], "sharedInbox")) || data["inbox"] + end) + |> Enum.uniq() + |> Enum.filter(fn inbox -> should_federate?(inbox, public) end) + |> Enum.each(fn inbox -> + Federator.publish_single_ap(%{ inbox: inbox, json: json, actor: actor, diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 7eed0a600..04c6fef3f 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -150,13 +150,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do with %User{} = user <- User.get_cached_by_nickname(nickname), true <- Utils.recipient_in_message(user.ap_id, params), params <- Utils.maybe_splice_recipient(user.ap_id, params) do - Federator.enqueue(:incoming_ap_doc, params) + Federator.incoming_ap_doc(params) json(conn, "ok") end end def inbox(%{assigns: %{valid_signature: true}} = conn, params) do - Federator.enqueue(:incoming_ap_doc, params) + Federator.incoming_ap_doc(params) json(conn, "ok") end diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index e40d05fcd..2ff8a1e8a 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -156,7 +156,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do _ -> 5 end - Pleroma.Web.Federator.enqueue(:publish, activity, priority) + Pleroma.Web.Federator.publish(activity, priority) :ok end diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index f3a0e18b8..4d03b4622 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -3,9 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Federator do - use GenServer alias Pleroma.User alias Pleroma.Activity + alias Pleroma.Jobs alias Pleroma.Web.{WebFinger, Websub} alias Pleroma.Web.Federator.RetryQueue alias Pleroma.Web.ActivityPub.ActivityPub @@ -18,39 +18,60 @@ defmodule Pleroma.Web.Federator do @websub Application.get_env(:pleroma, :websub) @ostatus Application.get_env(:pleroma, :ostatus) - def init(args) do - {:ok, args} + def init() do + # 1 minute + Process.sleep(1000 * 60 * 1) + refresh_subscriptions() end - def start_link do - spawn(fn -> - # 1 minute - Process.sleep(1000 * 60 * 1) - enqueue(:refresh_subscriptions, nil) - end) + # Client API + + def incoming_doc(doc) do + Jobs.enqueue(:federator_incoming, __MODULE__, [:incoming_doc, doc]) + end + + def incoming_ap_doc(params) do + Jobs.enqueue(:federator_incoming, __MODULE__, [:incoming_ap_doc, params]) + end + + def publish(activity, priority \\ 1) do + Jobs.enqueue(:federator_out, __MODULE__, [:publish, activity], priority) + end + + def publish_single_ap(params) do + Jobs.enqueue(:federator_out, __MODULE__, [:publish_single_ap, params]) + end - GenServer.start_link( - __MODULE__, - %{ - in: {:sets.new(), []}, - out: {:sets.new(), []} - }, - name: __MODULE__ - ) + def publish_single_websub(websub) do + Jobs.enqueue(:federator_out, __MODULE__, [:publish_single_websub, websub]) end - def handle(:refresh_subscriptions, _) do + def verify_websub(websub) do + Jobs.enqueue(:federator_out, __MODULE__, [:verify_websub, websub]) + end + + def request_subscription(sub) do + Jobs.enqueue(:federator_out, __MODULE__, [:request_subscription, sub]) + end + + def refresh_subscriptions() do + Jobs.enqueue(:federator_out, __MODULE__, [:refresh_subscriptions]) + end + + # Job Worker Callbacks + + def perform(:refresh_subscriptions) do Logger.debug("Federator running refresh subscriptions") Websub.refresh_subscriptions() spawn(fn -> # 6 hours Process.sleep(1000 * 60 * 60 * 6) - enqueue(:refresh_subscriptions, nil) + refresh_subscriptions() end) end - def handle(:request_subscription, websub) do + def perform(:request_subscription, websub) do Logger.debug("Refreshing #{websub.topic}") with {:ok, websub} <- Websub.request_subscription(websub) do @@ -60,7 +81,7 @@ defmodule Pleroma.Web.Federator do end end - def handle(:publish, activity) do + def perform(:publish, activity) do Logger.debug(fn -> "Running publish for #{activity.data["id"]}" end) with actor when not is_nil(actor) <- User.get_cached_by_ap_id(activity.data["actor"]) do @@ -86,7 +107,7 @@ defmodule Pleroma.Web.Federator do end end - def handle(:verify_websub, websub) do + def perform(:verify_websub, websub) do Logger.debug(fn -> "Running WebSub verification for #{websub.id} (#{websub.topic}, #{websub.callback})" end) @@ -94,12 +115,12 @@ defmodule Pleroma.Web.Federator do @websub.verify(websub) end - def handle(:incoming_doc, doc) do + def perform(:incoming_doc, doc) do Logger.info("Got document, trying to parse") @ostatus.handle_incoming(doc) end - def handle(:incoming_ap_doc, params) do + def perform(:incoming_ap_doc, params) do Logger.info("Handling incoming AP activity") params = Utils.normalize_params(params) @@ -124,7 +145,7 @@ defmodule Pleroma.Web.Federator do end end - def handle(:publish_single_ap, params) do + def perform(:publish_single_ap, params) do case ActivityPub.publish_one(params) do {:ok, _} -> :ok @@ -134,7 +155,7 @@ defmodule Pleroma.Web.Federator do end end - def handle( + def perform( :publish_single_websub, %{xml: _xml, topic: _topic, callback: _callback, secret: _secret} = params ) do @@ -147,75 +168,11 @@ defmodule Pleroma.Web.Federator do end end - def handle(type, _) do + def perform(type, _) do Logger.debug(fn -> "Unknown task: #{type}" end) {:error, "Don't know what to do with this"} end - if Mix.env() == :test do - def enqueue(type, payload, _priority \\ 1) do - if Pleroma.Config.get([:instance, :federating]) do - handle(type, payload) - end - end - else - def enqueue(type, payload, priority \\ 1) do - if Pleroma.Config.get([:instance, :federating]) do - GenServer.cast(__MODULE__, {:enqueue, type, payload, priority}) - end - end - end - - def maybe_start_job(running_jobs, queue) do - if :sets.size(running_jobs) < Pleroma.Config.get([__MODULE__, :max_jobs]) && queue != [] do - {{type, payload}, queue} = queue_pop(queue) - {:ok, pid} = Task.start(fn -> handle(type, payload) end) - mref = Process.monitor(pid) - {:sets.add_element(mref, running_jobs), queue} - else - {running_jobs, queue} - end - end - - def handle_cast({:enqueue, type, payload, _priority}, state) - when type in [:incoming_doc, :incoming_ap_doc] do - %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}} = state - i_queue = enqueue_sorted(i_queue, {type, payload}, 1) - {i_running_jobs, i_queue} = maybe_start_job(i_running_jobs, i_queue) - {:noreply, %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}}} - end - - def handle_cast({:enqueue, type, payload, _priority}, state) do - %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}} = state - o_queue = enqueue_sorted(o_queue, {type, payload}, 1) - {o_running_jobs, o_queue} = maybe_start_job(o_running_jobs, o_queue) - {:noreply, %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}}} - end - - def handle_cast(m, state) do - IO.inspect("Unknown: #{inspect(m)}, #{inspect(state)}") - {:noreply, state} - end - - def handle_info({:DOWN, ref, :process, _pid, _reason}, state) do - %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}} = state - i_running_jobs = :sets.del_element(ref, i_running_jobs) - o_running_jobs = :sets.del_element(ref, o_running_jobs) - {i_running_jobs, i_queue} = maybe_start_job(i_running_jobs, i_queue) - {o_running_jobs, o_queue} = maybe_start_job(o_running_jobs, o_queue) - - {:noreply, %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}}} - end - - def enqueue_sorted(queue, element, priority) do - [%{item: element, priority: priority} | queue] - |> Enum.sort_by(fn %{priority: priority} -> priority end) - end - - def queue_pop([%{item: element} | queue]) do - {element, queue} - end - def ap_enabled_actor(id) do user = User.get_by_ap_id(id) diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 823619edb..845bc60bb 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -82,7 +82,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do {:ok, body, _conn} = read_body(conn) {:ok, doc} = decode_or_retry(body) - Federator.enqueue(:incoming_doc, doc) + Federator.incoming_doc(doc) conn |> send_resp(200, "") diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 7ca62c83b..652ffd92c 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -7,7 +7,7 @@ defmodule Pleroma.Web.Websub do alias Pleroma.Repo alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription} alias Pleroma.Web.OStatus.FeedRepresenter - alias Pleroma.Web.{XML, Endpoint, OStatus} + alias Pleroma.Web.{XML, Endpoint, OStatus, Federator} alias Pleroma.Web.Router.Helpers require Logger @@ -77,7 +77,7 @@ defmodule Pleroma.Web.Websub do secret: sub.secret } - Pleroma.Web.Federator.enqueue(:publish_single_websub, data) + Federator.publish_single_websub(data) end) end @@ -109,7 +109,7 @@ defmodule Pleroma.Web.Websub do websub = Repo.update!(change) - Pleroma.Web.Federator.enqueue(:verify_websub, websub) + Federator.verify_websub(websub) {:ok, websub} else @@ -259,7 +259,7 @@ defmodule Pleroma.Web.Websub do subs = Repo.all(query) Enum.each(subs, fn sub -> - Pleroma.Web.Federator.enqueue(:request_subscription, sub) + Federator.request_subscription(sub) end) end diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex index e58f144e5..eb10227cb 100644 --- a/lib/pleroma/web/websub/websub_controller.ex +++ b/lib/pleroma/web/websub/websub_controller.ex @@ -80,7 +80,7 @@ defmodule Pleroma.Web.Websub.WebsubController do %WebsubClientSubscription{} = websub <- Repo.get(WebsubClientSubscription, id), {:ok, body, _conn} = read_body(conn), ^signature <- Websub.sign(websub.secret, body) do - Federator.enqueue(:incoming_doc, body) + Federator.incoming_doc(body) conn |> send_resp(200, "OK") -- cgit v1.2.3 From b2e9700785124a8ba4cfb037ae92a6bfc7c3b224 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Mon, 28 Jan 2019 23:12:02 +0700 Subject: cleanup --- lib/pleroma/jobs.ex | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/jobs.ex b/lib/pleroma/jobs.ex index dff0f2197..2a75ff529 100644 --- a/lib/pleroma/jobs.ex +++ b/lib/pleroma/jobs.ex @@ -40,7 +40,7 @@ defmodule Pleroma.Jobs do ## Arguments - `queue_name` - a queue name(must be specified in the config). - - `mod` - a worker module, must have `perform` function. + - `mod` - a worker module (must have `perform` function). - `args` - a list of arguments for the `perform` function of the worker module. - `priority` - a job priority (`0` by default). @@ -76,7 +76,6 @@ defmodule Pleroma.Jobs do apply(mod, :perform, args) end else - @spec enqueue(atom(), atom(), [any()], integer()) :: :ok def enqueue(queue_name, mod, args, priority \\ 1) do GenServer.cast(__MODULE__, {:enqueue, queue_name, mod, args, priority}) end @@ -95,11 +94,6 @@ defmodule Pleroma.Jobs do {:noreply, state} end - def handle_cast(m, state) do - IO.inspect("Unknown: #{inspect(m)}, #{inspect(state)}") - {:noreply, state} - end - def handle_info({:DOWN, ref, :process, _pid, _reason}, state) do queue_name = state.refs[ref] -- cgit v1.2.3 From 56533495b53c12223678de3f2fc6df8ee1165c19 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 29 Jan 2019 00:33:08 +0700 Subject: fix defaults --- lib/pleroma/jobs.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/jobs.ex b/lib/pleroma/jobs.ex index 2a75ff529..d42688193 100644 --- a/lib/pleroma/jobs.ex +++ b/lib/pleroma/jobs.ex @@ -76,7 +76,7 @@ defmodule Pleroma.Jobs do apply(mod, :perform, args) end else - def enqueue(queue_name, mod, args, priority \\ 1) do + def enqueue(queue_name, mod, args, priority) do GenServer.cast(__MODULE__, {:enqueue, queue_name, mod, args, priority}) end end -- cgit v1.2.3 From 1724a6b34b099dc83b94687d27d2492aaf97013e Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 29 Jan 2019 00:35:57 +0700 Subject: add spec back --- lib/pleroma/jobs.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/jobs.ex b/lib/pleroma/jobs.ex index d42688193..16dccb682 100644 --- a/lib/pleroma/jobs.ex +++ b/lib/pleroma/jobs.ex @@ -76,6 +76,7 @@ defmodule Pleroma.Jobs do apply(mod, :perform, args) end else + @spec enqueue(atom(), atom(), [any()], integer()) :: :ok def enqueue(queue_name, mod, args, priority) do GenServer.cast(__MODULE__, {:enqueue, queue_name, mod, args, priority}) end -- cgit v1.2.3 From 50d6183893166b51a400659a38dd657ac84603d6 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Mon, 28 Jan 2019 21:31:08 +0300 Subject: Split hide_network into hide_followers & hide_followings --- lib/pleroma/user/info.ex | 6 ++++-- lib/pleroma/web/activity_pub/views/user_view.ex | 8 ++++---- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 4 ++-- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 6 +++--- lib/pleroma/web/twitter_api/views/user_view.ex | 3 ++- 5 files changed, 15 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index c6c923aac..2186190a0 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -30,7 +30,8 @@ defmodule Pleroma.User.Info do field(:topic, :string, default: nil) field(:hub, :string, default: nil) field(:salmon, :string, default: nil) - field(:hide_network, :boolean, default: false) + field(:hide_followers, :boolean, default: false) + field(:hide_followings, :boolean, default: false) field(:pinned_activities, {:array, :string}, default: []) # Found in the wild @@ -143,7 +144,8 @@ defmodule Pleroma.User.Info do :no_rich_text, :default_scope, :banner, - :hide_network, + :hide_followings, + :hide_followers, :background ]) end diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index dcf681b6d..b9588bee5 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -86,7 +86,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = from(user in query, select: [:ap_id]) following = Repo.all(query) - collection(following, "#{user.ap_id}/following", page, !user.info.hide_network) + collection(following, "#{user.ap_id}/following", page, !user.info.hide_followings) |> Map.merge(Utils.make_json_ld_header()) end @@ -99,7 +99,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{user.ap_id}/following", "type" => "OrderedCollection", "totalItems" => length(following), - "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_network) + "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_followings) } |> Map.merge(Utils.make_json_ld_header()) end @@ -109,7 +109,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = from(user in query, select: [:ap_id]) followers = Repo.all(query) - collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_network) + collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers) |> Map.merge(Utils.make_json_ld_header()) end @@ -122,7 +122,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{user.ap_id}/followers", "type" => "OrderedCollection", "totalItems" => length(followers), - "first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_network) + "first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers) } |> Map.merge(Utils.make_json_ld_header()) end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index a366a149f..3364b2ac2 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -583,7 +583,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do followers = cond do for_user && user.id == for_user.id -> followers - user.info.hide_network -> [] + user.info.hide_followers -> [] true -> followers end @@ -599,7 +599,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do followers = cond do for_user && user.id == for_user.id -> followers - user.info.hide_network -> [] + user.info.hide_followings -> [] true -> followers end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 3064d61ea..5e3fe9352 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -503,7 +503,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do followers = cond do for_user && user.id == for_user.id -> followers - user.info.hide_network -> [] + user.info.hide_followers -> [] true -> followers end @@ -523,7 +523,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do friends = cond do for_user && user.id == for_user.id -> friends - user.info.hide_network -> [] + user.info.hide_followings -> [] true -> friends end @@ -618,7 +618,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do defp build_info_cng(user, params) do info_params = - ["no_rich_text", "locked", "hide_network"] + ["no_rich_text", "locked", "hide_followers", "hide_followings"] |> Enum.reduce(%{}, fn key, res -> if value = params[key] do Map.put(res, key, value == "true") diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 15682db8f..cd7c4349c 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -108,7 +108,8 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "locked" => user.info.locked, "default_scope" => user.info.default_scope, "no_rich_text" => user.info.no_rich_text, - "hide_network" => user.info.hide_network, + "hide_followers" => user.info.hide_followers, + "hide_followings" => user.info.hide_followings, "fields" => fields, # Pleroma extension -- cgit v1.2.3 From 8fb16e9f0f246e459fe6744fcf9b5d382a7c5c3f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 28 Jan 2019 19:59:36 +0000 Subject: rich media: parser: add copyright header --- lib/pleroma/web/rich_media/parser.ex | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 7787bf954..bd21d2a0e 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.RichMedia.Parser do @parsers [ Pleroma.Web.RichMedia.Parsers.OGP, -- cgit v1.2.3 From 83b7062634d10bfa91adeb89bac10d854d6213d5 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 28 Jan 2019 20:19:07 +0000 Subject: rich media: parser: cache negatives --- lib/pleroma/web/rich_media/parser.ex | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index bd21d2a0e..279e27273 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -15,11 +15,13 @@ defmodule Pleroma.Web.RichMedia.Parser do def parse(url), do: parse_url(url) else def parse(url) do - with {:ok, data} <- Cachex.fetch(:rich_media_cache, url, fn _ -> parse_url(url) end) do - data - else - _e -> - {:error, "Parsing error"} + try do + Cachex.fetch!(:rich_media_cache, url, fn _ -> + {:commit, parse_url(url)} + end) + rescue + e -> + {:error, "Cachex error: #{inspect(e)}"} end end end @@ -30,8 +32,8 @@ defmodule Pleroma.Web.RichMedia.Parser do html |> maybe_parse() |> get_parsed_data() rescue - _e -> - {:error, "Parsing error"} + e -> + {:error, "Parsing error: #{inspect(e)}"} end end -- cgit v1.2.3 From 0f11254a065d014d8fbb4f4a48cb03d14d8e02d0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 28 Jan 2019 20:31:43 +0000 Subject: rich media: parser: add some basic sanity checks on the returned data with pattern matching --- lib/pleroma/web/rich_media/parser.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 279e27273..76d977ac2 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -46,11 +46,11 @@ defmodule Pleroma.Web.RichMedia.Parser do end) end - defp get_parsed_data(data) when data == %{} do - {:error, "No metadata found"} + defp get_parsed_data(%{title: title} = data) when is_binary(title) and byte_size(title) > 0 do + {:ok, data} end defp get_parsed_data(data) do - {:ok, data} + {:error, "Found metadata was invalid or incomplete: #{inspect(data)}"} end end -- cgit v1.2.3 From ddb554520240bb534a4e968616edebd9299734da Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 28 Jan 2019 20:55:33 +0000 Subject: rich media: kill some testsuite noise --- lib/pleroma/html.ex | 2 +- lib/pleroma/web/rich_media/helpers.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index fb602d6b6..bf5daa948 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -69,7 +69,7 @@ defmodule Pleroma.HTML do |> Floki.attribute("a", "href") |> Enum.at(0) - {:commit, result} + {:commit, {:ok, result}} end) end end diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index 91c27f9e0..71fdddef9 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Web.RichMedia.Helpers do def fetch_data_for_activity(%Activity{} = activity) do with %Object{} = object <- Object.normalize(activity.data["object"]), - page_url <- HTML.extract_first_external_url(object, object.data["content"]), + {:ok, page_url} <- HTML.extract_first_external_url(object, object.data["content"]), {:ok, rich_media} <- Parser.parse(page_url) do %{page_url: page_url, rich_media: rich_media} else -- cgit v1.2.3 From 61d6715714fe9c2ce6bf4fe6afc353f7fe5502a6 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 28 Jan 2019 21:07:36 +0000 Subject: rich media: oembed: return data in the same format as the other parsers --- lib/pleroma/web/rich_media/parsers/oembed_parser.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parsers/oembed_parser.ex b/lib/pleroma/web/rich_media/parsers/oembed_parser.ex index ca7226faf..efa98bc2c 100644 --- a/lib/pleroma/web/rich_media/parsers/oembed_parser.ex +++ b/lib/pleroma/web/rich_media/parsers/oembed_parser.ex @@ -22,6 +22,10 @@ defmodule Pleroma.Web.RichMedia.Parsers.OEmbed do defp get_oembed_data(url) do {:ok, %Tesla.Env{body: json}} = Pleroma.HTTP.get(url) - {:ok, Poison.decode!(json)} + {:ok, data} = Jason.decode(json) + + data = data |> Map.new(fn {k, v} -> {String.to_atom(k), v} end) + + {:ok, data} end end -- cgit v1.2.3 From 92753b0cd9cfcdc5edb64a5e55ad27f73079f9e0 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 29 Jan 2019 13:12:28 +0300 Subject: [#534] Made federation push sender be determined basing on content instead of `referer` header. Updated tests. --- lib/pleroma/plugs/set_requester_reachable_plug.ex | 16 ---------------- lib/pleroma/reverse_proxy.ex | 3 +-- lib/pleroma/web/activity_pub/activity_pub.ex | 3 +-- lib/pleroma/web/activity_pub/activity_pub_controller.ex | 11 ++++++++++- lib/pleroma/web/ostatus/ostatus.ex | 3 +++ lib/pleroma/web/ostatus/ostatus_controller.ex | 1 - lib/pleroma/web/salmon/salmon.ex | 5 +---- lib/pleroma/web/websub/websub.ex | 3 +-- lib/pleroma/web/websub/websub_controller.ex | 2 -- 9 files changed, 17 insertions(+), 30 deletions(-) delete mode 100644 lib/pleroma/plugs/set_requester_reachable_plug.ex (limited to 'lib') diff --git a/lib/pleroma/plugs/set_requester_reachable_plug.ex b/lib/pleroma/plugs/set_requester_reachable_plug.ex deleted file mode 100644 index 88551be70..000000000 --- a/lib/pleroma/plugs/set_requester_reachable_plug.ex +++ /dev/null @@ -1,16 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.Plugs.SetRequesterReachablePlug do - import Plug.Conn - - def init(_), do: [] - - def call(%Plug.Conn{} = conn, _) do - with [referer] <- get_req_header(conn, "referer"), - do: Pleroma.Instances.set_reachable(referer) - - conn - end -end diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index d8b17212b..a25b5ea4e 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -3,8 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.ReverseProxy do - @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since) ++ - ~w(if-none-match if-range range referer) + @keep_req_headers ~w(accept user-agent accept-encoding cache-control if-modified-since if-unmodified-since if-none-match if-range range) @resp_cache_headers ~w(etag date last-modified cache-control) @keep_resp_headers @resp_cache_headers ++ ~w(content-type content-disposition content-encoding content-range accept-ranges vary) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 22c7824fa..4016808e8 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -784,8 +784,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do [ {"Content-Type", "application/activity+json"}, {"signature", signature}, - {"digest", digest}, - {"referer", Pleroma.Web.Endpoint.url()} + {"digest", digest} ] ) do Instances.set_reachable(inbox) diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index fadb038a2..4dea6ab83 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do action_fallback(:errors) plug(Pleroma.Web.FederatingPlug when action in [:inbox, :relay]) - plug(Pleroma.Web.Plugs.SetRequesterReachablePlug when action in [:inbox]) + plug(:set_requester_reachable when action in [:inbox]) plug(:relay_active? when action in [:relay]) def relay_active?(conn, _) do @@ -291,4 +291,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do |> put_status(500) |> json("error") end + + defp set_requester_reachable(%Plug.Conn{} = conn, _) do + with actor <- conn.params["actor"], + true <- is_binary(actor) do + Pleroma.Instances.set_reachable(actor) + end + + conn + end end diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index a3155b79d..a20ca17bb 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -48,6 +48,9 @@ defmodule Pleroma.Web.OStatus do def handle_incoming(xml_string) do with doc when doc != :error <- parse_document(xml_string) do + with {:ok, actor_user} <- find_make_or_update_user(doc), + do: Pleroma.Instances.set_reachable(actor_user.ap_id) + entries = :xmerl_xpath.string('//entry', doc) activities = diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 9392a97f0..302ff38a4 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -14,7 +14,6 @@ defmodule Pleroma.Web.OStatus.OStatusController do alias Pleroma.Web.ActivityPub.ActivityPub plug(Pleroma.Web.FederatingPlug when action in [:salmon_incoming]) - plug(Pleroma.Web.Plugs.SetRequesterReachablePlug when action in [:salmon_incoming]) action_fallback(:errors) diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index e96455423..07ca42a5f 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -172,10 +172,7 @@ defmodule Pleroma.Web.Salmon do poster.( url, feed, - [ - {"Content-Type", "application/magic-envelope+xml"}, - {"referer", Pleroma.Web.Endpoint.url()} - ] + [{"Content-Type", "application/magic-envelope+xml"}] ) do Instances.set_reachable(url) Logger.debug(fn -> "Pushed to #{url}, code #{code}" end) diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index abe148270..8f7d53b03 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -278,8 +278,7 @@ defmodule Pleroma.Web.Websub do xml, [ {"Content-Type", "application/atom+xml"}, - {"X-Hub-Signature", "sha1=#{signature}"}, - {"referer", Pleroma.Web.Endpoint.url()} + {"X-Hub-Signature", "sha1=#{signature}"} ] ) do Instances.set_reachable(callback) diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex index 9da7e70a1..a92dfe87b 100644 --- a/lib/pleroma/web/websub/websub_controller.ex +++ b/lib/pleroma/web/websub/websub_controller.ex @@ -20,8 +20,6 @@ defmodule Pleroma.Web.Websub.WebsubController do ] ) - plug(Pleroma.Web.Plugs.SetRequesterReachablePlug when action in [:websub_incoming]) - def websub_subscription_request(conn, %{"nickname" => nickname} = params) do user = User.get_cached_by_nickname(nickname) -- cgit v1.2.3 From cbb2b709de72c72542b0db883fa7b1b7d886688b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 29 Jan 2019 11:57:46 +0000 Subject: activitypub: transmogrifier: fix follow request rejections --- lib/pleroma/web/activity_pub/transmogrifier.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index c2ced51d8..43725c3db 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -453,9 +453,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"), %User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity.data["actor"]), {:ok, activity} <- - ActivityPub.accept(%{ + ActivityPub.reject(%{ to: follow_activity.data["to"], - type: "Accept", + type: "Reject", actor: followed.ap_id, object: follow_activity.data["id"], local: false -- cgit v1.2.3 From 57549f60434250d538d61b926906c0b7d284c627 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 29 Jan 2019 12:21:02 +0000 Subject: activitypub: utils: update the state of *any* pending follow relationship that matches the actor and target --- lib/pleroma/web/activity_pub/utils.ex | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index e40d05fcd..3b0cdfe71 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -316,6 +316,25 @@ defmodule Pleroma.Web.ActivityPub.Utils do @doc """ Updates a follow activity's state (for locked accounts). """ + def update_follow_state( + %Activity{data: %{"actor" => actor, "object" => object, "state" => "pending"}} = activity, + state + ) do + try do + Ecto.Adapters.SQL.query!( + Repo, + "UPDATE activities SET data = jsonb_set(data, '{state}', $1) WHERE data->>'type' = 'Follow' AND data->>'actor' = $2 AND data->>'object' = $3 AND data->>'state' = 'pending'", + [state, actor, object] + ) + + activity = Repo.get(Activity, activity.id) + {:ok, activity} + rescue + e -> + {:error, e} + end + end + def update_follow_state(%Activity{} = activity, state) do with new_data <- activity.data -- cgit v1.2.3 From 4aff4efa8d53988d00381b1346241359cf787e87 Mon Sep 17 00:00:00 2001 From: href Date: Wed, 30 Jan 2019 12:38:38 +0100 Subject: Use multiple hackney pools * federation (ap, salmon) * media (rich media, media proxy) * upload (uploader proxy) Each "part" will stop fighting others ones -- a huge federation outbound could before make the media proxy fail to checkout a connection in time. splitted media and uploaded media for the good reason than an upload pool will have all connections to the same host (the uploader upstream). it also has a longer default retention period for connections. --- lib/pleroma/application.ex | 34 ++++++++++++++++++---- lib/pleroma/http/connection.ex | 3 +- lib/pleroma/uploaders/mdii.ex | 3 +- .../web/mastodon_api/mastodon_api_controller.ex | 3 +- lib/pleroma/web/rich_media/parser.ex | 2 +- .../web/rich_media/parsers/oembed_parser.ex | 2 +- 6 files changed, 37 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index c65bebb3b..f775cd53d 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -101,12 +101,15 @@ defmodule Pleroma.Application do ], id: :cachex_idem ), - worker(Pleroma.FlakeId, []), - worker(Pleroma.Web.Federator.RetryQueue, []), - worker(Pleroma.Web.Federator, []), - worker(Pleroma.Stats, []), - worker(Pleroma.Web.Push, []) + worker(Pleroma.FlakeId, []) ] ++ + hackney_pool_children() ++ + [ + worker(Pleroma.Web.Federator.RetryQueue, []), + worker(Pleroma.Web.Federator, []), + worker(Pleroma.Stats, []), + worker(Pleroma.Web.Push, []) + ] ++ streamer_child() ++ chat_child() ++ [ @@ -121,6 +124,20 @@ defmodule Pleroma.Application do Supervisor.start_link(children, opts) end + def enabled_hackney_pools() do + [:media] ++ + if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Hackney do + [:federation] + else + [] + end ++ + if Pleroma.Config.get([Pleroma.Uploader, :proxy_remote]) do + [:uploadproxy] + else + [] + end + end + if Mix.env() == :test do defp streamer_child(), do: [] defp chat_child(), do: [] @@ -137,4 +154,11 @@ defmodule Pleroma.Application do end end end + + defp hackney_pool_children() do + for pool <- enabled_hackney_pools() do + options = Pleroma.Config.get([:hackney_pools, pool]) + :hackney_pool.child_spec(pool, options) + end + end end diff --git a/lib/pleroma/http/connection.ex b/lib/pleroma/http/connection.ex index 699d80cd7..b798eaa5a 100644 --- a/lib/pleroma/http/connection.ex +++ b/lib/pleroma/http/connection.ex @@ -10,7 +10,8 @@ defmodule Pleroma.HTTP.Connection do @hackney_options [ timeout: 10000, recv_timeout: 20000, - follow_redirect: true + follow_redirect: true, + pool: :federation ] @adapter Application.get_env(:tesla, :adapter) diff --git a/lib/pleroma/uploaders/mdii.ex b/lib/pleroma/uploaders/mdii.ex index 530b34362..320b07abd 100644 --- a/lib/pleroma/uploaders/mdii.ex +++ b/lib/pleroma/uploaders/mdii.ex @@ -24,7 +24,8 @@ defmodule Pleroma.Uploaders.MDII do extension = String.split(upload.name, ".") |> List.last() query = "#{cgi}?#{extension}" - with {:ok, %{status: 200, body: body}} <- @httpoison.post(query, file_data) do + with {:ok, %{status: 200, body: body}} <- + @httpoison.post(query, file_data, adapter: [pool: :default]) do remote_file_name = String.split(body) |> List.first() public_url = "#{files}/#{remote_file_name}.#{extension}" {:ok, {:url, public_url}} diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 65b612026..a92645ca3 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1311,7 +1311,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do [], adapter: [ timeout: timeout, - recv_timeout: timeout + recv_timeout: timeout, + pool: :default ] ), {:ok, data} <- Jason.decode(body) do diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 76d977ac2..874e8c5e6 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -28,7 +28,7 @@ defmodule Pleroma.Web.RichMedia.Parser do defp parse_url(url) do try do - {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url) + {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], pool: :media) html |> maybe_parse() |> get_parsed_data() rescue diff --git a/lib/pleroma/web/rich_media/parsers/oembed_parser.ex b/lib/pleroma/web/rich_media/parsers/oembed_parser.ex index efa98bc2c..c3adc4962 100644 --- a/lib/pleroma/web/rich_media/parsers/oembed_parser.ex +++ b/lib/pleroma/web/rich_media/parsers/oembed_parser.ex @@ -20,7 +20,7 @@ defmodule Pleroma.Web.RichMedia.Parsers.OEmbed do end defp get_oembed_data(url) do - {:ok, %Tesla.Env{body: json}} = Pleroma.HTTP.get(url) + {:ok, %Tesla.Env{body: json}} = Pleroma.HTTP.get(url, [], pool: :media) {:ok, data} = Jason.decode(json) -- cgit v1.2.3 From ab31adf15bbec1597a9b7cf065898fb3f712eef3 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Wed, 30 Jan 2019 22:56:59 +0700 Subject: tiny improve --- lib/pleroma/jobs.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/jobs.ex b/lib/pleroma/jobs.ex index 16dccb682..24b7e5e46 100644 --- a/lib/pleroma/jobs.ex +++ b/lib/pleroma/jobs.ex @@ -102,7 +102,11 @@ defmodule Pleroma.Jobs do running_jobs = :sets.del_element(ref, running_jobs) - state = state |> remove_ref(ref) |> maybe_start_job(queue_name, running_jobs, queue) + state = + state + |> remove_ref(ref) + |> update_queue(queue_name, {running_jobs, queue}) + |> maybe_start_job(queue_name, running_jobs, queue) {:noreply, state} end @@ -118,7 +122,7 @@ defmodule Pleroma.Jobs do |> add_ref(queue_name, mref) |> update_queue(queue_name, {:sets.add_element(mref, running_jobs), queue}) else - update_queue(state, queue_name, {running_jobs, queue}) + state end end -- cgit v1.2.3 From 935e65e2613d29d065166ba4605ee14349b74c53 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 30 Jan 2019 19:21:04 +0100 Subject: Use race-condition free following method. --- lib/pleroma/user.ex | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1468cc133..62a4a3db1 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -343,18 +343,17 @@ defmodule Pleroma.User do Websub.subscribe(follower, followed) end - following = - [ap_followers | follower.following] - |> Enum.uniq() + q = + from(u in User, + where: u.id == ^follower.id, + update: [push: [following: ^ap_followers]] + ) - follower = - follower - |> follow_changeset(%{following: following}) - |> update_and_set_cache + {1, [follower]} = Repo.update_all(q, [], returning: true) {:ok, _} = update_follower_count(followed) - follower + set_cache(follower) end end @@ -362,17 +361,18 @@ defmodule Pleroma.User do ap_followers = followed.follower_address if following?(follower, followed) and follower.ap_id != followed.ap_id do - following = - follower.following - |> List.delete(ap_followers) + q = + from(u in User, + where: u.id == ^follower.id, + update: [pull: [following: ^ap_followers]] + ) - {:ok, follower} = - follower - |> follow_changeset(%{following: following}) - |> update_and_set_cache + {1, [follower]} = Repo.update_all(q, [], returning: true) {:ok, followed} = update_follower_count(followed) + set_cache(follower) + {:ok, follower, Utils.fetch_latest_follow(follower, followed)} else {:error, "Not subscribed!"} @@ -423,12 +423,16 @@ defmodule Pleroma.User do get_by_nickname(nickname) end + def set_cache(user) do + Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user) + Cachex.put(:user_cache, "nickname:#{user.nickname}", user) + Cachex.put(:user_cache, "user_info:#{user.id}", user_info(user)) + {:ok, user} + end + def update_and_set_cache(changeset) do with {:ok, user} <- Repo.update(changeset) do - Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user) - Cachex.put(:user_cache, "nickname:#{user.nickname}", user) - Cachex.put(:user_cache, "user_info:#{user.id}", user_info(user)) - {:ok, user} + set_cache(user) else e -> e end -- cgit v1.2.3 From 47ec690c54d8af9e317217990fb0756c7d37e2a5 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 30 Jan 2019 19:33:25 +0100 Subject: Use race-condition free mass follow. --- lib/pleroma/user.ex | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 62a4a3db1..bd797db40 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -309,20 +309,21 @@ defmodule Pleroma.User do @doc "A mass follow for local users. Ignores blocks and has no side effects" @spec follow_all(User.t(), list(User.t())) :: {atom(), User.t()} def follow_all(follower, followeds) do - following = - (follower.following ++ Enum.map(followeds, fn %{follower_address: fa} -> fa end)) - |> Enum.uniq() + followed_addresses = Enum.map(followeds, fn %{follower_address: fa} -> fa end) + + q = + from(u in User, + where: u.id == ^follower.id, + update: [set: [following: fragment("array_cat(?, ?)", u.following, ^followed_addresses)]] + ) - {:ok, follower} = - follower - |> follow_changeset(%{following: following}) - |> update_and_set_cache + {1, [follower]} = Repo.update_all(q, [], returning: true) Enum.each(followeds, fn followed -> update_follower_count(followed) end) - {:ok, follower} + set_cache(follower) end def follow(%User{} = follower, %User{info: info} = followed) do -- cgit v1.2.3 From 5ea0397e2d941a95cda9b3c5d8d66cbec9a6b1d6 Mon Sep 17 00:00:00 2001 From: href Date: Wed, 30 Jan 2019 21:08:41 +0100 Subject: Fix 4aff4efa typos --- lib/pleroma/application.ex | 2 +- lib/pleroma/web/rich_media/parser.ex | 2 +- lib/pleroma/web/rich_media/parsers/oembed_parser.ex | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index f775cd53d..40bff08c7 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -132,7 +132,7 @@ defmodule Pleroma.Application do [] end ++ if Pleroma.Config.get([Pleroma.Uploader, :proxy_remote]) do - [:uploadproxy] + [:upload] else [] end diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 874e8c5e6..e67ecc47d 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -28,7 +28,7 @@ defmodule Pleroma.Web.RichMedia.Parser do defp parse_url(url) do try do - {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], pool: :media) + {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: [pool: :media]) html |> maybe_parse() |> get_parsed_data() rescue diff --git a/lib/pleroma/web/rich_media/parsers/oembed_parser.ex b/lib/pleroma/web/rich_media/parsers/oembed_parser.ex index c3adc4962..2530b8c9d 100644 --- a/lib/pleroma/web/rich_media/parsers/oembed_parser.ex +++ b/lib/pleroma/web/rich_media/parsers/oembed_parser.ex @@ -20,7 +20,7 @@ defmodule Pleroma.Web.RichMedia.Parsers.OEmbed do end defp get_oembed_data(url) do - {:ok, %Tesla.Env{body: json}} = Pleroma.HTTP.get(url, [], pool: :media) + {:ok, %Tesla.Env{body: json}} = Pleroma.HTTP.get(url, [], adapter: [pool: :media]) {:ok, data} = Jason.decode(json) -- cgit v1.2.3 From 58e250d9d27205116df5634d909ec1e43ea55286 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 31 Jan 2019 15:23:50 +0700 Subject: fix merge --- lib/pleroma/application.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index e81816e35..e44c48c35 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -109,7 +109,7 @@ defmodule Pleroma.Application do worker(Pleroma.Stats, []), worker(Pleroma.Web.Push, []), worker(Pleroma.Jobs, []), - worker(Task, [&Pleroma.Web.Federator.init/0], restart: :temporary) + worker(Task, [&Pleroma.Web.Federator.init/0], restart: :temporary) ] ++ streamer_child() ++ chat_child() ++ -- cgit v1.2.3 From a43a1c6d4e6ff26c751cce1284deb2ef40b00ab7 Mon Sep 17 00:00:00 2001 From: lambda Date: Thu, 31 Jan 2019 12:16:23 +0000 Subject: Revert "Merge branch 'spc-fix-3' into 'develop'" This reverts merge request !682 --- lib/pleroma/spc_fixes/spc_fixes.ex | 113 --- lib/pleroma/spc_fixes/users_conversion.txt | 1043 ---------------------------- 2 files changed, 1156 deletions(-) delete mode 100644 lib/pleroma/spc_fixes/spc_fixes.ex delete mode 100644 lib/pleroma/spc_fixes/users_conversion.txt (limited to 'lib') diff --git a/lib/pleroma/spc_fixes/spc_fixes.ex b/lib/pleroma/spc_fixes/spc_fixes.ex deleted file mode 100644 index 86bbb7f6f..000000000 --- a/lib/pleroma/spc_fixes/spc_fixes.ex +++ /dev/null @@ -1,113 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -alias Pleroma.Repo -alias Pleroma.User -alias Pleroma.Activity -alias Pleroma.Object -import Ecto.Query - -defmodule Pleroma.SpcFixes do - def upgrade_users do - query = - from(u in User, - where: fragment("? like ?", u.ap_id, "https://shitposter.club/user/%") - ) - - {:ok, file} = File.read("lib/pleroma/spc_fixes/users_conversion.txt") - - # Mapping of old ap_id to new ap_id and vice reversa - mapping = - file - |> String.trim() - |> String.split("\n") - |> Enum.map(fn line -> - line - |> String.split("\t") - end) - |> Enum.reduce(%{}, fn [_id, old_ap_id, new_ap_id], acc -> - acc - |> Map.put(String.trim(old_ap_id), String.trim(new_ap_id)) - |> Map.put(String.trim(new_ap_id), String.trim(old_ap_id)) - end) - - # First, refetch all the old users. - _old_users = - query - |> Repo.all() - |> Enum.each(fn user -> - with ap_id when is_binary(ap_id) <- mapping[user.ap_id] do - # This fetches and updates the user. - User.get_or_fetch_by_ap_id(ap_id) - end - end) - - # Now, fix follow relationships. - query = - from(u in User, - where: fragment("? like ?", u.ap_id, "https://shitposter.club/users/%") - ) - - query - |> Repo.all() - |> Enum.each(fn user -> - old_follower_address = User.ap_followers(user) - - # Fix users - query = - from(u in User, - where: ^old_follower_address in u.following, - update: [ - push: [following: ^user.follower_address] - ] - ) - - Repo.update_all(query, []) - - # Fix activities - query = - from(a in Activity, - where: fragment("?->>'actor' = ?", a.data, ^mapping[user.ap_id]), - update: [ - set: [ - data: - fragment( - "jsonb_set(jsonb_set(?, '{actor}', ?), '{to}', (?->'to')::jsonb || ?)", - a.data, - ^user.ap_id, - a.data, - ^[user.follower_address] - ), - actor: ^user.ap_id - ], - push: [ - recipients: ^user.follower_address - ] - ] - ) - - Repo.update_all(query, []) - - # Fix objects - query = - from(a in Object, - where: fragment("?->>'actor' = ?", a.data, ^mapping[user.ap_id]), - update: [ - set: [ - data: - fragment( - "jsonb_set(jsonb_set(?, '{actor}', ?), '{to}', (?->'to')::jsonb || ?)", - a.data, - ^user.ap_id, - a.data, - ^[user.follower_address] - ) - ] - ] - ) - - Repo.update_all(query, []) - end) - end -end diff --git a/lib/pleroma/spc_fixes/users_conversion.txt b/lib/pleroma/spc_fixes/users_conversion.txt deleted file mode 100644 index 0d0321e18..000000000 --- a/lib/pleroma/spc_fixes/users_conversion.txt +++ /dev/null @@ -1,1043 +0,0 @@ -1 https://shitposter.club/user/1 https://shitposter.club/users/moonman -2 https://shitposter.club/user/2 https://shitposter.club/users/sunman -45 https://shitposter.club/user/45 https://shitposter.club/users/chen -59 https://shitposter.club/user/59 https://shitposter.club/users/mona -63 https://shitposter.club/user/63 https://shitposter.club/users/wdgaster -64 https://shitposter.club/user/64 https://shitposter.club/users/waluigi -65 https://shitposter.club/user/65 https://shitposter.club/users/puke -66 https://shitposter.club/user/66 https://shitposter.club/users/sanstheskeleton -67 https://shitposter.club/user/67 https://shitposter.club/users/venus -68 https://shitposter.club/user/68 https://shitposter.club/users/noyoushutthefuckupdad -70 https://shitposter.club/user/70 https://shitposter.club/users/dualkeyblade -72 https://shitposter.club/user/72 https://shitposter.club/users/hyperbeam -74 https://shitposter.club/user/74 https://shitposter.club/users/chopperdave -75 https://shitposter.club/user/75 https://shitposter.club/users/itachi -78 https://shitposter.club/user/78 https://shitposter.club/users/gyro -80 https://shitposter.club/user/80 https://shitposter.club/users/drli -81 https://shitposter.club/user/81 https://shitposter.club/users/dril -82 https://shitposter.club/user/82 https://shitposter.club/users/bayonetta -83 https://shitposter.club/user/83 https://shitposter.club/users/imrc -91 https://shitposter.club/user/91 https://shitposter.club/users/hobi -95 https://shitposter.club/user/95 https://shitposter.club/users/houndoom -102 https://shitposter.club/user/102 https://shitposter.club/users/fuck -103 https://shitposter.club/user/103 https://shitposter.club/users/mh -114 https://shitposter.club/user/114 https://shitposter.club/users/strider -116 https://shitposter.club/user/116 https://shitposter.club/users/bunny -120 https://shitposter.club/user/120 https://shitposter.club/users/teddie -121 https://shitposter.club/user/121 https://shitposter.club/users/genesis -122 https://shitposter.club/user/122 https://shitposter.club/users/ninten -124 https://shitposter.club/user/124 https://shitposter.club/users/matsucest -125 https://shitposter.club/user/125 https://shitposter.club/users/yuri -126 https://shitposter.club/user/126 https://shitposter.club/users/yang -127 https://shitposter.club/user/127 https://shitposter.club/users/yokaiwatch -128 https://shitposter.club/user/128 https://shitposter.club/users/futo -129 https://shitposter.club/user/129 https://shitposter.club/users/captainfalcon -130 https://shitposter.club/user/130 https://shitposter.club/users/liquid -131 https://shitposter.club/user/131 https://shitposter.club/users/flonne -132 https://shitposter.club/user/132 https://shitposter.club/users/ryoubakura -133 https://shitposter.club/user/133 https://shitposter.club/users/kirisame -134 https://shitposter.club/user/134 https://shitposter.club/users/senyuu -135 https://shitposter.club/user/135 https://shitposter.club/users/protagonist -136 https://shitposter.club/user/136 https://shitposter.club/users/zelos -137 https://shitposter.club/user/137 https://shitposter.club/users/alba -138 https://shitposter.club/user/138 https://shitposter.club/users/yugo -139 https://shitposter.club/user/139 https://shitposter.club/users/vector -141 https://shitposter.club/user/141 https://shitposter.club/users/god -144 https://shitposter.club/user/144 https://shitposter.club/users/yuya -147 https://shitposter.club/user/147 https://shitposter.club/users/blmatsu -148 https://shitposter.club/user/148 https://shitposter.club/users/pain -149 https://shitposter.club/user/149 https://shitposter.club/users/bloodfalcon -150 https://shitposter.club/user/150 https://shitposter.club/users/yuzu -152 https://shitposter.club/user/152 https://shitposter.club/users/hex -153 https://shitposter.club/user/153 https://shitposter.club/users/coolcatlovesyou -154 https://shitposter.club/user/154 https://shitposter.club/users/cat -159 https://shitposter.club/user/159 https://shitposter.club/users/edna -162 https://shitposter.club/user/162 https://shitposter.club/users/uwu -163 https://shitposter.club/user/163 https://shitposter.club/users/onceler -164 https://shitposter.club/user/164 https://shitposter.club/users/swordofdoubt -168 https://shitposter.club/user/168 https://shitposter.club/users/komaeda -170 https://shitposter.club/user/170 https://shitposter.club/users/protoman -176 https://shitposter.club/user/176 https://shitposter.club/users/kiitanda -177 https://shitposter.club/user/177 https://shitposter.club/users/starscream -180 https://shitposter.club/user/180 https://shitposter.club/users/trishuna -183 https://shitposter.club/user/183 https://shitposter.club/users/milk -184 https://shitposter.club/user/184 https://shitposter.club/users/otacon -185 https://shitposter.club/user/185 https://shitposter.club/users/ragna -189 https://shitposter.club/user/189 https://shitposter.club/users/majintensei -193 https://shitposter.club/user/193 https://shitposter.club/users/deadpool -195 https://shitposter.club/user/195 https://shitposter.club/users/ramimalek -199 https://shitposter.club/user/199 https://shitposter.club/users/ritsu -200 https://shitposter.club/user/200 https://shitposter.club/users/alisha -201 https://shitposter.club/user/201 https://shitposter.club/users/naegi -202 https://shitposter.club/user/202 https://shitposter.club/users/shartmeister420 -203 https://shitposter.club/user/203 https://shitposter.club/users/lulz -204 https://shitposter.club/user/204 https://shitposter.club/users/youranonnews -208 https://shitposter.club/user/208 https://shitposter.club/users/haruna -209 https://shitposter.club/user/209 https://shitposter.club/users/bigboss -213 https://shitposter.club/user/213 https://shitposter.club/users/whisper -219 https://shitposter.club/user/219 https://shitposter.club/users/billfromnextdoor -228 https://shitposter.club/user/228 https://shitposter.club/users/cta -229 https://shitposter.club/user/229 https://shitposter.club/users/luketriton -230 https://shitposter.club/user/230 https://shitposter.club/users/striking -238 https://shitposter.club/user/238 https://shitposter.club/users/this -243 https://shitposter.club/user/243 https://shitposter.club/users/greed -244 https://shitposter.club/user/244 https://shitposter.club/users/quicksilver -246 https://shitposter.club/user/246 https://shitposter.club/users/zaveid -249 https://shitposter.club/user/249 https://shitposter.club/users/serena -263 https://shitposter.club/user/263 https://shitposter.club/users/compaq -264 https://shitposter.club/user/264 https://shitposter.club/users/squishy -265 https://shitposter.club/user/265 https://shitposter.club/users/furry -269 https://shitposter.club/user/269 https://shitposter.club/users/mikleo -270 https://shitposter.club/user/270 https://shitposter.club/users/ami -272 https://shitposter.club/user/272 https://shitposter.club/users/ruri -273 https://shitposter.club/user/273 https://shitposter.club/users/descole -292 https://shitposter.club/user/292 https://shitposter.club/users/shun -296 https://shitposter.club/user/296 https://shitposter.club/users/magician -297 https://shitposter.club/user/297 https://shitposter.club/users/pichan -301 https://shitposter.club/user/301 https://shitposter.club/users/scaryh -303 https://shitposter.club/user/303 https://shitposter.club/users/phz -349 https://shitposter.club/user/349 https://shitposter.club/users/star -350 https://shitposter.club/user/350 https://shitposter.club/users/pepe -351 https://shitposter.club/user/351 https://shitposter.club/users/disassemblyline -354 https://shitposter.club/user/354 https://shitposter.club/users/elrac -382 https://shitposter.club/user/382 https://shitposter.club/users/bigdinner -390 https://shitposter.club/user/390 https://shitposter.club/users/choromatsu -391 https://shitposter.club/user/391 https://shitposter.club/users/otasune -396 https://shitposter.club/user/396 https://shitposter.club/users/cavestoryost -415 https://shitposter.club/user/415 https://shitposter.club/users/hazama -453 https://shitposter.club/user/453 https://shitposter.club/users/mgs3 -479 https://shitposter.club/user/479 https://shitposter.club/users/kanarykrusade -486 https://shitposter.club/user/486 https://shitposter.club/users/yitzyy -495 https://shitposter.club/user/495 https://shitposter.club/users/frog -497 https://shitposter.club/user/497 https://shitposter.club/users/marik -498 https://shitposter.club/user/498 https://shitposter.club/users/cookboy -505 https://shitposter.club/user/505 https://shitposter.club/users/damnalex -511 https://shitposter.club/user/511 https://shitposter.club/users/asbellhant -512 https://shitposter.club/user/512 https://shitposter.club/users/hitler -515 https://shitposter.club/user/515 https://shitposter.club/users/zeloswilder -516 https://shitposter.club/user/516 https://shitposter.club/users/makotokikuchi -518 https://shitposter.club/user/518 https://shitposter.club/users/kaito -519 https://shitposter.club/user/519 https://shitposter.club/users/bluto -520 https://shitposter.club/user/520 https://shitposter.club/users/akuma -521 https://shitposter.club/user/521 https://shitposter.club/users/blythe -522 https://shitposter.club/user/522 https://shitposter.club/users/heavensfeel -523 https://shitposter.club/user/523 https://shitposter.club/users/sirscatters -524 https://shitposter.club/user/524 https://shitposter.club/users/gakupo -526 https://shitposter.club/user/526 https://shitposter.club/users/anntagonist -527 https://shitposter.club/user/527 https://shitposter.club/users/misscatling -529 https://shitposter.club/user/529 https://shitposter.club/users/misscatlin -532 https://shitposter.club/user/532 https://shitposter.club/users/rjohnlennon -533 https://shitposter.club/user/533 https://shitposter.club/users/randhask -535 https://shitposter.club/user/535 https://shitposter.club/users/zemichi -537 https://shitposter.club/user/537 https://shitposter.club/users/carol -539 https://shitposter.club/user/539 https://shitposter.club/users/catmeme -540 https://shitposter.club/user/540 https://shitposter.club/users/spikespiegel -542 https://shitposter.club/user/542 https://shitposter.club/users/marvinthemartian -545 https://shitposter.club/user/545 https://shitposter.club/users/androlphegax -547 https://shitposter.club/user/547 https://shitposter.club/users/atlfalconsfan -549 https://shitposter.club/user/549 https://shitposter.club/users/shaxpeer -550 https://shitposter.club/user/550 https://shitposter.club/users/toddkincannon -556 https://shitposter.club/user/556 https://shitposter.club/users/divider -557 https://shitposter.club/user/557 https://shitposter.club/users/rayogundead -558 https://shitposter.club/user/558 https://shitposter.club/users/breadgod -561 https://shitposter.club/user/561 https://shitposter.club/users/internetzenmaster -569 https://shitposter.club/user/569 https://shitposter.club/users/izzyjsmom -571 https://shitposter.club/user/571 https://shitposter.club/users/spb -573 https://shitposter.club/user/573 https://shitposter.club/users/necrofantasia -574 https://shitposter.club/user/574 https://shitposter.club/users/cvlztn -575 https://shitposter.club/user/575 https://shitposter.club/users/herbiemarcuse -577 https://shitposter.club/user/577 https://shitposter.club/users/simarilian -578 https://shitposter.club/user/578 https://shitposter.club/users/shingo -580 https://shitposter.club/user/580 https://shitposter.club/users/applebees -582 https://shitposter.club/user/582 https://shitposter.club/users/heechul -583 https://shitposter.club/user/583 https://shitposter.club/users/rin -584 https://shitposter.club/user/584 https://shitposter.club/users/killua -585 https://shitposter.club/user/585 https://shitposter.club/users/seamus -586 https://shitposter.club/user/586 https://shitposter.club/users/momoisatsuki -588 https://shitposter.club/user/588 https://shitposter.club/users/bs -589 https://shitposter.club/user/589 https://shitposter.club/users/nya -595 https://shitposter.club/user/595 https://shitposter.club/users/elfpietrok -598 https://shitposter.club/user/598 https://shitposter.club/users/cyc0 -600 https://shitposter.club/user/600 https://shitposter.club/users/9riest -601 https://shitposter.club/user/601 https://shitposter.club/users/bella -602 https://shitposter.club/user/602 https://shitposter.club/users/hopestillflies -604 https://shitposter.club/user/604 https://shitposter.club/users/mark -605 https://shitposter.club/user/605 https://shitposter.club/users/crappycoco -607 https://shitposter.club/user/607 https://shitposter.club/users/meme -609 https://shitposter.club/user/609 https://shitposter.club/users/raylan -610 https://shitposter.club/user/610 https://shitposter.club/users/berry -611 https://shitposter.club/user/611 https://shitposter.club/users/noobius -621 https://shitposter.club/user/621 https://shitposter.club/users/lit -622 https://shitposter.club/user/622 https://shitposter.club/users/thedominionofplumass -633 https://shitposter.club/user/633 https://shitposter.club/users/amish -640 https://shitposter.club/user/640 https://shitposter.club/users/yaoi -657 https://shitposter.club/user/657 https://shitposter.club/users/ayano -661 https://shitposter.club/user/661 https://shitposter.club/users/velvethammer -665 https://shitposter.club/user/665 https://shitposter.club/users/yushe -666 https://shitposter.club/user/666 https://shitposter.club/users/rw -684 https://shitposter.club/user/684 https://shitposter.club/users/justplainbill -685 https://shitposter.club/user/685 https://shitposter.club/users/bree -687 https://shitposter.club/user/687 https://shitposter.club/users/dinahlord -693 https://shitposter.club/user/693 https://shitposter.club/users/luna -694 https://shitposter.club/user/694 https://shitposter.club/users/winterjaeger -695 https://shitposter.club/user/695 https://shitposter.club/users/winterjaeger7 -696 https://shitposter.club/user/696 https://shitposter.club/users/vall -697 https://shitposter.club/user/697 https://shitposter.club/users/nsa -699 https://shitposter.club/user/699 https://shitposter.club/users/haolink -700 https://shitposter.club/user/700 https://shitposter.club/users/mrsaturday -711 https://shitposter.club/user/711 https://shitposter.club/users/ob -728 https://shitposter.club/user/728 https://shitposter.club/users/djormil -734 https://shitposter.club/user/734 https://shitposter.club/users/twittercoe -735 https://shitposter.club/user/735 https://shitposter.club/users/twitterceo -748 https://shitposter.club/user/748 https://shitposter.club/users/joeprich -751 https://shitposter.club/user/751 https://shitposter.club/users/cheeto -755 https://shitposter.club/user/755 https://shitposter.club/users/jojo -757 https://shitposter.club/user/757 https://shitposter.club/users/onet -759 https://shitposter.club/user/759 https://shitposter.club/users/hiredmind -769 https://shitposter.club/user/769 https://shitposter.club/users/bonzibuddy -771 https://shitposter.club/user/771 https://shitposter.club/users/six6six -772 https://shitposter.club/user/772 https://shitposter.club/users/grantweets2 -779 https://shitposter.club/user/779 https://shitposter.club/users/marcavis -783 https://shitposter.club/user/783 https://shitposter.club/users/wintergirl93 -785 https://shitposter.club/user/785 https://shitposter.club/users/moonmanmobile -795 https://shitposter.club/user/795 https://shitposter.club/users/oz -796 https://shitposter.club/user/796 https://shitposter.club/users/rei -797 https://shitposter.club/user/797 https://shitposter.club/users/luciela -798 https://shitposter.club/user/798 https://shitposter.club/users/nightray -799 https://shitposter.club/user/799 https://shitposter.club/users/sorey -800 https://shitposter.club/user/800 https://shitposter.club/users/jack -802 https://shitposter.club/user/802 https://shitposter.club/users/natsu -804 https://shitposter.club/user/804 https://shitposter.club/users/yuuya -805 https://shitposter.club/user/805 https://shitposter.club/users/leo -817 https://shitposter.club/user/817 https://shitposter.club/users/rottenleaf -831 https://shitposter.club/user/831 https://shitposter.club/users/aqua -832 https://shitposter.club/user/832 https://shitposter.club/users/jihadistjoe -833 https://shitposter.club/user/833 https://shitposter.club/users/comradegg -835 https://shitposter.club/user/835 https://shitposter.club/users/bossgod -836 https://shitposter.club/user/836 https://shitposter.club/users/realdonaldtrump -859 https://shitposter.club/user/859 https://shitposter.club/users/marufoi -862 https://shitposter.club/user/862 https://shitposter.club/users/buffdad -978 https://shitposter.club/user/978 https://shitposter.club/users/nonameko -979 https://shitposter.club/user/979 https://shitposter.club/users/ira -988 https://shitposter.club/user/988 https://shitposter.club/users/adrint -1001 https://shitposter.club/user/1001 https://shitposter.club/users/fajfus -1018 https://shitposter.club/user/1018 https://shitposter.club/users/jon -1019 https://shitposter.club/user/1019 https://shitposter.club/users/levo -1020 https://shitposter.club/user/1020 https://shitposter.club/users/bhm -1023 https://shitposter.club/user/1023 https://shitposter.club/users/librarian -1025 https://shitposter.club/user/1025 https://shitposter.club/users/conanedogawa -1027 https://shitposter.club/user/1027 https://shitposter.club/users/gentlefemdom -1029 https://shitposter.club/user/1029 https://shitposter.club/users/hentie -1030 https://shitposter.club/user/1030 https://shitposter.club/users/notaskeleton -1038 https://shitposter.club/user/1038 https://shitposter.club/users/succ -1061 https://shitposter.club/user/1061 https://shitposter.club/users/applepark -1110 https://shitposter.club/user/1110 https://shitposter.club/users/caraway -1115 https://shitposter.club/user/1115 https://shitposter.club/users/jump -1118 https://shitposter.club/user/1118 https://shitposter.club/users/test222 -1120 https://shitposter.club/user/1120 https://shitposter.club/users/lu -1127 https://shitposter.club/user/1127 https://shitposter.club/users/riocat5 -1130 https://shitposter.club/user/1130 https://shitposter.club/users/lovelive -1137 https://shitposter.club/user/1137 https://shitposter.club/users/johnsonmcfonson -1159 https://shitposter.club/user/1159 https://shitposter.club/users/j -1179 https://shitposter.club/user/1179 https://shitposter.club/users/kumatora -1180 https://shitposter.club/user/1180 https://shitposter.club/users/komasan -1181 https://shitposter.club/user/1181 https://shitposter.club/users/8xenon8 -1183 https://shitposter.club/user/1183 https://shitposter.club/users/lemon -1184 https://shitposter.club/user/1184 https://shitposter.club/users/osomatsu -1186 https://shitposter.club/user/1186 https://shitposter.club/users/anomalyuk -1188 https://shitposter.club/user/1188 https://shitposter.club/users/jelly -1195 https://shitposter.club/user/1195 https://shitposter.club/users/ultra -1196 https://shitposter.club/user/1196 https://shitposter.club/users/mrmichael -1198 https://shitposter.club/user/1198 https://shitposter.club/users/neue -1205 https://shitposter.club/user/1205 https://shitposter.club/users/tomasnau -1261 https://shitposter.club/user/1261 https://shitposter.club/users/aljam -1279 https://shitposter.club/user/1279 https://shitposter.club/users/pigeonburger -1315 https://shitposter.club/user/1315 https://shitposter.club/users/itsstillrealtomedamnit -1366 https://shitposter.club/user/1366 https://shitposter.club/users/pewdiepie -1608 https://shitposter.club/user/1608 https://shitposter.club/users/serrarreaver -1613 https://shitposter.club/user/1613 https://shitposter.club/users/furrystoat -1629 https://shitposter.club/user/1629 https://shitposter.club/users/lordkraftdinner -1670 https://shitposter.club/user/1670 https://shitposter.club/users/idiotska -1736 https://shitposter.club/user/1736 https://shitposter.club/users/rabit3a -1946 https://shitposter.club/user/1946 https://shitposter.club/users/tikiloungemahu -1977 https://shitposter.club/user/1977 https://shitposter.club/users/arashinarukami -2035 https://shitposter.club/user/2035 https://shitposter.club/users/spedru -2088 https://shitposter.club/user/2088 https://shitposter.club/users/idol -2175 https://shitposter.club/user/2175 https://shitposter.club/users/olmitch -2227 https://shitposter.club/user/2227 https://shitposter.club/users/dune -2322 https://shitposter.club/user/2322 https://shitposter.club/users/biwazimayui -2323 https://shitposter.club/user/2323 https://shitposter.club/users/cawfee -2325 https://shitposter.club/user/2325 https://shitposter.club/users/jimrusell -2329 https://shitposter.club/user/2329 https://shitposter.club/users/illya -2341 https://shitposter.club/user/2341 https://shitposter.club/users/apple -2357 https://shitposter.club/user/2357 https://shitposter.club/users/bear -2358 https://shitposter.club/user/2358 https://shitposter.club/users/goldburggoldenhour -2378 https://shitposter.club/user/2378 https://shitposter.club/users/b1940060 -2380 https://shitposter.club/user/2380 https://shitposter.club/users/garnerh42 -2388 https://shitposter.club/user/2388 https://shitposter.club/users/niceau -2389 https://shitposter.club/user/2389 https://shitposter.club/users/zekeyspaceylizard -2391 https://shitposter.club/user/2391 https://shitposter.club/users/fbi -2400 https://shitposter.club/user/2400 https://shitposter.club/users/miraculousladybug -2413 https://shitposter.club/user/2413 https://shitposter.club/users/maxauri -2450 https://shitposter.club/user/2450 https://shitposter.club/users/camedei456 -2466 https://shitposter.club/user/2466 https://shitposter.club/users/nurgledsatorin -2512 https://shitposter.club/user/2512 https://shitposter.club/users/conspiracy -2539 https://shitposter.club/user/2539 https://shitposter.club/users/dtluna -2542 https://shitposter.club/user/2542 https://shitposter.club/users/analepticalzabo -2573 https://shitposter.club/user/2573 https://shitposter.club/users/irregardlessly -2588 https://shitposter.club/user/2588 https://shitposter.club/users/chalt -2599 https://shitposter.club/user/2599 https://shitposter.club/users/shtposter -2639 https://shitposter.club/user/2639 https://shitposter.club/users/oogy -2647 https://shitposter.club/user/2647 https://shitposter.club/users/salad -2662 https://shitposter.club/user/2662 https://shitposter.club/users/godfather -2663 https://shitposter.club/user/2663 https://shitposter.club/users/good -2664 https://shitposter.club/user/2664 https://shitposter.club/users/mc -2672 https://shitposter.club/user/2672 https://shitposter.club/users/nilbo -2680 https://shitposter.club/user/2680 https://shitposter.club/users/ovrclockd -2687 https://shitposter.club/user/2687 https://shitposter.club/users/politics -2724 https://shitposter.club/user/2724 https://shitposter.club/users/soomeguy -2748 https://shitposter.club/user/2748 https://shitposter.club/users/lghb -2751 https://shitposter.club/user/2751 https://shitposter.club/users/imdarelzslimsha -2794 https://shitposter.club/user/2794 https://shitposter.club/users/robert -2795 https://shitposter.club/user/2795 https://shitposter.club/users/jani -2796 https://shitposter.club/user/2796 https://shitposter.club/users/richard -2797 https://shitposter.club/user/2797 https://shitposter.club/users/warmerbrudi -2798 https://shitposter.club/user/2798 https://shitposter.club/users/thomas -2800 https://shitposter.club/user/2800 https://shitposter.club/users/100days -2801 https://shitposter.club/user/2801 https://shitposter.club/users/christoffel -2814 https://shitposter.club/user/2814 https://shitposter.club/users/cmpunk -2841 https://shitposter.club/user/2841 https://shitposter.club/users/shit -2886 https://shitposter.club/user/2886 https://shitposter.club/users/bdf -2889 https://shitposter.club/user/2889 https://shitposter.club/users/memesbrasileiros -2909 https://shitposter.club/user/2909 https://shitposter.club/users/tiuluhen -2942 https://shitposter.club/user/2942 https://shitposter.club/users/wormhole -2947 https://shitposter.club/user/2947 https://shitposter.club/users/augustus -2954 https://shitposter.club/user/2954 https://shitposter.club/users/vaka -2974 https://shitposter.club/user/2974 https://shitposter.club/users/moonbot -2979 https://shitposter.club/user/2979 https://shitposter.club/users/fakedonaldtrump -3009 https://shitposter.club/user/3009 https://shitposter.club/users/r4 -3032 https://shitposter.club/user/3032 https://shitposter.club/users/delores -3127 https://shitposter.club/user/3127 https://shitposter.club/users/plusreed -3148 https://shitposter.club/user/3148 https://shitposter.club/users/deimos -3151 https://shitposter.club/user/3151 https://shitposter.club/users/memer69 -3162 https://shitposter.club/user/3162 https://shitposter.club/users/tyreese -3163 https://shitposter.club/user/3163 https://shitposter.club/users/glen -3167 https://shitposter.club/user/3167 https://shitposter.club/users/jonny -3171 https://shitposter.club/user/3171 https://shitposter.club/users/chrishansen -3174 https://shitposter.club/user/3174 https://shitposter.club/users/usindianaffairs -3175 https://shitposter.club/user/3175 https://shitposter.club/users/cia -3225 https://shitposter.club/user/3225 https://shitposter.club/users/baconbrain -3274 https://shitposter.club/user/3274 https://shitposter.club/users/jackmcbastard -3310 https://shitposter.club/user/3310 https://shitposter.club/users/lifeprotips -3321 https://shitposter.club/user/3321 https://shitposter.club/users/nerd -3322 https://shitposter.club/user/3322 https://shitposter.club/users/flandre -3324 https://shitposter.club/user/3324 https://shitposter.club/users/kingofmars -3365 https://shitposter.club/user/3365 https://shitposter.club/users/ben -3378 https://shitposter.club/user/3378 https://shitposter.club/users/staffanb -3387 https://shitposter.club/user/3387 https://shitposter.club/users/2321 -3391 https://shitposter.club/user/3391 https://shitposter.club/users/hydris -3393 https://shitposter.club/user/3393 https://shitposter.club/users/elj -3397 https://shitposter.club/user/3397 https://shitposter.club/users/yachise -3400 https://shitposter.club/user/3400 https://shitposter.club/users/robertomangueiragrossa -3408 https://shitposter.club/user/3408 https://shitposter.club/users/danclark -3409 https://shitposter.club/user/3409 https://shitposter.club/users/erm -3441 https://shitposter.club/user/3441 https://shitposter.club/users/govspiders -3466 https://shitposter.club/user/3466 https://shitposter.club/users/malduke -3543 https://shitposter.club/user/3543 https://shitposter.club/users/testslut -3568 https://shitposter.club/user/3568 https://shitposter.club/users/grimjim -3574 https://shitposter.club/user/3574 https://shitposter.club/users/dyingrectifrice -3642 https://shitposter.club/user/3642 https://shitposter.club/users/eyepie -3699 https://shitposter.club/user/3699 https://shitposter.club/users/emiko -3713 https://shitposter.club/user/3713 https://shitposter.club/users/dex -3767 https://shitposter.club/user/3767 https://shitposter.club/users/roi -3770 https://shitposter.club/user/3770 https://shitposter.club/users/jj -3814 https://shitposter.club/user/3814 https://shitposter.club/users/why -3820 https://shitposter.club/user/3820 https://shitposter.club/users/polstar -3854 https://shitposter.club/user/3854 https://shitposter.club/users/metalhead33 -3860 https://shitposter.club/user/3860 https://shitposter.club/users/valkitty -3891 https://shitposter.club/user/3891 https://shitposter.club/users/yata -3894 https://shitposter.club/user/3894 https://shitposter.club/users/oonska -3895 https://shitposter.club/user/3895 https://shitposter.club/users/1iceloops123 -3896 https://shitposter.club/user/3896 https://shitposter.club/users/69 -3897 https://shitposter.club/user/3897 https://shitposter.club/users/bitterandrew2 -3900 https://shitposter.club/user/3900 https://shitposter.club/users/neckbolt -3904 https://shitposter.club/user/3904 https://shitposter.club/users/kommentater -3909 https://shitposter.club/user/3909 https://shitposter.club/users/bae -3911 https://shitposter.club/user/3911 https://shitposter.club/users/eternalblizzard -3913 https://shitposter.club/user/3913 https://shitposter.club/users/trevgauntlet -3915 https://shitposter.club/user/3915 https://shitposter.club/users/vriska -3952 https://shitposter.club/user/3952 https://shitposter.club/users/gethn7 -3953 https://shitposter.club/user/3953 https://shitposter.club/users/mgd -4011 https://shitposter.club/user/4011 https://shitposter.club/users/dirds -4026 https://shitposter.club/user/4026 https://shitposter.club/users/panzervoulait -4027 https://shitposter.club/user/4027 https://shitposter.club/users/clublarsh -4046 https://shitposter.club/user/4046 https://shitposter.club/users/kaz -4047 https://shitposter.club/user/4047 https://shitposter.club/users/failure -4084 https://shitposter.club/user/4084 https://shitposter.club/users/oneiorosgrip -4095 https://shitposter.club/user/4095 https://shitposter.club/users/theraveduck -4106 https://shitposter.club/user/4106 https://shitposter.club/users/gothmatix -4133 https://shitposter.club/user/4133 https://shitposter.club/users/miserablesmileface -4164 https://shitposter.club/user/4164 https://shitposter.club/users/vektg -4166 https://shitposter.club/user/4166 https://shitposter.club/users/spectrum -4179 https://shitposter.club/user/4179 https://shitposter.club/users/powerclam -4186 https://shitposter.club/user/4186 https://shitposter.club/users/madcat -4230 https://shitposter.club/user/4230 https://shitposter.club/users/nbd -4231 https://shitposter.club/user/4231 https://shitposter.club/users/triodug -4350 https://shitposter.club/user/4350 https://shitposter.club/users/dog -4389 https://shitposter.club/user/4389 https://shitposter.club/users/reissdjo -4400 https://shitposter.club/user/4400 https://shitposter.club/users/daeavorn -4401 https://shitposter.club/user/4401 https://shitposter.club/users/yourgrandmother -4414 https://shitposter.club/user/4414 https://shitposter.club/users/harmlessduck -4416 https://shitposter.club/user/4416 https://shitposter.club/users/phoenixarised -4420 https://shitposter.club/user/4420 https://shitposter.club/users/maxmustermann -4423 https://shitposter.club/user/4423 https://shitposter.club/users/tomsequitur -4425 https://shitposter.club/user/4425 https://shitposter.club/users/suityourself -4434 https://shitposter.club/user/4434 https://shitposter.club/users/gibbfm -4436 https://shitposter.club/user/4436 https://shitposter.club/users/pcachu -4440 https://shitposter.club/user/4440 https://shitposter.club/users/misspixie345 -4443 https://shitposter.club/user/4443 https://shitposter.club/users/mosley -4444 https://shitposter.club/user/4444 https://shitposter.club/users/lonewolf031 -4450 https://shitposter.club/user/4450 https://shitposter.club/users/ajr -4451 https://shitposter.club/user/4451 https://shitposter.club/users/reno -4454 https://shitposter.club/user/4454 https://shitposter.club/users/panjoozek -4457 https://shitposter.club/user/4457 https://shitposter.club/users/realpennyfortheguy -4464 https://shitposter.club/user/4464 https://shitposter.club/users/thelogiconlyzone -4467 https://shitposter.club/user/4467 https://shitposter.club/users/craig -4496 https://shitposter.club/user/4496 https://shitposter.club/users/yuiiski -4506 https://shitposter.club/user/4506 https://shitposter.club/users/robot -4556 https://shitposter.club/user/4556 https://shitposter.club/users/boozearmada -4573 https://shitposter.club/user/4573 https://shitposter.club/users/combine -4605 https://shitposter.club/user/4605 https://shitposter.club/users/ultrapageup -4627 https://shitposter.club/user/4627 https://shitposter.club/users/eris -4633 https://shitposter.club/user/4633 https://shitposter.club/users/moethirteen -4636 https://shitposter.club/user/4636 https://shitposter.club/users/quuunno -4644 https://shitposter.club/user/4644 https://shitposter.club/users/moonatdefcon -4657 https://shitposter.club/user/4657 https://shitposter.club/users/lombon -4670 https://shitposter.club/user/4670 https://shitposter.club/users/mojadam -4686 https://shitposter.club/user/4686 https://shitposter.club/users/ghofan -4690 https://shitposter.club/user/4690 https://shitposter.club/users/cameron -4708 https://shitposter.club/user/4708 https://shitposter.club/users/thevortexcoalition -4713 https://shitposter.club/user/4713 https://shitposter.club/users/rosario -4724 https://shitposter.club/user/4724 https://shitposter.club/users/datass -4759 https://shitposter.club/user/4759 https://shitposter.club/users/melancholy -4770 https://shitposter.club/user/4770 https://shitposter.club/users/boris -4773 https://shitposter.club/user/4773 https://shitposter.club/users/2dollaslices -4793 https://shitposter.club/user/4793 https://shitposter.club/users/jesus -4814 https://shitposter.club/user/4814 https://shitposter.club/users/nils -4826 https://shitposter.club/user/4826 https://shitposter.club/users/netkitteh -4887 https://shitposter.club/user/4887 https://shitposter.club/users/birch -4924 https://shitposter.club/user/4924 https://shitposter.club/users/rt -4940 https://shitposter.club/user/4940 https://shitposter.club/users/comradeagle -4943 https://shitposter.club/user/4943 https://shitposter.club/users/luciel -4950 https://shitposter.club/user/4950 https://shitposter.club/users/rob -4952 https://shitposter.club/user/4952 https://shitposter.club/users/eros -4954 https://shitposter.club/user/4954 https://shitposter.club/users/smeagledorf -4962 https://shitposter.club/user/4962 https://shitposter.club/users/zep -4982 https://shitposter.club/user/4982 https://shitposter.club/users/furaffinity -4983 https://shitposter.club/user/4983 https://shitposter.club/users/gay -4988 https://shitposter.club/user/4988 https://shitposter.club/users/leny -5000 https://shitposter.club/user/5000 https://shitposter.club/users/mrmemetic -5002 https://shitposter.club/user/5002 https://shitposter.club/users/peggle -5381 https://shitposter.club/user/5381 https://shitposter.club/users/shpuld -5440 https://shitposter.club/user/5440 https://shitposter.club/users/diana -5461 https://shitposter.club/user/5461 https://shitposter.club/users/karkat -5462 https://shitposter.club/user/5462 https://shitposter.club/users/stagparty -5494 https://shitposter.club/user/5494 https://shitposter.club/users/davestrider -5495 https://shitposter.club/user/5495 https://shitposter.club/users/fursona -5524 https://shitposter.club/user/5524 https://shitposter.club/users/jerry -5618 https://shitposter.club/user/5618 https://shitposter.club/users/moonatwork -5640 https://shitposter.club/user/5640 https://shitposter.club/users/herberthreis -5660 https://shitposter.club/user/5660 https://shitposter.club/users/dg -5681 https://shitposter.club/user/5681 https://shitposter.club/users/wakarimasen -5693 https://shitposter.club/user/5693 https://shitposter.club/users/reposterclacke -5722 https://shitposter.club/user/5722 https://shitposter.club/users/moonoffsite -5774 https://shitposter.club/user/5774 https://shitposter.club/users/figuringshitout -5826 https://shitposter.club/user/5826 https://shitposter.club/users/hckr -5875 https://shitposter.club/user/5875 https://shitposter.club/users/zero -5905 https://shitposter.club/user/5905 https://shitposter.club/users/lawyerfortheguy -5921 https://shitposter.club/user/5921 https://shitposter.club/users/dimeforthedude -5922 https://shitposter.club/user/5922 https://shitposter.club/users/tiffany -5930 https://shitposter.club/user/5930 https://shitposter.club/users/rilut -5936 https://shitposter.club/user/5936 https://shitposter.club/users/rwdigest -5941 https://shitposter.club/user/5941 https://shitposter.club/users/voidexe -6002 https://shitposter.club/user/6002 https://shitposter.club/users/kaldonia -6030 https://shitposter.club/user/6030 https://shitposter.club/users/smokeyhills -6033 https://shitposter.club/user/6033 https://shitposter.club/users/pennyforthegoy -6053 https://shitposter.club/user/6053 https://shitposter.club/users/ninjabuttocks -6057 https://shitposter.club/user/6057 https://shitposter.club/users/mrmattimation -6076 https://shitposter.club/user/6076 https://shitposter.club/users/arachnidsgrip -6086 https://shitposter.club/user/6086 https://shitposter.club/users/bogs -6114 https://shitposter.club/user/6114 https://shitposter.club/users/homph -6143 https://shitposter.club/user/6143 https://shitposter.club/users/brassrod -6144 https://shitposter.club/user/6144 https://shitposter.club/users/abnoxio -6302 https://shitposter.club/user/6302 https://shitposter.club/users/hjkhan -6317 https://shitposter.club/user/6317 https://shitposter.club/users/tasmijn -6378 https://shitposter.club/user/6378 https://shitposter.club/users/cv -6394 https://shitposter.club/user/6394 https://shitposter.club/users/exceem -6531 https://shitposter.club/user/6531 https://shitposter.club/users/thot -6533 https://shitposter.club/user/6533 https://shitposter.club/users/zenburn -6534 https://shitposter.club/user/6534 https://shitposter.club/users/supermoon -6563 https://shitposter.club/user/6563 https://shitposter.club/users/lebronjames75 -6724 https://shitposter.club/user/6724 https://shitposter.club/users/dreya -6838 https://shitposter.club/user/6838 https://shitposter.club/users/blackhole -6840 https://shitposter.club/user/6840 https://shitposter.club/users/elgatoweebee -6908 https://shitposter.club/user/6908 https://shitposter.club/users/panzerklown -6960 https://shitposter.club/user/6960 https://shitposter.club/users/hitlertheanimation -7062 https://shitposter.club/user/7062 https://shitposter.club/users/lm9 -7063 https://shitposter.club/user/7063 https://shitposter.club/users/kbb -7064 https://shitposter.club/user/7064 https://shitposter.club/users/00 -7114 https://shitposter.club/user/7114 https://shitposter.club/users/sw0rn -7197 https://shitposter.club/user/7197 https://shitposter.club/users/skelepun -7204 https://shitposter.club/user/7204 https://shitposter.club/users/segata -7205 https://shitposter.club/user/7205 https://shitposter.club/users/niggerkiller6969 -7251 https://shitposter.club/user/7251 https://shitposter.club/users/kitredgrave -7261 https://shitposter.club/user/7261 https://shitposter.club/users/letters -7292 https://shitposter.club/user/7292 https://shitposter.club/users/goatholeonmy -7295 https://shitposter.club/user/7295 https://shitposter.club/users/varondus -7335 https://shitposter.club/user/7335 https://shitposter.club/users/arsaces -7339 https://shitposter.club/user/7339 https://shitposter.club/users/nixromina -7374 https://shitposter.club/user/7374 https://shitposter.club/users/vladdo -7436 https://shitposter.club/user/7436 https://shitposter.club/users/baery -7463 https://shitposter.club/user/7463 https://shitposter.club/users/bigdikk -7543 https://shitposter.club/user/7543 https://shitposter.club/users/bijorikoraku -7573 https://shitposter.club/user/7573 https://shitposter.club/users/mithras -7602 https://shitposter.club/user/7602 https://shitposter.club/users/timiddimwit -7614 https://shitposter.club/user/7614 https://shitposter.club/users/thricebitten003 -7640 https://shitposter.club/user/7640 https://shitposter.club/users/floopfloop -7664 https://shitposter.club/user/7664 https://shitposter.club/users/otakunopico -7686 https://shitposter.club/user/7686 https://shitposter.club/users/fashygoy -7703 https://shitposter.club/user/7703 https://shitposter.club/users/anonymous -7710 https://shitposter.club/user/7710 https://shitposter.club/users/wewlad -7720 https://shitposter.club/user/7720 https://shitposter.club/users/textophile -7732 https://shitposter.club/user/7732 https://shitposter.club/users/vetforumwars -7748 https://shitposter.club/user/7748 https://shitposter.club/users/chikimonki -7751 https://shitposter.club/user/7751 https://shitposter.club/users/s3krit -7752 https://shitposter.club/user/7752 https://shitposter.club/users/valka -7753 https://shitposter.club/user/7753 https://shitposter.club/users/notksj -7775 https://shitposter.club/user/7775 https://shitposter.club/users/femacampinmate -7777 https://shitposter.club/user/7777 https://shitposter.club/users/redbayp -7809 https://shitposter.club/user/7809 https://shitposter.club/users/wayy -7826 https://shitposter.club/user/7826 https://shitposter.club/users/eliotime3000 -8015 https://shitposter.club/user/8015 https://shitposter.club/users/beingham -8031 https://shitposter.club/user/8031 https://shitposter.club/users/cyberpotato -8058 https://shitposter.club/user/8058 https://shitposter.club/users/efina -8059 https://shitposter.club/user/8059 https://shitposter.club/users/milla -8060 https://shitposter.club/user/8060 https://shitposter.club/users/caden -8061 https://shitposter.club/user/8061 https://shitposter.club/users/tiz -8072 https://shitposter.club/user/8072 https://shitposter.club/users/mikemazzone -8079 https://shitposter.club/user/8079 https://shitposter.club/users/fraudexposer -8081 https://shitposter.club/user/8081 https://shitposter.club/users/redair -8084 https://shitposter.club/user/8084 https://shitposter.club/users/jmd -8093 https://shitposter.club/user/8093 https://shitposter.club/users/linkwood -8094 https://shitposter.club/user/8094 https://shitposter.club/users/stefan -8095 https://shitposter.club/user/8095 https://shitposter.club/users/perionic -8096 https://shitposter.club/user/8096 https://shitposter.club/users/retronet -8157 https://shitposter.club/user/8157 https://shitposter.club/users/culto -8181 https://shitposter.club/user/8181 https://shitposter.club/users/extrange -8194 https://shitposter.club/user/8194 https://shitposter.club/users/daniel197047 -8220 https://shitposter.club/user/8220 https://shitposter.club/users/schnapps -8227 https://shitposter.club/user/8227 https://shitposter.club/users/anonavenger -8256 https://shitposter.club/user/8256 https://shitposter.club/users/mikaela -8261 https://shitposter.club/user/8261 https://shitposter.club/users/loki -8330 https://shitposter.club/user/8330 https://shitposter.club/users/sloan -8337 https://shitposter.club/user/8337 https://shitposter.club/users/thehifman -8363 https://shitposter.club/user/8363 https://shitposter.club/users/threetoast -8410 https://shitposter.club/user/8410 https://shitposter.club/users/daphailwhale -8429 https://shitposter.club/user/8429 https://shitposter.club/users/jakob -8430 https://shitposter.club/user/8430 https://shitposter.club/users/stephenlynx -8433 https://shitposter.club/user/8433 https://shitposter.club/users/ayoholup -8463 https://shitposter.club/user/8463 https://shitposter.club/users/loltemp -8622 https://shitposter.club/user/8622 https://shitposter.club/users/chu -8635 https://shitposter.club/user/8635 https://shitposter.club/users/bilb -8639 https://shitposter.club/user/8639 https://shitposter.club/users/www -8644 https://shitposter.club/user/8644 https://shitposter.club/users/potus -8676 https://shitposter.club/user/8676 https://shitposter.club/users/testuser124578 -8716 https://shitposter.club/user/8716 https://shitposter.club/users/kentnelida -8853 https://shitposter.club/user/8853 https://shitposter.club/users/meff -8876 https://shitposter.club/user/8876 https://shitposter.club/users/liz -8896 https://shitposter.club/user/8896 https://shitposter.club/users/anonjustice -8974 https://shitposter.club/user/8974 https://shitposter.club/users/wintertsar -9052 https://shitposter.club/user/9052 https://shitposter.club/users/nerthos -9056 https://shitposter.club/user/9056 https://shitposter.club/users/mono -9089 https://shitposter.club/user/9089 https://shitposter.club/users/taeateh -9119 https://shitposter.club/user/9119 https://shitposter.club/users/twilly999 -9140 https://shitposter.club/user/9140 https://shitposter.club/users/poorlyreported -9157 https://shitposter.club/user/9157 https://shitposter.club/users/karabiner -9164 https://shitposter.club/user/9164 https://shitposter.club/users/spaceman -9176 https://shitposter.club/user/9176 https://shitposter.club/users/dbrz -9196 https://shitposter.club/user/9196 https://shitposter.club/users/meesa -9203 https://shitposter.club/user/9203 https://shitposter.club/users/tokage -9205 https://shitposter.club/user/9205 https://shitposter.club/users/adolfhitler -9223 https://shitposter.club/user/9223 https://shitposter.club/users/homotopy -9283 https://shitposter.club/user/9283 https://shitposter.club/users/alanman -9294 https://shitposter.club/user/9294 https://shitposter.club/users/posteur -9301 https://shitposter.club/user/9301 https://shitposter.club/users/mchnem -9329 https://shitposter.club/user/9329 https://shitposter.club/users/mm -9347 https://shitposter.club/user/9347 https://shitposter.club/users/caspermag -9348 https://shitposter.club/user/9348 https://shitposter.club/users/weimerica -9396 https://shitposter.club/user/9396 https://shitposter.club/users/fl1nt -9487 https://shitposter.club/user/9487 https://shitposter.club/users/heterowhiteman -9499 https://shitposter.club/user/9499 https://shitposter.club/users/bane -9521 https://shitposter.club/user/9521 https://shitposter.club/users/luke -9522 https://shitposter.club/user/9522 https://shitposter.club/users/friendlysmoker -9563 https://shitposter.club/user/9563 https://shitposter.club/users/momo -9565 https://shitposter.club/user/9565 https://shitposter.club/users/c1tyoffl1nt1 -9567 https://shitposter.club/user/9567 https://shitposter.club/users/takao -9568 https://shitposter.club/user/9568 https://shitposter.club/users/sim -9569 https://shitposter.club/user/9569 https://shitposter.club/users/sakuya -9572 https://shitposter.club/user/9572 https://shitposter.club/users/chiruno -9573 https://shitposter.club/user/9573 https://shitposter.club/users/usercorpse -9574 https://shitposter.club/user/9574 https://shitposter.club/users/yeetniqqa -9585 https://shitposter.club/user/9585 https://shitposter.club/users/subvert -9591 https://shitposter.club/user/9591 https://shitposter.club/users/hardbass2k8 -9620 https://shitposter.club/user/9620 https://shitposter.club/users/secretsquirrel -9654 https://shitposter.club/user/9654 https://shitposter.club/users/spacemandown -9655 https://shitposter.club/user/9655 https://shitposter.club/users/neimzr4luzerz -9664 https://shitposter.club/user/9664 https://shitposter.club/users/moontest -9695 https://shitposter.club/user/9695 https://shitposter.club/users/azurerose -9701 https://shitposter.club/user/9701 https://shitposter.club/users/leroilezard -9776 https://shitposter.club/user/9776 https://shitposter.club/users/awgeezrick -9879 https://shitposter.club/user/9879 https://shitposter.club/users/terezi -9885 https://shitposter.club/user/9885 https://shitposter.club/users/johnhenry -9968 https://shitposter.club/user/9968 https://shitposter.club/users/barf -10098 https://shitposter.club/user/10098 https://shitposter.club/users/mantis -10166 https://shitposter.club/user/10166 https://shitposter.club/users/anon -10260 https://shitposter.club/user/10260 https://shitposter.club/users/sonya -10394 https://shitposter.club/user/10394 https://shitposter.club/users/sarahjeong -10660 https://shitposter.club/user/10660 https://shitposter.club/users/kkitteh -10672 https://shitposter.club/user/10672 https://shitposter.club/users/data -10832 https://shitposter.club/user/10832 https://shitposter.club/users/marin -10963 https://shitposter.club/user/10963 https://shitposter.club/users/anthony -10986 https://shitposter.club/user/10986 https://shitposter.club/users/ashdroid -11068 https://shitposter.club/user/11068 https://shitposter.club/users/yair -11231 https://shitposter.club/user/11231 https://shitposter.club/users/dean -11262 https://shitposter.club/user/11262 https://shitposter.club/users/santiesteban -11401 https://shitposter.club/user/11401 https://shitposter.club/users/hughdarrow -11514 https://shitposter.club/user/11514 https://shitposter.club/users/mil -11604 https://shitposter.club/user/11604 https://shitposter.club/users/anime -11663 https://shitposter.club/user/11663 https://shitposter.club/users/jakk -11747 https://shitposter.club/user/11747 https://shitposter.club/users/buffyfan12 -11865 https://shitposter.club/user/11865 https://shitposter.club/users/thx2037 -11960 https://shitposter.club/user/11960 https://shitposter.club/users/gargron -12000 https://shitposter.club/user/12000 https://shitposter.club/users/chc4 -12046 https://shitposter.club/user/12046 https://shitposter.club/users/sergio -12115 https://shitposter.club/user/12115 https://shitposter.club/users/gooddoge -12235 https://shitposter.club/user/12235 https://shitposter.club/users/moonrise -12367 https://shitposter.club/user/12367 https://shitposter.club/users/0xdeadbabe -12519 https://shitposter.club/user/12519 https://shitposter.club/users/jesusaur -12577 https://shitposter.club/user/12577 https://shitposter.club/users/vpsorg -12693 https://shitposter.club/user/12693 https://shitposter.club/users/gnulibs -12695 https://shitposter.club/user/12695 https://shitposter.club/users/hydra -12699 https://shitposter.club/user/12699 https://shitposter.club/users/thegoldwater -12725 https://shitposter.club/user/12725 https://shitposter.club/users/pox -12820 https://shitposter.club/user/12820 https://shitposter.club/users/charafan -12822 https://shitposter.club/user/12822 https://shitposter.club/users/fly -12826 https://shitposter.club/user/12826 https://shitposter.club/users/jay -13068 https://shitposter.club/user/13068 https://shitposter.club/users/wannabe -13442 https://shitposter.club/user/13442 https://shitposter.club/users/twitter -13476 https://shitposter.club/user/13476 https://shitposter.club/users/huefee -13590 https://shitposter.club/user/13590 https://shitposter.club/users/d3wd -13712 https://shitposter.club/user/13712 https://shitposter.club/users/sacfly -13905 https://shitposter.club/user/13905 https://shitposter.club/users/athrygg -14115 https://shitposter.club/user/14115 https://shitposter.club/users/wolf -14145 https://shitposter.club/user/14145 https://shitposter.club/users/random -14158 https://shitposter.club/user/14158 https://shitposter.club/users/dm -14217 https://shitposter.club/user/14217 https://shitposter.club/users/okux -14533 https://shitposter.club/user/14533 https://shitposter.club/users/zeno -14612 https://shitposter.club/user/14612 https://shitposter.club/users/jk -14638 https://shitposter.club/user/14638 https://shitposter.club/users/grindecologist -14767 https://shitposter.club/user/14767 https://shitposter.club/users/skullum -14903 https://shitposter.club/user/14903 https://shitposter.club/users/tomey -14972 https://shitposter.club/user/14972 https://shitposter.club/users/uramekus -15044 https://shitposter.club/user/15044 https://shitposter.club/users/harlan -15118 https://shitposter.club/user/15118 https://shitposter.club/users/arash -15236 https://shitposter.club/user/15236 https://shitposter.club/users/coreilly -15371 https://shitposter.club/user/15371 https://shitposter.club/users/thisisnotanime -15416 https://shitposter.club/user/15416 https://shitposter.club/users/cg -15439 https://shitposter.club/user/15439 https://shitposter.club/users/wareya -15496 https://shitposter.club/user/15496 https://shitposter.club/users/auraninanettaadriana -15557 https://shitposter.club/user/15557 https://shitposter.club/users/dechi -15575 https://shitposter.club/user/15575 https://shitposter.club/users/vikohmeilaty -15578 https://shitposter.club/user/15578 https://shitposter.club/users/vikohsevmarmila -15581 https://shitposter.club/user/15581 https://shitposter.club/users/vikohalvianti -15587 https://shitposter.club/user/15587 https://shitposter.club/users/patriciamichelletangkangentot -15635 https://shitposter.club/user/15635 https://shitposter.club/users/novichok -16492 https://shitposter.club/user/16492 https://shitposter.club/users/oosh -16752 https://shitposter.club/user/16752 https://shitposter.club/users/floraplus -17083 https://shitposter.club/user/17083 https://shitposter.club/users/popeyethecunt -17319 https://shitposter.club/user/17319 https://shitposter.club/users/dctf -17581 https://shitposter.club/user/17581 https://shitposter.club/users/chriztheanvill -18540 https://shitposter.club/user/18540 https://shitposter.club/users/sabahsyria -18716 https://shitposter.club/user/18716 https://shitposter.club/users/dumbbabby -18855 https://shitposter.club/user/18855 https://shitposter.club/users/derpderpderp -19068 https://shitposter.club/user/19068 https://shitposter.club/users/ster -19095 https://shitposter.club/user/19095 https://shitposter.club/users/cajoh -19124 https://shitposter.club/user/19124 https://shitposter.club/users/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -19257 https://shitposter.club/user/19257 https://shitposter.club/users/friskan -19285 https://shitposter.club/user/19285 https://shitposter.club/users/zeo -19593 https://shitposter.club/user/19593 https://shitposter.club/users/akater -19649 https://shitposter.club/user/19649 https://shitposter.club/users/wololo -20046 https://shitposter.club/user/20046 https://shitposter.club/users/fujimura -20073 https://shitposter.club/user/20073 https://shitposter.club/users/jakethesnake -20267 https://shitposter.club/user/20267 https://shitposter.club/users/moontest2 -20426 https://shitposter.club/user/20426 https://shitposter.club/users/perspicacious01 -20651 https://shitposter.club/user/20651 https://shitposter.club/users/trivia -20686 https://shitposter.club/user/20686 https://shitposter.club/users/yovinnie -20759 https://shitposter.club/user/20759 https://shitposter.club/users/roytam -21026 https://shitposter.club/user/21026 https://shitposter.club/users/shakes31471 -21667 https://shitposter.club/user/21667 https://shitposter.club/users/bdjnk -21787 https://shitposter.club/user/21787 https://shitposter.club/users/cutscenes -21920 https://shitposter.club/user/21920 https://shitposter.club/users/rwdsaboo -21925 https://shitposter.club/user/21925 https://shitposter.club/users/mapomme -21934 https://shitposter.club/user/21934 https://shitposter.club/users/satori -22018 https://shitposter.club/user/22018 https://shitposter.club/users/vertu -22080 https://shitposter.club/user/22080 https://shitposter.club/users/raven -22177 https://shitposter.club/user/22177 https://shitposter.club/users/boa -22179 https://shitposter.club/user/22179 https://shitposter.club/users/tezcat -22230 https://shitposter.club/user/22230 https://shitposter.club/users/alex -22323 https://shitposter.club/user/22323 https://shitposter.club/users/tehsvin -22514 https://shitposter.club/user/22514 https://shitposter.club/users/shitehoney -22564 https://shitposter.club/user/22564 https://shitposter.club/users/becauseimgray -22706 https://shitposter.club/user/22706 https://shitposter.club/users/nimda -22883 https://shitposter.club/user/22883 https://shitposter.club/users/noflashfirm -22917 https://shitposter.club/user/22917 https://shitposter.club/users/silvertube -23288 https://shitposter.club/user/23288 https://shitposter.club/users/monad -23396 https://shitposter.club/user/23396 https://shitposter.club/users/mom -23576 https://shitposter.club/user/23576 https://shitposter.club/users/ntc -23735 https://shitposter.club/user/23735 https://shitposter.club/users/betobear730 -23872 https://shitposter.club/user/23872 https://shitposter.club/users/mackatron -23909 https://shitposter.club/user/23909 https://shitposter.club/users/johnnycumby -24048 https://shitposter.club/user/24048 https://shitposter.club/users/buttballoon -24247 https://shitposter.club/user/24247 https://shitposter.club/users/hoppeoffamychoppa -24370 https://shitposter.club/user/24370 https://shitposter.club/users/superjey -24519 https://shitposter.club/user/24519 https://shitposter.club/users/crufro -24550 https://shitposter.club/user/24550 https://shitposter.club/users/baseddrworm -24794 https://shitposter.club/user/24794 https://shitposter.club/users/marko -24893 https://shitposter.club/user/24893 https://shitposter.club/users/sweetnote -25222 https://shitposter.club/user/25222 https://shitposter.club/users/stiribune -25519 https://shitposter.club/user/25519 https://shitposter.club/users/taco -25726 https://shitposter.club/user/25726 https://shitposter.club/users/morbius -26103 https://shitposter.club/user/26103 https://shitposter.club/users/moonmanatgscon -26486 https://shitposter.club/user/26486 https://shitposter.club/users/lon -26603 https://shitposter.club/user/26603 https://shitposter.club/users/cj -26712 https://shitposter.club/user/26712 https://shitposter.club/users/existentialbro -26830 https://shitposter.club/user/26830 https://shitposter.club/users/weddingtorontolimo -26858 https://shitposter.club/user/26858 https://shitposter.club/users/hoskayne -27459 https://shitposter.club/user/27459 https://shitposter.club/users/dirb -27464 https://shitposter.club/user/27464 https://shitposter.club/users/assalchemy -27628 https://shitposter.club/user/27628 https://shitposter.club/users/walt1999walt -28122 https://shitposter.club/user/28122 https://shitposter.club/users/h8 -28526 https://shitposter.club/user/28526 https://shitposter.club/users/mariano -28601 https://shitposter.club/user/28601 https://shitposter.club/users/robofortune -28795 https://shitposter.club/user/28795 https://shitposter.club/users/falco -28892 https://shitposter.club/user/28892 https://shitposter.club/users/batemanboogers -28985 https://shitposter.club/user/28985 https://shitposter.club/users/pasty -28989 https://shitposter.club/user/28989 https://shitposter.club/users/podrickpaddington -29181 https://shitposter.club/user/29181 https://shitposter.club/users/ganix -29182 https://shitposter.club/user/29182 https://shitposter.club/users/marsprobe -29185 https://shitposter.club/user/29185 https://shitposter.club/users/tealdear -29251 https://shitposter.club/user/29251 https://shitposter.club/users/tico -29686 https://shitposter.club/user/29686 https://shitposter.club/users/pooryorick -29708 https://shitposter.club/user/29708 https://shitposter.club/users/vfp -29825 https://shitposter.club/user/29825 https://shitposter.club/users/camby -29856 https://shitposter.club/user/29856 https://shitposter.club/users/aqours -29857 https://shitposter.club/user/29857 https://shitposter.club/users/gaygrandma -29858 https://shitposter.club/user/29858 https://shitposter.club/users/zarya -29859 https://shitposter.club/user/29859 https://shitposter.club/users/ene -29969 https://shitposter.club/user/29969 https://shitposter.club/users/aw -30066 https://shitposter.club/user/30066 https://shitposter.club/users/oxenfree -30080 https://shitposter.club/user/30080 https://shitposter.club/users/roko -30202 https://shitposter.club/user/30202 https://shitposter.club/users/doingsomeposts -30241 https://shitposter.club/user/30241 https://shitposter.club/users/archaeme -30243 https://shitposter.club/user/30243 https://shitposter.club/users/zenpukku -30293 https://shitposter.club/user/30293 https://shitposter.club/users/styromaniac -30720 https://shitposter.club/user/30720 https://shitposter.club/users/thatbrickster -30748 https://shitposter.club/user/30748 https://shitposter.club/users/ryan -31040 https://shitposter.club/user/31040 https://shitposter.club/users/me -31101 https://shitposter.club/user/31101 https://shitposter.club/users/louiefillet -31132 https://shitposter.club/user/31132 https://shitposter.club/users/ok -31339 https://shitposter.club/user/31339 https://shitposter.club/users/alucard -31353 https://shitposter.club/user/31353 https://shitposter.club/users/spcnepfag -31536 https://shitposter.club/user/31536 https://shitposter.club/users/dmgctrl -31538 https://shitposter.club/user/31538 https://shitposter.club/users/lueyee -31714 https://shitposter.club/user/31714 https://shitposter.club/users/comstock -31832 https://shitposter.club/user/31832 https://shitposter.club/users/anotherwriter -31836 https://shitposter.club/user/31836 https://shitposter.club/users/luminous -31876 https://shitposter.club/user/31876 https://shitposter.club/users/toxic -31892 https://shitposter.club/user/31892 https://shitposter.club/users/soulkisser -31923 https://shitposter.club/user/31923 https://shitposter.club/users/piyush -31959 https://shitposter.club/user/31959 https://shitposter.club/users/lightlysalted -31973 https://shitposter.club/user/31973 https://shitposter.club/users/abr21 -31997 https://shitposter.club/user/31997 https://shitposter.club/users/demo -32079 https://shitposter.club/user/32079 https://shitposter.club/users/totallynotdogjaw -32123 https://shitposter.club/user/32123 https://shitposter.club/users/ctrlcreepbot -32158 https://shitposter.club/user/32158 https://shitposter.club/users/ben666 -32188 https://shitposter.club/user/32188 https://shitposter.club/users/polenstronkest -32201 https://shitposter.club/user/32201 https://shitposter.club/users/filthymcgarbage -32314 https://shitposter.club/user/32314 https://shitposter.club/users/notjeff -32324 https://shitposter.club/user/32324 https://shitposter.club/users/tanteifaust -32326 https://shitposter.club/user/32326 https://shitposter.club/users/vimtingu -32329 https://shitposter.club/user/32329 https://shitposter.club/users/dolus -32343 https://shitposter.club/user/32343 https://shitposter.club/users/sonicdreadzhog -32383 https://shitposter.club/user/32383 https://shitposter.club/users/nignog -32386 https://shitposter.club/user/32386 https://shitposter.club/users/owl -32390 https://shitposter.club/user/32390 https://shitposter.club/users/yoroshiku -32444 https://shitposter.club/user/32444 https://shitposter.club/users/chelzgrimace0 -32460 https://shitposter.club/user/32460 https://shitposter.club/users/mei -32466 https://shitposter.club/user/32466 https://shitposter.club/users/demigodloligagger -32690 https://shitposter.club/user/32690 https://shitposter.club/users/camoceltic -32736 https://shitposter.club/user/32736 https://shitposter.club/users/flamingkazin -33044 https://shitposter.club/user/33044 https://shitposter.club/users/root -33191 https://shitposter.club/user/33191 https://shitposter.club/users/949f45ac -33422 https://shitposter.club/user/33422 https://shitposter.club/users/surge -33683 https://shitposter.club/user/33683 https://shitposter.club/users/dielan -33789 https://shitposter.club/user/33789 https://shitposter.club/users/fickle -34011 https://shitposter.club/user/34011 https://shitposter.club/users/nurnymurse -34442 https://shitposter.club/user/34442 https://shitposter.club/users/ragecage -34659 https://shitposter.club/user/34659 https://shitposter.club/users/fuckinghackers -35102 https://shitposter.club/user/35102 https://shitposter.club/users/robotx -35167 https://shitposter.club/user/35167 https://shitposter.club/users/sojourner -35180 https://shitposter.club/user/35180 https://shitposter.club/users/dogjaw -35198 https://shitposter.club/user/35198 https://shitposter.club/users/radicooloperative -35340 https://shitposter.club/user/35340 https://shitposter.club/users/sn -35402 https://shitposter.club/user/35402 https://shitposter.club/users/demifiend -35510 https://shitposter.club/user/35510 https://shitposter.club/users/tempo -35623 https://shitposter.club/user/35623 https://shitposter.club/users/lphovercraft -35631 https://shitposter.club/user/35631 https://shitposter.club/users/realhitler -35775 https://shitposter.club/user/35775 https://shitposter.club/users/kian -35930 https://shitposter.club/user/35930 https://shitposter.club/users/jjcarter21r -36077 https://shitposter.club/user/36077 https://shitposter.club/users/wehateweebs -36115 https://shitposter.club/user/36115 https://shitposter.club/users/theplaguedr -36172 https://shitposter.club/user/36172 https://shitposter.club/users/surfinbird -36381 https://shitposter.club/user/36381 https://shitposter.club/users/sireebob -36384 https://shitposter.club/user/36384 https://shitposter.club/users/127001 -36717 https://shitposter.club/user/36717 https://shitposter.club/users/justaghost -36821 https://shitposter.club/user/36821 https://shitposter.club/users/shadow -36888 https://shitposter.club/user/36888 https://shitposter.club/users/moe -37046 https://shitposter.club/user/37046 https://shitposter.club/users/moe123 -37300 https://shitposter.club/user/37300 https://shitposter.club/users/lulinvega -37326 https://shitposter.club/user/37326 https://shitposter.club/users/haisenberg -37954 https://shitposter.club/user/37954 https://shitposter.club/users/kg -38017 https://shitposter.club/user/38017 https://shitposter.club/users/yvvu2 -38219 https://shitposter.club/user/38219 https://shitposter.club/users/spooks -38322 https://shitposter.club/user/38322 https://shitposter.club/users/invlpg -38364 https://shitposter.club/user/38364 https://shitposter.club/users/krochpuncher -38382 https://shitposter.club/user/38382 https://shitposter.club/users/artifaxxs -38482 https://shitposter.club/user/38482 https://shitposter.club/users/windclock -38491 https://shitposter.club/user/38491 https://shitposter.club/users/lobster -38618 https://shitposter.club/user/38618 https://shitposter.club/users/birdway -38733 https://shitposter.club/user/38733 https://shitposter.club/users/sulter -38796 https://shitposter.club/user/38796 https://shitposter.club/users/zika -38979 https://shitposter.club/user/38979 https://shitposter.club/users/manghoti -39546 https://shitposter.club/user/39546 https://shitposter.club/users/zlowiec -40673 https://shitposter.club/user/40673 https://shitposter.club/users/aaa -41496 https://shitposter.club/user/41496 https://shitposter.club/users/polywuf -41717 https://shitposter.club/user/41717 https://shitposter.club/users/shirtlords -41735 https://shitposter.club/user/41735 https://shitposter.club/users/vced01tbkrcy -41780 https://shitposter.club/user/41780 https://shitposter.club/users/reggiehathaway -41786 https://shitposter.club/user/41786 https://shitposter.club/users/parisc -41794 https://shitposter.club/user/41794 https://shitposter.club/users/nutjin -41801 https://shitposter.club/user/41801 https://shitposter.club/users/angelus -41836 https://shitposter.club/user/41836 https://shitposter.club/users/big -41985 https://shitposter.club/user/41985 https://shitposter.club/users/wario -42081 https://shitposter.club/user/42081 https://shitposter.club/users/animesniffer -42098 https://shitposter.club/user/42098 https://shitposter.club/users/yappariesaka -42115 https://shitposter.club/user/42115 https://shitposter.club/users/stjude -42120 https://shitposter.club/user/42120 https://shitposter.club/users/gaiusgermanicus -42260 https://shitposter.club/user/42260 https://shitposter.club/users/loveliestamie -42347 https://shitposter.club/user/42347 https://shitposter.club/users/ginz -42354 https://shitposter.club/user/42354 https://shitposter.club/users/antiracist -42363 https://shitposter.club/user/42363 https://shitposter.club/users/matthewmaci -42472 https://shitposter.club/user/42472 https://shitposter.club/users/rubberback -42927 https://shitposter.club/user/42927 https://shitposter.club/users/hatexgroup -42968 https://shitposter.club/user/42968 https://shitposter.club/users/gloriouscarwash -42997 https://shitposter.club/user/42997 https://shitposter.club/users/yayo -43012 https://shitposter.club/user/43012 https://shitposter.club/users/robloxhentie88 -43092 https://shitposter.club/user/43092 https://shitposter.club/users/haspop -43167 https://shitposter.club/user/43167 https://shitposter.club/users/walmartsupremacy -43268 https://shitposter.club/user/43268 https://shitposter.club/users/golpollo -43272 https://shitposter.club/user/43272 https://shitposter.club/users/rrx -43276 https://shitposter.club/user/43276 https://shitposter.club/users/rusty -43336 https://shitposter.club/user/43336 https://shitposter.club/users/caesarcrab -43384 https://shitposter.club/user/43384 https://shitposter.club/users/yap -43440 https://shitposter.club/user/43440 https://shitposter.club/users/triplekmafia -43443 https://shitposter.club/user/43443 https://shitposter.club/users/antonnizhny -43583 https://shitposter.club/user/43583 https://shitposter.club/users/cajon -43744 https://shitposter.club/user/43744 https://shitposter.club/users/dixieconstruct -43764 https://shitposter.club/user/43764 https://shitposter.club/users/pepsicanex -43776 https://shitposter.club/user/43776 https://shitposter.club/users/deraristokraut -43779 https://shitposter.club/user/43779 https://shitposter.club/users/red -43783 https://shitposter.club/user/43783 https://shitposter.club/users/boxiekun -43791 https://shitposter.club/user/43791 https://shitposter.club/users/emilia -43866 https://shitposter.club/user/43866 https://shitposter.club/users/qwerty -44035 https://shitposter.club/user/44035 https://shitposter.club/users/aspirator -44303 https://shitposter.club/user/44303 https://shitposter.club/users/cereal -44541 https://shitposter.club/user/44541 https://shitposter.club/users/animerapist -44666 https://shitposter.club/user/44666 https://shitposter.club/users/za -44681 https://shitposter.club/user/44681 https://shitposter.club/users/suicidal -44751 https://shitposter.club/user/44751 https://shitposter.club/users/illuminatoskeletono -45219 https://shitposter.club/user/45219 https://shitposter.club/users/sierrakilobravo -45312 https://shitposter.club/user/45312 https://shitposter.club/users/thufir -45467 https://shitposter.club/user/45467 https://shitposter.club/users/fermtnzheavy -45873 https://shitposter.club/user/45873 https://shitposter.club/users/jector -46020 https://shitposter.club/user/46020 https://shitposter.club/users/shitlordsupreme -46273 https://shitposter.club/user/46273 https://shitposter.club/users/y88 -46347 https://shitposter.club/user/46347 https://shitposter.club/users/catk111er -46752 https://shitposter.club/user/46752 https://shitposter.club/users/pr333 -46808 https://shitposter.club/user/46808 https://shitposter.club/users/catkittens -47284 https://shitposter.club/user/47284 https://shitposter.club/users/123lareputarana -47359 https://shitposter.club/user/47359 https://shitposter.club/users/traplordegen -47368 https://shitposter.club/user/47368 https://shitposter.club/users/norm -47569 https://shitposter.club/user/47569 https://shitposter.club/users/grass -47770 https://shitposter.club/user/47770 https://shitposter.club/users/realdavidreed -47943 https://shitposter.club/user/47943 https://shitposter.club/users/watch -48103 https://shitposter.club/user/48103 https://shitposter.club/users/bagel -48130 https://shitposter.club/user/48130 https://shitposter.club/users/stochastix -48329 https://shitposter.club/user/48329 https://shitposter.club/users/mewlan -48389 https://shitposter.club/user/48389 https://shitposter.club/users/andilinks -48440 https://shitposter.club/user/48440 https://shitposter.club/users/ao -48495 https://shitposter.club/user/48495 https://shitposter.club/users/futuredogefm -48496 https://shitposter.club/user/48496 https://shitposter.club/users/harold -48611 https://shitposter.club/user/48611 https://shitposter.club/users/hattiecat -48712 https://shitposter.club/user/48712 https://shitposter.club/users/mrmcmayhem -49233 https://shitposter.club/user/49233 https://shitposter.club/users/sushipantsu -49746 https://shitposter.club/user/49746 https://shitposter.club/users/siedge -49752 https://shitposter.club/user/49752 https://shitposter.club/users/honorrollcc -49829 https://shitposter.club/user/49829 https://shitposter.club/users/denza252 -49856 https://shitposter.club/user/49856 https://shitposter.club/users/web -49863 https://shitposter.club/user/49863 https://shitposter.club/users/donglord -49933 https://shitposter.club/user/49933 https://shitposter.club/users/chargedaffaires -50092 https://shitposter.club/user/50092 https://shitposter.club/users/joy -50183 https://shitposter.club/user/50183 https://shitposter.club/users/gravityfailsme -50216 https://shitposter.club/user/50216 https://shitposter.club/users/installgen2 -50331 https://shitposter.club/user/50331 https://shitposter.club/users/robbie -50332 https://shitposter.club/user/50332 https://shitposter.club/users/xirus11 -50339 https://shitposter.club/user/50339 https://shitposter.club/users/glendo -50340 https://shitposter.club/user/50340 https://shitposter.club/users/minus2 -51031 https://shitposter.club/user/51031 https://shitposter.club/users/kekmeister -51033 https://shitposter.club/user/51033 https://shitposter.club/users/akitosenshi -51037 https://shitposter.club/user/51037 https://shitposter.club/users/ganjabots -51337 https://shitposter.club/user/51337 https://shitposter.club/users/sadanimeman -51693 https://shitposter.club/user/51693 https://shitposter.club/users/iamfubar -51699 https://shitposter.club/user/51699 https://shitposter.club/users/honk -51732 https://shitposter.club/user/51732 https://shitposter.club/users/trash -51733 https://shitposter.club/user/51733 https://shitposter.club/users/normsndy -51827 https://shitposter.club/user/51827 https://shitposter.club/users/zeppy -52063 https://shitposter.club/user/52063 https://shitposter.club/users/anomaleon -52122 https://shitposter.club/user/52122 https://shitposter.club/users/huh -52172 https://shitposter.club/user/52172 https://shitposter.club/users/erzaknightfr -52276 https://shitposter.club/user/52276 https://shitposter.club/users/antasmeme -52457 https://shitposter.club/user/52457 https://shitposter.club/users/girl -52906 https://shitposter.club/user/52906 https://shitposter.club/users/threaddotrun -53474 https://shitposter.club/user/53474 https://shitposter.club/users/starz0r -53716 https://shitposter.club/user/53716 https://shitposter.club/users/yoyo -53967 https://shitposter.club/user/53967 https://shitposter.club/users/sebas -54382 https://shitposter.club/user/54382 https://shitposter.club/users/thndr -54503 https://shitposter.club/user/54503 https://shitposter.club/users/xenonman -54700 https://shitposter.club/user/54700 https://shitposter.club/users/crewofweebs -54831 https://shitposter.club/user/54831 https://shitposter.club/users/gutfuckllc -54859 https://shitposter.club/user/54859 https://shitposter.club/users/zeptat -54860 https://shitposter.club/user/54860 https://shitposter.club/users/zeptar -54876 https://shitposter.club/user/54876 https://shitposter.club/users/vf -55355 https://shitposter.club/user/55355 https://shitposter.club/users/arilando -55371 https://shitposter.club/user/55371 https://shitposter.club/users/deanberryministry -55616 https://shitposter.club/user/55616 https://shitposter.club/users/fatma -55866 https://shitposter.club/user/55866 https://shitposter.club/users/rice -56213 https://shitposter.club/user/56213 https://shitposter.club/users/atdirb -56789 https://shitposter.club/user/56789 https://shitposter.club/users/elshibes -57573 https://shitposter.club/user/57573 https://shitposter.club/users/cyberfreedom -57627 https://shitposter.club/user/57627 https://shitposter.club/users/asdf -57700 https://shitposter.club/user/57700 https://shitposter.club/users/awl -57958 https://shitposter.club/user/57958 https://shitposter.club/users/shitlord -58248 https://shitposter.club/user/58248 https://shitposter.club/users/johnnyneptune -58348 https://shitposter.club/user/58348 https://shitposter.club/users/littleman -58755 https://shitposter.club/user/58755 https://shitposter.club/users/loke -58802 https://shitposter.club/user/58802 https://shitposter.club/users/mysize69 -58859 https://shitposter.club/user/58859 https://shitposter.club/users/crablettes -58862 https://shitposter.club/user/58862 https://shitposter.club/users/fleshlightme -59088 https://shitposter.club/user/59088 https://shitposter.club/users/2rude -59930 https://shitposter.club/user/59930 https://shitposter.club/users/gonk -59955 https://shitposter.club/user/59955 https://shitposter.club/users/squidink -60066 https://shitposter.club/user/60066 https://shitposter.club/users/llxyo -60185 https://shitposter.club/user/60185 https://shitposter.club/users/scrawls -60544 https://shitposter.club/user/60544 https://shitposter.club/users/sigma -60790 https://shitposter.club/user/60790 https://shitposter.club/users/therealkayne -60794 https://shitposter.club/user/60794 https://shitposter.club/users/nanex -61124 https://shitposter.club/user/61124 https://shitposter.club/users/ejs -61307 https://shitposter.club/user/61307 https://shitposter.club/users/skeet -61456 https://shitposter.club/user/61456 https://shitposter.club/users/agentorange -61646 https://shitposter.club/user/61646 https://shitposter.club/users/toad -61652 https://shitposter.club/user/61652 https://shitposter.club/users/kuuomena -61767 https://shitposter.club/user/61767 https://shitposter.club/users/coolboymew -61770 https://shitposter.club/user/61770 https://shitposter.club/users/4fl0wn -61782 https://shitposter.club/user/61782 https://shitposter.club/users/borzoi -61839 https://shitposter.club/user/61839 https://shitposter.club/users/chazcon -61923 https://shitposter.club/user/61923 https://shitposter.club/users/tharsis -62000 https://shitposter.club/user/62000 https://shitposter.club/users/redboooook -62134 https://shitposter.club/user/62134 https://shitposter.club/users/aven -62194 https://shitposter.club/user/62194 https://shitposter.club/users/haydenjones -64293 https://shitposter.club/user/64293 https://shitposter.club/users/yoongi -64357 https://shitposter.club/user/64357 https://shitposter.club/users/cow2001 -64605 https://shitposter.club/user/64605 https://shitposter.club/users/tidux -64672 https://shitposter.club/user/64672 https://shitposter.club/users/d4klutz -64681 https://shitposter.club/user/64681 https://shitposter.club/users/nucleasthete -64727 https://shitposter.club/user/64727 https://shitposter.club/users/hurley -64748 https://shitposter.club/user/64748 https://shitposter.club/users/drgutfuckllc -64759 https://shitposter.club/user/64759 https://shitposter.club/users/0x68756973 -64882 https://shitposter.club/user/64882 https://shitposter.club/users/night -65019 https://shitposter.club/user/65019 https://shitposter.club/users/macgirvin -65080 https://shitposter.club/user/65080 https://shitposter.club/users/jeremiah -65083 https://shitposter.club/user/65083 https://shitposter.club/users/lawlcat -65087 https://shitposter.club/user/65087 https://shitposter.club/users/trippinkitty420 -65330 https://shitposter.club/user/65330 https://shitposter.club/users/leibwiht -65350 https://shitposter.club/user/65350 https://shitposter.club/users/nagiept -65532 https://shitposter.club/user/65532 https://shitposter.club/users/corzetan -66560 https://shitposter.club/user/66560 https://shitposter.club/users/footkage -66562 https://shitposter.club/user/66562 https://shitposter.club/users/pdpineapple -66709 https://shitposter.club/user/66709 https://shitposter.club/users/nigger -66897 https://shitposter.club/user/66897 https://shitposter.club/users/djzep -67554 https://shitposter.club/user/67554 https://shitposter.club/users/linuxsocist -68329 https://shitposter.club/user/68329 https://shitposter.club/users/fris -68895 https://shitposter.club/user/68895 https://shitposter.club/users/nobodyeverywhere -69714 https://shitposter.club/user/69714 https://shitposter.club/users/3000iq -69906 https://shitposter.club/user/69906 https://shitposter.club/users/trustandsaftey -70237 https://shitposter.club/user/70237 https://shitposter.club/users/pd -70249 https://shitposter.club/user/70249 https://shitposter.club/users/markm447 -70798 https://shitposter.club/user/70798 https://shitposter.club/users/sleepfight3r -71463 https://shitposter.club/user/71463 https://shitposter.club/users/jello -71487 https://shitposter.club/user/71487 https://shitposter.club/users/canonicalbrud -71511 https://shitposter.club/user/71511 https://shitposter.club/users/tahu -71605 https://shitposter.club/user/71605 https://shitposter.club/users/noisepollution -71642 https://shitposter.club/user/71642 https://shitposter.club/users/nekolover -72807 https://shitposter.club/user/72807 https://shitposter.club/users/hiddengabber -72824 https://shitposter.club/user/72824 https://shitposter.club/users/oversaturation -72842 https://shitposter.club/user/72842 https://shitposter.club/users/uh -72864 https://shitposter.club/user/72864 https://shitposter.club/users/iajasom -73079 https://shitposter.club/user/73079 https://shitposter.club/users/thunder -73228 https://shitposter.club/user/73228 https://shitposter.club/users/makin -73386 https://shitposter.club/user/73386 https://shitposter.club/users/nevergofullweev -73642 https://shitposter.club/user/73642 https://shitposter.club/users/uxredbyte -73920 https://shitposter.club/user/73920 https://shitposter.club/users/billadoid -73987 https://shitposter.club/user/73987 https://shitposter.club/users/tuturu -74440 https://shitposter.club/user/74440 https://shitposter.club/users/pennyfortheguy -74699 https://shitposter.club/user/74699 https://shitposter.club/users/pururu -74818 https://shitposter.club/user/74818 https://shitposter.club/users/mikem -74940 https://shitposter.club/user/74940 https://shitposter.club/users/undeadmockingbird -75019 https://shitposter.club/user/75019 https://shitposter.club/users/spot -75051 https://shitposter.club/user/75051 https://shitposter.club/users/veruune -75147 https://shitposter.club/user/75147 https://shitposter.club/users/millysoose -75390 https://shitposter.club/user/75390 https://shitposter.club/users/onyxxgoodmann -75534 https://shitposter.club/user/75534 https://shitposter.club/users/voxumbra -75823 https://shitposter.club/user/75823 https://shitposter.club/users/kvazarig -75893 https://shitposter.club/user/75893 https://shitposter.club/users/cobodo -76045 https://shitposter.club/user/76045 https://shitposter.club/users/enkidoodle -76090 https://shitposter.club/user/76090 https://shitposter.club/users/judasdervierte -76309 https://shitposter.club/user/76309 https://shitposter.club/users/itsale -76353 https://shitposter.club/user/76353 https://shitposter.club/users/drump -76858 https://shitposter.club/user/76858 https://shitposter.club/users/gudgames -76890 https://shitposter.club/user/76890 https://shitposter.club/users/yomama -77082 https://shitposter.club/user/77082 https://shitposter.club/users/nowayinhell -78315 https://shitposter.club/user/78315 https://shitposter.club/users/zp -78737 https://shitposter.club/user/78737 https://shitposter.club/users/fr -79635 https://shitposter.club/user/79635 https://shitposter.club/users/fl0wnspc -81502 https://shitposter.club/user/81502 https://shitposter.club/users/tester2 -- cgit v1.2.3 From 7057891db649e1a72abfda13418d8c4bddd4ec92 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 31 Jan 2019 18:18:20 +0300 Subject: Make rich media support toggleable --- lib/pleroma/web/rich_media/helpers.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index 71fdddef9..44e876777 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -7,7 +7,8 @@ defmodule Pleroma.Web.RichMedia.Helpers do alias Pleroma.Web.RichMedia.Parser def fetch_data_for_activity(%Activity{} = activity) do - with %Object{} = object <- Object.normalize(activity.data["object"]), + with true <- Pleroma.Config.get([:rich_media, :enabled], true), + %Object{} = object <- Object.normalize(activity.data["object"]), {:ok, page_url} <- HTML.extract_first_external_url(object, object.data["content"]), {:ok, rich_media} <- Parser.parse(page_url) do %{page_url: page_url, rich_media: rich_media} -- cgit v1.2.3 From dafb6f0b5efac3997080f6b164dfb35515f31b24 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 31 Jan 2019 16:03:56 +0000 Subject: rich media: parser: reject OGP fields we cannot safely process --- lib/pleroma/web/rich_media/parser.ex | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index e67ecc47d..b33411cc7 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -30,7 +30,7 @@ defmodule Pleroma.Web.RichMedia.Parser do try do {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: [pool: :media]) - html |> maybe_parse() |> get_parsed_data() + html |> maybe_parse() |> clean_parsed_data() |> check_parsed_data() rescue e -> {:error, "Parsing error: #{inspect(e)}"} @@ -46,11 +46,31 @@ defmodule Pleroma.Web.RichMedia.Parser do end) end - defp get_parsed_data(%{title: title} = data) when is_binary(title) and byte_size(title) > 0 do + defp check_parsed_data(%{title: title} = data) when is_binary(title) and byte_size(title) > 0 do {:ok, data} end - defp get_parsed_data(data) do + defp check_parsed_data(data) do {:error, "Found metadata was invalid or incomplete: #{inspect(data)}"} end + + defp string_is_valid_unicode(data) do + data + |> :unicode.characters_to_binary() + |> clean_string() + end + + defp clean_string({:error, _, _}), do: {:error, "Invalid data"} + defp clean_string(data), do: {:ok, data} + + defp clean_parsed_data(data) do + data + |> Enum.reject(fn {_, val} -> + case string_is_valid_unicode(val) do + {:ok, _} -> false + _ -> true + end + end) + |> Map.new() + end end -- cgit v1.2.3 From 46dba03098b2646fbfb47ccb17261221c9c26f11 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 31 Jan 2019 16:19:31 +0000 Subject: rich media: parser: only try to validate strings, not numbers (OEmbed) --- lib/pleroma/web/rich_media/parser.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index b33411cc7..32dec9887 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -54,12 +54,14 @@ defmodule Pleroma.Web.RichMedia.Parser do {:error, "Found metadata was invalid or incomplete: #{inspect(data)}"} end - defp string_is_valid_unicode(data) do + defp string_is_valid_unicode(data) when is_binary(data) do data |> :unicode.characters_to_binary() |> clean_string() end + defp string_is_valid_unicode(data), do: {:ok, data} + defp clean_string({:error, _, _}), do: {:error, "Invalid data"} defp clean_string(data), do: {:ok, data} -- cgit v1.2.3 From 308b35ebe2f2062b87a5d7703df8ab5b1210d9c8 Mon Sep 17 00:00:00 2001 From: href Date: Thu, 31 Jan 2019 18:07:46 +0100 Subject: User.follow_all: ensure its stays unique --- lib/pleroma/user.ex | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 60d1d4811..33630ac7c 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -315,7 +315,16 @@ defmodule Pleroma.User do q = from(u in User, where: u.id == ^follower.id, - update: [set: [following: fragment("array_cat(?, ?)", u.following, ^followed_addresses)]] + update: [ + set: [ + following: + fragment( + "array(select distinct unnest (array_cat(?, ?)))", + u.following, + ^followed_addresses + ) + ] + ] ) {1, [follower]} = Repo.update_all(q, [], returning: true) -- cgit v1.2.3 From b19b4f85376f6bad33bb37b1624f45dbd502bfda Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 31 Jan 2019 20:02:08 +0100 Subject: Remove default value for rich media. Setting it to true will actually override a 'false' set before. --- lib/pleroma/web/rich_media/helpers.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index 44e876777..521fa7ee0 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -7,7 +7,7 @@ defmodule Pleroma.Web.RichMedia.Helpers do alias Pleroma.Web.RichMedia.Parser def fetch_data_for_activity(%Activity{} = activity) do - with true <- Pleroma.Config.get([:rich_media, :enabled], true), + with true <- Pleroma.Config.get([:rich_media, :enabled]), %Object{} = object <- Object.normalize(activity.data["object"]), {:ok, page_url} <- HTML.extract_first_external_url(object, object.data["content"]), {:ok, rich_media} <- Parser.parse(page_url) do -- cgit v1.2.3 From c05928dbdabfafc536512341e8d64b240b097f62 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 03:55:10 -0300 Subject: use nodeinfo 2.1, add repository field that is the only change from nodeinfo 2.0 to 2.1 also this makes the nodeinfo tests use 2.1.json instead of 2.0.json --- lib/pleroma/application.ex | 2 ++ lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 40bff08c7..8b50bcf8c 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -8,9 +8,11 @@ defmodule Pleroma.Application do @name "Pleroma" @version Mix.Project.config()[:version] + @repository "https://git.pleroma.social/pleroma/pleroma" def name, do: @name def version, do: @version def named_version(), do: @name <> " " <> @version + def repository, do: @repository def user_agent() do info = "#{Pleroma.Web.base_url()} <#{Pleroma.Config.get([:instance, :email], "")}>" diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 11b97164d..de7256dda 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -17,8 +17,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do response = %{ links: [ %{ - rel: "http://nodeinfo.diaspora.software/ns/schema/2.0", - href: Web.base_url() <> "/nodeinfo/2.0.json" + rel: "http://nodeinfo.diaspora.software/ns/schema/2.1", + href: Web.base_url() <> "/nodeinfo/2.1.json" } ] } @@ -26,8 +26,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do json(conn, response) end - # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json - def nodeinfo(conn, %{"version" => "2.0"}) do + # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json + def nodeinfo(conn, %{"version" => "2.1"}) do instance = Application.get_env(:pleroma, :instance) media_proxy = Application.get_env(:pleroma, :media_proxy) suggestions = Application.get_env(:pleroma, :suggestions) @@ -99,10 +99,11 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do |> Enum.filter(& &1) response = %{ - version: "2.0", + version: "2.1", software: %{ name: Pleroma.Application.name(), - version: Pleroma.Application.version() + version: Pleroma.Application.version(), + repository: Pleroma.Application.repository(), }, protocols: ["ostatus", "activitypub"], services: %{ @@ -146,7 +147,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do conn |> put_resp_header( "content-type", - "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8" + "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.1#; charset=utf-8" ) |> json(response) end -- cgit v1.2.3 From b0c4c082c4d166f3f49ffce69bb86639c1a34790 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 04:02:40 -0300 Subject: mix format pass --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index de7256dda..f5974fbb9 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -103,7 +103,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do software: %{ name: Pleroma.Application.name(), version: Pleroma.Application.version(), - repository: Pleroma.Application.repository(), + repository: Pleroma.Application.repository() }, protocols: ["ostatus", "activitypub"], services: %{ -- cgit v1.2.3 From fa5ec765d9c6184027ba1e4371e9a6f863c3f5db Mon Sep 17 00:00:00 2001 From: href Date: Fri, 1 Feb 2019 11:34:41 +0100 Subject: Serve sw-pleroma.js properly --- lib/pleroma/plugs/instance_static.ex | 2 +- lib/pleroma/web/endpoint.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/plugs/instance_static.ex b/lib/pleroma/plugs/instance_static.ex index af2f6f331..11f108de7 100644 --- a/lib/pleroma/plugs/instance_static.ex +++ b/lib/pleroma/plugs/instance_static.ex @@ -21,7 +21,7 @@ defmodule Pleroma.Plugs.InstanceStatic do end end - @only ~w(index.html static emoji packs sounds images instance favicon.png) + @only ~w(index.html static emoji packs sounds images instance favicon.png sw.js sw-pleroma.js) def init(opts) do opts diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index 0b4ce9cc4..2b156fdfd 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -25,7 +25,7 @@ defmodule Pleroma.Web.Endpoint do at: "/", from: :pleroma, only: - ~w(index.html static finmoji emoji packs sounds images instance sw.js favicon.png schemas doc) + ~w(index.html static finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc) ) # Code reloading can be explicitly enabled under the -- cgit v1.2.3 From cd6db6abe4df010905649816735d925c0538da34 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 14:11:23 -0300 Subject: use Mix.Project.Config for some Application functions --- lib/pleroma/application.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 8b50bcf8c..d67e2cdc8 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -6,9 +6,9 @@ defmodule Pleroma.Application do use Application import Supervisor.Spec - @name "Pleroma" + @name Mix.Project.config()[:name] @version Mix.Project.config()[:version] - @repository "https://git.pleroma.social/pleroma/pleroma" + @repository Mix.Project.config()[:source_url] def name, do: @name def version, do: @version def named_version(), do: @name <> " " <> @version -- cgit v1.2.3 From 74c6119f2863be35312b9b6e11735b0c5ad4f845 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 1 Feb 2019 18:15:15 +0100 Subject: MastodonAPI.MastodonAPIController: Return a 404 when we fail to get a list --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 491ed9dc5..a94eb5c73 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -905,7 +905,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do res = ListView.render("list.json", list: list) json(conn, res) else - _e -> json(conn, "error") + _e -> + conn + |> put_status(404) + |> json(%{error: "Record not found"}) end end -- cgit v1.2.3 From b17ce875cf3ae73423f737e46b7103116f45e7d0 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 14:23:40 -0300 Subject: keep compatibility with nodeinfo 2.0 splits actual nodeinfo generation into raw_nodeinfo, the 2.0 handler gives the same result, while the 2.1 handler inserts the software.repository field. requested by @href --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 36 +++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index f5974fbb9..72b5d97ac 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -16,6 +16,10 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do def schemas(conn, _params) do response = %{ links: [ + %{ + rel: "http://nodeinfo.diaspora.software/ns/schema/2.0", + href: Web.base_url() <> "/nodeinfo/2.0.json" + }, %{ rel: "http://nodeinfo.diaspora.software/ns/schema/2.1", href: Web.base_url() <> "/nodeinfo/2.1.json" @@ -26,8 +30,9 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do json(conn, response) end - # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json - def nodeinfo(conn, %{"version" => "2.1"}) do + # returns a nodeinfo 2.0 map, since 2.1 just adds a repository field + # under software. + def raw_nodeinfo() do instance = Application.get_env(:pleroma, :instance) media_proxy = Application.get_env(:pleroma, :media_proxy) suggestions = Application.get_env(:pleroma, :suggestions) @@ -98,12 +103,11 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do ] |> Enum.filter(& &1) - response = %{ - version: "2.1", + %{ + version: "2.0", software: %{ name: Pleroma.Application.name(), version: Pleroma.Application.version(), - repository: Pleroma.Application.repository() }, protocols: ["ostatus", "activitypub"], services: %{ @@ -143,6 +147,28 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do restrictedNicknames: Pleroma.Config.get([Pleroma.User, :restricted_nicknames]) } } + end + + # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json + # and https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json + def nodeinfo(conn, %{"version" => "2.0"}) do + conn + |> put_resp_header( + "content-type", + "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8" + ) + |> json(raw_nodeinfo()) + end + + def nodeinfo(conn, %{"version" => "2.1"}) do + raw_response = raw_nodeinfo() + + updated_software = + raw_response + |> Map.get(:software) + |> Map.put(:repository, Pleroma.Application.repository()) + + response = raw_response |> Map.put(:software, updated_software) conn |> put_resp_header( -- cgit v1.2.3 From 23b1c64a19ab13b152ba46e1a744cbf2efafce57 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 14:35:08 -0300 Subject: downcase software name in nodeinfo --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 72b5d97ac..b1db58d0b 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -106,7 +106,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do %{ version: "2.0", software: %{ - name: Pleroma.Application.name(), + name: Pleroma.Application.name() |> String.downcase, version: Pleroma.Application.version(), }, protocols: ["ostatus", "activitypub"], -- cgit v1.2.3 From 1cdcee89daec2f0538c6ab69cd9259d6486a7f6f Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 14:40:43 -0300 Subject: mix format pass --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index b1db58d0b..a1a395c8f 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -106,8 +106,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do %{ version: "2.0", software: %{ - name: Pleroma.Application.name() |> String.downcase, - version: Pleroma.Application.version(), + name: Pleroma.Application.name() |> String.downcase(), + version: Pleroma.Application.version() }, protocols: ["ostatus", "activitypub"], services: %{ -- cgit v1.2.3 From d747bd98700dd8b015ef48e8a2a1df0025012b0a Mon Sep 17 00:00:00 2001 From: eugenijm Date: Fri, 1 Feb 2019 21:56:18 +0300 Subject: Use String.replace_leading instead of String.replace for getting websocket streaming api url. Extract the login responsible for obtaining websocket URL into the corresponding Endpoint function. --- lib/pleroma/web/endpoint.ex | 4 ++++ lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index 2b156fdfd..ebbc5d7b5 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -82,4 +82,8 @@ defmodule Pleroma.Web.Endpoint do port = System.get_env("PORT") || raise "expected the PORT environment variable to be set" {:ok, Keyword.put(config, :http, [:inet6, port: port])} end + + def websocket_url do + String.replace_leading(static_url(), "http", "ws") + end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index a94eb5c73..85769c3d7 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -138,7 +138,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})", email: Keyword.get(instance, :email), urls: %{ - streaming_api: String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws") + streaming_api: Pleroma.Web.Endpoint.websocket_url() }, stats: Stats.get_stats(), thumbnail: Web.base_url() <> "/instance/thumbnail.jpeg", -- cgit v1.2.3 From 9cac8729afa7219d8b87e2851b855cab7a1c04b3 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Feb 2019 16:03:23 -0300 Subject: update nodeinfo version when requesting 2.1 --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index a1a395c8f..21694a5ee 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -168,7 +168,10 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do |> Map.get(:software) |> Map.put(:repository, Pleroma.Application.repository()) - response = raw_response |> Map.put(:software, updated_software) + response = + raw_response + |> Map.put(:software, updated_software) + |> Map.put(:version, "2.1") conn |> put_resp_header( -- cgit v1.2.3 From a184811a605a56436cc5b9eae8ef5c3834285922 Mon Sep 17 00:00:00 2001 From: eugenijm Date: Fri, 1 Feb 2019 22:35:19 +0300 Subject: Use url() instead of static_url in Endpoint.websocket_url() --- lib/pleroma/web/endpoint.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index ebbc5d7b5..3eed047ca 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -84,6 +84,6 @@ defmodule Pleroma.Web.Endpoint do end def websocket_url do - String.replace_leading(static_url(), "http", "ws") + String.replace_leading(url(), "http", "ws") end end -- cgit v1.2.3 From af10ef8d4e4aefc7760bd85a4723c79a0bfbf2e0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 1 Feb 2019 19:38:57 +0000 Subject: object: use cached accesses when possible in Object.normalize() --- lib/pleroma/object.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 707a61f14..1088bb5e4 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -31,8 +31,8 @@ defmodule Pleroma.Object do Repo.one(from(object in Object, where: fragment("(?)->>'id' = ?", object.data, ^ap_id))) end - def normalize(obj) when is_map(obj), do: Object.get_by_ap_id(obj["id"]) - def normalize(ap_id) when is_binary(ap_id), do: Object.get_by_ap_id(ap_id) + def normalize(%{"id" => ap_id}), do: normalize(ap_id) + def normalize(ap_id) when is_binary(ap_id), do: get_cached_by_ap_id(ap_id) def normalize(_), do: nil # Owned objects can only be mutated by their owner -- cgit v1.2.3 From 486749064f72ac5078a42ed339519afbbf48027a Mon Sep 17 00:00:00 2001 From: kaniini Date: Fri, 1 Feb 2019 20:22:58 +0000 Subject: Revert "Merge branch 'feature/split-hide-network' into 'develop'" This reverts merge request !733 --- lib/pleroma/user/info.ex | 6 ++---- lib/pleroma/web/activity_pub/views/user_view.ex | 8 ++++---- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 4 ++-- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 6 +++--- lib/pleroma/web/twitter_api/views/user_view.ex | 3 +-- 5 files changed, 12 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 2186190a0..c6c923aac 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -30,8 +30,7 @@ defmodule Pleroma.User.Info do field(:topic, :string, default: nil) field(:hub, :string, default: nil) field(:salmon, :string, default: nil) - field(:hide_followers, :boolean, default: false) - field(:hide_followings, :boolean, default: false) + field(:hide_network, :boolean, default: false) field(:pinned_activities, {:array, :string}, default: []) # Found in the wild @@ -144,8 +143,7 @@ defmodule Pleroma.User.Info do :no_rich_text, :default_scope, :banner, - :hide_followings, - :hide_followers, + :hide_network, :background ]) end diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index b9588bee5..dcf681b6d 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -86,7 +86,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = from(user in query, select: [:ap_id]) following = Repo.all(query) - collection(following, "#{user.ap_id}/following", page, !user.info.hide_followings) + collection(following, "#{user.ap_id}/following", page, !user.info.hide_network) |> Map.merge(Utils.make_json_ld_header()) end @@ -99,7 +99,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{user.ap_id}/following", "type" => "OrderedCollection", "totalItems" => length(following), - "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_followings) + "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_network) } |> Map.merge(Utils.make_json_ld_header()) end @@ -109,7 +109,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = from(user in query, select: [:ap_id]) followers = Repo.all(query) - collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers) + collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_network) |> Map.merge(Utils.make_json_ld_header()) end @@ -122,7 +122,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{user.ap_id}/followers", "type" => "OrderedCollection", "totalItems" => length(followers), - "first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers) + "first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_network) } |> Map.merge(Utils.make_json_ld_header()) end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 85769c3d7..7f3fbff4a 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -605,7 +605,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do followers = cond do for_user && user.id == for_user.id -> followers - user.info.hide_followers -> [] + user.info.hide_network -> [] true -> followers end @@ -621,7 +621,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do followers = cond do for_user && user.id == for_user.id -> followers - user.info.hide_followings -> [] + user.info.hide_network -> [] true -> followers end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 5e3fe9352..3064d61ea 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -503,7 +503,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do followers = cond do for_user && user.id == for_user.id -> followers - user.info.hide_followers -> [] + user.info.hide_network -> [] true -> followers end @@ -523,7 +523,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do friends = cond do for_user && user.id == for_user.id -> friends - user.info.hide_followings -> [] + user.info.hide_network -> [] true -> friends end @@ -618,7 +618,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do defp build_info_cng(user, params) do info_params = - ["no_rich_text", "locked", "hide_followers", "hide_followings"] + ["no_rich_text", "locked", "hide_network"] |> Enum.reduce(%{}, fn key, res -> if value = params[key] do Map.put(res, key, value == "true") diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index cd7c4349c..15682db8f 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -108,8 +108,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "locked" => user.info.locked, "default_scope" => user.info.default_scope, "no_rich_text" => user.info.no_rich_text, - "hide_followers" => user.info.hide_followers, - "hide_followings" => user.info.hide_followings, + "hide_network" => user.info.hide_network, "fields" => fields, # Pleroma extension -- cgit v1.2.3 From cbadf9d3333d3840d21cfcd3bd4f33d3b5b90445 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 2 Feb 2019 11:38:37 +0300 Subject: Fix rich media relative path --- lib/pleroma/web/mastodon_api/views/status_view.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index d5b7e68c7..826563f74 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -184,6 +184,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do def render("card.json", %{rich_media: rich_media, page_url: page_url}) do page_url = rich_media[:url] || page_url page_url_data = URI.parse(page_url) + + image_url = + URI.merge(page_url_data, URI.parse(rich_media[:image])) + |> to_string + site_name = rich_media[:site_name] || page_url_data.host %{ @@ -191,7 +196,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do provider_name: site_name, provider_url: page_url_data.scheme <> "://" <> page_url_data.host, url: page_url, - image: rich_media[:image] |> MediaProxy.url(), + image: image_url |> MediaProxy.url(), title: rich_media[:title], description: rich_media[:description], pleroma: %{ -- cgit v1.2.3 From e4d18f328b738a2c3a953e721f0d350cfba20089 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 2 Feb 2019 11:53:46 +0300 Subject: merge only if page_url is an absolute path --- lib/pleroma/web/mastodon_api/views/status_view.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 826563f74..aa38784a6 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -186,8 +186,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do page_url_data = URI.parse(page_url) image_url = - URI.merge(page_url_data, URI.parse(rich_media[:image])) - |> to_string + if %URI{host: nil} = page_url_data do + rich_media[:image] + else + URI.merge(page_url_data, URI.parse(rich_media[:image])) + |> to_string + end site_name = rich_media[:site_name] || page_url_data.host -- cgit v1.2.3 From 833404f0f549a5c2ac58d43239217648cc354a6a Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 2 Feb 2019 12:04:18 +0300 Subject: Use with instead of if in the card --- lib/pleroma/web/mastodon_api/views/status_view.ex | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index aa38784a6..c8fde93ba 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -186,11 +186,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do page_url_data = URI.parse(page_url) image_url = - if %URI{host: nil} = page_url_data do + with %URI{host: nil} <- page_url_data do rich_media[:image] else - URI.merge(page_url_data, URI.parse(rich_media[:image])) - |> to_string + _ -> + URI.merge(page_url_data, URI.parse(rich_media[:image])) + |> to_string end site_name = rich_media[:site_name] || page_url_data.host -- cgit v1.2.3 From 68d461b3a9f3be58af85a7ae98ace2ebcbc616f2 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 2 Feb 2019 12:24:24 +0300 Subject: Check if rich media uri is relative --- lib/pleroma/web/mastodon_api/views/status_view.ex | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index c8fde93ba..d1b11d4f1 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -182,18 +182,19 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do end def render("card.json", %{rich_media: rich_media, page_url: page_url}) do - page_url = rich_media[:url] || page_url - page_url_data = URI.parse(page_url) - - image_url = - with %URI{host: nil} <- page_url_data do - rich_media[:image] + page_url_data = + if rich_media[:url] != nil do + URI.merge(URI.parse(page_url), URI.parse(rich_media[:url])) else - _ -> - URI.merge(page_url_data, URI.parse(rich_media[:image])) - |> to_string + page_url end + page_url = page_url_data |> to_string + + image_url = + URI.merge(page_url_data, URI.parse(rich_media[:image])) + |> to_string + site_name = rich_media[:site_name] || page_url_data.host %{ -- cgit v1.2.3 From 2c59eb3cfc93b4f23599fb3e551c38745440380c Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Sat, 2 Feb 2019 13:38:52 +0300 Subject: Add responsive features to layout --- lib/pleroma/web/templates/layout/app.html.eex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/templates/layout/app.html.eex b/lib/pleroma/web/templates/layout/app.html.eex index 2e96c1509..8dd3284d6 100644 --- a/lib/pleroma/web/templates/layout/app.html.eex +++ b/lib/pleroma/web/templates/layout/app.html.eex @@ -1,7 +1,8 @@ - + + <%= Application.get_env(:pleroma, :instance)[:name] %> -- cgit v1.2.3 From b40b4bc4e5b49ac2b35746cee7b1db92428d3ee1 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sun, 3 Feb 2019 12:41:27 +0300 Subject: [#582] Optimized federation retirement by reducing the number of SQL calls (calling `Instances.set_reachable/1` only if instance had `unreachable_since`, calling `Instances.set_unreachable/1` only if instance had nil `unreachable_since`). --- lib/pleroma/instances/instance.ex | 25 ++++++++++++++++++------- lib/pleroma/web/activity_pub/activity_pub.ex | 13 +++++++------ lib/pleroma/web/federator/federator.ex | 4 ++-- lib/pleroma/web/salmon/salmon.ex | 28 +++++++++++++++++----------- lib/pleroma/web/websub/websub.ex | 12 +++++++----- 5 files changed, 51 insertions(+), 31 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index a87590d8b..4a4ca26dd 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -26,7 +26,7 @@ defmodule Pleroma.Instances.Instance do |> unique_constraint(:host) end - def filter_reachable([]), do: [] + def filter_reachable([]), do: %{} def filter_reachable(urls_or_hosts) when is_list(urls_or_hosts) do hosts = @@ -34,17 +34,28 @@ defmodule Pleroma.Instances.Instance do |> Enum.map(&(&1 && host(&1))) |> Enum.filter(&(to_string(&1) != "")) - unreachable_hosts = + unreachable_since_by_host = Repo.all( from(i in Instance, - where: - i.host in ^hosts and - i.unreachable_since <= ^Instances.reachability_datetime_threshold(), - select: i.host + where: i.host in ^hosts, + select: {i.host, i.unreachable_since} ) ) + |> Map.new(& &1) - Enum.filter(urls_or_hosts, &(&1 && host(&1) not in unreachable_hosts)) + reachability_datetime_threshold = Instances.reachability_datetime_threshold() + + for entry <- Enum.filter(urls_or_hosts, &is_binary/1) do + host = host(entry) + unreachable_since = unreachable_since_by_host[host] + + if !unreachable_since || + NaiveDateTime.compare(unreachable_since, reachability_datetime_threshold) == :gt do + {entry, unreachable_since} + end + end + |> Enum.filter(& &1) + |> Map.new(& &1) end def reachable?(url_or_host) when is_binary(url_or_host) do diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 06e8c3f1c..5f6c8e7d3 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -744,7 +744,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do public = is_public?(activity) - remote_inboxes = + reachable_inboxes_metadata = (Pleroma.Web.Salmon.remote_users(activity) ++ remote_followers) |> Enum.filter(fn user -> User.ap_enabled?(user) end) |> Enum.map(fn %{info: %{source_data: data}} -> @@ -757,17 +757,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {:ok, data} = Transmogrifier.prepare_outgoing(activity.data) json = Jason.encode!(data) - Enum.each(remote_inboxes, fn inbox -> + Enum.each(reachable_inboxes_metadata, fn {inbox, unreachable_since} -> Federator.enqueue(:publish_single_ap, %{ inbox: inbox, json: json, actor: actor, - id: activity.data["id"] + id: activity.data["id"], + unreachable_since: unreachable_since }) end) end - def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do + def publish_one(%{inbox: inbox, json: json, actor: actor, id: id} = params) do Logger.info("Federating #{id} to #{inbox}") host = URI.parse(inbox).host @@ -791,11 +792,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {"digest", digest} ] ) do - Instances.set_reachable(inbox) + if params[:unreachable_since], do: Instances.set_reachable(inbox) result else {_post_result, response} -> - Instances.set_unreachable(inbox) + unless params[:unreachable_since], do: Instances.set_unreachable(inbox) {:error, response} end end diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index 46f7a4973..bb7676cf0 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -124,8 +124,8 @@ defmodule Pleroma.Web.Federator do end end - def handle(:publish_single_salmon, {user_or_url, feed, poster}) do - Salmon.send_to_user(user_or_url, feed, poster) + def handle(:publish_single_salmon, params) do + Salmon.send_to_user(params) end def handle(:publish_single_ap, params) do diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 07ca42a5f..4d519ece4 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -162,30 +162,29 @@ defmodule Pleroma.Web.Salmon do |> Enum.filter(fn user -> user && !user.local end) end - # push an activity to remote accounts - # - def send_to_user(%{info: %{salmon: salmon}}, feed, poster), - do: send_to_user(salmon, feed, poster) + @doc "Pushes an activity to remote account." + def send_to_user(%{recipient: %{info: %{salmon: salmon}}} = params), + do: send_to_user(Map.put(params, :recipient, salmon)) - def send_to_user(url, feed, poster) when is_binary(url) do + def send_to_user(%{recipient: url, feed: feed, poster: poster} = params) when is_binary(url) do with {:ok, %{status: code}} when code in 200..299 <- poster.( url, feed, [{"Content-Type", "application/magic-envelope+xml"}] ) do - Instances.set_reachable(url) + if params[:unreachable_since], do: Instances.set_reachable(url) Logger.debug(fn -> "Pushed to #{url}, code #{code}" end) :ok else e -> - Instances.set_unreachable(url) + unless params[:unreachable_since], do: Instances.set_reachable(url) Logger.debug(fn -> "Pushing Salmon to #{url} failed, #{inspect(e)}" end) :error end end - def send_to_user(_, _, _), do: :noop + def send_to_user(_), do: :noop @supported_activities [ "Create", @@ -218,13 +217,20 @@ defmodule Pleroma.Web.Salmon do remote_users = remote_users(activity) salmon_urls = Enum.map(remote_users, & &1.info.salmon) - reachable_salmon_urls = Instances.filter_reachable(salmon_urls) + reachable_urls_metadata = Instances.filter_reachable(salmon_urls) + reachable_urls = Map.keys(reachable_urls_metadata) remote_users - |> Enum.filter(&(&1.info.salmon in reachable_salmon_urls)) + |> Enum.filter(&(&1.info.salmon in reachable_urls)) |> Enum.each(fn remote_user -> Logger.debug(fn -> "Sending Salmon to #{remote_user.ap_id}" end) - Pleroma.Web.Federator.enqueue(:publish_single_salmon, {remote_user, feed, poster}) + + Pleroma.Web.Federator.enqueue(:publish_single_salmon, %{ + recipient: remote_user, + feed: feed, + poster: poster, + unreachable_since: reachable_urls_metadata[remote_user.info.salmon] + }) end) end end diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 8f7d53b03..cf51dce76 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -70,7 +70,8 @@ defmodule Pleroma.Web.Websub do subscriptions = Repo.all(query) callbacks = Enum.map(subscriptions, & &1.callback) - reachable_callbacks = Instances.filter_reachable(callbacks) + reachable_callbacks_metadata = Instances.filter_reachable(callbacks) + reachable_callbacks = Map.keys(reachable_callbacks_metadata) subscriptions |> Enum.filter(&(&1.callback in reachable_callbacks)) @@ -79,7 +80,8 @@ defmodule Pleroma.Web.Websub do xml: response, topic: topic, callback: sub.callback, - secret: sub.secret + secret: sub.secret, + unreachable_since: reachable_callbacks_metadata[sub.callback] } Pleroma.Web.Federator.enqueue(:publish_single_websub, data) @@ -268,7 +270,7 @@ defmodule Pleroma.Web.Websub do end) end - def publish_one(%{xml: xml, topic: topic, callback: callback, secret: secret}) do + def publish_one(%{xml: xml, topic: topic, callback: callback, secret: secret} = params) do signature = sign(secret || "", xml) Logger.info(fn -> "Pushing #{topic} to #{callback}" end) @@ -281,12 +283,12 @@ defmodule Pleroma.Web.Websub do {"X-Hub-Signature", "sha1=#{signature}"} ] ) do - Instances.set_reachable(callback) + if params[:unreachable_since], do: Instances.set_reachable(callback) Logger.info(fn -> "Pushed to #{callback}, code #{code}" end) {:ok, code} else {_post_result, response} -> - Instances.set_unreachable(callback) + unless params[:unreachable_since], do: Instances.set_reachable(callback) Logger.debug(fn -> "Couldn't push to #{callback}, #{inspect(response)}" end) {:error, response} end -- cgit v1.2.3 From 3913b0196e47c829df90aa835ade2efdb7c43850 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sun, 3 Feb 2019 13:28:13 +0300 Subject: [#582] Made single-pub task call Instance.set_reachable/1 if `set_reachable` is not specified. Added tests. --- lib/pleroma/web/activity_pub/activity_pub.ex | 4 +++- lib/pleroma/web/salmon/salmon.ex | 4 +++- lib/pleroma/web/websub/websub.ex | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 5f6c8e7d3..4635e7fcd 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -792,7 +792,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {"digest", digest} ] ) do - if params[:unreachable_since], do: Instances.set_reachable(inbox) + if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since], + do: Instances.set_reachable(inbox) + result else {_post_result, response} -> diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index 4d519ece4..b1c2dc7fa 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -173,7 +173,9 @@ defmodule Pleroma.Web.Salmon do feed, [{"Content-Type", "application/magic-envelope+xml"}] ) do - if params[:unreachable_since], do: Instances.set_reachable(url) + if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since], + do: Instances.set_reachable(url) + Logger.debug(fn -> "Pushed to #{url}, code #{code}" end) :ok else diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index cf51dce76..90ba79962 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -283,7 +283,9 @@ defmodule Pleroma.Web.Websub do {"X-Hub-Signature", "sha1=#{signature}"} ] ) do - if params[:unreachable_since], do: Instances.set_reachable(callback) + if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since], + do: Instances.set_reachable(callback) + Logger.info(fn -> "Pushed to #{callback}, code #{code}" end) {:ok, code} else -- cgit v1.2.3 From 0c08bd4181cda08112a9e12ba92cdfb25c602da1 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sun, 3 Feb 2019 16:39:42 +0000 Subject: Update Mogrify docs and warning for deprecated syntax to encourage users to enable both strip and auto-orient --- lib/pleroma/upload.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 0a19e737b..ce2a1b696 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -124,10 +124,10 @@ defmodule Pleroma.Upload do :pleroma, Pleroma.Upload, [filters: [Pleroma.Upload.Filter.Mogrify]] - :pleroma, Pleroma.Upload.Filter.Mogrify, args: "strip" + :pleroma, Pleroma.Upload.Filter.Mogrify, args: ["strip", "auto-orient"] """) - Pleroma.Config.put([Pleroma.Upload.Filter.Mogrify], args: "strip") + Pleroma.Config.put([Pleroma.Upload.Filter.Mogrify], args: ["strip", "auto-orient"]) Map.put(opts, :filters, opts.filters ++ [Pleroma.Upload.Filter.Mogrify]) else opts -- cgit v1.2.3 From 505a084058eeeed7d945b43630c97c38cafec656 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 3 Feb 2019 18:28:14 +0100 Subject: Still do caching in tests. --- lib/pleroma/object.ex | 43 ++++++++++++++++++++--------------- lib/pleroma/web/activity_pub/utils.ex | 2 +- 2 files changed, 26 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 1088bb5e4..7b46a3b05 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -42,24 +42,18 @@ defmodule Pleroma.Object do # Legacy objects can be mutated by anybody def authorize_mutation(%Object{}, %User{}), do: true - if Mix.env() == :test do - def get_cached_by_ap_id(ap_id) do - get_by_ap_id(ap_id) - end - else - def get_cached_by_ap_id(ap_id) do - key = "object:#{ap_id}" - - Cachex.fetch!(:object_cache, key, fn _ -> - object = get_by_ap_id(ap_id) - - if object do - {:commit, object} - else - {:ignore, object} - end - end) - end + def get_cached_by_ap_id(ap_id) do + key = "object:#{ap_id}" + + Cachex.fetch!(:object_cache, key, fn _ -> + object = get_by_ap_id(ap_id) + + if object do + {:commit, object} + else + {:ignore, object} + end + end) end def context_mapping(context) do @@ -90,4 +84,17 @@ defmodule Pleroma.Object do {:ok, object} end end + + def set_cache(%Object{data: %{"id" => ap_id}} = object) do + Cachex.put(:object_cache, "object:#{ap_id}", object) + {:ok, object} + end + + def update_and_set_cache(changeset) do + with {:ok, object} <- Repo.update(changeset) do + set_cache(object) + else + e -> e + end + end end diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 3b0cdfe71..4a2cc6738 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -285,7 +285,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do |> Map.put("#{property}_count", length(element)) |> Map.put("#{property}s", element), changeset <- Changeset.change(object, data: new_data), - {:ok, object} <- Repo.update(changeset), + {:ok, object} <- Object.update_and_set_cache(changeset), _ <- update_object_in_activities(object) do {:ok, object} end -- cgit v1.2.3 From 16ce129e382cc5fa0cf5d86fc0785457a0dedd76 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Sun, 3 Feb 2019 21:24:09 +0300 Subject: Split hide_network into hide_followers & hide_followings (fixed) --- lib/pleroma/user/info.ex | 6 ++++-- lib/pleroma/web/activity_pub/views/user_view.ex | 8 ++++---- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 4 ++-- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 6 +++--- lib/pleroma/web/twitter_api/views/user_view.ex | 3 ++- 5 files changed, 15 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index c6c923aac..2186190a0 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -30,7 +30,8 @@ defmodule Pleroma.User.Info do field(:topic, :string, default: nil) field(:hub, :string, default: nil) field(:salmon, :string, default: nil) - field(:hide_network, :boolean, default: false) + field(:hide_followers, :boolean, default: false) + field(:hide_followings, :boolean, default: false) field(:pinned_activities, {:array, :string}, default: []) # Found in the wild @@ -143,7 +144,8 @@ defmodule Pleroma.User.Info do :no_rich_text, :default_scope, :banner, - :hide_network, + :hide_followings, + :hide_followers, :background ]) end diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index dcf681b6d..b9588bee5 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -86,7 +86,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = from(user in query, select: [:ap_id]) following = Repo.all(query) - collection(following, "#{user.ap_id}/following", page, !user.info.hide_network) + collection(following, "#{user.ap_id}/following", page, !user.info.hide_followings) |> Map.merge(Utils.make_json_ld_header()) end @@ -99,7 +99,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{user.ap_id}/following", "type" => "OrderedCollection", "totalItems" => length(following), - "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_network) + "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_followings) } |> Map.merge(Utils.make_json_ld_header()) end @@ -109,7 +109,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = from(user in query, select: [:ap_id]) followers = Repo.all(query) - collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_network) + collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers) |> Map.merge(Utils.make_json_ld_header()) end @@ -122,7 +122,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{user.ap_id}/followers", "type" => "OrderedCollection", "totalItems" => length(followers), - "first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_network) + "first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers) } |> Map.merge(Utils.make_json_ld_header()) end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 7f3fbff4a..85769c3d7 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -605,7 +605,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do followers = cond do for_user && user.id == for_user.id -> followers - user.info.hide_network -> [] + user.info.hide_followers -> [] true -> followers end @@ -621,7 +621,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do followers = cond do for_user && user.id == for_user.id -> followers - user.info.hide_network -> [] + user.info.hide_followings -> [] true -> followers end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 3064d61ea..5e3fe9352 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -503,7 +503,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do followers = cond do for_user && user.id == for_user.id -> followers - user.info.hide_network -> [] + user.info.hide_followers -> [] true -> followers end @@ -523,7 +523,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do friends = cond do for_user && user.id == for_user.id -> friends - user.info.hide_network -> [] + user.info.hide_followings -> [] true -> friends end @@ -618,7 +618,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do defp build_info_cng(user, params) do info_params = - ["no_rich_text", "locked", "hide_network"] + ["no_rich_text", "locked", "hide_followers", "hide_followings"] |> Enum.reduce(%{}, fn key, res -> if value = params[key] do Map.put(res, key, value == "true") diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 15682db8f..cd7c4349c 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -108,7 +108,8 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "locked" => user.info.locked, "default_scope" => user.info.default_scope, "no_rich_text" => user.info.no_rich_text, - "hide_network" => user.info.hide_network, + "hide_followers" => user.info.hide_followers, + "hide_followings" => user.info.hide_followings, "fields" => fields, # Pleroma extension -- cgit v1.2.3 From 0ef0ae35abf7c1f1016175bd446436f9e5dd8fc2 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sun, 3 Feb 2019 20:12:23 +0100 Subject: added optional delist feature --- .../web/activity_pub/mrf/hellthread_policy.ex | 30 ++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index a3f516ae7..0b9caeb11 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -3,17 +3,37 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do + alias Pleroma.User @behaviour Pleroma.Web.ActivityPub.MRF @impl true def filter(%{"type" => "Create"} = object) do - threshold = Pleroma.Config.get([:mrf_hellthread, :threshold]) + delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold]) + reject_threshold = Pleroma.Config.get([:mrf_hellthread, :reject_threshold]) recipients = (object["to"] || []) ++ (object["cc"] || []) - if length(recipients) > threshold do - {:reject, nil} - else - {:ok, object} + cond do + length(recipients) > reject_threshold -> + {:reject, nil} + + length(recipients) > delist_threshold -> + if Enum.member?(object["to"], "https://www.w3.org/ns/activitystreams#Public") or + Enum.member?(object["cc"], "https://www.w3.org/ns/activitystreams#Public") do + object + |> Kernel.update_in(["object", "to"], [ + User.get_cached_by_ap_id(object["actor"].follower_address) + ]) + |> Kernel.update_in(["object", "cc"], ["https://www.w3.org/ns/activitystreams#Public"]) + |> Kernel.update_in(["to"], [ + User.get_cached_by_ap_id(object["actor"].follower_address) + ]) + |> Kernel.update_in(["cc"], ["https://www.w3.org/ns/activitystreams#Public"]) + else + {:ok, object} + end + + true -> + {:ok, object} end end -- cgit v1.2.3 From 10130fa7d6a2dca4250ada1144fcfcfe75c26f45 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sun, 3 Feb 2019 20:27:28 +0100 Subject: made toggleable, added docs --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 0b9caeb11..53588b264 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -13,10 +13,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do recipients = (object["to"] || []) ++ (object["cc"] || []) cond do - length(recipients) > reject_threshold -> + length(recipients) > reject_threshold and reject_threshold != 0 -> {:reject, nil} - length(recipients) > delist_threshold -> + length(recipients) > delist_threshold and delist_threshold != 0 -> if Enum.member?(object["to"], "https://www.w3.org/ns/activitystreams#Public") or Enum.member?(object["cc"], "https://www.w3.org/ns/activitystreams#Public") do object -- cgit v1.2.3 From 531507a635917e15e28a72a58ab0f977eefed571 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sun, 3 Feb 2019 20:45:32 +0100 Subject: fixed things --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 53588b264..d95424493 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -19,15 +19,15 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do length(recipients) > delist_threshold and delist_threshold != 0 -> if Enum.member?(object["to"], "https://www.w3.org/ns/activitystreams#Public") or Enum.member?(object["cc"], "https://www.w3.org/ns/activitystreams#Public") do + follower_collection = User.get_by_ap_id(object["actor"].follower_address) + object - |> Kernel.update_in(["object", "to"], [ - User.get_cached_by_ap_id(object["actor"].follower_address) - ]) + |> Kernel.update_in(["object", "to"], [follower_collection]) |> Kernel.update_in(["object", "cc"], ["https://www.w3.org/ns/activitystreams#Public"]) - |> Kernel.update_in(["to"], [ - User.get_cached_by_ap_id(object["actor"].follower_address) - ]) + |> Kernel.update_in(["to"], [follower_collection]) |> Kernel.update_in(["cc"], ["https://www.w3.org/ns/activitystreams#Public"]) + + {:ok, object} else {:ok, object} end -- cgit v1.2.3 From e10cda7541f5d76a32d0bf27d90a51c5fc8e7fcf Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sun, 3 Feb 2019 22:46:06 +0100 Subject: implemented tweaks --- lib/pleroma/config/deprecation_warnings.ex | 7 +++++ .../web/activity_pub/mrf/hellthread_policy.ex | 31 +++++++++++++--------- 2 files changed, 26 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex index dc50682ee..0eb1833aa 100644 --- a/lib/pleroma/config/deprecation_warnings.ex +++ b/lib/pleroma/config/deprecation_warnings.ex @@ -12,6 +12,13 @@ defmodule Pleroma.Config.DeprecationWarnings do You are using the old configuration mechanism for the frontend. Please check config.md. """) end + + if Pleroma.Config.get(:mrf_hellthread, :threshold) do + Logger.warn(""" + !!!DEPRECATION WARNING!!! + You are using the old configuration mechanism for the hellthread filter. Please check config.md. + """) + end end def warn do diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index d95424493..cd9f9b1c4 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -6,27 +6,34 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do alias Pleroma.User @behaviour Pleroma.Web.ActivityPub.MRF + defp delist_message(object) do + follower_collection = User.get_by_ap_id(object["actor"].follower_address) + + object + |> Kernel.update_in(["to"], [follower_collection]) + |> Kernel.update_in(["cc"], ["https://www.w3.org/ns/activitystreams#Public"]) + end + @impl true def filter(%{"type" => "Create"} = object) do delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold]) - reject_threshold = Pleroma.Config.get([:mrf_hellthread, :reject_threshold]) + + reject_threshold = + Pleroma.Config.get( + [:mrf_hellthread, :reject_threshold], + Pleroma.Config.get([:mrf_hellthread, :threshold]) + ) + recipients = (object["to"] || []) ++ (object["cc"] || []) cond do - length(recipients) > reject_threshold and reject_threshold != 0 -> + length(recipients) > reject_threshold and reject_threshold > 0 -> {:reject, nil} - length(recipients) > delist_threshold and delist_threshold != 0 -> + length(recipients) > delist_threshold and delist_threshold > 0 -> if Enum.member?(object["to"], "https://www.w3.org/ns/activitystreams#Public") or - Enum.member?(object["cc"], "https://www.w3.org/ns/activitystreams#Public") do - follower_collection = User.get_by_ap_id(object["actor"].follower_address) - - object - |> Kernel.update_in(["object", "to"], [follower_collection]) - |> Kernel.update_in(["object", "cc"], ["https://www.w3.org/ns/activitystreams#Public"]) - |> Kernel.update_in(["to"], [follower_collection]) - |> Kernel.update_in(["cc"], ["https://www.w3.org/ns/activitystreams#Public"]) - + Enum.member?(object["to"], "https://www.w3.org/ns/activitystreams#Public") do + delist_message(object) {:ok, object} else {:ok, object} -- cgit v1.2.3 From 583c4e0f17206d77174e1eaa84bb68fc5a57f196 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sun, 3 Feb 2019 23:56:20 +0100 Subject: more tweaks, fixed silly mistakes... --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index cd9f9b1c4..1c2de555f 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -6,12 +6,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do alias Pleroma.User @behaviour Pleroma.Web.ActivityPub.MRF - defp delist_message(object) do - follower_collection = User.get_by_ap_id(object["actor"].follower_address) + defp delist_message(message) do + follower_collection = User.get_by_ap_id(message["actor"].follower_address) - object - |> Kernel.update_in(["to"], [follower_collection]) - |> Kernel.update_in(["cc"], ["https://www.w3.org/ns/activitystreams#Public"]) + message + |> Map.put(["to"], [follower_collection]) + |> Map.put(["cc"], ["https://www.w3.org/ns/activitystreams#Public"]) end @impl true @@ -32,9 +32,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do length(recipients) > delist_threshold and delist_threshold > 0 -> if Enum.member?(object["to"], "https://www.w3.org/ns/activitystreams#Public") or - Enum.member?(object["to"], "https://www.w3.org/ns/activitystreams#Public") do - delist_message(object) - {:ok, object} + Enum.member?(object["cc"], "https://www.w3.org/ns/activitystreams#Public") do + {:ok, delist_message(object)} else {:ok, object} end -- cgit v1.2.3 From 63a4f4b7be14753d0e78f8a445351b7dae008254 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Mon, 4 Feb 2019 10:23:07 +0100 Subject: fixed Map,put arguments, updated nomenclature --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 1c2de555f..667f5da03 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -10,8 +10,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do follower_collection = User.get_by_ap_id(message["actor"].follower_address) message - |> Map.put(["to"], [follower_collection]) - |> Map.put(["cc"], ["https://www.w3.org/ns/activitystreams#Public"]) + |> Map.put("to", [follower_collection]) + |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) end @impl true -- cgit v1.2.3 From 3cf046babb706c9539a0e4e799c578a4ed207c24 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Mon, 4 Feb 2019 10:23:43 +0100 Subject: actually commited the changes --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 667f5da03..e78c9b5f8 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -15,7 +15,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do end @impl true - def filter(%{"type" => "Create"} = object) do + def filter(%{"type" => "Create"} = message) do delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold]) reject_threshold = @@ -24,25 +24,25 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do Pleroma.Config.get([:mrf_hellthread, :threshold]) ) - recipients = (object["to"] || []) ++ (object["cc"] || []) + recipients = (message["to"] || []) ++ (message["cc"] || []) cond do length(recipients) > reject_threshold and reject_threshold > 0 -> {:reject, nil} length(recipients) > delist_threshold and delist_threshold > 0 -> - if Enum.member?(object["to"], "https://www.w3.org/ns/activitystreams#Public") or - Enum.member?(object["cc"], "https://www.w3.org/ns/activitystreams#Public") do - {:ok, delist_message(object)} + if Enum.member?(message["to"], "https://www.w3.org/ns/activitystreams#Public") or + Enum.member?(message["cc"], "https://www.w3.org/ns/activitystreams#Public") do + {:ok, delist_message(message)} else - {:ok, object} + {:ok, message} end true -> - {:ok, object} + {:ok, message} end end @impl true - def filter(object), do: {:ok, object} + def filter(message), do: {:ok, message} end -- cgit v1.2.3 From 4430641349a6f322be52b787cc817c0ff691b836 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Mon, 4 Feb 2019 12:09:00 +0100 Subject: squished a bug --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index e78c9b5f8..dd0d6dd5f 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -7,7 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do @behaviour Pleroma.Web.ActivityPub.MRF defp delist_message(message) do - follower_collection = User.get_by_ap_id(message["actor"].follower_address) + follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address message |> Map.put("to", [follower_collection]) @@ -44,5 +44,5 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do end @impl true - def filter(message), do: {:ok, message} + def filter(message), do: {:ok_notcreate, message} end -- cgit v1.2.3 From 58262a8b8a759ecb69663a92a56f65b6e16db6ea Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Mon, 4 Feb 2019 11:22:25 +0000 Subject: removed a debug thingy --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index dd0d6dd5f..4c6e612b2 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -44,5 +44,5 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do end @impl true - def filter(message), do: {:ok_notcreate, message} + def filter(message), do: {:ok, message} end -- cgit v1.2.3 From 127f99ae18eea7732e8cb7756a102ca4c5beacca Mon Sep 17 00:00:00 2001 From: href Date: Mon, 4 Feb 2019 17:44:41 +0100 Subject: Mime: detect RIFF formats (wave, webp, avi) --- lib/pleroma/mime.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/mime.ex b/lib/pleroma/mime.ex index 84fb536e0..36771533f 100644 --- a/lib/pleroma/mime.ex +++ b/lib/pleroma/mime.ex @@ -102,10 +102,18 @@ defmodule Pleroma.MIME do "audio/ogg" end - defp check_mime_type(<<0x52, 0x49, 0x46, 0x46, _::binary>>) do + defp check_mime_type(<<"RIFF", _::binary-size(4), "WAVE", _::binary>>) do "audio/wav" end + defp check_mime_type(<<"RIFF", _::binary-size(4), "WEBP", _::binary>>) do + "image/webp" + end + + defp check_mime_type(<<"RIFF", _::binary-size(4), "AVI.", _::binary>>) do + "video/avi" + end + defp check_mime_type(_) do @default end -- cgit v1.2.3 From 93e136d70b181fa271c2b4a5decd258f1287b1fa Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 4 Feb 2019 02:33:11 +0000 Subject: mix: add user tag/untag task --- lib/mix/tasks/pleroma/user.ex | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index c311d48e0..ffc45fd03 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -52,6 +52,14 @@ defmodule Mix.Tasks.Pleroma.User do - `--locked`/`--no-locked` - whether the user's account is locked - `--moderator`/`--no-moderator` - whether the user is a moderator - `--admin`/`--no-admin` - whether the user is an admin + + ## Add tags to a user. + + mix pleroma.user tag NICKNAME TAGS + + ## Delete tags from a user. + + mix pleroma.user untag NICKNAME TAGS """ def run(["new", nickname, email | rest]) do {options, [], []} = @@ -249,6 +257,32 @@ defmodule Mix.Tasks.Pleroma.User do end end + def run(["tag", nickname | tags]) do + Common.start_pleroma() + + with %User{} = user <- User.get_by_nickname(nickname) do + user = user |> User.tag(tags) + + Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}") + else + _ -> + Mix.shell().error("Could not change user tags for #{nickname}") + end + end + + def run(["untag", nickname | tags]) do + Common.start_pleroma() + + with %User{} = user <- User.get_by_nickname(nickname) do + user = user |> User.untag(tags) + + Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}") + else + _ -> + Mix.shell().error("Could not change user tags for #{nickname}") + end + end + def run(["invite"]) do Common.start_pleroma() -- cgit v1.2.3 From 88e32a32ce6a23de12a431c57a6db8251b0e323a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 4 Feb 2019 02:35:46 +0000 Subject: mrf: add initial MRF.TagPolicy engine --- lib/pleroma/web/activity_pub/mrf/tag_policy.ex | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lib/pleroma/web/activity_pub/mrf/tag_policy.ex (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/tag_policy.ex b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex new file mode 100644 index 000000000..4d6dc9c9e --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex @@ -0,0 +1,54 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do + alias Pleroma.User + @behaviour Pleroma.Web.ActivityPub.MRF + + defp get_tags(%User{tags: tags}) when is_list(tags), do: tags + defp get_tags(_), do: [] + + defp process_tag( + "mrf_tag:media-force-nsfw", + %{"type" => "Create", "object" => %{"attachment" => child_attachment} = object} = message + ) + when length(child_attachment) > 0 do + tags = (object["tag"] || []) ++ ["nsfw"] + + object = + object + |> Map.put("tags", tags) + |> Map.put("sensitive", true) + + message = Map.put(message, "object", object) + + {:ok, message} + end + + defp process_tag( + "mrf_tag:media-strip", + %{"type" => "Create", "object" => %{"attachment" => child_attachment} = object} = message + ) + when length(child_attachment) > 0 do + object = Map.delete(object, "attachment") + message = Map.put(message, "object", object) + + {:ok, message} + end + + defp process_tag(_, message), do: {:ok, message} + + @impl true + def filter(%{"actor" => actor} = message) do + User.get_cached_by_ap_id(actor) + |> get_tags() + |> Enum.reduce({:ok, message}, fn + tag, {:ok, message} -> + process_tag(tag, message) + + _, error -> + error + end) + end +end -- cgit v1.2.3 From 084bb8ccd546410c77cf37e1a9850b83e3782e81 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 4 Feb 2019 15:55:20 +0000 Subject: activitypub: mrf: tag policy: implement force-unlisted and sandbox --- lib/pleroma/web/activity_pub/mrf/tag_policy.ex | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/tag_policy.ex b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex index 4d6dc9c9e..e05663371 100644 --- a/lib/pleroma/web/activity_pub/mrf/tag_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex @@ -37,6 +37,54 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do {:ok, message} end + defp process_tag( + "mrf_tag:force-unlisted", + %{"type" => "Create", "to" => to, "cc" => cc, "actor" => actor} = message + ) do + user = User.get_cached_by_ap_id(actor) + + if Enum.member?(to, "https://www.w3.org/ns/activitystreams#Public") do + to = + List.delete(to, "https://www.w3.org/ns/activitystreams#Public") ++ [user.follower_address] + + cc = + List.delete(cc, user.follower_address) ++ ["https://www.w3.org/ns/activitystreams#Public"] + + message = + message + |> Map.put("to", to) + |> Map.put("cc", cc) + + {:ok, message} + else + {:ok, message} + end + end + + defp process_tag( + "mrf_tag:sandbox", + %{"type" => "Create", "to" => to, "cc" => cc, "actor" => actor} = message + ) do + user = User.get_cached_by_ap_id(actor) + + if Enum.member?(to, "https://www.w3.org/ns/activitystreams#Public") or + Enum.member?(cc, "https://www.w3.org/ns/activitystreams#Public") do + to = + List.delete(to, "https://www.w3.org/ns/activitystreams#Public") ++ [user.follower_address] + + cc = List.delete(cc, "https://www.w3.org/ns/activitystreams#Public") + + message = + message + |> Map.put("to", to) + |> Map.put("cc", cc) + + {:ok, message} + else + {:ok, message} + end + end + defp process_tag(_, message), do: {:ok, message} @impl true -- cgit v1.2.3 From 9a69f08e86ce79a36dfe3d1a6f4c20b0a8a0f3c6 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 4 Feb 2019 17:03:34 +0000 Subject: activitypub: mrf: tag policy: add support for processing follow requests --- lib/pleroma/web/activity_pub/mrf/tag_policy.ex | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/tag_policy.ex b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex index e05663371..2af36616f 100644 --- a/lib/pleroma/web/activity_pub/mrf/tag_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex @@ -88,7 +88,20 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do defp process_tag(_, message), do: {:ok, message} @impl true - def filter(%{"actor" => actor} = message) do + def filter(%{"object" => target_actor, "type" => "Follow"} = message) do + User.get_cached_by_ap_id(target_actor) + |> get_tags() + |> Enum.reduce({:ok, message}, fn + tag, {:ok, message} -> + process_tag(tag, message) + + _, error -> + error + end) + end + + @impl true + def filter(%{"actor" => actor, "type" => "Create"} = message) do User.get_cached_by_ap_id(actor) |> get_tags() |> Enum.reduce({:ok, message}, fn @@ -99,4 +112,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do error end) end + + @impl true + def filter(message), do: {:ok, message} end -- cgit v1.2.3 From ff2c28fd6d58b0985e8d59dfbe4ee0d52544e8b3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 4 Feb 2019 17:06:37 +0000 Subject: activitypub: mrf: tag policy: refactor the filtering hook a bit --- lib/pleroma/web/activity_pub/mrf/tag_policy.ex | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/tag_policy.ex b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex index 2af36616f..dd3129707 100644 --- a/lib/pleroma/web/activity_pub/mrf/tag_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex @@ -87,9 +87,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do defp process_tag(_, message), do: {:ok, message} - @impl true - def filter(%{"object" => target_actor, "type" => "Follow"} = message) do - User.get_cached_by_ap_id(target_actor) + def filter_message(actor, message) do + User.get_cached_by_ap_id(actor) |> get_tags() |> Enum.reduce({:ok, message}, fn tag, {:ok, message} -> @@ -101,17 +100,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do end @impl true - def filter(%{"actor" => actor, "type" => "Create"} = message) do - User.get_cached_by_ap_id(actor) - |> get_tags() - |> Enum.reduce({:ok, message}, fn - tag, {:ok, message} -> - process_tag(tag, message) + def filter(%{"object" => target_actor, "type" => "Follow"} = message), + do: filter_message(target_actor, message) - _, error -> - error - end) - end + @impl true + def filter(%{"actor" => actor, "type" => "Create"} = message), + do: filter_message(actor, message) @impl true def filter(message), do: {:ok, message} -- cgit v1.2.3 From 4031c94a59dd36753d96666dadc1b32678d37c74 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Mon, 4 Feb 2019 18:26:56 +0100 Subject: fix hellthread threshold deprecation warning --- lib/pleroma/config/deprecation_warnings.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex index 0eb1833aa..7451fd0a7 100644 --- a/lib/pleroma/config/deprecation_warnings.ex +++ b/lib/pleroma/config/deprecation_warnings.ex @@ -12,8 +12,10 @@ defmodule Pleroma.Config.DeprecationWarnings do You are using the old configuration mechanism for the frontend. Please check config.md. """) end + end - if Pleroma.Config.get(:mrf_hellthread, :threshold) do + def check_hellthread_threshold do + if Pleroma.Config.get([:mrf_hellthread, :threshold]) do Logger.warn(""" !!!DEPRECATION WARNING!!! You are using the old configuration mechanism for the hellthread filter. Please check config.md. @@ -23,5 +25,6 @@ defmodule Pleroma.Config.DeprecationWarnings do def warn do check_frontend_config_mechanism() + check_hellthread_threshold() end end -- cgit v1.2.3 From 64a3993425a062842a6affc7a6faa81c194c5e2b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 4 Feb 2019 17:48:48 +0000 Subject: activitypub: mrf: tag policy: add support for subscription control --- lib/pleroma/web/activity_pub/mrf/tag_policy.ex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/tag_policy.ex b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex index dd3129707..901a0f2b0 100644 --- a/lib/pleroma/web/activity_pub/mrf/tag_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex @@ -85,6 +85,21 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do end end + defp process_tag( + "mrf_tag:disable-remote-subscription", + %{"type" => "Follow", "actor" => actor} = message + ) do + user = User.get_cached_by_ap_id(actor) + + if user.local == true do + {:ok, message} + else + {:reject, nil} + end + end + + defp process_tag("mrf_tag:disable-any-subscription", %{"type" => "Follow"}), do: {:reject, nil} + defp process_tag(_, message), do: {:ok, message} def filter_message(actor, message) do -- cgit v1.2.3 From 7d110be1195dad6f96c8e41ee233daf4563994e3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 4 Feb 2019 19:03:25 +0000 Subject: activitypub: mrf: tag policy: fix force-unlisted and sandbox actions --- lib/pleroma/web/activity_pub/mrf/tag_policy.ex | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/tag_policy.ex b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex index 901a0f2b0..b242e44e6 100644 --- a/lib/pleroma/web/activity_pub/mrf/tag_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/tag_policy.ex @@ -50,10 +50,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do cc = List.delete(cc, user.follower_address) ++ ["https://www.w3.org/ns/activitystreams#Public"] + object = + message["object"] + |> Map.put("to", to) + |> Map.put("cc", cc) + message = message |> Map.put("to", to) |> Map.put("cc", cc) + |> Map.put("object", object) {:ok, message} else @@ -74,10 +80,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do cc = List.delete(cc, "https://www.w3.org/ns/activitystreams#Public") + object = + message["object"] + |> Map.put("to", to) + |> Map.put("cc", cc) + message = message |> Map.put("to", to) |> Map.put("cc", cc) + |> Map.put("object", object) {:ok, message} else -- cgit v1.2.3 From f3c8b02d65f6abc8263c73c10c9028606bfe6894 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 4 Feb 2019 23:47:29 +0100 Subject: Massage index until it actually does the stuff we want. Also makes the index a lot smoler. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 4635e7fcd..b33912721 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -521,7 +521,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_actor(query, _), do: query defp restrict_type(query, %{"type" => type}) when is_binary(type) do - restrict_type(query, %{"type" => [type]}) + from(activity in query, where: fragment("?->>'type' = ?", activity.data, ^type)) end defp restrict_type(query, %{"type" => type}) do -- cgit v1.2.3 From db1165f70f76b5892c4f3a2861db90549e2291a6 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 4 Feb 2019 22:58:29 +0000 Subject: activitypub: c2s: add /api/ap/whoami endpoint for andstatus --- lib/pleroma/web/activity_pub/activity_pub_controller.ex | 8 ++++++++ lib/pleroma/web/router.ex | 1 + 2 files changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 4dea6ab83..2cdf132e2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -198,6 +198,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do end end + def whoami(%{assigns: %{user: %User{} = user}} = conn, _params) do + conn + |> put_resp_header("content-type", "application/activity+json") + |> json(UserView.render("user.json", %{user: user})) + end + + def whoami(_conn, _params), do: {:error, :not_found} + def read_inbox(%{assigns: %{user: user}} = conn, %{"nickname" => nickname} = params) do if nickname == user.nickname do conn diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index c6b4d37ab..7f606ac40 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -454,6 +454,7 @@ defmodule Pleroma.Web.Router do scope "/", Pleroma.Web.ActivityPub do pipe_through([:activitypub_client]) + get("/api/ap/whoami", ActivityPubController, :whoami) get("/users/:nickname/inbox", ActivityPubController, :read_inbox) post("/users/:nickname/outbox", ActivityPubController, :update_outbox) end -- cgit v1.2.3 From e71ab5a10fd19c563ff1627ded58c79ae084f016 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 5 Feb 2019 00:32:49 +0000 Subject: activitypub: transmogrifier: fix bare tags --- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 43725c3db..7151efdeb 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -313,6 +313,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do |> Map.put("tag", combined) end + def fix_tag(%{"tag" => %{} = tag} = object), do: Map.put(object, "tag", [tag]) + def fix_tag(object), do: object # content map usually only has one language so this will do for now. -- cgit v1.2.3 From a2bb5d890d95062e146a4ec6f5923d77ac44a1b9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 5 Feb 2019 05:06:17 +0000 Subject: html: don't attempt to parse nil content --- lib/pleroma/html.ex | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index bf5daa948..b4a4742ee 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -59,6 +59,8 @@ defmodule Pleroma.HTML do end) end + def extract_first_external_url(_, nil), do: {:error, "No content"} + def extract_first_external_url(object, content) do key = "URL|#{object.id}" -- cgit v1.2.3 From 1d94b67e409010e4da20b4d325813390d9d8bb73 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 5 Feb 2019 18:30:27 +0000 Subject: mastodon api: fix rendering of cards without image URLs (closes #597) --- lib/pleroma/web/mastodon_api/views/status_view.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index d1b11d4f1..c0e289ef8 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -192,8 +192,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do page_url = page_url_data |> to_string image_url = - URI.merge(page_url_data, URI.parse(rich_media[:image])) - |> to_string + if rich_media[:image] != nil do + URI.merge(page_url_data, URI.parse(rich_media[:image])) + |> to_string + else + nil + end site_name = rich_media[:site_name] || page_url_data.host -- cgit v1.2.3 From d83dbd9070e8af0ec6c36c1bbd11c417510fa7e3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 5 Feb 2019 20:50:57 +0000 Subject: rich media: parser: reject any data which cannot be explicitly encoded into JSON --- lib/pleroma/web/rich_media/parser.ex | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 32dec9887..38f1cdeec 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -54,22 +54,12 @@ defmodule Pleroma.Web.RichMedia.Parser do {:error, "Found metadata was invalid or incomplete: #{inspect(data)}"} end - defp string_is_valid_unicode(data) when is_binary(data) do - data - |> :unicode.characters_to_binary() - |> clean_string() - end - - defp string_is_valid_unicode(data), do: {:ok, data} - - defp clean_string({:error, _, _}), do: {:error, "Invalid data"} - defp clean_string(data), do: {:ok, data} - defp clean_parsed_data(data) do data - |> Enum.reject(fn {_, val} -> - case string_is_valid_unicode(val) do - {:ok, _} -> false + |> Enum.reject(fn {key, val} -> + with {:ok, _} <- Jason.encode(%{key => val}) do + false + else _ -> true end end) -- cgit v1.2.3 From 398c81f9c8e55b280e64948b4ac63ae51fabd32f Mon Sep 17 00:00:00 2001 From: eugenijm Date: Mon, 4 Feb 2019 05:03:57 +0300 Subject: Add is_admin and is_moderator boolean fields to the user view --- lib/pleroma/web/twitter_api/views/user_view.ex | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index cd7c4349c..2a0cc5c0f 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -105,6 +105,8 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "cover_photo" => User.banner_url(user) |> MediaProxy.url(), "background_image" => image_url(user.info.background) |> MediaProxy.url(), "is_local" => user.local, + "is_moderator" => user.info.is_moderator, + "is_admin" => user.info.is_admin, "locked" => user.info.locked, "default_scope" => user.info.default_scope, "no_rich_text" => user.info.no_rich_text, -- cgit v1.2.3 From 035eaeb9b8702ed233e8bb589a78838efd1f131e Mon Sep 17 00:00:00 2001 From: eugenijm Date: Mon, 4 Feb 2019 15:28:35 +0300 Subject: Allow to configure visibility for admin and moderator badges --- lib/pleroma/user/info.ex | 7 +++++-- .../web/twitter_api/twitter_api_controller.ex | 4 ++-- lib/pleroma/web/twitter_api/views/user_view.ex | 22 ++++++++++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 2186190a0..dcc599e7e 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -23,6 +23,7 @@ defmodule Pleroma.User.Info do field(:ap_enabled, :boolean, default: false) field(:is_moderator, :boolean, default: false) field(:is_admin, :boolean, default: false) + field(:show_role, :boolean, default: true) field(:keys, :string, default: nil) field(:settings, :map, default: nil) field(:magic_key, :string, default: nil) @@ -146,7 +147,8 @@ defmodule Pleroma.User.Info do :banner, :hide_followings, :hide_followers, - :background + :background, + :show_role ]) end @@ -196,7 +198,8 @@ defmodule Pleroma.User.Info do info |> cast(params, [ :is_moderator, - :is_admin + :is_admin, + :show_role ]) end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 5e3fe9352..3dbc49c87 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -24,7 +24,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do conn |> put_view(UserView) - |> render("show.json", %{user: user, token: token}) + |> render("show.json", %{user: user, token: token, for: user}) end def status_update(%{assigns: %{user: user}} = conn, %{"status" => _} = status_data) do @@ -618,7 +618,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do defp build_info_cng(user, params) do info_params = - ["no_rich_text", "locked", "hide_followers", "hide_followings"] + ["no_rich_text", "locked", "hide_followers", "hide_followings", "show_role"] |> Enum.reduce(%{}, fn key, res -> if value = params[key] do Map.put(res, key, value == "true") diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 2a0cc5c0f..ad37baf3a 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -105,8 +105,6 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "cover_photo" => User.banner_url(user) |> MediaProxy.url(), "background_image" => image_url(user.info.background) |> MediaProxy.url(), "is_local" => user.local, - "is_moderator" => user.info.is_moderator, - "is_admin" => user.info.is_admin, "locked" => user.info.locked, "default_scope" => user.info.default_scope, "no_rich_text" => user.info.no_rich_text, @@ -121,6 +119,12 @@ defmodule Pleroma.Web.TwitterAPI.UserView do } } + data = + if(user.info.is_admin || user.info.is_moderator, + do: maybe_with_role(data, user, for_user), + else: data + ) + if assigns[:token] do Map.put(data, "token", token_string(assigns[:token])) else @@ -128,6 +132,20 @@ defmodule Pleroma.Web.TwitterAPI.UserView do end end + defp maybe_with_role(data, %User{id: id} = user, %User{id: id}) do + Map.merge(data, %{"role" => role(user), "show_role" => user.info.show_role}) + end + + defp maybe_with_role(data, %User{info: %{show_role: true}} = user, _user) do + Map.merge(data, %{"role" => role(user)}) + end + + defp maybe_with_role(data, _, _), do: data + + defp role(%User{info: %{:is_admin => true}}), do: "admin" + defp role(%User{info: %{:is_moderator => true}}), do: "moderator" + defp role(_), do: "member" + defp image_url(%{"url" => [%{"href" => href} | _]}), do: href defp image_url(_), do: nil -- cgit v1.2.3 From f753043ce03c71c536b2f1d2fcc3a1304ec3efa3 Mon Sep 17 00:00:00 2001 From: href Date: Wed, 6 Feb 2019 18:42:19 +0100 Subject: Fix if clause in activity_pub user_view --- lib/pleroma/web/activity_pub/views/user_view.ex | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index b9588bee5..1f6b591a5 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -239,6 +239,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do if offset < total do Map.put(map, "next", "#{iri}?page=#{page + 1}") + else + map end end end -- cgit v1.2.3 From 65a4b9fbea6e1ec331e6aae30abe12e6d4494102 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 6 Feb 2019 18:02:15 +0000 Subject: mastodon api: rich media: don't clobber %URI struct with a string --- lib/pleroma/web/mastodon_api/views/status_view.ex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index c0e289ef8..a227d742d 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -182,11 +182,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do end def render("card.json", %{rich_media: rich_media, page_url: page_url}) do + page_url_data = URI.parse(page_url) + page_url_data = if rich_media[:url] != nil do - URI.merge(URI.parse(page_url), URI.parse(rich_media[:url])) + URI.merge(page_url_data, URI.parse(rich_media[:url])) else - page_url + page_url_data end page_url = page_url_data |> to_string -- cgit v1.2.3 From 74518d0b607695a80e25f17de8369f47c7652b17 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 6 Feb 2019 22:34:44 +0000 Subject: hide_followings was renamed to hide_followers in the FE, but never synced up in the BE This was a dirty regex replace which worked on my server --- lib/pleroma/user/info.ex | 4 ++-- lib/pleroma/web/activity_pub/views/user_view.ex | 4 ++-- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 4 ++-- lib/pleroma/web/twitter_api/views/user_view.ex | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index dcc599e7e..9d8779fab 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -32,7 +32,7 @@ defmodule Pleroma.User.Info do field(:hub, :string, default: nil) field(:salmon, :string, default: nil) field(:hide_followers, :boolean, default: false) - field(:hide_followings, :boolean, default: false) + field(:hide_follows, :boolean, default: false) field(:pinned_activities, {:array, :string}, default: []) # Found in the wild @@ -145,7 +145,7 @@ defmodule Pleroma.User.Info do :no_rich_text, :default_scope, :banner, - :hide_followings, + :hide_follows, :hide_followers, :background, :show_role diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 1f6b591a5..43ec2010d 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -86,7 +86,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = from(user in query, select: [:ap_id]) following = Repo.all(query) - collection(following, "#{user.ap_id}/following", page, !user.info.hide_followings) + collection(following, "#{user.ap_id}/following", page, !user.info.hide_follows) |> Map.merge(Utils.make_json_ld_header()) end @@ -99,7 +99,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{user.ap_id}/following", "type" => "OrderedCollection", "totalItems" => length(following), - "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_followings) + "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_follows) } |> Map.merge(Utils.make_json_ld_header()) end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 85769c3d7..b6a3c895c 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -621,7 +621,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do followers = cond do for_user && user.id == for_user.id -> followers - user.info.hide_followings -> [] + user.info.hide_follows -> [] true -> followers end diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 3dbc49c87..b781d981f 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -523,7 +523,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do friends = cond do for_user && user.id == for_user.id -> friends - user.info.hide_followings -> [] + user.info.hide_follows -> [] true -> friends end @@ -618,7 +618,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do defp build_info_cng(user, params) do info_params = - ["no_rich_text", "locked", "hide_followers", "hide_followings", "show_role"] + ["no_rich_text", "locked", "hide_followers", "hide_follows", "show_role"] |> Enum.reduce(%{}, fn key, res -> if value = params[key] do Map.put(res, key, value == "true") diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index ad37baf3a..cc53dfbc2 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -109,7 +109,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "default_scope" => user.info.default_scope, "no_rich_text" => user.info.no_rich_text, "hide_followers" => user.info.hide_followers, - "hide_followings" => user.info.hide_followings, + "hide_follows" => user.info.hide_follows, "fields" => fields, # Pleroma extension -- cgit v1.2.3 From f4ff4ffba2761925dde59ff1989dfdb232732dd7 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Tue, 5 Feb 2019 13:35:24 +0100 Subject: Migration and some boilerplate stuff --- .../web/mastodon_api/mastodon_api_controller.ex | 16 +++++++++++++ lib/pleroma/web/router.ex | 2 ++ lib/pleroma/web/thread_mute.ex | 26 ++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 lib/pleroma/web/thread_mute.ex (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 7f3fbff4a..00b39d76b 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -445,6 +445,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end + def mute_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do + with {:ok, activity} <- Pleroma.Web.ThreadMute.add_mute(user, id) do + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) + end + end + + def unmute_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do + with {:ok, activity} <- Pleroma.Web.ThreadMute.remove_mute(user, id) do + conn + |> put_view(StatusView) + |> try_render("status.json", %{activity: activity, for: user, as: :activity}) + end + end + def notifications(%{assigns: %{user: user}} = conn, params) do notifications = Notification.for_user(user, params) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index c6b4d37ab..3f9759ca9 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -198,6 +198,8 @@ defmodule Pleroma.Web.Router do post("/statuses/:id/unpin", MastodonAPIController, :unpin_status) post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status) post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status) + post("/statuses/:id/mute", MastodonAPIController, :mute_conversation) + post("/statuses/:id/unmute", MastodonAPIController, :unmute_conversation) post("/notifications/clear", MastodonAPIController, :clear_notifications) post("/notifications/dismiss", MastodonAPIController, :dismiss_notification) diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex new file mode 100644 index 000000000..8892155cd --- /dev/null +++ b/lib/pleroma/web/thread_mute.ex @@ -0,0 +1,26 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ThreadMute do + use Ecto.Schema + + alias Pleroma.{Activity, Notification, User} + + schema "thread_mutes" do + field(:user_id, :string) + field(:context, :string) + end + + def add_mute(user, id) do + %{id: user_id} = user + %{data: %{"context" => context}} = Activity.get_by_id(id) + Pleroma.Repo.insert(%Pleroma.Web.ThreadMute{user_id: user_id, context: context}) + end + + def remove_mute(user, id) do + end + + def mute_thread() do + end +end -- cgit v1.2.3 From 2c68cf7e9ee6718f83f2209e6b009b02b50bc8f4 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 7 Feb 2019 22:14:06 +0300 Subject: OAuth2 security fixes: redirect URI validation, "Mastodon-Local" security breach fix. (`POST /api/v1/apps` could create "Mastodon-Local" app wth any redirect_uris, and if that happened before /web/login is accessed for the first time then Pleroma used this externally created record with arbitrary redirect_uris and client_secret known by creator). --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 17 ++++++++--------- lib/pleroma/web/oauth/oauth_controller.ex | 1 + 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index b6a3c895c..dbe7c2554 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -26,12 +26,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do require Logger @httpoison Application.get_env(:pleroma, :httpoison) + @local_mastodon_name "Mastodon-Local" action_fallback(:errors) def create_app(conn, params) do - with cs <- App.register_changeset(%App{}, params) |> IO.inspect(), - {:ok, app} <- Repo.insert(cs) |> IO.inspect() do + with cs <- App.register_changeset(%App{}, params), + false <- cs.changes[:client_name] == @local_mastodon_name, + {:ok, app} <- Repo.insert(cs) do res = %{ id: app.id |> to_string, name: app.client_name, @@ -1154,16 +1156,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end defp get_or_make_app() do - with %App{} = app <- Repo.get_by(App, client_name: "Mastodon-Local") do + find_attrs = %{client_name: @local_mastodon_name, redirect_uris: "."} + + with %App{} = app <- Repo.get_by(App, find_attrs) do {:ok, app} else _e -> - cs = - App.register_changeset(%App{}, %{ - client_name: "Mastodon-Local", - redirect_uris: ".", - scopes: "read,write,follow" - }) + cs = App.register_changeset(%App{}, Map.put(find_attrs, :scopes, "read,write,follow")) Repo.insert(cs) end diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 4d4e85836..8ec963c79 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -37,6 +37,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do true <- Pbkdf2.checkpw(password, user.password_hash), {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, %App{} = app <- Repo.get_by(App, client_id: client_id), + true <- redirect_uri in String.split(app.redirect_uris), {:ok, auth} <- Authorization.create_authorization(app, user) do # Special case: Local MastodonFE. redirect_uri = -- cgit v1.2.3 From 77448de4925f3793bde201a49d204f881163b1b8 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Thu, 7 Feb 2019 22:25:07 +0100 Subject: ugghhhh --- lib/pleroma/web/thread_mute.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex index 8892155cd..50a6219d1 100644 --- a/lib/pleroma/web/thread_mute.ex +++ b/lib/pleroma/web/thread_mute.ex @@ -8,14 +8,14 @@ defmodule Pleroma.Web.ThreadMute do alias Pleroma.{Activity, Notification, User} schema "thread_mutes" do - field(:user_id, :string) + belongs_to(:user, User, type: Pleroma.FlakeId) field(:context, :string) end def add_mute(user, id) do - %{id: user_id} = user + user_id = user.id %{data: %{"context" => context}} = Activity.get_by_id(id) - Pleroma.Repo.insert(%Pleroma.Web.ThreadMute{user_id: user_id, context: context}) + Pleroma.Repo.insert(%Pleroma.Web.ThreadMute{user: user_id, context: context}) end def remove_mute(user, id) do -- cgit v1.2.3 From 7e3ec93ed0047063c54a9e2a31be803e7ec4780f Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Thu, 7 Feb 2019 22:38:54 +0100 Subject: made a silly oopsie --- lib/pleroma/web/thread_mute.ex | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex index 50a6219d1..333b26246 100644 --- a/lib/pleroma/web/thread_mute.ex +++ b/lib/pleroma/web/thread_mute.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.ThreadMute do use Ecto.Schema - alias Pleroma.{Activity, Notification, User} + alias Pleroma.{Activity, Notification, User, Repo} schema "thread_mutes" do belongs_to(:user, User, type: Pleroma.FlakeId) @@ -13,9 +13,8 @@ defmodule Pleroma.Web.ThreadMute do end def add_mute(user, id) do - user_id = user.id %{data: %{"context" => context}} = Activity.get_by_id(id) - Pleroma.Repo.insert(%Pleroma.Web.ThreadMute{user: user_id, context: context}) + Repo.insert(%Pleroma.Web.ThreadMute{}, %{user_id: user.id, context: context}) end def remove_mute(user, id) do -- cgit v1.2.3 From c43f414a79ff9b276b8162ac1ab10e84651e881d Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Thu, 7 Feb 2019 23:44:30 +0100 Subject: Somehow fixed the repo insert [skip-ci] --- lib/pleroma/web/thread_mute.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex index 333b26246..b37dda58b 100644 --- a/lib/pleroma/web/thread_mute.ex +++ b/lib/pleroma/web/thread_mute.ex @@ -14,7 +14,8 @@ defmodule Pleroma.Web.ThreadMute do def add_mute(user, id) do %{data: %{"context" => context}} = Activity.get_by_id(id) - Repo.insert(%Pleroma.Web.ThreadMute{}, %{user_id: user.id, context: context}) + mute = %Pleroma.Web.ThreadMute{user_id: user.id, context: context} + Repo.insert(mute) end def remove_mute(user, id) do -- cgit v1.2.3 From 46aa8c18a211034bc102cfffec61c9cc8c3cdf02 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 8 Feb 2019 12:38:24 +0300 Subject: Add keyword policy --- lib/pleroma/web/activity_pub/mrf/keyword_policy.ex | 74 ++++++++++++++++++++++ lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 28 ++++++++ 2 files changed, 102 insertions(+) create mode 100644 lib/pleroma/web/activity_pub/mrf/keyword_policy.ex (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex new file mode 100644 index 000000000..6e2673e9c --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex @@ -0,0 +1,74 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do + @behaviour Pleroma.Web.ActivityPub.MRF + defp string_matches?(string, pattern) when is_binary(pattern) do + String.contains?(string, pattern) + end + + defp string_matches?(string, pattern) do + String.match?(string, pattern) + end + + defp check_reject(%{"object" => %{"content" => content}} = message) do + if Enum.any?(Pleroma.Config.get([:mrf_keyword, :reject]), fn pattern -> + string_matches?(content, pattern) + end) do + {:reject, nil} + else + {:ok, message} + end + end + + defp check_ftl_removal(%{"to" => to, "object" => %{"content" => content}} = message) do + if "https://www.w3.org/ns/activitystreams#Public" in to and + Enum.any?(Pleroma.Config.get([:mrf_keyword, :ftl_removal]), fn pattern -> + string_matches?(content, pattern) + end) do + to = List.delete(to, "https://www.w3.org/ns/activitystreams#Public") + cc = ["https://www.w3.org/ns/activitystreams#Public" | [message["cc"] || []]] + + message = + message + |> Map.put("to", to) + |> Map.put("cc", cc) + + IO.inspect(message) + {:ok, message} + else + {:ok, message} + end + end + + defp check_replace(%{"object" => %{"content" => content}} = message) do + content = + Enum.reduce(Pleroma.Config.get([:mrf_keyword, :replace]), content, fn {pattern, replacement}, + acc -> + String.replace(acc, pattern, replacement) + end) + + {:ok, put_in(message["object"]["content"], content)} + end + + @impl true + def filter(%{"object" => %{"content" => nil}} = message) do + {:ok, message} + end + + @impl true + def filter(%{"type" => "Create", "object" => %{"content" => _content}} = message) do + with {:ok, message} <- check_reject(message), + {:ok, message} <- check_ftl_removal(message), + {:ok, message} <- check_replace(message) do + {:ok, message} + else + _e -> + {:reject, nil} + end + end + + @impl true + def filter(message), do: {:ok, message} +end diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 21694a5ee..7c24d4761 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -44,6 +44,33 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do Application.get_env(:pleroma, :mrf_simple) |> Enum.into(%{}) + # This horror is needed to convert regex sigils to strings + mrf_keyword = + Application.get_env(:pleroma, :mrf_keyword) + |> Enum.map(fn {key, value} -> + {key, + Enum.map(value, fn + {pattern, replacement} -> + %{ + "pattern" => + if not is_binary(pattern) do + inspect(pattern) + else + pattern + end, + "replacement" => replacement + } + + pattern -> + if not is_binary(pattern) do + inspect(pattern) + else + pattern + end + end)} + end) + |> Enum.into(%{}) + mrf_policies = MRF.get_policies() |> Enum.map(fn policy -> to_string(policy) |> String.split(".") |> List.last() end) @@ -73,6 +100,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do %{ mrf_policies: mrf_policies, mrf_simple: mrf_simple, + mrf_keyword: mrf_keyword, mrf_user_allowlist: mrf_user_allowlist, quarantined_instances: quarantined } -- cgit v1.2.3 From 2174f6eb4f2b9b970e9823fe0846643fb274f009 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 8 Feb 2019 12:48:39 +0300 Subject: Add default config for keyword policy --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 7c24d4761..8c7df5b90 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -46,7 +46,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do # This horror is needed to convert regex sigils to strings mrf_keyword = - Application.get_env(:pleroma, :mrf_keyword) + Application.get_env(:pleroma, :mrf_keyword, []) |> Enum.map(fn {key, value} -> {key, Enum.map(value, fn -- cgit v1.2.3 From 8a0b755c19ef9c896f69de2b1bf22418a3aedf6f Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 8 Feb 2019 13:12:09 +0300 Subject: rename ftl_removal to federated_timeline_removal to keep consistent naming with SimplePolicy --- lib/pleroma/web/activity_pub/mrf/keyword_policy.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex index 6e2673e9c..073b86372 100644 --- a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex @@ -24,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do defp check_ftl_removal(%{"to" => to, "object" => %{"content" => content}} = message) do if "https://www.w3.org/ns/activitystreams#Public" in to and - Enum.any?(Pleroma.Config.get([:mrf_keyword, :ftl_removal]), fn pattern -> + Enum.any?(Pleroma.Config.get([:mrf_keyword, :federated_timeline_removal]), fn pattern -> string_matches?(content, pattern) end) do to = List.delete(to, "https://www.w3.org/ns/activitystreams#Public") -- cgit v1.2.3 From f88dec8b33f96de64c3a9ee212ea265a87608b3b Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 8 Feb 2019 13:16:50 +0300 Subject: What idiot did that? (me) --- lib/pleroma/web/activity_pub/mrf/keyword_policy.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex index 073b86372..8f49d8bfb 100644 --- a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex @@ -28,7 +28,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do string_matches?(content, pattern) end) do to = List.delete(to, "https://www.w3.org/ns/activitystreams#Public") - cc = ["https://www.w3.org/ns/activitystreams#Public" | [message["cc"] || []]] + cc = ["https://www.w3.org/ns/activitystreams#Public" | message["cc"] || []] message = message -- cgit v1.2.3 From 73566592734320bce1262ff7e38199bdcdd2c7c9 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 8 Feb 2019 15:12:13 +0300 Subject: wow --- lib/pleroma/web/activity_pub/mrf/keyword_policy.ex | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex index 8f49d8bfb..ce6d2e529 100644 --- a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex @@ -35,7 +35,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do |> Map.put("to", to) |> Map.put("cc", cc) - IO.inspect(message) {:ok, message} else {:ok, message} -- cgit v1.2.3 From a44e532fb1be973d6974aa9e357096764252796d Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Fri, 8 Feb 2019 13:17:11 +0100 Subject: Added thread unmuting (still a bit buggy maybe) --- lib/pleroma/web/thread_mute.ex | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex index b37dda58b..a0d564e82 100644 --- a/lib/pleroma/web/thread_mute.ex +++ b/lib/pleroma/web/thread_mute.ex @@ -4,8 +4,8 @@ defmodule Pleroma.Web.ThreadMute do use Ecto.Schema - - alias Pleroma.{Activity, Notification, User, Repo} + alias Pleroma.{Activity, Repo, User} + require Ecto.Query schema "thread_mutes" do belongs_to(:user, User, type: Pleroma.FlakeId) @@ -19,8 +19,9 @@ defmodule Pleroma.Web.ThreadMute do end def remove_mute(user, id) do - end - - def mute_thread() do + user_id = Pleroma.FlakeId.from_string(user.id) + %{data: %{"context" => context}} = Activity.get_by_id(id) + Ecto.Query.from(m in "thread_mutes", where: m.user_id == ^user_id and m.context == ^context) + |> Repo.delete_all end end -- cgit v1.2.3 From 5c5b228f21a75c665ab7501ab02765183d00f410 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Fri, 8 Feb 2019 13:17:11 +0100 Subject: Added thread unmuting (still a bit buggy maybe) --- lib/pleroma/web/thread_mute.ex | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex index b37dda58b..a0d564e82 100644 --- a/lib/pleroma/web/thread_mute.ex +++ b/lib/pleroma/web/thread_mute.ex @@ -4,8 +4,8 @@ defmodule Pleroma.Web.ThreadMute do use Ecto.Schema - - alias Pleroma.{Activity, Notification, User, Repo} + alias Pleroma.{Activity, Repo, User} + require Ecto.Query schema "thread_mutes" do belongs_to(:user, User, type: Pleroma.FlakeId) @@ -19,8 +19,9 @@ defmodule Pleroma.Web.ThreadMute do end def remove_mute(user, id) do - end - - def mute_thread() do + user_id = Pleroma.FlakeId.from_string(user.id) + %{data: %{"context" => context}} = Activity.get_by_id(id) + Ecto.Query.from(m in "thread_mutes", where: m.user_id == ^user_id and m.context == ^context) + |> Repo.delete_all end end -- cgit v1.2.3 From bbd0049faef310d1ef9f1f04ecceee3fc924249d Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 9 Feb 2019 13:24:23 +0100 Subject: Respect blocks in mass follow. --- lib/pleroma/user.ex | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 33630ac7c..cd7752554 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -96,12 +96,6 @@ defmodule Pleroma.User do "#{ap_id(user)}/followers" end - def follow_changeset(struct, params \\ %{}) do - struct - |> cast(params, [:following]) - |> validate_required([:following]) - end - def user_info(%User{} = user) do oneself = if user.local, do: 1, else: 0 @@ -307,10 +301,13 @@ defmodule Pleroma.User do end end - @doc "A mass follow for local users. Ignores blocks and has no side effects" + @doc "A mass follow for local users. Respects blocks but does not create activities." @spec follow_all(User.t(), list(User.t())) :: {atom(), User.t()} def follow_all(follower, followeds) do - followed_addresses = Enum.map(followeds, fn %{follower_address: fa} -> fa end) + followed_addresses = + followeds + |> Enum.reject(fn %{ap_id: ap_id} -> ap_id in follower.info.blocks end) + |> Enum.map(fn %{follower_address: fa} -> fa end) q = from(u in User, -- cgit v1.2.3 From 563f04e81bdda320b5a872be63c106fdfa5f42a6 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 9 Feb 2019 13:39:57 +0100 Subject: Do autofollow first. --- lib/pleroma/user.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index cd7752554..361034887 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -250,8 +250,8 @@ defmodule Pleroma.User do @doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)" def register(%Ecto.Changeset{} = changeset) do with {:ok, user} <- Repo.insert(changeset), - {:ok, _} <- try_send_confirmation_email(user), - {:ok, user} <- autofollow_users(user) do + {:ok, user} <- autofollow_users(user), + {:ok, _} <- try_send_confirmation_email(user) do {:ok, user} end end -- cgit v1.2.3 From 8bcfac93a8586c12661427187ba8147dacc28c5b Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 3 Feb 2019 18:44:18 +0100 Subject: Make credo happy --- lib/mix/tasks/pleroma/user.ex | 2 +- lib/pleroma/stats.ex | 2 +- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/common_api/utils.ex | 3 +- lib/pleroma/web/federator/federator.ex | 3 +- .../web/mastodon_api/mastodon_api_controller.ex | 124 +++++++++++---------- lib/pleroma/web/mastodon_api/views/account_view.ex | 6 +- lib/pleroma/web/mastodon_api/views/filter_view.ex | 2 +- lib/pleroma/web/mastodon_api/views/status_view.ex | 8 +- lib/pleroma/web/mastodon_api/websocket_handler.ex | 2 +- lib/pleroma/web/media_proxy/controller.ex | 5 +- lib/pleroma/web/media_proxy/media_proxy.ex | 2 +- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 11 +- lib/pleroma/web/uploader_controller.ex | 2 +- 14 files changed, 84 insertions(+), 90 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index ffc45fd03..5da3edfd2 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -211,7 +211,7 @@ defmodule Mix.Tasks.Pleroma.User do user = Repo.get(User, user.id) - if length(user.following) == 0 do + if Enum.empty?(user.following) do Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}") end else diff --git a/lib/pleroma/stats.ex b/lib/pleroma/stats.ex index b3566ceb6..16cc2856a 100644 --- a/lib/pleroma/stats.ex +++ b/lib/pleroma/stats.ex @@ -23,7 +23,7 @@ defmodule Pleroma.Stats do def schedule_update do spawn(fn -> # 1 hour - Process.sleep(1000 * 60 * 60 * 1) + Process.sleep(1000 * 60 * 60) schedule_update() end) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index b33912721..e1cd2d34c 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -119,7 +119,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do activity.data["object"] |> Map.get("tag", []) |> Enum.filter(fn tag -> is_bitstring(tag) end) - |> Enum.map(fn tag -> Pleroma.Web.Streamer.stream("hashtag:" <> tag, activity) end) + |> Enum.each(fn tag -> Pleroma.Web.Streamer.stream("hashtag:" <> tag, activity) end) if activity.data["object"]["attachment"] != [] do Pleroma.Web.Streamer.stream("public:media", activity) diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 208677bd7..84be1d4a3 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -6,8 +6,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do alias Calendar.Strftime alias Comeonin.Pbkdf2 alias Pleroma.{Activity, Formatter, Object, Repo} - alias Pleroma.User - alias Pleroma.Web + alias Pleroma.{User, Web} alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.Endpoint alias Pleroma.Web.MediaProxy diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index bb7676cf0..6fe3dd2a0 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -25,7 +25,7 @@ defmodule Pleroma.Web.Federator do def start_link do spawn(fn -> # 1 minute - Process.sleep(1000 * 60 * 1) + Process.sleep(1000 * 60) enqueue(:refresh_subscriptions, nil) end) @@ -197,7 +197,6 @@ defmodule Pleroma.Web.Federator do end def handle_cast(m, state) do - IO.inspect("Unknown: #{inspect(m)}, #{inspect(state)}") {:noreply, state} end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index dbe7c2554..74f1bed4d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -4,23 +4,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do use Pleroma.Web, :controller - alias Pleroma.{Repo, Object, Activity, User, Notification, Stats} + alias Pleroma.{Activity, Config, Filter, Notification, Object, Repo, Stats, User} alias Pleroma.Web + alias Pleroma.Web.{CommonAPI, MediaProxy, Push} + alias Push.Subscription alias Pleroma.Web.MastodonAPI.{ - StatusView, AccountView, - MastodonView, - ListView, FilterView, - PushSubscriptionView + ListView, + MastodonView, + PushSubscriptionView, + StatusView } - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Utils - alias Pleroma.Web.CommonAPI - alias Pleroma.Web.OAuth.{Authorization, Token, App} - alias Pleroma.Web.MediaProxy + alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} + alias Pleroma.Web.OAuth.{App, Authorization, Token} import Ecto.Query require Logger @@ -131,7 +130,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do @mastodon_api_level "2.5.0" def masto_instance(conn, _params) do - instance = Pleroma.Config.get(:instance) + instance = Config.get(:instance) response = %{ uri: Web.base_url(), @@ -227,7 +226,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> Map.put("user", user) activities = - ActivityPub.fetch_activities([user.ap_id | user.following], params) + [user.ap_id | user.following] + |> ActivityPub.fetch_activities(params) |> ActivityPub.contain_timeline(user) |> Enum.reverse() @@ -240,14 +240,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do def public_timeline(%{assigns: %{user: user}} = conn, params) do local_only = params["local"] in [true, "True", "true", "1"] - params = + activities = params |> Map.put("type", ["Create", "Announce"]) |> Map.put("local_only", local_only) |> Map.put("blocking_user", user) - - activities = - ActivityPub.fetch_public_activities(params) + |> ActivityPub.fetch_public_activities() |> Enum.reverse() conn @@ -316,6 +314,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do as: :activity ) |> Enum.reverse(), + # credo:disable-for-previous-line Credo.Check.Refactor.PipeChainStart descendants: StatusView.render( "index.json", @@ -324,6 +323,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do as: :activity ) |> Enum.reverse() + # credo:disable-for-previous-line Credo.Check.Refactor.PipeChainStart } json(conn, result) @@ -451,9 +451,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do notifications = Notification.for_user(user, params) result = - Enum.map(notifications, fn x -> - render_notification(user, x) - end) + notifications + |> Enum.map(fn x -> render_notification(user, x) end) |> Enum.filter(& &1) conn @@ -582,7 +581,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do [] |> Enum.map(&String.downcase(&1)) - query_params = + activities = params |> Map.put("type", "Create") |> Map.put("local_only", local_only) @@ -590,9 +589,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> Map.put("tag", tags) |> Map.put("tag_all", tag_all) |> Map.put("tag_reject", tag_reject) - - activities = - ActivityPub.fetch_public_activities(query_params) + |> ActivityPub.fetch_public_activities() |> Enum.reverse() conn @@ -692,7 +689,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do {:ok, _activity} <- ActivityPub.follow(follower, followed), {:ok, follower, followed} <- User.wait_and_refresh( - Pleroma.Config.get([:activitypub, :follow_handshake_timeout]), + Config.get([:activitypub, :follow_handshake_timeout]), follower, followed ) do @@ -821,7 +818,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do tags_path = Web.base_url() <> "/tag/" tags = - String.split(query) + query + |> String.split() |> Enum.uniq() |> Enum.filter(fn tag -> String.starts_with?(tag, "#") end) |> Enum.map(fn tag -> String.slice(tag, 1..-1) end) @@ -843,7 +841,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do statuses = status_search(user, query) tags = - String.split(query) + query + |> String.split() |> Enum.uniq() |> Enum.filter(fn tag -> String.starts_with?(tag, "#") end) |> Enum.map(fn tag -> String.slice(tag, 1..-1) end) @@ -867,14 +866,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def favourites(%{assigns: %{user: user}} = conn, params) do - params = + activities = params |> Map.put("type", "Create") |> Map.put("favorited_by", user.ap_id) |> Map.put("blocking_user", user) - - activities = - ActivityPub.fetch_public_activities(params) + |> ActivityPub.fetch_public_activities() |> Enum.reverse() conn @@ -990,12 +987,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do # we must filter the following list for the user to avoid leaking statuses the user # does not actually have permission to see (for more info, peruse security issue #270). - following_to = + activities = following |> Enum.filter(fn x -> x in user.following end) - - activities = - ActivityPub.fetch_activities_bounded(following_to, following, params) + |> ActivityPub.fetch_activities_bounded(following, params) |> Enum.reverse() conn @@ -1017,7 +1012,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do if user && token do mastodon_emoji = mastodonized_emoji() - limit = Pleroma.Config.get([:instance, :limit]) + limit = Config.get([:instance, :limit]) accounts = Map.put(%{}, user.id, AccountView.render("account.json", %{user: user, for: user})) @@ -1041,8 +1036,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do max_toot_chars: limit }, rights: %{ - delete_others_notice: !!user.info.is_moderator, - admin: !!user.info.is_admin + delete_others_notice: present?(user.info.is_moderator), + admin: present?(user.info.is_admin) }, compose: %{ me: "#{user.id}", @@ -1234,7 +1229,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def get_filters(%{assigns: %{user: user}} = conn, _) do - filters = Pleroma.Filter.get_filters(user) + filters = Filter.get_filters(user) res = FilterView.render("filters.json", filters: filters) json(conn, res) end @@ -1243,7 +1238,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do %{assigns: %{user: user}} = conn, %{"phrase" => phrase, "context" => context} = params ) do - query = %Pleroma.Filter{ + query = %Filter{ user_id: user.id, phrase: phrase, context: context, @@ -1252,13 +1247,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do # expires_at } - {:ok, response} = Pleroma.Filter.create(query) + {:ok, response} = Filter.create(query) res = FilterView.render("filter.json", filter: response) json(conn, res) end def get_filter(%{assigns: %{user: user}} = conn, %{"id" => filter_id}) do - filter = Pleroma.Filter.get(filter_id, user) + filter = Filter.get(filter_id, user) res = FilterView.render("filter.json", filter: filter) json(conn, res) end @@ -1267,7 +1262,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do %{assigns: %{user: user}} = conn, %{"phrase" => phrase, "context" => context, "id" => filter_id} = params ) do - query = %Pleroma.Filter{ + query = %Filter{ user_id: user.id, filter_id: filter_id, phrase: phrase, @@ -1277,32 +1272,32 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do # expires_at } - {:ok, response} = Pleroma.Filter.update(query) + {:ok, response} = Filter.update(query) res = FilterView.render("filter.json", filter: response) json(conn, res) end def delete_filter(%{assigns: %{user: user}} = conn, %{"id" => filter_id}) do - query = %Pleroma.Filter{ + query = %Filter{ user_id: user.id, filter_id: filter_id } - {:ok, _} = Pleroma.Filter.delete(query) + {:ok, _} = Filter.delete(query) json(conn, %{}) end def create_push_subscription(%{assigns: %{user: user, token: token}} = conn, params) do - true = Pleroma.Web.Push.enabled() - Pleroma.Web.Push.Subscription.delete_if_exists(user, token) - {:ok, subscription} = Pleroma.Web.Push.Subscription.create(user, token, params) + true = Push.enabled() + Subscription.delete_if_exists(user, token) + {:ok, subscription} = Subscription.create(user, token, params) view = PushSubscriptionView.render("push_subscription.json", subscription: subscription) json(conn, view) end def get_push_subscription(%{assigns: %{user: user, token: token}} = conn, _params) do - true = Pleroma.Web.Push.enabled() - subscription = Pleroma.Web.Push.Subscription.get(user, token) + true = Push.enabled() + subscription = Subscription.get(user, token) view = PushSubscriptionView.render("push_subscription.json", subscription: subscription) json(conn, view) end @@ -1311,15 +1306,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do %{assigns: %{user: user, token: token}} = conn, params ) do - true = Pleroma.Web.Push.enabled() - {:ok, subscription} = Pleroma.Web.Push.Subscription.update(user, token, params) + true = Push.enabled() + {:ok, subscription} = Subscription.update(user, token, params) view = PushSubscriptionView.render("push_subscription.json", subscription: subscription) json(conn, view) end def delete_push_subscription(%{assigns: %{user: user, token: token}} = conn, _params) do - true = Pleroma.Web.Push.enabled() - {:ok, _response} = Pleroma.Web.Push.Subscription.delete(user, token) + true = Push.enabled() + {:ok, _response} = Subscription.delete(user, token) json(conn, %{}) end @@ -1330,17 +1325,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def suggestions(%{assigns: %{user: user}} = conn, _) do - suggestions = Pleroma.Config.get(:suggestions) + suggestions = Config.get(:suggestions) if Keyword.get(suggestions, :enabled, false) do api = Keyword.get(suggestions, :third_party_engine, "") timeout = Keyword.get(suggestions, :timeout, 5000) limit = Keyword.get(suggestions, :limit, 23) - host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host]) + host = Config.get([Pleroma.Web.Endpoint, :url, :host]) user = user.nickname - url = String.replace(api, "{{host}}", host) |> String.replace("{{user}}", user) + + url = + api + |> String.replace("{{host}}", host) + |> String.replace("{{user}}", user) with {:ok, %{status: 200, body: body}} <- @httpoison.get( @@ -1353,8 +1352,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do ] ), {:ok, data} <- Jason.decode(body) do - data2 = - Enum.slice(data, 0, limit) + data = + data + |> Enum.slice(0, limit) |> Enum.map(fn x -> Map.put( x, @@ -1373,7 +1373,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end) conn - |> json(data2) + |> json(data) else e -> Logger.error("Could not retrieve suggestions at fetch #{url}, #{inspect(e)}") end @@ -1416,4 +1416,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do |> put_status(501) |> json(%{error: "Can't display this activity"}) end + + defp present?(nil), do: false + defp present?(false), do: false + defp present?(_), do: true end diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 0ba4289da..0235f5d5b 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -4,11 +4,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do use Pleroma.Web, :view - alias Pleroma.User - alias Pleroma.Web.MastodonAPI.AccountView + + alias Pleroma.{HTML, User} alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MediaProxy - alias Pleroma.HTML def render("accounts.json", %{users: users} = opts) do users diff --git a/lib/pleroma/web/mastodon_api/views/filter_view.ex b/lib/pleroma/web/mastodon_api/views/filter_view.ex index 1052a449d..a685bc7b6 100644 --- a/lib/pleroma/web/mastodon_api/views/filter_view.ex +++ b/lib/pleroma/web/mastodon_api/views/filter_view.ex @@ -4,8 +4,8 @@ defmodule Pleroma.Web.MastodonAPI.FilterView do use Pleroma.Web, :view - alias Pleroma.Web.MastodonAPI.FilterView alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.MastodonAPI.FilterView def render("filters.json", %{filters: filters} = opts) do render_many(filters, FilterView, "filter.json", opts) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index a227d742d..cd030fe54 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -5,14 +5,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do use Pleroma.Web, :view - alias Pleroma.Activity - alias Pleroma.HTML - alias Pleroma.Repo - alias Pleroma.User + alias Pleroma.{Activity, HTML, Repo, User} alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.MastodonAPI.{AccountView, StatusView} alias Pleroma.Web.MediaProxy - alias Pleroma.Web.MastodonAPI.AccountView - alias Pleroma.Web.MastodonAPI.StatusView # TODO: Add cached version. defp get_replied_to_activities(activities) do diff --git a/lib/pleroma/web/mastodon_api/websocket_handler.ex b/lib/pleroma/web/mastodon_api/websocket_handler.ex index c0254c8e6..ce42338a7 100644 --- a/lib/pleroma/web/mastodon_api/websocket_handler.ex +++ b/lib/pleroma/web/mastodon_api/websocket_handler.ex @@ -6,7 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do require Logger alias Pleroma.Web.OAuth.Token - alias Pleroma.{User, Repo} + alias Pleroma.{Repo, User} @behaviour :cowboy_websocket_handler diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex index de79cad73..c0552d89f 100644 --- a/lib/pleroma/web/media_proxy/controller.ex +++ b/lib/pleroma/web/media_proxy/controller.ex @@ -4,11 +4,12 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do use Pleroma.Web, :controller - alias Pleroma.{Web.MediaProxy, ReverseProxy} + alias Pleroma.ReverseProxy + alias Pleroma.Web.MediaProxy @default_proxy_opts [max_body_length: 25 * 1_048_576, http: [follow_redirect: true]] - def remote(conn, params = %{"sig" => sig64, "url" => url64}) do + def remote(conn, %{"sig" => sig64, "url" => url64} = params) do with config <- Pleroma.Config.get([:media_proxy], []), true <- Keyword.get(config, :enabled, false), {:ok, url} <- MediaProxy.decode_url(sig64, url64), diff --git a/lib/pleroma/web/media_proxy/media_proxy.ex b/lib/pleroma/web/media_proxy/media_proxy.ex index e1eb1472d..1e9da7283 100644 --- a/lib/pleroma/web/media_proxy/media_proxy.ex +++ b/lib/pleroma/web/media_proxy/media_proxy.ex @@ -9,7 +9,7 @@ defmodule Pleroma.Web.MediaProxy do def url(""), do: nil - def url(url = "/" <> _), do: url + def url("/" <> _ = url), do: url def url(url) do config = Application.get_env(:pleroma, :media_proxy, []) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 21694a5ee..e81de7bbd 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -5,10 +5,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do use Pleroma.Web, :controller - alias Pleroma.Stats - alias Pleroma.Web - alias Pleroma.{User, Repo} - alias Pleroma.Config + alias Pleroma.{Config, Repo, Stats, User, Web} alias Pleroma.Web.ActivityPub.MRF plug(Pleroma.Web.FederatingPlug) @@ -32,7 +29,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do # returns a nodeinfo 2.0 map, since 2.1 just adds a repository field # under software. - def raw_nodeinfo() do + def raw_nodeinfo do instance = Application.get_env(:pleroma, :instance) media_proxy = Application.get_env(:pleroma, :media_proxy) suggestions = Application.get_env(:pleroma, :suggestions) @@ -66,10 +63,8 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do Config.get([:mrf_user_allowlist], []) |> Enum.into(%{}, fn {k, v} -> {k, length(v)} end) - mrf_transparency = Keyword.get(instance, :mrf_transparency) - federation_response = - if mrf_transparency do + if Keyword.get(instance, :mrf_transparency) do %{ mrf_policies: mrf_policies, mrf_simple: mrf_simple, diff --git a/lib/pleroma/web/uploader_controller.ex b/lib/pleroma/web/uploader_controller.ex index 6c28d1197..5d8a77346 100644 --- a/lib/pleroma/web/uploader_controller.ex +++ b/lib/pleroma/web/uploader_controller.ex @@ -3,7 +3,7 @@ defmodule Pleroma.Web.UploaderController do alias Pleroma.Uploaders.Uploader - def callback(conn, params = %{"upload_path" => upload_path}) do + def callback(conn, %{"upload_path" => upload_path} = params) do process_callback(conn, :global.whereis_name({Uploader, upload_path}), params) end -- cgit v1.2.3 From 106f4e7a0fd70ab04a116238af0322e991cc88c6 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 6 Feb 2019 20:19:39 +0100 Subject: Credo fixes: parameter consistency --- lib/pleroma/flake_id.ex | 4 ++-- lib/pleroma/gopher/server.ex | 2 +- lib/pleroma/plugs/instance_static.ex | 2 +- lib/pleroma/plugs/uploaded_media.ex | 2 +- lib/pleroma/upload.ex | 2 +- lib/pleroma/upload/filter/dedupe.ex | 2 +- lib/pleroma/uploaders/s3.ex | 2 +- lib/pleroma/web/common_api/utils.ex | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex index 69ab8ccf9..9f098ce33 100644 --- a/lib/pleroma/flake_id.ex +++ b/lib/pleroma/flake_id.ex @@ -27,7 +27,7 @@ defmodule Pleroma.FlakeId do Kernel.to_string(id) end - def to_string(flake = <<_::integer-size(64), _::integer-size(48), _::integer-size(16)>>) do + def to_string(<<_::integer-size(64), _::integer-size(48), _::integer-size(16)>> = flake) do encode_base62(flake) end @@ -42,7 +42,7 @@ defmodule Pleroma.FlakeId do def from_string(unquote(Kernel.to_string(i))), do: <<0::integer-size(128)>> end - def from_string(flake = <<_::integer-size(128)>>), do: flake + def from_string(<<_::integer-size(128)>> = flake), do: flake def from_string(string) when is_binary(string) and byte_size(string) < 18 do case Integer.parse(string) do diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index 336142e9b..b47a0697d 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -47,7 +47,7 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do {:ok, pid} end - def init(ref, socket, transport, _Opts = []) do + def init(ref, socket, transport, [] = _Opts) do :ok = :ranch.accept_ack(ref) loop(socket, transport) end diff --git a/lib/pleroma/plugs/instance_static.ex b/lib/pleroma/plugs/instance_static.ex index 11f108de7..41125921a 100644 --- a/lib/pleroma/plugs/instance_static.ex +++ b/lib/pleroma/plugs/instance_static.ex @@ -33,7 +33,7 @@ defmodule Pleroma.Plugs.InstanceStatic do for only <- @only do at = Plug.Router.Utils.split("/") - def call(conn = %{request_path: "/" <> unquote(only) <> _}, opts) do + def call(%{request_path: "/" <> unquote(only) <> _} = conn, opts) do call_static( conn, opts, diff --git a/lib/pleroma/plugs/uploaded_media.ex b/lib/pleroma/plugs/uploaded_media.ex index be53ac00c..13aa8641a 100644 --- a/lib/pleroma/plugs/uploaded_media.ex +++ b/lib/pleroma/plugs/uploaded_media.ex @@ -23,7 +23,7 @@ defmodule Pleroma.Plugs.UploadedMedia do %{static_plug_opts: static_plug_opts} end - def call(conn = %{request_path: <<"/", @path, "/", file::binary>>}, opts) do + def call(%{request_path: <<"/", @path, "/", file::binary>>} = conn, opts) do config = Pleroma.Config.get([Pleroma.Upload]) with uploader <- Keyword.fetch!(config, :uploader), diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index ce2a1b696..91a5db8c5 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -180,7 +180,7 @@ defmodule Pleroma.Upload do end # For Mix.Tasks.MigrateLocalUploads - defp prepare_upload(upload = %__MODULE__{tempfile: path}, _opts) do + defp prepare_upload(%__MODULE__{tempfile: path} = upload, _opts) do with {:ok, content_type} <- Pleroma.MIME.file_mime_type(path) do {:ok, %__MODULE__{upload | content_type: content_type}} end diff --git a/lib/pleroma/upload/filter/dedupe.ex b/lib/pleroma/upload/filter/dedupe.ex index 8fcce320f..e4c225833 100644 --- a/lib/pleroma/upload/filter/dedupe.ex +++ b/lib/pleroma/upload/filter/dedupe.ex @@ -6,7 +6,7 @@ defmodule Pleroma.Upload.Filter.Dedupe do @behaviour Pleroma.Upload.Filter alias Pleroma.Upload - def filter(upload = %Upload{name: name}) do + def filter(%Upload{name: name} = upload) do extension = String.split(name, ".") |> List.last() shasum = :crypto.hash(:sha256, File.read!(upload.tempfile)) |> Base.encode16(case: :lower) filename = shasum <> "." <> extension diff --git a/lib/pleroma/uploaders/s3.ex b/lib/pleroma/uploaders/s3.ex index fbd89616c..0038ba01f 100644 --- a/lib/pleroma/uploaders/s3.ex +++ b/lib/pleroma/uploaders/s3.ex @@ -27,7 +27,7 @@ defmodule Pleroma.Uploaders.S3 do ])}} end - def put_file(upload = %Pleroma.Upload{}) do + def put_file(%Pleroma.Upload{} = upload) do config = Pleroma.Config.get([__MODULE__]) bucket = Keyword.get(config, :bucket) diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 84be1d4a3..be90b60bc 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -94,7 +94,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do def make_context(%Activity{data: %{"context" => context}}), do: context def make_context(_), do: Utils.generate_context_id() - def maybe_add_attachments(text, _attachments, _no_links = true), do: text + def maybe_add_attachments(text, _attachments, true = _no_links), do: text def maybe_add_attachments(text, attachments, _no_links) do add_attachments(text, attachments) -- cgit v1.2.3 From 60ea29dfe64c9b3c4e7b7bfa8aef0dfed4d37f3f Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 6 Feb 2019 20:20:02 +0100 Subject: Credo fixes: alias grouping/ordering --- lib/pleroma/captcha/captcha.ex | 3 +-- lib/pleroma/formatter.ex | 4 +--- lib/pleroma/gopher/server.ex | 5 +---- lib/pleroma/html.ex | 1 + lib/pleroma/instances/instance.ex | 4 +--- lib/pleroma/plugs/user_fetcher_plug.ex | 4 ++-- lib/pleroma/user_invite_token.ex | 3 +-- lib/pleroma/web/activity_pub/activity_pub.ex | 6 +++--- lib/pleroma/web/activity_pub/activity_pub_controller.ex | 5 +---- lib/pleroma/web/activity_pub/transmogrifier.ex | 8 ++------ lib/pleroma/web/activity_pub/views/user_view.ex | 12 +++++------- lib/pleroma/web/common_api/common_api.ex | 3 +-- lib/pleroma/web/common_api/utils.ex | 3 +-- lib/pleroma/web/federator/federator.ex | 10 ++++------ lib/pleroma/web/http_signatures/http_signatures.ex | 4 ++-- lib/pleroma/web/metadata/opengraph.ex | 5 ++--- lib/pleroma/web/ostatus/feed_representer.ex | 5 ++--- lib/pleroma/web/ostatus/handlers/note_handler.ex | 3 +-- lib/pleroma/web/ostatus/ostatus.ex | 3 +-- lib/pleroma/web/ostatus/ostatus_controller.ex | 10 ++++------ lib/pleroma/web/salmon/salmon.ex | 5 +++-- lib/pleroma/web/twitter_api/controllers/util_controller.ex | 10 +++++----- .../web/twitter_api/representers/activity_representer.ex | 6 ++---- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 9 ++++----- lib/pleroma/web/twitter_api/views/activity_view.ex | 14 +++----------- lib/pleroma/web/twitter_api/views/notification_view.ex | 3 +-- lib/pleroma/web/twitter_api/views/user_view.ex | 4 +--- lib/pleroma/web/websub/websub.ex | 3 +-- 28 files changed, 57 insertions(+), 98 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index 0207bcbea..f70f5a191 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -3,8 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Captcha do - alias Plug.Crypto.KeyGenerator - alias Plug.Crypto.MessageEncryptor + alias Plug.Crypto.{KeyGenerator, MessageEncryptor} alias Calendar.DateTime use GenServer diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 386096a52..8a8af266c 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -3,10 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Formatter do - alias Pleroma.User + alias Pleroma.{Emoji, HTML, User} alias Pleroma.Web.MediaProxy - alias Pleroma.HTML - alias Pleroma.Emoji @tag_regex ~r/((?<=[^&])|\A)(\#)(\w+)/u @markdown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/ diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index b47a0697d..a284b3c61 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -37,10 +37,7 @@ end defmodule Pleroma.Gopher.Server.ProtocolHandler do alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.User - alias Pleroma.Activity - alias Pleroma.Repo - alias Pleroma.HTML + alias Pleroma.{Activity, HTML, User, Repo} def start_link(ref, socket, transport, opts) do pid = spawn_link(__MODULE__, :init, [ref, socket, transport, opts]) diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index b4a4742ee..0fd41ffb8 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -125,6 +125,7 @@ defmodule Pleroma.HTML.Scrubber.Default do @doc "The default HTML scrubbing policy: no " require HtmlSanitizeEx.Scrubber.Meta + alias HtmlSanitizeEx.Scrubber.Meta @markup Application.get_env(:pleroma, :markup) diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index 4a4ca26dd..bab8e0564 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -1,15 +1,13 @@ defmodule Pleroma.Instances.Instance do @moduledoc "Instance." - alias Pleroma.Instances + alias Pleroma.{Instances, Repo} alias Pleroma.Instances.Instance use Ecto.Schema import Ecto.{Query, Changeset} - alias Pleroma.Repo - schema "instances" do field(:host, :string) field(:unreachable_since, :naive_datetime) diff --git a/lib/pleroma/plugs/user_fetcher_plug.ex b/lib/pleroma/plugs/user_fetcher_plug.ex index f874e2f95..6d6ab0926 100644 --- a/lib/pleroma/plugs/user_fetcher_plug.ex +++ b/lib/pleroma/plugs/user_fetcher_plug.ex @@ -3,9 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.UserFetcherPlug do + alias Pleroma.{User, Repo} + import Plug.Conn - alias Pleroma.Repo - alias Pleroma.User def init(options) do options diff --git a/lib/pleroma/user_invite_token.ex b/lib/pleroma/user_invite_token.ex index 5a448114c..8e449444c 100644 --- a/lib/pleroma/user_invite_token.ex +++ b/lib/pleroma/user_invite_token.ex @@ -7,8 +7,7 @@ defmodule Pleroma.UserInviteToken do import Ecto.Changeset - alias Pleroma.UserInviteToken - alias Pleroma.Repo + alias Pleroma.{UserInviteToken, Repo} schema "user_invite_tokens" do field(:token, :string) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index e1cd2d34c..6028e96a9 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -5,11 +5,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do alias Pleroma.{Activity, Repo, Object, Upload, User, Notification, Instances} alias Pleroma.Web.ActivityPub.{Transmogrifier, MRF} - alias Pleroma.Web.WebFinger - alias Pleroma.Web.Federator - alias Pleroma.Web.OStatus + alias Pleroma.Web.{WebFinger, Federator, OStatus} + import Ecto.Query import Pleroma.Web.ActivityPub.Utils + require Logger @httpoison Application.get_env(:pleroma, :httpoison) diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 2cdf132e2..01b521051 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -7,10 +7,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do alias Pleroma.{Activity, User, Object} alias Pleroma.Web.ActivityPub.{ObjectView, UserView} - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Relay - alias Pleroma.Web.ActivityPub.Utils - alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Transmogrifier, Utils} alias Pleroma.Web.Federator require Logger diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 7151efdeb..edfbc9bb2 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -6,12 +6,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do @moduledoc """ A module to handle coding from internal to wire ActivityPub and back. """ - alias Pleroma.User - alias Pleroma.Object - alias Pleroma.Activity - alias Pleroma.Repo - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.{Activity, User, Object, Repo} + alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} import Ecto.Query diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 43ec2010d..ba3aea1a6 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -4,13 +4,11 @@ defmodule Pleroma.Web.ActivityPub.UserView do use Pleroma.Web, :view - alias Pleroma.Web.Salmon - alias Pleroma.Web.WebFinger - alias Pleroma.User - alias Pleroma.Repo - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Transmogrifier - alias Pleroma.Web.ActivityPub.Utils + + alias Pleroma.Web.{WebFinger, Salmon} + alias Pleroma.{User, Repo} + alias Pleroma.Web.ActivityPub.{ActivityPub, Transmogrifier, Utils} + import Ecto.Query # the instance itself is not a Person, but instead an Application diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 7084da6de..4388396cf 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -4,8 +4,7 @@ defmodule Pleroma.Web.CommonAPI do alias Pleroma.{User, Repo, Activity, Object} - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} alias Pleroma.Formatter import Pleroma.Web.CommonAPI.Utils diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index be90b60bc..e50d63d77 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -7,9 +7,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do alias Comeonin.Pbkdf2 alias Pleroma.{Activity, Formatter, Object, Repo} alias Pleroma.{User, Web} + alias Pleroma.Web.{Endpoint, MediaProxy} alias Pleroma.Web.ActivityPub.Utils - alias Pleroma.Web.Endpoint - alias Pleroma.Web.MediaProxy # This is a hack for twidere. def get_by_id_or_ap_id(id) do diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index 6fe3dd2a0..71648e8c7 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -4,15 +4,13 @@ defmodule Pleroma.Web.Federator do use GenServer - alias Pleroma.User - alias Pleroma.Activity + + alias Pleroma.{Activity, User} alias Pleroma.Web.{WebFinger, Websub, Salmon} + alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Transmogrifier, Utils} alias Pleroma.Web.Federator.RetryQueue - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Relay - alias Pleroma.Web.ActivityPub.Transmogrifier - alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.OStatus + require Logger @websub Application.get_env(:pleroma, :websub) diff --git a/lib/pleroma/web/http_signatures/http_signatures.ex b/lib/pleroma/web/http_signatures/http_signatures.ex index e81f9e27a..5ff93663e 100644 --- a/lib/pleroma/web/http_signatures/http_signatures.ex +++ b/lib/pleroma/web/http_signatures/http_signatures.ex @@ -5,8 +5,8 @@ # https://tools.ietf.org/html/draft-cavage-http-signatures-08 defmodule Pleroma.Web.HTTPSignatures do alias Pleroma.User - alias Pleroma.Web.ActivityPub.Utils - alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} + require Logger def split_signature(sig) do diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 30333785e..479c9d20d 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -3,10 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.OpenGraph do - alias Pleroma.Web.Metadata.Providers.Provider - alias Pleroma.Web.Metadata alias Pleroma.{HTML, Formatter, User} - alias Pleroma.Web.MediaProxy + alias Pleroma.Web.{Metadata, MediaProxy} + alias Pleroma.Web.Metadata.Providers.Provider @behaviour Provider diff --git a/lib/pleroma/web/ostatus/feed_representer.ex b/lib/pleroma/web/ostatus/feed_representer.ex index 934d4042f..fd530307c 100644 --- a/lib/pleroma/web/ostatus/feed_representer.ex +++ b/lib/pleroma/web/ostatus/feed_representer.ex @@ -3,10 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.FeedRepresenter do - alias Pleroma.Web.OStatus - alias Pleroma.Web.OStatus.{UserRepresenter, ActivityRepresenter} alias Pleroma.User - alias Pleroma.Web.MediaProxy + alias Pleroma.Web.{OStatus, MediaProxy} + alias Pleroma.Web.OStatus.{UserRepresenter, ActivityRepresenter} def to_simple_form(user, activities, _users) do most_recent_update = diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex index c5b3e8d97..5bbb86f87 100644 --- a/lib/pleroma/web/ostatus/handlers/note_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex @@ -6,8 +6,7 @@ defmodule Pleroma.Web.OStatus.NoteHandler do require Logger alias Pleroma.Web.{XML, OStatus} alias Pleroma.{Object, Activity} - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} alias Pleroma.Web.CommonAPI @doc """ diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index a20ca17bb..e1213923e 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -10,10 +10,9 @@ defmodule Pleroma.Web.OStatus do require Logger alias Pleroma.{Repo, User, Web, Object, Activity} - alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.{ActivityPub, Transmogrifier} alias Pleroma.Web.{WebFinger, Websub} alias Pleroma.Web.OStatus.{FollowHandler, UnfollowHandler, NoteHandler, DeleteHandler} - alias Pleroma.Web.ActivityPub.Transmogrifier def is_representable?(%Activity{data: data}) do object = Object.normalize(data["object"]) diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 302ff38a4..ed0df620b 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -5,13 +5,11 @@ defmodule Pleroma.Web.OStatus.OStatusController do use Pleroma.Web, :controller - alias Pleroma.{User, Activity, Object} - alias Pleroma.Web.OStatus.{FeedRepresenter, ActivityRepresenter} - alias Pleroma.Web.{OStatus, Federator} + alias Pleroma.{Activity, Object, User} + alias Pleroma.Web.ActivityPub.{ActivityPub, ActivityPubController, ObjectView} + alias Pleroma.Web.OStatus.{ActivityRepresenter, FeedRepresenter} + alias Pleroma.Web.{Federator, OStatus} alias Pleroma.Web.XML - alias Pleroma.Web.ActivityPub.ObjectView - alias Pleroma.Web.ActivityPub.ActivityPubController - alias Pleroma.Web.ActivityPub.ActivityPub plug(Pleroma.Web.FederatingPlug when action in [:salmon_incoming]) diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index b1c2dc7fa..fb08d645b 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -6,10 +6,11 @@ defmodule Pleroma.Web.Salmon do @httpoison Application.get_env(:pleroma, :httpoison) use Bitwise - alias Pleroma.Instances + + alias Pleroma.{Instances, User} alias Pleroma.Web.XML alias Pleroma.Web.OStatus.ActivityRepresenter - alias Pleroma.User + require Logger def decode(salmon) do diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index b347faa71..bf8d7e5aa 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -4,14 +4,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do use Pleroma.Web, :controller + require Logger - alias Pleroma.Web - alias Pleroma.Web.OStatus - alias Pleroma.Web.WebFinger - alias Pleroma.Web.CommonAPI + alias Comeonin.Pbkdf2 + alias Pleroma.{Emoji, PasswordResetToken, User, Repo} + alias Pleroma.Web + alias Pleroma.Web.{CommonAPI, OStatus, WebFinger} alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.{Repo, PasswordResetToken, User, Emoji} def show_password_reset(conn, %{"token" => token}) do with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}), diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index c4025cbd7..a5fec88f7 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -7,11 +7,9 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter - alias Pleroma.{Activity, User} - alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView} + alias Pleroma.{Activity, Formatter, HTML, User} + alias Pleroma.Web.TwitterAPI.{ActivityView, TwitterAPI, UserView} alias Pleroma.Web.CommonAPI.Utils - alias Pleroma.Formatter - alias Pleroma.HTML alias Pleroma.Web.MastodonAPI.StatusView defp user_by_ap_id(user_list, ap_id) do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index b781d981f..c0081bf6e 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -7,12 +7,11 @@ defmodule Pleroma.Web.TwitterAPI.Controller do import Pleroma.Web.ControllerHelper, only: [json_response: 3] - alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView} - alias Pleroma.Web.CommonAPI - alias Pleroma.{Repo, Activity, Object, User, Notification} - alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.Web.ActivityPub.Utils alias Ecto.Changeset + alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.TwitterAPI.{ActivityView, NotificationView, TwitterAPI, UserView} + alias Pleroma.{Activity, Object, Notification, Repo, User} require Logger diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index d0d1221c3..dbcb732fe 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -4,19 +4,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do use Pleroma.Web, :view + alias Pleroma.{Activity, Formatter, HTML, Object, Repo, User} alias Pleroma.Web.CommonAPI.Utils - alias Pleroma.User - alias Pleroma.Web.TwitterAPI.UserView - alias Pleroma.Web.TwitterAPI.ActivityView - alias Pleroma.Web.TwitterAPI.TwitterAPI - alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter alias Pleroma.Web.MastodonAPI.StatusView - alias Pleroma.Activity - alias Pleroma.HTML - alias Pleroma.Object - alias Pleroma.User - alias Pleroma.Repo - alias Pleroma.Formatter + alias Pleroma.Web.TwitterAPI.{ActivityView, TwitterAPI, UserView} + alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter import Ecto.Query require Logger diff --git a/lib/pleroma/web/twitter_api/views/notification_view.ex b/lib/pleroma/web/twitter_api/views/notification_view.ex index d6a1c0a4d..414ed4731 100644 --- a/lib/pleroma/web/twitter_api/views/notification_view.ex +++ b/lib/pleroma/web/twitter_api/views/notification_view.ex @@ -6,8 +6,7 @@ defmodule Pleroma.Web.TwitterAPI.NotificationView do use Pleroma.Web, :view alias Pleroma.{Notification, User} alias Pleroma.Web.CommonAPI.Utils - alias Pleroma.Web.TwitterAPI.UserView - alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.{ActivityView, UserView} defp get_user(ap_id, opts) do cond do diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index cc53dfbc2..3cde3bc1b 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -4,11 +4,9 @@ defmodule Pleroma.Web.TwitterAPI.UserView do use Pleroma.Web, :view - alias Pleroma.User - alias Pleroma.Formatter + alias Pleroma.{Formatter, HTML, User} alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MediaProxy - alias Pleroma.HTML def render("show.json", %{user: user = %User{}} = assigns) do render_one(user, Pleroma.Web.TwitterAPI.UserView, "user.json", assigns) diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index 90ba79962..de6508f52 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -4,8 +4,7 @@ defmodule Pleroma.Web.Websub do alias Ecto.Changeset - alias Pleroma.Repo - alias Pleroma.Instances + alias Pleroma.{Instances, Repo} alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription} alias Pleroma.Web.OStatus.FeedRepresenter alias Pleroma.Web.{XML, Endpoint, OStatus} -- cgit v1.2.3 From 473095faf2a74e11b6a5662a4b30caec5d5636d2 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 6 Feb 2019 21:04:11 +0100 Subject: Web.Federator: Fix unused variable --- lib/pleroma/web/federator/federator.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index 71648e8c7..3e8469a6f 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -194,7 +194,7 @@ defmodule Pleroma.Web.Federator do {:noreply, %{in: {i_running_jobs, i_queue}, out: {o_running_jobs, o_queue}}} end - def handle_cast(m, state) do + def handle_cast(_, state) do {:noreply, state} end -- cgit v1.2.3 From bd9b5fffbcffed5d5cab238d5f3c36cf90edc881 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 6 Feb 2019 21:24:57 +0100 Subject: Mix.Tasks.Pleroma.Uploads: Fix typo in documentation --- lib/mix/tasks/pleroma/uploads.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index f0eb13e1a..460fa161b 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -20,7 +20,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do - `--delete` - delete local uploads after migrating them to the target uploader - A list of avalible uploaders can be seen in config.exs + A list of available uploaders can be seen in config.exs """ def run(["migrate_local", target_uploader | args]) do delete? = Enum.member?(args, "--delete") -- cgit v1.2.3 From d2e4eb7c748c918b1e9e7133fef4c1b84cf66755 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 6 Feb 2019 21:19:35 +0100 Subject: Web.ActivityPub.ActivityPub: assign the Enum.filter to recipients & simplify it --- lib/pleroma/web/activity_pub/activity_pub.ex | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 6028e96a9..d22f04bb2 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -19,19 +19,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp get_recipients(%{"type" => "Announce"} = data) do to = data["to"] || [] cc = data["cc"] || [] - recipients = to ++ cc actor = User.get_cached_by_ap_id(data["actor"]) - recipients - |> Enum.filter(fn recipient -> - case User.get_cached_by_ap_id(recipient) do - nil -> - true - - user -> - User.following?(user, actor) - end - end) + recipients = + (to ++ cc) + |> Enum.filter(fn recipient -> + case User.get_cached_by_ap_id(recipient) do + nil -> + true + + user -> + User.following?(user, actor) + end + end) {recipients, to, cc} end -- cgit v1.2.3 From 2272934a5e5d5f2d0319381bd2f4dc322da78e18 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 8 Feb 2019 17:18:44 +0100 Subject: Stash --- lib/pleroma/html.ex | 7 ++----- lib/pleroma/web/web.ex | 2 ++ 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 0fd41ffb8..291b0e612 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -83,8 +83,7 @@ defmodule Pleroma.HTML.Scrubber.TwitterText do """ @markup Application.get_env(:pleroma, :markup) - @uri_schemes Application.get_env(:pleroma, :uri_schemes, []) - @valid_schemes Keyword.get(@uri_schemes, :valid_schemes, []) + @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], []) require HtmlSanitizeEx.Scrubber.Meta alias HtmlSanitizeEx.Scrubber.Meta @@ -125,12 +124,10 @@ defmodule Pleroma.HTML.Scrubber.Default do @doc "The default HTML scrubbing policy: no " require HtmlSanitizeEx.Scrubber.Meta - alias HtmlSanitizeEx.Scrubber.Meta @markup Application.get_env(:pleroma, :markup) - @uri_schemes Application.get_env(:pleroma, :uri_schemes, []) - @valid_schemes Keyword.get(@uri_schemes, :valid_schemes, []) + @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], []) Meta.remove_cdata_sections_before_scrub() Meta.strip_comments() diff --git a/lib/pleroma/web/web.ex b/lib/pleroma/web/web.ex index 30558e692..4d5fd028e 100644 --- a/lib/pleroma/web/web.ex +++ b/lib/pleroma/web/web.ex @@ -71,6 +71,7 @@ defmodule Pleroma.Web do def router do quote do use Phoenix.Router + # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse import Plug.Conn import Phoenix.Controller end @@ -78,6 +79,7 @@ defmodule Pleroma.Web do def channel do quote do + # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse use Phoenix.Channel import Pleroma.Web.Gettext end -- cgit v1.2.3 From 381fe4417260e93cba79aa85785f53b410d0e0f7 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 9 Feb 2019 14:39:27 +0100 Subject: HTML.Scrubber.Default: Consistency --- lib/pleroma/html.ex | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 291b0e612..4dc6998b1 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -125,6 +125,8 @@ defmodule Pleroma.HTML.Scrubber.Default do require HtmlSanitizeEx.Scrubber.Meta alias HtmlSanitizeEx.Scrubber.Meta + # credo:disable-for-previous-line + # No idea how to fix this one… @markup Application.get_env(:pleroma, :markup) @valid_schemes Pleroma.Config.get([:uri_schemes, :valid_schemes], []) -- cgit v1.2.3 From 4ad843fb9df838f36c014ddfb76d7107ba2b5c7b Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sat, 9 Feb 2019 17:09:08 +0300 Subject: [#468] Prototype of OAuth2 scopes support. TwitterAPI scope restrictions. --- lib/pleroma/plugs/oauth_scopes_plug.ex | 29 +++++++ lib/pleroma/web/oauth.ex | 11 +++ lib/pleroma/web/oauth/authorization.ex | 6 +- lib/pleroma/web/oauth/oauth_controller.ex | 12 +-- lib/pleroma/web/oauth/token.ex | 8 +- lib/pleroma/web/router.ex | 98 ++++++++++++++-------- .../web/templates/o_auth/o_auth/show.html.eex | 4 +- 7 files changed, 119 insertions(+), 49 deletions(-) create mode 100644 lib/pleroma/plugs/oauth_scopes_plug.ex create mode 100644 lib/pleroma/web/oauth.ex (limited to 'lib') diff --git a/lib/pleroma/plugs/oauth_scopes_plug.ex b/lib/pleroma/plugs/oauth_scopes_plug.ex new file mode 100644 index 000000000..a16adb004 --- /dev/null +++ b/lib/pleroma/plugs/oauth_scopes_plug.ex @@ -0,0 +1,29 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Plugs.OAuthScopesPlug do + import Plug.Conn + alias Pleroma.Web.OAuth + + @behaviour Plug + + def init(%{required_scopes: _} = options), do: options + + def call(%Plug.Conn{assigns: assigns} = conn, %{required_scopes: required_scopes}) do + token = assigns[:token] + granted_scopes = token && OAuth.parse_scopes(token.scope) + + if is_nil(token) || required_scopes -- granted_scopes == [] do + conn + else + missing_scopes = required_scopes -- granted_scopes + error_message = "Insufficient permissions: #{Enum.join(missing_scopes, ", ")}." + + conn + |> put_resp_content_type("application/json") + |> send_resp(403, Jason.encode!(%{error: error_message})) + |> halt() + end + end +end diff --git a/lib/pleroma/web/oauth.ex b/lib/pleroma/web/oauth.ex new file mode 100644 index 000000000..44b83433e --- /dev/null +++ b/lib/pleroma/web/oauth.ex @@ -0,0 +1,11 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.OAuth do + def parse_scopes(scopes) do + scopes + |> to_string() + |> String.split([" ", ","]) + end +end diff --git a/lib/pleroma/web/oauth/authorization.ex b/lib/pleroma/web/oauth/authorization.ex index f8c65602d..0fbaa902b 100644 --- a/lib/pleroma/web/oauth/authorization.ex +++ b/lib/pleroma/web/oauth/authorization.ex @@ -6,12 +6,14 @@ defmodule Pleroma.Web.OAuth.Authorization do use Ecto.Schema alias Pleroma.{User, Repo} + alias Pleroma.Web.OAuth alias Pleroma.Web.OAuth.{Authorization, App} import Ecto.{Changeset, Query} schema "oauth_authorizations" do field(:token, :string) + field(:scope, :string) field(:valid_until, :naive_datetime) field(:used, :boolean, default: false) belongs_to(:user, Pleroma.User, type: Pleroma.FlakeId) @@ -20,7 +22,8 @@ defmodule Pleroma.Web.OAuth.Authorization do timestamps() end - def create_authorization(%App{} = app, %User{} = user) do + def create_authorization(%App{} = app, %User{} = user, scope \\ nil) do + scopes = OAuth.parse_scopes(scope || app.scopes) token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() authorization = %Authorization{ @@ -28,6 +31,7 @@ defmodule Pleroma.Web.OAuth.Authorization do used: false, user_id: user.id, app_id: app.id, + scope: Enum.join(scopes, " "), valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10) } diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 8ec963c79..15345d4ba 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -38,7 +38,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, %App{} = app <- Repo.get_by(App, client_id: client_id), true <- redirect_uri in String.split(app.redirect_uris), - {:ok, auth} <- Authorization.create_authorization(app, user) do + {:ok, auth} <- Authorization.create_authorization(app, user, params["scope"]) do # Special case: Local MastodonFE. redirect_uri = if redirect_uri == "." do @@ -81,8 +81,6 @@ defmodule Pleroma.Web.OAuth.OAuthController do end end - # TODO - # - proper scope handling def token_exchange(conn, %{"grant_type" => "authorization_code"} = params) do with %App{} = app <- get_app_from_request(conn, params), fixed_token = fix_padding(params["code"]), @@ -96,7 +94,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do refresh_token: token.refresh_token, created_at: DateTime.to_unix(inserted_at), expires_in: 60 * 10, - scope: "read write follow" + scope: token.scope } json(conn, response) @@ -107,8 +105,6 @@ defmodule Pleroma.Web.OAuth.OAuthController do end end - # TODO - # - investigate a way to verify the user wants to grant read/write/follow once scope handling is done def token_exchange( conn, %{"grant_type" => "password", "username" => name, "password" => password} = params @@ -117,14 +113,14 @@ defmodule Pleroma.Web.OAuth.OAuthController do %User{} = user <- User.get_by_nickname_or_email(name), true <- Pbkdf2.checkpw(password, user.password_hash), {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, - {:ok, auth} <- Authorization.create_authorization(app, user), + {:ok, auth} <- Authorization.create_authorization(app, user, params["scope"]), {:ok, token} <- Token.exchange_token(app, auth) do response = %{ token_type: "Bearer", access_token: token.token, refresh_token: token.refresh_token, expires_in: 60 * 10, - scope: "read write follow" + scope: token.scope } json(conn, response) diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index 4e01b123b..61f43ed5a 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -8,11 +8,13 @@ defmodule Pleroma.Web.OAuth.Token do import Ecto.Query alias Pleroma.{User, Repo} + alias Pleroma.Web.OAuth alias Pleroma.Web.OAuth.{Token, App, Authorization} schema "oauth_tokens" do field(:token, :string) field(:refresh_token, :string) + field(:scope, :string) field(:valid_until, :naive_datetime) belongs_to(:user, Pleroma.User, type: Pleroma.FlakeId) belongs_to(:app, App) @@ -23,17 +25,19 @@ defmodule Pleroma.Web.OAuth.Token do def exchange_token(app, auth) do with {:ok, auth} <- Authorization.use_token(auth), true <- auth.app_id == app.id do - create_token(app, Repo.get(User, auth.user_id)) + create_token(app, Repo.get(User, auth.user_id), auth.scope) end end - def create_token(%App{} = app, %User{} = user) do + def create_token(%App{} = app, %User{} = user, scope \\ nil) do + scopes = OAuth.parse_scopes(scope || app.scopes) token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() refresh_token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() token = %Token{ token: token, refresh_token: refresh_token, + scope: Enum.join(scopes, " "), user_id: user.id, app_id: app.id, valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 7f606ac40..1316d7f98 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -74,6 +74,18 @@ defmodule Pleroma.Web.Router do plug(Pleroma.Plugs.EnsureUserKeyPlug) end + pipeline :oauth_read do + plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["read"]}) + end + + pipeline :oauth_write do + plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["write"]}) + end + + pipeline :oauth_follow do + plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["follow"]}) + end + pipeline :well_known do plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"]) end @@ -338,55 +350,67 @@ defmodule Pleroma.Web.Router do get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials) post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials) - post("/account/update_profile", TwitterAPI.Controller, :update_profile) - post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner) - post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background) + scope [] do + pipe_through(:oauth_read) + + get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline) + get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline) + get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline) + get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline) + get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline) + get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications) - get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline) - get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline) - get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline) - get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline) - get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline) - get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications) + get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests) - # XXX: this is really a pleroma API, but we want to keep the pleroma namespace clean - # for now. - post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read) + get("/friends/ids", TwitterAPI.Controller, :friends_ids) + get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array) - post("/statuses/update", TwitterAPI.Controller, :status_update) - post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet) - post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet) - post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post) + get("/mutes/users/ids", TwitterAPI.Controller, :empty_array) + get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array) - post("/statuses/pin/:id", TwitterAPI.Controller, :pin) - post("/statuses/unpin/:id", TwitterAPI.Controller, :unpin) + get("/externalprofile/show", TwitterAPI.Controller, :external_profile) - get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests) - post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request) - post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request) + post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read) + end + + scope [] do + pipe_through(:oauth_write) - post("/friendships/create", TwitterAPI.Controller, :follow) - post("/friendships/destroy", TwitterAPI.Controller, :unfollow) - post("/blocks/create", TwitterAPI.Controller, :block) - post("/blocks/destroy", TwitterAPI.Controller, :unblock) + post("/account/update_profile", TwitterAPI.Controller, :update_profile) + post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner) + post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background) - post("/statusnet/media/upload", TwitterAPI.Controller, :upload) - post("/media/upload", TwitterAPI.Controller, :upload_json) - post("/media/metadata/create", TwitterAPI.Controller, :update_media) + post("/statuses/update", TwitterAPI.Controller, :status_update) + post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet) + post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet) + post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post) - post("/favorites/create/:id", TwitterAPI.Controller, :favorite) - post("/favorites/create", TwitterAPI.Controller, :favorite) - post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite) + post("/statuses/pin/:id", TwitterAPI.Controller, :pin) + post("/statuses/unpin/:id", TwitterAPI.Controller, :unpin) - post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar) + post("/statusnet/media/upload", TwitterAPI.Controller, :upload) + post("/media/upload", TwitterAPI.Controller, :upload_json) + post("/media/metadata/create", TwitterAPI.Controller, :update_media) - get("/friends/ids", TwitterAPI.Controller, :friends_ids) - get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array) + post("/favorites/create/:id", TwitterAPI.Controller, :favorite) + post("/favorites/create", TwitterAPI.Controller, :favorite) + post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite) + + post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar) + end - get("/mutes/users/ids", TwitterAPI.Controller, :empty_array) - get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array) + scope [] do + pipe_through(:oauth_follow) - get("/externalprofile/show", TwitterAPI.Controller, :external_profile) + post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request) + post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request) + + post("/friendships/create", TwitterAPI.Controller, :follow) + post("/friendships/destroy", TwitterAPI.Controller, :unfollow) + + post("/blocks/create", TwitterAPI.Controller, :block) + post("/blocks/destroy", TwitterAPI.Controller, :unblock) + end end pipeline :ap_relay do diff --git a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex index de2241ec9..e1c0af975 100644 --- a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex +++ b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex @@ -8,10 +8,12 @@ <%= label f, :password, "Password" %> <%= password_input f, :password %>
+<%= label f, :scope, "Scopes" %> +<%= text_input f, :scope, value: @scope %> +
<%= hidden_input f, :client_id, value: @client_id %> <%= hidden_input f, :response_type, value: @response_type %> <%= hidden_input f, :redirect_uri, value: @redirect_uri %> -<%= hidden_input f, :scope, value: @scope %> <%= hidden_input f, :state, value: @state%> <%= submit "Authorize" %> <% end %> -- cgit v1.2.3 From a337bd114c3cbbb8e8270ec56a012e82f84df808 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sat, 9 Feb 2019 17:32:33 +0300 Subject: [#468] MastodonAPI scope restrictions. Removed obsolete "POST /web/login" route. --- lib/pleroma/web/router.ex | 155 +++++++++++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 64 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 1316d7f98..4ece311d3 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -154,10 +154,20 @@ defmodule Pleroma.Web.Router do scope "/api/pleroma", Pleroma.Web.TwitterAPI do pipe_through(:authenticated_api) - post("/blocks_import", UtilController, :blocks_import) - post("/follow_import", UtilController, :follow_import) - post("/change_password", UtilController, :change_password) - post("/delete_account", UtilController, :delete_account) + + scope [] do + pipe_through(:oauth_write) + + post("/change_password", UtilController, :change_password) + post("/delete_account", UtilController, :delete_account) + end + + scope [] do + pipe_through(:oauth_follow) + + post("/blocks_import", UtilController, :blocks_import) + post("/follow_import", UtilController, :follow_import) + end end scope "/oauth", Pleroma.Web.OAuth do @@ -170,86 +180,104 @@ defmodule Pleroma.Web.Router do scope "/api/v1", Pleroma.Web.MastodonAPI do pipe_through(:authenticated_api) - patch("/accounts/update_credentials", MastodonAPIController, :update_credentials) get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials) - get("/accounts/relationships", MastodonAPIController, :relationships) - get("/accounts/search", MastodonAPIController, :account_search) - post("/accounts/:id/follow", MastodonAPIController, :follow) - post("/accounts/:id/unfollow", MastodonAPIController, :unfollow) - post("/accounts/:id/block", MastodonAPIController, :block) - post("/accounts/:id/unblock", MastodonAPIController, :unblock) - post("/accounts/:id/mute", MastodonAPIController, :relationship_noop) - post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop) - get("/accounts/:id/lists", MastodonAPIController, :account_lists) - get("/follow_requests", MastodonAPIController, :follow_requests) - post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request) - post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request) + scope [] do + pipe_through(:oauth_read) - post("/follows", MastodonAPIController, :follow) + get("/accounts/relationships", MastodonAPIController, :relationships) + get("/accounts/search", MastodonAPIController, :account_search) - get("/blocks", MastodonAPIController, :blocks) + get("/accounts/:id/lists", MastodonAPIController, :account_lists) - get("/mutes", MastodonAPIController, :empty_array) + get("/follow_requests", MastodonAPIController, :follow_requests) + get("/blocks", MastodonAPIController, :blocks) + get("/mutes", MastodonAPIController, :empty_array) - get("/timelines/home", MastodonAPIController, :home_timeline) + get("/timelines/home", MastodonAPIController, :home_timeline) + get("/timelines/direct", MastodonAPIController, :dm_timeline) - get("/timelines/direct", MastodonAPIController, :dm_timeline) + get("/favourites", MastodonAPIController, :favourites) + get("/bookmarks", MastodonAPIController, :bookmarks) - get("/favourites", MastodonAPIController, :favourites) - get("/bookmarks", MastodonAPIController, :bookmarks) + post("/notifications/clear", MastodonAPIController, :clear_notifications) + post("/notifications/dismiss", MastodonAPIController, :dismiss_notification) + get("/notifications", MastodonAPIController, :notifications) + get("/notifications/:id", MastodonAPIController, :get_notification) - post("/statuses", MastodonAPIController, :post_status) - delete("/statuses/:id", MastodonAPIController, :delete_status) + get("/lists", MastodonAPIController, :get_lists) + get("/lists/:id", MastodonAPIController, :get_list) + get("/lists/:id/accounts", MastodonAPIController, :list_accounts) - post("/statuses/:id/reblog", MastodonAPIController, :reblog_status) - post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status) - post("/statuses/:id/favourite", MastodonAPIController, :fav_status) - post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status) - post("/statuses/:id/pin", MastodonAPIController, :pin_status) - post("/statuses/:id/unpin", MastodonAPIController, :unpin_status) - post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status) - post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status) + get("/domain_blocks", MastodonAPIController, :domain_blocks) - post("/notifications/clear", MastodonAPIController, :clear_notifications) - post("/notifications/dismiss", MastodonAPIController, :dismiss_notification) - get("/notifications", MastodonAPIController, :notifications) - get("/notifications/:id", MastodonAPIController, :get_notification) + get("/filters", MastodonAPIController, :get_filters) - post("/media", MastodonAPIController, :upload) - put("/media/:id", MastodonAPIController, :update_media) + get("/suggestions", MastodonAPIController, :suggestions) - get("/lists", MastodonAPIController, :get_lists) - get("/lists/:id", MastodonAPIController, :get_list) - delete("/lists/:id", MastodonAPIController, :delete_list) - post("/lists", MastodonAPIController, :create_list) - put("/lists/:id", MastodonAPIController, :rename_list) - get("/lists/:id/accounts", MastodonAPIController, :list_accounts) - post("/lists/:id/accounts", MastodonAPIController, :add_to_list) - delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list) + get("/endorsements", MastodonAPIController, :empty_array) + end - get("/domain_blocks", MastodonAPIController, :domain_blocks) - post("/domain_blocks", MastodonAPIController, :block_domain) - delete("/domain_blocks", MastodonAPIController, :unblock_domain) + scope [] do + pipe_through(:oauth_write) - get("/filters", MastodonAPIController, :get_filters) - post("/filters", MastodonAPIController, :create_filter) - get("/filters/:id", MastodonAPIController, :get_filter) - put("/filters/:id", MastodonAPIController, :update_filter) - delete("/filters/:id", MastodonAPIController, :delete_filter) + patch("/accounts/update_credentials", MastodonAPIController, :update_credentials) - post("/push/subscription", MastodonAPIController, :create_push_subscription) - get("/push/subscription", MastodonAPIController, :get_push_subscription) - put("/push/subscription", MastodonAPIController, :update_push_subscription) - delete("/push/subscription", MastodonAPIController, :delete_push_subscription) + post("/statuses", MastodonAPIController, :post_status) + delete("/statuses/:id", MastodonAPIController, :delete_status) - get("/suggestions", MastodonAPIController, :suggestions) + post("/statuses/:id/reblog", MastodonAPIController, :reblog_status) + post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status) + post("/statuses/:id/favourite", MastodonAPIController, :fav_status) + post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status) + post("/statuses/:id/pin", MastodonAPIController, :pin_status) + post("/statuses/:id/unpin", MastodonAPIController, :unpin_status) + post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status) + post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status) - get("/endorsements", MastodonAPIController, :empty_array) + post("/media", MastodonAPIController, :upload) + put("/media/:id", MastodonAPIController, :update_media) + + delete("/lists/:id", MastodonAPIController, :delete_list) + post("/lists", MastodonAPIController, :create_list) + put("/lists/:id", MastodonAPIController, :rename_list) + + post("/lists/:id/accounts", MastodonAPIController, :add_to_list) + delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list) + + post("/filters", MastodonAPIController, :create_filter) + get("/filters/:id", MastodonAPIController, :get_filter) + put("/filters/:id", MastodonAPIController, :update_filter) + delete("/filters/:id", MastodonAPIController, :delete_filter) + end + + scope [] do + pipe_through(:oauth_follow) + + post("/follows", MastodonAPIController, :follow) + post("/accounts/:id/follow", MastodonAPIController, :follow) + + post("/accounts/:id/unfollow", MastodonAPIController, :unfollow) + post("/accounts/:id/block", MastodonAPIController, :block) + post("/accounts/:id/unblock", MastodonAPIController, :unblock) + post("/accounts/:id/mute", MastodonAPIController, :relationship_noop) + post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop) + + post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request) + post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request) + + post("/domain_blocks", MastodonAPIController, :block_domain) + delete("/domain_blocks", MastodonAPIController, :unblock_domain) + + post("/push/subscription", MastodonAPIController, :create_push_subscription) + get("/push/subscription", MastodonAPIController, :get_push_subscription) + put("/push/subscription", MastodonAPIController, :update_push_subscription) + delete("/push/subscription", MastodonAPIController, :delete_push_subscription) + end end scope "/api/web", Pleroma.Web.MastodonAPI do - pipe_through(:authenticated_api) + pipe_through([:authenticated_api, :oauth_write]) put("/settings", MastodonAPIController, :put_settings) end @@ -510,7 +538,6 @@ defmodule Pleroma.Web.Router do pipe_through(:mastodon_html) get("/web/login", MastodonAPIController, :login) - post("/web/login", MastodonAPIController, :login_post) get("/web/*path", MastodonAPIController, :index) delete("/auth/sign_out", MastodonAPIController, :logout) end -- cgit v1.2.3 From 6a6a5b3251f7137e30b687a9a8448e678446f8b0 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 9 Feb 2019 16:16:26 +0100 Subject: de-group alias/es --- lib/mix/tasks/pleroma/uploads.ex | 3 +- lib/mix/tasks/pleroma/user.ex | 3 +- lib/pleroma/PasswordResetToken.ex | 4 ++- lib/pleroma/activity.ex | 6 +++- lib/pleroma/captcha/captcha.ex | 3 +- lib/pleroma/emails/user_email.ex | 3 +- lib/pleroma/filter.ex | 8 +++-- lib/pleroma/formatter.ex | 4 ++- lib/pleroma/gopher/server.ex | 5 +++- lib/pleroma/instances/instance.ex | 3 +- lib/pleroma/list.ex | 9 ++++-- lib/pleroma/notification.ex | 7 ++++- lib/pleroma/object.ex | 11 +++++-- lib/pleroma/plugs/oauth_plug.ex | 8 ++--- lib/pleroma/plugs/user_fetcher_plug.ex | 3 +- lib/pleroma/stats.ex | 3 +- lib/pleroma/user.ex | 18 ++++++++--- lib/pleroma/user_invite_token.ex | 3 +- lib/pleroma/web/activity_pub/activity_pub.ex | 15 ++++++++-- .../web/activity_pub/activity_pub_controller.ex | 12 ++++++-- lib/pleroma/web/activity_pub/relay.ex | 4 ++- lib/pleroma/web/activity_pub/transmogrifier.ex | 8 +++-- lib/pleroma/web/activity_pub/utils.ex | 12 ++++++-- lib/pleroma/web/activity_pub/views/object_view.ex | 3 +- lib/pleroma/web/activity_pub/views/user_view.ex | 10 +++++-- lib/pleroma/web/common_api/common_api.ex | 8 +++-- lib/pleroma/web/common_api/utils.ex | 11 +++++-- lib/pleroma/web/federator/federator.ex | 12 ++++++-- lib/pleroma/web/http_signatures/http_signatures.ex | 3 +- .../web/mastodon_api/mastodon_api_controller.ex | 35 ++++++++++++++-------- lib/pleroma/web/mastodon_api/views/account_view.ex | 3 +- lib/pleroma/web/mastodon_api/views/status_view.ex | 8 +++-- lib/pleroma/web/mastodon_api/websocket_handler.ex | 3 +- lib/pleroma/web/metadata/opengraph.ex | 7 +++-- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 6 +++- lib/pleroma/web/oauth/authorization.ex | 6 ++-- lib/pleroma/web/oauth/oauth_controller.ex | 7 +++-- lib/pleroma/web/oauth/token.ex | 7 +++-- lib/pleroma/web/ostatus/activity_representer.ex | 5 +++- lib/pleroma/web/ostatus/feed_representer.ex | 6 ++-- lib/pleroma/web/ostatus/handlers/follow_handler.ex | 3 +- lib/pleroma/web/ostatus/handlers/note_handler.ex | 9 ++++-- .../web/ostatus/handlers/unfollow_handler.ex | 3 +- lib/pleroma/web/ostatus/ostatus.ex | 17 ++++++++--- lib/pleroma/web/ostatus/ostatus_controller.ex | 14 ++++++--- lib/pleroma/web/push/push.ex | 3 +- lib/pleroma/web/push/subscription.ex | 5 +++- lib/pleroma/web/rich_media/helpers.ex | 4 ++- lib/pleroma/web/salmon/salmon.ex | 3 +- lib/pleroma/web/streamer.ex | 6 +++- .../web/twitter_api/controllers/util_controller.ex | 9 ++++-- .../representers/activity_representer.ex | 10 +++++-- lib/pleroma/web/twitter_api/twitter_api.ex | 9 ++++-- .../web/twitter_api/twitter_api_controller.ex | 14 +++++++-- lib/pleroma/web/twitter_api/views/activity_view.ex | 11 +++++-- .../web/twitter_api/views/notification_view.ex | 6 ++-- lib/pleroma/web/twitter_api/views/user_view.ex | 4 ++- lib/pleroma/web/web_finger/web_finger.ex | 7 +++-- lib/pleroma/web/websub/websub.ex | 10 +++++-- lib/pleroma/web/websub/websub_controller.ex | 6 ++-- 60 files changed, 328 insertions(+), 120 deletions(-) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index 460fa161b..697ad1a7b 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -4,7 +4,8 @@ defmodule Mix.Tasks.Pleroma.Uploads do use Mix.Task - alias Pleroma.{Upload, Uploaders.Local} + alias Pleroma.Upload + alias Pleroma.Uploaders.Local alias Mix.Tasks.Pleroma.Common require Logger diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 5da3edfd2..037e44716 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -5,7 +5,8 @@ defmodule Mix.Tasks.Pleroma.User do use Mix.Task import Ecto.Changeset - alias Pleroma.{Repo, User} + alias Pleroma.Repo + alias Pleroma.User alias Mix.Tasks.Pleroma.Common @shortdoc "Manages Pleroma users" diff --git a/lib/pleroma/PasswordResetToken.ex b/lib/pleroma/PasswordResetToken.ex index c3c0384d2..750ddd3c0 100644 --- a/lib/pleroma/PasswordResetToken.ex +++ b/lib/pleroma/PasswordResetToken.ex @@ -7,7 +7,9 @@ defmodule Pleroma.PasswordResetToken do import Ecto.Changeset - alias Pleroma.{User, PasswordResetToken, Repo} + alias Pleroma.User + alias Pleroma.Repo + alias Pleroma.PasswordResetToken schema "password_reset_tokens" do belongs_to(:user, User, type: Pleroma.FlakeId) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index f0aa3ce97..cdfe7ea9e 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -4,7 +4,11 @@ defmodule Pleroma.Activity do use Ecto.Schema - alias Pleroma.{Repo, Activity, Notification} + + alias Pleroma.Repo + alias Pleroma.Activity + alias Pleroma.Notification + import Ecto.Query @type t :: %__MODULE__{} diff --git a/lib/pleroma/captcha/captcha.ex b/lib/pleroma/captcha/captcha.ex index f70f5a191..aa41acd1a 100644 --- a/lib/pleroma/captcha/captcha.ex +++ b/lib/pleroma/captcha/captcha.ex @@ -3,8 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Captcha do - alias Plug.Crypto.{KeyGenerator, MessageEncryptor} alias Calendar.DateTime + alias Plug.Crypto.KeyGenerator + alias Plug.Crypto.MessageEncryptor use GenServer diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index c42c53c99..a3a09e96c 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -7,7 +7,8 @@ defmodule Pleroma.UserEmail do import Swoosh.Email - alias Pleroma.Web.{Endpoint, Router} + alias Pleroma.Web.Endpoint + alias Pleroma.Web.Router defp instance_config, do: Pleroma.Config.get(:instance) diff --git a/lib/pleroma/filter.ex b/lib/pleroma/filter.ex index 308bd70e1..bdc34698c 100644 --- a/lib/pleroma/filter.ex +++ b/lib/pleroma/filter.ex @@ -4,8 +4,12 @@ defmodule Pleroma.Filter do use Ecto.Schema - import Ecto.{Changeset, Query} - alias Pleroma.{User, Repo} + + import Ecto.Changeset + import Ecto.Query + + alias Pleroma.User + alias Pleroma.Repo schema "filters" do belongs_to(:user, User, type: Pleroma.FlakeId) diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 8a8af266c..f31aafa0d 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -3,7 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Formatter do - alias Pleroma.{Emoji, HTML, User} + alias Pleroma.Emoji + alias Pleroma.HTML + alias Pleroma.User alias Pleroma.Web.MediaProxy @tag_regex ~r/((?<=[^&])|\A)(\#)(\w+)/u diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index a284b3c61..32cb817d2 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -37,7 +37,10 @@ end defmodule Pleroma.Gopher.Server.ProtocolHandler do alias Pleroma.Web.ActivityPub.ActivityPub - alias Pleroma.{Activity, HTML, User, Repo} + alias Pleroma.Activity + alias Pleroma.HTML + alias Pleroma.User + alias Pleroma.Repo def start_link(ref, socket, transport, opts) do pid = spawn_link(__MODULE__, :init, [ref, socket, transport, opts]) diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index bab8e0564..ce3b46d50 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -1,7 +1,8 @@ defmodule Pleroma.Instances.Instance do @moduledoc "Instance." - alias Pleroma.{Instances, Repo} + alias Pleroma.Instances + alias Pleroma.Repo alias Pleroma.Instances.Instance use Ecto.Schema diff --git a/lib/pleroma/list.ex b/lib/pleroma/list.ex index ca66c6916..55c4cf6df 100644 --- a/lib/pleroma/list.ex +++ b/lib/pleroma/list.ex @@ -4,8 +4,13 @@ defmodule Pleroma.List do use Ecto.Schema - import Ecto.{Changeset, Query} - alias Pleroma.{User, Repo, Activity} + + import Ecto.Query + import Ecto.Changeset + + alias Pleroma.Activity + alias Pleroma.Repo + alias Pleroma.User schema "lists" do belongs_to(:user, User, type: Pleroma.FlakeId) diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 2364d36da..c7c925c89 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -4,8 +4,13 @@ defmodule Pleroma.Notification do use Ecto.Schema - alias Pleroma.{User, Activity, Notification, Repo} + + alias Pleroma.User + alias Pleroma.Activity + alias Pleroma.Notification + alias Pleroma.Repo alias Pleroma.Web.CommonAPI.Utils + import Ecto.Query schema "notifications" do diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 7b46a3b05..5f1fc801b 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -4,8 +4,15 @@ defmodule Pleroma.Object do use Ecto.Schema - alias Pleroma.{Repo, Object, User, Activity, ObjectTombstone} - import Ecto.{Query, Changeset} + + alias Pleroma.Repo + alias Pleroma.Object + alias Pleroma.User + alias Pleroma.Activity + alias Pleroma.ObjectTombstone + + import Ecto.Query + import Ecto.Changeset schema "objects" do field(:data, :map) diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex index 945a1d49f..22f0406f4 100644 --- a/lib/pleroma/plugs/oauth_plug.ex +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -6,11 +6,9 @@ defmodule Pleroma.Plugs.OAuthPlug do import Plug.Conn import Ecto.Query - alias Pleroma.{ - User, - Repo, - Web.OAuth.Token - } + alias Pleroma.User + alias Pleroma.Repo + alias Pleroma.Web.OAuth.Token @realm_reg Regex.compile!("Bearer\:?\s+(.*)$", "i") diff --git a/lib/pleroma/plugs/user_fetcher_plug.ex b/lib/pleroma/plugs/user_fetcher_plug.ex index 6d6ab0926..7ed4602bb 100644 --- a/lib/pleroma/plugs/user_fetcher_plug.ex +++ b/lib/pleroma/plugs/user_fetcher_plug.ex @@ -3,7 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Plugs.UserFetcherPlug do - alias Pleroma.{User, Repo} + alias Pleroma.User + alias Pleroma.Repo import Plug.Conn diff --git a/lib/pleroma/stats.ex b/lib/pleroma/stats.ex index 16cc2856a..fe0ce9051 100644 --- a/lib/pleroma/stats.ex +++ b/lib/pleroma/stats.ex @@ -4,7 +4,8 @@ defmodule Pleroma.Stats do import Ecto.Query - alias Pleroma.{User, Repo} + alias Pleroma.User + alias Pleroma.Repo def start_link do agent = Agent.start_link(fn -> {[], %{}} end, name: __MODULE__) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 33630ac7c..b44ba1279 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -5,13 +5,23 @@ defmodule Pleroma.User do use Ecto.Schema - import Ecto.{Changeset, Query} - alias Pleroma.{Repo, User, Object, Web, Activity, Notification} + import Ecto.Changeset + import Ecto.Query + + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Object + alias Pleroma.Web + alias Pleroma.Activity + alias Pleroma.Notification alias Comeonin.Pbkdf2 alias Pleroma.Formatter alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils - alias Pleroma.Web.{OStatus, Websub, OAuth} - alias Pleroma.Web.ActivityPub.{Utils, ActivityPub} + alias Pleroma.Web.OStatus + alias Pleroma.Web.Websub + alias Pleroma.Web.OAuth + alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.ActivityPub.ActivityPub require Logger diff --git a/lib/pleroma/user_invite_token.ex b/lib/pleroma/user_invite_token.ex index 8e449444c..5a448114c 100644 --- a/lib/pleroma/user_invite_token.ex +++ b/lib/pleroma/user_invite_token.ex @@ -7,7 +7,8 @@ defmodule Pleroma.UserInviteToken do import Ecto.Changeset - alias Pleroma.{UserInviteToken, Repo} + alias Pleroma.UserInviteToken + alias Pleroma.Repo schema "user_invite_tokens" do field(:token, :string) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index d22f04bb2..c46d8233e 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -3,9 +3,18 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ActivityPub do - alias Pleroma.{Activity, Repo, Object, Upload, User, Notification, Instances} - alias Pleroma.Web.ActivityPub.{Transmogrifier, MRF} - alias Pleroma.Web.{WebFinger, Federator, OStatus} + alias Pleroma.Activity + alias Pleroma.Repo + alias Pleroma.Object + alias Pleroma.Upload + alias Pleroma.User + alias Pleroma.Notification + alias Pleroma.Instances + alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.ActivityPub.MRF + alias Pleroma.Web.WebFinger + alias Pleroma.Web.Federator + alias Pleroma.Web.OStatus import Ecto.Query import Pleroma.Web.ActivityPub.Utils diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 01b521051..69879476e 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -5,9 +5,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do use Pleroma.Web, :controller - alias Pleroma.{Activity, User, Object} - alias Pleroma.Web.ActivityPub.{ObjectView, UserView} - alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Transmogrifier, Utils} + alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Object + alias Pleroma.Web.ActivityPub.ObjectView + alias Pleroma.Web.ActivityPub.UserView + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Relay + alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.Federator require Logger diff --git a/lib/pleroma/web/activity_pub/relay.ex b/lib/pleroma/web/activity_pub/relay.ex index c0a52e349..c496063ea 100644 --- a/lib/pleroma/web/activity_pub/relay.ex +++ b/lib/pleroma/web/activity_pub/relay.ex @@ -3,7 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Relay do - alias Pleroma.{User, Object, Activity} + alias Pleroma.User + alias Pleroma.Object + alias Pleroma.Activity alias Pleroma.Web.ActivityPub.ActivityPub require Logger diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index edfbc9bb2..98a2af819 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -6,8 +6,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do @moduledoc """ A module to handle coding from internal to wire ActivityPub and back. """ - alias Pleroma.{Activity, User, Object, Repo} - alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} + alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Utils import Ecto.Query diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 4a2cc6738..964e11c9d 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -3,11 +3,19 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Utils do - alias Pleroma.{Repo, Web, Object, Activity, User, Notification} + alias Pleroma.Repo + alias Pleroma.Web + alias Pleroma.Object + alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Notification alias Pleroma.Web.Router.Helpers alias Pleroma.Web.Endpoint - alias Ecto.{Changeset, UUID} + alias Ecto.Changeset + alias Ecto.UUID + import Ecto.Query + require Logger @supported_object_types ["Article", "Note", "Video", "Page"] diff --git a/lib/pleroma/web/activity_pub/views/object_view.ex b/lib/pleroma/web/activity_pub/views/object_view.ex index 394d82fbc..84fa94e32 100644 --- a/lib/pleroma/web/activity_pub/views/object_view.ex +++ b/lib/pleroma/web/activity_pub/views/object_view.ex @@ -4,7 +4,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectView do use Pleroma.Web, :view - alias Pleroma.{Object, Activity} + alias Pleroma.Activity + alias Pleroma.Object alias Pleroma.Web.ActivityPub.Transmogrifier def render("object.json", %{object: %Object{} = object}) do diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index ba3aea1a6..15e6c1f68 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -5,9 +5,13 @@ defmodule Pleroma.Web.ActivityPub.UserView do use Pleroma.Web, :view - alias Pleroma.Web.{WebFinger, Salmon} - alias Pleroma.{User, Repo} - alias Pleroma.Web.ActivityPub.{ActivityPub, Transmogrifier, Utils} + alias Pleroma.Web.WebFinger + alias Pleroma.Web.Salmon + alias Pleroma.User + alias Pleroma.Repo + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.ActivityPub.Utils import Ecto.Query diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 4388396cf..c0d6fb5c4 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -3,8 +3,12 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPI do - alias Pleroma.{User, Repo, Activity, Object} - alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} + alias Pleroma.User + alias Pleroma.Repo + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Formatter import Pleroma.Web.CommonAPI.Utils diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index e50d63d77..123107b56 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -5,9 +5,14 @@ defmodule Pleroma.Web.CommonAPI.Utils do alias Calendar.Strftime alias Comeonin.Pbkdf2 - alias Pleroma.{Activity, Formatter, Object, Repo} - alias Pleroma.{User, Web} - alias Pleroma.Web.{Endpoint, MediaProxy} + alias Pleroma.Activity + alias Pleroma.Formatter + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Web + alias Pleroma.Web.Endpoint + alias Pleroma.Web.MediaProxy alias Pleroma.Web.ActivityPub.Utils # This is a hack for twidere. diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index 3e8469a6f..468959a65 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -5,9 +5,15 @@ defmodule Pleroma.Web.Federator do use GenServer - alias Pleroma.{Activity, User} - alias Pleroma.Web.{WebFinger, Websub, Salmon} - alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Transmogrifier, Utils} + alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Web.WebFinger + alias Pleroma.Web.Websub + alias Pleroma.Web.Salmon + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Relay + alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.Federator.RetryQueue alias Pleroma.Web.OStatus diff --git a/lib/pleroma/web/http_signatures/http_signatures.ex b/lib/pleroma/web/http_signatures/http_signatures.ex index 5ff93663e..8e2e2a44b 100644 --- a/lib/pleroma/web/http_signatures/http_signatures.ex +++ b/lib/pleroma/web/http_signatures/http_signatures.ex @@ -5,7 +5,8 @@ # https://tools.ietf.org/html/draft-cavage-http-signatures-08 defmodule Pleroma.Web.HTTPSignatures do alias Pleroma.User - alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Utils require Logger diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 74f1bed4d..06f870393 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -4,22 +4,31 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do use Pleroma.Web, :controller - alias Pleroma.{Activity, Config, Filter, Notification, Object, Repo, Stats, User} + alias Pleroma.Activity + alias Pleroma.Config + alias Pleroma.Filter + alias Pleroma.Notification + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.Stats + alias Pleroma.User alias Pleroma.Web - alias Pleroma.Web.{CommonAPI, MediaProxy, Push} + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.MediaProxy + alias Pleroma.Web.Push alias Push.Subscription - alias Pleroma.Web.MastodonAPI.{ - AccountView, - FilterView, - ListView, - MastodonView, - PushSubscriptionView, - StatusView - } - - alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} - alias Pleroma.Web.OAuth.{App, Authorization, Token} + alias Pleroma.Web.MastodonAPI.AccountView + alias Pleroma.Web.MastodonAPI.FilterView + alias Pleroma.Web.MastodonAPI.ListView + alias Pleroma.Web.MastodonAPI.MastodonView + alias Pleroma.Web.MastodonAPI.PushSubscriptionView + alias Pleroma.Web.MastodonAPI.StatusView + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.OAuth.App + alias Pleroma.Web.OAuth.Authorization + alias Pleroma.Web.OAuth.Token import Ecto.Query require Logger diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 0235f5d5b..9df9f14b2 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -5,7 +5,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do use Pleroma.Web, :view - alias Pleroma.{HTML, User} + alias Pleroma.HTML + alias Pleroma.User alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MediaProxy diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index cd030fe54..f51a2ebb0 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -5,9 +5,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do use Pleroma.Web, :view - alias Pleroma.{Activity, HTML, Repo, User} + alias Pleroma.Activity + alias Pleroma.HTML + alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.CommonAPI.Utils - alias Pleroma.Web.MastodonAPI.{AccountView, StatusView} + alias Pleroma.Web.MastodonAPI.AccountView + alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.Web.MediaProxy # TODO: Add cached version. diff --git a/lib/pleroma/web/mastodon_api/websocket_handler.ex b/lib/pleroma/web/mastodon_api/websocket_handler.ex index ce42338a7..ea75070c4 100644 --- a/lib/pleroma/web/mastodon_api/websocket_handler.ex +++ b/lib/pleroma/web/mastodon_api/websocket_handler.ex @@ -6,7 +6,8 @@ defmodule Pleroma.Web.MastodonAPI.WebsocketHandler do require Logger alias Pleroma.Web.OAuth.Token - alias Pleroma.{Repo, User} + alias Pleroma.Repo + alias Pleroma.User @behaviour :cowboy_websocket_handler diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 479c9d20d..190377767 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -3,8 +3,11 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.OpenGraph do - alias Pleroma.{HTML, Formatter, User} - alias Pleroma.Web.{Metadata, MediaProxy} + alias Pleroma.HTML + alias Pleroma.Formatter + alias Pleroma.User + alias Pleroma.Web.Metadata + alias Pleroma.Web.MediaProxy alias Pleroma.Web.Metadata.Providers.Provider @behaviour Provider diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index e81de7bbd..c38827165 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -5,7 +5,11 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do use Pleroma.Web, :controller - alias Pleroma.{Config, Repo, Stats, User, Web} + alias Pleroma.Config + alias Pleroma.Repo + alias Pleroma.Stats + alias Pleroma.User + alias Pleroma.Web alias Pleroma.Web.ActivityPub.MRF plug(Pleroma.Web.FederatingPlug) diff --git a/lib/pleroma/web/oauth/authorization.ex b/lib/pleroma/web/oauth/authorization.ex index f8c65602d..ea742f678 100644 --- a/lib/pleroma/web/oauth/authorization.ex +++ b/lib/pleroma/web/oauth/authorization.ex @@ -5,8 +5,10 @@ defmodule Pleroma.Web.OAuth.Authorization do use Ecto.Schema - alias Pleroma.{User, Repo} - alias Pleroma.Web.OAuth.{Authorization, App} + alias Pleroma.User + alias Pleroma.Repo + alias Pleroma.Web.OAuth.Authorization + alias Pleroma.Web.OAuth.App import Ecto.{Changeset, Query} diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 8ec963c79..e4d0601f8 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -5,8 +5,11 @@ defmodule Pleroma.Web.OAuth.OAuthController do use Pleroma.Web, :controller - alias Pleroma.Web.OAuth.{Authorization, Token, App} - alias Pleroma.{Repo, User} + alias Pleroma.Web.OAuth.Authorization + alias Pleroma.Web.OAuth.Token + alias Pleroma.Web.OAuth.App + alias Pleroma.Repo + alias Pleroma.User alias Comeonin.Pbkdf2 plug(:fetch_session) diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index 4e01b123b..b0bbeeb69 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -7,8 +7,11 @@ defmodule Pleroma.Web.OAuth.Token do import Ecto.Query - alias Pleroma.{User, Repo} - alias Pleroma.Web.OAuth.{Token, App, Authorization} + alias Pleroma.User + alias Pleroma.Repo + alias Pleroma.Web.OAuth.Token + alias Pleroma.Web.OAuth.App + alias Pleroma.Web.OAuth.Authorization schema "oauth_tokens" do field(:token, :string) diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex index 3d41fc708..9e1f24bc4 100644 --- a/lib/pleroma/web/ostatus/activity_representer.ex +++ b/lib/pleroma/web/ostatus/activity_representer.ex @@ -3,8 +3,11 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.ActivityRepresenter do - alias Pleroma.{Activity, User, Object} + alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Object alias Pleroma.Web.OStatus.UserRepresenter + require Logger defp get_href(id) do diff --git a/lib/pleroma/web/ostatus/feed_representer.ex b/lib/pleroma/web/ostatus/feed_representer.ex index fd530307c..025d4731c 100644 --- a/lib/pleroma/web/ostatus/feed_representer.ex +++ b/lib/pleroma/web/ostatus/feed_representer.ex @@ -4,8 +4,10 @@ defmodule Pleroma.Web.OStatus.FeedRepresenter do alias Pleroma.User - alias Pleroma.Web.{OStatus, MediaProxy} - alias Pleroma.Web.OStatus.{UserRepresenter, ActivityRepresenter} + alias Pleroma.Web.OStatus + alias Pleroma.Web.MediaProxy + alias Pleroma.Web.OStatus.ActivityRepresenter + alias Pleroma.Web.OStatus.UserRepresenter def to_simple_form(user, activities, _users) do most_recent_update = diff --git a/lib/pleroma/web/ostatus/handlers/follow_handler.ex b/lib/pleroma/web/ostatus/handlers/follow_handler.ex index becdf2fbf..91ad4bc40 100644 --- a/lib/pleroma/web/ostatus/handlers/follow_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/follow_handler.ex @@ -3,7 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.FollowHandler do - alias Pleroma.Web.{XML, OStatus} + alias Pleroma.Web.XML + alias Pleroma.Web.OStatus alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.User diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex index 5bbb86f87..c2e585cac 100644 --- a/lib/pleroma/web/ostatus/handlers/note_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex @@ -4,9 +4,12 @@ defmodule Pleroma.Web.OStatus.NoteHandler do require Logger - alias Pleroma.Web.{XML, OStatus} - alias Pleroma.{Object, Activity} - alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} + alias Pleroma.Web.OStatus + alias Pleroma.Web.XML + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.CommonAPI @doc """ diff --git a/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex b/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex index 1c64f3c3d..c9085894d 100644 --- a/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex +++ b/lib/pleroma/web/ostatus/handlers/unfollow_handler.ex @@ -3,7 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OStatus.UnfollowHandler do - alias Pleroma.Web.{XML, OStatus} + alias Pleroma.Web.XML + alias Pleroma.Web.OStatus alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.User diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex index e1213923e..b4f5761ac 100644 --- a/lib/pleroma/web/ostatus/ostatus.ex +++ b/lib/pleroma/web/ostatus/ostatus.ex @@ -9,10 +9,19 @@ defmodule Pleroma.Web.OStatus do import Pleroma.Web.XML require Logger - alias Pleroma.{Repo, User, Web, Object, Activity} - alias Pleroma.Web.ActivityPub.{ActivityPub, Transmogrifier} - alias Pleroma.Web.{WebFinger, Websub} - alias Pleroma.Web.OStatus.{FollowHandler, UnfollowHandler, NoteHandler, DeleteHandler} + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Web + alias Pleroma.Object + alias Pleroma.Activity + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.WebFinger + alias Pleroma.Web.Websub + alias Pleroma.Web.OStatus.FollowHandler + alias Pleroma.Web.OStatus.UnfollowHandler + alias Pleroma.Web.OStatus.NoteHandler + alias Pleroma.Web.OStatus.DeleteHandler def is_representable?(%Activity{data: data}) do object = Object.normalize(data["object"]) diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index ed0df620b..db4c8f4da 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -5,10 +5,16 @@ defmodule Pleroma.Web.OStatus.OStatusController do use Pleroma.Web, :controller - alias Pleroma.{Activity, Object, User} - alias Pleroma.Web.ActivityPub.{ActivityPub, ActivityPubController, ObjectView} - alias Pleroma.Web.OStatus.{ActivityRepresenter, FeedRepresenter} - alias Pleroma.Web.{Federator, OStatus} + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.ActivityPubController + alias Pleroma.Web.ActivityPub.ObjectView + alias Pleroma.Web.OStatus.ActivityRepresenter + alias Pleroma.Web.OStatus.FeedRepresenter + alias Pleroma.Web.Federator + alias Pleroma.Web.OStatus alias Pleroma.Web.XML plug(Pleroma.Web.FederatingPlug when action in [:salmon_incoming]) diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex index ffd2aac91..ddd4fe037 100644 --- a/lib/pleroma/web/push/push.ex +++ b/lib/pleroma/web/push/push.ex @@ -5,7 +5,8 @@ defmodule Pleroma.Web.Push do use GenServer - alias Pleroma.{Repo, User} + alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.Push.Subscription require Logger diff --git a/lib/pleroma/web/push/subscription.ex b/lib/pleroma/web/push/subscription.ex index bd9d9f3a7..242e30910 100644 --- a/lib/pleroma/web/push/subscription.ex +++ b/lib/pleroma/web/push/subscription.ex @@ -4,8 +4,11 @@ defmodule Pleroma.Web.Push.Subscription do use Ecto.Schema + import Ecto.Changeset - alias Pleroma.{Repo, User} + + alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.OAuth.Token alias Pleroma.Web.Push.Subscription diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index 521fa7ee0..abb1cf7f2 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -3,7 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.RichMedia.Helpers do - alias Pleroma.{Activity, Object, HTML} + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.HTML alias Pleroma.Web.RichMedia.Parser def fetch_data_for_activity(%Activity{} = activity) do diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex index fb08d645b..a5a9e16c6 100644 --- a/lib/pleroma/web/salmon/salmon.ex +++ b/lib/pleroma/web/salmon/salmon.ex @@ -7,7 +7,8 @@ defmodule Pleroma.Web.Salmon do use Bitwise - alias Pleroma.{Instances, User} + alias Pleroma.Instances + alias Pleroma.User alias Pleroma.Web.XML alias Pleroma.Web.OStatus.ActivityRepresenter diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index 978c77e57..4de7608e4 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -5,7 +5,11 @@ defmodule Pleroma.Web.Streamer do use GenServer require Logger - alias Pleroma.{User, Notification, Activity, Object, Repo} + alias Pleroma.User + alias Pleroma.Notification + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.Repo alias Pleroma.Web.ActivityPub.ActivityPub @keepalive_interval :timer.seconds(30) diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index bf8d7e5aa..e2fdedb25 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -8,9 +8,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do require Logger alias Comeonin.Pbkdf2 - alias Pleroma.{Emoji, PasswordResetToken, User, Repo} + alias Pleroma.Emoji + alias Pleroma.PasswordResetToken + alias Pleroma.User + alias Pleroma.Repo alias Pleroma.Web - alias Pleroma.Web.{CommonAPI, OStatus, WebFinger} + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.OStatus + alias Pleroma.Web.WebFinger alias Pleroma.Web.ActivityPub.ActivityPub def show_password_reset(conn, %{"token" => token}) do diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index a5fec88f7..192ab7334 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -2,13 +2,19 @@ # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only +# FIXME: Remove this module? # THIS MODULE IS DEPRECATED! DON'T USE IT! # USE THE Pleroma.Web.TwitterAPI.Views.ActivityView MODULE! defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter - alias Pleroma.{Activity, Formatter, HTML, User} - alias Pleroma.Web.TwitterAPI.{ActivityView, TwitterAPI, UserView} + alias Pleroma.Activity + alias Pleroma.Formatter + alias Pleroma.HTML + alias Pleroma.User + alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.TwitterAPI + alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MastodonAPI.StatusView diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 7d00c01a1..db521a3ad 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -3,8 +3,13 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.TwitterAPI do - alias Pleroma.{UserInviteToken, User, Activity, Repo, Object} - alias Pleroma.{UserEmail, Mailer} + alias Pleroma.UserInviteToken + alias Pleroma.User + alias Pleroma.Activity + alias Pleroma.Repo + alias Pleroma.Object + alias Pleroma.UserEmail + alias Pleroma.Mailer alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.CommonAPI diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index c0081bf6e..c2f0dc2a9 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -8,10 +8,18 @@ defmodule Pleroma.Web.TwitterAPI.Controller do import Pleroma.Web.ControllerHelper, only: [json_response: 3] alias Ecto.Changeset - alias Pleroma.Web.ActivityPub.{ActivityPub, Utils} + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.CommonAPI - alias Pleroma.Web.TwitterAPI.{ActivityView, NotificationView, TwitterAPI, UserView} - alias Pleroma.{Activity, Object, Notification, Repo, User} + alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.NotificationView + alias Pleroma.Web.TwitterAPI.TwitterAPI + alias Pleroma.Web.TwitterAPI.UserView + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.Notification + alias Pleroma.Repo + alias Pleroma.User require Logger diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index dbcb732fe..661022afa 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -4,10 +4,17 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do use Pleroma.Web, :view - alias Pleroma.{Activity, Formatter, HTML, Object, Repo, User} + alias Pleroma.Activity + alias Pleroma.Formatter + alias Pleroma.HTML + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MastodonAPI.StatusView - alias Pleroma.Web.TwitterAPI.{ActivityView, TwitterAPI, UserView} + alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.TwitterAPI + alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter import Ecto.Query diff --git a/lib/pleroma/web/twitter_api/views/notification_view.ex b/lib/pleroma/web/twitter_api/views/notification_view.ex index 414ed4731..e7c7a7496 100644 --- a/lib/pleroma/web/twitter_api/views/notification_view.ex +++ b/lib/pleroma/web/twitter_api/views/notification_view.ex @@ -4,9 +4,11 @@ defmodule Pleroma.Web.TwitterAPI.NotificationView do use Pleroma.Web, :view - alias Pleroma.{Notification, User} + alias Pleroma.Notification + alias Pleroma.User alias Pleroma.Web.CommonAPI.Utils - alias Pleroma.Web.TwitterAPI.{ActivityView, UserView} + alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.UserView defp get_user(ap_id, opts) do cond do diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index 3cde3bc1b..a09450df7 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -4,7 +4,9 @@ defmodule Pleroma.Web.TwitterAPI.UserView do use Pleroma.Web, :view - alias Pleroma.{Formatter, HTML, User} + alias Pleroma.Formatter + alias Pleroma.HTML + alias Pleroma.User alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MediaProxy diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 0a6338312..5ea5ae48e 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -5,9 +5,12 @@ defmodule Pleroma.Web.WebFinger do @httpoison Application.get_env(:pleroma, :httpoison) - alias Pleroma.{User, XmlBuilder} + alias Pleroma.User + alias Pleroma.XmlBuilder alias Pleroma.Web - alias Pleroma.Web.{XML, Salmon, OStatus} + alias Pleroma.Web.XML + alias Pleroma.Web.Salmon + alias Pleroma.Web.OStatus require Jason require Logger diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex index de6508f52..a08d7993d 100644 --- a/lib/pleroma/web/websub/websub.ex +++ b/lib/pleroma/web/websub/websub.ex @@ -4,10 +4,14 @@ defmodule Pleroma.Web.Websub do alias Ecto.Changeset - alias Pleroma.{Instances, Repo} - alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription} + alias Pleroma.Instances + alias Pleroma.Repo + alias Pleroma.Web.Websub.WebsubServerSubscription + alias Pleroma.Web.Websub.WebsubClientSubscription alias Pleroma.Web.OStatus.FeedRepresenter - alias Pleroma.Web.{XML, Endpoint, OStatus} + alias Pleroma.Web.XML + alias Pleroma.Web.Endpoint + alias Pleroma.Web.OStatus alias Pleroma.Web.Router.Helpers require Logger diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex index a92dfe87b..1ad18a8a4 100644 --- a/lib/pleroma/web/websub/websub_controller.ex +++ b/lib/pleroma/web/websub/websub_controller.ex @@ -5,8 +5,10 @@ defmodule Pleroma.Web.Websub.WebsubController do use Pleroma.Web, :controller - alias Pleroma.{Repo, User} - alias Pleroma.Web.{Websub, Federator} + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Web.Websub + alias Pleroma.Web.Federator alias Pleroma.Web.Websub.WebsubClientSubscription require Logger -- cgit v1.2.3 From d924dc73ba9d4031c73cfa0cc810d3b2b2759b1d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 9 Feb 2019 16:20:18 +0100 Subject: de-group import/s --- lib/pleroma/instances/instance.ex | 3 ++- lib/pleroma/web/oauth/app.ex | 2 +- lib/pleroma/web/oauth/authorization.ex | 3 ++- lib/pleroma/web/web.ex | 7 +++++-- 4 files changed, 10 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex index ce3b46d50..48bc939dd 100644 --- a/lib/pleroma/instances/instance.ex +++ b/lib/pleroma/instances/instance.ex @@ -7,7 +7,8 @@ defmodule Pleroma.Instances.Instance do use Ecto.Schema - import Ecto.{Query, Changeset} + import Ecto.Query + import Ecto.Changeset schema "instances" do field(:host, :string) diff --git a/lib/pleroma/web/oauth/app.ex b/lib/pleroma/web/oauth/app.ex index 967ac04b5..3e8acde31 100644 --- a/lib/pleroma/web/oauth/app.ex +++ b/lib/pleroma/web/oauth/app.ex @@ -4,7 +4,7 @@ defmodule Pleroma.Web.OAuth.App do use Ecto.Schema - import Ecto.{Changeset} + import Ecto.Changeset schema "apps" do field(:client_name, :string) diff --git a/lib/pleroma/web/oauth/authorization.ex b/lib/pleroma/web/oauth/authorization.ex index ea742f678..75c9ab9aa 100644 --- a/lib/pleroma/web/oauth/authorization.ex +++ b/lib/pleroma/web/oauth/authorization.ex @@ -10,7 +10,8 @@ defmodule Pleroma.Web.OAuth.Authorization do alias Pleroma.Web.OAuth.Authorization alias Pleroma.Web.OAuth.App - import Ecto.{Changeset, Query} + import Ecto.Changeset + import Ecto.Query schema "oauth_authorizations" do field(:token, :string) diff --git a/lib/pleroma/web/web.ex b/lib/pleroma/web/web.ex index 4d5fd028e..853aa2a87 100644 --- a/lib/pleroma/web/web.ex +++ b/lib/pleroma/web/web.ex @@ -24,7 +24,8 @@ defmodule Pleroma.Web do quote do use Phoenix.Controller, namespace: Pleroma.Web import Plug.Conn - import Pleroma.Web.{Gettext, Router.Helpers} + import Pleroma.Web.Gettext + import Pleroma.Web.Router.Helpers end end @@ -37,7 +38,9 @@ defmodule Pleroma.Web do # Import convenience functions from controllers import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1] - import Pleroma.Web.{ErrorHelpers, Gettext, Router.Helpers} + import Pleroma.Web.ErrorHelpers + import Pleroma.Web.Gettext + import Pleroma.Web.Router.Helpers require Logger -- cgit v1.2.3 From 6ca633ddd30e8330e47f6456fe16fa72506e2e13 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 9 Feb 2019 16:30:42 +0100 Subject: Mix.Tasks.Pleroma.Uploads: Disable Enum.reduce warning on line 100 (unsure) --- lib/mix/tasks/pleroma/uploads.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/mix/tasks/pleroma/uploads.ex b/lib/mix/tasks/pleroma/uploads.ex index 697ad1a7b..a01e61627 100644 --- a/lib/mix/tasks/pleroma/uploads.ex +++ b/lib/mix/tasks/pleroma/uploads.ex @@ -97,6 +97,7 @@ defmodule Mix.Tasks.Pleroma.Uploads do timeout: 150_000 ) |> Stream.chunk_every(@log_every) + # credo:disable-for-next-line Credo.Check.Warning.UnusedEnumOperation |> Enum.reduce(0, fn done, count -> count = count + length(done) Mix.shell().info("Uploaded #{count}/#{total_count} files") -- cgit v1.2.3 From a0d732ec55fcbce8cf345344d1456dc77bb0f3bf Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 9 Feb 2019 17:47:57 +0100 Subject: it works!! --- lib/pleroma/notification.ex | 2 ++ lib/pleroma/web/thread_mute.ex | 28 +++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 2364d36da..d05708e41 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -6,6 +6,7 @@ defmodule Pleroma.Notification do use Ecto.Schema alias Pleroma.{User, Activity, Notification, Repo} alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.ThreadMute import Ecto.Query schema "notifications" do @@ -112,6 +113,7 @@ defmodule Pleroma.Notification do # TODO move to sql, too. def create_notification(%Activity{} = activity, %User{} = user) do unless User.blocks?(user, %{ap_id: activity.data["actor"]}) or + ThreadMute.muted?(user, activity) or user.ap_id == activity.data["actor"] or (activity.data["type"] == "Follow" and Enum.any?(Notification.for_user(user), fn notif -> diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex index 3a950f474..146de0d80 100644 --- a/lib/pleroma/web/thread_mute.ex +++ b/lib/pleroma/web/thread_mute.ex @@ -4,6 +4,7 @@ defmodule Pleroma.Web.ThreadMute do use Ecto.Schema + alias Pleroma.Web.ThreadMute alias Pleroma.{Activity, Repo, User} require Ecto.Query @@ -13,16 +14,37 @@ defmodule Pleroma.Web.ThreadMute do end def add_mute(user, id) do - %{data: %{"context" => context}} = Activity.get_by_id(id) + activity = Activity.get_by_id(id) + context = activity.data["context"] mute = %Pleroma.Web.ThreadMute{user_id: user.id, context: context} Repo.insert(mute) + {:ok, activity} end def remove_mute(user, id) do user_id = Pleroma.FlakeId.from_string(user.id) - %{data: %{"context" => context}} = Activity.get_by_id(id) + activity = Activity.get_by_id(id) + context = activity.data["context"] - Ecto.Query.from(m in "thread_mutes", where: m.user_id == ^user_id and m.context == ^context) + Ecto.Query.from(m in ThreadMute, where: m.user_id == ^user_id and m.context == ^context) |> Repo.delete_all() + + {:ok, activity} + end + + def muted?(user, activity) do + user_id = Pleroma.FlakeId.from_string(user.id) + context = activity.data["context"] + + result = + Ecto.Query.from(m in ThreadMute, + where: m.user_id == ^user_id and m.context == ^context + ) + |> Repo.all() + + case result do + [] -> false + _ -> true + end end end -- cgit v1.2.3 From 638456ce8f6b7f44356e69bac89d794c19e969d7 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 9 Feb 2019 18:08:46 +0100 Subject: elixir too new for CI's mix format lol --- lib/pleroma/notification.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index d05708e41..ce4826b23 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -113,8 +113,7 @@ defmodule Pleroma.Notification do # TODO move to sql, too. def create_notification(%Activity{} = activity, %User{} = user) do unless User.blocks?(user, %{ap_id: activity.data["actor"]}) or - ThreadMute.muted?(user, activity) or - user.ap_id == activity.data["actor"] or + ThreadMute.muted?(user, activity) or user.ap_id == activity.data["actor"] or (activity.data["type"] == "Follow" and Enum.any?(Notification.for_user(user), fn notif -> notif.activity.data["type"] == "Follow" and -- cgit v1.2.3 From 6a150de3bd416cfe0b4870deee2e6557791345f8 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 9 Feb 2019 20:52:11 +0100 Subject: Add unique index and unique constraint check, uniqueness test fails --- lib/pleroma/web/thread_mute.ex | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex index 146de0d80..b5bff86be 100644 --- a/lib/pleroma/web/thread_mute.ex +++ b/lib/pleroma/web/thread_mute.ex @@ -13,12 +13,22 @@ defmodule Pleroma.Web.ThreadMute do field(:context, :string) end + def changeset(mute, params \\ %{}) do + mute + |> Ecto.Changeset.cast(params, [:user_id, :context]) + |> Ecto.Changeset.foreign_key_constraint(:user_id) + |> Ecto.Changeset.unique_constraint(:user_id, name: :unique_index) + end + def add_mute(user, id) do activity = Activity.get_by_id(id) context = activity.data["context"] - mute = %Pleroma.Web.ThreadMute{user_id: user.id, context: context} - Repo.insert(mute) - {:ok, activity} + changeset = changeset(%Pleroma.Web.ThreadMute{}, %{user_id: user.id, context: context}) + + case Repo.insert(changeset) do + {:ok, _} -> {:ok, activity} + {:error, _} -> {:error, "conversation is already muted"} + end end def remove_mute(user, id) do -- cgit v1.2.3 From f8388be9c69981958e9a96dce68fc39bdedb5cd3 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 9 Feb 2019 22:01:08 +0100 Subject: Do object insertion through Cachex So we don't flood our postgres logs with errors. Should also make things slightly faster. --- lib/pleroma/object.ex | 22 +++++++++++++++++++++- lib/pleroma/web/activity_pub/utils.ex | 10 ++-------- lib/pleroma/web/twitter_api/twitter_api.ex | 12 ++---------- 3 files changed, 25 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 7b46a3b05..96079cf22 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -13,9 +13,29 @@ defmodule Pleroma.Object do timestamps() end + def insert_or_get(cng) do + {_, data} = fetch_field(cng, :data) + id = data["id"] || data[:id] + key = "object:#{id}" + + fetcher = fn _ -> + with nil <- get_by_ap_id(id), + {:ok, object} <- Repo.insert(cng) do + {:commit, object} + else + %Object{} = object -> {:commit, object} + e -> {:ignore, e} + end + end + + with {state, object} when state in [:commit, :ok] <- Cachex.fetch(:object_cache, key, fetcher) do + {:ok, object} + end + end + def create(data) do Object.change(%Object{}, %{data: data}) - |> Repo.insert() + |> insert_or_get() end def change(struct, params \\ %{}) do diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 4a2cc6738..134701e80 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -134,14 +134,8 @@ defmodule Pleroma.Web.ActivityPub.Utils do context = context || generate_id("contexts") changeset = Object.context_mapping(context) - case Repo.insert(changeset) do - {:ok, object} -> - object - - # This should be solved by an upsert, but it seems ecto - # has problems accessing the constraint inside the jsonb. - {:error, _} -> - Object.get_cached_by_ap_id(context) + with {:ok, object} <- Object.insert_or_get(changeset) do + object end end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 7d00c01a1..ddd5c5cfb 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -305,16 +305,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do else _e -> changeset = Object.context_mapping(context) - - case Repo.insert(changeset) do - {:ok, %{id: id}} -> - id - - # This should be solved by an upsert, but it seems ecto - # has problems accessing the constraint inside the jsonb. - {:error, _} -> - Object.get_cached_by_ap_id(context).id - end + {:ok, object} = Object.insert_or_get(changeset) + object.id end end -- cgit v1.2.3 From cc21fc5f537510416a088adff085b675de1be58e Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sun, 10 Feb 2019 09:31:20 +0100 Subject: refactor, status view updating, error handling --- .../web/mastodon_api/mastodon_api_controller.ex | 5 +++ lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- lib/pleroma/web/thread_mute.ex | 38 ++++++++++++---------- 3 files changed, 26 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index a93f4297b..073e0a5ea 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -450,6 +450,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do conn |> put_view(StatusView) |> try_render("status.json", %{activity: activity, for: user, as: :activity}) + else + {:error, reason} -> + conn + |> put_resp_content_type("application/json") + |> send_resp(:bad_request, Jason.encode!(%{"error" => reason})) end end diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index a227d742d..d6176a68a 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -160,7 +160,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do reblogged: present?(repeated), favourited: present?(favorited), bookmarked: present?(bookmarked), - muted: false, + muted: Pleroma.Web.ThreadMute.muted?(user, activity), pinned: pinned?(activity, user), sensitive: sensitive, spoiler_text: object["summary"] || "", diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex index b5bff86be..695ea2512 100644 --- a/lib/pleroma/web/thread_mute.ex +++ b/lib/pleroma/web/thread_mute.ex @@ -20,40 +20,42 @@ defmodule Pleroma.Web.ThreadMute do |> Ecto.Changeset.unique_constraint(:user_id, name: :unique_index) end + def query(user, context) do + user_id = Pleroma.FlakeId.from_string(user.id) + + ThreadMute + |> Ecto.Query.where(user_id: ^user_id) + |> Ecto.Query.where(context: ^context) + end + def add_mute(user, id) do activity = Activity.get_by_id(id) - context = activity.data["context"] - changeset = changeset(%Pleroma.Web.ThreadMute{}, %{user_id: user.id, context: context}) - case Repo.insert(changeset) do - {:ok, _} -> {:ok, activity} + with changeset <- + changeset(%ThreadMute{}, %{user_id: user.id, context: activity.data["context"]}), + {:ok, _} <- Repo.insert(changeset) do + {:ok, activity} + else {:error, _} -> {:error, "conversation is already muted"} end end def remove_mute(user, id) do - user_id = Pleroma.FlakeId.from_string(user.id) activity = Activity.get_by_id(id) - context = activity.data["context"] - Ecto.Query.from(m in ThreadMute, where: m.user_id == ^user_id and m.context == ^context) + query(user, activity.data["context"]) |> Repo.delete_all() {:ok, activity} end - def muted?(user, activity) do - user_id = Pleroma.FlakeId.from_string(user.id) - context = activity.data["context"] + def muted?(%{id: nil} = _user, _), do: false - result = - Ecto.Query.from(m in ThreadMute, - where: m.user_id == ^user_id and m.context == ^context - ) - |> Repo.all() - - case result do - [] -> false + def muted?(user, activity) do + with query <- query(user, activity.data["context"]), + [] <- Repo.all(query) do + false + else _ -> true end end -- cgit v1.2.3 From 45e57dd187ecb9463f0114f75a05f03dbc9e206a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 10 Feb 2019 21:37:51 +0000 Subject: rich media: tighten fetching timeouts and size limits --- lib/pleroma/web/rich_media/parser.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index 38f1cdeec..4341141df 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -9,6 +9,13 @@ defmodule Pleroma.Web.RichMedia.Parser do Pleroma.Web.RichMedia.Parsers.OEmbed ] + @hackney_options [ + pool: :media, + timeout: 2_000, + recv_timeout: 2_000, + max_body: 2_000_000 + ] + def parse(nil), do: {:error, "No URL provided"} if Mix.env() == :test do @@ -28,7 +35,7 @@ defmodule Pleroma.Web.RichMedia.Parser do defp parse_url(url) do try do - {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: [pool: :media]) + {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @hackney_options) html |> maybe_parse() |> clean_parsed_data() |> check_parsed_data() rescue -- cgit v1.2.3 From d53e36bf1e004177277cb5917bb290d512278aa9 Mon Sep 17 00:00:00 2001 From: lambda Date: Mon, 11 Feb 2019 08:07:39 +0000 Subject: Revert "Merge branch 'object-creation' into 'develop'" This reverts merge request !802 --- lib/pleroma/object.ex | 22 +--------------------- lib/pleroma/web/activity_pub/utils.ex | 10 ++++++++-- lib/pleroma/web/twitter_api/twitter_api.ex | 12 ++++++++++-- 3 files changed, 19 insertions(+), 25 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index dabb49536..5f1fc801b 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -20,29 +20,9 @@ defmodule Pleroma.Object do timestamps() end - def insert_or_get(cng) do - {_, data} = fetch_field(cng, :data) - id = data["id"] || data[:id] - key = "object:#{id}" - - fetcher = fn _ -> - with nil <- get_by_ap_id(id), - {:ok, object} <- Repo.insert(cng) do - {:commit, object} - else - %Object{} = object -> {:commit, object} - e -> {:ignore, e} - end - end - - with {state, object} when state in [:commit, :ok] <- Cachex.fetch(:object_cache, key, fetcher) do - {:ok, object} - end - end - def create(data) do Object.change(%Object{}, %{data: data}) - |> insert_or_get() + |> Repo.insert() end def change(struct, params \\ %{}) do diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index da6cca4dd..964e11c9d 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -142,8 +142,14 @@ defmodule Pleroma.Web.ActivityPub.Utils do context = context || generate_id("contexts") changeset = Object.context_mapping(context) - with {:ok, object} <- Object.insert_or_get(changeset) do - object + case Repo.insert(changeset) do + {:ok, object} -> + object + + # This should be solved by an upsert, but it seems ecto + # has problems accessing the constraint inside the jsonb. + {:error, _} -> + Object.get_cached_by_ap_id(context) end end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 162beb9be..db521a3ad 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -310,8 +310,16 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do else _e -> changeset = Object.context_mapping(context) - {:ok, object} = Object.insert_or_get(changeset) - object.id + + case Repo.insert(changeset) do + {:ok, %{id: id}} -> + id + + # This should be solved by an upsert, but it seems ecto + # has problems accessing the constraint inside the jsonb. + {:error, _} -> + Object.get_cached_by_ap_id(context).id + end end end -- cgit v1.2.3 From c01ef574c192488c2643a20b4064439757613449 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Mon, 11 Feb 2019 11:59:51 +0100 Subject: Refactor as per Rin's suggestions, add endpoint tests --- lib/pleroma/notification.ex | 4 +- lib/pleroma/thread_mute.ex | 45 ++++++++++++++++ lib/pleroma/web/common_api/common_api.ex | 25 ++++++++- .../web/mastodon_api/mastodon_api_controller.ex | 6 ++- lib/pleroma/web/mastodon_api/views/status_view.ex | 3 +- lib/pleroma/web/thread_mute.ex | 62 ---------------------- 6 files changed, 77 insertions(+), 68 deletions(-) create mode 100644 lib/pleroma/thread_mute.ex delete mode 100644 lib/pleroma/web/thread_mute.ex (limited to 'lib') diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index ce4826b23..9ebfd5cb0 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -6,7 +6,7 @@ defmodule Pleroma.Notification do use Ecto.Schema alias Pleroma.{User, Activity, Notification, Repo} alias Pleroma.Web.CommonAPI.Utils - alias Pleroma.Web.ThreadMute + alias Pleroma.Web.CommonAPI import Ecto.Query schema "notifications" do @@ -113,7 +113,7 @@ defmodule Pleroma.Notification do # TODO move to sql, too. def create_notification(%Activity{} = activity, %User{} = user) do unless User.blocks?(user, %{ap_id: activity.data["actor"]}) or - ThreadMute.muted?(user, activity) or user.ap_id == activity.data["actor"] or + CommonAPI.thread_muted?(user, activity) or user.ap_id == activity.data["actor"] or (activity.data["type"] == "Follow" and Enum.any?(Notification.for_user(user), fn notif -> notif.activity.data["type"] == "Follow" and diff --git a/lib/pleroma/thread_mute.ex b/lib/pleroma/thread_mute.ex new file mode 100644 index 000000000..0b577113d --- /dev/null +++ b/lib/pleroma/thread_mute.ex @@ -0,0 +1,45 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.ThreadMute do + use Ecto.Schema + alias Pleroma.{Repo, User, ThreadMute} + require Ecto.Query + + schema "thread_mutes" do + belongs_to(:user, User, type: Pleroma.FlakeId) + field(:context, :string) + end + + def changeset(mute, params \\ %{}) do + mute + |> Ecto.Changeset.cast(params, [:user_id, :context]) + |> Ecto.Changeset.foreign_key_constraint(:user_id) + |> Ecto.Changeset.unique_constraint(:user_id, name: :unique_index) + end + + def query(user_id, context) do + user_id = Pleroma.FlakeId.from_string(user_id) + + ThreadMute + |> Ecto.Query.where(user_id: ^user_id) + |> Ecto.Query.where(context: ^context) + end + + def add_mute(user_id, context) do + %ThreadMute{} + |> changeset(%{user_id: user_id, context: context}) + |> Repo.insert() + end + + def remove_mute(user_id, context) do + query(user_id, context) + |> Repo.delete_all() + end + + def check_muted(user_id, context) do + query(user_id, context) + |> Repo.all() + end +end diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 7084da6de..7782c64dd 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPI do - alias Pleroma.{User, Repo, Activity, Object} + alias Pleroma.{User, Repo, Activity, Object, ThreadMute} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Formatter @@ -216,4 +216,27 @@ defmodule Pleroma.Web.CommonAPI do {:error, "Could not unpin"} end end + + def add_mute(user, activity) do + with {:ok, _} <- ThreadMute.add_mute(user.id, activity.data["context"]) do + {:ok, activity} + else + {:error, _} -> {:error, "conversation is already muted"} + end + end + + def remove_mute(user, activity) do + ThreadMute.remove_mute(user.id, activity.data["context"]) + {:ok, activity} + end + + def thread_muted?(%{id: nil} = _user, _activity), do: false + + def thread_muted?(user, activity) do + with [] <- ThreadMute.check_muted(user.id, activity.data["context"]) do + false + else + _ -> true + end + end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 073e0a5ea..18fa16b03 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -446,7 +446,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def mute_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with {:ok, activity} <- Pleroma.Web.ThreadMute.add_mute(user, id) do + activity = Activity.get_by_id(id) + with {:ok, activity} <- CommonAPI.add_mute(user, activity) do conn |> put_view(StatusView) |> try_render("status.json", %{activity: activity, for: user, as: :activity}) @@ -459,7 +460,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def unmute_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do - with {:ok, activity} <- Pleroma.Web.ThreadMute.remove_mute(user, id) do + activity = Activity.get_by_id(id) + with {:ok, activity} <- CommonAPI.remove_mute(user, activity) do conn |> put_view(StatusView) |> try_render("status.json", %{activity: activity, for: user, as: :activity}) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index d6176a68a..368b79ea7 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -9,6 +9,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do alias Pleroma.HTML alias Pleroma.Repo alias Pleroma.User + alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MediaProxy alias Pleroma.Web.MastodonAPI.AccountView @@ -160,7 +161,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do reblogged: present?(repeated), favourited: present?(favorited), bookmarked: present?(bookmarked), - muted: Pleroma.Web.ThreadMute.muted?(user, activity), + muted: CommonAPI.thread_muted?(user, activity), pinned: pinned?(activity, user), sensitive: sensitive, spoiler_text: object["summary"] || "", diff --git a/lib/pleroma/web/thread_mute.ex b/lib/pleroma/web/thread_mute.ex deleted file mode 100644 index 695ea2512..000000000 --- a/lib/pleroma/web/thread_mute.ex +++ /dev/null @@ -1,62 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.ThreadMute do - use Ecto.Schema - alias Pleroma.Web.ThreadMute - alias Pleroma.{Activity, Repo, User} - require Ecto.Query - - schema "thread_mutes" do - belongs_to(:user, User, type: Pleroma.FlakeId) - field(:context, :string) - end - - def changeset(mute, params \\ %{}) do - mute - |> Ecto.Changeset.cast(params, [:user_id, :context]) - |> Ecto.Changeset.foreign_key_constraint(:user_id) - |> Ecto.Changeset.unique_constraint(:user_id, name: :unique_index) - end - - def query(user, context) do - user_id = Pleroma.FlakeId.from_string(user.id) - - ThreadMute - |> Ecto.Query.where(user_id: ^user_id) - |> Ecto.Query.where(context: ^context) - end - - def add_mute(user, id) do - activity = Activity.get_by_id(id) - - with changeset <- - changeset(%ThreadMute{}, %{user_id: user.id, context: activity.data["context"]}), - {:ok, _} <- Repo.insert(changeset) do - {:ok, activity} - else - {:error, _} -> {:error, "conversation is already muted"} - end - end - - def remove_mute(user, id) do - activity = Activity.get_by_id(id) - - query(user, activity.data["context"]) - |> Repo.delete_all() - - {:ok, activity} - end - - def muted?(%{id: nil} = _user, _), do: false - - def muted?(user, activity) do - with query <- query(user, activity.data["context"]), - [] <- Repo.all(query) do - false - else - _ -> true - end - end -end -- cgit v1.2.3 From 379d04692cdbf558c611c588c0e6a4262c02a58c Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 11 Feb 2019 21:35:40 +0300 Subject: Filter summary in keywordpolicy --- lib/pleroma/web/activity_pub/mrf/keyword_policy.ex | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex index ce6d2e529..5fdc03414 100644 --- a/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/keyword_policy.ex @@ -12,9 +12,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do String.match?(string, pattern) end - defp check_reject(%{"object" => %{"content" => content}} = message) do + defp check_reject(%{"object" => %{"content" => content, "summary" => summary}} = message) do if Enum.any?(Pleroma.Config.get([:mrf_keyword, :reject]), fn pattern -> - string_matches?(content, pattern) + string_matches?(content, pattern) or string_matches?(summary, pattern) end) do {:reject, nil} else @@ -22,10 +22,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do end end - defp check_ftl_removal(%{"to" => to, "object" => %{"content" => content}} = message) do + defp check_ftl_removal( + %{"to" => to, "object" => %{"content" => content, "summary" => summary}} = message + ) do if "https://www.w3.org/ns/activitystreams#Public" in to and Enum.any?(Pleroma.Config.get([:mrf_keyword, :federated_timeline_removal]), fn pattern -> - string_matches?(content, pattern) + string_matches?(content, pattern) or string_matches?(summary, pattern) end) do to = List.delete(to, "https://www.w3.org/ns/activitystreams#Public") cc = ["https://www.w3.org/ns/activitystreams#Public" | message["cc"] || []] @@ -41,14 +43,20 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do end end - defp check_replace(%{"object" => %{"content" => content}} = message) do - content = - Enum.reduce(Pleroma.Config.get([:mrf_keyword, :replace]), content, fn {pattern, replacement}, - acc -> - String.replace(acc, pattern, replacement) + defp check_replace(%{"object" => %{"content" => content, "summary" => summary}} = message) do + {content, summary} = + Enum.reduce(Pleroma.Config.get([:mrf_keyword, :replace]), {content, summary}, fn {pattern, + replacement}, + {content_acc, + summary_acc} -> + {String.replace(content_acc, pattern, replacement), + String.replace(summary_acc, pattern, replacement)} end) - {:ok, put_in(message["object"]["content"], content)} + {:ok, + message + |> put_in(["object", "content"], content) + |> put_in(["object", "summary"], summary)} end @impl true -- cgit v1.2.3 From ea1058929c4dd569c00864f5292ec0a689acd1c6 Mon Sep 17 00:00:00 2001 From: shibayashi Date: Tue, 12 Feb 2019 00:08:52 +0100 Subject: Use url[:scheme] instead of protocol to determine if https is enabled --- lib/pleroma/plugs/http_security_plug.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/plugs/http_security_plug.ex b/lib/pleroma/plugs/http_security_plug.ex index 2a266c407..3c8e6a18f 100644 --- a/lib/pleroma/plugs/http_security_plug.ex +++ b/lib/pleroma/plugs/http_security_plug.ex @@ -33,7 +33,7 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do end defp csp_string do - protocol = Config.get([Pleroma.Web.Endpoint, :protocol]) + scheme = Config.get([Pleroma.Web.Endpoint, :url])[:scheme] [ "default-src 'none'", @@ -46,7 +46,7 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do "script-src 'self'", "connect-src 'self' " <> String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"), "manifest-src 'self'", - if protocol == "https" do + if scheme == "https" do "upgrade-insecure-requests" end ] -- cgit v1.2.3 From ac7ef0999d70145ed5217258a4908eba609d68de Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 11 Feb 2019 23:59:04 +0000 Subject: WIP: Fix Twitter Cards Twitter cards were not passing any useful metadata. A few things were being handled on Twitter's end by trying to match OpenGraph tags with their own, but it wasn't working at all for media. This is an attempt to fix that. Common functions have been pulled out of opengraph and put into utils. Twitter's functionality was entirely replaced with a direct copy of Opengraph's and then modified as needed. Profiles are now represented as Summary Cards Posts with images are now represented as Summart with Large Image Cards Posts with video and audio attachments are represented as Player Cards. This now passes the Twitter Card Validator. Validator and Docs are below https://cards-dev.twitter.com/validator https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/abouts-cards --- lib/pleroma/web/metadata/opengraph.ex | 58 ++++---------- lib/pleroma/web/metadata/twitter_card.ex | 128 ++++++++++++++++++++++++------- lib/pleroma/web/metadata/utils.ex | 42 ++++++++++ 3 files changed, 157 insertions(+), 71 deletions(-) create mode 100644 lib/pleroma/web/metadata/utils.ex (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 190377767..4d6639c84 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -3,12 +3,10 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.OpenGraph do - alias Pleroma.HTML - alias Pleroma.Formatter alias Pleroma.User alias Pleroma.Web.Metadata - alias Pleroma.Web.MediaProxy alias Pleroma.Web.Metadata.Providers.Provider + alias Pleroma.Web.Metadata.Utils @behaviour Provider @@ -19,7 +17,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do user: user }) do attachments = build_attachments(object) - scrubbed_content = scrub_html_and_truncate(object) + scrubbed_content = Utils.scrub_html_and_truncate(object) # Zero width space content = if scrubbed_content != "" and scrubbed_content != "\u200B" do @@ -44,13 +42,14 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do {:meta, [ property: "og:description", - content: "#{user_name_string(user)}" <> content + content: "#{Utils.user_name_string(user)}" <> content ], []}, {:meta, [property: "og:type", content: "website"], []} ] ++ if attachments == [] or Metadata.activity_nsfw?(object) do [ - {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, + {:meta, [property: "og:image", content: Utils.attachment_url(User.avatar_url(user))], + []}, {:meta, [property: "og:image:width", content: 150], []}, {:meta, [property: "og:image:height", content: 150], []} ] @@ -61,17 +60,17 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do @impl Provider def build_tags(%{user: user}) do - with truncated_bio = scrub_html_and_truncate(user.bio || "") do + with truncated_bio = Utils.scrub_html_and_truncate(user.bio || "") do [ {:meta, [ property: "og:title", - content: user_name_string(user) + content: Utils.user_name_string(user) ], []}, {:meta, [property: "og:url", content: User.profile_url(user)], []}, {:meta, [property: "og:description", content: truncated_bio], []}, {:meta, [property: "og:type", content: "website"], []}, - {:meta, [property: "og:image", content: attachment_url(User.avatar_url(user))], []}, + {:meta, [property: "og:image", content: Utils.attachment_url(User.avatar_url(user))], []}, {:meta, [property: "og:image:width", content: 150], []}, {:meta, [property: "og:image:height", content: 150], []} ] @@ -93,13 +92,14 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do case media_type do "audio" -> [ - {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []} + {:meta, + [property: "og:" <> media_type, content: Utils.attachment_url(url["href"])], []} | acc ] "image" -> [ - {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], + {:meta, [property: "og:" <> media_type, content: Utils.attachment_url(url["href"])], []}, {:meta, [property: "og:image:width", content: 150], []}, {:meta, [property: "og:image:height", content: 150], []} @@ -108,7 +108,8 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do "video" -> [ - {:meta, [property: "og:" <> media_type, content: attachment_url(url["href"])], []} + {:meta, + [property: "og:" <> media_type, content: Utils.attachment_url(url["href"])], []} | acc ] @@ -120,37 +121,4 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do acc ++ rendered_tags end) end - - defp scrub_html_and_truncate(%{data: %{"content" => content}} = object) do - content - # html content comes from DB already encoded, decode first and scrub after - |> HtmlEntities.decode() - |> String.replace(~r//, " ") - |> HTML.get_cached_stripped_html_for_object(object, __MODULE__) - |> Formatter.demojify() - |> Formatter.truncate() - end - - defp scrub_html_and_truncate(content) when is_binary(content) do - content - # html content comes from DB already encoded, decode first and scrub after - |> HtmlEntities.decode() - |> String.replace(~r//, " ") - |> HTML.strip_tags() - |> Formatter.demojify() - |> Formatter.truncate() - end - - defp attachment_url(url) do - MediaProxy.url(url) - end - - defp user_name_string(user) do - "#{user.name} " <> - if user.local do - "(@#{user.nickname}@#{Pleroma.Web.Endpoint.host()})" - else - "(@#{user.nickname})" - end - end end diff --git a/lib/pleroma/web/metadata/twitter_card.ex b/lib/pleroma/web/metadata/twitter_card.ex index 32b979357..0365e4647 100644 --- a/lib/pleroma/web/metadata/twitter_card.ex +++ b/lib/pleroma/web/metadata/twitter_card.ex @@ -3,44 +3,120 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.TwitterCard do - alias Pleroma.Web.Metadata.Providers.Provider + alias Pleroma.User alias Pleroma.Web.Metadata + alias Pleroma.Web.Metadata.Providers.Provider + alias Pleroma.Web.Metadata.Utils @behaviour Provider @impl Provider - def build_tags(%{object: object}) do - if Metadata.activity_nsfw?(object) or object.data["attachment"] == [] do - build_tags(nil) - else - case find_first_acceptable_media_type(object) do - "image" -> - [{:meta, [property: "twitter:card", content: "summary_large_image"], []}] - - "audio" -> - [{:meta, [property: "twitter:card", content: "player"], []}] - - "video" -> - [{:meta, [property: "twitter:card", content: "player"], []}] - - _ -> - build_tags(nil) + def build_tags(%{ + object: object, + user: user + }) do + attachments = build_attachments(object) + scrubbed_content = Utils.scrub_html_and_truncate(object) + # Zero width space + content = + if scrubbed_content != "" and scrubbed_content != "\u200B" do + "“" <> scrubbed_content <> "”" + else + "" + end + + [ + {:meta, + [ + property: "twitter:title", + content: Utils.user_name_string(user) + ], []}, + {:meta, + [ + property: "twitter:description", + content: content + ], []} + ] ++ + if attachments == [] or Metadata.activity_nsfw?(object) do + [ + {:meta, + [property: "twitter:image", content: Utils.attachment_url(User.avatar_url(user))], []}, + {:meta, [property: "twitter:card", content: "summary_large_image"], []} + ] + else + attachments end - end end @impl Provider - def build_tags(_) do - [{:meta, [property: "twitter:card", content: "summary"], []}] + def build_tags(%{user: user}) do + with truncated_bio = Utils.scrub_html_and_truncate(user.bio || "") do + [ + {:meta, + [ + property: "twitter:title", + content: Utils.user_name_string(user) + ], []}, + {:meta, [property: "twitter:description", content: truncated_bio], []}, + {:meta, [property: "twitter:image", content: Utils.attachment_url(User.avatar_url(user))], + []}, + {:meta, [property: "twitter:card", content: "summary"], []} + ] + end end - def find_first_acceptable_media_type(%{data: %{"attachment" => attachment}}) do - Enum.find_value(attachment, fn attachment -> - Enum.find_value(attachment["url"], fn url -> - Enum.find(["image", "audio", "video"], fn media_type -> - String.starts_with?(url["mediaType"], media_type) + defp build_attachments(%{data: %{"attachment" => attachments}}) do + Enum.reduce(attachments, [], fn attachment, acc -> + rendered_tags = + Enum.reduce(attachment["url"], [], fn url, acc -> + content_type = url["mediaType"] + + media_type = + Enum.find(["image", "audio", "video"], fn media_type -> + String.starts_with?(url["mediaType"], media_type) + end) + + # TODO: Add additional properties to objects when we have the data available. + case media_type do + "audio" -> + [ + {:meta, [property: "twitter:card", content: "player"], []}, + {:meta, [property: "twitter:player", content: Utils.attachment_url(url["href"])], + []} + | acc + ] + + "image" -> + [ + {:meta, [property: "twitter:card", content: "summary_large_image"], []}, + {:meta, + [ + property: "twitter:player", + content: + Utils.attachment_url( + Pleroma.Uploaders.Uploader.preview_url(content_type, url["href"]) + ) + ], []} + | acc + ] + + # TODO: Need the true width and height values here or Twitter renders an iFrame with a bad aspect ratio + "video" -> + [ + {:meta, [property: "twitter:card", content: "player"], []}, + {:meta, [property: "twitter:player", content: Utils.attachment_url(url["href"])], + []}, + {:meta, [property: "twitter:player:width", content: "1280"], []}, + {:meta, [property: "twitter:player:height", content: "720"], []} + | acc + ] + + _ -> + acc + end end) - end) + + acc ++ rendered_tags end) end end diff --git a/lib/pleroma/web/metadata/utils.ex b/lib/pleroma/web/metadata/utils.ex new file mode 100644 index 000000000..a166800d4 --- /dev/null +++ b/lib/pleroma/web/metadata/utils.ex @@ -0,0 +1,42 @@ +# Pleroma: A lightweight social networking server +# Copyright \xc2\xa9 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Metadata.Utils do + alias Pleroma.HTML + alias Pleroma.Formatter + alias Pleroma.Web.MediaProxy + + def scrub_html_and_truncate(%{data: %{"content" => content}} = object) do + content + # html content comes from DB already encoded, decode first and scrub after + |> HtmlEntities.decode() + |> String.replace(~r//, " ") + |> HTML.get_cached_stripped_html_for_object(object, __MODULE__) + |> Formatter.demojify() + |> Formatter.truncate() + end + + def scrub_html_and_truncate(content) when is_binary(content) do + content + # html content comes from DB already encoded, decode first and scrub after + |> HtmlEntities.decode() + |> String.replace(~r//, " ") + |> HTML.strip_tags() + |> Formatter.demojify() + |> Formatter.truncate() + end + + def attachment_url(url) do + MediaProxy.url(url) + end + + def user_name_string(user) do + "#{user.name} " <> + if user.local do + "(@#{user.nickname}@#{Pleroma.Web.Endpoint.host()})" + else + "(@#{user.nickname})" + end + end +end -- cgit v1.2.3 From 4956ab5ea30e49147947ba321c1bf93d38d790bd Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 12 Feb 2019 00:25:12 +0000 Subject: Fix compile --- lib/pleroma/web/metadata/twitter_card.ex | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata/twitter_card.ex b/lib/pleroma/web/metadata/twitter_card.ex index 0365e4647..13fa22240 100644 --- a/lib/pleroma/web/metadata/twitter_card.ex +++ b/lib/pleroma/web/metadata/twitter_card.ex @@ -69,8 +69,6 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do Enum.reduce(attachments, [], fn attachment, acc -> rendered_tags = Enum.reduce(attachment["url"], [], fn url, acc -> - content_type = url["mediaType"] - media_type = Enum.find(["image", "audio", "video"], fn media_type -> String.starts_with?(url["mediaType"], media_type) @@ -92,10 +90,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do {:meta, [ property: "twitter:player", - content: - Utils.attachment_url( - Pleroma.Uploaders.Uploader.preview_url(content_type, url["href"]) - ) + content: Utils.attachment_url(url["href"]) ], []} | acc ] -- cgit v1.2.3 From c984e8272a89276a805226be974af5d916a930ee Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 12 Feb 2019 00:37:22 +0000 Subject: Formatting --- lib/pleroma/web/metadata/opengraph.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/metadata/opengraph.ex b/lib/pleroma/web/metadata/opengraph.ex index 4d6639c84..cafb8134b 100644 --- a/lib/pleroma/web/metadata/opengraph.ex +++ b/lib/pleroma/web/metadata/opengraph.ex @@ -99,8 +99,8 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraph do "image" -> [ - {:meta, [property: "og:" <> media_type, content: Utils.attachment_url(url["href"])], - []}, + {:meta, + [property: "og:" <> media_type, content: Utils.attachment_url(url["href"])], []}, {:meta, [property: "og:image:width", content: 150], []}, {:meta, [property: "og:image:height", content: 150], []} | acc -- cgit v1.2.3 From 00e8f0b07dd3dced84b0317e1c5c4156d249dec4 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 1 Feb 2019 13:10:50 +0100 Subject: Plugs.HTTPSecurityPlug: Add unsafe-eval to script-src when in dev mode This is needed to run dev mode mastofe at the same time --- lib/pleroma/plugs/http_security_plug.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/plugs/http_security_plug.ex b/lib/pleroma/plugs/http_security_plug.ex index 3c8e6a18f..05e935f2c 100644 --- a/lib/pleroma/plugs/http_security_plug.ex +++ b/lib/pleroma/plugs/http_security_plug.ex @@ -43,9 +43,11 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do "media-src 'self' https:", "style-src 'self' 'unsafe-inline'", "font-src 'self'", - "script-src 'self'", "connect-src 'self' " <> String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"), "manifest-src 'self'", + if Mix.env() == :dev do + "script-src 'self' 'unsafe-eval'" + end, if scheme == "https" do "upgrade-insecure-requests" end -- cgit v1.2.3 From da4c662af31a2c45c767f2a9ed136272ee9fc2c8 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 2 Feb 2019 19:06:26 +0100 Subject: Plugs.HTTPSecurityPlug: Add webpacker to connect-src --- lib/pleroma/plugs/http_security_plug.ex | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/plugs/http_security_plug.ex b/lib/pleroma/plugs/http_security_plug.ex index 05e935f2c..057553e24 100644 --- a/lib/pleroma/plugs/http_security_plug.ex +++ b/lib/pleroma/plugs/http_security_plug.ex @@ -34,6 +34,21 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do defp csp_string do scheme = Config.get([Pleroma.Web.Endpoint, :url])[:scheme] + websocket_url = String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws") + + connect_src = + if Mix.env() == :dev do + "connect-src 'self' http://localhost:3035/ " <> websocket_url + else + "connect-src 'self' " <> websocket_url + end + + script_src = + if Mix.env() == :dev do + "script-src 'self' 'unsafe-eval'" + else + "script-src 'self'" + end [ "default-src 'none'", @@ -43,11 +58,9 @@ defmodule Pleroma.Plugs.HTTPSecurityPlug do "media-src 'self' https:", "style-src 'self' 'unsafe-inline'", "font-src 'self'", - "connect-src 'self' " <> String.replace(Pleroma.Web.Endpoint.static_url(), "http", "ws"), "manifest-src 'self'", - if Mix.env() == :dev do - "script-src 'self' 'unsafe-eval'" - end, + connect_src, + script_src, if scheme == "https" do "upgrade-insecure-requests" end -- cgit v1.2.3 From 1d727cd0691fdedcd78d5ef22c07a1b280531037 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Tue, 12 Feb 2019 23:25:09 +0100 Subject: added checks for public url and follower collections --- .../web/activity_pub/mrf/hellthread_policy.ex | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 4c6e612b2..9be382972 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -14,6 +14,23 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) end + defp get_recipient_count(message) do + recipients = (message["to"] || []) ++ (message["cc"] || []) + + cond do + Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") && + Enum.find(recipients, &String.ends_with?(&1, "/followers")) -> + length(recipients) - 2 + + Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") || + Enum.find(recipients, &String.ends_with?(&1, "/followers")) -> + length(recipients) - 1 + + true -> + length(recipients) + end + end + @impl true def filter(%{"type" => "Create"} = message) do delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold]) @@ -24,13 +41,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do Pleroma.Config.get([:mrf_hellthread, :threshold]) ) - recipients = (message["to"] || []) ++ (message["cc"] || []) + recipients = get_recipient_count(message) cond do - length(recipients) > reject_threshold and reject_threshold > 0 -> + recipients > reject_threshold and reject_threshold > 0 -> {:reject, nil} - length(recipients) > delist_threshold and delist_threshold > 0 -> + recipients > delist_threshold and delist_threshold > 0 -> if Enum.member?(message["to"], "https://www.w3.org/ns/activitystreams#Public") or Enum.member?(message["cc"], "https://www.w3.org/ns/activitystreams#Public") do {:ok, delist_message(message)} -- cgit v1.2.3 From b7bc666200d6cd113365af7456b4135c86f1db03 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Wed, 13 Feb 2019 15:46:42 +0900 Subject: bugfix mdii uploader --- lib/pleroma/uploaders/mdii.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/uploaders/mdii.ex b/lib/pleroma/uploaders/mdii.ex index 320b07abd..190ed9f3a 100644 --- a/lib/pleroma/uploaders/mdii.ex +++ b/lib/pleroma/uploaders/mdii.ex @@ -25,7 +25,7 @@ defmodule Pleroma.Uploaders.MDII do query = "#{cgi}?#{extension}" with {:ok, %{status: 200, body: body}} <- - @httpoison.post(query, file_data, adapter: [pool: :default]) do + @httpoison.post(query, file_data, [], adapter: [pool: :default]) do remote_file_name = String.split(body) |> List.first() public_url = "#{files}/#{remote_file_name}.#{extension}" {:ok, {:url, public_url}} -- cgit v1.2.3 From 61a4bc50952b11a59dce7f655c883de59306adcd Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Sun, 10 Feb 2019 22:41:06 +0300 Subject: Add OAuth tokens endpoint --- lib/pleroma/web/oauth/token.ex | 8 ++++++++ lib/pleroma/web/router.ex | 2 ++ .../web/twitter_api/twitter_api_controller.ex | 12 ++++++++++++ lib/pleroma/web/twitter_api/views/token_view.ex | 22 ++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 lib/pleroma/web/twitter_api/views/token_view.ex (limited to 'lib') diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index b0bbeeb69..40bf0ac6b 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -52,4 +52,12 @@ defmodule Pleroma.Web.OAuth.Token do ) |> Repo.delete_all() end + + def get_user_tokens(%User{id: user_id}) do + from( + t in Pleroma.Web.OAuth.Token, + where: t.user_id == ^user_id + ) + |> Repo.all() + end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 5b5627ce8..a394900b2 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -389,6 +389,8 @@ defmodule Pleroma.Web.Router do get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array) get("/externalprofile/show", TwitterAPI.Controller, :external_profile) + + get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens) end pipeline :ap_relay do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index c2f0dc2a9..1a43e9a60 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -8,6 +8,10 @@ defmodule Pleroma.Web.TwitterAPI.Controller do import Pleroma.Web.ControllerHelper, only: [json_response: 3] alias Ecto.Changeset + alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView, TokenView} + alias Pleroma.Web.CommonAPI + alias Pleroma.{Repo, Activity, Object, User, Notification} + alias Pleroma.Web.OAuth.Token alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.CommonAPI @@ -542,6 +546,14 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def oauth_tokens(%{assigns: %{user: user}} = conn, _params) do + with oauth_tokens <- Token.get_user_tokens(user) do + conn + |> put_view(TokenView) + |> render("index.json", %{tokens: oauth_tokens}) + end + end + def blocks(%{assigns: %{user: user}} = conn, _params) do with blocked_users <- User.blocked_users(user) do conn diff --git a/lib/pleroma/web/twitter_api/views/token_view.ex b/lib/pleroma/web/twitter_api/views/token_view.ex new file mode 100644 index 000000000..96b8526a4 --- /dev/null +++ b/lib/pleroma/web/twitter_api/views/token_view.ex @@ -0,0 +1,22 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.TwitterAPI.TokenView do + use Pleroma.Web, :view + + def render("index.json", %{tokens: tokens}) do + tokens + |> render_many(Pleroma.Web.TwitterAPI.TokenView, "show.json") + |> Enum.filter(&Enum.any?/1) + end + + def render("show.json", %{token: token_entry}) do + %{ + id: token_entry.id, + token: token_entry.token, + refresh_token: token_entry.refresh_token, + valid_until: token_entry.valid_until + } + end +end -- cgit v1.2.3 From 62a45bdc11bc98ca4c24b0b8aa54c9d2958f81a1 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Mon, 11 Feb 2019 00:49:56 +0300 Subject: Add revoke token --- lib/pleroma/web/oauth/token.ex | 11 ++++++++++- lib/pleroma/web/router.ex | 1 + lib/pleroma/web/twitter_api/twitter_api_controller.ex | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index 40bf0ac6b..380a39360 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -53,9 +53,18 @@ defmodule Pleroma.Web.OAuth.Token do |> Repo.delete_all() end - def get_user_tokens(%User{id: user_id}) do + def delete_user_token(%User{id: user_id}, token_id) do from( t in Pleroma.Web.OAuth.Token, + where: t.user_id == ^user_id, + where: t.id == ^token_id + ) + |> Repo.delete_all() + end + + def get_user_tokens(%User{id: user_id}) do + from( + t in Token, where: t.user_id == ^user_id ) |> Repo.all() diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index a394900b2..d45fa526e 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -391,6 +391,7 @@ defmodule Pleroma.Web.Router do get("/externalprofile/show", TwitterAPI.Controller, :external_profile) get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens) + delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token) end pipeline :ap_relay do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 1a43e9a60..fac05f288 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -554,6 +554,12 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def revoke_token(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do + Token.delete_user_token(user, id) + + json_reply(conn, 201, "") + end + def blocks(%{assigns: %{user: user}} = conn, _params) do with blocked_users <- User.blocked_users(user) do conn -- cgit v1.2.3 From 760fec4cb85c7ddf2ec4fa5578ab4a1ceafc1e84 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Mon, 11 Feb 2019 09:48:24 +0000 Subject: Update token.ex --- lib/pleroma/web/oauth/token.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index 380a39360..f5594f834 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -47,7 +47,7 @@ defmodule Pleroma.Web.OAuth.Token do def delete_user_tokens(%User{id: user_id}) do from( - t in Pleroma.Web.OAuth.Token, + t in Token, where: t.user_id == ^user_id ) |> Repo.delete_all() @@ -55,7 +55,7 @@ defmodule Pleroma.Web.OAuth.Token do def delete_user_token(%User{id: user_id}, token_id) do from( - t in Pleroma.Web.OAuth.Token, + t in Token, where: t.user_id == ^user_id, where: t.id == ^token_id ) -- cgit v1.2.3 From 88a4de24f9bc6fc73696cb5c986440c2c659b636 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 13 Feb 2019 13:52:27 +0100 Subject: User.follow_all: Respect blocks in both directions. --- lib/pleroma/user.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 0060d966b..3232cb842 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -311,12 +311,12 @@ defmodule Pleroma.User do end end - @doc "A mass follow for local users. Respects blocks but does not create activities." + @doc "A mass follow for local users. Respects blocks in both directions but does not create activities." @spec follow_all(User.t(), list(User.t())) :: {atom(), User.t()} def follow_all(follower, followeds) do followed_addresses = followeds - |> Enum.reject(fn %{ap_id: ap_id} -> ap_id in follower.info.blocks end) + |> Enum.reject(fn followed -> blocks?(follower, followed) || blocks?(followed, follower) end) |> Enum.map(fn %{follower_address: fa} -> fa end) q = -- cgit v1.2.3 From bef9b9cb669d6c1081eb83c624af89dbf9a8b9da Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Wed, 13 Feb 2019 16:23:09 +0100 Subject: refactored code --- .../web/activity_pub/mrf/hellthread_policy.ex | 82 ++++++++++++---------- 1 file changed, 46 insertions(+), 36 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 9be382972..1f09b4e66 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -7,56 +7,66 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do @behaviour Pleroma.Web.ActivityPub.MRF defp delist_message(message) do + delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold]) follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address - message - |> Map.put("to", [follower_collection]) - |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) - end - - defp get_recipient_count(message) do - recipients = (message["to"] || []) ++ (message["cc"] || []) - - cond do - Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") && - Enum.find(recipients, &String.ends_with?(&1, "/followers")) -> - length(recipients) - 2 - - Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") || - Enum.find(recipients, &String.ends_with?(&1, "/followers")) -> - length(recipients) - 1 + message = + with {:public, recipients} <- get_recipient_count(message) do + if recipients > delist_threshold and delist_threshold > 0 do + message + |> Map.put("to", [follower_collection]) + |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) + else + message + end + else + _ -> message + end - true -> - length(recipients) - end + {:ok, message} end - @impl true - def filter(%{"type" => "Create"} = message) do - delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold]) - + defp reject_message(message) do reject_threshold = Pleroma.Config.get( [:mrf_hellthread, :reject_threshold], Pleroma.Config.get([:mrf_hellthread, :threshold]) ) - recipients = get_recipient_count(message) - - cond do - recipients > reject_threshold and reject_threshold > 0 -> + with {_, recipients} <- get_recipient_count(message) do + if recipients > reject_threshold and reject_threshold > 0 do {:reject, nil} + else + {:ok, message} + end + end + end - recipients > delist_threshold and delist_threshold > 0 -> - if Enum.member?(message["to"], "https://www.w3.org/ns/activitystreams#Public") or - Enum.member?(message["cc"], "https://www.w3.org/ns/activitystreams#Public") do - {:ok, delist_message(message)} - else - {:ok, message} - end + defp get_recipient_count(message) do + recipients = (message["to"] || []) ++ (message["cc"] || []) + follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address - true -> - {:ok, message} + if Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") do + recipients + |> List.delete("https://www.w3.org/ns/activitystreams#Public") + |> List.delete(follower_collection) + + {:public, length(recipients)} + else + recipients + |> List.delete(follower_collection) + + {:not_public, length(recipients)} + end + end + + @impl true + def filter(%{"type" => "Create"} = message) do + with {:ok, message} <- reject_message(message), + {:ok, message} <- delist_message(message) do + {:ok, message} + else + _e -> {:reject, nil} end end -- cgit v1.2.3 From 90facd359813197060f6c33f2389fce772550fc3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 12 Feb 2019 21:28:11 +0000 Subject: user view: add AP C2S oauth endpoints to local user profiles --- lib/pleroma/web/activity_pub/views/user_view.ex | 26 +++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 15e6c1f68..0d880212e 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -15,6 +15,20 @@ defmodule Pleroma.Web.ActivityPub.UserView do import Ecto.Query + def render("endpoints.json", %{user: %{local: true} = _user}) do + %{ + "oauthAuthorizationEndpoint" => "#{Pleroma.Web.Endpoint.url()}/oauth/authorize", + "oauthTokenEndpoint" => "#{Pleroma.Web.Endpoint.url()}/oauth/token" + } + |> Map.merge(render("endpoints.json", nil)) + end + + def render("endpoints.json", _) do + %{ + "sharedInbox" => "#{Pleroma.Web.Endpoint.url()}/inbox" + } + end + # the instance itself is not a Person, but instead an Application def render("user.json", %{user: %{nickname: nil} = user}) do {:ok, user} = WebFinger.ensure_keys_present(user) @@ -22,6 +36,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key) public_key = :public_key.pem_encode([public_key]) + endpoints = render("endpoints.json", %{user: user}) + %{ "id" => user.ap_id, "type" => "Application", @@ -37,9 +53,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "owner" => user.ap_id, "publicKeyPem" => public_key }, - "endpoints" => %{ - "sharedInbox" => "#{Pleroma.Web.Endpoint.url()}/inbox" - } + "endpoints" => endpoints } |> Map.merge(Utils.make_json_ld_header()) end @@ -50,6 +64,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key) public_key = :public_key.pem_encode([public_key]) + endpoints = render("endpoints.json", %{user: user}) + %{ "id" => user.ap_id, "type" => "Person", @@ -67,9 +83,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do "owner" => user.ap_id, "publicKeyPem" => public_key }, - "endpoints" => %{ - "sharedInbox" => "#{Pleroma.Web.Endpoint.url()}/inbox" - }, + "endpoints" => endpoints, "icon" => %{ "type" => "Image", "url" => User.avatar_url(user) -- cgit v1.2.3 From db8abd958dc2266262def048352466280c12d3a7 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 12 Feb 2019 21:42:32 +0000 Subject: activitypub: user view: fix up endpoints rendering --- lib/pleroma/web/activity_pub/views/user_view.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 0d880212e..44beee728 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -15,12 +15,12 @@ defmodule Pleroma.Web.ActivityPub.UserView do import Ecto.Query - def render("endpoints.json", %{user: %{local: true} = _user}) do + def render("endpoints.json", %{user: %User{local: true} = _user}) do %{ "oauthAuthorizationEndpoint" => "#{Pleroma.Web.Endpoint.url()}/oauth/authorize", "oauthTokenEndpoint" => "#{Pleroma.Web.Endpoint.url()}/oauth/token" } - |> Map.merge(render("endpoints.json", nil)) + |> Map.merge(render("endpoints.json", %{user: nil})) end def render("endpoints.json", _) do -- cgit v1.2.3 From 29e946ace43f5dd3342e2bd3699004e9c56e711d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 12 Feb 2019 21:49:48 +0000 Subject: activitypub: user view: add oauthRegistrationEndpoint to user profiles --- lib/pleroma/web/activity_pub/views/user_view.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 44beee728..af75546dd 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -18,6 +18,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do def render("endpoints.json", %{user: %User{local: true} = _user}) do %{ "oauthAuthorizationEndpoint" => "#{Pleroma.Web.Endpoint.url()}/oauth/authorize", + "oauthRegistrationEndpoint" => "#{Pleroma.Web.Endpoint.url()}/api/v1/apps", "oauthTokenEndpoint" => "#{Pleroma.Web.Endpoint.url()}/oauth/token" } |> Map.merge(render("endpoints.json", %{user: nil})) -- cgit v1.2.3 From 9bd6ed975ec57f46ff6796fadb8822faec262bbc Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 13 Feb 2019 19:20:41 +0000 Subject: activitypub: user view: use route helpers instead of hardcoded URIs --- lib/pleroma/web/activity_pub/views/user_view.ex | 18 ++++++++---------- lib/pleroma/web/router.ex | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index af75546dd..035463de2 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -12,23 +12,21 @@ defmodule Pleroma.Web.ActivityPub.UserView do alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.Router.Helpers + alias Pleroma.Web.Endpoint import Ecto.Query - def render("endpoints.json", %{user: %User{local: true} = _user}) do + def render("endpoints.json", %{user: %User{nickname: _nickname, local: true} = _user}) do %{ - "oauthAuthorizationEndpoint" => "#{Pleroma.Web.Endpoint.url()}/oauth/authorize", - "oauthRegistrationEndpoint" => "#{Pleroma.Web.Endpoint.url()}/api/v1/apps", - "oauthTokenEndpoint" => "#{Pleroma.Web.Endpoint.url()}/oauth/token" + "oauthAuthorizationEndpoint" => Helpers.o_auth_url(Endpoint, :authorize), + "oauthRegistrationEndpoint" => Helpers.mastodon_api_url(Endpoint, :create_app), + "oauthTokenEndpoint" => Helpers.o_auth_url(Endpoint, :token_exchange), + "sharedInbox" => Helpers.activity_pub_url(Endpoint, :inbox) } - |> Map.merge(render("endpoints.json", %{user: nil})) end - def render("endpoints.json", _) do - %{ - "sharedInbox" => "#{Pleroma.Web.Endpoint.url()}/inbox" - } - end + def render("endpoints.json", _), do: %{} # the instance itself is not a Person, but instead an Application def render("user.json", %{user: %{nickname: nil} = user}) do diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 5b5627ce8..d66a1c2a1 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -468,8 +468,8 @@ defmodule Pleroma.Web.Router do scope "/", Pleroma.Web.ActivityPub do pipe_through(:activitypub) - post("/users/:nickname/inbox", ActivityPubController, :inbox) post("/inbox", ActivityPubController, :inbox) + post("/users/:nickname/inbox", ActivityPubController, :inbox) end scope "/.well-known", Pleroma.Web do -- cgit v1.2.3 From 063baca5e4f3a100c0d45dffb14e4968599ef43b Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 14 Feb 2019 00:29:29 +0300 Subject: [#468] User UI for OAuth permissions restriction. Standardized storage format for `scopes` fields, updated usages. --- lib/pleroma/plugs/oauth_scopes_plug.ex | 3 +-- .../web/mastodon_api/mastodon_api_controller.ex | 12 ++++++++++-- lib/pleroma/web/oauth.ex | 19 ++++++++++++++++--- lib/pleroma/web/oauth/app.ex | 2 +- lib/pleroma/web/oauth/authorization.ex | 9 ++++----- lib/pleroma/web/oauth/oauth_controller.ex | 18 +++++++++++++----- lib/pleroma/web/oauth/token.ex | 11 +++++------ lib/pleroma/web/templates/layout/app.html.eex | 4 ++++ lib/pleroma/web/templates/o_auth/o_auth/show.html.eex | 12 ++++++++++-- 9 files changed, 64 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/plugs/oauth_scopes_plug.ex b/lib/pleroma/plugs/oauth_scopes_plug.ex index a16adb004..a81e29830 100644 --- a/lib/pleroma/plugs/oauth_scopes_plug.ex +++ b/lib/pleroma/plugs/oauth_scopes_plug.ex @@ -4,7 +4,6 @@ defmodule Pleroma.Plugs.OAuthScopesPlug do import Plug.Conn - alias Pleroma.Web.OAuth @behaviour Plug @@ -12,7 +11,7 @@ defmodule Pleroma.Plugs.OAuthScopesPlug do def call(%Plug.Conn{assigns: assigns} = conn, %{required_scopes: required_scopes}) do token = assigns[:token] - granted_scopes = token && OAuth.parse_scopes(token.scope) + granted_scopes = token && token.scopes if is_nil(token) || required_scopes -- granted_scopes == [] do conn diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index dbe7c2554..59f472e91 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -19,6 +19,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.CommonAPI + alias Pleroma.Web.OAuth alias Pleroma.Web.OAuth.{Authorization, Token, App} alias Pleroma.Web.MediaProxy @@ -31,7 +32,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do action_fallback(:errors) def create_app(conn, params) do - with cs <- App.register_changeset(%App{}, params), + scopes = OAuth.parse_scopes(params["scope"] || params["scopes"]) + app_attrs = params |> Map.drop(["scope", "scopes"]) |> Map.put("scopes", scopes) + + with cs <- App.register_changeset(%App{}, app_attrs), false <- cs.changes[:client_name] == @local_mastodon_name, {:ok, app} <- Repo.insert(cs) do res = %{ @@ -1162,7 +1166,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do {:ok, app} else _e -> - cs = App.register_changeset(%App{}, Map.put(find_attrs, :scopes, "read,write,follow")) + cs = + App.register_changeset( + %App{}, + Map.put(find_attrs, :scopes, ["read", "write", "follow"]) + ) Repo.insert(cs) end diff --git a/lib/pleroma/web/oauth.ex b/lib/pleroma/web/oauth.ex index 44b83433e..761b80fde 100644 --- a/lib/pleroma/web/oauth.ex +++ b/lib/pleroma/web/oauth.ex @@ -3,9 +3,22 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth do - def parse_scopes(scopes) do + def parse_scopes(nil) do + nil + end + + def parse_scopes(scopes) when is_list(scopes) do scopes - |> to_string() - |> String.split([" ", ","]) + end + + def parse_scopes(scopes) do + scopes = + scopes + |> to_string() + |> String.trim() + + if scopes == "", + do: [], + else: String.split(scopes, [" ", ","]) end end diff --git a/lib/pleroma/web/oauth/app.ex b/lib/pleroma/web/oauth/app.ex index 967ac04b5..c04626a73 100644 --- a/lib/pleroma/web/oauth/app.ex +++ b/lib/pleroma/web/oauth/app.ex @@ -9,7 +9,7 @@ defmodule Pleroma.Web.OAuth.App do schema "apps" do field(:client_name, :string) field(:redirect_uris, :string) - field(:scopes, :string) + field(:scopes, {:array, :string}, default: []) field(:website, :string) field(:client_id, :string) field(:client_secret, :string) diff --git a/lib/pleroma/web/oauth/authorization.ex b/lib/pleroma/web/oauth/authorization.ex index 0fbaa902b..c5b7ec9a5 100644 --- a/lib/pleroma/web/oauth/authorization.ex +++ b/lib/pleroma/web/oauth/authorization.ex @@ -6,14 +6,13 @@ defmodule Pleroma.Web.OAuth.Authorization do use Ecto.Schema alias Pleroma.{User, Repo} - alias Pleroma.Web.OAuth alias Pleroma.Web.OAuth.{Authorization, App} import Ecto.{Changeset, Query} schema "oauth_authorizations" do field(:token, :string) - field(:scope, :string) + field(:scopes, {:array, :string}, default: []) field(:valid_until, :naive_datetime) field(:used, :boolean, default: false) belongs_to(:user, Pleroma.User, type: Pleroma.FlakeId) @@ -22,8 +21,8 @@ defmodule Pleroma.Web.OAuth.Authorization do timestamps() end - def create_authorization(%App{} = app, %User{} = user, scope \\ nil) do - scopes = OAuth.parse_scopes(scope || app.scopes) + def create_authorization(%App{} = app, %User{} = user, scopes \\ nil) do + scopes = scopes || app.scopes token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() authorization = %Authorization{ @@ -31,7 +30,7 @@ defmodule Pleroma.Web.OAuth.Authorization do used: false, user_id: user.id, app_id: app.id, - scope: Enum.join(scopes, " "), + scopes: scopes, valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10) } diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 15345d4ba..f00d5293d 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -5,6 +5,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do use Pleroma.Web, :controller + alias Pleroma.Web.OAuth alias Pleroma.Web.OAuth.{Authorization, Token, App} alias Pleroma.{Repo, User} alias Comeonin.Pbkdf2 @@ -18,7 +19,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do render(conn, "show.html", %{ response_type: params["response_type"], client_id: params["client_id"], - scope: params["scope"], + scopes: scopes(params) || [], redirect_uri: params["redirect_uri"], state: params["state"] }) @@ -38,7 +39,10 @@ defmodule Pleroma.Web.OAuth.OAuthController do {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, %App{} = app <- Repo.get_by(App, client_id: client_id), true <- redirect_uri in String.split(app.redirect_uris), - {:ok, auth} <- Authorization.create_authorization(app, user, params["scope"]) do + scopes <- scopes(params) || app.scopes, + [] <- scopes -- app.scopes, + true <- Enum.any?(scopes), + {:ok, auth} <- Authorization.create_authorization(app, user, scopes) do # Special case: Local MastodonFE. redirect_uri = if redirect_uri == "." do @@ -94,7 +98,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do refresh_token: token.refresh_token, created_at: DateTime.to_unix(inserted_at), expires_in: 60 * 10, - scope: token.scope + scope: Enum.join(token.scopes) } json(conn, response) @@ -113,14 +117,15 @@ defmodule Pleroma.Web.OAuth.OAuthController do %User{} = user <- User.get_by_nickname_or_email(name), true <- Pbkdf2.checkpw(password, user.password_hash), {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, - {:ok, auth} <- Authorization.create_authorization(app, user, params["scope"]), + scopes <- scopes(params) || app.scopes, + {:ok, auth} <- Authorization.create_authorization(app, user, scopes), {:ok, token} <- Token.exchange_token(app, auth) do response = %{ token_type: "Bearer", access_token: token.token, refresh_token: token.refresh_token, expires_in: 60 * 10, - scope: token.scope + scope: Enum.join(token.scopes, " ") } json(conn, response) @@ -192,4 +197,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do nil end end + + defp scopes(params), + do: OAuth.parse_scopes(params["scopes"] || params["scope"]) end diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index 61f43ed5a..1fae5ed3a 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -8,13 +8,12 @@ defmodule Pleroma.Web.OAuth.Token do import Ecto.Query alias Pleroma.{User, Repo} - alias Pleroma.Web.OAuth alias Pleroma.Web.OAuth.{Token, App, Authorization} schema "oauth_tokens" do field(:token, :string) field(:refresh_token, :string) - field(:scope, :string) + field(:scopes, {:array, :string}, default: []) field(:valid_until, :naive_datetime) belongs_to(:user, Pleroma.User, type: Pleroma.FlakeId) belongs_to(:app, App) @@ -25,19 +24,19 @@ defmodule Pleroma.Web.OAuth.Token do def exchange_token(app, auth) do with {:ok, auth} <- Authorization.use_token(auth), true <- auth.app_id == app.id do - create_token(app, Repo.get(User, auth.user_id), auth.scope) + create_token(app, Repo.get(User, auth.user_id), auth.scopes) end end - def create_token(%App{} = app, %User{} = user, scope \\ nil) do - scopes = OAuth.parse_scopes(scope || app.scopes) + def create_token(%App{} = app, %User{} = user, scopes \\ nil) do + scopes = scopes || app.scopes token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() refresh_token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() token = %Token{ token: token, refresh_token: refresh_token, - scope: Enum.join(scopes, " "), + scopes: scopes, user_id: user.id, app_id: app.id, valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10) diff --git a/lib/pleroma/web/templates/layout/app.html.eex b/lib/pleroma/web/templates/layout/app.html.eex index 8dd3284d6..f944cbc26 100644 --- a/lib/pleroma/web/templates/layout/app.html.eex +++ b/lib/pleroma/web/templates/layout/app.html.eex @@ -54,6 +54,10 @@ border-bottom: 2px solid #4b8ed8; } + input[type="checkbox"] { + width: auto; + } + button { box-sizing: border-box; width: 100%; diff --git a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex index e1c0af975..1ecb5b444 100644 --- a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex +++ b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex @@ -5,12 +5,20 @@ <%= label f, :name, "Name or email" %> <%= text_input f, :name %>
+
<%= label f, :password, "Password" %> <%= password_input f, :password %>
-<%= label f, :scope, "Scopes" %> -<%= text_input f, :scope, value: @scope %>
+ +<%= label f, :scope, "Permissions" %> +
+<%= for scope <- @scopes do %> + <%= checkbox f, :"scopes_#{scope}", hidden_input: false, value: scope, checked_value: scope, name: "authorization[scopes][]" %> + <%= label f, :"scopes_#{scope}", String.capitalize(scope) %> +
+<% end %> + <%= hidden_input f, :client_id, value: @client_id %> <%= hidden_input f, :response_type, value: @response_type %> <%= hidden_input f, :redirect_uri, value: @redirect_uri %> -- cgit v1.2.3 From f62c1d6266be1af59aa5e0fe05e438c54c330e74 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 13 Feb 2019 22:33:22 +0000 Subject: Improve login error for OAuth flow --- lib/pleroma/web/templates/layout/app.html.eex | 26 ++++++++++++++++++++++ .../web/templates/o_auth/o_auth/show.html.eex | 4 ++++ 2 files changed, 30 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/templates/layout/app.html.eex b/lib/pleroma/web/templates/layout/app.html.eex index 8dd3284d6..520e4b3d5 100644 --- a/lib/pleroma/web/templates/layout/app.html.eex +++ b/lib/pleroma/web/templates/layout/app.html.eex @@ -67,6 +67,32 @@ font-weight: 500; font-size: 16px; } + + .alert-danger { + box-sizing: border-box; + width: 100%; + color: #D8000C; + background-color: #FFD2D2; + border-radius: 4px; + border: none; + padding: 10px; + margin-top: 20px; + font-weight: 500; + font-size: 16px; + } + + .alert-info { + box-sizing: border-box; + width: 100%; + color: #00529B; + background-color: #BDE5F8; + border-radius: 4px; + border: none; + padding: 10px; + margin-top: 20px; + font-weight: 500; + font-size: 16px; + } diff --git a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex index de2241ec9..32c458f0c 100644 --- a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex +++ b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex @@ -1,5 +1,9 @@ +<%= if get_flash(@conn, :info) do %> +<% end %> +<%= if get_flash(@conn, :error) do %> +<% end %>

OAuth Authorization

<%= form_for @conn, o_auth_path(@conn, :authorize), [as: "authorization"], fn f -> %> <%= label f, :name, "Name or email" %> -- cgit v1.2.3 From 94cbbb0e3a047c1d2851e2214b408dc19f569fbd Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 00:27:35 +0000 Subject: activitypub: transmogrifier: do not attempt to expand pre-existing AS2 tag objects --- lib/pleroma/web/activity_pub/transmogrifier.ex | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 98a2af819..5da65fa39 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -765,12 +765,18 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do def add_hashtags(object) do tags = (object["tag"] || []) - |> Enum.map(fn tag -> - %{ - "href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}", - "name" => "##{tag}", - "type" => "Hashtag" - } + |> Enum.map(fn + # Expand internal representation tags into AS2 tags. + tag when is_binary(tag) -> + %{ + "href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}", + "name" => "##{tag}", + "type" => "Hashtag" + } + + # Do not process tags which are already AS2 tag objects. + tag when is_map(tag) -> + tag end) object -- cgit v1.2.3 From e05bf2940f764e8182edcf58659eeee1db751118 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 00:34:20 +0000 Subject: activitypub: transmogrifier: correctly handle nil inReplyTo value --- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 5da65fa39..26b2dd575 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -649,7 +649,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do if object = Object.normalize(id), do: {:ok, object}, else: nil end - def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) do + def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) when is_binary(inReplyTo) do with false <- String.starts_with?(inReplyTo, "http"), {:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo) -- cgit v1.2.3 From e9ef4b8da627e516d5f1a2b742c6dafa65232098 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 01:05:25 +0000 Subject: oauth: never use base64 padding when returning tokens to applications The normal Base64 alphabet uses the equals sign (=) as a padding character. Since Base64 strings are self-synchronizing, padding characters are unnecessary, so don't generate them in the first place. --- lib/pleroma/web/oauth/app.ex | 10 ++++++++-- lib/pleroma/web/oauth/authorization.ex | 2 +- lib/pleroma/web/oauth/oauth_controller.ex | 2 +- lib/pleroma/web/oauth/token.ex | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/oauth/app.ex b/lib/pleroma/web/oauth/app.ex index 3e8acde31..8b61bf3a4 100644 --- a/lib/pleroma/web/oauth/app.ex +++ b/lib/pleroma/web/oauth/app.ex @@ -25,8 +25,14 @@ defmodule Pleroma.Web.OAuth.App do if changeset.valid? do changeset - |> put_change(:client_id, :crypto.strong_rand_bytes(32) |> Base.url_encode64()) - |> put_change(:client_secret, :crypto.strong_rand_bytes(32) |> Base.url_encode64()) + |> put_change( + :client_id, + :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false) + ) + |> put_change( + :client_secret, + :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false) + ) else changeset end diff --git a/lib/pleroma/web/oauth/authorization.ex b/lib/pleroma/web/oauth/authorization.ex index 75c9ab9aa..9039b8b45 100644 --- a/lib/pleroma/web/oauth/authorization.ex +++ b/lib/pleroma/web/oauth/authorization.ex @@ -24,7 +24,7 @@ defmodule Pleroma.Web.OAuth.Authorization do end def create_authorization(%App{} = app, %User{} = user) do - token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() + token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false) authorization = %Authorization{ token: token, diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index e4d0601f8..dddfcf299 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -173,7 +173,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do token |> URI.decode() |> Base.url_decode64!(padding: false) - |> Base.url_encode64() + |> Base.url_encode64(padding: false) end defp get_app_from_request(conn, params) do diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index b0bbeeb69..ca9e718ac 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -31,8 +31,8 @@ defmodule Pleroma.Web.OAuth.Token do end def create_token(%App{} = app, %User{} = user) do - token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() - refresh_token = :crypto.strong_rand_bytes(32) |> Base.url_encode64() + token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false) + refresh_token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false) token = %Token{ token: token, -- cgit v1.2.3 From 64620d8980e3e93791d3f880296be2060ffc4d39 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 02:41:21 +0000 Subject: activitypub: user view: do not expose oAuth endpoints for instance users --- lib/pleroma/web/activity_pub/views/user_view.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 035463de2..b363a3dc4 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -17,7 +17,11 @@ defmodule Pleroma.Web.ActivityPub.UserView do import Ecto.Query - def render("endpoints.json", %{user: %User{nickname: _nickname, local: true} = _user}) do + def render("endpoints.json", %{user: %User{nickname: nil, local: true} = _user}) do + %{"sharedInbox" => Helpers.activity_pub_url(Endpoint, :inbox)} + end + + def render("endpoints.json", %{user: %User{local: true} = _user}) do %{ "oauthAuthorizationEndpoint" => Helpers.o_auth_url(Endpoint, :authorize), "oauthRegistrationEndpoint" => Helpers.mastodon_api_url(Endpoint, :create_app), -- cgit v1.2.3 From ee2fa1a31475259575a267e67cf5d7da04a30616 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 03:01:39 +0000 Subject: activitypub: user view: remove totalInbox from user inbox view It is not really feasible to quickly calculate the totalItems value and it shouldn't be trusted anyway. --- lib/pleroma/web/activity_pub/views/user_view.ex | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index b363a3dc4..1e16f7ebb 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -224,7 +224,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{iri}?max_id=#{max_id}", "type" => "OrderedCollectionPage", "partOf" => iri, - "totalItems" => -1, "orderedItems" => collection, "next" => "#{iri}?max_id=#{min_id}" } @@ -233,7 +232,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do %{ "id" => iri, "type" => "OrderedCollection", - "totalItems" => -1, "first" => page } |> Map.merge(Utils.make_json_ld_header()) -- cgit v1.2.3 From 6542b8629203cd3b3ef4f0a08a5ad67451366a72 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 03:02:45 +0000 Subject: activitypub: user view: remove totalItems from user outbox (this is based on a counter in User.Info, but the counter is not reliable.) --- lib/pleroma/web/activity_pub/views/user_view.ex | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 1e16f7ebb..506fa5ea3 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -177,7 +177,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{iri}?max_id=#{max_id}", "type" => "OrderedCollectionPage", "partOf" => iri, - "totalItems" => info.note_count, "orderedItems" => collection, "next" => "#{iri}?max_id=#{min_id}" } @@ -186,7 +185,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do %{ "id" => iri, "type" => "OrderedCollection", - "totalItems" => info.note_count, "first" => page } |> Map.merge(Utils.make_json_ld_header()) -- cgit v1.2.3 From 5307c211b8ca00def779221ecbde2cc4bea6d2d5 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 03:03:41 +0000 Subject: activitypub: user view: report totalItems=0 for follows/followers when hidden --- lib/pleroma/web/activity_pub/views/user_view.ex | 37 +++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 506fa5ea3..dd1ab3d2b 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -104,8 +104,14 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = User.get_friends_query(user) query = from(user in query, select: [:ap_id]) following = Repo.all(query) + total = + if !user.info.hide_follows do + length(following) + else + 0 + end - collection(following, "#{user.ap_id}/following", page, !user.info.hide_follows) + collection(following, "#{user.ap_id}/following", page, !user.info.hide_follows, total) |> Map.merge(Utils.make_json_ld_header()) end @@ -113,11 +119,17 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = User.get_friends_query(user) query = from(user in query, select: [:ap_id]) following = Repo.all(query) + total = + if !user.info.hide_follows do + length(following) + else + 0 + end %{ "id" => "#{user.ap_id}/following", "type" => "OrderedCollection", - "totalItems" => length(following), + "totalItems" => total, "first" => collection(following, "#{user.ap_id}/following", 1, !user.info.hide_follows) } |> Map.merge(Utils.make_json_ld_header()) @@ -127,8 +139,14 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = User.get_followers_query(user) query = from(user in query, select: [:ap_id]) followers = Repo.all(query) + total = + if !user.info.hide_followers do + length(followers) + else + 0 + end - collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers) + collection(followers, "#{user.ap_id}/followers", page, !user.info.hide_followers, total) |> Map.merge(Utils.make_json_ld_header()) end @@ -136,20 +154,23 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = User.get_followers_query(user) query = from(user in query, select: [:ap_id]) followers = Repo.all(query) + total = + if !user.info.hide_followers do + length(followers) + else + 0 + end %{ "id" => "#{user.ap_id}/followers", "type" => "OrderedCollection", - "totalItems" => length(followers), - "first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers) + "totalItems" => total, + "first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers, total) } |> Map.merge(Utils.make_json_ld_header()) end def render("outbox.json", %{user: user, max_id: max_qid}) do - # XXX: technically note_count is wrong for this, but it's better than nothing - info = User.user_info(user) - params = %{ "limit" => "10" } -- cgit v1.2.3 From 72ba5b4ab73ff725b91888e38af612082f8df5ad Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 03:13:07 +0000 Subject: activitypub: user view: formatting --- lib/pleroma/web/activity_pub/views/user_view.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index dd1ab3d2b..c8e154989 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -104,6 +104,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = User.get_friends_query(user) query = from(user in query, select: [:ap_id]) following = Repo.all(query) + total = if !user.info.hide_follows do length(following) @@ -119,6 +120,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = User.get_friends_query(user) query = from(user in query, select: [:ap_id]) following = Repo.all(query) + total = if !user.info.hide_follows do length(following) @@ -139,6 +141,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = User.get_followers_query(user) query = from(user in query, select: [:ap_id]) followers = Repo.all(query) + total = if !user.info.hide_followers do length(followers) @@ -154,6 +157,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do query = User.get_followers_query(user) query = from(user in query, select: [:ap_id]) followers = Repo.all(query) + total = if !user.info.hide_followers do length(followers) @@ -165,7 +169,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do "id" => "#{user.ap_id}/followers", "type" => "OrderedCollection", "totalItems" => total, - "first" => collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers, total) + "first" => + collection(followers, "#{user.ap_id}/followers", 1, !user.info.hide_followers, total) } |> Map.merge(Utils.make_json_ld_header()) end -- cgit v1.2.3 From 907306174b082cccd823894c855194a4fc1e8305 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 14 Feb 2019 15:55:21 +0700 Subject: fix S3 links encoding in Mediaproxy --- lib/pleroma/web/media_proxy/media_proxy.ex | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/media_proxy/media_proxy.ex b/lib/pleroma/web/media_proxy/media_proxy.ex index 1e9da7283..39a725a69 100644 --- a/lib/pleroma/web/media_proxy/media_proxy.ex +++ b/lib/pleroma/web/media_proxy/media_proxy.ex @@ -19,11 +19,16 @@ defmodule Pleroma.Web.MediaProxy do else secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base] + # Must preserve `%2F` for compatibility with S3 (https://git.pleroma.social/pleroma/pleroma/issues/580) + replacement = get_replacement(url, ":2F:") + # The URL is url-decoded and encoded again to ensure it is correctly encoded and not twice. base64 = url + |> String.replace("%2F", replacement) |> URI.decode() |> URI.encode() + |> String.replace(replacement, "%2F") |> Base.url_encode64(@base64_opts) sig = :crypto.hmac(:sha, secret, base64) @@ -60,4 +65,12 @@ defmodule Pleroma.Web.MediaProxy do |> Enum.filter(fn value -> value end) |> Path.join() end + + defp get_replacement(url, replacement) do + if String.contains?(url, replacement) do + get_replacement(url, replacement <> replacement) + else + replacement + end + end end -- cgit v1.2.3 From 3f32d7b937a2368707794b55d1256bfa9fa508f4 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 14 Feb 2019 17:02:47 +0700 Subject: Fix queue name --- lib/pleroma/web/federator/federator.ex | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index 7df75aca6..d4e2a9742 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -38,31 +38,31 @@ defmodule Pleroma.Web.Federator do end def publish(activity, priority \\ 1) do - Jobs.enqueue(:federator_out, __MODULE__, [:publish, activity], priority) + Jobs.enqueue(:federator_outgoing, __MODULE__, [:publish, activity], priority) end def publish_single_ap(params) do - Jobs.enqueue(:federator_out, __MODULE__, [:publish_single_ap, params]) + Jobs.enqueue(:federator_outgoing, __MODULE__, [:publish_single_ap, params]) end def publish_single_websub(websub) do - Jobs.enqueue(:federator_out, __MODULE__, [:publish_single_websub, websub]) + Jobs.enqueue(:federator_outgoing, __MODULE__, [:publish_single_websub, websub]) end def verify_websub(websub) do - Jobs.enqueue(:federator_out, __MODULE__, [:verify_websub, websub]) + Jobs.enqueue(:federator_outgoing, __MODULE__, [:verify_websub, websub]) end def request_subscription(sub) do - Jobs.enqueue(:federator_out, __MODULE__, [:request_subscription, sub]) + Jobs.enqueue(:federator_outgoing, __MODULE__, [:request_subscription, sub]) end def refresh_subscriptions() do - Jobs.enqueue(:federator_out, __MODULE__, [:refresh_subscriptions]) + Jobs.enqueue(:federator_outgoing, __MODULE__, [:refresh_subscriptions]) end def publish_single_salmon(params) do - Jobs.enqueue(:federator_out, __MODULE__, [:publish_single_salmon, params]) + Jobs.enqueue(:federator_outgoing, __MODULE__, [:publish_single_salmon, params]) end # Job Worker Callbacks -- cgit v1.2.3 From 027adbc9e5c60cd43b8857eb7a3124e6df1310c2 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 14 Feb 2019 17:03:19 +0300 Subject: [#468] Refactored OAuth scopes parsing / defaults handling. --- lib/pleroma/web/controller_helper.ex | 4 ++++ .../web/mastodon_api/mastodon_api_controller.ex | 11 ++++++++--- lib/pleroma/web/oauth.ex | 23 +++++++++++----------- lib/pleroma/web/oauth/oauth_controller.ex | 12 +++++------ 4 files changed, 28 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index 14e3d19fd..a32195b49 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -5,6 +5,10 @@ defmodule Pleroma.Web.ControllerHelper do use Pleroma.Web, :controller + def oauth_scopes(params, default) do + Pleroma.Web.OAuth.parse_scopes(params["scopes"] || params["scope"], default) + end + def json_response(conn, status, json) do conn |> put_status(status) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 59f472e91..a1e9472b2 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -19,11 +19,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.CommonAPI - alias Pleroma.Web.OAuth alias Pleroma.Web.OAuth.{Authorization, Token, App} alias Pleroma.Web.MediaProxy + import Pleroma.Web.ControllerHelper, only: [oauth_scopes: 2] import Ecto.Query + require Logger @httpoison Application.get_env(:pleroma, :httpoison) @@ -32,8 +33,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do action_fallback(:errors) def create_app(conn, params) do - scopes = OAuth.parse_scopes(params["scope"] || params["scopes"]) - app_attrs = params |> Map.drop(["scope", "scopes"]) |> Map.put("scopes", scopes) + scopes = oauth_scopes(params, []) + + app_attrs = + params + |> Map.drop(["scope", "scopes"]) + |> Map.put("scopes", scopes) with cs <- App.register_changeset(%App{}, app_attrs), false <- cs.changes[:client_name] == @local_mastodon_name, diff --git a/lib/pleroma/web/oauth.ex b/lib/pleroma/web/oauth.ex index 761b80fde..8c78d1100 100644 --- a/lib/pleroma/web/oauth.ex +++ b/lib/pleroma/web/oauth.ex @@ -3,22 +3,21 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth do - def parse_scopes(nil) do - nil + def parse_scopes(scopes, default) when is_list(scopes) do + scopes = Enum.filter(scopes, &(&1 not in [nil, ""])) + + if Enum.any?(scopes), + do: scopes, + else: default end - def parse_scopes(scopes) when is_list(scopes) do + def parse_scopes(scopes, default) when is_binary(scopes) do scopes + |> String.split(~r/[\s,]+/) + |> parse_scopes(default) end - def parse_scopes(scopes) do - scopes = - scopes - |> to_string() - |> String.trim() - - if scopes == "", - do: [], - else: String.split(scopes, [" ", ","]) + def parse_scopes(_, default) do + default end end diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index f00d5293d..3e905c7c7 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -5,11 +5,12 @@ defmodule Pleroma.Web.OAuth.OAuthController do use Pleroma.Web, :controller - alias Pleroma.Web.OAuth alias Pleroma.Web.OAuth.{Authorization, Token, App} alias Pleroma.{Repo, User} alias Comeonin.Pbkdf2 + import Pleroma.Web.ControllerHelper, only: [oauth_scopes: 2] + plug(:fetch_session) plug(:fetch_flash) @@ -19,7 +20,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do render(conn, "show.html", %{ response_type: params["response_type"], client_id: params["client_id"], - scopes: scopes(params) || [], + scopes: oauth_scopes(params, []), redirect_uri: params["redirect_uri"], state: params["state"] }) @@ -39,7 +40,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, %App{} = app <- Repo.get_by(App, client_id: client_id), true <- redirect_uri in String.split(app.redirect_uris), - scopes <- scopes(params) || app.scopes, + scopes <- oauth_scopes(params, app.scopes), [] <- scopes -- app.scopes, true <- Enum.any?(scopes), {:ok, auth} <- Authorization.create_authorization(app, user, scopes) do @@ -117,7 +118,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do %User{} = user <- User.get_by_nickname_or_email(name), true <- Pbkdf2.checkpw(password, user.password_hash), {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, - scopes <- scopes(params) || app.scopes, + scopes <- oauth_scopes(params, app.scopes), {:ok, auth} <- Authorization.create_authorization(app, user, scopes), {:ok, token} <- Token.exchange_token(app, auth) do response = %{ @@ -197,7 +198,4 @@ defmodule Pleroma.Web.OAuth.OAuthController do nil end end - - defp scopes(params), - do: OAuth.parse_scopes(params["scopes"] || params["scope"]) end -- cgit v1.2.3 From 56862f4ce1275689416661847b0734129f5471ae Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 19:42:33 +0000 Subject: activitypub: clean up logging statements a little --- lib/pleroma/web/activity_pub/activity_pub.ex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index c46d8233e..ab2872f56 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -818,8 +818,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do if object = Object.get_cached_by_ap_id(id) do {:ok, object} else - Logger.info("Fetching #{id} via AP") - with {:ok, data} <- fetch_and_contain_remote_object_from_id(id), nil <- Object.normalize(data), params <- %{ @@ -851,7 +849,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end def fetch_and_contain_remote_object_from_id(id) do - Logger.info("Fetching #{id} via AP") + Logger.info("Fetching object #{id} via AP") with true <- String.starts_with?(id, "http"), {:ok, %{body: body, status: code}} when code in 200..299 <- -- cgit v1.2.3 From da44cdd3812fabb777c738b162c704de22e4b2f4 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 19:58:24 +0000 Subject: user: search: use get_or_fetch() instead of get_or_fetch_by_nickname() get_or_fetch() handles the nickname verses URI differences transparently. --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 3232cb842..29d2b3d89 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -731,7 +731,7 @@ defmodule Pleroma.User do # Strip the beginning @ off if there is a query query = String.trim_leading(query, "@") - if resolve, do: User.get_or_fetch_by_nickname(query) + if resolve, do: get_or_fetch(query) fts_results = do_search(fts_search_subquery(query), for_user) -- cgit v1.2.3 From ecdf0657ba4a90d821d3874c827593963e0ff041 Mon Sep 17 00:00:00 2001 From: eugenijm Date: Sun, 10 Feb 2019 02:26:29 +0300 Subject: Add logic for keeping follow_request_count up-to-date on the `follow`, `approve_friend_request`, and `deny_friend_request` actions. Add follow_request_count to the user view. --- lib/pleroma/user.ex | 26 ++++++++++++++++++++++ lib/pleroma/user/info.ex | 1 + lib/pleroma/web/activity_pub/activity_pub.ex | 16 ++++++++----- lib/pleroma/web/activity_pub/transmogrifier.ex | 6 ++--- .../web/mastodon_api/mastodon_api_controller.ex | 4 ++-- .../web/twitter_api/twitter_api_controller.ex | 4 ++-- lib/pleroma/web/twitter_api/views/user_view.ex | 18 +++++++++++---- 7 files changed, 58 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 3232cb842..854787a2b 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -618,6 +618,32 @@ defmodule Pleroma.User do ) end + def update_follow_request_count(%User{} = user) do + subquery = + user + |> User.get_follow_requests_query() + |> select([a], %{count: count(a.id)}) + + User + |> where(id: ^user.id) + |> join(:inner, [u], s in subquery(subquery)) + |> update([u, s], + set: [ + info: + fragment( + "jsonb_set(?, '{follow_request_count}', ?::varchar::jsonb, true)", + u.info, + s.count + ) + ] + ) + |> Repo.update_all([], returning: true) + |> case do + {1, [user]} -> {:ok, user} + _ -> {:error, user} + end + end + def get_follow_requests(%User{} = user) do q = get_follow_requests_query(user) reqs = Repo.all(q) diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 9d8779fab..c59e74c45 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -12,6 +12,7 @@ defmodule Pleroma.User.Info do field(:source_data, :map, default: %{}) field(:note_count, :integer, default: 0) field(:follower_count, :integer, default: 0) + field(:follow_request_count, :integer, default: 0) field(:locked, :boolean, default: false) field(:confirmation_pending, :boolean, default: false) field(:confirmation_token, :string, default: nil) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index c46d8233e..975f9fde3 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -172,9 +172,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do # only accept false as false value local = !(params[:local] == false) - with data <- %{"to" => to, "type" => "Accept", "actor" => actor, "object" => object}, + with data <- %{"to" => to, "type" => "Accept", "actor" => actor.ap_id, "object" => object}, {:ok, activity} <- insert(data, local), - :ok <- maybe_federate(activity) do + :ok <- maybe_federate(activity), + _ <- User.update_follow_request_count(actor) do {:ok, activity} end end @@ -183,9 +184,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do # only accept false as false value local = !(params[:local] == false) - with data <- %{"to" => to, "type" => "Reject", "actor" => actor, "object" => object}, + with data <- %{"to" => to, "type" => "Reject", "actor" => actor.ap_id, "object" => object}, {:ok, activity} <- insert(data, local), - :ok <- maybe_federate(activity) do + :ok <- maybe_federate(activity), + _ <- User.update_follow_request_count(actor) do {:ok, activity} end end @@ -283,7 +285,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def follow(follower, followed, activity_id \\ nil, local \\ true) do with data <- make_follow_data(follower, followed, activity_id), {:ok, activity} <- insert(data, local), - :ok <- maybe_federate(activity) do + :ok <- maybe_federate(activity), + _ <- User.update_follow_request_count(followed) do {:ok, activity} end end @@ -293,7 +296,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {:ok, follow_activity} <- update_follow_state(follow_activity, "cancelled"), unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_id), {:ok, activity} <- insert(unfollow_data, local), - :ok <- maybe_federate(activity) do + :ok <- maybe_federate(activity), + _ <- User.update_follow_request_count(followed) do {:ok, activity} end end diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 26b2dd575..41d89a02b 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -406,7 +406,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do if not User.locked?(followed) do ActivityPub.accept(%{ to: [follower.ap_id], - actor: followed.ap_id, + actor: followed, object: data, local: true }) @@ -432,7 +432,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do ActivityPub.accept(%{ to: follow_activity.data["to"], type: "Accept", - actor: followed.ap_id, + actor: followed, object: follow_activity.data["id"], local: false }) do @@ -458,7 +458,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do ActivityPub.reject(%{ to: follow_activity.data["to"], type: "Reject", - actor: followed.ap_id, + actor: followed, object: follow_activity.data["id"], local: false }) do diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index dcaeccac6..f0bbe5b3f 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -680,7 +680,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do {:ok, _activity} <- ActivityPub.accept(%{ to: [follower.ap_id], - actor: followed.ap_id, + actor: followed, object: follow_activity.data["id"], type: "Accept" }) do @@ -702,7 +702,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do {:ok, _activity} <- ActivityPub.reject(%{ to: [follower.ap_id], - actor: followed.ap_id, + actor: followed, object: follow_activity.data["id"], type: "Reject" }) do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index c2f0dc2a9..70ae4068a 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -570,7 +570,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do {:ok, _activity} <- ActivityPub.accept(%{ to: [follower.ap_id], - actor: followed.ap_id, + actor: followed, object: follow_activity.data["id"], type: "Accept" }) do @@ -590,7 +590,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do {:ok, _activity} <- ActivityPub.reject(%{ to: [follower.ap_id], - actor: followed.ap_id, + actor: followed, object: follow_activity.data["id"], type: "Reject" }) do diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex index a09450df7..df7384476 100644 --- a/lib/pleroma/web/twitter_api/views/user_view.ex +++ b/lib/pleroma/web/twitter_api/views/user_view.ex @@ -113,10 +113,12 @@ defmodule Pleroma.Web.TwitterAPI.UserView do "fields" => fields, # Pleroma extension - "pleroma" => %{ - "confirmation_pending" => user_info.confirmation_pending, - "tags" => user.tags - } + "pleroma" => + %{ + "confirmation_pending" => user_info.confirmation_pending, + "tags" => user.tags + } + |> maybe_with_follow_request_count(user, for_user) } data = @@ -132,6 +134,14 @@ defmodule Pleroma.Web.TwitterAPI.UserView do end end + defp maybe_with_follow_request_count(data, %User{id: id, info: %{locked: true}} = user, %User{ + id: id + }) do + Map.put(data, "follow_request_count", user.info.follow_request_count) + end + + defp maybe_with_follow_request_count(data, _, _), do: data + defp maybe_with_role(data, %User{id: id} = user, %User{id: id}) do Map.merge(data, %{"role" => role(user), "show_role" => user.info.show_role}) end -- cgit v1.2.3 From d943c90249e0a598e57a0dbdf41d387b53916092 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Fri, 15 Feb 2019 12:47:50 +0100 Subject: Add tests, change default config values, fix a bug --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 1f09b4e66..95211c596 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -47,14 +47,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address if Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") do - recipients - |> List.delete("https://www.w3.org/ns/activitystreams#Public") - |> List.delete(follower_collection) + recipients = + recipients + |> List.delete("https://www.w3.org/ns/activitystreams#Public") + |> List.delete(follower_collection) {:public, length(recipients)} else - recipients - |> List.delete(follower_collection) + recipients = + recipients + |> List.delete(follower_collection) {:not_public, length(recipients)} end -- cgit v1.2.3 From dca6bee2f7eba1dc366cc65d3087f20678549739 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Fri, 15 Feb 2019 13:43:14 +0100 Subject: Rename test, add check for follower collection when delisting --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 95211c596..1fd7b9c67 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -10,17 +10,22 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold]) follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address + follower_collection? = Enum.member?(message["to"] ++ message["cc"], follower_collection) + message = - with {:public, recipients} <- get_recipient_count(message) do - if recipients > delist_threshold and delist_threshold > 0 do + case recipients = get_recipient_count(message) do + {:public, _} when follower_collection? and recipients > delist_threshold -> message |> Map.put("to", [follower_collection]) |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) - else + + {:public, _} when recipients > delist_threshold -> + message + |> Map.put("to", []) + |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) + + _ -> message - end - else - _ -> message end {:ok, message} -- cgit v1.2.3 From c2e0a0c8d44f8697160d4597db45c5c4afd0d8a6 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Fri, 15 Feb 2019 14:05:20 +0100 Subject: Readd threshold is not 0 check, optmization? --- .../web/activity_pub/mrf/hellthread_policy.ex | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 1fd7b9c67..8ab1dd4e5 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -6,20 +6,20 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do alias Pleroma.User @behaviour Pleroma.Web.ActivityPub.MRF - defp delist_message(message) do - delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold]) + defp delist_message(message, threshold) when threshold > 0 do follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address follower_collection? = Enum.member?(message["to"] ++ message["cc"], follower_collection) message = case recipients = get_recipient_count(message) do - {:public, _} when follower_collection? and recipients > delist_threshold -> + {:public, _} + when follower_collection? and recipients > threshold -> message |> Map.put("to", [follower_collection]) |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) - {:public, _} when recipients > delist_threshold -> + {:public, _} when recipients > threshold -> message |> Map.put("to", []) |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) @@ -31,15 +31,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do {:ok, message} end - defp reject_message(message) do - reject_threshold = - Pleroma.Config.get( - [:mrf_hellthread, :reject_threshold], - Pleroma.Config.get([:mrf_hellthread, :threshold]) - ) + defp delist_message(message, _threshold), do: {:ok, message} + defp reject_message(message, threshold) when threshold > 0 do with {_, recipients} <- get_recipient_count(message) do - if recipients > reject_threshold and reject_threshold > 0 do + if recipients > threshold do {:reject, nil} else {:ok, message} @@ -47,6 +43,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do end end + defp reject_message(message, _threshold), do: {:ok, message} + defp get_recipient_count(message) do recipients = (message["to"] || []) ++ (message["cc"] || []) follower_collection = User.get_cached_by_ap_id(message["actor"]).follower_address @@ -69,8 +67,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do @impl true def filter(%{"type" => "Create"} = message) do - with {:ok, message} <- reject_message(message), - {:ok, message} <- delist_message(message) do + reject_threshold = + Pleroma.Config.get( + [:mrf_hellthread, :reject_threshold], + Pleroma.Config.get([:mrf_hellthread, :threshold]) + ) + + delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold]) + + with {:ok, message} <- reject_message(message, reject_threshold), + {:ok, message} <- delist_message(message, delist_threshold) do {:ok, message} else _e -> {:reject, nil} -- cgit v1.2.3 From 2a4a4f3342bb3d2bbbd2354e858278d2e17f8654 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 15 Feb 2019 19:54:37 +0300 Subject: [#468] Defined OAuth restrictions for all applicable routes. Improved missing "scopes" param handling. Allowed "any of" / "all of" mode specification in OAuthScopesPlug. Fixed auth UI / behavior when user selects no permissions at /oauth/authorize. --- lib/pleroma/plugs/oauth_scopes_plug.ex | 41 ++++--- lib/pleroma/web/controller_helper.ex | 2 +- .../web/mastodon_api/mastodon_api_controller.ex | 2 +- lib/pleroma/web/oauth.ex | 9 +- lib/pleroma/web/oauth/oauth_controller.ex | 42 +++++-- lib/pleroma/web/router.ex | 124 ++++++++++++++------- .../web/templates/o_auth/o_auth/show.html.eex | 2 +- 7 files changed, 144 insertions(+), 78 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/plugs/oauth_scopes_plug.ex b/lib/pleroma/plugs/oauth_scopes_plug.ex index a81e29830..f2bfa2b1a 100644 --- a/lib/pleroma/plugs/oauth_scopes_plug.ex +++ b/lib/pleroma/plugs/oauth_scopes_plug.ex @@ -7,22 +7,35 @@ defmodule Pleroma.Plugs.OAuthScopesPlug do @behaviour Plug - def init(%{required_scopes: _} = options), do: options + def init(%{scopes: _} = options), do: options - def call(%Plug.Conn{assigns: assigns} = conn, %{required_scopes: required_scopes}) do + def call(%Plug.Conn{assigns: assigns} = conn, %{scopes: scopes} = options) do + op = options[:op] || :| token = assigns[:token] - granted_scopes = token && token.scopes - - if is_nil(token) || required_scopes -- granted_scopes == [] do - conn - else - missing_scopes = required_scopes -- granted_scopes - error_message = "Insufficient permissions: #{Enum.join(missing_scopes, ", ")}." - - conn - |> put_resp_content_type("application/json") - |> send_resp(403, Jason.encode!(%{error: error_message})) - |> halt() + + cond do + is_nil(token) -> + conn + + op == :| && scopes -- token.scopes != scopes -> + conn + + op == :& && scopes -- token.scopes == [] -> + conn + + options[:fallback] == :proceed_unauthenticated -> + conn + |> assign(:user, nil) + |> assign(:token, nil) + + true -> + missing_scopes = scopes -- token.scopes + error_message = "Insufficient permissions: #{Enum.join(missing_scopes, " #{op} ")}." + + conn + |> put_resp_content_type("application/json") + |> send_resp(403, Jason.encode!(%{error: error_message})) + |> halt() end end end diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index a32195b49..8f36329ee 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -6,7 +6,7 @@ defmodule Pleroma.Web.ControllerHelper do use Pleroma.Web, :controller def oauth_scopes(params, default) do - Pleroma.Web.OAuth.parse_scopes(params["scopes"] || params["scope"], default) + Pleroma.Web.OAuth.parse_scopes(params["scope"] || params["scopes"], default) end def json_response(conn, status, json) do diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index a1e9472b2..0e77ec907 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -33,7 +33,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do action_fallback(:errors) def create_app(conn, params) do - scopes = oauth_scopes(params, []) + scopes = oauth_scopes(params, ["read"]) app_attrs = params diff --git a/lib/pleroma/web/oauth.ex b/lib/pleroma/web/oauth.ex index 8c78d1100..d2835a0ba 100644 --- a/lib/pleroma/web/oauth.ex +++ b/lib/pleroma/web/oauth.ex @@ -3,16 +3,13 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth do - def parse_scopes(scopes, default) when is_list(scopes) do - scopes = Enum.filter(scopes, &(&1 not in [nil, ""])) - - if Enum.any?(scopes), - do: scopes, - else: default + def parse_scopes(scopes, _default) when is_list(scopes) do + Enum.filter(scopes, &(&1 not in [nil, ""])) end def parse_scopes(scopes, default) when is_binary(scopes) do scopes + |> String.trim() |> String.split(~r/[\s,]+/) |> parse_scopes(default) end diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 3e905c7c7..d8d3ea5b4 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -17,10 +17,20 @@ defmodule Pleroma.Web.OAuth.OAuthController do action_fallback(Pleroma.Web.OAuth.FallbackController) def authorize(conn, params) do + params_scopes = oauth_scopes(params, nil) + + scopes = + if params_scopes do + params_scopes + else + app = Repo.get_by(App, client_id: params["client_id"]) + app && app.scopes + end + render(conn, "show.html", %{ response_type: params["response_type"], client_id: params["client_id"], - scopes: oauth_scopes(params, []), + scopes: scopes || [], redirect_uri: params["redirect_uri"], state: params["state"] }) @@ -33,14 +43,14 @@ defmodule Pleroma.Web.OAuth.OAuthController do "password" => password, "client_id" => client_id, "redirect_uri" => redirect_uri - } = params + } = auth_params }) do with %User{} = user <- User.get_by_nickname_or_email(name), true <- Pbkdf2.checkpw(password, user.password_hash), {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, %App{} = app <- Repo.get_by(App, client_id: client_id), true <- redirect_uri in String.split(app.redirect_uris), - scopes <- oauth_scopes(params, app.scopes), + scopes <- oauth_scopes(auth_params, []), [] <- scopes -- app.scopes, true <- Enum.any?(scopes), {:ok, auth} <- Authorization.create_authorization(app, user, scopes) do @@ -64,8 +74,8 @@ defmodule Pleroma.Web.OAuth.OAuthController do url_params = %{:code => auth.token} url_params = - if params["state"] do - Map.put(url_params, :state, params["state"]) + if auth_params["state"] do + Map.put(url_params, :state, auth_params["state"]) else url_params end @@ -75,14 +85,20 @@ defmodule Pleroma.Web.OAuth.OAuthController do redirect(conn, external: url) end else - {:auth_active, false} -> - conn - |> put_flash(:error, "Account confirmation pending") - |> put_status(:forbidden) - |> authorize(params) + res -> + msg = + if res == {:auth_active, false}, + do: "Account confirmation pending", + else: "Invalid Username/Password/Permissions" + + app = Repo.get_by(App, client_id: client_id) + available_scopes = (app && app.scopes) || oauth_scopes(auth_params, []) + scope_param = Enum.join(available_scopes, " ") - error -> - error + conn + |> put_flash(:error, msg) + |> put_status(:unauthorized) + |> authorize(Map.merge(auth_params, %{"scope" => scope_param})) end end @@ -119,6 +135,8 @@ defmodule Pleroma.Web.OAuth.OAuthController do true <- Pbkdf2.checkpw(password, user.password_hash), {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, scopes <- oauth_scopes(params, app.scopes), + [] <- scopes -- app.scopes, + true <- Enum.any?(scopes), {:ok, auth} <- Authorization.create_authorization(app, user, scopes), {:ok, token} <- Token.exchange_token(app, auth) do response = %{ diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 4ece311d3..6f17de1ca 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -74,16 +74,23 @@ defmodule Pleroma.Web.Router do plug(Pleroma.Plugs.EnsureUserKeyPlug) end + pipeline :oauth_read_or_unauthenticated do + plug(Pleroma.Plugs.OAuthScopesPlug, %{ + scopes: ["read"], + fallback: :proceed_unauthenticated + }) + end + pipeline :oauth_read do - plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["read"]}) + plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["read"]}) end pipeline :oauth_write do - plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["write"]}) + plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["write"]}) end pipeline :oauth_follow do - plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["follow"]}) + plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["follow"]}) end pipeline :well_known do @@ -113,6 +120,7 @@ defmodule Pleroma.Web.Router do scope "/api/pleroma", Pleroma.Web.TwitterAPI do pipe_through(:pleroma_api) + get("/password_reset/:token", UtilController, :show_password_reset) post("/password_reset", UtilController, :password_reset) get("/emoji", UtilController, :emoji) @@ -125,7 +133,8 @@ defmodule Pleroma.Web.Router do end scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do - pipe_through(:admin_api) + pipe_through([:admin_api, :oauth_write]) + delete("/user", AdminAPIController, :user_delete) post("/user", AdminAPIController, :user_create) put("/users/tag", AdminAPIController, :tag_users) @@ -147,9 +156,14 @@ defmodule Pleroma.Web.Router do scope "/", Pleroma.Web.TwitterAPI do pipe_through(:pleroma_html) - get("/ostatus_subscribe", UtilController, :remote_follow) - post("/ostatus_subscribe", UtilController, :do_remote_follow) + post("/main/ostatus", UtilController, :remote_subscribe) + get("/ostatus_subscribe", UtilController, :remote_follow) + + scope [] do + pipe_through(:oauth_follow) + post("/ostatus_subscribe", UtilController, :do_remote_follow) + end end scope "/api/pleroma", Pleroma.Web.TwitterAPI do @@ -180,11 +194,11 @@ defmodule Pleroma.Web.Router do scope "/api/v1", Pleroma.Web.MastodonAPI do pipe_through(:authenticated_api) - get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials) - scope [] do pipe_through(:oauth_read) + get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials) + get("/accounts/relationships", MastodonAPIController, :relationships) get("/accounts/search", MastodonAPIController, :account_search) @@ -284,33 +298,40 @@ defmodule Pleroma.Web.Router do scope "/api/v1", Pleroma.Web.MastodonAPI do pipe_through(:api) + get("/instance", MastodonAPIController, :masto_instance) get("/instance/peers", MastodonAPIController, :peers) post("/apps", MastodonAPIController, :create_app) get("/custom_emojis", MastodonAPIController, :custom_emojis) - get("/timelines/public", MastodonAPIController, :public_timeline) - get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline) - get("/timelines/list/:list_id", MastodonAPIController, :list_timeline) - - get("/statuses/:id", MastodonAPIController, :get_status) - get("/statuses/:id/context", MastodonAPIController, :get_context) get("/statuses/:id/card", MastodonAPIController, :status_card) + get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by) get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by) - get("/accounts/:id/statuses", MastodonAPIController, :user_statuses) - get("/accounts/:id/followers", MastodonAPIController, :followers) - get("/accounts/:id/following", MastodonAPIController, :following) - get("/accounts/:id", MastodonAPIController, :user) - get("/trends", MastodonAPIController, :empty_array) - get("/search", MastodonAPIController, :search) + scope [] do + pipe_through(:oauth_read_or_unauthenticated) + + get("/timelines/public", MastodonAPIController, :public_timeline) + get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline) + get("/timelines/list/:list_id", MastodonAPIController, :list_timeline) + + get("/statuses/:id", MastodonAPIController, :get_status) + get("/statuses/:id/context", MastodonAPIController, :get_context) + + get("/accounts/:id/statuses", MastodonAPIController, :user_statuses) + get("/accounts/:id/followers", MastodonAPIController, :followers) + get("/accounts/:id/following", MastodonAPIController, :following) + get("/accounts/:id", MastodonAPIController, :user) + + get("/search", MastodonAPIController, :search) + end end scope "/api/v2", Pleroma.Web.MastodonAPI do - pipe_through(:api) + pipe_through([:api, :oauth_read_or_unauthenticated]) get("/search", MastodonAPIController, :search2) end @@ -327,19 +348,11 @@ defmodule Pleroma.Web.Router do scope "/api", Pleroma.Web do pipe_through(:api) - get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline) - get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline) - get("/users/show", TwitterAPI.Controller, :show_user) - - get("/statuses/followers", TwitterAPI.Controller, :followers) - get("/statuses/friends", TwitterAPI.Controller, :friends) - get("/statuses/blocks", TwitterAPI.Controller, :blocks) - get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status) - get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation) - post("/account/register", TwitterAPI.Controller, :register) post("/account/password_reset", TwitterAPI.Controller, :password_reset) + post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email) + get( "/account/confirm_email/:user_id/:token", TwitterAPI.Controller, @@ -347,14 +360,26 @@ defmodule Pleroma.Web.Router do as: :confirm_email ) - post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email) + scope [] do + pipe_through(:oauth_read_or_unauthenticated) + + get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline) + get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline) + get("/users/show", TwitterAPI.Controller, :show_user) + + get("/statuses/followers", TwitterAPI.Controller, :followers) + get("/statuses/friends", TwitterAPI.Controller, :friends) + get("/statuses/blocks", TwitterAPI.Controller, :blocks) + get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status) + get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation) - get("/search", TwitterAPI.Controller, :search) - get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline) + get("/search", TwitterAPI.Controller, :search) + get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline) + end end scope "/api", Pleroma.Web do - pipe_through(:api) + pipe_through([:api, :oauth_read_or_unauthenticated]) get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline) @@ -368,19 +393,19 @@ defmodule Pleroma.Web.Router do end scope "/api", Pleroma.Web, as: :twitter_api_search do - pipe_through(:api) + pipe_through([:api, :oauth_read_or_unauthenticated]) get("/pleroma/search_user", TwitterAPI.Controller, :search_user) end scope "/api", Pleroma.Web, as: :authenticated_twitter_api do pipe_through(:authenticated_api) - get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials) - post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials) - scope [] do pipe_through(:oauth_read) + get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials) + post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials) + get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline) get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline) get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline) @@ -506,9 +531,16 @@ defmodule Pleroma.Web.Router do scope "/", Pleroma.Web.ActivityPub do pipe_through([:activitypub_client]) - get("/api/ap/whoami", ActivityPubController, :whoami) - get("/users/:nickname/inbox", ActivityPubController, :read_inbox) - post("/users/:nickname/outbox", ActivityPubController, :update_outbox) + scope [] do + pipe_through(:oauth_read) + get("/api/ap/whoami", ActivityPubController, :whoami) + get("/users/:nickname/inbox", ActivityPubController, :read_inbox) + end + + scope [] do + pipe_through(:oauth_write) + post("/users/:nickname/outbox", ActivityPubController, :update_outbox) + end end scope "/relay", Pleroma.Web.ActivityPub do @@ -518,6 +550,7 @@ defmodule Pleroma.Web.Router do scope "/", Pleroma.Web.ActivityPub do pipe_through(:activitypub) + post("/users/:nickname/inbox", ActivityPubController, :inbox) post("/inbox", ActivityPubController, :inbox) end @@ -538,8 +571,12 @@ defmodule Pleroma.Web.Router do pipe_through(:mastodon_html) get("/web/login", MastodonAPIController, :login) - get("/web/*path", MastodonAPIController, :index) delete("/auth/sign_out", MastodonAPIController, :logout) + + scope [] do + pipe_through(:oauth_read) + get("/web/*path", MastodonAPIController, :index) + end end pipeline :remote_media do @@ -547,6 +584,7 @@ defmodule Pleroma.Web.Router do scope "/proxy/", Pleroma.Web.MediaProxy do pipe_through(:remote_media) + get("/:sig/:url", MediaProxyController, :remote) get("/:sig/:url/:filename", MediaProxyController, :remote) end diff --git a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex index 1ecb5b444..41b58aca0 100644 --- a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex +++ b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex @@ -14,7 +14,7 @@ <%= label f, :scope, "Permissions" %>
<%= for scope <- @scopes do %> - <%= checkbox f, :"scopes_#{scope}", hidden_input: false, value: scope, checked_value: scope, name: "authorization[scopes][]" %> + <%= checkbox f, :"scopes_#{scope}", value: scope, checked_value: scope, unchecked_value: "", name: "authorization[scopes][]" %> <%= label f, :"scopes_#{scope}", String.capitalize(scope) %>
<% end %> -- cgit v1.2.3 From d812a347ca936dba764eb223fde029d83ca3fba0 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 16 Feb 2019 16:42:34 +0100 Subject: Add optional welcome message. --- lib/pleroma/user.ex | 1 + lib/pleroma/user/welcome_message.ex | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 lib/pleroma/user/welcome_message.ex (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 29d2b3d89..3c6a9953d 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -261,6 +261,7 @@ defmodule Pleroma.User do def register(%Ecto.Changeset{} = changeset) do with {:ok, user} <- Repo.insert(changeset), {:ok, user} <- autofollow_users(user), + {:ok, _} <- Pleroma.User.WelcomeMessage.post_welcome_message_to_user(user), {:ok, _} <- try_send_confirmation_email(user) do {:ok, user} end diff --git a/lib/pleroma/user/welcome_message.ex b/lib/pleroma/user/welcome_message.ex new file mode 100644 index 000000000..6a0ec084f --- /dev/null +++ b/lib/pleroma/user/welcome_message.ex @@ -0,0 +1,33 @@ +defmodule Pleroma.User.WelcomeMessage do + alias Pleroma.User + alias Pleroma.Web.CommonAPI + import Ecto.Query + + def post_welcome_message_to_user(user) do + with %User{} = sender_user <- welcome_user(), + message when is_binary(message) <- welcome_message() do + CommonAPI.post(sender_user, %{ + "visibility" => "direct", + "status" => "@#{user.nickname}\n#{message}" + }) + else + _ -> {:ok, nil} + end + end + + defp welcome_user() do + if nickname = Pleroma.Config.get([:instance, :welcome_user_nickname]) do + from(u in User, + where: u.local == true, + where: u.nickname == ^nickname + ) + |> Pleroma.Repo.one() + else + nil + end + end + + defp welcome_message() do + Pleroma.Config.get([:instance, :welcome_message]) + end +end -- cgit v1.2.3 From 38e15930cb7e8aec4742eb85da26955b4c08e8ce Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 16 Feb 2019 17:01:15 +0100 Subject: Add option to return all friends in twitter api. Mainly useful for user export. --- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index c2f0dc2a9..a8ef0a8ca 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -524,6 +524,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def friends(%{assigns: %{user: for_user}} = conn, params) do {:ok, page} = Ecto.Type.cast(:integer, params["page"] || 1) + {:ok, export} = Ecto.Type.cast(:boolean, params["all"] || false) + + page = if export, do: nil, else: page with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params), {:ok, friends} <- User.get_friends(user, page) do -- cgit v1.2.3 From 269d3e1ca6c1d01feb995a108852963ce5bc32fc Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 16 Feb 2019 17:24:48 +0100 Subject: WelcomeMessage: Get rid of Ecto reference. --- lib/pleroma/user/welcome_message.ex | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/welcome_message.ex b/lib/pleroma/user/welcome_message.ex index 6a0ec084f..8018ac22f 100644 --- a/lib/pleroma/user/welcome_message.ex +++ b/lib/pleroma/user/welcome_message.ex @@ -1,7 +1,6 @@ defmodule Pleroma.User.WelcomeMessage do alias Pleroma.User alias Pleroma.Web.CommonAPI - import Ecto.Query def post_welcome_message_to_user(user) do with %User{} = sender_user <- welcome_user(), @@ -16,14 +15,12 @@ defmodule Pleroma.User.WelcomeMessage do end defp welcome_user() do - if nickname = Pleroma.Config.get([:instance, :welcome_user_nickname]) do - from(u in User, - where: u.local == true, - where: u.nickname == ^nickname - ) - |> Pleroma.Repo.one() + with nickname when is_binary(nickname) <- + Pleroma.Config.get([:instance, :welcome_user_nickname]), + %User{local: true} = user <- User.get_cached_by_nickname(nickname) do + user else - nil + _ -> nil end end -- cgit v1.2.3 From 96c725328b556833d59de23093fb4aeba9bb5684 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 16 Feb 2019 20:38:25 +0300 Subject: Remove a limit on attachments in Mastodon API and document the changes in responses from vanilla mastodon --- lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 69f5f992c..a49b381c9 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -166,7 +166,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do sensitive: sensitive, spoiler_text: object["summary"] || "", visibility: get_visibility(object), - media_attachments: attachments |> Enum.take(4), + media_attachments: attachments, mentions: mentions, tags: build_tags(tags), application: %{ -- cgit v1.2.3 From 4df455f69bef5270c7e6a57022237ff75f13687c Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 3 Feb 2019 12:31:12 +0100 Subject: [MastoAPI] Add switching of frontend flavours --- lib/pleroma/user/info.ex | 9 +++++ .../web/mastodon_api/mastodon_api_controller.ex | 41 +++++++++++++++++++++- lib/pleroma/web/router.ex | 3 ++ .../templates/mastodon_api/mastodon/index.html.eex | 8 ++--- 4 files changed, 56 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 9d8779fab..e33ec816b 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -34,6 +34,7 @@ defmodule Pleroma.User.Info do field(:hide_followers, :boolean, default: false) field(:hide_follows, :boolean, default: false) field(:pinned_activities, {:array, :string}, default: []) + field(:flavour, :string, default: nil) # Found in the wild # ap_id -> Where is this used? @@ -186,6 +187,14 @@ defmodule Pleroma.User.Info do |> validate_required([:settings]) end + def mastodon_flavour_update(info, flavour) do + params = %{flavour: flavour} + + info + |> cast(params, [:flavour]) + |> validate_required([:flavour]) + end + def set_source_data(info, source_data) do params = %{source_data: source_data} diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index dcaeccac6..0150f18f8 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1051,6 +1051,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do accounts = Map.put(%{}, user.id, AccountView.render("account.json", %{user: user, for: user})) + flavour = get_user_flavour(user) + initial_state = %{ meta: %{ @@ -1135,7 +1137,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do conn |> put_layout(false) |> put_view(MastodonView) - |> render("index.html", %{initial_state: initial_state}) + |> render("index.html", %{initial_state: initial_state, flavour: flavour}) else conn |> redirect(to: "/web/login") @@ -1157,6 +1159,43 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end + @supported_flavours ["glitch", "vanilla"] + + def set_flavour(%{assigns: %{user: user}} = conn, %{"flavour" => flavour} = _params) + when flavour in @supported_flavours do + flavour_cng = User.Info.mastodon_flavour_update(user.info, flavour) + + with changeset <- Ecto.Changeset.change(user), + changeset <- Ecto.Changeset.put_embed(changeset, :info, flavour_cng), + {:ok, user} <- User.update_and_set_cache(changeset), + flavour <- user.info.flavour do + json(conn, flavour) + else + e -> + conn + |> put_resp_content_type("application/json") + |> send_resp(500, Jason.encode!(%{"error" => inspect(e)})) + end + end + + def set_flavour(conn, _params) do + conn + |> put_status(400) + |> json(%{error: "Unsupported flavour"}) + end + + def get_flavour(%{assigns: %{user: user}} = conn, _params) do + json(conn, get_user_flavour(user)) + end + + defp get_user_flavour(%User{info: %{flavour: flavour}}) when flavour in @supported_flavours do + flavour + end + + defp get_user_flavour(_) do + "glitch" + end + def login(conn, %{"code" => code}) do with {:ok, app} <- get_or_make_app(), %Authorization{} = auth <- Repo.get_by(Authorization, token: code, app_id: app.id), diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index d66a1c2a1..664f93c1c 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -236,6 +236,9 @@ defmodule Pleroma.Web.Router do get("/suggestions", MastodonAPIController, :suggestions) get("/endorsements", MastodonAPIController, :empty_array) + + post("/pleroma/flavour/:flavour", MastodonAPIController, :set_flavour) + get("/pleroma/flavour", MastodonAPIController, :get_flavour) end scope "/api/web", Pleroma.Web.MastodonAPI do diff --git a/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex b/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex index 9a725e420..5659c7828 100644 --- a/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex +++ b/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex @@ -8,7 +8,7 @@ - + @@ -19,10 +19,10 @@ - - + + - +
-- cgit v1.2.3 From 8f98d970c105bec3205c6ce524750583ad5fb502 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sun, 17 Feb 2019 13:46:40 +0300 Subject: Fix recipient count in hellthread policy --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 8ab1dd4e5..6736f3cb9 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -12,14 +12,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do follower_collection? = Enum.member?(message["to"] ++ message["cc"], follower_collection) message = - case recipients = get_recipient_count(message) do - {:public, _} + case get_recipient_count(message) do + {:public, recipients} when follower_collection? and recipients > threshold -> message |> Map.put("to", [follower_collection]) |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) - {:public, _} when recipients > threshold -> + {:public, recipients} when recipients > threshold -> message |> Map.put("to", []) |> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"]) -- cgit v1.2.3 From dcf24a3233bb50689d26f9d7833f98158730ce35 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sun, 17 Feb 2019 13:49:14 +0300 Subject: [#468] Refactored OAuth scopes' defaults & missing selection handling. --- lib/pleroma/web/controller_helper.ex | 1 + .../web/mastodon_api/mastodon_api_controller.ex | 2 +- lib/pleroma/web/oauth/oauth_controller.ex | 46 ++++++++++------------ .../web/templates/o_auth/o_auth/show.html.eex | 7 ++-- 4 files changed, 27 insertions(+), 29 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex index 8f36329ee..5915ea40e 100644 --- a/lib/pleroma/web/controller_helper.ex +++ b/lib/pleroma/web/controller_helper.ex @@ -6,6 +6,7 @@ defmodule Pleroma.Web.ControllerHelper do use Pleroma.Web, :controller def oauth_scopes(params, default) do + # Note: `scopes` is used by Mastodon — supporting it but sticking to OAuth's standard `scope` wherever we control it Pleroma.Web.OAuth.parse_scopes(params["scope"] || params["scopes"], default) end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 0e77ec907..5d51e913d 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1156,7 +1156,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do response_type: "code", client_id: app.client_id, redirect_uri: ".", - scope: app.scopes + scope: Enum.join(app.scopes, " ") ) conn diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index d8d3ea5b4..fe2c958c9 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -17,20 +17,15 @@ defmodule Pleroma.Web.OAuth.OAuthController do action_fallback(Pleroma.Web.OAuth.FallbackController) def authorize(conn, params) do - params_scopes = oauth_scopes(params, nil) - - scopes = - if params_scopes do - params_scopes - else - app = Repo.get_by(App, client_id: params["client_id"]) - app && app.scopes - end + app = Repo.get_by(App, client_id: params["client_id"]) + available_scopes = (app && app.scopes) || [] + scopes = oauth_scopes(params, nil) || available_scopes render(conn, "show.html", %{ response_type: params["response_type"], client_id: params["client_id"], - scopes: scopes || [], + available_scopes: available_scopes, + scopes: scopes, redirect_uri: params["redirect_uri"], state: params["state"] }) @@ -47,12 +42,13 @@ defmodule Pleroma.Web.OAuth.OAuthController do }) do with %User{} = user <- User.get_by_nickname_or_email(name), true <- Pbkdf2.checkpw(password, user.password_hash), - {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, %App{} = app <- Repo.get_by(App, client_id: client_id), true <- redirect_uri in String.split(app.redirect_uris), scopes <- oauth_scopes(auth_params, []), - [] <- scopes -- app.scopes, - true <- Enum.any?(scopes), + {:unsupported_scopes, []} <- {:unsupported_scopes, scopes -- app.scopes}, + # Note: `scope` param is intentionally not optional in this context + {:missing_scopes, false} <- {:missing_scopes, scopes == []}, + {:auth_active, true} <- {:auth_active, User.auth_active?(user)}, {:ok, auth} <- Authorization.create_authorization(app, user, scopes) do # Special case: Local MastodonFE. redirect_uri = @@ -85,20 +81,20 @@ defmodule Pleroma.Web.OAuth.OAuthController do redirect(conn, external: url) end else - res -> - msg = - if res == {:auth_active, false}, - do: "Account confirmation pending", - else: "Invalid Username/Password/Permissions" - - app = Repo.get_by(App, client_id: client_id) - available_scopes = (app && app.scopes) || oauth_scopes(auth_params, []) - scope_param = Enum.join(available_scopes, " ") - + {scopes_issue, _} when scopes_issue in [:unsupported_scopes, :missing_scopes] -> conn - |> put_flash(:error, msg) + |> put_flash(:error, "Permissions not specified.") |> put_status(:unauthorized) - |> authorize(Map.merge(auth_params, %{"scope" => scope_param})) + |> authorize(auth_params) + + {:auth_active, false} -> + conn + |> put_flash(:error, "Account confirmation pending.") + |> put_status(:forbidden) + |> authorize(auth_params) + + error -> + error end end diff --git a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex index 41b58aca0..6e88efe11 100644 --- a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex +++ b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex @@ -13,9 +13,10 @@ <%= label f, :scope, "Permissions" %>
-<%= for scope <- @scopes do %> - <%= checkbox f, :"scopes_#{scope}", value: scope, checked_value: scope, unchecked_value: "", name: "authorization[scopes][]" %> - <%= label f, :"scopes_#{scope}", String.capitalize(scope) %> +<%= for scope <- @available_scopes do %> + <%# Note: using hidden input with `unchecked_value` in order to distinguish user's empty selection from `scope` param being omitted %> + <%= checkbox f, :"scope_#{scope}", value: scope in @scopes && scope, checked_value: scope, unchecked_value: "", name: "authorization[scope][]" %> + <%= label f, :"scope_#{scope}", String.capitalize(scope) %>
<% end %> -- cgit v1.2.3 From d3fe2c8ec6116fbc3058f7a795ef59564bddfb08 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sun, 17 Feb 2019 14:07:35 +0300 Subject: [#468] Formatting fix. --- lib/pleroma/web/router.ex | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index e09164a77..81e83579e 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -240,16 +240,16 @@ defmodule Pleroma.Web.Router do post("/statuses", MastodonAPIController, :post_status) delete("/statuses/:id", MastodonAPIController, :delete_status) - post("/statuses/:id/reblog", MastodonAPIController, :reblog_status) - post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status) - post("/statuses/:id/favourite", MastodonAPIController, :fav_status) - post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status) - post("/statuses/:id/pin", MastodonAPIController, :pin_status) - post("/statuses/:id/unpin", MastodonAPIController, :unpin_status) - post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status) - post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status) - post("/statuses/:id/mute", MastodonAPIController, :mute_conversation) - post("/statuses/:id/unmute", MastodonAPIController, :unmute_conversation) + post("/statuses/:id/reblog", MastodonAPIController, :reblog_status) + post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status) + post("/statuses/:id/favourite", MastodonAPIController, :fav_status) + post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status) + post("/statuses/:id/pin", MastodonAPIController, :pin_status) + post("/statuses/:id/unpin", MastodonAPIController, :unpin_status) + post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status) + post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status) + post("/statuses/:id/mute", MastodonAPIController, :mute_conversation) + post("/statuses/:id/unmute", MastodonAPIController, :unmute_conversation) post("/media", MastodonAPIController, :upload) put("/media/:id", MastodonAPIController, :update_media) -- cgit v1.2.3 From 94708d63705f1e4e7f3aaebb6744634237b0cf21 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Sun, 17 Feb 2019 23:57:35 +0300 Subject: Render only "id", "valid_until" and "app_name" in TokenView --- lib/pleroma/web/oauth/token.ex | 1 + lib/pleroma/web/twitter_api/views/token_view.ex | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index f5594f834..7fe58f6a2 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -68,5 +68,6 @@ defmodule Pleroma.Web.OAuth.Token do where: t.user_id == ^user_id ) |> Repo.all() + |> Repo.preload(:app) end end diff --git a/lib/pleroma/web/twitter_api/views/token_view.ex b/lib/pleroma/web/twitter_api/views/token_view.ex index 96b8526a4..3ff314913 100644 --- a/lib/pleroma/web/twitter_api/views/token_view.ex +++ b/lib/pleroma/web/twitter_api/views/token_view.ex @@ -14,9 +14,8 @@ defmodule Pleroma.Web.TwitterAPI.TokenView do def render("show.json", %{token: token_entry}) do %{ id: token_entry.id, - token: token_entry.token, - refresh_token: token_entry.refresh_token, - valid_until: token_entry.valid_until + valid_until: token_entry.valid_until, + app_name: token_entry.app.client_name } end end -- cgit v1.2.3 From fc35481445c4fdfea9fab58a74c5f4231b56885b Mon Sep 17 00:00:00 2001 From: eugenijm Date: Tue, 19 Feb 2019 10:43:37 +0300 Subject: Update user cache when user tags are updated --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index ff84e7b0a..322c338cd 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1200,7 +1200,7 @@ defmodule Pleroma.User do {:ok, updated_user} = user |> change(%{tags: new_tags}) - |> Repo.update() + |> update_and_set_cache() updated_user end -- cgit v1.2.3 From 96dcacade1fb5efd3c5118a1b8510e0cedbfeb85 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 19 Feb 2019 13:23:13 +0300 Subject: properly check for follower address in is_private? --- lib/pleroma/web/activity_pub/activity_pub.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index ab2872f56..839b6ce2a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -876,7 +876,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end def is_private?(activity) do - !is_public?(activity) && Enum.any?(activity.data["to"], &String.contains?(&1, "/followers")) + unless is_public?(activity) do + follower_address = User.get_cached_by_ap_id(activity.data["actor"]).follower_address + Enum.any?(activity.data["to"], &(&1 == follower_address)) + else + false + end end def is_direct?(%Activity{data: %{"directMessage" => true}}), do: true -- cgit v1.2.3 From 109b01a6318e01566a3a148c9c9ecd0313546f5f Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 19 Feb 2019 13:52:15 +0300 Subject: mark ap_id unique_constraint --- lib/pleroma/user.ex | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 29d2b3d89..c2ca58fb9 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -237,6 +237,7 @@ defmodule Pleroma.User do changeset |> put_change(:password_hash, hashed) |> put_change(:ap_id, ap_id) + |> unique_constraint(:ap_id) |> put_change(:following, [followers]) |> put_change(:follower_address, followers) else -- cgit v1.2.3 From 25b9e7a8c39602e6463a867089948a7957cfab9f Mon Sep 17 00:00:00 2001 From: eugenijm Date: Tue, 19 Feb 2019 18:40:57 +0300 Subject: Added admin API for changing user activation status --- lib/pleroma/web/admin_api/admin_api_controller.ex | 7 +++++++ lib/pleroma/web/router.ex | 2 ++ 2 files changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index dc01f46f3..9ec50bb90 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -124,6 +124,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do |> json(%{error: "No such permission_group"}) end + def set_activation_status(conn, %{"nickname" => nickname, "status" => status}) do + with {:ok, status} <- Ecto.Type.cast(:boolean, status), + %User{} = user <- User.get_by_nickname(nickname), + {:ok, _} <- User.deactivate(user, !status), + do: json_response(conn, :no_content, "") + end + def relay_follow(conn, %{"relay_url" => target}) do with {:ok, _message} <- Relay.follow(target) do json(conn, target) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 9a6cf2232..a4a382110 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -124,6 +124,8 @@ defmodule Pleroma.Web.Router do post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add) delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete) + put("/activation_status/:nickname", AdminAPIController, :set_activation_status) + post("/relay", AdminAPIController, :relay_follow) delete("/relay", AdminAPIController, :relay_unfollow) -- cgit v1.2.3 From 10a11f083ca543022c61e24b1ec0cc83811d6d06 Mon Sep 17 00:00:00 2001 From: href Date: Tue, 19 Feb 2019 17:39:42 +0100 Subject: Embed player suitable for Twitter Cards --- lib/pleroma/web/metadata/player_view.ex | 21 +++++++++++++++++++++ lib/pleroma/web/metadata/twitter_card.ex | 19 +++++++++++++------ lib/pleroma/web/ostatus/ostatus_controller.ex | 20 ++++++++++++++++++++ lib/pleroma/web/router.ex | 1 + .../web/templates/layout/metadata_player.html.eex | 16 ++++++++++++++++ 5 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 lib/pleroma/web/metadata/player_view.ex create mode 100644 lib/pleroma/web/templates/layout/metadata_player.html.eex (limited to 'lib') diff --git a/lib/pleroma/web/metadata/player_view.ex b/lib/pleroma/web/metadata/player_view.ex new file mode 100644 index 000000000..68b0a3507 --- /dev/null +++ b/lib/pleroma/web/metadata/player_view.ex @@ -0,0 +1,21 @@ +defmodule Pleroma.Web.Metadata.PlayerView do + use Pleroma.Web, :view + import Phoenix.HTML.Tag, only: [content_tag: 3, tag: 2] + + def render("player.html", %{"mediaType" => type, "href" => href}) do + tag_type = + case type do + "audio" <> _ -> :audio + "video" <> _ -> :video + end + + content_tag( + tag_type, + [ + tag(:source, src: href, type: type), + "Your browser does not support #{type} playback." + ], + controls: true + ) + end +end diff --git a/lib/pleroma/web/metadata/twitter_card.ex b/lib/pleroma/web/metadata/twitter_card.ex index 13fa22240..e7f5760a9 100644 --- a/lib/pleroma/web/metadata/twitter_card.ex +++ b/lib/pleroma/web/metadata/twitter_card.ex @@ -12,10 +12,11 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do @impl Provider def build_tags(%{ + activity_id: id, object: object, user: user }) do - attachments = build_attachments(object) + attachments = build_attachments(id, object) scrubbed_content = Utils.scrub_html_and_truncate(object) # Zero width space content = @@ -65,7 +66,9 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do end end - defp build_attachments(%{data: %{"attachment" => attachments}}) do + defp build_attachments(id, z = %{data: %{"attachment" => attachments}}) do + IO.puts(inspect(z)) + Enum.reduce(attachments, [], fn attachment, acc -> rendered_tags = Enum.reduce(attachment["url"], [], fn url, acc -> @@ -79,8 +82,9 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do "audio" -> [ {:meta, [property: "twitter:card", content: "player"], []}, - {:meta, [property: "twitter:player", content: Utils.attachment_url(url["href"])], - []} + {:meta, [property: "twitter:player:width", content: "480"], []}, + {:meta, [property: "twitter:player:height", content: "80"], []}, + {:meta, [property: "twitter:player", content: player_url(id)], []} | acc ] @@ -99,8 +103,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do "video" -> [ {:meta, [property: "twitter:card", content: "player"], []}, - {:meta, [property: "twitter:player", content: Utils.attachment_url(url["href"])], - []}, + {:meta, [property: "twitter:player", content: player_url(id)], []}, {:meta, [property: "twitter:player:width", content: "1280"], []}, {:meta, [property: "twitter:player:height", content: "720"], []} | acc @@ -114,4 +117,8 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do acc ++ rendered_tags end) end + + defp player_url(id) do + Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice_player, id) + end end diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index db4c8f4da..e7bde28a6 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -153,6 +153,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do %Object{} = object = Object.normalize(activity.data["object"]) Fallback.RedirectController.redirector_with_meta(conn, %{ + activity_id: activity.id, object: object, url: Pleroma.Web.Router.Helpers.o_status_url( @@ -184,6 +185,25 @@ defmodule Pleroma.Web.OStatus.OStatusController do end end + # Returns an HTML embedded