mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
feat(admin)!: move the admin api to rest and fix its defects (#2515)
This commit is contained in:
@@ -218,6 +218,16 @@ async fn user_fragment_alias_returns_drawer_fragment() {
|
||||
assert!(fragment.contains("SearchedUser"), "{fragment}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_peek_alias_is_gone() {
|
||||
let app = setup().await;
|
||||
|
||||
assert_eq!(
|
||||
get_status(&app, "/users/1500000000000000001/peek").await,
|
||||
StatusCode::NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn drawer_triggers_use_htmx_and_native_popover() {
|
||||
let app = setup().await;
|
||||
@@ -644,6 +654,23 @@ async fn get(app: &TestApp, uri: &str, headers: &[(&str, &str)]) -> String {
|
||||
get_with_headers(app, uri, headers).await.1
|
||||
}
|
||||
|
||||
async fn get_status(app: &TestApp, uri: &str) -> StatusCode {
|
||||
let response = app
|
||||
.router
|
||||
.clone()
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method(Method::GET)
|
||||
.uri(uri)
|
||||
.header(header::COOKIE, &app.session_cookie)
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
response.status()
|
||||
}
|
||||
|
||||
async fn get_with_headers(
|
||||
app: &TestApp,
|
||||
uri: &str,
|
||||
@@ -752,8 +779,9 @@ async fn spawn_mock_api() -> String {
|
||||
}
|
||||
|
||||
async fn mock_api(method: Method, uri: Uri) -> Response {
|
||||
match (method, uri.path()) {
|
||||
(Method::GET, "/admin/users/me") => json_response(json!({ "user": admin_user() })),
|
||||
let path = uri.path().to_owned();
|
||||
match (method, path.as_str()) {
|
||||
(Method::GET, "/admin/users/@me") => json_response(json!({ "user": admin_user() })),
|
||||
(Method::GET, "/admin/api-keys") => json_response(json!([])),
|
||||
(Method::POST, "/admin/api-keys") => json_response(json!({
|
||||
"key_id": "1900000000000000001",
|
||||
@@ -763,60 +791,56 @@ async fn mock_api(method: Method, uri: Uri) -> Response {
|
||||
"expires_at": null,
|
||||
"acls": ["*"]
|
||||
})),
|
||||
(Method::POST, "/admin/users/search") => {
|
||||
(Method::GET, "/admin/users") => {
|
||||
json_response(json!({ "users": [searched_user()], "total": 1 }))
|
||||
}
|
||||
(Method::POST, "/admin/users/lookup") => {
|
||||
(Method::GET, "/admin/users/1500000000000000001") => {
|
||||
json_response(json!({ "users": [searched_user()] }))
|
||||
}
|
||||
(Method::POST, "/admin/users/update-has-verified-phone") => {
|
||||
(Method::PUT, "/admin/users/1500000000000000001/phone-verification") => {
|
||||
json_response(json!({ "user": searched_user() }))
|
||||
}
|
||||
(Method::POST, "/admin/guilds/search") => {
|
||||
(Method::GET, "/admin/guilds") => {
|
||||
json_response(json!({ "guilds": [searched_guild()], "total": 1 }))
|
||||
}
|
||||
(Method::POST, "/admin/guilds/lookup") => {
|
||||
(Method::GET, "/admin/guilds/1600000000000000001") => {
|
||||
json_response(json!({ "guild": searched_guild_detail() }))
|
||||
}
|
||||
(Method::POST, "/admin/applications/lookup") => {
|
||||
json_response(json!({ "application": searched_application() }))
|
||||
}
|
||||
(Method::POST, "/admin/applications/list-by-owner") => {
|
||||
(Method::GET, "/admin/applications") => {
|
||||
json_response(json!({ "applications": [searched_application()] }))
|
||||
}
|
||||
(Method::POST, "/admin/reports/search") => json_response(
|
||||
(Method::GET, "/admin/reports") => json_response(
|
||||
json!({ "reports": [searched_report()], "total": 1, "offset": 0, "limit": 25 }),
|
||||
),
|
||||
(Method::GET, "/admin/reports/1800000000000000001") => json_response(searched_report()),
|
||||
(Method::GET, "/admin/reports/1800000000000000002") => {
|
||||
json_response(searched_message_report())
|
||||
}
|
||||
(Method::POST, "/admin/reports/resolve") => json_response(json!({
|
||||
(Method::PATCH, "/admin/reports/1800000000000000001") => json_response(json!({
|
||||
"report_id": "1800000000000000001",
|
||||
"status": 1,
|
||||
"resolved_at": "2026-05-26T12:03:00.000Z",
|
||||
"public_comment": "done"
|
||||
})),
|
||||
(Method::POST, "/admin/jobs/list") => {
|
||||
(Method::GET, "/admin/jobs") => {
|
||||
json_response(json!({ "jobs": [searched_job()], "next_cursor": null, "cursor": null }))
|
||||
}
|
||||
(Method::POST, "/admin/jobs/get") => json_response(json!({ "job": searched_job() })),
|
||||
(Method::POST, "/admin/instance-config/get") => json_response(instance_config()),
|
||||
(Method::POST, "/admin/instance-config/registration-urls/create") => json_response(json!({
|
||||
(Method::GET, "/admin/jobs/1900000000000000001") => {
|
||||
json_response(json!({ "job": searched_job() }))
|
||||
}
|
||||
(Method::GET, "/admin/instance/config") => json_response(instance_config()),
|
||||
(Method::POST, "/admin/instance/registration-urls") => json_response(json!({
|
||||
"registration_url": registration_url_fixture(),
|
||||
"code": "11111111-1111-4111-8111-111111111111",
|
||||
"url": "https://app.example.test/register?registration_url=11111111-1111-4111-8111-111111111111"
|
||||
})),
|
||||
(Method::POST, "/admin/instance-config/registration-urls/revoke") => {
|
||||
(Method::DELETE, path) if path.starts_with("/admin/instance/registration-urls/") => {
|
||||
json_response(instance_config_without_registration_urls())
|
||||
}
|
||||
(Method::POST, "/admin/instance-config/pending-registrations/approve") => {
|
||||
(Method::PATCH, path) if path.starts_with("/admin/instance/pending-registrations/") => {
|
||||
json_response(instance_config_without_pending_registrations())
|
||||
}
|
||||
(Method::POST, "/admin/instance-config/pending-registrations/reject") => {
|
||||
json_response(instance_config_without_pending_registrations())
|
||||
}
|
||||
(Method::POST, "/admin/limit-config/get") => json_response(limit_config()),
|
||||
(Method::GET, "/admin/limit-config") => json_response(limit_config()),
|
||||
_ => (StatusCode::NOT_FOUND, Json(json!({ "error": "not found" }))).into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"routes": [
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/admin/users/me",
|
||||
"path": "/admin/users/@me",
|
||||
"body_file": "admin_user_me.json"
|
||||
},
|
||||
{
|
||||
@@ -21,28 +21,28 @@
|
||||
"body": "{}"
|
||||
},
|
||||
{
|
||||
"method": "POST",
|
||||
"path": "/admin/users/search",
|
||||
"method": "GET",
|
||||
"path": "/admin/users",
|
||||
"body_file": "search_users.json"
|
||||
},
|
||||
{
|
||||
"method": "POST",
|
||||
"path": "/admin/users/lookup",
|
||||
"method": "GET",
|
||||
"path": "/admin/users/1508576042312688531",
|
||||
"body_file": "lookup_user.json"
|
||||
},
|
||||
{
|
||||
"method": "POST",
|
||||
"path": "/admin/guilds/search",
|
||||
"method": "GET",
|
||||
"path": "/admin/guilds",
|
||||
"body_file": "search_guilds.json"
|
||||
},
|
||||
{
|
||||
"method": "POST",
|
||||
"path": "/admin/guilds/lookup",
|
||||
"method": "GET",
|
||||
"path": "/admin/guilds/1600000000000000001",
|
||||
"body_file": "lookup_guild.json"
|
||||
},
|
||||
{
|
||||
"method": "POST",
|
||||
"path": "/admin/reports/search",
|
||||
"method": "GET",
|
||||
"path": "/admin/reports",
|
||||
"body_file": "search_reports.json"
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user