mirror of
https://github.com/wassname/talk.git
synced 2026-07-27 11:28:12 +08:00
[CORL-406] Tenant Locale Selection (#2450)
* feat: added preload config * feat: support changing locale * fix: name case * fix: removed unused code * feat: added translations for default reactions * fix: do not translate icon * fix: shorter i18n keys
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import crypto from "crypto";
|
||||
import { FluentBundle } from "fluent/compat";
|
||||
|
||||
import { GQLReactionConfiguration } from "coral-server/graph/tenant/schema/__generated__/types";
|
||||
import { translate } from "coral-server/services/i18n";
|
||||
|
||||
export const getDefaultReactionConfiguration = (
|
||||
bundle: FluentBundle
|
||||
): GQLReactionConfiguration => ({
|
||||
// By default, the standard reaction style will use the Respect with the
|
||||
// handshake.
|
||||
label: translate(bundle, "Respect", "reaction-labelRespect"),
|
||||
labelActive: translate(bundle, "Respected", "reaction-labelActiveRespected"),
|
||||
sortLabel: translate(
|
||||
bundle,
|
||||
"Most Respected",
|
||||
"reaction-sortLabelMostRespected"
|
||||
),
|
||||
icon: "thumb_up",
|
||||
});
|
||||
|
||||
export function generateSSOKey() {
|
||||
// Generate a new key. We generate a key of minimum length 32 up to 37 bytes,
|
||||
// as 16 was the minimum length recommended.
|
||||
//
|
||||
// Reference: https://security.stackexchange.com/a/96176
|
||||
return crypto.randomBytes(32 + Math.floor(Math.random() * 5)).toString("hex");
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./tenant";
|
||||
export * from "./helpers";
|
||||
@@ -1,4 +1,3 @@
|
||||
import crypto from "crypto";
|
||||
import { Db } from "mongodb";
|
||||
import uuid from "uuid";
|
||||
|
||||
@@ -14,6 +13,8 @@ import {
|
||||
createIndexFactory,
|
||||
} from "coral-server/models/helpers";
|
||||
import { Settings } from "coral-server/models/settings";
|
||||
import { I18n } from "coral-server/services/i18n";
|
||||
import { generateSSOKey, getDefaultReactionConfiguration } from "./helpers";
|
||||
|
||||
const collection = createCollection<Tenant>("tenants");
|
||||
|
||||
@@ -72,6 +73,7 @@ export type CreateTenantInput = Pick<
|
||||
*/
|
||||
export async function createTenant(
|
||||
mongo: Db,
|
||||
i18n: I18n,
|
||||
input: CreateTenantInput,
|
||||
now = new Date()
|
||||
) {
|
||||
@@ -178,14 +180,7 @@ export async function createTenant(
|
||||
doNotStore: true,
|
||||
},
|
||||
},
|
||||
reaction: {
|
||||
// By default, the standard reaction style will use the Respect with the
|
||||
// handshake.
|
||||
label: "Respect",
|
||||
labelActive: "Respected",
|
||||
sortLabel: "Most Respected",
|
||||
icon: "thumb_up",
|
||||
},
|
||||
reaction: getDefaultReactionConfiguration(i18n.getBundle(input.locale)),
|
||||
stories: {
|
||||
scraping: {
|
||||
enabled: true,
|
||||
@@ -281,14 +276,6 @@ export async function updateTenant(
|
||||
return result.value || null;
|
||||
}
|
||||
|
||||
function generateSSOKey() {
|
||||
// Generate a new key. We generate a key of minimum length 32 up to 37 bytes,
|
||||
// as 16 was the minimum length recommended.
|
||||
//
|
||||
// Reference: https://security.stackexchange.com/a/96176
|
||||
return crypto.randomBytes(32 + Math.floor(Math.random() * 5)).toString("hex");
|
||||
}
|
||||
|
||||
/**
|
||||
* regenerateTenantSSOKey will regenerate the SSO key used for Single Sing-On
|
||||
* for the specified Tenant. All existing user sessions signed with the old
|
||||
Reference in New Issue
Block a user