Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(admin): allow up to 100 custom badges of each type (#3691)

Hampus59357eee38fd
diff --git a/fluxer_admin/src/templates/pages/badges.rs b/fluxer_admin/src/templates/pages/badges.rs
index 691b5cd56..87991d7b5 100644
--- a/fluxer_admin/src/templates/pages/badges.rs
+++ b/fluxer_admin/src/templates/pages/badges.rs
@@ -44,7 +44,7 @@ pub fn badges_page(
let content = html! {
(page_header(
"Badges",
- Some("Badges that you give to users and guilds. Users show them on their profile, and guilds show them next to their name. You can make up to 10 badges of each type."),
+ Some("Badges that you give to users and guilds. Users show them on their profile, and guilds show them next to their name. You can make up to 100 badges of each type."),
))
@match badges {
None => (error_alert("Failed to load badges.")),
diff --git a/fluxer_api/src/api/admin/tests/AdminCustomBadges.test.ts b/fluxer_api/src/api/admin/tests/AdminCustomBadges.test.ts
index d08befa7e..23e74a22a 100644
--- a/fluxer_api/src/api/admin/tests/AdminCustomBadges.test.ts
+++ b/fluxer_api/src/api/admin/tests/AdminCustomBadges.test.ts
@@ -91,6 +91,26 @@ describe('custom badges', () => {
.execute();
});
+ test('allows 100 badges of a type and refuses the next one', async () => {
+ const template = await createTestCustomBadge(harness, admin.token, 'user');
+ const [stored] = await getInstanceConfigRepository().getCustomBadges();
+ await getInstanceConfigRepository().updateCustomBadges((current) => [
+ ...current,
+ ...Array.from({length: 98}, (_, index) => ({
+ ...stored!,
+ id: (BigInt(template.id) + BigInt(index + 1)).toString(),
+ name: `Badge ${index}`,
+ })),
+ ]);
+ await createTestCustomBadge(harness, admin.token, 'user', 'Last one');
+ await createTestCustomBadge(harness, admin.token, 'guild', 'Other type');
+ await createBuilder(harness, admin.token)
+ .post('/admin/badges')
+ .body({type: 'user', name: 'One too many', image: getPngDataUrl()})
+ .expect(HTTP_STATUS.BAD_REQUEST, 'MAX_BADGES')
+ .execute();
+ });
+
test('needs the matching ACL on every route', async () => {
const badge = await createTestCustomBadge(harness, admin.token);
const target = await createTestAccount(harness);
diff --git a/fluxer_api/src/api/openapi/openapi.json b/fluxer_api/src/api/openapi/openapi.json
index e63b113a1..174f4160e 100644
--- a/fluxer_api/src/api/openapi/openapi.json
+++ b/fluxer_api/src/api/openapi/openapi.json
@@ -37404,7 +37404,7 @@
},
"guild_badges": {
"description": "Custom badges that communities on this instance can show next to their name, in display order",
- "maxItems": 10,
+ "maxItems": 100,
"type": "array",
"items": {"$ref": "#/components/schemas/InstanceGuildBadgeSchema"}
}
diff --git a/fluxer_docs/src/content/docs/admin-api/badges.mdx b/fluxer_docs/src/content/docs/admin-api/badges.mdx
index ea9ca4ea8..830a04414 100644
--- a/fluxer_docs/src/content/docs/admin-api/badges.mdx
+++ b/fluxer_docs/src/content/docs/admin-api/badges.mdx
@@ -8,7 +8,7 @@ import RouteHeader from '@/components/RouteHeader.astro';
A custom badge is an image that instance admins make and give out. A user badge shows on the [profile](/http-api/users/#profile-badge-object) of each account it's given to, after the built-in badges. A guild badge shows next to the guild name, after its verified, partnered or discoverable badge, and [instance discovery](/http-api/instance/#guild-badge-object) lists every guild badge for clients.
-You can make up to 10 badges of each type, and an account or guild can have up to 10. Give badges with [Update user badges](/admin-api/users/#update-user-badges) and the `badge_ids` field of [Update guild](/admin-api/guilds/#update-guild). Deleting a badge takes it off everyone who had it.
+You can make up to 100 badges of each type, and an account or guild can have up to 10. Give badges with [Update user badges](/admin-api/users/#update-user-badges) and the `badge_ids` field of [Update guild](/admin-api/guilds/#update-guild). Deleting a badge takes it off everyone who had it.
## Admin custom badge object
@@ -79,7 +79,7 @@ Uploads the image to the media proxy, makes the badge and returns it. You need `
| Status | Body | Condition |
| --- | --- | --- |
| 200 | [Admin custom badge](#admin-custom-badge-object) object | The badge was made |
-| 400 | [error response](/admin-api/#error-response) | `MAX_BADGES` when the type already has 10 badges, or `INVALID_FORM_BODY` for a bad field |
+| 400 | [error response](/admin-api/#error-response) | `MAX_BADGES` when the type already has 100 badges, or `INVALID_FORM_BODY` for a bad field |
| 400 | [error response](/admin-api/#error-response) | `IMAGE_SIZE_EXCEEDS_LIMIT`, `INVALID_IMAGE_FORMAT` or `FAILED_TO_UPLOAD_IMAGE` for a bad image |
The rate limit is 100 requests per minute, on the `admin:user:modify` bucket.
diff --git a/packages/constants/src/BadgeConstants.ts b/packages/constants/src/BadgeConstants.ts
index 13ec356e4..6448ce865 100644
--- a/packages/constants/src/BadgeConstants.ts
+++ b/packages/constants/src/BadgeConstants.ts
@@ -9,7 +9,7 @@ export const CustomBadgeTypes = {
export type CustomBadgeType = ValueOf<typeof CustomBadgeTypes>;
-export const MAX_CUSTOM_BADGES_PER_TYPE = 10;
+export const MAX_CUSTOM_BADGES_PER_TYPE = 100;
export const MAX_CUSTOM_BADGES_PER_ENTITY = 10;
export const CUSTOM_BADGE_NAME_MAX_LENGTH = 64;
export const CUSTOM_BADGE_DESCRIPTION_MAX_LENGTH = 256;
@@ -28,7 +28,7 @@ export type ProfileBadgeKind = (typeof PROFILE_BADGE_KINDS)[number];
export type ProfileBadgeKey = ProfileBadgeKind | `custom:${string}`;
-export const MAX_HIDDEN_PROFILE_BADGES = PROFILE_BADGE_KINDS.length + MAX_CUSTOM_BADGES_PER_TYPE;
+export const MAX_HIDDEN_PROFILE_BADGES = PROFILE_BADGE_KINDS.length + MAX_CUSTOM_BADGES_PER_ENTITY;
export const PREMIUM_PROFILE_BADGE_KINDS: ReadonlyArray<ProfileBadgeKind> = ['plutonium', 'visionary', 'premium'];