mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
Merge pull request #976 from OpenSignLabs/multiuser_issue
This commit is contained in:
@@ -58,6 +58,8 @@ import updateOrganization from './parsefunction/updateOrganization.js';
|
||||
import getTeams from './parsefunction/getTeams.js';
|
||||
import addTeam from './parsefunction/addTeam.js';
|
||||
import updateTeam from './parsefunction/updateTeam.js';
|
||||
import getOrgAdmins from './parsefunction/getOrgAdmins.js';
|
||||
import getAllUserTeamByOrg from './parsefunction/getAllUserTeamByOrg.js';
|
||||
|
||||
// This afterSave function triggers after an object is added or updated in the specified class, allowing for post-processing logic.
|
||||
Parse.Cloud.afterSave('contracts_Document', DocumentAftersave);
|
||||
@@ -125,3 +127,5 @@ Parse.Cloud.define('updateorganization', updateOrganization);
|
||||
Parse.Cloud.define('getteams', getTeams);
|
||||
Parse.Cloud.define('addteam', addTeam);
|
||||
Parse.Cloud.define('updateteam', updateTeam);
|
||||
Parse.Cloud.define('getorgadmins', getOrgAdmins);
|
||||
Parse.Cloud.define('getalluserteambyorg', getAllUserTeamByOrg);
|
||||
|
||||
@@ -48,6 +48,15 @@ export default async function addOrganization(request) {
|
||||
objectId: resExt.id,
|
||||
});
|
||||
const newResOrg = await newOrg.save(null, { useMasterKey: true });
|
||||
const teamCls = new Parse.Object('contracts_Teams');
|
||||
teamCls.set('Name', 'All Users');
|
||||
teamCls.set('OrganizationId', {
|
||||
__type: 'Pointer',
|
||||
className: 'contracts_Organizations',
|
||||
objectId: newResOrg.id,
|
||||
});
|
||||
teamCls.set('IsActive', true);
|
||||
await teamCls.save(null, { useMasterKey: true });
|
||||
if (newResOrg) {
|
||||
return newResOrg;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
export default async function getAllUserTeamByOrg(request) {
|
||||
const OrgId = request.params.orgId;
|
||||
if (!request?.user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
|
||||
}
|
||||
try {
|
||||
const teamCls = new Parse.Query('contracts_Teams');
|
||||
teamCls.equalTo('OrganizationId', {
|
||||
__type: 'Pointer',
|
||||
className: 'contracts_Organizations',
|
||||
objectId: OrgId,
|
||||
});
|
||||
teamCls.equalTo('IsActive', true);
|
||||
const teamRes = await teamCls.first({ useMasterKey: true });
|
||||
if (teamRes) {
|
||||
return teamRes;
|
||||
} else {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Team not found.');
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in getOrganizations', err);
|
||||
const code = err?.code || 400;
|
||||
const msg = err?.message || 'Something went wrong.';
|
||||
throw new Parse.Error(code, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
export default async function getOrgAdmins(req) {
|
||||
if (!req?.user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
|
||||
} else {
|
||||
try {
|
||||
const extUser = new Parse.Query('contracts_Users');
|
||||
extUser.equalTo('UserRole', 'contracts_OrgAdmin');
|
||||
extUser.equalTo('CreatedBy', req?.user);
|
||||
extUser.notEqualTo('UserId', req?.user);
|
||||
extUser.include('TeamIds,OrganizationId');
|
||||
extUser.descending('createdAt');
|
||||
const userRes = await extUser.find({ useMasterKey: true });
|
||||
if (userRes.length > 0) {
|
||||
const _userRes = JSON.parse(JSON.stringify(userRes));
|
||||
return _userRes;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in getOrgAdmins', err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ export default async function getOrganizations(request) {
|
||||
const limit = request.params.limit || 200;
|
||||
const skip = request.params.skip || 0;
|
||||
const extUserId = request.params.extUserId;
|
||||
const activeOrgs = request.params.active;
|
||||
if (!request?.user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
|
||||
}
|
||||
@@ -17,7 +18,9 @@ export default async function getOrganizations(request) {
|
||||
className: 'contracts_Users',
|
||||
objectId: extUserId,
|
||||
});
|
||||
orgQuery.equalTo('IsActive', true);
|
||||
if (activeOrgs) {
|
||||
orgQuery.equalTo('IsActive', true);
|
||||
}
|
||||
orgQuery.exclude('ExtUserId');
|
||||
orgQuery.limit(limit);
|
||||
orgQuery.skip(skip);
|
||||
|
||||
Reference in New Issue
Block a user