Skip to content

Commit ce6af17

Browse files
committed
fix: Fix access merge
1 parent 085d826 commit ce6af17

File tree

7 files changed

+134
-8
lines changed

7 files changed

+134
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ debug.log
66
.env
77
coverage
88
.DS_Store
9+
backups

docker-compose.ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
- PORT=3003
1010
- NODE_ENV=test
1111
ports:
12-
- 3000:3003
12+
- 3001:3003
1313
container_name: jami_dev
1414

1515
db:

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
volumes:
1414
- ./:/usr/src/app
1515
ports:
16-
- 3000:3000
16+
- 3001:3000
1717
container_name: jami_dev
1818
tty: true
1919

@@ -22,8 +22,8 @@ services:
2222
environment:
2323
- PGDATA=/data
2424
- POSTGRES_PASSWORD=postgres
25-
ports:
26-
- 5432:5432
25+
# ports:
26+
# - 5432:5432
2727
volumes:
2828
- pg_data:/data
2929
container_name: jami_db

scripts/get_prod_db.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
CONTAINER=jami_db
4+
SERVICE_NAME=db
5+
DB_NAME=postgres
6+
7+
# JAMI_DB=jami-db
8+
9+
# current_date=$(date +"%Y%m%d")
10+
# JAMI_FILE_NAME="jami_${current_date}.sql.gz"
11+
12+
FOLDER_NAME="jami"
13+
14+
PROJECT_ROOT=$(dirname $(dirname $(realpath "$0")))
15+
BACKUPS=$PROJECT_ROOT/backups/
16+
DOCKER_COMPOSE=$PROJECT_ROOT/docker-compose.yml
17+
18+
S3_CONF=~/.s3cfg
19+
20+
retry () {
21+
for i in {1..60}
22+
do
23+
$@ && break || echo "Retry attempt $i failed, waiting..." && sleep 3;
24+
done
25+
}
26+
27+
if [ ! -f "$S3_CONF" ]; then
28+
echo ""
29+
echo "!! No config file for s3 bucket !!"
30+
echo "Create file for path ~/.s3cfg and copy the credetials from version.helsinki.fi"
31+
echo ""
32+
return 0
33+
fi
34+
35+
echo "Creating backups folder"
36+
mkdir -p ${BACKUPS}
37+
38+
echo "Listing available backups in S3 bucket..."
39+
backup_files=$(s3cmd -c "$S3_CONF" ls "s3://psyduck/${FOLDER_NAME}/" | awk '{print $4}' | grep '\.sql\.gz$')
40+
41+
if [ -z "$backup_files" ]; then
42+
echo "No backup files found in S3 bucket!"
43+
exit 1
44+
fi
45+
46+
echo "Available backups:"
47+
select chosen_backup in $backup_files; do
48+
if [ -n "$chosen_backup" ]; then
49+
echo "You selected: $chosen_backup"
50+
FILE_NAME=$(basename "$chosen_backup")
51+
break
52+
else
53+
echo "Invalid selection. Please select a valid backup number."
54+
fi
55+
done
56+
57+
echo "Fetching the selected dump: $FILE_NAME"
58+
s3cmd -c "$S3_CONF" get "$chosen_backup" "$BACKUPS"
59+
60+
if [ ! -f "${BACKUPS}${FILE_NAME}" ]; then
61+
echo "Download failed or file not found: ${BACKUPS}${FILE_NAME}"
62+
exit 1
63+
fi
64+
65+
echo "Removing database and related volume"
66+
docker-compose -f $DOCKER_COMPOSE down -v
67+
68+
echo "Starting postgres in the background"
69+
docker-compose -f $DOCKER_COMPOSE up -d $SERVICE_NAME
70+
71+
retry docker-compose -f $DOCKER_COMPOSE exec $SERVICE_NAME pg_isready --dbname=$DB_NAME
72+
73+
echo "Populating ${FOLDER_NAME}"
74+
docker exec -i $CONTAINER /bin/bash -c "gunzip | psql -U postgres" < ${BACKUPS}${FILE_NAME}

src/auth/IAMRights.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ const getFacultyAdminRights: AccessSpecialGroupFunction = (hyGroups) => {
237237
return { access, specialGroup: {} }
238238
}
239239

240-
241-
242240
/**
243241
* Grant reading rights to programmes of faculties if user is kosu or dekaanaatti of some faculties
244242
*/
@@ -437,7 +435,17 @@ const getIAMRights: AccessSpecialGroupFunction = (hyGroups) => {
437435
]
438436
.map((f) => f(hyGroups))
439437
.forEach((accessInfo) => {
440-
access = { ...access, ...accessInfo.access }
438+
for (const code in accessInfo.access) {
439+
const newAccess = accessInfo.access[code]
440+
const oldAccess = access[code]
441+
442+
access[code] = {
443+
read: newAccess.read || oldAccess?.read,
444+
write: newAccess.write || oldAccess?.write,
445+
admin: newAccess.admin || oldAccess?.admin
446+
}
447+
}
448+
441449
specialGroup = { ...specialGroup, ...accessInfo.specialGroup }
442450
})
443451

tests/dekaani.spec.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,47 @@ describe.concurrent('Dekaani', () => {
5151
expect(access[programme].admin).toBe(true)
5252
})
5353
})
54+
55+
it('R K-T works', async () => {
56+
const res = await api.post('', {
57+
userId: 'rkt',
58+
iamGroups: [
59+
'hy-employees',
60+
'grp-oodikone-users',
61+
'grp-oodikone-basic-users',
62+
'hy-varadekaanit-opetus',
63+
'hy-one',
64+
'hy-eltdk-dekanaatti',
65+
'grp-katselmus-eltdk',
66+
],
67+
})
68+
69+
expect(res.status).toBe(200)
70+
const access = await res.json()
71+
72+
expect(access['H90'].read).toBe(true)
73+
expect(access['H90'].write).toBe(true)
74+
expect(access['H90'].admin).toBeFalsy()
75+
76+
;[
77+
'KH90_001',
78+
'MH90_001',
79+
'T921108',
80+
'T922106'
81+
].forEach((programme) => {
82+
expect(access[programme].read).toBe(true)
83+
expect(access[programme].write).toBe(true)
84+
expect(access[programme].admin).toBe(true)
85+
})
86+
87+
;[
88+
'KH10_001',
89+
'MH30_005',
90+
'T920102'
91+
].forEach((programme) => {
92+
expect(access[programme].read).toBe(true)
93+
expect(access[programme].write).toBeFalsy()
94+
expect(access[programme].admin).toBeFalsy()
95+
})
96+
})
5497
})

tests/util/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const baseUrl = 'http://localhost:3000'
1+
const baseUrl = 'http://localhost:3001'
22

33
export const api = {
44
get: async (endpoint) => {

0 commit comments

Comments
 (0)