mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
fix(schema): allow assigning every admin ACL to a user (#1797)
This commit is contained in:
1 parent
2c8b3ff45c
commit
ba96f52ed6
2 files changed
+24
-2
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
import {AdminACLs} from '@fluxer/constants/src/AdminACLs';
|
||||||
|
import {SetUserAclsRequest} from '@fluxer/schema/src/domains/admin/AdminUserSchemas';
|
||||||
|
import {describe, expect, test} from 'vitest';
|
||||||
|
|
||||||
|
describe('SetUserAclsRequest', () => {
|
||||||
|
test('accepts every ACL the instance defines', () => {
|
||||||
|
const acls = Object.values(AdminACLs);
|
||||||
|
const result = SetUserAclsRequest.safeParse({user_id: '1', acls});
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('rejects more entries than there are ACLs', () => {
|
||||||
|
const acls = [...Object.values(AdminACLs), 'overflow:one'];
|
||||||
|
const result = SetUserAclsRequest.safeParse({user_id: '1', acls});
|
||||||
|
expect(result.success).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
UserFlags,
|
UserFlags,
|
||||||
UserFlagsDescriptions,
|
UserFlagsDescriptions,
|
||||||
} from '@fluxer/constants/src/UserConstants';
|
} from '@fluxer/constants/src/UserConstants';
|
||||||
|
import {AdminACLs} from '@fluxer/constants/src/AdminACLs';
|
||||||
import {NSFWLevelSchema} from '@fluxer/schema/src/primitives/GuildValidators';
|
import {NSFWLevelSchema} from '@fluxer/schema/src/primitives/GuildValidators';
|
||||||
import {
|
import {
|
||||||
createBitflagInt32Type,
|
createBitflagInt32Type,
|
||||||
@@ -21,6 +22,8 @@ import {
|
|||||||
import {DiscriminatorType, EmailType, UsernameType} from '@fluxer/schema/src/primitives/UserValidators';
|
import {DiscriminatorType, EmailType, UsernameType} from '@fluxer/schema/src/primitives/UserValidators';
|
||||||
import {z} from 'zod';
|
import {z} from 'zod';
|
||||||
|
|
||||||
|
const ADMIN_ACL_COUNT = Object.keys(AdminACLs).length;
|
||||||
|
|
||||||
export const UserAdminResponseSchema = z.object({
|
export const UserAdminResponseSchema = z.object({
|
||||||
id: SnowflakeStringType,
|
id: SnowflakeStringType,
|
||||||
username: z.string(),
|
username: z.string(),
|
||||||
@@ -65,7 +68,7 @@ export const UserAdminResponseSchema = z.object({
|
|||||||
pending_bulk_message_deletion_at: z.string().nullable(),
|
pending_bulk_message_deletion_at: z.string().nullable(),
|
||||||
deletion_reason_code: Int32Type.nullable(),
|
deletion_reason_code: Int32Type.nullable(),
|
||||||
deletion_public_reason: z.string().nullable(),
|
deletion_public_reason: z.string().nullable(),
|
||||||
acls: z.array(z.string()).max(100),
|
acls: z.array(z.string()).max(ADMIN_ACL_COUNT),
|
||||||
traits: z.array(z.string()).max(100),
|
traits: z.array(z.string()).max(100),
|
||||||
has_totp: z.boolean(),
|
has_totp: z.boolean(),
|
||||||
authenticator_types: z.array(Int32Type).max(10),
|
authenticator_types: z.array(Int32Type).max(10),
|
||||||
@@ -353,7 +356,7 @@ export type ScheduleAccountDeletionRequest = z.infer<typeof ScheduleAccountDelet
|
|||||||
|
|
||||||
export const SetUserAclsRequest = z.object({
|
export const SetUserAclsRequest = z.object({
|
||||||
user_id: SnowflakeType.describe('ID of the user to set ACLs for'),
|
user_id: SnowflakeType.describe('ID of the user to set ACLs for'),
|
||||||
acls: z.array(createStringType(1, 64)).max(100).describe('List of access control permissions to assign'),
|
acls: z.array(createStringType(1, 64)).max(ADMIN_ACL_COUNT).describe('List of access control permissions to assign'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type SetUserAclsRequest = z.infer<typeof SetUserAclsRequest>;
|
export type SetUserAclsRequest = z.infer<typeof SetUserAclsRequest>;
|
||||||
|
|||||||
Reference in new issue
Block a user