Skip to content
Draft
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
3 changes: 2 additions & 1 deletion src/api/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { configPrivate } from '$config/private';
import type { RequestEvent } from '@sveltejs/kit';
import { GraphQLError } from 'graphql';

export const oidcRoles = ['admin', 'member', 'service_user'] as const;

Expand All @@ -20,7 +21,7 @@ export async function context(req: RequestEvent) {
...req.locals,
mustBeLoggedIn: () => {
if (!req.locals.oidc?.user) {
throw new Error('Must be logged in');
throw new GraphQLError('Must be logged in');
}

return req.locals.oidc.user;
Expand Down
25 changes: 16 additions & 9 deletions src/api/handlers/agendaItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,24 @@ import {
schemaBuilder,
arg as rumbleArg
} from '$api/rumble';
import { isDMUNEmail } from '$api/services/isDMUNEmail';
import { nanoid } from '$lib/helpers/nanoid';
import { assertFindFirstExists, assertFirstEntryExists } from '@m1212e/rumble';
import { GraphQLError } from 'graphql';

abilityBuilder.agendaItem.allow(['read']).when(({ mustBeLoggedIn }) => {
const user = mustBeLoggedIn();

return {
where: {
committee: {
conference: {
users: {
userEmail: user.email!
}
}
}
}
};
});

const ref = object({
table: 'agendaItem',
Expand All @@ -36,13 +50,6 @@ query({
table: 'agendaItem'
});

abilityBuilder.agendaItem.allow(['read']).when(({ mustBeLoggedIn }) => {
const user = mustBeLoggedIn();
if (user?.email && isDMUNEmail(user.email)) {
return 'allow';
}
});

schemaBuilder.mutationFields((t) => {
return {
createAgendaItem: t.drizzleField({
Expand Down
27 changes: 19 additions & 8 deletions src/api/handlers/committee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,30 @@ import {
schemaBuilder,
arg as rumbleArg
} from '$api/rumble';
import { isDMUNEmail } from '$api/services/isDMUNEmail';
import { assertFirstEntryExists } from '@m1212e/rumble';
import { and, count, eq, type InferSelectModel } from 'drizzle-orm';

const statusEnum = enum_({
tsName: 'committeeStatus'
abilityBuilder.committee.allow(['read']).when(({ mustBeLoggedIn }) => {
const user = mustBeLoggedIn();

return {
where: {
OR: [
{
members: {
user: {
userEmail: user.email
}
}
}
//TODO continue here
]
}
};
});

abilityBuilder.committee.allow(['read', 'update']).when(({ mustBeLoggedIn }) => {
const user = mustBeLoggedIn();
if (user?.email && isDMUNEmail(user.email)) {
return 'allow';
}
const statusEnum = enum_({
tsName: 'committeeStatus'
});

const getTotalPresentCount = async (
Expand Down
5 changes: 0 additions & 5 deletions src/api/services/isDMUNEmail.ts

This file was deleted.

Loading