forked from AkkomaGang/akkoma
Merge branch 'feature/admin-api-user-statuses' into 'develop'
Admin API: Endpoint for fetching latest user's statuses See merge request pleroma/pleroma!1413
This commit is contained in:
commit
9c6357324e
7 changed files with 110 additions and 6 deletions
|
@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Federation: Return 403 errors when trying to request pages from a user's follower/following collections if they have `hide_followers`/`hide_follows` set
|
- Federation: Return 403 errors when trying to request pages from a user's follower/following collections if they have `hide_followers`/`hide_follows` set
|
||||||
- NodeInfo: Return `skipThreadContainment` in `metadata` for the `skip_thread_containment` option
|
- NodeInfo: Return `skipThreadContainment` in `metadata` for the `skip_thread_containment` option
|
||||||
- Mastodon API: Unsubscribe followers when they unfollow a user
|
- Mastodon API: Unsubscribe followers when they unfollow a user
|
||||||
|
- AdminAPI: Add "godmode" while fetching user statuses (i.e. admin can see private statuses)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Not being able to pin unlisted posts
|
- Not being able to pin unlisted posts
|
||||||
|
@ -54,6 +55,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Twitter API: added rate limit for `/api/account/password_reset` endpoint.
|
- Twitter API: added rate limit for `/api/account/password_reset` endpoint.
|
||||||
- ActivityPub: Add an internal service actor for fetching ActivityPub objects.
|
- ActivityPub: Add an internal service actor for fetching ActivityPub objects.
|
||||||
- ActivityPub: Optional signing of ActivityPub object fetches.
|
- ActivityPub: Optional signing of ActivityPub object fetches.
|
||||||
|
- Admin API: Endpoint for fetching latest user's statuses
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Configuration: Filter.AnonymizeFilename added ability to retain file extension with custom text
|
- Configuration: Filter.AnonymizeFilename added ability to retain file extension with custom text
|
||||||
|
|
|
@ -187,6 +187,19 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
- On failure: `Not found`
|
- On failure: `Not found`
|
||||||
- On success: JSON of the user
|
- On success: JSON of the user
|
||||||
|
|
||||||
|
## `/api/pleroma/admin/users/:nickname_or_id/statuses`
|
||||||
|
|
||||||
|
### Retrive user's latest statuses
|
||||||
|
|
||||||
|
- Method: `GET`
|
||||||
|
- Params:
|
||||||
|
- `nickname` or `id`
|
||||||
|
- *optional* `page_size`: number of statuses to return (default is `20`)
|
||||||
|
- *optional* `godmode`: `true`/`false` – allows to see private statuses
|
||||||
|
- Response:
|
||||||
|
- On failure: `Not found`
|
||||||
|
- On success: JSON array of user's latest statuses
|
||||||
|
|
||||||
## `/api/pleroma/admin/relay`
|
## `/api/pleroma/admin/relay`
|
||||||
|
|
||||||
### Follow a Relay
|
### Follow a Relay
|
||||||
|
|
|
@ -631,15 +631,26 @@ def fetch_user_activities(user, reading_user, params \\ %{}) do
|
||||||
|> Map.put("pinned_activity_ids", user.info.pinned_activities)
|
|> Map.put("pinned_activity_ids", user.info.pinned_activities)
|
||||||
|
|
||||||
recipients =
|
recipients =
|
||||||
|
user_activities_recipients(%{
|
||||||
|
"godmode" => params["godmode"],
|
||||||
|
"reading_user" => reading_user
|
||||||
|
})
|
||||||
|
|
||||||
|
fetch_activities(recipients, params)
|
||||||
|
|> Enum.reverse()
|
||||||
|
end
|
||||||
|
|
||||||
|
defp user_activities_recipients(%{"godmode" => true}) do
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
|
defp user_activities_recipients(%{"reading_user" => reading_user}) do
|
||||||
if reading_user do
|
if reading_user do
|
||||||
["https://www.w3.org/ns/activitystreams#Public"] ++
|
["https://www.w3.org/ns/activitystreams#Public"] ++
|
||||||
[reading_user.ap_id | reading_user.following]
|
[reading_user.ap_id | reading_user.following]
|
||||||
else
|
else
|
||||||
["https://www.w3.org/ns/activitystreams#Public"]
|
["https://www.w3.org/ns/activitystreams#Public"]
|
||||||
end
|
end
|
||||||
|
|
||||||
fetch_activities(recipients, params)
|
|
||||||
|> Enum.reverse()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp restrict_since(query, %{"since_id" => ""}), do: query
|
defp restrict_since(query, %{"since_id" => ""}), do: query
|
||||||
|
|
|
@ -82,6 +82,25 @@ def user_show(conn, %{"nickname" => nickname}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def list_user_statuses(conn, %{"nickname" => nickname} = params) do
|
||||||
|
godmode = params["godmode"] == "true" || params["godmode"] == true
|
||||||
|
|
||||||
|
with %User{} = user <- User.get_cached_by_nickname_or_id(nickname) do
|
||||||
|
{_, page_size} = page_params(params)
|
||||||
|
|
||||||
|
activities =
|
||||||
|
ActivityPub.fetch_user_activities(user, nil, %{
|
||||||
|
"limit" => page_size,
|
||||||
|
"godmode" => godmode
|
||||||
|
})
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> json(StatusView.render("index.json", %{activities: activities, as: :activity}))
|
||||||
|
else
|
||||||
|
_ -> {:error, :not_found}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def user_toggle_activation(conn, %{"nickname" => nickname}) do
|
def user_toggle_activation(conn, %{"nickname" => nickname}) do
|
||||||
user = User.get_cached_by_nickname(nickname)
|
user = User.get_cached_by_nickname(nickname)
|
||||||
|
|
||||||
|
|
|
@ -184,6 +184,7 @@ defmodule Pleroma.Web.Router do
|
||||||
|
|
||||||
get("/users", AdminAPIController, :list_users)
|
get("/users", AdminAPIController, :list_users)
|
||||||
get("/users/:nickname", AdminAPIController, :user_show)
|
get("/users/:nickname", AdminAPIController, :user_show)
|
||||||
|
get("/users/:nickname/statuses", AdminAPIController, :list_user_statuses)
|
||||||
|
|
||||||
get("/reports", AdminAPIController, :list_reports)
|
get("/reports", AdminAPIController, :list_reports)
|
||||||
get("/reports/:id", AdminAPIController, :report_show)
|
get("/reports/:id", AdminAPIController, :report_show)
|
||||||
|
|
|
@ -118,6 +118,7 @@ def direct_note_activity_factory do
|
||||||
def note_activity_factory(attrs \\ %{}) do
|
def note_activity_factory(attrs \\ %{}) do
|
||||||
user = attrs[:user] || insert(:user)
|
user = attrs[:user] || insert(:user)
|
||||||
note = attrs[:note] || insert(:note, user: user)
|
note = attrs[:note] || insert(:note, user: user)
|
||||||
|
|
||||||
data_attrs = attrs[:data_attrs] || %{}
|
data_attrs = attrs[:data_attrs] || %{}
|
||||||
attrs = Map.drop(attrs, [:user, :note, :data_attrs])
|
attrs = Map.drop(attrs, [:user, :note, :data_attrs])
|
||||||
|
|
||||||
|
|
|
@ -1915,6 +1915,63 @@ test "queues key as atom", %{conn: conn} do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "GET /api/pleroma/admin/users/:nickname/statuses" do
|
||||||
|
setup do
|
||||||
|
admin = insert(:user, info: %{is_admin: true})
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
date1 = (DateTime.to_unix(DateTime.utc_now()) + 2000) |> DateTime.from_unix!()
|
||||||
|
date2 = (DateTime.to_unix(DateTime.utc_now()) + 1000) |> DateTime.from_unix!()
|
||||||
|
date3 = (DateTime.to_unix(DateTime.utc_now()) + 3000) |> DateTime.from_unix!()
|
||||||
|
|
||||||
|
insert(:note_activity, user: user, published: date1)
|
||||||
|
insert(:note_activity, user: user, published: date2)
|
||||||
|
insert(:note_activity, user: user, published: date3)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
build_conn()
|
||||||
|
|> assign(:user, admin)
|
||||||
|
|
||||||
|
{:ok, conn: conn, user: user}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders user's statuses", %{conn: conn, user: user} do
|
||||||
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
|
||||||
|
|
||||||
|
assert json_response(conn, 200) |> length() == 3
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders user's statuses with a limit", %{conn: conn, user: user} do
|
||||||
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=2")
|
||||||
|
|
||||||
|
assert json_response(conn, 200) |> length() == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
test "doesn't return private statuses by default", %{conn: conn, user: user} do
|
||||||
|
{:ok, _private_status} =
|
||||||
|
CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
|
||||||
|
|
||||||
|
{:ok, _public_status} =
|
||||||
|
CommonAPI.post(user, %{"status" => "public", "visibility" => "public"})
|
||||||
|
|
||||||
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses")
|
||||||
|
|
||||||
|
assert json_response(conn, 200) |> length() == 4
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns private statuses with godmode on", %{conn: conn, user: user} do
|
||||||
|
{:ok, _private_status} =
|
||||||
|
CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
|
||||||
|
|
||||||
|
{:ok, _public_status} =
|
||||||
|
CommonAPI.post(user, %{"status" => "public", "visibility" => "public"})
|
||||||
|
|
||||||
|
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?godmode=true")
|
||||||
|
|
||||||
|
assert json_response(conn, 200) |> length() == 5
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Needed for testing
|
# Needed for testing
|
||||||
|
|
Loading…
Reference in a new issue