mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
fix(AdminUserSchemas): use DiscriminatorType for discriminator (#1218)
Co-authored-by: Hampus <[email protected]>
This commit is contained in:
@@ -15012,11 +15012,12 @@
|
||||
"properties": {
|
||||
"user_id": {"$ref": "#/components/schemas/SnowflakeType"},
|
||||
"username": {"$ref": "#/components/schemas/UsernameType"},
|
||||
"discriminator": {"$ref": "#/components/schemas/Int32Type"}
|
||||
"discriminator": {"$ref": "#/components/schemas/DiscriminatorType"}
|
||||
},
|
||||
"required": ["user_id", "username"]
|
||||
},
|
||||
"UsernameType": {"type": "string", "minLength": 1, "maxLength": 32, "pattern": "^[a-zA-Z0-9_]+$"},
|
||||
"DiscriminatorType": {"type": "string", "pattern": "^\\d{1,4}$"},
|
||||
"ClearUserFieldsRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -397,10 +397,13 @@ impl AdminApiClient {
|
||||
&self,
|
||||
user_id: &str,
|
||||
username: &str,
|
||||
discriminator: Option<i32>,
|
||||
discriminator: Option<&str>,
|
||||
) -> ApiResult<AdminUser> {
|
||||
let body = generated_types::ChangeUsernameRequest {
|
||||
discriminator: discriminator.map(generated_types::Int32Type::from),
|
||||
discriminator: discriminator
|
||||
.map(generated_types::DiscriminatorType::try_from)
|
||||
.transpose()
|
||||
.map_err(|e| ApiError::Parse(e.to_string()))?,
|
||||
user_id: snowflake(user_id),
|
||||
username: generated_types::UsernameType::try_from(username)
|
||||
.map_err(|e| ApiError::Parse(e.to_string()))?,
|
||||
|
||||
@@ -205,10 +205,10 @@ pub async fn dispatch(
|
||||
let Some(username) = get("username") else {
|
||||
return DispatchOutcome::error("Username is required");
|
||||
};
|
||||
let discriminator = form.parse_i32("discriminator");
|
||||
let discriminator = get("discriminator");
|
||||
DispatchOutcome::from_result(
|
||||
client
|
||||
.change_username(user_id, &username, discriminator)
|
||||
.change_username(user_id, &username, discriminator.as_deref())
|
||||
.await,
|
||||
"Username changed successfully",
|
||||
"Failed to change username",
|
||||
|
||||
@@ -47,8 +47,8 @@ fn edit_account_card(base: &str, user: &AdminUser, csrf_token: &str) -> Markup {
|
||||
p class="text-sm font-medium text-neutral-700" { "Change Username:" }
|
||||
input type="text" name="username" placeholder="New username"
|
||||
required class=(INPUT_CLS);
|
||||
input type="number" name="discriminator"
|
||||
placeholder="Discriminator (optional)" min="0" max="9999"
|
||||
input type="text" name="discriminator"
|
||||
placeholder="Discriminator (optional)" inputmode="numeric" pattern="[0-9]{1,4}" maxlength="4"
|
||||
class=(INPUT_CLS);
|
||||
(form_actions(html! {
|
||||
(submit_button("Change Username"))
|
||||
|
||||
@@ -23611,7 +23611,7 @@
|
||||
"name": "discriminator",
|
||||
"in": "query",
|
||||
"required": true,
|
||||
"schema": {"type": "string", "pattern": "^\\d{1,4}$", "description": "The discriminator to check"}
|
||||
"schema": {"$ref": "#/components/schemas/DiscriminatorType"}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -32140,7 +32140,7 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"username": {"$ref": "#/components/schemas/UsernameType"},
|
||||
"discriminator": {"type": "string", "pattern": "^\\d{1,4}$", "description": "The discriminator of the bot"},
|
||||
"discriminator": {"$ref": "#/components/schemas/DiscriminatorType"},
|
||||
"avatar": {
|
||||
"anyOf": [{"$ref": "#/components/schemas/Base64ImageType"}, {"type": "null"}],
|
||||
"description": "The avatar image as base64"
|
||||
@@ -32153,6 +32153,7 @@
|
||||
"bot_flags": {"$ref": "#/components/schemas/BotFlags"}
|
||||
}
|
||||
},
|
||||
"DiscriminatorType": {"type": "string", "pattern": "^\\d{1,4}$"},
|
||||
"BotTokenResetResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -34722,7 +34723,7 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"username": {"$ref": "#/components/schemas/UsernameType"},
|
||||
"discriminator": {"type": "string", "pattern": "^\\d{1,4}$", "description": "The 4-digit discriminator tag"},
|
||||
"discriminator": {"$ref": "#/components/schemas/DiscriminatorType"},
|
||||
"global_name": {
|
||||
"anyOf": [{"type": "string"}, {"type": "null"}],
|
||||
"description": "The display name shown to other users"
|
||||
@@ -36398,7 +36399,7 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"username": {"$ref": "#/components/schemas/UsernameType"},
|
||||
"discriminator": {"type": "string", "pattern": "^\\d{1,4}$", "description": "Discriminator tag of the user"}
|
||||
"discriminator": {"$ref": "#/components/schemas/DiscriminatorType"}
|
||||
},
|
||||
"required": ["username", "discriminator"]
|
||||
},
|
||||
|
||||
@@ -42,6 +42,11 @@ export const UsernameTypeSchema: OpenAPISchema = {
|
||||
pattern: '^[a-zA-Z0-9_]+$',
|
||||
};
|
||||
export const UsernameTypeRef: OpenAPIRef = {$ref: '#/components/schemas/UsernameType'};
|
||||
export const DiscriminatorTypeSchema: OpenAPISchema = {
|
||||
type: 'string',
|
||||
pattern: '^\\d{1,4}$',
|
||||
};
|
||||
export const DiscriminatorTypeRef: OpenAPIRef = {$ref: '#/components/schemas/DiscriminatorType'};
|
||||
export const EmailTypeSchema: OpenAPISchema = {
|
||||
type: 'string',
|
||||
format: 'email',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
import {
|
||||
Base64ImageTypeRef,
|
||||
DiscriminatorTypeRef,
|
||||
EmailTypeRef,
|
||||
Int32TypeRef,
|
||||
Int64StringTypeRef,
|
||||
@@ -58,6 +59,8 @@ function getRefForCustomTypeName(typeName: string): OpenAPISchemaOrRef | null {
|
||||
return UnsignedInt64TypeRef;
|
||||
case 'UsernameType':
|
||||
return UsernameTypeRef;
|
||||
case 'DiscriminatorType':
|
||||
return DiscriminatorTypeRef;
|
||||
case 'EmailType':
|
||||
return EmailTypeRef;
|
||||
case 'PasswordType':
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import {
|
||||
APIErrorCodeSchema,
|
||||
Base64ImageTypeSchema,
|
||||
DiscriminatorTypeSchema,
|
||||
EmailTypeSchema,
|
||||
Int32TypeSchema,
|
||||
Int64StringTypeSchema,
|
||||
@@ -130,6 +131,7 @@ const BUILT_IN_SCHEMAS: ReadonlyArray<readonly [string, OpenAPISchema]> = [
|
||||
['Int64StringType', Int64StringTypeSchema],
|
||||
['UnsignedInt64Type', UnsignedInt64TypeSchema],
|
||||
['UsernameType', UsernameTypeSchema],
|
||||
['DiscriminatorType', DiscriminatorTypeSchema],
|
||||
['EmailType', EmailTypeSchema],
|
||||
['PasswordType', PasswordTypeSchema],
|
||||
['PhoneNumberType', PhoneNumberTypeSchema],
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
SnowflakeStringType,
|
||||
SnowflakeType,
|
||||
} from '@fluxer/schema/src/primitives/SchemaPrimitives';
|
||||
import {EmailType, UsernameType} from '@fluxer/schema/src/primitives/UserValidators';
|
||||
import {DiscriminatorType, EmailType, UsernameType} from '@fluxer/schema/src/primitives/UserValidators';
|
||||
import {z} from 'zod';
|
||||
|
||||
export const UserAdminResponseSchema = z.object({
|
||||
@@ -302,7 +302,7 @@ export type SendPasswordResetRequest = z.infer<typeof SendPasswordResetRequest>;
|
||||
export const ChangeUsernameRequest = z.object({
|
||||
user_id: SnowflakeType.describe('ID of the user to change username for'),
|
||||
username: UsernameType.describe('New username for the user'),
|
||||
discriminator: Int32Type.optional().describe('Legacy discriminator value'),
|
||||
discriminator: DiscriminatorType.optional().describe('Legacy discriminator value'),
|
||||
});
|
||||
|
||||
export type ChangeUsernameRequest = z.infer<typeof ChangeUsernameRequest>;
|
||||
|
||||
@@ -50,13 +50,16 @@ export const EmailType = withOpenApiType(
|
||||
}, ValidationErrorCodes.INVALID_EMAIL_LOCAL_PART),
|
||||
'EmailType',
|
||||
);
|
||||
export const DiscriminatorType = z
|
||||
.union([z.string(), z.number()])
|
||||
.transform((value) => String(value))
|
||||
.pipe(z.string().regex(DISCRIMINATOR_REGEX, ValidationErrorCodes.DISCRIMINATOR_INVALID_FORMAT))
|
||||
.transform((value) => {
|
||||
return Number.parseInt(value, 10);
|
||||
});
|
||||
export const DiscriminatorType = withOpenApiType(
|
||||
z
|
||||
.union([z.string(), z.number()])
|
||||
.transform((value) => String(value))
|
||||
.pipe(z.string().regex(DISCRIMINATOR_REGEX, ValidationErrorCodes.DISCRIMINATOR_INVALID_FORMAT))
|
||||
.transform((value) => {
|
||||
return Number.parseInt(value, 10);
|
||||
}),
|
||||
'DiscriminatorType',
|
||||
);
|
||||
export const UsernameType = withOpenApiType(
|
||||
z
|
||||
.string()
|
||||
|
||||
Reference in New Issue
Block a user