Merge branch 'feat/client_app_details' into 'develop'
authorlain <lain@soykaf.club>
Sun, 28 Feb 2021 16:17:34 +0000 (16:17 +0000)
committerlain <lain@soykaf.club>
Sun, 28 Feb 2021 16:17:34 +0000 (16:17 +0000)
Support application field

See merge request pleroma/pleroma!3311

1  2 
CHANGELOG.md
test/pleroma/web/mastodon_api/controllers/status_controller_test.exs

diff --combined CHANGELOG.md
index 508a6ea1543277d00174bcdf4a2d4708084b9d02,69b9e2c5299e78f020d1297128e1c6bd1582cc58..c4837c9553b763cbaa458ae710e8a003e7e00f4b
@@@ -6,10 -6,6 +6,10 @@@ The format is based on [Keep a Changelo
  
  ## Unreleased
  
 +### Removed
 +
 +- `:auth, :enforce_oauth_admin_scope_usage` configuration option.
 +
  ### Changed
  
  - **Breaking**: Changed `mix pleroma.user toggle_confirmed` to `mix pleroma.user confirm`
@@@ -25,7 -21,6 +25,7 @@@
  - Provide redirect of external posts from `/notice/:id` to their original URL
  - Admins no longer receive notifications for reports if they are the actor making the report.
  - Improved Mailer configuration setting descriptions for AdminFE.
 +- Updated default avatar to look nicer.
  
  <details>
    <summary>API Changes</summary>
@@@ -36,7 -31,6 +36,7 @@@
  - **Breaking:** AdminAPI `GET /api/pleroma/admin/users/:nickname_or_id/statuses` changed response format and added the number of total users posts.
  - **Breaking:** AdminAPI `GET /api/pleroma/admin/instances/:instance/statuses` changed response format and added the number of total users posts.
  - Admin API: Reports now ordered by newest
 +- Pleroma API: `GET /api/v1/pleroma/chats` is deprecated in favor of `GET /api/v2/pleroma/chats`.
  
  </details>
  
  - Ability to define custom HTTP headers per each frontend
  - MRF (`NoEmptyPolicy`): New MRF Policy which will deny empty statuses or statuses of only mentions from being created by local users
  - New users will receive a simple email confirming their registration if no other emails will be dispatched. (e.g., Welcome, Confirmation, or Approval Required)
+ - The `application` metadata returned with statuses is no longer hardcoded. Apps that want to display these details will now have valid data for new posts after this change.
  
  <details>
    <summary>API Changes</summary>
  - Admin API: (`GET /api/pleroma/admin/users`) filter users by `unconfirmed` status and `actor_type`.
 +- Pleroma API: `GET /api/v2/pleroma/chats` added. It is exactly like `GET /api/v1/pleroma/chats` except supports pagination.
  - Pleroma API: Add `idempotency_key` to the chat message entity that can be used for optimistic message sending.
  - Pleroma API: (`GET /api/v1/pleroma/federation_status`) Add a way to get a list of unreachable instances.
  - Mastodon API: User and conversation mutes can now auto-expire if `expires_in` parameter was given while adding the mute.
@@@ -73,8 -67,6 +74,8 @@@
  - Mastodon API: Add monthly active users to `/api/v1/instance` (`pleroma.stats.mau`).
  - Mastodon API: Home, public, hashtag & list timelines accept `only_media`, `remote` & `local` parameters for filtration.
  - Mastodon API: `/api/v1/accounts/:id` & `/api/v1/mutes` endpoints accept `with_relationships` parameter and return filled `pleroma.relationship` field.
 +- Mastodon API: Endpoint to remove a conversation (`DELETE /api/v1/conversations/:id`).
 +- Mastodon API: `expires_in` in the scheduled post `params` field on `/api/v1/statuses` and `/api/v1/scheduled_statuses/:id` endpoints.
  </details>
  
  ### Fixed
index c59b156bf44c929430922dbb5b66acdff4e5a67d,bae2ad4bfad19f242cf4f63b957919f8a4ab9039..dd2f306b793e2d5a5af936464fbb6e00b671d897
@@@ -357,6 -357,50 +357,50 @@@ defmodule Pleroma.Web.MastodonAPI.Statu
        assert activity.data["to"] == [user2.ap_id]
        assert activity.data["cc"] == []
      end
+     test "discloses application metadata when enabled" do
+       user = insert(:user, disclose_client: true)
+       %{user: _user, token: token, conn: conn} = oauth_access(["write:statuses"], user: user)
+       %Pleroma.Web.OAuth.Token{
+         app: %Pleroma.Web.OAuth.App{
+           client_name: _app_name,
+           website: _app_website
+         }
+       } = token
+       result =
+         conn
+         |> put_req_header("content-type", "application/json")
+         |> post("/api/v1/statuses", %{
+           "status" => "cofe is my copilot"
+         })
+       assert %{
+                "content" => "cofe is my copilot",
+                "application" => %{
+                  "name" => app_name,
+                  "website" => app_website
+                }
+              } = json_response_and_validate_schema(result, 200)
+     end
+     test "hides application metadata when disabled" do
+       user = insert(:user, disclose_client: false)
+       %{user: _user, token: _token, conn: conn} = oauth_access(["write:statuses"], user: user)
+       result =
+         conn
+         |> put_req_header("content-type", "application/json")
+         |> post("/api/v1/statuses", %{
+           "status" => "club mate is my wingman"
+         })
+       assert %{
+                "content" => "club mate is my wingman",
+                "application" => nil
+              } = json_response_and_validate_schema(result, 200)
+     end
    end
  
    describe "posting scheduled statuses" do
        assert [] == Repo.all(Activity)
      end
  
 +    test "with expiration" do
 +      %{conn: conn} = oauth_access(["write:statuses", "read:statuses"])
 +
 +      scheduled_at =
 +        NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(6), :millisecond)
 +        |> NaiveDateTime.to_iso8601()
 +        |> Kernel.<>("Z")
 +
 +      assert %{"id" => status_id, "params" => %{"expires_in" => 300}} =
 +               conn
 +               |> put_req_header("content-type", "application/json")
 +               |> post("/api/v1/statuses", %{
 +                 "status" => "scheduled",
 +                 "scheduled_at" => scheduled_at,
 +                 "expires_in" => 300
 +               })
 +               |> json_response_and_validate_schema(200)
 +
 +      assert %{"id" => ^status_id, "params" => %{"expires_in" => 300}} =
 +               conn
 +               |> put_req_header("content-type", "application/json")
 +               |> get("/api/v1/scheduled_statuses/#{status_id}")
 +               |> json_response_and_validate_schema(200)
 +    end
 +
      test "ignores nil values", %{conn: conn} do
        conn =
          conn