Skip to content

Commit

Permalink
Fix docker build and other issues
Browse files Browse the repository at this point in the history
  • Loading branch information
7dev7urandom committed Aug 29, 2024
1 parent 54f29cf commit 4b4e84a
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 147 deletions.
4 changes: 3 additions & 1 deletion deployment/development/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ volumes:
redis-data:
outdir:


services:
db:
image: postgres:10
Expand Down Expand Up @@ -98,8 +99,9 @@ services:
dockerfile: Dockerfile
ports:
- "5173:3000"
env_file: .env
env_file: source/SIL.AppBuilder.Portal/.env
environment:
VITE_DATABASE_URL: "postgresql://db-user:1234@db:5432/development?schema=public"
# MUST be included (the path the application will be accessed on) and MUST NOT have a trailing slash
ORIGIN: "http://localhost:5173"
redis:
Expand Down
2 changes: 2 additions & 0 deletions source/SIL.AppBuilder.Portal/common/databaseProxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const handlers = {
const obj: DataType = {};
for (const prop in Prisma.ModelName) {
const uncapitalized = prop[0].toLowerCase() + prop.substring(1);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
obj[uncapitalized] = prisma[uncapitalized];
}

Expand Down
2 changes: 2 additions & 0 deletions source/SIL.AppBuilder.Portal/common/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { ReadonlyClient } from './ReadonlyPrisma.js';
// other packages, but we keep the writable client behind the abstraction layer.

if (!process.env.VITE_DATABASE_URL)
// @ts-expect-error This is necessary for browser, where import.meta.env will in fact exist
process.env.VITE_DATABASE_URL = import.meta.env.VITE_DATABASE_URL;

const prisma = new PrismaClient();

export type PrismaClientExact = PrismaClient;
Expand Down
28 changes: 0 additions & 28 deletions source/SIL.AppBuilder.Portal/common/public/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,3 @@ export enum ProductTransitionType {
CancelWorkflow,
ProjectAccess
}

// export async function getOrganizationsForUser(userId: number) {
// const user = await prisma.users.findUnique({
// where: {
// Id: userId
// },
// include: { UserRoles: true, Organizations: true }
// });
// const organizations = user?.UserRoles.find((roleDef) => roleDef.RoleId === RoleId.SuperAdmin)
// ? await prisma.organizations.findMany({
// include: {
// Owner: true
// }
// })
// : await prisma.organizations.findMany({
// where: {
// OrganizationMemberships: {
// every: {
// UserId: userId
// }
// }
// },
// include: {
// Owner: true
// }
// });
// return organizations;
// }
4 changes: 2 additions & 2 deletions source/SIL.AppBuilder.Portal/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SvelteKitAuth, type DefaultSession, type SvelteKitAuthConfig } from '@a
import Auth0Provider from '@auth/sveltekit/providers/auth0';
import { redirect, type Handle } from '@sveltejs/kit';
import { DatabaseWrites, prisma } from 'sil.appbuilder.portal.common';
import { RoleId } from 'sil.appbuilder.portal.common/prisma';

declare module '@auth/sveltekit' {
interface Session {
Expand Down Expand Up @@ -44,11 +45,10 @@ const config: SvelteKitAuthConfig = {
// safest method is just handle such values in session below (see user.roles)
// user.isSuperAdmin is a special case handled here to give the /admin/jobs route
// access to see if the user has permission to see the BullMQ bull-board queue
console.log('SVELTE @jwt', token);
if (!profile) return token;
const dbUser = await DatabaseWrites.users.getOrCreateUser(profile);
token.userId = dbUser.Id;
token.isSuperAdmin = await isUserSuperAdmin(dbUser.Id);
token.isSuperAdmin = !!dbUser.UserRoles.find((r) => r.RoleId === RoleId.SuperAdmin);
return token;
},
async session({ session, token }) {
Expand Down
87 changes: 0 additions & 87 deletions source/SIL.AppBuilder.Portal/src/node-server/index.ts

This file was deleted.

9 changes: 0 additions & 9 deletions source/SIL.AppBuilder.Portal/src/node-server/tsconfig.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
];
</script>

<form action="/admin/settings" method="post">
<button type="submit" class="btn btn-primary">Add Test BullMQ task</button>
</form>

<TabbedMenu
routeId="/(authenticated)/admin/settings"
base="{base}/admin/settings"
Expand Down

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { PageServerLoad } from './$types';
export const load = (async ({ locals }) => {
const userId = (await locals.auth())?.user.userId;
if (!userId) return error(400);
// const orgs = await getOrganizationsForUser(userId);
const projects = await prisma.projects.findMany({
where: {
IsPublic: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import prisma from '$lib/prisma';
import { prisma } from 'sil.appbuilder.portal.common';
import type { PageServerLoad } from './$types';

export const load = (async ({ params }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
import { redirect } from '@sveltejs/kit';
import { getOrganizationsForUser } from 'sil.appbuilder.portal.common/prisma';
import { prisma } from 'sil.appbuilder.portal.common';
import { RoleId } from 'sil.appbuilder.portal.common/prisma';
import type { PageServerLoad } from './$types';

export const load = (async (event) => {
const auth = await event.locals.auth();
const organizations = await getOrganizationsForUser(auth!.user.userId);
const user = await prisma.users.findUnique({
where: {
Id: auth?.user.userId
},
include: { UserRoles: true, Organizations: true }
});
const organizations = user?.UserRoles.find((roleDef) => roleDef.RoleId === RoleId.SuperAdmin)
? await prisma.organizations.findMany({
include: {
Owner: true
}
})
: await prisma.organizations.findMany({
where: {
OrganizationMemberships: {
every: {
UserId: auth?.user.userId
}
}
},
include: {
Owner: true
}
});
if (organizations.length === 1) {
return redirect(302, '/organizations/' + organizations[0].Id + '/settings');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { updateProject } from '$lib/server/relationVerification/projects';
import { idSchema } from '$lib/valibot';
import { error } from '@sveltejs/kit';
import { prisma } from 'sil.appbuilder.portal.common';
import { DatabaseWrites, prisma } from 'sil.appbuilder.portal.common';
import { fail, superValidate } from 'sveltekit-superforms';
import { valibot } from 'sveltekit-superforms/adapters';
import * as v from 'valibot';
Expand Down Expand Up @@ -57,7 +56,7 @@ export const actions: Actions = {
const form = await superValidate(event.request, valibot(projectPropertyEditSchema));
if (!form.valid) return fail(400, { form, ok: false });
if (isNaN(parseInt(event.params.id))) return fail(400, { form, ok: false });
const success = await updateProject(parseInt(event.params.id), {
const success = await DatabaseWrites.projects.update(parseInt(event.params.id), {
Name: form.data.name,
GroupId: form.data.group,
OwnerId: form.data.owner,
Expand Down

0 comments on commit 4b4e84a

Please sign in to comment.