52 lines
2.2 KiB
JavaScript
52 lines
2.2 KiB
JavaScript
/**
|
|
* The PocketBase superuser's own entry points for reviewing a new,
|
|
* still-private layout mapping and approving it straight to "shared" -
|
|
* AdminLayoutReviewView.vue (layout mapper L.8) is the only consumer.
|
|
* Uses pbAdmin (pocketbaseAdminRepository.js), never the app user's own
|
|
* `pb` client - a superuser session lives in its own PocketBase auth
|
|
* collection (`_superusers`), entirely separate from the app's `users`
|
|
* collection, so this never touches or is affected by whatever app user
|
|
* (if any) is logged in on the same machine.
|
|
*/
|
|
import { pbAdmin } from '../repositories/pocketbaseAdminRepository'
|
|
|
|
export async function login(email, password) {
|
|
await pbAdmin.collection('_superusers').authWithPassword(email, password)
|
|
}
|
|
|
|
export function logout() {
|
|
pbAdmin.authStore.clear()
|
|
}
|
|
|
|
export function isLoggedIn() {
|
|
return pbAdmin.authStore.isValid
|
|
}
|
|
|
|
/** Every mapping awaiting review - a real superuser session bypasses every collection rule, so this sees every owner's own private mappings, not just one user's. */
|
|
export async function listPending() {
|
|
return pbAdmin.collection('layoutMappings').getFullList({
|
|
filter: 'status = "private"',
|
|
sort: '-created',
|
|
})
|
|
}
|
|
|
|
/** Promotes one mapping straight to shared, bypassing the second-user-confirmation path entirely. */
|
|
export async function approve(id) {
|
|
return pbAdmin.collection('layoutMappings').update(id, {
|
|
status: 'shared',
|
|
promotedReason: 'superuser_approved',
|
|
approvedBySuperuser: pbAdmin.authStore.record?.email || '',
|
|
promotedAt: new Date().toISOString(),
|
|
})
|
|
}
|
|
|
|
/** A mapping's own sourceDocument record, as the superuser - bypasses the owner-only rule documentsService.js's own pb client would be blocked by (a superuser session never shares that client or its session at all). */
|
|
export async function getSourceDocument(documentId) {
|
|
return pbAdmin.collection('documents').getOne(documentId)
|
|
}
|
|
|
|
/** Same shape as documentsService.sourceFileUrl, but resolved through the superuser's own pbAdmin client - needed since that document record was fetched as the superuser, not the (possibly nonexistent) logged-in app user. */
|
|
export function sourceFileUrl(record) {
|
|
return record?.sourceFile ? pbAdmin.files.getURL(record, record.sourceFile) : null
|
|
}
|