1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-15 01:16:22 +02:00

Change request approvals table (#2347)

1. Added database table for change request approvals
2. Removed separate endpoint for applying. **Now all state changes will
go through same endpoint.**
This commit is contained in:
sjaanus 2022-11-09 09:40:47 +01:00 committed by GitHub
parent d998f4c67a
commit 5e14e80ae3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 18 deletions

View File

@ -47,7 +47,7 @@ export const ChangeRequestOverview: FC = () => {
projectId,
id
);
const { applyChanges } = useChangeRequestApi();
const { changeState } = useChangeRequestApi();
const { setToastData, setToastApiError } = useToast();
if (!changeRequest) {
@ -56,7 +56,9 @@ export const ChangeRequestOverview: FC = () => {
const onApplyChanges = async () => {
try {
await applyChanges(projectId, id);
await changeState(projectId, Number(id), {
state: 'Applied',
});
refetchChangeRequest();
setToastData({
type: 'success',

View File

@ -51,19 +51,6 @@ export const useChangeRequestApi = () => {
}
};
const applyChanges = async (project: string, changeRequestId: string) => {
const path = `api/admin/projects/${project}/change-requests/${changeRequestId}/apply`;
const req = createRequest(path, {
method: 'PUT',
});
try {
const response = await makeRequest(req.caller, req.id);
return response;
} catch (e) {
throw e;
}
};
const discardChangeRequestEvent = async (
project: string,
changeRequestId: number,
@ -82,7 +69,6 @@ export const useChangeRequestApi = () => {
return {
addChangeRequest,
applyChanges,
changeState,
discardChangeRequestEvent,
errors,

View File

@ -1,5 +1,9 @@
import { IAuthRequest } from '../server-impl';
import { IAuthRequest, User } from '../server-impl';
export function extractUsernameFromUser(user: User): string {
return user ? user.email || user.username : 'unknown';
}
export function extractUsername(req: IAuthRequest): string {
return req.user ? req.user.email || req.user.username : 'unknown';
return extractUsernameFromUser(req.user);
}

View File

@ -0,0 +1,24 @@
'use strict';
exports.up = function (db, callback) {
db.runSql(
`
CREATE TABLE IF NOT EXISTS change_request_approvals (
id serial primary key,
change_request_id integer NOT NULL REFERENCES change_requests(id) ON DELETE CASCADE,
created_by integer not null references users (id) ON DELETE CASCADE,
created_at timestamp default now()
);
`,
callback,
);
};
exports.down = function (db, callback) {
db.runSql(
`
DROP TABLE IF EXISTS change_request_approvals;
`,
callback,
);
};