fix: splitQuery

This commit is contained in:
Grégoire Cutzach 2024-09-09 19:33:06 +02:00
parent 346c9fc0b4
commit a83c0ee660
No known key found for this signature in database
GPG Key ID: AA4155BE23C375E6

View File

@ -2016,30 +2016,29 @@ export class HomeDBManager extends EventEmitter {
const result = await this._connection.transaction(async manager => { const result = await this._connection.transaction(async manager => {
const analysis = await this._usersManager.verifyAndLookupDeltaEmails(userId, delta, false, manager); const analysis = await this._usersManager.verifyAndLookupDeltaEmails(userId, delta, false, manager);
let {userIdDelta} = analysis; let {userIdDelta} = analysis;
let wsQuery = this._workspace(scope, wsId, { const options = {
manager, manager,
markPermissions: analysis.permissionThreshold, markPermissions: analysis.permissionThreshold,
}) };
// Join the workspace's ACL rules and groups/users so we can edit them. let wsQuery = this._buildWorkspaceWithACLRules(scope, wsId, options);
.leftJoinAndSelect('workspaces.aclRules', 'acl_rules')
.leftJoinAndSelect('acl_rules.group', 'workspace_groups')
.leftJoinAndSelect('workspace_groups.memberUsers', 'workspace_users')
// Join the workspace's org and org member groups so we know what should be inherited.
.leftJoinAndSelect('workspaces.org', 'org')
.leftJoinAndSelect('org.aclRules', 'org_acl_rules')
.leftJoinAndSelect('org_acl_rules.group', 'org_groups')
.leftJoinAndSelect('org_groups.memberUsers', 'org_users');
wsQuery = this._addFeatures(wsQuery, 'org');
wsQuery = this._withAccess(wsQuery, userId, 'workspaces'); wsQuery = this._withAccess(wsQuery, userId, 'workspaces');
const queryResult = await verifyEntity(wsQuery); const wsQueryResult = await verifyEntity(wsQuery);
if (queryResult.status !== 200) {
if (wsQueryResult.status !== 200) {
// If the query for the workspace failed, return the failure result. // If the query for the workspace failed, return the failure result.
return queryResult; return wsQueryResult;
} }
this._failIfPowerfulAndChangingSelf(analysis, queryResult); this._failIfPowerfulAndChangingSelf(analysis, wsQueryResult);
const ws: Workspace = queryResult.data; const ws: Workspace = wsQueryResult.data;
const orgId = ws.org.id;
let orgQuery = this._buildOrgWithACLRulesQuery(scope, orgId, options);
orgQuery = this._addFeatures(orgQuery);
const orgQueryResult = await verifyEntity(orgQuery);
const org: Organization = orgQueryResult.data;
// Get all the non-guest groups on the org. // Get all the non-guest groups on the org.
const orgGroups = getNonGuestGroups(ws.org); const orgGroups = getNonGuestGroups(org);
// Get all the non-guest groups to be updated by the delta. // Get all the non-guest groups to be updated by the delta.
const groups = getNonGuestGroups(ws); const groups = getNonGuestGroups(ws);
if ('maxInheritedRole' in delta) { if ('maxInheritedRole' in delta) {
@ -2062,7 +2061,7 @@ export class HomeDBManager extends EventEmitter {
await this._updateUserPermissions(groups, userIdDelta, manager); await this._updateUserPermissions(groups, userIdDelta, manager);
this._checkUserChangeAllowed(userId, groups); this._checkUserChangeAllowed(userId, groups);
const nonOrgMembersAfter = this._usersManager.getUserDifference(groups, orgGroups); const nonOrgMembersAfter = this._usersManager.getUserDifference(groups, orgGroups);
const features = ws.org.billingAccount.getFeatures(); const features = org.billingAccount.getFeatures();
const limit = features.maxSharesPerWorkspace; const limit = features.maxSharesPerWorkspace;
if (limit !== undefined) { if (limit !== undefined) {
this._restrictShares(null, limit, removeRole(nonOrgMembersBefore), this._restrictShares(null, limit, removeRole(nonOrgMembersBefore),
@ -2072,7 +2071,7 @@ export class HomeDBManager extends EventEmitter {
await manager.save(groups); await manager.save(groups);
// If the users in workspace were changed, make a call to repair the guests in the org. // If the users in workspace were changed, make a call to repair the guests in the org.
if (userIdDelta) { if (userIdDelta) {
await this._repairOrgGuests(scope, ws.org.id, manager); await this._repairOrgGuests(scope, orgId, manager);
notifications.push(this._inviteNotification(userId, ws, userIdDelta, membersBefore)); notifications.push(this._inviteNotification(userId, ws, userIdDelta, membersBefore));
} }
return { return {
@ -4652,9 +4651,8 @@ export class HomeDBManager extends EventEmitter {
return { personal: true, public: !realAccess }; return { personal: true, public: !realAccess };
} }
private _getWorkspaceWithACLRules(scope: Scope, wsId: number, options: Partial<QueryOptions> = {}) { private _buildWorkspaceWithACLRules(scope: Scope, wsId: number, options: Partial<QueryOptions> = {}) {
const query = this._workspace(scope, wsId, { return this._workspace(scope, wsId, {
markPermissions: Permissions.VIEW,
...options ...options
}) })
// Join the workspace's ACL rules (with 1st level groups/users listed). // Join the workspace's ACL rules (with 1st level groups/users listed).
@ -4664,6 +4662,13 @@ export class HomeDBManager extends EventEmitter {
.leftJoinAndSelect('workspace_groups.memberGroups', 'workspace_group_groups') .leftJoinAndSelect('workspace_groups.memberGroups', 'workspace_group_groups')
.leftJoinAndSelect('workspace_group_users.logins', 'workspace_user_logins') .leftJoinAndSelect('workspace_group_users.logins', 'workspace_user_logins')
.leftJoinAndSelect('workspaces.org', 'org'); .leftJoinAndSelect('workspaces.org', 'org');
}
private _getWorkspaceWithACLRules(scope: Scope, wsId: number, options: Partial<QueryOptions> = {}) {
const query = this._buildWorkspaceWithACLRules(scope, wsId, {
markPermissions: Permissions.VIEW,
...options
});
return verifyEntity(query); return verifyEntity(query);
} }