diff options
28 files changed, 285 insertions, 74 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a7ec1032..1c15cbe3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).  ### Fixed +- rel="me" was missing its cache +  ### Removed  ## 2.5.1 diff --git a/lib/mix/tasks/pleroma/openapi_spec.ex b/lib/mix/tasks/pleroma/openapi_spec.ex index 884f931f8..1ea468476 100644 --- a/lib/mix/tasks/pleroma/openapi_spec.ex +++ b/lib/mix/tasks/pleroma/openapi_spec.ex @@ -6,7 +6,70 @@ defmodule Mix.Tasks.Pleroma.OpenapiSpec do    def run([path]) do      # Load Pleroma application to get version info      Application.load(:pleroma) -    spec = Pleroma.Web.ApiSpec.spec(server_specific: false) |> Jason.encode!() -    File.write(path, spec) + +    spec_json = Pleroma.Web.ApiSpec.spec(server_specific: false) |> Jason.encode!() +    # to get rid of the structs +    spec_regened = spec_json |> Jason.decode!() + +    check_specs!(spec_regened) + +    File.write(path, spec_json) +  end + +  defp check_specs!(spec) do +    with :ok <- check_specs(spec) do +      :ok +    else +      {_, errors} -> +        IO.puts(IO.ANSI.format([:red, :bright, "Spec check failed, errors:"])) +        Enum.map(errors, &IO.puts/1) + +        raise "Spec check failed" +    end +  end + +  def check_specs(spec) do +    errors = +      spec["paths"] +      |> Enum.flat_map(fn {path, %{} = endpoints} -> +        Enum.map( +          endpoints, +          fn {method, endpoint} -> +            with :ok <- check_endpoint(spec, endpoint) do +              :ok +            else +              error -> +                "#{endpoint["operationId"]} (#{method} #{path}): #{error}" +            end +          end +        ) +        |> Enum.reject(fn res -> res == :ok end) +      end) + +    if errors == [] do +      :ok +    else +      {:error, errors} +    end +  end + +  defp check_endpoint(spec, endpoint) do +    valid_tags = available_tags(spec) + +    with {_, [_ | _] = tags} <- {:tags, endpoint["tags"]}, +         {_, []} <- {:unavailable, Enum.reject(tags, &(&1 in valid_tags))} do +      :ok +    else +      {:tags, _} -> +        "No tags specified" + +      {:unavailable, tags} -> +        "Tags #{inspect(tags)} not available. Please add it in \"x-tagGroups\" in Pleroma.Web.ApiSpec" +    end +  end + +  defp available_tags(spec) do +    spec["x-tagGroups"] +    |> Enum.flat_map(fn %{"tags" => tags} -> tags end)    end  end diff --git a/lib/pleroma/web/api_spec.ex b/lib/pleroma/web/api_spec.ex index cae4241ff..2d56dc643 100644 --- a/lib/pleroma/web/api_spec.ex +++ b/lib/pleroma/web/api_spec.ex @@ -95,7 +95,8 @@ defmodule Pleroma.Web.ApiSpec do                "Relays",                "Report managment",                "Status administration", -              "User administration" +              "User administration", +              "Announcement management"              ]            },            %{"name" => "Applications", "tags" => ["Applications", "Push subscriptions"]}, @@ -110,10 +111,12 @@ defmodule Pleroma.Web.ApiSpec do                "Follow requests",                "Mascot",                "Markers", -              "Notifications" +              "Notifications", +              "Filters", +              "Settings"              ]            }, -          %{"name" => "Instance", "tags" => ["Custom emojis"]}, +          %{"name" => "Instance", "tags" => ["Custom emojis", "Instance misc"]},            %{"name" => "Messaging", "tags" => ["Chats", "Conversations"]},            %{              "name" => "Statuses", @@ -125,10 +128,21 @@ defmodule Pleroma.Web.ApiSpec do                "Retrieve status information",                "Scheduled statuses",                "Search", -              "Status actions" +              "Status actions", +              "Media attachments"              ]            }, -          %{"name" => "Miscellaneous", "tags" => ["Emoji packs", "Reports", "Suggestions"]} +          %{ +            "name" => "Miscellaneous", +            "tags" => [ +              "Emoji packs", +              "Reports", +              "Suggestions", +              "Announcements", +              "Remote interaction", +              "Others" +            ] +          }          ]        }      } diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index aabe988f7..294590186 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -461,7 +461,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do    def lookup_operation do      %Operation{ -      tags: ["Account lookup"], +      tags: ["Retrieve account information"],        summary: "Find a user by nickname",        operationId: "AccountController.lookup",        parameters: [ diff --git a/lib/pleroma/web/api_spec/operations/admin/announcement_operation.ex b/lib/pleroma/web/api_spec/operations/admin/announcement_operation.ex index 58a039e72..49850e5d2 100644 --- a/lib/pleroma/web/api_spec/operations/admin/announcement_operation.ex +++ b/lib/pleroma/web/api_spec/operations/admin/announcement_operation.ex @@ -17,7 +17,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.AnnouncementOperation do    def index_operation do      %Operation{ -      tags: ["Announcement managment"], +      tags: ["Announcement management"],        summary: "Retrieve a list of announcements",        operationId: "AdminAPI.AnnouncementController.index",        security: [%{"oAuth" => ["admin:read"]}], @@ -46,7 +46,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.AnnouncementOperation do    def show_operation do      %Operation{ -      tags: ["Announcement managment"], +      tags: ["Announcement management"],        summary: "Display one announcement",        operationId: "AdminAPI.AnnouncementController.show",        security: [%{"oAuth" => ["admin:read"]}], @@ -69,7 +69,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.AnnouncementOperation do    def delete_operation do      %Operation{ -      tags: ["Announcement managment"], +      tags: ["Announcement management"],        summary: "Delete one announcement",        operationId: "AdminAPI.AnnouncementController.delete",        security: [%{"oAuth" => ["admin:write"]}], @@ -92,7 +92,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.AnnouncementOperation do    def create_operation do      %Operation{ -      tags: ["Announcement managment"], +      tags: ["Announcement management"],        summary: "Create one announcement",        operationId: "AdminAPI.AnnouncementController.create",        security: [%{"oAuth" => ["admin:write"]}], @@ -107,7 +107,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.AnnouncementOperation do    def change_operation do      %Operation{ -      tags: ["Announcement managment"], +      tags: ["Announcement management"],        summary: "Change one announcement",        operationId: "AdminAPI.AnnouncementController.change",        security: [%{"oAuth" => ["admin:write"]}], diff --git a/lib/pleroma/web/api_spec/operations/admin/status_operation.ex b/lib/pleroma/web/api_spec/operations/admin/status_operation.ex index 229912dd7..17383f1d0 100644 --- a/lib/pleroma/web/api_spec/operations/admin/status_operation.ex +++ b/lib/pleroma/web/api_spec/operations/admin/status_operation.ex @@ -70,7 +70,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.StatusOperation do    def show_operation do      %Operation{ -      tags: ["Status adminitration)"], +      tags: ["Status administration"],        summary: "Get status",        operationId: "AdminAPI.StatusController.show",        parameters: [id_param() | admin_api_params()], @@ -84,7 +84,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.StatusOperation do    def update_operation do      %Operation{ -      tags: ["Status adminitration)"], +      tags: ["Status administration"],        summary: "Change the scope of a status",        operationId: "AdminAPI.StatusController.update",        parameters: [id_param() | admin_api_params()], @@ -99,7 +99,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.StatusOperation do    def delete_operation do      %Operation{ -      tags: ["Status adminitration)"], +      tags: ["Status administration"],        summary: "Delete status",        operationId: "AdminAPI.StatusController.delete",        parameters: [id_param() | admin_api_params()], @@ -143,7 +143,7 @@ defmodule Pleroma.Web.ApiSpec.Admin.StatusOperation do            }          },          tags: %Schema{type: :string}, -        is_confirmed: %Schema{type: :string} +        is_confirmed: %Schema{type: :boolean}        }      }    end diff --git a/lib/pleroma/web/api_spec/operations/announcement_operation.ex b/lib/pleroma/web/api_spec/operations/announcement_operation.ex index 71be0002a..6f7031962 100644 --- a/lib/pleroma/web/api_spec/operations/announcement_operation.ex +++ b/lib/pleroma/web/api_spec/operations/announcement_operation.ex @@ -15,7 +15,7 @@ defmodule Pleroma.Web.ApiSpec.AnnouncementOperation do    def index_operation do      %Operation{ -      tags: ["Announcement"], +      tags: ["Announcements"],        summary: "Retrieve a list of announcements",        operationId: "MastodonAPI.AnnouncementController.index",        security: [%{"oAuth" => []}], @@ -28,7 +28,7 @@ defmodule Pleroma.Web.ApiSpec.AnnouncementOperation do    def mark_read_operation do      %Operation{ -      tags: ["Announcement"], +      tags: ["Announcements"],        summary: "Mark one announcement as read",        operationId: "MastodonAPI.AnnouncementController.mark_read",        security: [%{"oAuth" => ["write:accounts"]}], diff --git a/lib/pleroma/web/api_spec/operations/directory_operation.ex b/lib/pleroma/web/api_spec/operations/directory_operation.ex index 55752fa62..23fa84dff 100644 --- a/lib/pleroma/web/api_spec/operations/directory_operation.ex +++ b/lib/pleroma/web/api_spec/operations/directory_operation.ex @@ -17,7 +17,7 @@ defmodule Pleroma.Web.ApiSpec.DirectoryOperation do    def index_operation do      %Operation{ -      tags: ["Directory"], +      tags: ["Others"],        summary: "Profile directory",        operationId: "DirectoryController.index",        parameters: diff --git a/lib/pleroma/web/api_spec/operations/instance_operation.ex b/lib/pleroma/web/api_spec/operations/instance_operation.ex index 3c4b504fe..a07be7e40 100644 --- a/lib/pleroma/web/api_spec/operations/instance_operation.ex +++ b/lib/pleroma/web/api_spec/operations/instance_operation.ex @@ -13,7 +13,7 @@ defmodule Pleroma.Web.ApiSpec.InstanceOperation do    def show_operation do      %Operation{ -      tags: ["Instance"], +      tags: ["Instance misc"],        summary: "Retrieve instance information",        description: "Information about the server",        operationId: "InstanceController.show", @@ -25,7 +25,7 @@ defmodule Pleroma.Web.ApiSpec.InstanceOperation do    def peers_operation do      %Operation{ -      tags: ["Instance"], +      tags: ["Instance misc"],        summary: "Retrieve list of known instances",        operationId: "InstanceController.peers",        responses: %{ diff --git a/lib/pleroma/web/api_spec/operations/pleroma_emoji_file_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_emoji_file_operation.ex index d09c1c10e..b05bad197 100644 --- a/lib/pleroma/web/api_spec/operations/pleroma_emoji_file_operation.ex +++ b/lib/pleroma/web/api_spec/operations/pleroma_emoji_file_operation.ex @@ -133,7 +133,11 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do    defp files_object do      %Schema{        type: :object, -      additionalProperties: %Schema{type: :string}, +      additionalProperties: %Schema{ +        type: :string, +        description: "Filename of the emoji", +        extensions: %{"x-additionalPropertiesName": "Emoji name"} +      },        description: "Object with emoji names as keys and filenames as values"      }    end diff --git a/lib/pleroma/web/api_spec/operations/pleroma_emoji_pack_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_emoji_pack_operation.ex index 6add3ff33..efa36ffdc 100644 --- a/lib/pleroma/web/api_spec/operations/pleroma_emoji_pack_operation.ex +++ b/lib/pleroma/web/api_spec/operations/pleroma_emoji_pack_operation.ex @@ -227,13 +227,29 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiPackOperation do    defp emoji_packs_response do      Operation.response( -      "Object with pack names as keys and pack contents as values", +      "Emoji packs and the count",        "application/json",        %Schema{          type: :object, -        additionalProperties: emoji_pack(), +        properties: %{ +          packs: %Schema{ +            type: :object, +            description: "Object with pack names as keys and pack contents as values", +            additionalProperties: %Schema{ +              emoji_pack() +              | extensions: %{"x-additionalPropertiesName": "Pack name"} +            } +          }, +          count: %Schema{ +            type: :integer, +            description: "Number of emoji packs" +          } +        },          example: %{ -          "emojos" => emoji_pack().example +          "packs" => %{ +            "emojos" => emoji_pack().example +          }, +          "count" => 1          }        }      ) @@ -274,7 +290,11 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiPackOperation do    defp files_object do      %Schema{        type: :object, -      additionalProperties: %Schema{type: :string}, +      additionalProperties: %Schema{ +        type: :string, +        description: "Filename", +        extensions: %{"x-additionalPropertiesName": "Emoji name"} +      },        description: "Object with emoji names as keys and filenames as values"      }    end diff --git a/lib/pleroma/web/api_spec/operations/pleroma_instances_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_instances_operation.ex index 82db4e1a8..e9319f3fb 100644 --- a/lib/pleroma/web/api_spec/operations/pleroma_instances_operation.ex +++ b/lib/pleroma/web/api_spec/operations/pleroma_instances_operation.ex @@ -13,7 +13,7 @@ defmodule Pleroma.Web.ApiSpec.PleromaInstancesOperation do    def show_operation do      %Operation{ -      tags: ["Instance"], +      tags: ["Instance misc"],        summary: "Retrieve federation status",        description: "Information about instances deemed unreachable by the server",        operationId: "PleromaInstances.show", diff --git a/lib/pleroma/web/api_spec/operations/status_operation.ex b/lib/pleroma/web/api_spec/operations/status_operation.ex index e921128c7..5d6e82f3c 100644 --- a/lib/pleroma/web/api_spec/operations/status_operation.ex +++ b/lib/pleroma/web/api_spec/operations/status_operation.ex @@ -440,7 +440,7 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do    def show_history_operation do      %Operation{ -      tags: ["Retrieve status history"], +      tags: ["Retrieve status information"],        summary: "Status history",        description: "View history of a status",        operationId: "StatusController.show_history", @@ -457,7 +457,7 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do    def show_source_operation do      %Operation{ -      tags: ["Retrieve status source"], +      tags: ["Retrieve status information"],        summary: "Status source",        description: "View source of a status",        operationId: "StatusController.show_source", @@ -474,7 +474,7 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do    def update_operation do      %Operation{ -      tags: ["Update status"], +      tags: ["Status actions"],        summary: "Update status",        description: "Change the content of a status",        operationId: "StatusController.update", diff --git a/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex b/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex index 29df03e34..084329ad7 100644 --- a/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex +++ b/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex @@ -17,7 +17,7 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do    def emoji_operation do      %Operation{ -      tags: ["Emojis"], +      tags: ["Custom emojis"],        summary: "List all custom emojis",        operationId: "UtilController.emoji",        parameters: [], @@ -30,7 +30,8 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do                properties: %{                  image_url: %Schema{type: :string},                  tags: %Schema{type: :array, items: %Schema{type: :string}} -              } +              }, +              extensions: %{"x-additionalPropertiesName": "Emoji name"}              },              example: %{                "firefox" => %{ @@ -45,7 +46,7 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do    def frontend_configurations_operation do      %Operation{ -      tags: ["Configuration"], +      tags: ["Others"],        summary: "Dump frontend configurations",        operationId: "UtilController.frontend_configurations",        parameters: [], @@ -53,7 +54,12 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do          200 =>            Operation.response("List", "application/json", %Schema{              type: :object, -            additionalProperties: %Schema{type: :object} +            additionalProperties: %Schema{ +              type: :object, +              description: +                "Opaque object representing the instance-wide configuration for the frontend", +              extensions: %{"x-additionalPropertiesName": "Frontend name"} +            }            })        }      } @@ -132,7 +138,7 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do    def update_notificaton_settings_operation do      %Operation{ -      tags: ["Accounts"], +      tags: ["Settings"],        summary: "Update Notification Settings",        security: [%{"oAuth" => ["write:accounts"]}],        operationId: "UtilController.update_notificaton_settings", @@ -207,6 +213,7 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do      %Operation{        summary: "Get a captcha",        operationId: "UtilController.captcha", +      tags: ["Others"],        parameters: [],        responses: %{          200 => Operation.response("Success", "application/json", %Schema{type: :object}) @@ -356,7 +363,7 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do    def healthcheck_operation do      %Operation{ -      tags: ["Accounts"], +      tags: ["Others"],        summary: "Quick status check on the instance",        security: [%{"oAuth" => ["write:accounts"]}],        operationId: "UtilController.healthcheck", @@ -371,7 +378,7 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do    def remote_subscribe_operation do      %Operation{ -      tags: ["Accounts"], +      tags: ["Remote interaction"],        summary: "Remote Subscribe",        operationId: "UtilController.remote_subscribe",        parameters: [], @@ -381,7 +388,7 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do    def remote_interaction_operation do      %Operation{ -      tags: ["Accounts"], +      tags: ["Remote interaction"],        summary: "Remote interaction",        operationId: "UtilController.remote_interaction",        requestBody: request_body("Parameters", remote_interaction_request(), required: true), @@ -407,7 +414,7 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do    def show_subscribe_form_operation do      %Operation{ -      tags: ["Accounts"], +      tags: ["Remote interaction"],        summary: "Show remote subscribe form",        operationId: "UtilController.show_subscribe_form",        parameters: [], diff --git a/lib/pleroma/web/api_spec/schemas/status.ex b/lib/pleroma/web/api_spec/schemas/status.ex index 698f11794..bc29cf4a6 100644 --- a/lib/pleroma/web/api_spec/schemas/status.ex +++ b/lib/pleroma/web/api_spec/schemas/status.ex @@ -144,7 +144,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do          properties: %{            content: %Schema{              type: :object, -            additionalProperties: %Schema{type: :string}, +            additionalProperties: %Schema{ +              type: :string, +              description: "Alternate representation in the MIME type specified", +              extensions: %{"x-additionalPropertiesName": "MIME type"} +            },              description:                "A map consisting of alternate representations of the `content` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`"            }, @@ -195,7 +199,11 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do            },            spoiler_text: %Schema{              type: :object, -            additionalProperties: %Schema{type: :string}, +            additionalProperties: %Schema{ +              type: :string, +              description: "Alternate representation in the MIME type specified", +              extensions: %{"x-additionalPropertiesName": "MIME type"} +            },              description:                "A map consisting of alternate representations of the `spoiler_text` property with the key being it's mimetype. Currently the only alternate representation supported is `text/plain`."            }, diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index ea6e593d9..02dfc552f 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -269,14 +269,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do    end    defp normalize_fields_attributes(fields) do -    if Enum.all?(fields, &is_tuple/1) do -      Enum.map(fields, fn {_, v} -> v end) -    else -      Enum.map(fields, fn -        %{} = field -> %{"name" => field.name, "value" => field.value} -        field -> field -      end) -    end +    if(Enum.all?(fields, &is_tuple/1), do: Enum.map(fields, fn {_, v} -> v end), else: fields) +    |> Enum.map(fn +      %{} = field -> %{"name" => field.name, "value" => field.value} +      field -> field +    end)    end    @doc "GET /api/v1/accounts/relationships" @@ -4,7 +4,7 @@ defmodule Pleroma.Mixfile do    def project do      [        app: :pleroma, -      version: version("2.5.1"), +      version: version("2.5.51"),        elixir: "~> 1.11",        elixirc_paths: elixirc_paths(Mix.env()),        compilers: [:phoenix, :gettext] ++ Mix.compilers(), @@ -194,7 +194,7 @@ defmodule Pleroma.Mixfile do        {:restarter, path: "./restarter"},        {:majic, "~> 1.0"},        {:eblurhash, "~> 1.2.2"}, -      {:open_api_spex, "~> 3.10"}, +      {:open_api_spex, "~> 3.16"},        {:ecto_psql_extras, "~> 0.6"},        # indirect dependency version override @@ -83,7 +83,7 @@    "nimble_pool": {:hex, :nimble_pool, "0.2.6", "91f2f4c357da4c4a0a548286c84a3a28004f68f05609b4534526871a22053cde", [:mix], [], "hexpm", "1c715055095d3f2705c4e236c18b618420a35490da94149ff8b580a2144f653f"},    "nodex": {:git, "https://git.pleroma.social/pleroma/nodex", "cb6730f943cfc6aad674c92161be23a8411f15d1", [ref: "cb6730f943cfc6aad674c92161be23a8411f15d1"]},    "oban": {:hex, :oban, "2.13.4", "b4c4f48f4c89cc01036670eefa28aa9c03d09aadd402655475b936983d597006", [:mix], [{:ecto_sql, "~> 3.6", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a7d26f82b409e2d7928fbb75a17716e06ad3f783ebe9af260e3dd23abed7f124"}, -  "open_api_spex": {:hex, :open_api_spex, "3.10.0", "94e9521ad525b3fcf6dc77da7c45f87fdac24756d4de588cb0816b413e7c1844", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 3.1", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm", "2dbb2bde3d2b821f06936e8dfaf3284331186556291946d84eeba3750ac28765"}, +  "open_api_spex": {:hex, :open_api_spex, "3.16.0", "9843af4e87550cd8ac5821b10e4c74f1d51f0d4e3310f824d780614743423b25", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 3.0 or ~> 4.0 or ~> 5.0", [hex: :poison, repo: "hexpm", optional: true]}, {:ymlr, "~> 2.0 or ~> 3.0", [hex: :ymlr, repo: "hexpm", optional: true]}], "hexpm", "bb0be24a648b73e8fc8cbda17f514b8486262275e8b33e8b5ae66283df972129"},    "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},    "pbkdf2_elixir": {:hex, :pbkdf2_elixir, "1.2.1", "9cbe354b58121075bd20eb83076900a3832324b7dd171a6895fab57b6bb2752c", [:mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}], "hexpm", "d3b40a4a4630f0b442f19eca891fcfeeee4c40871936fed2f68e1c4faa30481f"},    "phoenix": {:hex, :phoenix, "1.6.15", "0a1d96bbc10747fd83525370d691953cdb6f3ccbac61aa01b4acb012474b047d", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d70ab9fbf6b394755ea88b644d34d79d8b146e490973151f248cacd122d20672"}, diff --git a/priv/gettext/config_descriptions.pot b/priv/gettext/config_descriptions.pot index 1c3a98d3e..53b81fa41 100644 --- a/priv/gettext/config_descriptions.pot +++ b/priv/gettext/config_descriptions.pot @@ -1914,12 +1914,6 @@ msgstr ""  #, elixir-autogen, elixir-format  #: lib/pleroma/docs/translator.ex:5 -msgctxt "config description at :pleroma-:instance > :privileged_staff" -msgid "Let moderators access sensitive data (e.g. updating user credentials, get password reset token, delete users, index and read private statuses and chats)" -msgstr "" - -#, elixir-autogen, elixir-format -#: lib/pleroma/docs/translator.ex:5  msgctxt "config description at :pleroma-:instance > :profile_directory"  msgid "Enable profile directory."  msgstr "" @@ -4326,12 +4320,6 @@ msgstr ""  #, elixir-autogen, elixir-format  #: lib/pleroma/docs/translator.ex:5 -msgctxt "config label at :pleroma-:instance > :privileged_staff" -msgid "Privileged staff" -msgstr "" - -#, elixir-autogen, elixir-format -#: lib/pleroma/docs/translator.ex:5  msgctxt "config label at :pleroma-:instance > :profile_directory"  msgid "Profile directory"  msgstr "" @@ -6021,3 +6009,39 @@ msgstr ""  msgctxt "config label at :pleroma-:instance > :report_strip_status"  msgid "Report strip status"  msgstr "" + +#, elixir-autogen, elixir-format +#: lib/pleroma/docs/translator.ex:5 +msgctxt "config description at :pleroma-:instance > :admin_privileges" +msgid "What extra privileges to allow admins (e.g. updating user credentials, get password reset token, delete users, index and read private statuses and chats)" +msgstr "" + +#, elixir-autogen, elixir-format +#: lib/pleroma/docs/translator.ex:5 +msgctxt "config description at :pleroma-:instance > :moderator_privileges" +msgid "What extra privileges to allow moderators (e.g. updating user credentials, get password reset token, delete users, index and read private statuses and chats)" +msgstr "" + +#, elixir-autogen, elixir-format +#: lib/pleroma/docs/translator.ex:5 +msgctxt "config label at :pleroma-:instance > :admin_privileges" +msgid "Admin privileges" +msgstr "" + +#, elixir-autogen, elixir-format +#: lib/pleroma/docs/translator.ex:5 +msgctxt "config label at :pleroma-:instance > :moderator_privileges" +msgid "Moderator privileges" +msgstr "" + +#, elixir-autogen, elixir-format +#: lib/pleroma/docs/translator.ex:5 +msgctxt "config description at :pleroma-:instance > :languages" +msgid "Languages to be exposed in /api/v1/instance. Should be in the format of BCP47 language codes." +msgstr "" + +#, elixir-autogen, elixir-format +#: lib/pleroma/docs/translator.ex:5 +msgctxt "config label at :pleroma-:instance > :languages" +msgid "Languages" +msgstr "" diff --git a/priv/gettext/errors.pot b/priv/gettext/errors.pot index 19a0039ca..fa61d509e 100644 --- a/priv/gettext/errors.pot +++ b/priv/gettext/errors.pot @@ -111,7 +111,7 @@ msgid "Can't display this activity"  msgstr ""  #, elixir-autogen, elixir-format -#: lib/pleroma/web/mastodon_api/controllers/account_controller.ex:337 +#: lib/pleroma/web/mastodon_api/controllers/account_controller.ex:334  msgid "Can't find user"  msgstr "" @@ -236,7 +236,7 @@ msgid "Poll's author can't vote"  msgstr ""  #, elixir-autogen, elixir-format -#: lib/pleroma/web/mastodon_api/controllers/account_controller.ex:502 +#: lib/pleroma/web/mastodon_api/controllers/account_controller.ex:499  #: lib/pleroma/web/mastodon_api/controllers/fallback_controller.ex:20  #: lib/pleroma/web/mastodon_api/controllers/poll_controller.ex:39  #: lib/pleroma/web/mastodon_api/controllers/poll_controller.ex:51 @@ -558,12 +558,11 @@ msgid "Access denied"  msgstr ""  #, elixir-autogen, elixir-format -#: lib/pleroma/web/mastodon_api/controllers/account_controller.ex:334 +#: lib/pleroma/web/mastodon_api/controllers/account_controller.ex:331  msgid "This API requires an authenticated user"  msgstr ""  #, elixir-autogen, elixir-format -#: lib/pleroma/web/plugs/ensure_staff_privileged_plug.ex:26  #: lib/pleroma/web/plugs/user_is_admin_plug.ex:21  msgid "User is not an admin."  msgstr "" @@ -586,7 +585,6 @@ msgid "Too many attachments"  msgstr ""  #, elixir-autogen, elixir-format -#: lib/pleroma/web/plugs/ensure_staff_privileged_plug.ex:33  #: lib/pleroma/web/plugs/user_is_staff_plug.ex:20  msgid "User is not a staff member."  msgstr "" @@ -602,3 +600,10 @@ msgstr ""  #: lib/pleroma/web/mastodon_api/controllers/account_controller.ex:264  msgid "File is too large"  msgstr "" + +#, elixir-autogen, elixir-format +#: lib/pleroma/web/plugs/ensure_privileged_plug.ex:21 +#: lib/pleroma/web/plugs/ensure_privileged_plug.ex:34 +#: lib/pleroma/web/plugs/ensure_privileged_plug.ex:41 +msgid "User isn't privileged." +msgstr "" diff --git a/test/mix/tasks/pleroma/openapi_spec_test.exs b/test/mix/tasks/pleroma/openapi_spec_test.exs new file mode 100644 index 000000000..01437187a --- /dev/null +++ b/test/mix/tasks/pleroma/openapi_spec_test.exs @@ -0,0 +1,62 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Mix.Tasks.Pleroma.OpenapiSpecTest do +  use Pleroma.DataCase, async: true + +  alias Mix.Tasks.Pleroma.OpenapiSpec + +  @spec_base %{ +    "paths" => %{ +      "/cofe" => %{ +        "get" => %{ +          "operationId" => "Some.operation", +          "tags" => [] +        } +      }, +      "/mew" => %{ +        "post" => %{ +          "operationId" => "Another.operation", +          "tags" => ["mew mew"] +        } +      } +    }, +    "x-tagGroups" => [ +      %{ +        "name" => "mew", +        "tags" => ["mew mew", "abc"] +      }, +      %{ +        "name" => "lol", +        "tags" => ["lol lol", "xyz"] +      } +    ] +  } + +  describe "check_specs/1" do +    test "Every operation must have a tag" do +      assert {:error, ["Some.operation (get /cofe): No tags specified"]} == +               OpenapiSpec.check_specs(@spec_base) +    end + +    test "Every tag must be in tag groups" do +      spec = +        @spec_base +        |> put_in(["paths", "/cofe", "get", "tags"], ["abc", "def", "not specified"]) + +      assert {:error, +              [ +                "Some.operation (get /cofe): Tags #{inspect(["def", "not specified"])} not available. Please add it in \"x-tagGroups\" in Pleroma.Web.ApiSpec" +              ]} == OpenapiSpec.check_specs(spec) +    end + +    test "No errors if ok" do +      spec = +        @spec_base +        |> put_in(["paths", "/cofe", "get", "tags"], ["abc", "mew mew"]) + +      assert :ok == OpenapiSpec.check_specs(spec) +    end +  end +end diff --git a/test/pleroma/user/import_test.exs b/test/pleroma/user/import_test.exs index b4efd4bb0..f75305e0e 100644 --- a/test/pleroma/user/import_test.exs +++ b/test/pleroma/user/import_test.exs @@ -3,7 +3,6 @@  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.User.ImportTest do -  alias Pleroma.Repo    alias Pleroma.Tests.ObanHelpers    alias Pleroma.User diff --git a/test/pleroma/user_search_test.exs b/test/pleroma/user_search_test.exs index 1deab6888..1af9a1493 100644 --- a/test/pleroma/user_search_test.exs +++ b/test/pleroma/user_search_test.exs @@ -3,7 +3,6 @@  # SPDX-License-Identifier: AGPL-3.0-only  defmodule Pleroma.UserSearchTest do -  alias Pleroma.Repo    alias Pleroma.User    use Pleroma.DataCase diff --git a/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs index 9d99df27c..83bf59c6f 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs @@ -65,7 +65,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do      object = Object.get_by_ap_id(data["object"])      assert object.data["reaction_count"] == 1 -    assert match?([[emoji, _]], object.data["reactions"]) +    assert match?([[^emoji, _]], object.data["reactions"])    end    test "it reject invalid emoji reactions" do diff --git a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs index 7c406fbd0..a9ad3e9c8 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs @@ -104,6 +104,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do        end      end +    @tag capture_log: true      test "it does not crash if the object in inReplyTo can't be fetched" do        data =          File.read!("test/fixtures/mastodon-post-activity.json") @@ -723,6 +724,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do      assert modified.data["context"] == object.data["id"]    end +  @tag capture_log: true    test "the reply note uses its parent's ID when context is missing and reply is unreachable" do      insert(:user, ap_id: "https://mk.absturztau.be/users/8ozbzjs3o8") diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs index 9ef7c0c46..9fb5fb520 100644 --- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs @@ -316,6 +316,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do        assert Application.get_env(:idna, :key5) == {"string", Pleroma.Captcha.NotReal, []}      end +    @tag capture_log: true      test "save configs setting without explicit key", %{conn: conn} do        adapter = Application.get_env(:http, :adapter)        send_user_agent = Application.get_env(:http, :send_user_agent) diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index 57fa0f047..6c63d53c2 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -375,7 +375,9 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do            "pleroma_background_image" => new_background_oversized          }) -      assert user_response = json_response_and_validate_schema(res, 413) +      assert %{"error" => "File is too large"} == json_response_and_validate_schema(res, 413) + +      user = Repo.get(User, user.id)        assert user.background == %{}        clear_config([:instance, :upload_limit], upload_limit) diff --git a/test/test_helper.exs b/test/test_helper.exs index 60a61484f..7727cffbc 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -2,6 +2,8 @@  # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only +Code.put_compiler_option(:warnings_as_errors, true) +  os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: []  ExUnit.start(exclude: [:federated, :erratic] ++ os_exclude)  | 
