Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
5df15f1
fix combining rows
ahjyrkia Mar 10, 2023
344cc15
Merge pull request #362 from HSLdevcom/timetable-fix
ahjyrkia Mar 10, 2023
732a101
MM-484: Allow launching separate services as different instances (#363)
e-halinen Mar 29, 2023
9be2fb4
MM-497: Endpoint for render URL generation, Update README about servi…
e-halinen Apr 26, 2023
8677a96
Allow route title to enter the padding area
jhanninen May 5, 2023
0943138
Merge pull request #367 from HSLdevcom/hotfix-routes-overflow
jhanninen May 5, 2023
e1b1a4e
MM-495: Rename ticket-zones.json, update README (#365)
e-halinen May 9, 2023
518bfa6
MM-502: Add more functionality to generateRenderUrl endpoint and rend…
e-halinen May 9, 2023
4397c12
Fix url env variables for server (#368)
e-halinen May 10, 2023
0e6e5dc
MM-504: Add redirect parameter to generateRenderUrl endpoint
e-halinen May 10, 2023
1bb0e9b
Merge pull request #369 from HSLdevcom/MM-504
jhanninen Jun 8, 2023
63d3416
Remove forever from deployment
jhanninen Jun 12, 2023
0dbfed1
Add publisher server url to env to be build in the image
jhanninen Jun 12, 2023
a60cf90
Fix and enhance puppeteer console logging
jhanninen Jun 13, 2023
4b254d9
Remove trailing slash from server url env
jhanninen Jun 13, 2023
c9fbb7c
Upgrade hsl-map-style
jhanninen Jul 5, 2023
f684bdb
Fix single departure grouping with same minutes
e-halinen Aug 24, 2023
ad29935
Add filtering for duplicate departures
e-halinen Aug 24, 2023
8daf91e
Merge pull request #370 from HSLdevcom/MM-522
jhanninen Aug 25, 2023
1d6370b
Drop console statement
jhanninen Aug 25, 2023
a308ffc
day specific a4 timetable departures
ahjyrkia Sep 1, 2023
fa78fa6
bug fixes
ahjyrkia Sep 5, 2023
60fb703
Merge pull request #372 from HSLdevcom/MM-525-day-specific-timetables
jhanninen Sep 7, 2023
d2202dc
l_rail color added
ahjyrkia Sep 25, 2023
b1d9c56
legend updated
ahjyrkia Sep 25, 2023
47d2488
translations
ahjyrkia Sep 25, 2023
898cb04
Merge pull request #374 from HSLdevcom/MM-511-L-rail
ahjyrkia Sep 26, 2023
1600040
style reference update
ahjyrkia Sep 26, 2023
d783730
Merge pull request #375 from HSLdevcom/MM-511-hsl-map-style-fix
ahjyrkia Sep 26, 2023
c6610d0
yarn.lock
ahjyrkia Sep 26, 2023
3eb24bc
Merge pull request #376 from HSLdevcom/MM-511-hsl-map-style-fix
ahjyrkia Sep 26, 2023
9314565
revert package.json and yarn.lock
ahjyrkia Sep 26, 2023
f947fac
Merge pull request #377 from HSLdevcom/MM-511-hsl-map-style-fix
ahjyrkia Sep 26, 2023
fb96b6b
new color and background color for stopPoster
ahjyrkia Sep 26, 2023
1aba0d1
Merge pull request #378 from HSLdevcom/MM-511-L-rail
ahjyrkia Sep 26, 2023
03abf02
yarn.lock update
ahjyrkia Sep 26, 2023
ed2dbc0
Merge branch 'development' into MM-511-L-rail
ahjyrkia Sep 26, 2023
2711fde
Merge pull request #379 from HSLdevcom/MM-511-L-rail
ahjyrkia Sep 26, 2023
47a0709
L-rail icon and color update
ahjyrkia Sep 27, 2023
f955569
Merge pull request #380 from HSLdevcom/MM-511-L-rail
ahjyrkia Sep 27, 2023
14347ba
MM-507: Add Docker Compose setup for development (#383)
e-halinen Oct 9, 2023
05b1b60
Use tram diagram also on light rail stops
jhanninen Oct 11, 2023
e9f0e14
Merge pull request #384 from HSLdevcom/25242-tram-diagram-on-light-ra…
jhanninen Oct 11, 2023
ab41ab2
Resize Pikaratikka's icon to render it correctly
jhanninen Oct 12, 2023
c5fb6ca
fixed StopPoster timetable columns
ahjyrkia Oct 31, 2023
49a4b5f
removed redundant prop
ahjyrkia Oct 31, 2023
fd17a6b
Merge pull request #389 from HSLdevcom/timetables-column-fix
ahjyrkia Nov 2, 2023
090a6f9
#26114: language change for print button (#388)
e-halinen Nov 6, 2023
f226f12
#26236: Fix StopPosterA3 generating error (#391)
e-halinen Nov 14, 2023
05a9b5f
Merge branch 'master' into development
e-halinen Nov 15, 2023
9c3dadc
Merge conflict fix
e-halinen Nov 15, 2023
fcd10c8
empty day columns fixed
ahjyrkia Dec 12, 2023
c26f785
Merge pull request #395 from HSLdevcom/daily-timetable-empty-days-hotfix
ahjyrkia Dec 12, 2023
abd2096
AB#27362: Scripted test stops (#393)
e-halinen Dec 13, 2023
39dfd02
yarn.lock and dockerfile updates
ahjyrkia Jan 10, 2024
82af63b
update react
ahjyrkia Jan 31, 2024
2fd120d
deprecated lifecycles removed
ahjyrkia Jan 31, 2024
4b96aca
WIP: Create line timetable component
e-halinen Mar 7, 2024
88b0afb
Include app.js for new component
e-halinen Mar 7, 2024
7d29073
AB#32085: WIP: Add LineTimetable component
e-halinen Mar 13, 2024
a7701c8
Change routeIdentifier property
e-halinen Mar 13, 2024
323f370
AB#32085: Add LineTimetable to test script
e-halinen Mar 14, 2024
eb5b081
Add font styling, tweak font sizes and date formatting
e-halinen Mar 14, 2024
3929423
AB#33201: Fix wrong route color in StopPoster
e-halinen Mar 19, 2024
b7155b6
Merge pull request #398 from HSLdevcom/AB#33201_routeId_color_fix
jhanninen Mar 22, 2024
1bdc2b9
Merge pull request #396 from HSLdevcom/#AB25283-node-update
jhanninen Mar 22, 2024
91be8f2
Merge pull request #397 from HSLdevcom/AB#32085_line_timetable
jhanninen Mar 22, 2024
ec9939b
Add build command to compose and fix output folder location
jhanninen Mar 22, 2024
89aa890
Revert "Merge pull request #397 from HSLdevcom/AB#32085_line_timetable"
jhanninen Mar 25, 2024
fa31eb4
Merge pull request #400 from HSLdevcom/docker-compose-enhancements
jhanninen Mar 25, 2024
c210c6a
Revert "#AB25283 Node/React update"
jhanninen Mar 25, 2024
28aa23d
Revert "Revert "Merge pull request #397 from HSLdevcom/AB#32085_line_…
jhanninen Mar 25, 2024
7d3cf1d
Merge pull request #401 from HSLdevcom/revert-396-#AB25283-node-update
jhanninen Mar 25, 2024
cb348b8
Revert "Revert "#AB25283 Node/React update""
ahjyrkia Mar 25, 2024
174b083
build fix
ahjyrkia Mar 25, 2024
aee895f
Merge pull request #403 from HSLdevcom/revert-401-revert-396-#AB25283…
ahjyrkia Mar 25, 2024
91bc942
removing fast refresh from dev webpack
ahjyrkia Mar 25, 2024
b730080
Merge pull request #404 from HSLdevcom/revert-401-revert-396-#AB25283…
ahjyrkia Mar 25, 2024
bf5ee49
removing fast refresh from webpack.common
ahjyrkia Mar 25, 2024
514837d
Merge pull request #405 from HSLdevcom/revert-401-revert-396-#AB25283…
ahjyrkia Mar 25, 2024
47aeacb
node env
ahjyrkia Mar 27, 2024
77a92fb
Merge pull request #406 from HSLdevcom/revert-401-revert-396-#AB25283…
ahjyrkia Mar 27, 2024
da5eaf4
AB#33966: Pass api key to client-side in env variables (#407)
e-halinen Mar 27, 2024
93aff58
Revert "AB#33966: Pass api key to client-side in env variables (#407)"
e-halinen Mar 28, 2024
74ecf4c
AB#33966: Expose local env file in compose to pass apikey without ext…
e-halinen Mar 28, 2024
c5fb6d4
AB#32085: add print button (#409)
e-halinen Mar 28, 2024
b1cabdb
AB#32085: Remove unused prop
e-halinen Mar 28, 2024
61d6f59
AB#32667: Add smaller size variant to TerminalPoster component (#399)
e-halinen Apr 3, 2024
8fdc3df
Bump map-style version to 1.1.3 (#412)
e-halinen Apr 24, 2024
3333d21
WIP: Bug fix for stop poster
e-halinen May 15, 2024
f0d31fc
AB#37216: Fix horizontal overflow error on large terminal route lists…
e-halinen May 17, 2024
5945c68
Fix trunk route color in route diagram (#414)
e-halinen May 21, 2024
e76e844
AB#39315: remove opening times from SVG (#416)
e-halinen Jun 17, 2024
98db819
AB#32085: Refactor generateRenderUrl endpoint to accept LineTimetable…
e-halinen Aug 6, 2024
32913de
AB#32085: Show both directions in same timetable (#411)
e-halinen Aug 6, 2024
d834563
AB#32085: Tweak styling, refactor render logic (#419)
e-halinen Sep 12, 2024
a367a14
AB#32085: Change LineTimetable print layout to A5 (#420)
e-halinen Oct 15, 2024
3f321ad
AB#44831: Add font styling to StopPoster map legend texts (#421)
e-halinen Oct 22, 2024
83f0e6b
AB#44831: Add italics to Stop Poster TableHeaders (#422)
e-halinen Oct 24, 2024
07d2fa5
AB#46862: Refactor route filtering logic (#425)
e-halinen Nov 18, 2024
3800544
AB#32085: Add page numbering (#424)
e-halinen Nov 22, 2024
7f72e74
AB#32085: Tweak print parameters, clean up (#428)
e-halinen Nov 25, 2024
7f748be
AB#32085: Tweak LineTimetable font styles (#429)
e-halinen Nov 26, 2024
f80ea9f
Merge branch 'master' into development
e-halinen Nov 26, 2024
ed19393
AB#48147: Improve missing line data error handling (#431)
e-halinen Dec 9, 2024
b569ac6
AB#48147: Improve empty line node array error handling (#432)
e-halinen Dec 9, 2024
597d80a
Merge branch 'master' into development
e-halinen Dec 9, 2024
8c0cbf8
AB#36691 terminal posters (#434)
e-halinen Dec 11, 2024
f932907
AB#44833: Fix smaller terminal poster footer vector placements (#435)
e-halinen Dec 12, 2024
6253c81
AB#48634: Bump hsl-map-style version to 1.2.0 (#437)
e-halinen Dec 30, 2024
8875129
AB#48698: Add cover page generation for timetable builds (#438)
e-halinen Jan 29, 2025
d42b90d
AB#34352: Smaller terminal poster horizontal overflow error (#436)
e-halinen Jan 29, 2025
6bce428
Fix icons appearing underneath the custom vectors (#440)
e-halinen Feb 10, 2025
43cc5af
AB#54863: Fix broken URL in string template resulting in unbound quer…
e-halinen Mar 20, 2025
8c95d1b
AB#48698: Adjust timetable font sizes (#443)
e-halinen Apr 29, 2025
4ffab24
AB#57971: Switch to validation library for access control (#444)
e-halinen May 6, 2025
4bf2e6e
AB#58144: Improve StopPoster salespoint rendering logic and error han…
e-halinen May 6, 2025
141db52
AB#37770: Fix local test generation errors (#439)
e-halinen May 6, 2025
6b482fa
AB#55637: StopRoutePlate support (#442)
e-halinen May 6, 2025
2e7fa73
AB#58661: Remove redundant ticket sales component from map request (#…
e-halinen May 13, 2025
263a6be
Merge branch 'master' into development
e-halinen May 13, 2025
cf1cb0c
AB#55638: Fix downloaded filepath typo (#450)
e-halinen May 15, 2025
bf021d3
AB#57920: Add line query input option for StopRoutePlate (#451)
e-halinen May 21, 2025
5f81595
AB#56572: Add version number check against prod (#452)
e-halinen May 23, 2025
dcdb9af
AB#56568: Change license to AGPL-3.0-only (#454)
e-halinen Jun 3, 2025
4e0fcef
Switch login provider for production environment (#455)
e-halinen Jun 12, 2025
c1ae78e
v1.1.0
e-halinen Jun 12, 2025
1034368
Merge branch 'master' into development
e-halinen Jun 12, 2025
10d2b31
v1.1.1
e-halinen Jun 12, 2025
c91a359
v1.1.2
e-halinen Jun 12, 2025
4667b5c
AB#61685: Fix HTTP 431 errors when generating large spreadsheets (#456)
e-halinen Jul 8, 2025
167e154
AB#62084: Change ticket sales point endpoint URL (#457)
e-halinen Jul 8, 2025
093ddb7
AB#62084 change sales point endpoint url (#458)
e-halinen Jul 9, 2025
6554de9
AB#61685: Fix props fetch (#459)
e-halinen Jul 9, 2025
c6c00dd
AB#61806: Insert default dates for LineTimetable request (#462)
e-halinen Jul 10, 2025
0b903e3
AB#60124: Switch access control to use HSL ID assigned groups (#453)
e-halinen Jul 10, 2025
3211400
AB#60109: Fix readonly role permissions (#463)
e-halinen Jul 10, 2025
6a9006c
AB#62375: Switch StopRoutePlate via-property to plateVia (#464)
e-halinen Jul 24, 2025
4407a0c
Bump dot-prop from 4.2.0 to 4.2.1 (#255)
dependabot[bot] Aug 4, 2025
dc662bf
Bump elliptic from 6.5.3 to 6.5.4 (#262)
dependabot[bot] Aug 4, 2025
c59739c
Bump node-fetch from 1.7.3 to 3.3.0 (#350)
dependabot[bot] Aug 4, 2025
d21c20d
fixed tag and note filtering (#381)
ahjyrkia Aug 4, 2025
512462a
Downgrade node-fetch due to build errors
e-halinen Aug 4, 2025
5ef1b2b
Bump worker-loader from 2.0.0 to 3.0.8 (#465)
dependabot[bot] Aug 5, 2025
18cfbd2
Bump eslint-plugin-jsx-a11y from 6.8.0 to 6.10.2 (#466)
dependabot[bot] Aug 5, 2025
0313d1e
Bump koa-session from 5.13.1 to 7.0.2 (#467)
dependabot[bot] Aug 5, 2025
4053db6
Bump qrcode from 1.5.3 to 1.5.4 (#469)
dependabot[bot] Aug 5, 2025
cdc9739
Bump style-loader from 0.19.1 to 2.0.0 (#468)
dependabot[bot] Aug 5, 2025
e4d4f1e
downgrade koa-session
e-halinen Aug 5, 2025
8342672
AB#63281: Improve Dependabot config (#475)
e-halinen Aug 22, 2025
1a6fccf
AB#64706: Add LineTimetable error page (#479)
e-halinen Aug 28, 2025
fa115db
AB#64706 rendering error page (#480)
e-halinen Aug 28, 2025
fe02dcf
AB#64706: Remove unused errorPage component
e-halinen Aug 28, 2025
44f9b6d
AB#64924: Add static GET endpoint for weekly Line Timetables (#481)
e-halinen Aug 29, 2025
322d2c5
AB#64924: Add query param for GET endpoint (#482)
e-halinen Aug 29, 2025
bdf4a6d
AB#64927: Refactor LineTimetable Line handling (#483)
e-halinen Sep 1, 2025
1f3eaee
AB#64926 fix svg styles leaking outside of svgs (#485)
avicarie Sep 4, 2025
68277dc
Switch to english service naming (#486)
e-halinen Sep 9, 2025
5d46730
Fix merge conflicts (#489)
e-halinen Sep 10, 2025
1919955
AB#65345 fix 100H line issue (#490)
e-halinen Sep 11, 2025
fb668c5
fetch all variants for lineTimetable
ahjyrkia Sep 12, 2025
d32f821
Merge pull request #491 from HSLdevcom/AB#64927_fetch_with_base_lineId
ahjyrkia Sep 12, 2025
c6ee69a
Merge branch 'master' into test_tst
avicarie Sep 17, 2025
ae8074f
v1.1.4
avicarie Sep 17, 2025
66bb9dd
Merge pull request #493 from HSLdevcom/merge_master_into_development
avicarie Sep 17, 2025
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
7 changes: 3 additions & 4 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PG_CONNECTION_STRING=
REDIS_CONNECTION_STRING=
PUBLISHER_RENDER_URL=
REACT_APP_PUBLISHER_SERVER_URL=http://julistegeneraattori-server:4000
REACT_APP_PUBLISHER_SERVER_URL=http://map-publisher-server:4000

DIGITRANSIT_URL=https://dev-api.digitransit.fi/
DIGITRANSIT_APIKEY=
Expand All @@ -21,7 +21,6 @@ API_CLIENT_SECRET=

REDIRECT_URI=https://dev.kartat.hsl.fi/julkaisin
LOGIN_PROVIDER_URI=https://hslid-uat.cinfra.fi
DOMAINS_ALLOWED_TO_GENERATE=
DOMAINS_ALLOWED_TO_LOGIN=

PUBLISHER_TEST_GROUP=Karttajulkaisin-test
GROUP_GENERATE=
GROUP_READONLY=
5 changes: 2 additions & 3 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ API_CLIENT_SECRET=

REDIRECT_URI=http://localhost:3000
LOGIN_PROVIDER_URI=https://hslid-uat.cinfra.fi
DOMAINS_ALLOWED_TO_GENERATE=
DOMAINS_ALLOWED_TO_LOGIN=

PUBLISHER_TEST_GROUP=Karttajulkaisin-test
GROUP_GENERATE=
GROUP_READONLY=

BUILD_ENV=local
5 changes: 2 additions & 3 deletions .env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ API_CLIENT_SECRET=

REDIRECT_URI=https://kartat.hsl.fi/julkaisin
LOGIN_PROVIDER_URI=https://id.hsl.fi
DOMAINS_ALLOWED_TO_GENERATE=
DOMAINS_ALLOWED_TO_LOGIN=

PUBLISHER_TEST_GROUP=Karttajulkaisin-test
GROUP_GENERATE=
GROUP_READONLY=
26 changes: 18 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# Specify a non-default branch for pull requests for npm

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
# Raise pull requests for version updates
# to npm against the `development` branch
interval: "weekly"
cooldown:
semver-major-days: 90
semver-minor-days: 60
semver-patch-days: 30
groups:
major:
update-types:
- "major"
minor:
update-types:
- "minor"
- "patch"
open-pull-requests-limit: 5
target-branch: "development"
# Labels on pull requests for version updates only
labels:
- "NPM Dependencies"
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:18-buster-slim
FROM node:18-bullseye-slim

RUN apt-get update \
RUN apt-get -y update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq wget curl gnupg fontconfig fonts-liberation ca-certificates --no-install-recommends \
# This installs the necessary libs to make the bundled version of Chromium that Puppeteer installs work
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
Expand Down
5 changes: 2 additions & 3 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ module.exports = {
AZURE_STORAGE_KEY: secretsEnv.AZURE_STORAGE_KEY || '',
CLIENT_SECRET: secretsEnv.CLIENT_SECRET || '',
API_CLIENT_SECRET: secretsEnv.API_CLIENT_SECRET || '',
DOMAINS_ALLOWED_TO_GENERATE: secretsEnv.DOMAINS_ALLOWED_TO_GENERATE || '',
DOMAINS_ALLOWED_TO_LOGIN: secretsEnv.DOMAINS_ALLOWED_TO_LOGIN || '',
HSL_TESTING_HSLID_USERNAME: secretsEnv.HSL_TESTING_HSLID_USERNAME || '',
HSL_TESTING_HSLID_PASSWORD: secretsEnv.HSL_TESTING_HSLID_PASSWORD || '',
PUBLISHER_TEST_GROUP: secretsEnv.PUBLISHER_TEST_GROUP || '',
GROUP_GENERATE: secretsEnv.GROUP_GENERATE || '',
GROUP_READONLY: secretsEnv.GROUP_READONLY || '',
TEST_PUBLISHER_SERVER_URL: secretsEnv.TEST_PUBLISHER_SERVER_URL || 'http://localhost:4000',
};
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hsl-map-publisher",
"version": "1.1.3",
"version": "1.1.4",
"description": "HSL Map Publisher",
"main": "index.js",
"scripts": {
Expand All @@ -23,7 +23,7 @@
"docker:rebuild": "yarn run docker:stop && yarn run docker:rm && yarn run docker:build && yarn run docker:run",
"docker:logs": "docker logs publisher",
"prepare": "husky install",
"test": "node -r dotenv/config test/testStops"
"test": "node -r dotenv/config test/tests"
},
"lint-staged": {
"*.js": [
Expand Down Expand Up @@ -63,7 +63,7 @@
"eslint-import-resolver-webpack": "^0.10.1",
"eslint-loader": "^2.1.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.1",
"husky": "^8.0.0",
Expand All @@ -72,7 +72,7 @@
"react-refresh": "^0.14.0",
"webpack-cli": "^3.0.8",
"webpack-serve": "^1.0.4",
"worker-loader": "^2.0.0"
"worker-loader": "^3.0.8"
},
"dependencies": {
"@azure/storage-blob": "^10.4.0",
Expand Down Expand Up @@ -102,16 +102,16 @@
"koa-body": "^6.0.1",
"koa-json-body": "^5.3.0",
"koa-router": "^7.4.0",
"koa-session": "^5.10.1",
"koa-session": "6.0.0",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"node-fetch": "^1.7.3",
"node-fetch": "2.6.6",
"p-map": "^1.2.0",
"pdf-merger-js": "^3.4.0",
"pg": "^8.7.3",
"prop-types": "^15.6.0",
"puppeteer": "^13.7.0",
"qrcode": "^1.0.0",
"qrcode": "^1.5.4",
"qs": "^6.5.2",
"raw-loader": "^0.5.1",
"react": "18.2.0",
Expand All @@ -122,9 +122,8 @@
"recompose": "^0.30.0",
"segseg": "^0.2.2",
"serve": "^13.0.2",
"style-loader": "^0.19.0",
"style-loader": "^2.0.0",
"uuid": "^3.1.0",
"validator": "^13.15.0",
"viewport-mercator-project": "^4.1.1",
"webpack": "^4.12.1",
"webpack-merge": "^4.1.3"
Expand Down
36 changes: 12 additions & 24 deletions scripts/auth/authEndpoints.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
const { get, clone } = require('lodash');
const AuthService = require('./authService');
const validator = require('validator');

const { DOMAINS_ALLOWED_TO_LOGIN, PUBLISHER_TEST_GROUP } = require('../../constants');
const { GROUP_GENERATE, GROUP_READONLY } = require('../../constants');

const allowedDomains = DOMAINS_ALLOWED_TO_LOGIN.split(',');
const hasAllowedGroup = async userInfo => {
const groups = get(userInfo, 'groups', {});

const hasAllowedDomain = async userInfo => {
const groups = get(userInfo, 'groups');

const emailValidationOptions = {
host_whitelist: allowedDomains,
};

if (groups.includes(PUBLISHER_TEST_GROUP)) {
return true;
}

if (
!validator.isEmail(userInfo.email, emailValidationOptions) &&
!groups.includes(PUBLISHER_TEST_GROUP)
) {
console.log(`User does not have allowed domain. Logging out.`);
if (!groups || !Array.isArray(groups)) {
console.log('User does not have valid groups assigned');
return false;
}

return true;
if (groups.includes(GROUP_GENERATE) || groups.includes(GROUP_READONLY)) {
return true;
}
return false;
};

const authorize = async (req, res, session) => {
Expand Down Expand Up @@ -68,13 +56,13 @@ const authorize = async (req, res, session) => {
if (session && tokenResponse.access_token) {
modifiedSession.accessToken = tokenResponse.access_token;
const userInfo = await AuthService.requestUserInfo(modifiedSession.accessToken);
const isAllowed = await hasAllowedDomain(userInfo);
const isAllowed = await hasAllowedGroup(userInfo);
if (!isAllowed) {
return {
status: 401,
body: {
isOk: false,
message: 'No allowed group.',
message: 'User does not have valid groups assigned.',
},
};
}
Expand Down Expand Up @@ -105,7 +93,7 @@ const authorize = async (req, res, session) => {

const checkExistingSession = async (req, res, session) => {
if (session && session.accessToken) {
const isAllowed = await hasAllowedDomain(session);
const isAllowed = await hasAllowedGroup(session);
if (!isAllowed) {
await AuthService.logoutFromIdentityProvider(session.accessToken);
return {
Expand Down
Loading
Loading