Skip to content

Commit

Permalink
NRPT-707: Add feature flags (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
marklise authored May 19, 2021
1 parent 101f76b commit b30a0a4
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export class ImportComponent implements OnInit, OnDestroy {
self.importService.refreshData();
});

// Feature flagging
this.buttonActions['nris-emli'] = this.configService.config['FEATURE_FLAG']['nris-emli-importer'];

this.disableSourceSystem();
}

Expand Down
3 changes: 3 additions & 0 deletions angular/projects/admin-nrpti/src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

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

// Import component defaults
window.__env.IMPORT_TABLE_INTERVAL = 15000;
Expand Down
43 changes: 43 additions & 0 deletions api/migrations/20210507195356-featureFlag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

let dbm;
let type;
let seed;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
}

exports.up = async function(db) {
console.log('**** Adding feature flag ****');
const mClient = await db.connection.connect(db.connectionString, { native_parser: true });

try {
const nrpti = await mClient.collection('nrpti');
await nrpti.insertOne({
_schemaName: 'FeatureFlag',
data: {
"nris-emli-importer": "true"
}
});
console.log('**** Finished adding flag ****');
} catch (error) {
console.error(`Migration did not complete. Error processing records: ${error.message}`);
}

mClient.close();
}

exports.down = function(db) {
return null;
}

exports._meta = {
"version": 1
}
7 changes: 6 additions & 1 deletion api/src/controllers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const BcmiConfig = require('./config/bcmi');
const NrcedConfig = require('./config/nrced');
const LngConfig = require('./config/lng');
const NrptiConfig = require('./config/nrpti');
const { featureFlag: FeatureFlag } = require('../models/index');

const CheckRole = function (roles, roleName, includeSysadmin = false) {
if (includeSysadmin) {
Expand All @@ -31,7 +32,7 @@ exports.protectedOptions = function (args, res, next) {
* @returns {object}
*/
exports.publicGetConfig = async function (args, res, next) {
console.log("Got configuration data");
console.log("Sent configuration data");
let configurationData = {};

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

// TODO: Put this in each respective application sub-section so we can feature-flag for each app
// independently.
configurationData['FEATURE_FLAG'] = await FeatureFlag.findOne({ _schemaName: 'FeatureFlag' });

// get project specific confguration
// fetch the latest business area specific CommunicationPackage
// attach it to the configuration data under "COMMUNICATIONS"
Expand Down
20 changes: 20 additions & 0 deletions api/src/models/featureFlag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const mongoose = require('mongoose');

module.exports = require('../utils/model-schema-generator')(
'FeatureFlag',
{
_schemaName: { type: String, default: 'FeatureFlag', index: true },
data: { type: mongoose.SchemaTypes.Mixed, default: '{}' },

addedBy: { type: String, default: null },
dateAdded: { type: Date, default: Date.now() },

updatedBy: { type: String, default: null },
dateUpdated: { type: Date, default: null },

// Permissions
write: [{ type: String, trim: true, default: 'sysadmin' }],
read: [{ type: String, trim: true, default: 'public' }]
},
'nrpti'
);
1 change: 1 addition & 0 deletions api/src/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports.epicProject = require('./epicProject');
exports.configData = require('./configData');
exports.mapLayerInfo = require('./mapLayerInfo');
exports.metric = require('./metric');
exports.featureFlag = require('./featureFlag');

// master
require('./master');
Expand Down

0 comments on commit b30a0a4

Please sign in to comment.