// Human copy for the reason column of the sign-in log. // // The server writes stable snake_case codes; the legacy literals are kept in // the map because stored rows live for seven days after an upgrade. Anything // not in the map is free text from the we360 service and is flagged as such so // the UI can style it differently. const labels: Record< string, string > = { allow_list: 'On your allow list', 'User is in allow list': 'On your allow list', repeat_decision: 'Repeated recent attempt — previous decision reused', 'Extending existing ban': 'Repeated recent attempt — previous decision reused', 'Extending existing allow': 'Repeated recent attempt — previous decision reused', too_many_failures: 'Blocked after too many failed sign-ins', 'Too many login failures': 'Blocked after too many failed sign-ins', service_unexpected: 'Could not be checked — allowed through', 'Unexpected reply from we360 service': 'Could not be checked — allowed through', service_error: 'Could not be checked — allowed through', 'Error communicating with we360 service': 'Could not be checked — allowed through', manual_block: 'Blocked by you', // A private or office address is never assessed or automatically banned // (Redmine #25592 f). not_assessable: 'Private network address — not assessed, never blocked automatically', }; // Watch mode records what Protect would have blocked, with the underlying // reason after this prefix (Redmine #25592 a). The inner part is either one // of the codes above or the service's free text. const WOULD_BLOCK = 'would_block_'; export interface ReasonNote { text: string; cloud: boolean; } /** * Map a stored reason to display copy, or null for an empty reason. * @param reason */ export function reasonLabel( reason: string | null | undefined ): ReasonNote | null { if ( ! reason ) { return null; } if ( reason in labels ) { return { text: labels[ reason ], cloud: false }; } if ( reason.startsWith( WOULD_BLOCK ) ) { const inner = reason.slice( WOULD_BLOCK.length ); const mapped = inner in labels ? labels[ inner ] : inner; return { text: 'Would be blocked with protection on — ' + mapped, cloud: ! ( inner in labels ), }; } return { text: reason, cloud: true }; }