mirror of
https://github.com/UniversityOfHelsinkiCS/oodikone.git
synced 2026-10-12 19:03:39 +03:00
[combined programme access] Now only one of the rights is enough
This commit is contained in:
@@ -200,7 +200,13 @@ router.get('/v3/populationstatistics', async (req, res) => {
|
||||
} = req
|
||||
|
||||
try {
|
||||
if (!isAdmin && !rights.includes(studyRights.programme) && !iamRights.includes(studyRights.programme)) {
|
||||
if (
|
||||
!isAdmin &&
|
||||
!rights.includes(studyRights.programme) &&
|
||||
!rights.includes(studyRights.combinedProgramme) &&
|
||||
!iamRights.includes(studyRights.programme) &&
|
||||
!iamRights.includes(studyRights.combinedProgramme)
|
||||
) {
|
||||
res.status(403).json([])
|
||||
return
|
||||
}
|
||||
@@ -218,12 +224,15 @@ router.get('/v3/populationstatistics', async (req, res) => {
|
||||
const multipopulationstudentPromises = Promise.all(
|
||||
req.query.years.map(year => {
|
||||
const newMonths = (upperYearBound - Number(year)) * 12
|
||||
const populationStudents = Population.optimizedStatisticsOf({
|
||||
...req.query,
|
||||
studyRights: { programme: studyRights.programme },
|
||||
year,
|
||||
months: newMonths,
|
||||
})
|
||||
const populationStudents = Population.optimizedStatisticsOf(
|
||||
{
|
||||
...req.query,
|
||||
studyRights: { programme: studyRights.programme },
|
||||
year,
|
||||
months: newMonths,
|
||||
},
|
||||
null
|
||||
)
|
||||
return populationStudents
|
||||
})
|
||||
)
|
||||
@@ -251,7 +260,7 @@ router.get('/v3/populationstatistics', async (req, res) => {
|
||||
}
|
||||
|
||||
// Obfuscate if user has only iam rights
|
||||
if (!isAdmin && !rights.includes(studyRights.programme)) {
|
||||
if (!isAdmin && !rights.includes(studyRights.programme) && !rights.includes(studyRights.combinedProgramme)) {
|
||||
result.students = result.students.map(student => {
|
||||
const { iv, encryptedData } = encrypt(student.studentNumber)
|
||||
const obfuscatedBirthDate = new Date(new Date(student.birthdate).setMonth(0, 0)) // only birth year for age distribution
|
||||
@@ -431,7 +440,11 @@ router.get('/v3/populationstatistics/studyprogrammes', async (req, res) => {
|
||||
mapCodesToIds(studyrights.programmes)
|
||||
res.json(studyrights)
|
||||
} else {
|
||||
const studyrights = await StudyrightService.getFilteredAssociations(rights.concat(iamRights))
|
||||
const allRights = rights.concat(iamRights)
|
||||
// For combined programme
|
||||
// If more programmes are combined, then a function might be a better idea to add moar rights
|
||||
if (allRights.includes('KH90_001') || allRights.includes('MH90_001')) allRights.push('KH90_001', 'MH90_001')
|
||||
const studyrights = await StudyrightService.getFilteredAssociations(allRights)
|
||||
mapCodesToIds(studyrights.programmes)
|
||||
res.json(studyrights)
|
||||
}
|
||||
|
||||
@@ -145,7 +145,8 @@ router.delete('/studenttags/delete_one', async (req, res) => {
|
||||
user: { rights, roles, id },
|
||||
} = req
|
||||
|
||||
if (!rights.includes(studytrack) && !roles?.includes('admin')) return res.status(403).end()
|
||||
if (!rights.includes(studytrack) && !rights.includes(combinedProgramme) && !roles?.includes('admin'))
|
||||
return res.status(403).end()
|
||||
const studytrackCode = combinedProgramme ? `${studytrack}-${combinedProgramme}` : studytrack
|
||||
const tags = await Tags.findTagsFromStudytrackById(studytrackCode, [tag_id])
|
||||
if (tags.length === 0) return res.status(403).json({ error: 'The tag does not exist' })
|
||||
@@ -161,7 +162,8 @@ router.delete('/studenttags/delete_many', async (req, res) => {
|
||||
user: { rights, roles, id },
|
||||
} = req
|
||||
|
||||
if (!rights.includes(studytrack) && !roles?.includes('admin')) return res.status(403).end()
|
||||
if (!rights.includes(studytrack) && !rights.includes(combinedProgramme) && !roles?.includes('admin'))
|
||||
return res.status(403).end()
|
||||
const studytrackCode = combinedProgramme ? `${studytrack}-${combinedProgramme}` : studytrack
|
||||
const tags = await Tags.findTagsFromStudytrackById(studytrackCode, [tagId])
|
||||
if (tags.length === 0) return res.status(403).json({ error: 'The tag does not exist' })
|
||||
|
||||
@@ -955,6 +955,7 @@ const formatStudentsForApi = async (
|
||||
courses,
|
||||
elementdetails,
|
||||
}
|
||||
|
||||
return returnvalue
|
||||
}
|
||||
|
||||
@@ -1001,6 +1002,7 @@ const optimizedStatisticsOf = async (query, studentnumberlist) => {
|
||||
!transferredStudents,
|
||||
true
|
||||
)
|
||||
|
||||
const code = studyRights[0] || ''
|
||||
let optionData = {}
|
||||
let criteria = {}
|
||||
|
||||
@@ -85,7 +85,11 @@ const PopulationDetails = ({
|
||||
return null
|
||||
}
|
||||
|
||||
const onlyIamRights = !authLoading && !isAdmin && !rights.includes(query?.studyRights?.programme)
|
||||
const onlyIamRights =
|
||||
!authLoading &&
|
||||
!isAdmin &&
|
||||
!rights.includes(query?.studyRights?.programme) &&
|
||||
!rights.includes(query?.studyRights?.combinedProgramme)
|
||||
|
||||
const panels = [
|
||||
{
|
||||
|
||||
@@ -55,7 +55,10 @@ const PopulationSearchForm = props => {
|
||||
const { query, isLoading, momentYear } = totalState
|
||||
|
||||
const { studyProgrammes, location, queries, history, language, onProgress } = props
|
||||
if (studyProgrammes.KH90_001 && !Object.keys(studyProgrammes).includes('KH90_001+MH90_001')) {
|
||||
if (
|
||||
(studyProgrammes.KH90_001 || studyProgrammes.MH90_001) &&
|
||||
!Object.keys(studyProgrammes).includes('KH90_001+MH90_001')
|
||||
) {
|
||||
const vetenaryCombined = { ...studyProgrammes.KH90_001 }
|
||||
vetenaryCombined.name = {
|
||||
fi: 'Eläinlääketieteen kandiohjelma ja lisensiaatin koulutusohjelma',
|
||||
|
||||
+36
-16
@@ -2,6 +2,7 @@ import React, { useState } from 'react'
|
||||
import { Icon, Popup, Table } from 'semantic-ui-react'
|
||||
|
||||
import useLanguage from 'components/LanguagePicker/useLanguage'
|
||||
import { useGetAuthorizedUserQuery } from 'redux/auth'
|
||||
import PopulationLink from './PopulationLink'
|
||||
import Toggle from '../Toggle'
|
||||
|
||||
@@ -65,17 +66,28 @@ const getCountriesPopup = ({ index, combinedProgramme, value, row, year, studypr
|
||||
)
|
||||
}
|
||||
|
||||
const getFirstCell = ({ yearlyData, year, show, studyprogramme, calendarYears, combinedProgramme, setShow }) => {
|
||||
const getFirstCell = ({
|
||||
yearlyData,
|
||||
year,
|
||||
show,
|
||||
studyprogramme,
|
||||
calendarYears,
|
||||
combinedProgramme,
|
||||
setShow,
|
||||
allRights,
|
||||
}) => {
|
||||
return (
|
||||
<Table.Cell key={getKey(year)} className={getCellClass(year)} onClick={setShow}>
|
||||
{yearlyData.length > 1 && <Icon name={`${show ? 'angle down' : 'angle right'}`} />}
|
||||
{year}
|
||||
<PopulationLink
|
||||
studyprogramme={studyprogramme}
|
||||
year={year}
|
||||
years={calendarYears}
|
||||
combinedProgramme={combinedProgramme}
|
||||
/>
|
||||
{(allRights.includes(studyprogramme) || allRights.includes(combinedProgramme)) && (
|
||||
<PopulationLink
|
||||
studyprogramme={studyprogramme}
|
||||
year={year}
|
||||
years={calendarYears}
|
||||
combinedProgramme={combinedProgramme}
|
||||
/>
|
||||
)}
|
||||
</Table.Cell>
|
||||
)
|
||||
}
|
||||
@@ -88,6 +100,7 @@ const getSingleTrackRow = ({
|
||||
calendarYears,
|
||||
combinedProgramme,
|
||||
otherCountriesStats,
|
||||
allRights,
|
||||
}) => {
|
||||
return (
|
||||
<Table.Row key={getKey(row[0])} className="regular-row">
|
||||
@@ -111,7 +124,7 @@ const getSingleTrackRow = ({
|
||||
key={getKey(row[0])}
|
||||
>
|
||||
{value}
|
||||
{index === 0 && (
|
||||
{index === 0 && (allRights.includes(studyprogramme) || allRights.includes(combinedProgramme)) && (
|
||||
<PopulationLink
|
||||
studyprogramme={studyprogramme}
|
||||
year={row[0]}
|
||||
@@ -140,6 +153,7 @@ const getRow = ({
|
||||
combinedProgramme,
|
||||
otherCountriesStats,
|
||||
getTextIn,
|
||||
allRights,
|
||||
}) => {
|
||||
const year = yearlyData && yearlyData[0] && yearlyData[0][0]
|
||||
// Get row for the studyprogramme
|
||||
@@ -157,6 +171,7 @@ const getRow = ({
|
||||
calendarYears,
|
||||
combinedProgramme,
|
||||
setShow,
|
||||
allRights,
|
||||
})
|
||||
if (index === row.length - 2 && otherCountriesStats)
|
||||
return getCountriesPopup({
|
||||
@@ -186,13 +201,15 @@ const getRow = ({
|
||||
return (
|
||||
<Table.Cell textAlign="left" style={{ paddingLeft: '50px' }} key={getKey(row[0])}>
|
||||
{title}
|
||||
<PopulationLink
|
||||
studyprogramme={studyprogramme}
|
||||
year={year}
|
||||
years={calendarYears}
|
||||
studytrack={correctStudytrack}
|
||||
combinedProgramme={combinedProgramme}
|
||||
/>
|
||||
{(allRights.includes(studyprogramme) || allRights.includes(combinedProgramme)) && (
|
||||
<PopulationLink
|
||||
studyprogramme={studyprogramme}
|
||||
year={year}
|
||||
years={calendarYears}
|
||||
studytrack={correctStudytrack}
|
||||
combinedProgramme={combinedProgramme}
|
||||
/>
|
||||
)}
|
||||
</Table.Cell>
|
||||
)
|
||||
}
|
||||
@@ -268,8 +285,9 @@ const StudytrackDataTable = ({
|
||||
const [show, setShow] = useState([])
|
||||
const [showPercentages, setShowPercentages] = useState(false)
|
||||
const { getTextIn } = useLanguage()
|
||||
const { rights, iamRights } = useGetAuthorizedUserQuery()
|
||||
const allRights = rights.concat(iamRights)
|
||||
if (!dataOfAllTracks && !dataOfSingleTrack) return null
|
||||
|
||||
const firstCellClicked = index => {
|
||||
const newShow = [...show]
|
||||
show[index] = newShow[index] === undefined ? true : !show[index]
|
||||
@@ -349,6 +367,7 @@ const StudytrackDataTable = ({
|
||||
calendarYears,
|
||||
combinedProgramme,
|
||||
otherCountriesStats,
|
||||
allRights,
|
||||
})
|
||||
)
|
||||
: sortedMainStats?.map((yearlyData, index) =>
|
||||
@@ -367,6 +386,7 @@ const StudytrackDataTable = ({
|
||||
otherCountriesStats,
|
||||
getTextIn,
|
||||
index,
|
||||
allRights,
|
||||
})
|
||||
)
|
||||
)}
|
||||
|
||||
@@ -95,7 +95,7 @@ const StudyProgramme = props => {
|
||||
),
|
||||
})
|
||||
|
||||
if (isAdmin || rights.includes(programmeId)) {
|
||||
if (isAdmin || rights.includes(programmeId) || rights.includes(secondProgrammeId)) {
|
||||
panes.push({
|
||||
menuItem: <Menu.Item key="Programme courses">Programme courses</Menu.Item>,
|
||||
render: () => (
|
||||
|
||||
Reference in New Issue
Block a user