Skip to content

Commit

Permalink
added preferredFaculty to Users
Browse files Browse the repository at this point in the history
  • Loading branch information
Catrovitch committed Mar 18, 2024
1 parent 1618418 commit 4c8d393
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/client/pages/InventionDisclosure.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import React from 'react'
import { Box, Grid } from '@mui/material'
import { Box, Grid, Typography } from '@mui/material'

import InformationChip from '../components/Chip/InformationChip'
import styles from '../styles'

const InventionDisclosurePage = () => {
const { formStyles } = styles

return (
<Box sx={formStyles.formWrapper}>
<Grid container>
<InformationChip
title='Invention Disclosure'
label='disclosure'
link='/invention_disclosure'
/>
</Grid>
</Box>
)
}
const InventionDisclosurePage = () => (
<Box>
<Grid container>
<InformationChip
title='Invention Disclosure'
label='disclosure'
link='/invention_disclosure'
/>
</Grid>
<Typography variant='h2'>Hej</Typography>
</Box>
)
export default InventionDisclosurePage
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { DataTypes } from 'sequelize'

import { Migration } from '../connection'

export const up: Migration = async ({ context: queryInterface }) => {
await queryInterface.addColumn('users', 'preferred_faculty', {
type: DataTypes.STRING,
allowNull: true,
})
}

export const down: Migration = async ({ context: queryInterface }) => {
await queryInterface.removeColumn('users', 'preferred_faculty')
}
6 changes: 6 additions & 0 deletions src/server/db/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
declare lastLoggedIn: Date

declare isAdmin: boolean

declare preferredFaculty: string
}

User.init(
Expand Down Expand Up @@ -56,6 +58,10 @@ User.init(
allowNull: false,
defaultValue: false,
},
preferredFaculty: {
type: DataTypes.STRING,
allowNull: true,
},
},
{
underscored: true,
Expand Down
1 change: 1 addition & 0 deletions src/server/db/seeders/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const user = {
language: 'fi',
isAdmin: true,
lastLoggedIn: new Date(),
preferredFaculty: 'H50',
}

const seedUsers = async () => {
Expand Down
1 change: 1 addition & 0 deletions src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface User {
isAdmin: boolean
iamGroups: string[]
newUser?: boolean
preferredFaculty: string
}

export interface RequestWithUser extends Request {
Expand Down
4 changes: 4 additions & 0 deletions src/server/util/oicd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import passport from 'passport'

import { User } from '../db/models'
import NotFoundError from '../errors/NotFoundError'
import { getUserFaculties } from '../services/faculty'
import { User as UserType, UserInfo } from '../types'

import {
Expand Down Expand Up @@ -66,6 +67,8 @@ const verifyLogin = async (
family_name: lastName,
} = userinfo as unknown as UserInfo

const userPreferedFaculty = await getUserFaculties(id, iamGroups)

const user: UserType = {
username,
id: id || username,
Expand All @@ -75,6 +78,7 @@ const verifyLogin = async (
firstName,
lastName,
isAdmin: checkAdmin(iamGroups) || username === 'glandmic',
preferredFaculty: userPreferedFaculty[0].code || 'OTHER',
}

await User.upsert({
Expand Down

0 comments on commit 4c8d393

Please sign in to comment.