Skip to content

Commit

Permalink
Merge pull request #191 from City-of-Turku/develop
Browse files Browse the repository at this point in the history
 Release tku-v1.3

Changes:
- added customer group support for reservation payments
- added support for paid reservations that require manual confirmation
- added reservation order details to be included among other reservation details in staff pages
- updated Matomo tracking code and renamed tracking env variable from PIWIK_SITE_ID to MATOMO_SITE_ID
- changed home page purpose banners to be more compact on phones
- added support for service announcements via a header banner
- changed minimum node version requirement to be v14
- various minor improvements and fixes
  • Loading branch information
SanttuA authored Mar 24, 2022
2 parents 14f5b31 + 1a9ebe3 commit 77bbe04
Showing 127 changed files with 7,849 additions and 5,043 deletions.
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Dockerfile
.dockerignore
.editorconfig
.env.example
.github
.git
.gitattributes
.gitignore
.travis.yml
.vscode
node_modules
coverage
dist
docker-compose.yml
docker-compose.dev.yml
docker-compose.prod.yml
CHANGELOG.md
README.md
yarn.lock
70 changes: 70 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ develop ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ develop ]
schedule:
- cron: '41 14 * * 3'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
2 changes: 1 addition & 1 deletion .github/workflows/varaamo.yml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [10.x]
node-version: [14.x]

steps:
- uses: actions/checkout@v2
54 changes: 45 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
# Docker image for Varaamo
FROM node:14-alpine AS appbase

# Pull node image with locked node version
FROM node:10.15.1
# Install dependencies
FROM appbase AS deps
ENV NPM_CONFIG_LOGLEVEL warn

# Make guest app dir
RUN mkdir -p /usr/src/app
# defaults to production, docker-compose dev overrides this to development on build and run.
ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

WORKDIR /app
COPY package.json package-lock.json ./

RUN if [ "$NODE_ENV" = "production" ]; \
then npm ci --only=production && npm cache clean --force; \
else npm install; \
fi

# Create build
FROM appbase AS builder
WORKDIR /app
COPY --from=deps /app/node_modules /app/node_modules
COPY --from=deps /app/package.json /app/package-lock.json ./
COPY . .
RUN npm run build

# Create production image
FROM appbase AS runner

# defaults to production, docker-compose dev overrides this to development on build and run.
ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

# set babel cache under tmp to allow writes for non root users
ENV BABEL_CACHE_PATH=/tmp/babel_cache.json

# Set workdir
WORKDIR /usr/src/app

COPY package.json package.json
# copy desired files
COPY --from=builder /app/package.json /app/.babelrc ./

COPY yarn.lock yarn.lock
# copy individual folders
COPY --from=builder /app/config ./config
COPY --from=builder /app/server ./server
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist

RUN yarn install --silent
EXPOSE 8080

CMD ["yarn", "start"]
# set user to not be root
USER node
CMD ["node", "server/index.js"]
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@ User interface for the City of Turku [varaamo.turku.fi](https://varaamo.turku.fi
Recommended requirements
------------

- [node](http://nodejs.org/) `>=8.15.1` | Suggestion: `10.15.1`
- [npm](https://www.npmjs.com/) `>=6.4.1` | Suggestion: `6.4.1`
- [node](http://nodejs.org/) `>=14.19` | Suggestion: `14.19.0`
- [npm](https://www.npmjs.com/) `>=6.14` | Suggestion: `6.14.16`
- [yarn](https://yarnpkg.com/) Optional, if `yarn` is not included as part of your current node version. `npm` can be used.

Architecture
@@ -41,10 +41,21 @@ Usage
```
3. Start building docker image and start container:
```
$ docker-compose up
$ docker compose -f docker-compose.yml -f docker-compose.dev.yml up
```
4. Open `localhost:3000` on browser when Webpack bundling is ready.
### Starting dockerized production server
Starting production server works in the same way as starting a development server with these exceptions:
- Production default port is `8080`
- Starting production server with docker compose:
```
$ docker compose -f docker-compose.yml -f docker-compose.prod.yml up
```
### Starting local development server
Follow the instructions below to set up the development environment.
@@ -151,27 +162,27 @@ By default the running app uses port `8080`.
```
OR enable `eslint --fix` onSave config in your code editor config.
### Useful docker command
### Useful docker commands
- To rebuild the docker images:
```
$ docker-compose up --force-recreate --build
$ docker compose -f docker-compose.yml -f docker-compose.dev.yml up --force-recreate --build
```
- To enter inside docker container environment:
```
$ docker-compose exec web sh
$ docker compose exec node-app sh
```
- Remove docker container if needed:
```
$ docker rm -f varaamo-frontend
$ docker rm -f <container_name>
```
- Remove docker image:
```
$ docker rmi varaamo_web
$ docker rmi varaamo_node-app
```
- Running command inside Docker environment (test for example):
- Running command inside Docker environment:
(Make sure docker container is running)
```
$ docker-compose run web YOUR_COMMAND_HERE
$ docker compose run node-app YOUR_COMMAND_HERE
```
- Encounter `node-sass` issue ? try to go inside docker container environment and run `npm rebuild node-sass`
16 changes: 16 additions & 0 deletions app/actions/__tests__/reservationActions.spec.js
Original file line number Diff line number Diff line change
@@ -10,8 +10,10 @@ describe('Actions: reservationActions', () => {
};

let getRequestTypeDescriptorMock;
let getSuccessTypeDescriptorMock;
beforeEach(() => {
getRequestTypeDescriptorMock = simple.mock(apiUtils, 'getRequestTypeDescriptor');
getSuccessTypeDescriptorMock = simple.mock(apiUtils, 'getSuccessTypeDescriptor');
});

describe('deleteReservation', () => {
@@ -67,5 +69,19 @@ describe('Actions: reservationActions', () => {
],
});
});

describe('includes correct omitNotification boolean in meta', () => {
test('by default when value not given', () => {
reservationActions.putReservation(reservation);
expect(getSuccessTypeDescriptorMock.lastCall.args[1].meta.omitNotification).toBe(false);
});

test('when omitNotification is given', () => {
const omitSuccessNotification = true;
reservationActions.putReservation(reservation, omitSuccessNotification);
expect(getSuccessTypeDescriptorMock.lastCall.args[1].meta.omitNotification)
.toBe(omitSuccessNotification);
});
});
});
});
6 changes: 4 additions & 2 deletions app/actions/__tests__/resourceActions.spec.js
Original file line number Diff line number Diff line change
@@ -26,15 +26,17 @@ describe('Actions: resourceActions', () => {
start: time.startOf('day').toISOString(),
};

const include = 'order_detail';

test('when source = adminResourcesPage and userIsSuperUser = false', () => {
const actual = fetchFavoritedResources(time, source);
const expected = fetchResources(params, source);
const expected = fetchResources({ ...params, include }, source);
expect(JSON.stringify(actual)).toEqual(JSON.stringify(expected));
});

test('when source = adminResourcesPage and userIsSuperUser = true', () => {
const actual = fetchFavoritedResources(time, source, true);
const expected = fetchResources(paramsAll, source);
const expected = fetchResources({ ...paramsAll, include }, source);
expect(JSON.stringify(actual)).toEqual(JSON.stringify(expected));
});

10 changes: 5 additions & 5 deletions app/actions/__tests__/searchActions.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import simple from 'simple-mock';

import { getPiwikActionName, searchResources } from 'actions/searchActions';
import { getMatomoActionName, searchResources } from 'actions/searchActions';
import * as apiUtils from 'utils/apiUtils';

describe('Actions: searchActions', () => {
@@ -9,15 +9,15 @@ describe('Actions: searchActions', () => {
getRequestTypeDescriptorMock = simple.mock(apiUtils, 'getRequestTypeDescriptor');
});

describe('getPiwikActionName', () => {
describe('getMatomoActionName', () => {
describe('when searchParams.search is non-empty string', () => {
const searchParams = {
search: 'my search',
purpose: 'some purpose',
};

test('returns searchParams.search', () => {
expect(getPiwikActionName(searchParams)).toBe(searchParams.search);
expect(getMatomoActionName(searchParams)).toBe(searchParams.search);
});
});

@@ -30,7 +30,7 @@ describe('Actions: searchActions', () => {

test('returns text "category:" with searchParams.purpose', () => {
const expected = `category: ${searchParams.purpose}`;
expect(getPiwikActionName(searchParams)).toBe(expected);
expect(getMatomoActionName(searchParams)).toBe(expected);
});
});

@@ -41,7 +41,7 @@ describe('Actions: searchActions', () => {
};

test('returns text "-empty-search-"', () => {
expect(getPiwikActionName(searchParams)).toBe('-empty-search-');
expect(getMatomoActionName(searchParams)).toBe('-empty-search-');
});
});
});
1 change: 0 additions & 1 deletion app/actions/__tests__/userActions.spec.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ describe('Actions: userActions', () => {
args: [
'User',
'user-get',
id,
],
});
});
7 changes: 5 additions & 2 deletions app/actions/reservationActions.js
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ function postReservation(reservation) {
};
}

function putReservation(reservation) {
function putReservation(reservation, omitSuccessNotification = false) {
return {
[RSAA]: {
types: [
@@ -177,7 +177,10 @@ function putReservation(reservation) {
),
getSuccessTypeDescriptor(
types.API.RESERVATION_PUT_SUCCESS,
{ countable: true }
{
countable: true,
meta: { omitNotification: omitSuccessNotification }
}
),
getErrorTypeDescriptor(
types.API.RESERVATION_PUT_ERROR,
9 changes: 8 additions & 1 deletion app/actions/resourceActions.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,14 @@ function fetchFavoritedResources(timeAsMoment, source, userIsSuperUser = false)
is_favorite: true,
start: timeAsMoment.startOf('day').toISOString(),
};
if (source === 'adminResourcesPage' && userIsSuperUser === true) { return fetchResources(paramsAll, source); }

if (source === 'adminResourcesPage') {
if (userIsSuperUser) {
return fetchResources({ ...paramsAll, include: 'order_detail' }, source);
}
return fetchResources({ ...params, include: 'order_detail' }, source);
}

return fetchResources(params, source);
}

Loading

0 comments on commit 77bbe04

Please sign in to comment.