Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"docker:dobbelOmega:run": "docker compose -f docker-compose.dev.yml exec projectnext /bin/sh -c 'npm run dobbelOmega:run'",
"docker:seed": "docker compose -f docker-compose.dev.yml exec projectnext /bin/sh -c 'npm run seed'",
"seed": "npx prisma db push --force-reset --skip-generate && IGNORE_SERVER_ONLY=true npx prisma db seed",
"dev-seed": "(if [ ! -d './node_modules/.prisma-dobbel-omega' ]; then npm run dobbelOmega-generate; fi) && npm run seed && npm run dev"
"dev-seed": "(if [ ! -d './node_modules/.prisma-dobbel-omega' ]; then npm run dobbelOmega:generate; fi) && npm run seed && npm run dev"
},
"prisma": {
"schema": "src/prisma/schema",
Expand Down
7 changes: 0 additions & 7 deletions src/app/api/users/connectStudentCard/route.ts

This file was deleted.

32 changes: 32 additions & 0 deletions src/app/connect-student-card/[newCard]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Form from '@/components/Form/Form'
import PageWrapper from '@/components/PageWrapper/PageWrapper'
import { configureAction } from '@/services/configureAction'
import { connectStudentCardAction } from '@/services/users/actions'


export default async function ConnectStucentCard({ params }: { params: Promise<{ newCard: string }> }) {
const newCard = (await params).newCard

const cardParsed = parseInt(newCard, 10)

if (isNaN(cardParsed)) {
return <p>Kortet er ikke gyldig. Det må være et heltall.</p>
}


return <PageWrapper
title="Registrert Student Kort"
>
<p>Trykk på knappen under for å registrere kortet ditt: <b>{cardParsed}</b></p>

<Form
submitText="Registrer kort"
action={configureAction(connectStudentCardAction, {
params: {
studentCard: cardParsed
}
})}
>
</Form>
</PageWrapper>
}
4 changes: 2 additions & 2 deletions src/app/events/[nameAndId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default async function Event({ params }: PropTypes) {

const tags = unwrapActionReturn(await readEventTagsAction())

const ownRegitration = event.eventRegistrations.length ? event.eventRegistrations[0] : undefined
const ownRegistration = event.eventRegistrations.length ? event.eventRegistrations[0] : undefined

return (
<div className={styles.wrapper}>
Expand Down Expand Up @@ -111,7 +111,7 @@ export default async function Event({ params }: PropTypes) {
{event.waitingList && <p>
På venteliste: {event.numOnWaitingList}
</p>}
<RegistrationUI event={event} registration={ownRegitration} onWaitingList={event.onWaitingList} />
<RegistrationUI event={event} registration={ownRegistration} onWaitingList={event.onWaitingList} />
</> : <p>
<FontAwesomeIcon icon={faExclamation} />
Dette arrangementet tar ikke påmeldinger
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions src/app/users/[username]/(user-admin)/settings/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import RegisterStudentCardButton from './RegisterStudentCardButton'
import { getProfileForAdmin } from '@/app/users/[username]/(user-admin)/getProfileForAdmin'
import Image from '@/components/Image/Image'
import type { PropTypes } from '@/app/users/[username]/page'
Expand All @@ -10,7 +9,6 @@ export default async function UserSettings({ params }: PropTypes) {
<div>
<h2>Generelle Instillinger</h2>
<Image width={300} image={profile.user.image} />
<RegisterStudentCardButton userId={profile.user.id} />
</div>
)
}
2 changes: 0 additions & 2 deletions src/prisma/schema/permission.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ enum Permission {
USERS_DESTROY
USERS_CREATE

USERS_CONNECT_STUDENT_CARD

IMAGE_COLLECTION_CREATE
IMAGE_ADMIN

Expand Down
7 changes: 0 additions & 7 deletions src/prisma/schema/user.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ model User {

dots DotWrapper[] @relation(name: "dot_user")
dotsAccused DotWrapper[] @relation(name: "dot_accuser")
registerStudentCardQueue RegisterStudentCardQueue[]
Event Event[]

cabinBooking Booking[] @relation()
Expand Down Expand Up @@ -70,12 +69,6 @@ model FeideAccount {
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
}

model RegisterStudentCardQueue {
userId Int @id
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
expiry DateTime
}

model ContactDetails {
id Int @id @default(autoincrement())
name String
Expand Down
10 changes: 5 additions & 5 deletions src/prisma/seeder/src/dobbelOmega/migrateCommittees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export default async function migrateCommittees(
// })).order

await Promise.all(committees.map(async committee => {
const committeeParagraph = await readCommitteParagraph(`${committee.shortName}_p.md`)
const committeArticle = await readCommitteArticle(`${committee.shortName}_a.md`)
const committeeParagraph = await readCommitteParagraph(`${committee.shortname}_p.md`)
const committeArticle = await readCommitteArticle(`${committee.shortname}_a.md`)

const newCommittee = await pnPrisma.committee.create({
data: {
name: committee.name,
shortName: committee.shortName,
shortName: committee.shortname,
videoLink: committee.applicationVideo,
logoImage: {
create: {
Expand All @@ -85,7 +85,7 @@ export default async function migrateCommittees(
name: committee.name,
coverImage: {
create: {
name: `${committee.shortName}'s bilde`
name: `${committee.shortname}'s bilde`
}
},
articleSections: committeArticle
Expand All @@ -102,7 +102,7 @@ export default async function migrateCommittees(

await Promise.all(committee.CommitteeMembers.map(async member => {
if (member.UserId === null) {
console.warn(`${committee.shortName} has a member that is not connected to a user!`)
console.warn(`${committee.shortname} has a member that is not connected to a user!`)
console.warn(member)
return
}
Expand Down
36 changes: 31 additions & 5 deletions src/prisma/seeder/src/dobbelOmega/migrateUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ type ExtendedMemberGroup = Prisma.OmegaMembershipGroupGetPayload<{
const userIncluder = {
StudyProgrammes: {
select: {
years: true
}
}
}
years: true,
},
},
MoneySourceAccounts: {
select: {
NTNUCard: true,
},
},
} satisfies VevenPrisma.UsersInclude

type userExtended = VevenPrisma.UsersGetPayload<{
include: typeof userIncluder
}>
Expand Down Expand Up @@ -192,7 +198,8 @@ export class UserMigrator {
updatedAt: user.updatedAt,
imageId: vevenIdToPnId(this.imageIdMap, user.ImageId),
archived: user.archived,
}
} satisfies Prisma.UserUncheckedCreateInput

try {
pnUser = await this.pnPrisma.user.create({
data: userData
Expand All @@ -215,6 +222,25 @@ export class UserMigrator {
}
this.userIdMap[user.id] = pnUser.id

// Try to add the studentCard, this can throw an unique contraint exception
if (user.MoneySourceAccounts?.NTNUCard) {
try {
await this.pnPrisma.user.update({
where: {
id: pnUser.id
},
data: {
studentCard: user.MoneySourceAccounts?.NTNUCard
}
})
} catch (e) {
console.error(
`Failed to conenct StudentCard to user. StudentCard: ${user.MoneySourceAccounts?.NTNUCard} `,
`User: ${pnUser} Error: ${e}`
)
}
}

return pnUser
}

Expand Down
14 changes: 7 additions & 7 deletions src/prisma/vevenSchema/schema.veven.prisma
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
datasource db {
provider = "postgresql"
url = env("VEVEN_DB_URI")
}

generator veven {
provider = "prisma-client-js"
output = "../../../node_modules/.prisma-dobbel-omega"
}

datasource db {
provider = "postgresql"
url = env("VEVEN_DB_URI")
}

model AliasAssociations {
MailAliasId Int
UserId Int
Expand Down Expand Up @@ -109,7 +109,7 @@ model CommitteeMembersHist {
model Committees {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
shortName String @unique @db.VarChar(255)
shortname String @unique @db.VarChar(255)
applicationLead String?
applicationVideo String? @db.VarChar(255)
applicationText String?
Expand Down Expand Up @@ -509,7 +509,7 @@ model PollVotes {
model Polls {
id Int @id @default(autoincrement())
question String
deadline DateTime @default(dbgenerated("'2022-10-17 19:43:15.587+02'::timestamp with time zone")) @db.Timestamptz(6)
deadline DateTime @default(dbgenerated("'2022-10-17 17:43:15.587+00'::timestamp with time zone")) @db.Timestamptz(6)
anonymous Boolean @default(false)
allow enum_Polls_allow @default(everyone)
createdAt DateTime @db.Timestamptz(6)
Expand Down
6 changes: 0 additions & 6 deletions src/services/permissions/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,6 @@ export const permissionConfig = {
description: 'kan oppdatere bruker',
category: 'brukere',
},
USERS_CONNECT_STUDENT_CARD: {
name: 'Koble studentkort til andre brukere',
description: `Kan legge til andre personer i registreringskøen for å
registrere et kort og kan registrere et kort på en person`,
category: 'brukere'
},
IMAGE_ADMIN: {
name: 'Bildeadministrator',
description: 'kan administrere bilder',
Expand Down
3 changes: 2 additions & 1 deletion src/services/users/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ export const readGroupsForPageFilteringAction = makeAction(groupOperations.readG
export const updateUserAction = makeAction(userOperations.update)
export const registerNewEmailAction = makeAction(userOperations.registerNewEmail)
export const registerUser = makeAction(userOperations.register)
export const registerStudentCardInQueueAction = makeAction(userOperations.registerStudentCardInQueue)

export const connectStudentCardAction = makeAction(userOperations.connectStudentCard)
4 changes: 2 additions & 2 deletions src/services/users/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RequirePermission } from '@/auth/auther/RequirePermission'
import { RequireUser } from '@/auth/auther/RequireUser'
import { RequireUserFieldOrPermission } from '@/auth/auther/RequireUserFieldOrPermission'
import { RequireUserId } from '@/auth/auther/RequireUserId'
import { RequireUserIdOrPermission } from '@/auth/auther/RequireUserIdOrPermission'
Expand All @@ -10,8 +11,7 @@ export const userAuth = {
readOrNull: RequireUserFieldOrPermission.staticFields({ permission: 'USERS_READ' }),
readPage: RequirePermission.staticFields({ permission: 'USERS_READ' }),
create: RequirePermission.staticFields({ permission: 'USERS_CREATE' }),
connectStudentCard: RequirePermission.staticFields({ permission: 'USERS_CONNECT_STUDENT_CARD' }),
registerStudentCardInQueue: RequireUserIdOrPermission.staticFields({ permission: 'USERS_CONNECT_STUDENT_CARD' }),
connectStudentCard: RequireUser.staticFields({}),
registerNewEmail: RequireUserIdOrPermission.staticFields({ permission: 'USERS_UPDATE' }),
updatePassword: RequireUserIdOrPermission.staticFields({ permission: 'USERS_UPDATE' }),
update: RequirePermission.staticFields({ permission: 'USERS_UPDATE' }),
Expand Down
1 change: 0 additions & 1 deletion src/services/users/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createSelection } from '@/services/createSelection'
import type { Prisma, User, SEX } from '@prisma/client'

export const maxNumberOfGroupsInFilter = 7
export const studentCardRegistrationExpiry = 2 // minutter

// TODO: This needs to be divived into seperate filters, depending on how much information is needed
export const userFieldsToExpose = [
Expand Down
Loading