Move working documents to its own area, rename dashboard
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { hasStoredClientSession } from '$lib/session';
|
||||
import { getStoredClientSession, hasModuleAccess, hasStoredClientSession } from '$lib/session';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
export async function load({ fetch }) {
|
||||
@@ -12,13 +12,15 @@ export async function load({ fetch }) {
|
||||
};
|
||||
}
|
||||
|
||||
const session = getStoredClientSession();
|
||||
|
||||
try {
|
||||
const [rawMaterials, mixes, productCosts, scenarios, dataQuality] = await Promise.all([
|
||||
api.rawMaterials(fetch),
|
||||
api.mixes(fetch),
|
||||
api.productCosts(fetch),
|
||||
api.scenarios(fetch),
|
||||
api.dataQuality(fetch)
|
||||
hasModuleAccess(session, 'raw_materials') ? api.rawMaterials(fetch) : Promise.resolve([]),
|
||||
hasModuleAccess(session, 'mix_master') ? api.mixes(fetch) : Promise.resolve([]),
|
||||
hasModuleAccess(session, 'products') ? api.productCosts(fetch) : Promise.resolve([]),
|
||||
hasModuleAccess(session, 'scenarios') ? api.scenarios(fetch) : Promise.resolve([]),
|
||||
hasModuleAccess(session, 'dashboard') ? api.dataQuality(fetch) : Promise.resolve([])
|
||||
]);
|
||||
|
||||
return {
|
||||
|
||||
@@ -10,6 +10,8 @@ export async function load({ fetch }) {
|
||||
client_rows: [],
|
||||
user_rows: [],
|
||||
feature_rows: [],
|
||||
permission_rows: [],
|
||||
audit_rows: [],
|
||||
clients: []
|
||||
}
|
||||
};
|
||||
@@ -30,6 +32,8 @@ export async function load({ fetch }) {
|
||||
client_rows: [],
|
||||
user_rows: [],
|
||||
feature_rows: [],
|
||||
permission_rows: [],
|
||||
audit_rows: [],
|
||||
clients: []
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,6 +10,8 @@ export async function load({ fetch }) {
|
||||
client_rows: [],
|
||||
user_rows: [],
|
||||
feature_rows: [],
|
||||
permission_rows: [],
|
||||
audit_rows: [],
|
||||
clients: []
|
||||
}
|
||||
};
|
||||
@@ -30,6 +32,8 @@ export async function load({ fetch }) {
|
||||
client_rows: [],
|
||||
user_rows: [],
|
||||
feature_rows: [],
|
||||
permission_rows: [],
|
||||
audit_rows: [],
|
||||
clients: []
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import { api } from '$lib/api';
|
||||
import { hasStoredAdminSession, hasStoredClientSession } from '$lib/session';
|
||||
|
||||
export function load() {
|
||||
throw redirect(307, '/admin/client-access');
|
||||
function emptyPayload() {
|
||||
return {
|
||||
clients: [],
|
||||
exportPreview: {
|
||||
generated_at: '',
|
||||
client_rows: [],
|
||||
user_rows: [],
|
||||
feature_rows: [],
|
||||
permission_rows: [],
|
||||
audit_rows: [],
|
||||
clients: []
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function load({ fetch }) {
|
||||
if (!hasStoredAdminSession() && !hasStoredClientSession()) {
|
||||
return emptyPayload();
|
||||
}
|
||||
|
||||
try {
|
||||
const [clients, exportPreview] = await Promise.all([api.clientAccess(fetch), api.clientAccessExport(fetch)]);
|
||||
return { clients, exportPreview };
|
||||
} catch {
|
||||
return emptyPayload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ const apiMocks = vi.hoisted(() => ({
|
||||
}));
|
||||
|
||||
const sessionMocks = vi.hoisted(() => ({
|
||||
getStoredClientSession: vi.fn(),
|
||||
hasStoredClientSession: vi.fn(),
|
||||
hasStoredAdminSession: vi.fn()
|
||||
hasStoredAdminSession: vi.fn(),
|
||||
hasModuleAccess: vi.fn()
|
||||
}));
|
||||
|
||||
vi.mock('$lib/api', () => ({
|
||||
@@ -39,6 +41,8 @@ describe('route loaders use the SvelteKit fetch argument', () => {
|
||||
vi.clearAllMocks();
|
||||
sessionMocks.hasStoredClientSession.mockReturnValue(true);
|
||||
sessionMocks.hasStoredAdminSession.mockReturnValue(true);
|
||||
sessionMocks.getStoredClientSession.mockReturnValue({ role: 'client', module_permissions: {} });
|
||||
sessionMocks.hasModuleAccess.mockReturnValue(true);
|
||||
|
||||
apiMocks.rawMaterials.mockResolvedValue([{ id: 1 }]);
|
||||
apiMocks.mixes.mockResolvedValue([{ id: 2 }]);
|
||||
@@ -48,7 +52,15 @@ describe('route loaders use the SvelteKit fetch argument', () => {
|
||||
apiMocks.scenarios.mockResolvedValue([{ id: 5 }]);
|
||||
apiMocks.dataQuality.mockResolvedValue([{ id: 6 }]);
|
||||
apiMocks.clientAccess.mockResolvedValue([{ id: 7 }]);
|
||||
apiMocks.clientAccessExport.mockResolvedValue({ generated_at: '', clients: [] });
|
||||
apiMocks.clientAccessExport.mockResolvedValue({
|
||||
generated_at: '',
|
||||
client_rows: [],
|
||||
user_rows: [],
|
||||
feature_rows: [],
|
||||
permission_rows: [],
|
||||
audit_rows: [],
|
||||
clients: []
|
||||
});
|
||||
});
|
||||
|
||||
it('passes fetch through the home page loader', async () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { hasStoredClientSession } from '$lib/session';
|
||||
import { getStoredClientSession, hasModuleAccess, hasStoredClientSession } from '$lib/session';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
export async function load({ fetch }) {
|
||||
@@ -8,9 +8,11 @@ export async function load({ fetch }) {
|
||||
};
|
||||
}
|
||||
|
||||
const session = getStoredClientSession();
|
||||
|
||||
try {
|
||||
return {
|
||||
mixes: await api.mixes(fetch)
|
||||
mixes: hasModuleAccess(session, 'mix_master') ? await api.mixes(fetch) : []
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { api } from '$lib/api';
|
||||
import { hasStoredClientSession } from '$lib/session';
|
||||
import { getStoredClientSession, hasModuleAccess, hasStoredClientSession } from '$lib/session';
|
||||
|
||||
export async function load({ params, fetch }) {
|
||||
const mixId = Number(params.id);
|
||||
@@ -16,8 +16,19 @@ export async function load({ params, fetch }) {
|
||||
};
|
||||
}
|
||||
|
||||
const session = getStoredClientSession();
|
||||
if (!hasModuleAccess(session, 'mix_master')) {
|
||||
return {
|
||||
mix: null,
|
||||
rawMaterials: []
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const [mix, rawMaterials] = await Promise.all([api.mix(mixId, fetch), api.rawMaterials(fetch)]);
|
||||
const [mix, rawMaterials] = await Promise.all([
|
||||
api.mix(mixId, fetch),
|
||||
hasModuleAccess(session, 'raw_materials') ? api.rawMaterials(fetch) : Promise.resolve([])
|
||||
]);
|
||||
|
||||
return {
|
||||
mix,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { hasStoredClientSession } from '$lib/session';
|
||||
import { getStoredClientSession, hasModuleAccess, hasStoredClientSession } from '$lib/session';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
export async function load({ fetch }) {
|
||||
@@ -8,9 +8,11 @@ export async function load({ fetch }) {
|
||||
};
|
||||
}
|
||||
|
||||
const session = getStoredClientSession();
|
||||
|
||||
try {
|
||||
return {
|
||||
rawMaterials: await api.rawMaterials(fetch)
|
||||
rawMaterials: hasModuleAccess(session, 'mix_master') && hasModuleAccess(session, 'raw_materials') ? await api.rawMaterials(fetch) : []
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { hasStoredClientSession } from '$lib/session';
|
||||
import { getStoredClientSession, hasModuleAccess, hasStoredClientSession } from '$lib/session';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
export async function load({ fetch }) {
|
||||
@@ -9,8 +9,13 @@ export async function load({ fetch }) {
|
||||
};
|
||||
}
|
||||
|
||||
const session = getStoredClientSession();
|
||||
|
||||
try {
|
||||
const [products, productCosts] = await Promise.all([api.products(fetch), api.productCosts(fetch)]);
|
||||
const [products, productCosts] = await Promise.all([
|
||||
hasModuleAccess(session, 'products') ? api.products(fetch) : Promise.resolve([]),
|
||||
hasModuleAccess(session, 'products') ? api.productCosts(fetch) : Promise.resolve([])
|
||||
]);
|
||||
return {
|
||||
products,
|
||||
productCosts
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { hasStoredClientSession } from '$lib/session';
|
||||
import { getStoredClientSession, hasModuleAccess, hasStoredClientSession } from '$lib/session';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
export async function load({ fetch }) {
|
||||
@@ -11,12 +11,14 @@ export async function load({ fetch }) {
|
||||
};
|
||||
}
|
||||
|
||||
const session = getStoredClientSession();
|
||||
|
||||
try {
|
||||
const [rawMaterials, mixes, products, productCosts] = await Promise.all([
|
||||
api.rawMaterials(fetch),
|
||||
api.mixes(fetch),
|
||||
api.products(fetch),
|
||||
api.productCosts(fetch)
|
||||
hasModuleAccess(session, 'raw_materials') ? api.rawMaterials(fetch) : Promise.resolve([]),
|
||||
hasModuleAccess(session, 'mix_master') ? api.mixes(fetch) : Promise.resolve([]),
|
||||
hasModuleAccess(session, 'products') ? api.products(fetch) : Promise.resolve([]),
|
||||
hasModuleAccess(session, 'products') ? api.productCosts(fetch) : Promise.resolve([])
|
||||
]);
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { hasStoredClientSession } from '$lib/session';
|
||||
import { getStoredClientSession, hasModuleAccess, hasStoredClientSession } from '$lib/session';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
export async function load({ fetch }) {
|
||||
@@ -8,9 +8,11 @@ export async function load({ fetch }) {
|
||||
};
|
||||
}
|
||||
|
||||
const session = getStoredClientSession();
|
||||
|
||||
try {
|
||||
return {
|
||||
scenarios: await api.scenarios(fetch)
|
||||
scenarios: hasModuleAccess(session, 'scenarios') ? await api.scenarios(fetch) : []
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user