mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
Merge pull request #2576 from nxglabs/sync-to-public_repo-27677371306
Merge pull request #2575 from nxglabs/staging
This commit is contained in:
@@ -8,6 +8,30 @@ export default async function updateTenant(request) {
|
||||
if (!request.user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'unauthorized');
|
||||
}
|
||||
|
||||
// Derive the caller's tenant and role server-side. Never trust the
|
||||
// client-supplied tenantId: an authenticated user may only update their own
|
||||
// tenant and must hold an admin role to do so.
|
||||
const callerQuery = new Parse.Query('contracts_Users');
|
||||
callerQuery.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: request.user.id,
|
||||
});
|
||||
callerQuery.notEqualTo('IsDisabled', true);
|
||||
const callerExtUser = await callerQuery.first({ useMasterKey: true });
|
||||
if (!callerExtUser) {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'User not found.');
|
||||
}
|
||||
const callerRole = callerExtUser.get('UserRole');
|
||||
if (callerRole !== 'contracts_Admin' && callerRole !== 'contracts_OrgAdmin') {
|
||||
throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, 'Unauthorized.');
|
||||
}
|
||||
const callerTenantId = callerExtUser.get('TenantId')?.id;
|
||||
if (!callerTenantId || callerTenantId !== tenantId) {
|
||||
throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, 'Unauthorized.');
|
||||
}
|
||||
|
||||
const validKeys = ['CompletionBody', 'CompletionSubject', 'RequestBody', 'RequestSubject'];
|
||||
try {
|
||||
const tenant = new Parse.Object('partners_Tenant');
|
||||
|
||||
Reference in New Issue
Block a user