Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#110 [FIX]: Validation of visualization hierarchy between protocols and applications #111

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum ItemGroupType {
}

enum ItemType {
TABLEROW
TEXTBOX
CHECKBOX
RADIO
Expand Down
37 changes: 27 additions & 10 deletions src/controllers/applicationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,28 @@ const validateVisibility = async (
const protocolViewers = await prismaClient.protocol.findUnique({
where: {
id: protocolId,
visibility: visibility,
answersVisibility: answersVisibility,
answersViewersUser: { every: { id: { in: answersViewersUsers } } },
answersViewersClassroom: { every: { id: { in: answersViewersClassrooms } } },
viewersUser: { every: { id: { in: viewersUsers } } },
viewersClassroom: { every: { id: { in: viewersClassrooms } } },
AND: [
{
OR: [
{ visibility: 'PUBLIC' },
{
visibility: visibility,
viewersUser: { every: { id: { in: viewersUsers } } },
viewersClassroom: { every: { id: { in: viewersClassrooms } } },
},
],
},
{
OR: [
{ answersVisibility: 'PUBLIC' },
{
answersVisibility: answersVisibility,
answersViewersUser: { every: { id: { in: answersViewersUsers } } },
answersViewersClassroom: { every: { id: { in: answersViewersClassrooms } } },
},
],
},
],
},
});

Expand Down Expand Up @@ -151,6 +167,7 @@ const fieldsWProtocol = {
type: true,
placement: true,
isRepeatable: true,
tableColumns: { select: { id: true, text: true, placement: true } },
items: {
orderBy: { placement: 'asc' as any },
select: {
Expand Down Expand Up @@ -244,10 +261,10 @@ export const updateApplication = async (req: Request, res: Response): Promise<vo
.shape({
visibility: yup.mixed<VisibilityMode>().oneOf(Object.values(VisibilityMode)),
answersVisibility: yup.mixed<VisibilityMode>().oneOf(Object.values(VisibilityMode)),
viewersUser: yup.array().of(yup.number()).required(),
viewersClassroom: yup.array().of(yup.number()).required(),
answersViewersUser: yup.array().of(yup.number()).required(),
answersViewersClassroom: yup.array().of(yup.number()).required(),
viewersUser: yup.array().of(yup.number()).default([]),
viewersClassroom: yup.array().of(yup.number()).default([]),
answersViewersUser: yup.array().of(yup.number()).default([]),
answersViewersClassroom: yup.array().of(yup.number()).default([]),
})
.noUnknown();
// Yup parsing/validation
Expand Down