Skip to content

Commit

Permalink
Merge pull request #314 from oslokommune/develop
Browse files Browse the repository at this point in the history
Release 2.6.0
  • Loading branch information
aulonm authored Nov 9, 2021
2 parents 5ceca83 + a9b5388 commit a642150
Show file tree
Hide file tree
Showing 83 changed files with 11,923 additions and 10,525 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
'func-names': 'off',
},
parserOptions: {
parser: 'babel-eslint',
parser: '@babel/eslint-parser',
},
settings: {
'import/resolver': {
Expand Down
27 changes: 17 additions & 10 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{
"plugins": [
"stylelint-order",
"stylelint-config-rational-order/plugin",
"stylelint-scss"
],
"customSyntax": "postcss-scss",
"plugins": ["stylelint-order", "stylelint-scss"],
"extends": ["stylelint-config-recommended-scss", "stylelint-config-recommended-vue"],
"rules": {
"color-hex-length": "long",
"indentation": 2,
"order/properties-order": [ ],
"order/properties-order": [],
"at-rule-no-unknown": null,
"scss/at-rule-no-unknown": true,
"no-descending-specificity": null,
"plugin/rational-order": [true, {
"border-in-box-model": false,
"empty-line-between-groups": false
}]
"scss/no-global-function-names": null,
"font-family-no-missing-generic-family-keyword": [
true,
{
"ignoreFontFamilies": ["Font Awesome 5 Free"]
}
],
"selector-pseudo-element-no-unknown": [
true,
{
"ignorePseudoElements": ["v-deep"]
}
]
}
}
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file. The format

## [UNRELEASED]

## [2.6.0] 2021-11-09

Last minor update before releasing our new design. New updates from now on will only be small bug fixes.

### Changes

- Rewritten sass rules from @import to @use/@forward - hopefully easier to implement the new Oslo Design System
- Rewritten all the Cloud Functions to es modules - we can now write more future-proof code.
- Updated all dependencies of Cloud Functions
- Updated dependencies
- Updated stylelint to v14 and fixed all the breaking changes

### Fixed

- Not allowed to update Period if you only changed the name.
- Showing loading spinner when fetching KPI/KeyResult progress
- Moved widgets around for a better UX experience for mobile users
- When updating Org/Dep/Prod, the state store would get corrupt and only refresh fixed it. Double documents would show because vuexfire does not handle hundreds of documents that well.
- functions: config to active slackbot or not actually works

## [2.5.3] 2021-10-27

### Fixed
Expand Down
22 changes: 12 additions & 10 deletions functions/api/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const functions = require('firebase-functions');
import functions from 'firebase-functions';

const express = require('express');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const morgan = require('morgan');
import express from 'express';
import cors from 'cors';
import cookieParser from 'cookie-parser';
import morgan from 'morgan';

const config = require('../config');
import config from '../config.js';

// Routes
const kpiRoutes = require('./routes/kpi');
const keyresRoutes = require('./routes/keyres');
import kpiRoutes from './routes/kpi.js';
import keyResRoutes from './routes/keyres.js';

const app = express();

Expand All @@ -20,6 +20,8 @@ app.use(morgan('combined'));

app.use('/kpi', kpiRoutes);

app.use('/keyres', keyresRoutes);
app.use('/keyres', keyResRoutes);

exports.app = functions.runWith(config.runtimeOpts).region(config.region).https.onRequest(app);
const api = functions.runWith(config.runtimeOpts).region(config.region).https.onRequest(app);

export default api;
29 changes: 16 additions & 13 deletions functions/api/routes/keyres.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const router = require('express').Router();
const admin = require('firebase-admin');
const { param, matchedData, body } = require('express-validator');
import express from 'express';
import { getFirestore } from 'firebase-admin/firestore';
import { param, matchedData, body } from 'express-validator';

const db = admin.firestore();

const collection = db.collection('keyResults');
const router = express.Router();

const validate = [body('progress').isFloat().escape(), param('id').trim().escape()];

Expand All @@ -18,7 +16,9 @@ router.post('/:id', ...validate, async (req, res) => {
return;
}

let keyres;
const db = getFirestore();
const collection = await db.collection('keyResults');
let keyRes;

try {
if (!progress || Number.isNaN(progress)) {
Expand All @@ -31,16 +31,16 @@ router.post('/:id', ...validate, async (req, res) => {
return;
}

keyres = await collection.doc(id).get();
keyRes = await collection.doc(id).get();

const { exists, ref } = keyres;
const { exists, ref } = keyRes;

if (!exists) {
res.status(404).send(`Could not find KPI with ID: ${id}`);
return;
}

const { parent } = keyres.data();
const { parent } = keyRes.data();

const parentData = await parent.get().then((snapshot) => snapshot.data());

Expand All @@ -61,8 +61,8 @@ router.post('/:id', ...validate, async (req, res) => {
res.send(`Updated Key result (${id}) with progress: ${progress}`);
} catch (e) {
console.error('ERROR: ', e.message);
if (keyres && keyres.ref) {
await keyres.ref.update({ valid: false, error: e.message });
if (keyRes && keyRes.ref) {
await keyRes.ref.update({ valid: false, error: e.message });
}
res.status(500).send(e.message);
}
Expand All @@ -72,6 +72,9 @@ router.get('/:id', param('id').trim().escape(), async (req, res) => {
const sanitized = matchedData(req);
const { id } = sanitized;

const db = getFirestore();
const collection = await db.collection('keyResults');

try {
const keyRes = await collection.doc(id).get();

Expand Down Expand Up @@ -141,4 +144,4 @@ router.get('/:id', param('id').trim().escape(), async (req, res) => {
}
});

module.exports = router;
export default router;
18 changes: 11 additions & 7 deletions functions/api/routes/kpi.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const router = require('express').Router();
const admin = require('firebase-admin');
const { body, param, matchedData } = require('express-validator');
import express from 'express';
import { getFirestore } from 'firebase-admin/firestore';
import { body, param, matchedData } from 'express-validator';

const db = admin.firestore();

const collection = db.collection('kpis');
const router = express.Router();

const validate = [body('progress').isFloat().escape(), param('id').trim().escape()];

Expand All @@ -18,6 +16,9 @@ router.post('/:id', ...validate, async (req, res) => {
return;
}

const db = getFirestore();
const collection = await db.collection('kpis');

try {
if (!progress || Number.isNaN(progress)) {
res.status(400).send('Invalid number');
Expand Down Expand Up @@ -61,6 +62,9 @@ router.get('/:id', param('id').trim().escape(), async (req, res) => {
const sanitized = matchedData(req);
const { id } = sanitized;

const db = getFirestore();
const collection = await db.collection('kpis');

try {
const kpi = await collection.doc(id).get();

Expand Down Expand Up @@ -125,4 +129,4 @@ router.get('/:id', param('id').trim().escape(), async (req, res) => {
}
});

module.exports = router;
export default router;
30 changes: 17 additions & 13 deletions functions/audit/auditOnCreateGenerator.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const config = require('../config');
import { getFirestore } from 'firebase-admin/firestore';
import functions from 'firebase-functions';
import config from '../config.js';
import { pushToSlack, colors, slackMessageCreated } from './helpers.js';

const environment = functions.config();
const isSlackActive = JSON.parse(functions.config().slack.active) || false;
const { host_url: HOST_URL } = environment.slack;

const { pushToSlack, colors, slackMessageCreated } = require('./helpers');

const db = admin.firestore();

exports.auditOnCreateGenerator = function ({ docPath, collectionRef, documentType }) {
return functions
const auditOnCreateGenerator = ({ docPath, collectionRef, documentType }) =>
functions
.runWith(config.runtimeOpts)
.region(config.region)
.firestore.document(docPath)
.onCreate(async (snapshot, context) => {
const db = getFirestore();

const collection = await db.collection(collectionRef);

const { documentId } = context.params;

const auditData = {
event: `${documentType}Created`,
timestamp: new Date(),
documentRef: collectionRef.doc(documentId),
documentRef: collection.doc(documentId),
};

const documentData = snapshot.data();
Expand All @@ -34,12 +36,12 @@ exports.auditOnCreateGenerator = function ({ docPath, collectionRef, documentTyp
auditData.department = documentData.department;
}

await checkIfRelevantToPushToSlack(auditData, documentType);
if (isSlackActive) {
await checkIfRelevantToPushToSlack(auditData, documentType);
}

return db.collection('audit').add(auditData);
});
};


/**
* Check if the audit log is relevant to push to slack channels
Expand Down Expand Up @@ -81,3 +83,5 @@ const checkIfRelevantToPushToSlack = async (auditData, documentType) => {

return true;
};

export default auditOnCreateGenerator;
21 changes: 12 additions & 9 deletions functions/audit/auditOnDeleteGenerator.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const config = require('../config');
import { getFirestore } from 'firebase-admin/firestore';
import functions from 'firebase-functions';
import config from '../config.js';

const db = admin.firestore();

exports.auditOnDeleteGenerator = function ({ docPath, collectionRef, documentType }) {
return functions
const auditOnDeleteGenerator = ({ docPath, collectionRef, documentType }) =>
functions
.runWith(config.runtimeOpts)
.region(config.region)
.firestore.document(docPath)
.onDelete(async (snapshot, context) => {
const db = getFirestore();

const collection = await db.collection(collectionRef);

const { documentId } = context.params;

const auditData = {
event: `${documentType}Deleted`,
timestamp: new Date(),
documentRef: collectionRef.doc(documentId),
documentRef: collection.doc(documentId),
};

const documentData = snapshot.data();
Expand Down Expand Up @@ -49,4 +51,5 @@ exports.auditOnDeleteGenerator = function ({ docPath, collectionRef, documentTyp

return db.collection('audit').add(auditData);
});
};

export default auditOnDeleteGenerator;
28 changes: 16 additions & 12 deletions functions/audit/auditOnUpdateGenerator.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const config = require('../config');
import { getFirestore } from 'firebase-admin/firestore';
import functions from 'firebase-functions';
import config from '../config.js';

const { checkIfRelevantToPushToSlack } = require('./helpers');
import { checkIfRelevantToPushToSlack } from './helpers.js';

const db = admin.firestore();
const isSlackActive = JSON.parse(functions.config().slack.active) || false;

exports.auditOnUpdateGenerator = function ({ docPath, fields, collectionRef, documentType }) {
return functions
const auditOnUpdateGenerator = ({ docPath, fields, collectionRef, documentType }) =>
functions
.runWith(config.runtimeOpts)
.region(config.region)
.firestore.document(docPath)
.onUpdate(async ({ before, after }, context) => {
const db = getFirestore();

const collection = await db.collection(collectionRef);

let event;
const diff = getDiff({ before, after }, fields);

Expand All @@ -32,30 +36,28 @@ exports.auditOnUpdateGenerator = function ({ docPath, fields, collectionRef, doc
const user = await (async () => {
try {
if ('progression' in diff) {
return getProgressionCreator(collectionRef.doc(documentId));
return getProgressionCreator(collection.doc(documentId));
}
return after.data().editedBy;
} catch {
return 'system';
}
})();


const auditData = {
event,
timestamp: new Date(),
documentRef: collectionRef.doc(documentId),
documentRef: collection.doc(documentId),
user: user || 'system',
diff,
};

if (auditData.event.includes('Updated')) {
if (auditData.event.includes('Updated') && isSlackActive) {
await checkIfRelevantToPushToSlack(documentType, auditData);
}

return db.collection('audit').add(auditData);
});
};

function getProgressionCreator(document) {
try {
Expand Down Expand Up @@ -94,3 +96,5 @@ function getDiff({ before, after }, keys) {

return diff;
}

export default auditOnUpdateGenerator;
Loading

0 comments on commit a642150

Please sign in to comment.