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

#137 [FEAT]: Permission management optimizations #138

Merged
merged 14 commits into from
Feb 23, 2025
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
175 changes: 97 additions & 78 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum InstitutionType {
}

enum UserRole {
GUEST
USER
APPLIER
PUBLISHER
Expand All @@ -68,6 +69,7 @@ enum UserRole {

enum VisibilityMode {
PUBLIC
AUTHENTICATED
RESTRICT
}

Expand All @@ -81,39 +83,39 @@ enum ItemValidationType {
model Address {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

city String
state String
country String

institutions Institution[]
applicationAnswers ApplicationAnswer[]
institutions Institution[]

@@unique([city, state, country])
}

model ApplicationAnswer {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

date DateTime
date DateTime
approved Boolean @default(false)

itemAnswerGroups ItemAnswerGroup[]

userId Int?
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
applicationId Int
application Application @relation(fields: [applicationId], references: [id], onDelete: Cascade)
addressId Int?
address Address? @relation(fields: [addressId], references: [id], onDelete: SetNull)
coordinateId Int?
coordinate Coordinate? @relation(fields: [coordinateId], references: [id], onDelete: SetNull)
}

model ItemAnswer {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

text String?

Expand All @@ -128,7 +130,7 @@ model ItemAnswer {
model ItemAnswerGroup {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

itemAnswers ItemAnswer[]
optionAnswers OptionAnswer[]
Expand All @@ -141,7 +143,7 @@ model ItemAnswerGroup {
model OptionAnswer {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

text String?

Expand All @@ -156,7 +158,7 @@ model OptionAnswer {
model TableAnswer {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

text String?

Expand All @@ -171,7 +173,7 @@ model TableAnswer {
model Institution {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

name String
type InstitutionType
Expand All @@ -186,26 +188,27 @@ model Institution {
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

name String
username String @unique
hash String
role UserRole
acceptedTerms Boolean @default(false)
name String
username String @unique
hash String
role UserRole
acceptedTerms Boolean @default(false)
profileImageId Int?
profileImage File? @relation(name: "UserProfileImage", fields: [profileImageId], references: [id], onDelete: SetNull)
profileImage File? @relation(name: "UserProfileImage", fields: [profileImageId], references: [id], onDelete: SetNull)

createdProtocols Protocol[] @relation(name: "Creator") // protocols that the user has created
createdProtocols Protocol[] @relation(name: "Creator") // protocols that the user has created
ownedProtocols Protocol[] @relation(name: "ManagersProtocols") // protocols that the user can edit
answeredApplications ApplicationAnswer[]
applications Application[] @relation(name: "Applier") // applications that the user has created
visibleApplications Application[] @relation(name: "ApplicationViewersUser") // applications that the user can see
visibleProtocols Protocol[] @relation(name: "ProtocolViewersUsers") // protocols that the user can see
appliableProtocols Protocol[] @relation(name: "Appliers") // protocols that the user can apply
visibleProtocolAnswers Protocol[] @relation(name: "ProtocolAnswersViewersUsers") // protocols that the user can see the answers
visibleApplicationAnswers Application[] @relation(name: "ApplicationAnswersViewersUsers") // applications that the user can see the answers
classrooms Classroom[]
answeredApplications ApplicationAnswer[]
applications Application[] @relation(name: "Applier") // applications that the user has created
visibleApplications Application[] @relation(name: "ApplicationViewersUser") // applications that the user can see
visibleProtocols Protocol[] @relation(name: "ProtocolViewersUsers") // protocols that the user can see
appliableProtocols Protocol[] @relation(name: "Appliers") // protocols that the user can apply
visibleProtocolAnswers Protocol[] @relation(name: "ProtocolAnswersViewersUsers") // protocols that the user can see the answers
visibleApplicationAnswers Application[] @relation(name: "ApplicationAnswersViewersUsers") // applications that the user can see the answers
classrooms Classroom[] @relation(name: "ClassroomUsers") // classrooms that the user is in
createdClassrooms Classroom[] @relation(name: "ClassroomCreator") // classrooms that the user has created

institutionId Int?
institution Institution? @relation(fields: [institutionId], references: [id], onDelete: SetNull)
Expand All @@ -214,18 +217,20 @@ model User {
model Classroom {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

name String

users User[]
visibleApplications Application[] @relation(name: "ApplicationViewersClassroom") // applications that the classroom can see
visibleProtocols Protocol[] @relation(name: "ProtocolViewersClassroom") // protocols that the classroom can see
visibleProtocolAnswers Protocol[] @relation(name: "ProtocolAnswersViewersClassroom") // protocols that the classroom can see the answers
users User[] @relation(name: "ClassroomUsers") // users that are in the classroom
visibleApplications Application[] @relation(name: "ApplicationViewersClassroom") // applications that the classroom can see
visibleProtocols Protocol[] @relation(name: "ProtocolViewersClassroom") // protocols that the classroom can see
visibleProtocolAnswers Protocol[] @relation(name: "ProtocolAnswersViewersClassroom") // protocols that the classroom can see the answers
visibleApplicationAnswers Application[] @relation(name: "ApplicationAnswersViewersClassroom") // applications that the classroom can see the answers

institutionId Int?
institution Institution? @relation(fields: [institutionId], references: [id], onDelete: Cascade)
creatorId Int
creator User @relation(name: "ClassroomCreator", fields: [creatorId], references: [id], onDelete: Cascade)

@@unique([name, institutionId])
}
Expand All @@ -235,55 +240,56 @@ model Application {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

visibility VisibilityMode
visibility VisibilityMode
answersVisibility VisibilityMode
keepLocation Boolean

answers ApplicationAnswer[]
viewersClassroom Classroom[] @relation(name: "ApplicationViewersClassroom") // classrooms that can see the application
viewersUser User[] @relation(name: "ApplicationViewersUser") // users that can see the application
answersViewersUser User[] @relation(name: "ApplicationAnswersViewersUsers") // users that can see the answers
answersViewersClassroom Classroom[] @relation(name: "ApplicationAnswersViewersClassroom") // classrooms that can see the answers
answers ApplicationAnswer[]
viewersClassroom Classroom[] @relation(name: "ApplicationViewersClassroom") // classrooms that can see the application
viewersUser User[] @relation(name: "ApplicationViewersUser") // users that can see the application
answersViewersUser User[] @relation(name: "ApplicationAnswersViewersUsers") // users that can see the answers
answersViewersClassroom Classroom[] @relation(name: "ApplicationAnswersViewersClassroom") // classrooms that can see the answers

protocolId Int
protocol Protocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
applierId Int
applier User @relation(name: "Applier", fields: [applierId], references: [id], onDelete: Cascade)
protocolId Int
protocol Protocol @relation(fields: [protocolId], references: [id], onDelete: Cascade)
applierId Int
applier User @relation(name: "Applier", fields: [applierId], references: [id], onDelete: Cascade)
}

model Protocol {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

title String
description String?
enabled Boolean
replicable Boolean
creatorId Int
creator User @relation(name: "Creator", fields: [creatorId], references: [id], onDelete: Cascade)
applicability VisibilityMode
visibility VisibilityMode
answersVisibility VisibilityMode
appliers User[] @relation(name: "Appliers") // users that can apply the protocol
viewersUser User[] @relation(name: "ProtocolViewersUsers") // users that can see the protocol
viewersClassroom Classroom[] @relation(name: "ProtocolViewersClassroom") // classrooms that can see the protocol
answersViewersUser User[] @relation(name: "ProtocolAnswersViewersUsers") // users that can see the answers
answersViewersClassroom Classroom[] @relation(name: "ProtocolAnswersViewersClassroom") // classrooms that can see the answers
title String
description String?
enabled Boolean
replicable Boolean
creatorId Int
creator User @relation(name: "Creator", fields: [creatorId], references: [id], onDelete: Cascade)
applicability VisibilityMode
visibility VisibilityMode
answersVisibility VisibilityMode
appliers User[] @relation(name: "Appliers") // users that can apply the protocol
viewersUser User[] @relation(name: "ProtocolViewersUsers") // users that can see the protocol
viewersClassroom Classroom[] @relation(name: "ProtocolViewersClassroom") // classrooms that can see the protocol
answersViewersUser User[] @relation(name: "ProtocolAnswersViewersUsers") // users that can see the answers
answersViewersClassroom Classroom[] @relation(name: "ProtocolAnswersViewersClassroom") // classrooms that can see the answers

pages Page[]
managers User[] @relation(name: "ManagersProtocols") // users that can edit the protocol
managers User[] @relation(name: "ManagersProtocols") // users that can edit the protocol
applications Application[]
}

model Page {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

type PageType
placement Int

itemGroups ItemGroup[]
itemGroups ItemGroup[]
dependencies PageDependencyRule[]

protocolId Int
Expand All @@ -293,7 +299,7 @@ model Page {
model ItemGroup {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

type ItemGroupType
placement Int
Expand All @@ -310,20 +316,20 @@ model ItemGroup {
model Item {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

text String
description String?
type ItemType
placement Int
enabled Boolean

itemOptions ItemOption[]
itemAnswers ItemAnswer[]
optionAnswers OptionAnswer[]
tableAnswers TableAnswer[]
files File[]
itemValidations ItemValidation[]
itemOptions ItemOption[]
itemAnswers ItemAnswer[]
optionAnswers OptionAnswer[]
tableAnswers TableAnswer[]
files File[]
itemValidations ItemValidation[]
pageDependencies PageDependencyRule[]
itemGroupDependencies ItemGroupDependencyRule[]

Expand All @@ -334,7 +340,7 @@ model Item {
model ItemValidation {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

type ItemValidationType
argument String
Expand All @@ -349,7 +355,7 @@ model ItemValidation {
model ItemOption {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

text String
placement Int
Expand All @@ -364,7 +370,7 @@ model ItemOption {
model TableColumn {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

text String
placement Int
Expand All @@ -378,9 +384,9 @@ model TableColumn {
model File {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

path String
path String
description String?

itemId Int?
Expand All @@ -389,13 +395,13 @@ model File {
itemOption ItemOption? @relation(fields: [itemOptionId], references: [id], onDelete: Cascade)
itemAnswerId Int?
itemAnswer ItemAnswer? @relation(fields: [itemAnswerId], references: [id], onDelete: Cascade)
users User[] @relation(name: "UserProfileImage")
users User[] @relation(name: "UserProfileImage")
}

model ItemGroupDependencyRule {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

type DependencyType
argument String
Expand All @@ -412,7 +418,7 @@ model ItemGroupDependencyRule {
model PageDependencyRule {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt

type DependencyType
argument String
Expand All @@ -424,4 +430,17 @@ model PageDependencyRule {
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)

@@unique([pageId, itemId, type])
}
}

model Coordinate {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

latitude Float
longitude Float

answers ApplicationAnswer[]

@@unique([latitude, longitude])
}
Loading