Handle users.demote event (#6315)

* fix: Handle users.demote event

* fix: fetchAll

* fix: fetch based on total
This commit is contained in:
Apoorv Mishra
2023-12-27 08:33:44 +05:30
committed by GitHub
parent 4fd0e99909
commit 08aacdb302
6 changed files with 56 additions and 19 deletions

View File

@@ -139,6 +139,7 @@ class Event extends IdModel {
"documents.restore",
"revisions.create",
"users.create",
"users.demote",
];
static AUDIT_EVENTS: TEvent["name"][] = [

View File

@@ -616,6 +616,12 @@ export default class WebsocketsProcessor {
.emit(event.name, presentTeam(team));
}
case "users.demote": {
return socketio
.to(`user-${event.userId}`)
.emit(event.name, { id: event.userId });
}
default:
return;
}

View File

@@ -759,17 +759,20 @@ router.post(
teamId: user.teamId,
id: collectionIds,
};
const collections = await Collection.scope({
method: ["withMembership", user.id],
}).findAll({
where,
order: [
Sequelize.literal('"collection"."index" collate "C"'),
["updatedAt", "DESC"],
],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
});
const [collections, total] = await Promise.all([
Collection.scope({
method: ["withMembership", user.id],
}).findAll({
where,
order: [
Sequelize.literal('"collection"."index" collate "C"'),
["updatedAt", "DESC"],
],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
}),
Collection.count({ where }),
]);
const nullIndex = collections.findIndex(
(collection) => collection.index === null
@@ -783,7 +786,7 @@ router.post(
}
ctx.body = {
pagination: ctx.state.pagination,
pagination: { ...ctx.state.pagination, total },
data: collections.map(presentCollection),
policies: presentPolicies(user, collections),
};

View File

@@ -152,12 +152,15 @@ router.post(
sort = "updatedAt";
}
const documents = await Document.defaultScopeWithUser(user.id).findAll({
where,
order: [[sort, direction]],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
});
const [documents, total] = await Promise.all([
Document.defaultScopeWithUser(user.id).findAll({
where,
order: [[sort, direction]],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
}),
Document.count({ where }),
]);
// index sort is special because it uses the order of the documents in the
// collection.documentStructure rather than a database column
@@ -172,7 +175,7 @@ router.post(
);
const policies = presentPolicies(user, documents);
ctx.body = {
pagination: ctx.state.pagination,
pagination: { ...ctx.state.pagination, total },
data,
policies,
};