Skip to content
Open
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/2fa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@digabi/2fa",
"version": "2.1.0",
"version": "3.0.0",
"author": "Matriculation Examination Board, Finland",
"license": "EUPL-1.2",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/user-management/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@digabi/user-management",
"version": "0.4.0",
"version": "0.6.0-fixUserForAuthentication.1",
"author": "Matriculation Examination Board, Finland",
"license": "EUPL-1.2",
"repository": {
Expand Down
43 changes: 30 additions & 13 deletions packages/user-management/src/user-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export const PrincipalOrganizationSchema = z.object({

export type Impersonation = z.infer<typeof ImpersonationSchema>
export const ImpersonationSchema = z.object({
id: z.number(),
id: z.uuid(),
realSsn: zodSsn,
impersonatedSsn: zodSsn,
impersonatedSsn: zodSsn.or(z.literal('')),
explanation: z.string(),
validityStart: z.string(),
validityEnd: z.string(),
schoolUuid: z.string().optional()
schoolUuid: z.string().nullish()
})

export type MockUser = z.infer<typeof MockUserSchema>
Expand Down Expand Up @@ -141,25 +141,42 @@ export const UserSchema = StoredUserDetailsSchema.extend({
ssn: zodSsn,
userAccountId: z.string(),
schools: z.array(UserSchoolSchema),
censorRole: CensorRoleSchema.optional()
})
censorRole: CensorRoleSchema.optional(),
impersonation: z.never().optional()
}).strict()

export type UserToUpsert = z.infer<typeof UserToUpsertSchema>
export const UserToUpsertSchema = UserDetailsSchema.extend({
ssn: zodSsn,
schools: z.array(UserSchoolToUpsertSchema)
}).strict()

export type ImpersonatedUser = z.infer<typeof ImpersonatedUserSchema>
const ImpersonatedUserSchema = z.object({
ssn: z.string(),
schools: z.array(UserSchoolSchema),
impersonation: ImpersonationSchema,
censorRole: CensorRoleSchema.optional()
})
export type PersonalImpersonation = z.infer<typeof PersonalImpersonationSchema>
export const PersonalImpersonationSchema = UserSchema.extend({
impersonation: ImpersonationSchema
}).strict()

export type SchoolImpersonation = z.infer<typeof SchoolImpersonationSchema>
export const SchoolImpersonationSchema = z
.object({
impersonation: ImpersonationSchema,
ssn: z.literal('IMPERSONATED'),
schools: z
.array(
z.object({
schoolId: z.string(),
principal: z.literal(true),
permissions: z.array(z.unknown()).max(0, "Impersonated principal doesn't have other permissions")
})
)
.max(1, 'Impersonated principal has one school')
})
.strict()

export type ImpersonatedUser = z.infer<typeof ImpersonatedUserSchema>
export const ImpersonatedUserSchema = z.xor([PersonalImpersonationSchema, SchoolImpersonationSchema])
export type UserForAuthentication = z.infer<typeof UserForAuthenticationSchema>
export const UserForAuthenticationSchema = z.union([UserSchema, ImpersonatedUserSchema])
export const UserForAuthenticationSchema = z.xor([UserSchema, ImpersonatedUserSchema])

export type UserWithSchoolRoleAndSchoolId = z.infer<typeof UserWithSchoolRoleAndSchoolIdSchema>
export const UserWithSchoolRoleAndSchoolIdSchema = z.object({
Expand Down