A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(guild): default empty template role and channel names (#3875)
Hampusb4cd67402769
diff --git a/fluxer_admin/openapi-admin.json b/fluxer_admin/openapi-admin.jsonindex 719340fcf..1f0c9f1b1 100644--- a/fluxer_admin/openapi-admin.json+++ b/fluxer_admin/openapi-admin.json@@ -18977,7 +18977,7 @@"type": "object","properties": {"id": {"$ref": "#/components/schemas/SnowflakeStringType"},- "name": {"type": "string", "minLength": 1, "maxLength": 100},+ "name": {"type": "string", "maxLength": 100},"animated": {"type": "boolean"},"creator_id": {"$ref": "#/components/schemas/SnowflakeStringType"},"media_url": {"type": "string", "minLength": 1, "maxLength": 2048}@@ -19019,7 +19019,7 @@"type": "object","properties": {"id": {"$ref": "#/components/schemas/SnowflakeStringType"},- "name": {"type": "string", "minLength": 1, "maxLength": 100},+ "name": {"type": "string", "maxLength": 100},"animated": {"type": "boolean"},"creator_id": {"$ref": "#/components/schemas/SnowflakeStringType"},"media_url": {"type": "string", "minLength": 1, "maxLength": 2048}@@ -19308,7 +19308,7 @@"owner_username": {"nullable": true, "type": "string"},"owner_global_name": {"nullable": true, "type": "string"},"owner_discriminator": {"nullable": true, "type": "string"},- "name": {"type": "string", "minLength": 1, "maxLength": 100},+ "name": {"type": "string", "maxLength": 100},"vanity_url_code": {"nullable": true, "type": "string", "minLength": 1, "maxLength": 256},"icon": {"nullable": true, "type": "string", "minLength": 1, "maxLength": 256},"banner": {"nullable": true, "type": "string", "minLength": 1, "maxLength": 256},@@ -19343,7 +19343,7 @@"type": "object","properties": {"id": {"$ref": "#/components/schemas/SnowflakeStringType"},- "name": {"nullable": true, "type": "string", "minLength": 1, "maxLength": 100},+ "name": {"nullable": true, "type": "string", "maxLength": 100},"type": {"allOf": [{"$ref": "#/components/schemas/ChannelType"}]},"position": {"$ref": "#/components/schemas/Int32Type"},"parent_id": {"nullable": true, "allOf": [{"$ref": "#/components/schemas/SnowflakeStringType"}]},@@ -19363,7 +19363,7 @@"type": "object","properties": {"id": {"$ref": "#/components/schemas/SnowflakeStringType"},- "name": {"type": "string", "minLength": 1, "maxLength": 100},+ "name": {"type": "string", "maxLength": 100},"color": {"$ref": "#/components/schemas/Int32Type"},"position": {"$ref": "#/components/schemas/Int32Type"},"permissions": {diff --git a/fluxer_admin/src/routes/guilds.rs b/fluxer_admin/src/routes/guilds.rsindex 5092524a6..1356773cc 100644--- a/fluxer_admin/src/routes/guilds.rs+++ b/fluxer_admin/src/routes/guilds.rs@@ -129,11 +129,9 @@ async fn guild_detail(let csrf_token = csrf::get_csrf_token(&request);let client = AdminApiClient::new(state.http_client(), config, &auth.0.session);- let guild = client- .lookup_guild(&guild_id)- .await- .log_error("load guild detail")- .flatten();+ let lookup = client.lookup_guild(&guild_id).await;+ let load_failed = lookup.is_err();+ let guild = lookup.log_error("load guild detail").flatten();let tq = to_tab_query(&query);let admin_acls = auth.0.acls();@@ -172,6 +170,7 @@ async fn guild_detail(tab_body,is_detail_fragment,username_sign_in,+ load_failed,);Html(markup.into_string()).into_response()}diff --git a/fluxer_admin/src/templates/pages/guild_detail.rs b/fluxer_admin/src/templates/pages/guild_detail.rsindex 52ee8d6a8..c2e0efa68 100644--- a/fluxer_admin/src/templates/pages/guild_detail.rs+++ b/fluxer_admin/src/templates/pages/guild_detail.rs@@ -43,17 +43,19 @@ pub fn guild_detail_with_tab(tab_body: Option<Markup>,is_htmx: bool,username_sign_in: bool,+ load_failed: bool,) -> Markup {let content = match guild {Some(guild) => {render_guild_detail(config, auth, guild, active_tab, tab_body, username_sign_in)}+ None if load_failed => load_failed_state(guild_id),None => not_found_state("Guild", guild_id, None, None),};- let title = if guild.is_some() {- "Guild Details"- } else {- "Guild Not Found"+ let title = match (guild.is_some(), load_failed) {+ (true, _) => "Guild Details",+ (false, true) => "Guild Failed to Load",+ (false, false) => "Guild Not Found",};if is_htmx {content@@ -229,3 +231,15 @@ fn guild_tab_visible(_config: &AdminConfig, tab_id: &str, admin_acls: &[String])_ => false,}}++fn load_failed_state(guild_id: &str) -> Markup {+ html! {+ div class="flex flex-col items-center justify-center py-16 text-center" {+ h2 class="text-xl font-semibold text-neutral-900 mb-2" { "Guild Failed to Load" }+ p class="text-neutral-500 text-sm mb-4" {+ "The admin couldn't load guild " (guild_id) ". The admin logs have the error."+ }+ a href="javascript:history.back()" class="text-sm text-blue-600 hover:text-blue-800 hover:underline" { "Go back" }+ }+ }+}diff --git a/fluxer_api/src/api/guild/services/data/GuildOperationsService.ts b/fluxer_api/src/api/guild/services/data/GuildOperationsService.tsindex bca951b2a..1a6bac600 100644--- a/fluxer_api/src/api/guild/services/data/GuildOperationsService.ts+++ b/fluxer_api/src/api/guild/services/data/GuildOperationsService.ts@@ -112,6 +112,7 @@ import type {TemplateSerializedGuild,} from '@fluxer/schema/src/domains/guild/GuildTemplateSchemas';import {isValidSingleUnicodeEmoji} from '@fluxer/schema/src/primitives/EmojiValidators';+import {normalizeString} from '@fluxer/schema/src/primitives/SchemaPrimitives';import {extractTimestamp} from '@fluxer/snowflake/src/SnowflakeUtils';import type {IWorkerService} from '@pkgs/worker/src/contracts/IWorkerService';@@ -215,6 +216,16 @@ function isSystemChannelType(type: number): boolean {return type === ChannelTypes.GUILD_TEXT || type === ChannelTypes.GUILD_ANNOUNCEMENT;}+function templateChannelFallbackName(type: number, locale: string | null): string {+ if (type === ChannelTypes.GUILD_CATEGORY) {+ return getContentMessage('guild.default_category_text', locale);+ }+ if (type === ChannelTypes.GUILD_VOICE) {+ return getContentMessage('guild.default_channel_voice', locale);+ }+ return getContentMessage('guild.default_channel_text', locale);+}+export class GuildOperationsService {constructor(private readonly guildRepository: GuildRepository,@@ -1106,7 +1117,7 @@ export class GuildOperationsService {GuildRoles.insert({guild_id: guildId,role_id: roleId,- name: role.name,+ name: normalizeString(role.name) || 'new role',permissions: this.parseTemplatePermissionBitfield(role.permissions_new ?? role.permissions, permissionMask),position: nextRolePosition,hoist_position: null,@@ -1158,7 +1169,7 @@ export class GuildOperationsService {channel_id: channelId,guild_id: guildId,type: fluxerType,- name: channel.name,+ name: normalizeString(channel.name) || templateChannelFallbackName(fluxerType, locale),topic: clipTemplateTopic(channel.topic, fluxerType),icon_hash: null,url: null,diff --git a/packages/schema/src/domains/admin/AdminSchemas.ts b/packages/schema/src/domains/admin/AdminSchemas.tsindex 1587f2ccb..c81b9e819 100644--- a/packages/schema/src/domains/admin/AdminSchemas.ts+++ b/packages/schema/src/domains/admin/AdminSchemas.ts@@ -1554,7 +1554,7 @@ const AdminGuildResponseSchema = z.object({});const AdminGuildChannelSummarySchema = z.object({id: SnowflakeStringType,- name: createStringType(1, 100).nullable(),+ name: z.string().max(100).nullable(),type: ChannelTypeSchema,position: Int32Type,parent_id: SnowflakeStringType.nullable(),@@ -1566,7 +1566,7 @@ const AdminGuildChannelSummarySchema = z.object({});const AdminGuildRoleSummarySchema = z.object({id: SnowflakeStringType,- name: createStringType(1, 100),+ name: z.string().max(100),color: Int32Type,position: Int32Type,permissions: PermissionStringType.describe('The role permissions bitfield'),@@ -1581,7 +1581,7 @@ const AdminLookupGuildSchema = z.object({owner_username: z.string().nullable(),owner_global_name: z.string().nullable(),owner_discriminator: z.string().nullable(),- name: createStringType(1, 100),+ name: z.string().max(100),vanity_url_code: createStringType(1, 256).nullable(),icon: createStringType(1, 256).nullable(),banner: createStringType(1, 256).nullable(),@@ -1623,7 +1623,7 @@ export const ListGuildMembersResponse = z.object({});const GuildAssetItemSchema = z.object({id: SnowflakeStringType,- name: createStringType(1, 100),+ name: z.string().max(100),animated: z.boolean(),creator_id: SnowflakeStringType,media_url: createStringType(1, 2048),