Some checks failed
CI / skip-ci-check (push) Successful in 1m27s
CI / skip-ci-check (pull_request) Successful in 1m27s
CI / lint-and-type-check (pull_request) Has been cancelled
CI / python-lint (pull_request) Has been cancelled
CI / test-backend (pull_request) Has been cancelled
CI / build (pull_request) Has been cancelled
CI / secret-scanning (pull_request) Has been cancelled
CI / dependency-scan (pull_request) Has been cancelled
CI / sast-scan (pull_request) Has been cancelled
CI / workflow-summary (pull_request) Has been cancelled
CI / lint-and-type-check (push) Successful in 2m4s
CI / python-lint (push) Successful in 1m53s
CI / test-backend (push) Successful in 2m37s
CI / build (push) Failing after 2m13s
CI / secret-scanning (push) Successful in 1m40s
CI / dependency-scan (push) Successful in 1m34s
CI / sast-scan (push) Successful in 2m42s
CI / workflow-summary (push) Successful in 1m26s
This commit modifies the `.gitignore` file to exclude Python library directories while ensuring the viewer-frontend's `lib` directory is not ignored. It also updates the `package.json` to activate the virtual environment during backend tests, improving the testing process. Additionally, the CI workflow is enhanced to prevent duplicate runs for branches with open pull requests. Various components in the viewer frontend are updated to ensure consistent naming conventions and improve type safety. These changes contribute to a cleaner codebase and a more efficient development workflow.
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { auth } from '@/app/api/auth/[...nextauth]/route';
|
|
import { prismaAuth } from './db';
|
|
|
|
/**
|
|
* Check if the current user is an admin
|
|
*/
|
|
export async function isAdmin(): Promise<boolean> {
|
|
try {
|
|
const session = await auth();
|
|
|
|
if (!session?.user?.id) {
|
|
return false;
|
|
}
|
|
|
|
// First check if isAdmin is already in the session (faster, no DB query needed)
|
|
if (session.user.isAdmin !== undefined) {
|
|
return session.user.isAdmin === true;
|
|
}
|
|
|
|
// Fallback to database query if session doesn't have isAdmin
|
|
const userId = parseInt(session.user.id, 10);
|
|
if (isNaN(userId)) {
|
|
return false;
|
|
}
|
|
|
|
const user = await prismaAuth.user.findUnique({
|
|
where: { id: userId },
|
|
select: { isAdmin: true, isActive: true },
|
|
});
|
|
|
|
// User must be active to have admin permissions (treat null/undefined as true)
|
|
if (user?.isActive === false) {
|
|
return false;
|
|
}
|
|
|
|
return user?.isAdmin ?? false;
|
|
} catch (error: any) {
|
|
console.error('[isAdmin] Error checking admin status:', error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if the current user can approve identifications (admin only)
|
|
*/
|
|
export async function canApproveIdentifications(): Promise<boolean> {
|
|
return isAdmin();
|
|
}
|
|
|