Refine branding labels and access checks
This commit is contained in:
29
resources/js/admin/lib/__tests__/events.test.ts
Normal file
29
resources/js/admin/lib/__tests__/events.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { isBrandingAllowed, isWatermarkAllowed } from '../events';
|
||||
|
||||
describe('event branding access helpers', () => {
|
||||
it('respects package-level disallow', () => {
|
||||
const event = {
|
||||
settings: { branding_allowed: true, watermark_allowed: true },
|
||||
package: { branding_allowed: false, watermark_allowed: false },
|
||||
};
|
||||
|
||||
expect(isBrandingAllowed(event as any)).toBe(false);
|
||||
expect(isWatermarkAllowed(event as any)).toBe(false);
|
||||
});
|
||||
|
||||
it('uses settings when package allows', () => {
|
||||
const event = {
|
||||
settings: { branding_allowed: false, watermark_allowed: true },
|
||||
package: { branding_allowed: true, watermark_allowed: true },
|
||||
};
|
||||
|
||||
expect(isBrandingAllowed(event as any)).toBe(false);
|
||||
expect(isWatermarkAllowed(event as any)).toBe(true);
|
||||
});
|
||||
|
||||
it('defaults to allow when nothing is set', () => {
|
||||
expect(isBrandingAllowed({} as any)).toBe(true);
|
||||
expect(isWatermarkAllowed({} as any)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -92,7 +92,28 @@ export function resolveEngagementMode(event?: TenantEvent | null): 'tasks' | 'ph
|
||||
|
||||
export function isBrandingAllowed(event?: TenantEvent | null): boolean {
|
||||
if (!event) return true;
|
||||
return Boolean((event.package as any)?.branding_allowed ?? true);
|
||||
const settings = (event.settings ?? {}) as Record<string, unknown>;
|
||||
const packageAllowed = (event.package as any)?.branding_allowed;
|
||||
if (packageAllowed === false) {
|
||||
return false;
|
||||
}
|
||||
if (typeof settings.branding_allowed === 'boolean') {
|
||||
return settings.branding_allowed;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function isWatermarkAllowed(event?: TenantEvent | null): boolean {
|
||||
if (!event) return true;
|
||||
const settings = (event.settings ?? {}) as Record<string, unknown>;
|
||||
const packageAllowed = (event.package as any)?.watermark_allowed;
|
||||
if (packageAllowed === false) {
|
||||
return false;
|
||||
}
|
||||
if (typeof settings.watermark_allowed === 'boolean') {
|
||||
return settings.watermark_allowed;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function formatEventStatusLabel(
|
||||
|
||||
Reference in New Issue
Block a user