mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
Improves the existing document rejection process by actually marking a document as completed cancelling further actions. ## Related Issue N/A ## Changes Made - Added a new rejection status for documents - Updated a million areas that check for document completion - Updated email sending, so rejection is confirmed for the rejecting recipient while other recipients are notified that the document is now cancelled. ## Testing Performed - Ran the testing suite to ensure there are no regressions. - Performed manual testing of current core flows.
123 lines
4.0 KiB
TypeScript
123 lines
4.0 KiB
TypeScript
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
|
import { findDocuments } from '@documenso/lib/server-only/admin/get-all-documents';
|
|
import { getEntireDocument } from '@documenso/lib/server-only/admin/get-entire-document';
|
|
import { updateRecipient } from '@documenso/lib/server-only/admin/update-recipient';
|
|
import { updateUser } from '@documenso/lib/server-only/admin/update-user';
|
|
import { sealDocument } from '@documenso/lib/server-only/document/seal-document';
|
|
import { sendDeleteEmail } from '@documenso/lib/server-only/document/send-delete-email';
|
|
import { superDeleteDocument } from '@documenso/lib/server-only/document/super-delete-document';
|
|
import { upsertSiteSetting } from '@documenso/lib/server-only/site-settings/upsert-site-setting';
|
|
import { deleteUser } from '@documenso/lib/server-only/user/delete-user';
|
|
import { disableUser } from '@documenso/lib/server-only/user/disable-user';
|
|
import { enableUser } from '@documenso/lib/server-only/user/enable-user';
|
|
import { getUserById } from '@documenso/lib/server-only/user/get-user-by-id';
|
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
|
|
|
import { adminProcedure, router } from '../trpc';
|
|
import {
|
|
ZAdminDeleteDocumentMutationSchema,
|
|
ZAdminDeleteUserMutationSchema,
|
|
ZAdminDisableUserMutationSchema,
|
|
ZAdminEnableUserMutationSchema,
|
|
ZAdminFindDocumentsQuerySchema,
|
|
ZAdminResealDocumentMutationSchema,
|
|
ZAdminUpdateProfileMutationSchema,
|
|
ZAdminUpdateRecipientMutationSchema,
|
|
ZAdminUpdateSiteSettingMutationSchema,
|
|
} from './schema';
|
|
|
|
export const adminRouter = router({
|
|
findDocuments: adminProcedure.input(ZAdminFindDocumentsQuerySchema).query(async ({ input }) => {
|
|
const { query, page, perPage } = input;
|
|
|
|
return await findDocuments({ query, page, perPage });
|
|
}),
|
|
|
|
updateUser: adminProcedure
|
|
.input(ZAdminUpdateProfileMutationSchema)
|
|
.mutation(async ({ input }) => {
|
|
const { id, name, email, roles } = input;
|
|
|
|
return await updateUser({ id, name, email, roles });
|
|
}),
|
|
|
|
updateRecipient: adminProcedure
|
|
.input(ZAdminUpdateRecipientMutationSchema)
|
|
.mutation(async ({ input }) => {
|
|
const { id, name, email } = input;
|
|
|
|
return await updateRecipient({ id, name, email });
|
|
}),
|
|
|
|
updateSiteSetting: adminProcedure
|
|
.input(ZAdminUpdateSiteSettingMutationSchema)
|
|
.mutation(async ({ ctx, input }) => {
|
|
const { id, enabled, data } = input;
|
|
|
|
return await upsertSiteSetting({
|
|
id,
|
|
enabled,
|
|
data,
|
|
userId: ctx.user.id,
|
|
});
|
|
}),
|
|
|
|
resealDocument: adminProcedure
|
|
.input(ZAdminResealDocumentMutationSchema)
|
|
.mutation(async ({ input }) => {
|
|
const { id } = input;
|
|
|
|
const document = await getEntireDocument({ id });
|
|
|
|
const isResealing = isDocumentCompleted(document.status);
|
|
|
|
return await sealDocument({ documentId: id, isResealing });
|
|
}),
|
|
|
|
enableUser: adminProcedure.input(ZAdminEnableUserMutationSchema).mutation(async ({ input }) => {
|
|
const { id } = input;
|
|
|
|
const user = await getUserById({ id }).catch(() => null);
|
|
|
|
if (!user) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
message: 'User not found',
|
|
});
|
|
}
|
|
|
|
return await enableUser({ id });
|
|
}),
|
|
|
|
disableUser: adminProcedure.input(ZAdminDisableUserMutationSchema).mutation(async ({ input }) => {
|
|
const { id } = input;
|
|
|
|
const user = await getUserById({ id }).catch(() => null);
|
|
|
|
if (!user) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
message: 'User not found',
|
|
});
|
|
}
|
|
|
|
return await disableUser({ id });
|
|
}),
|
|
|
|
deleteUser: adminProcedure.input(ZAdminDeleteUserMutationSchema).mutation(async ({ input }) => {
|
|
const { id } = input;
|
|
|
|
return await deleteUser({ id });
|
|
}),
|
|
|
|
deleteDocument: adminProcedure
|
|
.input(ZAdminDeleteDocumentMutationSchema)
|
|
.mutation(async ({ ctx, input }) => {
|
|
const { id, reason } = input;
|
|
await sendDeleteEmail({ documentId: id, reason });
|
|
|
|
return await superDeleteDocument({
|
|
id,
|
|
requestMetadata: ctx.metadata.requestMetadata,
|
|
});
|
|
}),
|
|
});
|