Skip to content

Commit

Permalink
Merge branch 'dev' into wip/bewest/document-data-rights
Browse files Browse the repository at this point in the history
  • Loading branch information
bewest authored May 2, 2023
2 parents a6ad678 + aa4faa6 commit 37a4ec1
Show file tree
Hide file tree
Showing 108 changed files with 5,030 additions and 3,784 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
branches: [ dev ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
branches: [ dev ]
schedule:
- cron: '43 23 * * 3'

Expand All @@ -37,11 +37,11 @@ jobs:

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

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -52,7 +52,7 @@ jobs:
# 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
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -66,4 +66,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
strategy:
matrix:
node-version: [14.x, 16.x]
mongodb-version: [4.2, 4.4]
mongodb-version: [4.4, 5.0, 6.0]

steps:
- name: Git Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
password: ${{ secrets.DOCKER_PASS }}
- name: Clean git Checkout
if: success()
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Build, tag and push the dev Docker image
if: success() && github.ref == 'refs/heads/dev'
uses: docker/build-push-action@v2
Expand Down
5 changes: 5 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@
"description": "Default setting for new browser views, for the time mode. ('12' or '24')",
"value": "12",
"required": false
},
"USE_NPM_INSTALL": {
"description": "You need to have this set for deployment to work in Heroku",
"value": "true",
"required": true
}
},
"addons": [
Expand Down
10 changes: 8 additions & 2 deletions bundle/bundle.source.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ require('../node_modules/flot/jquery.flot.time');
require('../node_modules/flot/jquery.flot.pie');
require('../node_modules/flot/jquery.flot.fillbetween');

window.moment = require('moment-timezone');
const moment = require('moment-timezone');

window.moment = moment;

window.Nightscout = window.Nightscout || {};

var ctx = {
moment: moment
};

window.Nightscout = {
client: require('../lib/client'),
units: require('../lib/units')(),
admin_plugins: require('../lib/admin_plugins/')()
admin_plugins: require('../lib/admin_plugins/')(ctx)
};

window.Nightscout.report_plugins_preinit = require('../lib/report_plugins/');
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
version: '3'

x-logging:
&default-logging
options:
max-size: '10m'
max-file: '5'
driver: json-file

services:
mongo:
image: mongo:4.4
volumes:
- ${NS_MONGO_DATA_DIR:-./mongo-data}:/data/db:cached
logging: *default-logging

nightscout:
image: nightscout/cgm-remote-monitor:latest
Expand All @@ -19,6 +27,7 @@ services:
- 'traefik.http.routers.nightscout.rule=Host(`localhost`)'
- 'traefik.http.routers.nightscout.entrypoints=websecure'
- 'traefik.http.routers.nightscout.tls.certresolver=le'
logging: *default-logging
environment:
### Variables for the container
NODE_ENV: production
Expand Down Expand Up @@ -74,3 +83,4 @@ services:
volumes:
- './letsencrypt:/letsencrypt'
- '/var/run/docker.sock:/var/run/docker.sock:ro'
logging: *default-logging
5 changes: 3 additions & 2 deletions lib/admin_plugins/cleanentriesdb.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';

var moment = require('moment');
var moment;

var cleanentriesdb = {
name: 'cleanentriesdb'
, label: 'Clean Mongo entries (glucose entries) database'
, pluginType: 'admin'
};

function init() {
function init(ctx) {
moment = ctx.moment;
return cleanentriesdb;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/admin_plugins/cleanstatusdb.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';

var moment = require('moment');
var moment;

var cleanstatusdb = {
name: 'cleanstatusdb'
, label: 'Clean Mongo status database'
, pluginType: 'admin'
};

function init () {
function init (ctx) {
moment = ctx.moment;
return cleanstatusdb;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/admin_plugins/cleantreatmentsdb.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';

var moment = require('moment');
var moment;

var cleantreatmentsdb = {
name: 'cleantreatmentsdb'
, label: 'Clean Mongo treatments database'
, pluginType: 'admin'
};

function init() {
function init(ctx) {
moment = ctx.moment;
return cleantreatmentsdb;
}

Expand Down
14 changes: 7 additions & 7 deletions lib/admin_plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
var _find = require('lodash/find');
var _each = require('lodash/each');

function init() {
function init(ctx) {
var allPlugins = [
require('./subjects')()
, require('./roles')()
, require('./cleanstatusdb')()
, require('./cleantreatmentsdb')()
, require('./cleanentriesdb')()
, require('./futureitems')()
require('./subjects')(ctx)
, require('./roles')(ctx)
, require('./cleanstatusdb')(ctx)
, require('./cleantreatmentsdb')(ctx)
, require('./cleanentriesdb')(ctx)
, require('./futureitems')(ctx)
];

function plugins(name) {
Expand Down
10 changes: 6 additions & 4 deletions lib/api/entries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,16 @@ function configure (app, wares, ctx, env) {
});
} else {
inMemoryCollection = ctx.cache.getData('entries');

inMemoryCollection = _.sortBy(inMemoryCollection, function(item) {
return item.mills;
}).reverse();
}

if (inMemoryPossible && query.count <= inMemoryCollection.length) {
res.entries = _.cloneDeep(_.take(inMemoryCollection,query.count));

for (let i = 0; i < res.entries.length; i++) {
let e = res.entries[i];
e.mills = e.mills || e.date;
}

res.entries_err = null;
return next();
}
Expand Down
4 changes: 4 additions & 0 deletions lib/api/notifications-api.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
'use strict';

var consts = require('../constants');
var bodyParser = require('body-parser');

function configure (app, wares, ctx) {
var express = require('express')
, api = express.Router( )
;

app.use(bodyParser.urlencoded({extended : true}));
app.use(bodyParser.json());

api.post('/notifications/pushovercallback', function (req, res) {
if (ctx.pushnotify.pushoverAck(req.body)) {
res.sendStatus(consts.HTTP_OK);
Expand Down
4 changes: 3 additions & 1 deletion lib/api/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function create (env, ctx) {
*
* Expecting to define extended syntax and support for several query params
*/
properties.use(ctx.authorization.isPermitted('api:entries:read'),
ctx.authorization.isPermitted('api:treatments:read'));
properties.get(['/', '/*'], function getProperties (req, res) {

var sbx = sandbox.serverInit(env, ctx);
Expand Down Expand Up @@ -57,4 +59,4 @@ function create (env, ctx) {
return properties;
}

module.exports = create;
module.exports = create;
24 changes: 13 additions & 11 deletions lib/api/treatments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,20 @@ function configure (app, wares, ctx, env) {
}
});

if (!_isNil(d1)) res.setHeader('Last-Modified', d1.toUTCString());

if (ifModifiedSince && d1.getTime() <= moment(ifModifiedSince).valueOf()) {
res.status(304).send({
status: 304
, message: 'Not modified'
, type: 'internal'
});
return;
} else {
return res.json(results);
if (!_isNil(d1)) {
res.setHeader('Last-Modified', d1.toUTCString());

if (ifModifiedSince && d1.getTime() <= moment(ifModifiedSince).valueOf()) {
res.status(304).send({
status: 304
, message: 'Not modified'
, type: 'internal'
});
return;
}
}

return res.json(results);
}

// List treatments available
Expand Down
Loading

0 comments on commit 37a4ec1

Please sign in to comment.