fix: Suspended users showing in group and collection member management (#1302)
* fix: Suspended users showing in group and collection member management * test
This commit is contained in:
@@ -21,13 +21,22 @@ const { authorize } = policy;
|
||||
const router = new Router();
|
||||
|
||||
router.post('users.list', auth(), pagination(), async ctx => {
|
||||
const { query } = ctx.body;
|
||||
const { query, includeSuspended = false } = ctx.body;
|
||||
const user = ctx.state.user;
|
||||
|
||||
let where = {
|
||||
teamId: user.teamId,
|
||||
};
|
||||
|
||||
if (!includeSuspended) {
|
||||
where = {
|
||||
...where,
|
||||
suspendedAt: {
|
||||
[Op.eq]: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (query) {
|
||||
where = {
|
||||
...where,
|
||||
|
||||
@@ -14,6 +14,13 @@ describe('#users.list', async () => {
|
||||
it('should allow filtering by user name', async () => {
|
||||
const user = await buildUser({ name: 'Tester' });
|
||||
|
||||
// suspended user should not be returned
|
||||
await buildUser({
|
||||
name: 'Tester',
|
||||
teamId: user.teamId,
|
||||
suspendedAt: new Date(),
|
||||
});
|
||||
|
||||
const res = await server.post('/api/users.list', {
|
||||
body: {
|
||||
query: 'test',
|
||||
@@ -27,6 +34,27 @@ describe('#users.list', async () => {
|
||||
expect(body.data[0].id).toEqual(user.id);
|
||||
});
|
||||
|
||||
it('should allow including suspended', async () => {
|
||||
const user = await buildUser({ name: 'Tester' });
|
||||
await buildUser({
|
||||
name: 'Tester',
|
||||
teamId: user.teamId,
|
||||
suspendedAt: new Date(),
|
||||
});
|
||||
|
||||
const res = await server.post('/api/users.list', {
|
||||
body: {
|
||||
query: 'test',
|
||||
includeSuspended: true,
|
||||
token: user.getJwtToken(),
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.length).toEqual(2);
|
||||
});
|
||||
|
||||
it('should return teams paginated user list', async () => {
|
||||
const { admin, user } = await seed();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user