This commit is contained in:
1 parent
e4843e7d1d
commit
1808f14cc6
17 files changed
+711
-23
No files matched your search
+13
-5
@@ -1,3 +1,5 @@
|
||||
import { enrichUserOrganization } from './org-context.js';
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
@@ -223,7 +225,8 @@ function normalizeClaims(claims) {
|
||||
const primaryTenant = tenantList.find((tenant) => typeof tenant !== 'string' && (tenant.id || tenant.tenantId) === tenantId) || tenantList[0] || {};
|
||||
const tenantName = claims.tenant_name || claims.tenantName || custom.tenant_name || custom.tenantName || (typeof primaryTenant === 'object' ? (primaryTenant.name || primaryTenant.tenantName || primaryTenant.displayName || primaryTenant.label || '') : '');
|
||||
const email = claims.email || profile.email || '';
|
||||
const company = companyNameFromEmail(email) || custom.company || claims.company || claims.organization || profile.company || '';
|
||||
const explicitCompany = custom.company || claims.company || claims.organization || profile.company || claims.affiliation || '';
|
||||
const company = explicitCompany || companyNameFromEmail(email);
|
||||
const subject = claims.sub || claims.subject || claims.userId || claims.user_id || '';
|
||||
return {
|
||||
userUuid: claims.userId || claims.user_id || subject,
|
||||
@@ -240,8 +243,9 @@ function normalizeClaims(claims) {
|
||||
phone: claims.phone || claims.phone_number || claims.phoneNumber || claims.mobile || claims.mobilePhone || customPhone || profilePhone,
|
||||
tenantName,
|
||||
company,
|
||||
companySource: explicitCompany ? 'sso' : 'email',
|
||||
familyCompany: custom.familyCompany || custom.family_company || claims.familyCompany || claims.affiliation || '',
|
||||
department: custom.team || custom.department || claims.department || primaryTenant.name || '',
|
||||
department: custom.team || custom.department || claims.department || profile.department || (!['COMPANY', 'COMPANY_GROUP', 'ROOT'].includes(String(primaryTenant.type || primaryTenant.orgUnitType || '').toUpperCase()) ? primaryTenant.name : '') || '',
|
||||
position: custom.position || claims.position || profile.position || primaryTenant.position || primaryTenant.title || '',
|
||||
grade: custom.grade || claims.grade || profile.grade || primaryTenant.grade || ''
|
||||
};
|
||||
@@ -323,14 +327,14 @@ async function getSession(request, env) {
|
||||
}
|
||||
|
||||
async function sessionResponse(request, env) {
|
||||
const user = await getSession(request, env);
|
||||
const user = await enrichUserOrganization(await getSession(request, env), env);
|
||||
return json({ authenticated: Boolean(user), user }, 200, { 'access-control-allow-credentials': 'true' });
|
||||
}
|
||||
|
||||
async function createFeedback(request, env) {
|
||||
if (request.method !== 'POST') return json({ error: 'method_not_allowed' }, 405, { allow: 'POST' });
|
||||
const user = await getSession(request, env);
|
||||
if (!user) return json({ error: 'unauthenticated' }, 401);
|
||||
const sessionUser = await getSession(request, env);
|
||||
if (!sessionUser) return json({ error: 'unauthenticated' }, 401);
|
||||
if (!env.ABC_API_KEY) return json({ error: 'feedback_api_not_configured' }, 503);
|
||||
if (!env.ABC_PROJECT_ID || !env.ABC_CHANNEL_ID) return json({ error: 'feedback_target_not_configured' }, 503);
|
||||
|
||||
@@ -362,6 +366,7 @@ async function createFeedback(request, env) {
|
||||
if (!title || !contents || !category) return json({ error: 'title_contents_category_required' }, 400);
|
||||
if (!['ERROR_QNA', 'IMPROVEMENT_QNA', 'GENERAL_QNA'].includes(category)) return json({ error: 'invalid_category' }, 400);
|
||||
|
||||
const user = await enrichUserOrganization(sessionUser, env);
|
||||
const feedbackId = isUuidv7(input.feedbackId) ? input.feedbackId : uuidv7();
|
||||
const requesterId = String(user.requesterId || user.ssoSubject || user.userUuid || '');
|
||||
const requesterTenantId = String(user.requesterTenantId || user.tenantId || '');
|
||||
@@ -380,6 +385,9 @@ async function createFeedback(request, env) {
|
||||
requester_email: String(user.email || ''),
|
||||
requester_name: String(user.name || ''),
|
||||
requester_department: String(user.department || ''),
|
||||
requester_affiliation: String(user.companySource === 'email' ? '' : (user.company || user.familyCompany || '')),
|
||||
requester_position: String(user.position || ''),
|
||||
requester_grade: String(user.grade || ''),
|
||||
requester_phone_number: requesterPhone,
|
||||
is_secret: input.is_secret === true || input.is_secret === 'true' || input.is_secret === 1 || input.is_secret === '1' ? 'true' : 'false'
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user