feat: Move get user API endpoint to admin namespace
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { renderObject } from '../../../../helpers/renderer.js';
|
import { renderObject } from '../../../../../helpers/renderer.js';
|
||||||
import User from '../../../../models/user.js';
|
import User from '../../../../../models/user.js';
|
||||||
|
|
||||||
export default async (request, response) => {
|
export default async (request, response) => {
|
||||||
const user = await User.query()
|
const user = await User.query()
|
@@ -0,0 +1,34 @@
|
|||||||
|
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||||
|
import request from 'supertest';
|
||||||
|
import app from '../../../../../app.js';
|
||||||
|
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id';
|
||||||
|
import { createUser } from '../../../../../../test/factories/user';
|
||||||
|
import { createRole } from '../../../../../../test/factories/role';
|
||||||
|
import getUserMock from '../../../../../../test/mocks/rest/api/v1/admin/users/get-user.js';
|
||||||
|
import * as license from '../../../../../helpers/license.ee.js';
|
||||||
|
|
||||||
|
describe('GET /api/v1/admin/users/:userId', () => {
|
||||||
|
let currentUser, currentUserRole, anotherUser, anotherUserRole, token;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
currentUserRole = await createRole({ key: 'admin' });
|
||||||
|
currentUser = await createUser({ roleId: currentUserRole.id });
|
||||||
|
|
||||||
|
anotherUser = await createUser();
|
||||||
|
anotherUserRole = await anotherUser.$relatedQuery('role');
|
||||||
|
|
||||||
|
token = createAuthTokenByUserId(currentUser.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return specified user info', async () => {
|
||||||
|
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||||
|
|
||||||
|
const response = await request(app)
|
||||||
|
.get(`/api/v1/admin/users/${anotherUser.id}`)
|
||||||
|
.set('Authorization', token)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const expectedPayload = getUserMock(anotherUser, anotherUserRole);
|
||||||
|
expect(response.body).toEqual(expectedPayload);
|
||||||
|
});
|
||||||
|
});
|
@@ -1,36 +0,0 @@
|
|||||||
import { describe, it, expect, beforeEach } from 'vitest';
|
|
||||||
import request from 'supertest';
|
|
||||||
import app from '../../../../app.js';
|
|
||||||
import createAuthTokenByUserId from '../../../../helpers/create-auth-token-by-user-id';
|
|
||||||
import { createUser } from '../../../../../test/factories/user';
|
|
||||||
import { createPermission } from '../../../../../test/factories/permission';
|
|
||||||
import getUserMock from '../../../../../test/mocks/rest/api/v1/users/get-user';
|
|
||||||
|
|
||||||
describe('GET /api/v1/users/:userId', () => {
|
|
||||||
let currentUser, currentUserRole, anotherUser, anotherUserRole, token;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
currentUser = await createUser();
|
|
||||||
anotherUser = await createUser();
|
|
||||||
currentUserRole = await currentUser.$relatedQuery('role');
|
|
||||||
anotherUserRole = await anotherUser.$relatedQuery('role');
|
|
||||||
|
|
||||||
await createPermission({
|
|
||||||
roleId: currentUserRole.id,
|
|
||||||
action: 'read',
|
|
||||||
subject: 'User',
|
|
||||||
});
|
|
||||||
|
|
||||||
token = createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return specified user info', async () => {
|
|
||||||
const response = await request(app)
|
|
||||||
.get(`/api/v1/users/${anotherUser.id}`)
|
|
||||||
.set('Authorization', token)
|
|
||||||
.expect(200);
|
|
||||||
|
|
||||||
const expectedPayload = getUserMock(anotherUser, anotherUserRole);
|
|
||||||
expect(response.body).toEqual(expectedPayload);
|
|
||||||
});
|
|
||||||
});
|
|
@@ -3,6 +3,7 @@ import { authenticateUser } from '../../../../helpers/authentication.js';
|
|||||||
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
import { authorizeAdmin } from '../../../../helpers/authorization.js';
|
||||||
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
import { checkIsEnterprise } from '../../../../helpers/check-is-enterprise.js';
|
||||||
import getUsersAction from '../../../../controllers/api/v1/admin/users/get-users.ee.js';
|
import getUsersAction from '../../../../controllers/api/v1/admin/users/get-users.ee.js';
|
||||||
|
import getUserAction from '../../../../controllers/api/v1/admin/users/get-user.ee.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@@ -14,4 +15,12 @@ router.get(
|
|||||||
getUsersAction
|
getUsersAction
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/:userId',
|
||||||
|
authenticateUser,
|
||||||
|
authorizeAdmin,
|
||||||
|
checkIsEnterprise,
|
||||||
|
getUserAction
|
||||||
|
);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -1,15 +1,13 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import { authenticateUser } from '../../../helpers/authentication.js';
|
import { authenticateUser } from '../../../helpers/authentication.js';
|
||||||
import { authorizeUser } from '../../../helpers/authorization.js';
|
|
||||||
import checkIsCloud from '../../../helpers/check-is-cloud.js';
|
import checkIsCloud from '../../../helpers/check-is-cloud.js';
|
||||||
import getCurrentUserAction from '../../../controllers/api/v1/users/get-current-user.js';
|
import getCurrentUserAction from '../../../controllers/api/v1/users/get-current-user.js';
|
||||||
import getUserAction from '../../../controllers/api/v1/users/get-user.js';
|
|
||||||
import getUserTrialAction from '../../../controllers/api/v1/users/get-user-trial.ee.js';
|
import getUserTrialAction from '../../../controllers/api/v1/users/get-user-trial.ee.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/me', authenticateUser, getCurrentUserAction);
|
router.get('/me', authenticateUser, getCurrentUserAction);
|
||||||
router.get('/:userId', authenticateUser, authorizeUser, getUserAction);
|
|
||||||
router.get(
|
router.get(
|
||||||
'/:userId/trial',
|
'/:userId/trial',
|
||||||
authenticateUser,
|
authenticateUser,
|
||||||
|
Reference in New Issue
Block a user