Skip to content

Commit b30a0a4

Browse files
authored
NRPT-707: Add feature flags (#861)
1 parent 101f76b commit b30a0a4

File tree

6 files changed

+76
-1
lines changed

6 files changed

+76
-1
lines changed

angular/projects/admin-nrpti/src/app/import/import.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ export class ImportComponent implements OnInit, OnDestroy {
9999
self.importService.refreshData();
100100
});
101101

102+
// Feature flagging
103+
this.buttonActions['nris-emli'] = this.configService.config['FEATURE_FLAG']['nris-emli-importer'];
104+
102105
this.disableSourceSystem();
103106
}
104107

angular/projects/admin-nrpti/src/env.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
// This is a hardcoded variable that does not come from the backend
2020
window.__env.APPLICATION = 'NRPTI';
21+
window.__env.FEATURE_FLAG = {
22+
"nris-emli-importer": false
23+
};
2124

2225
// Import component defaults
2326
window.__env.IMPORT_TABLE_INTERVAL = 15000;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
let dbm;
4+
let type;
5+
let seed;
6+
7+
/**
8+
* We receive the dbmigrate dependency from dbmigrate initially.
9+
* This enables us to not have to rely on NODE_PATH.
10+
*/
11+
exports.setup = function(options, seedLink) {
12+
dbm = options.dbmigrate;
13+
type = dbm.dataType;
14+
seed = seedLink;
15+
}
16+
17+
exports.up = async function(db) {
18+
console.log('**** Adding feature flag ****');
19+
const mClient = await db.connection.connect(db.connectionString, { native_parser: true });
20+
21+
try {
22+
const nrpti = await mClient.collection('nrpti');
23+
await nrpti.insertOne({
24+
_schemaName: 'FeatureFlag',
25+
data: {
26+
"nris-emli-importer": "true"
27+
}
28+
});
29+
console.log('**** Finished adding flag ****');
30+
} catch (error) {
31+
console.error(`Migration did not complete. Error processing records: ${error.message}`);
32+
}
33+
34+
mClient.close();
35+
}
36+
37+
exports.down = function(db) {
38+
return null;
39+
}
40+
41+
exports._meta = {
42+
"version": 1
43+
}

api/src/controllers/config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const BcmiConfig = require('./config/bcmi');
77
const NrcedConfig = require('./config/nrced');
88
const LngConfig = require('./config/lng');
99
const NrptiConfig = require('./config/nrpti');
10+
const { featureFlag: FeatureFlag } = require('../models/index');
1011

1112
const CheckRole = function (roles, roleName, includeSysadmin = false) {
1213
if (includeSysadmin) {
@@ -31,7 +32,7 @@ exports.protectedOptions = function (args, res, next) {
3132
* @returns {object}
3233
*/
3334
exports.publicGetConfig = async function (args, res, next) {
34-
console.log("Got configuration data");
35+
console.log("Sent configuration data");
3536
let configurationData = {};
3637

3738
configurationData['API_LOCATION'] = process.env.API_LOCATION;
@@ -48,6 +49,10 @@ exports.publicGetConfig = async function (args, res, next) {
4849
configurationData['IMPORT_TABLE_INTERVAL'] = process.env.IMPORT_TABLE_INTERVAL;
4950
configurationData['DEFAULT_IMPORT_TABLE_QUERY_PARAMS'] = process.env.DEFAULT_IMPORT_TABLE_QUERY_PARAMS;
5051

52+
// TODO: Put this in each respective application sub-section so we can feature-flag for each app
53+
// independently.
54+
configurationData['FEATURE_FLAG'] = await FeatureFlag.findOne({ _schemaName: 'FeatureFlag' });
55+
5156
// get project specific confguration
5257
// fetch the latest business area specific CommunicationPackage
5358
// attach it to the configuration data under "COMMUNICATIONS"

api/src/models/featureFlag.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const mongoose = require('mongoose');
2+
3+
module.exports = require('../utils/model-schema-generator')(
4+
'FeatureFlag',
5+
{
6+
_schemaName: { type: String, default: 'FeatureFlag', index: true },
7+
data: { type: mongoose.SchemaTypes.Mixed, default: '{}' },
8+
9+
addedBy: { type: String, default: null },
10+
dateAdded: { type: Date, default: Date.now() },
11+
12+
updatedBy: { type: String, default: null },
13+
dateUpdated: { type: Date, default: null },
14+
15+
// Permissions
16+
write: [{ type: String, trim: true, default: 'sysadmin' }],
17+
read: [{ type: String, trim: true, default: 'public' }]
18+
},
19+
'nrpti'
20+
);

api/src/models/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ exports.epicProject = require('./epicProject');
88
exports.configData = require('./configData');
99
exports.mapLayerInfo = require('./mapLayerInfo');
1010
exports.metric = require('./metric');
11+
exports.featureFlag = require('./featureFlag');
1112

1213
// master
1314
require('./master');

0 commit comments

Comments
 (0)