2017-06-28 10:20:22 +02:00
|
|
|
'use strict';
|
|
|
|
|
2018-11-30 10:11:36 +01:00
|
|
|
const Controller = require('../controller');
|
2017-06-28 10:20:22 +02:00
|
|
|
|
|
|
|
const { FEATURE_REVIVED } = require('../../event-type');
|
2018-06-25 18:34:23 +02:00
|
|
|
const extractUser = require('../../extract-user');
|
2018-12-19 12:22:48 +01:00
|
|
|
const { UPDATE_FEATURE } = require('../../permissions');
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2018-11-30 10:11:36 +01:00
|
|
|
class ArchiveController extends Controller {
|
2018-12-19 14:50:01 +01:00
|
|
|
constructor(config) {
|
|
|
|
super(config);
|
2019-04-30 21:14:23 +02:00
|
|
|
this.logger = config.getLogger('/admin-api/archive.js');
|
2018-12-19 14:50:01 +01:00
|
|
|
this.featureToggleStore = config.stores.featureToggleStore;
|
|
|
|
this.eventStore = config.stores.eventStore;
|
2018-11-30 08:24:22 +01:00
|
|
|
|
2018-11-30 10:11:36 +01:00
|
|
|
this.get('/features', this.getArchivedFeatures);
|
2018-12-19 12:22:48 +01:00
|
|
|
this.post('/revive/:name', this.reviveFeatureToggle, UPDATE_FEATURE);
|
2017-06-28 10:20:22 +02:00
|
|
|
}
|
|
|
|
|
2018-11-30 08:24:22 +01:00
|
|
|
async getArchivedFeatures(req, res) {
|
|
|
|
const features = await this.featureToggleStore.getArchivedFeatures();
|
|
|
|
res.json({ features });
|
|
|
|
}
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2018-11-30 08:24:22 +01:00
|
|
|
async reviveFeatureToggle(req, res) {
|
|
|
|
const userName = extractUser(req);
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2018-11-30 08:24:22 +01:00
|
|
|
try {
|
|
|
|
await this.eventStore.store({
|
|
|
|
type: FEATURE_REVIVED,
|
|
|
|
createdBy: userName,
|
|
|
|
data: { name: req.params.name },
|
|
|
|
});
|
|
|
|
res.status(200).end();
|
|
|
|
} catch (error) {
|
2019-04-30 21:14:23 +02:00
|
|
|
this.logger.error('Server failed executing request', error);
|
2018-11-30 08:24:22 +01:00
|
|
|
return res.status(500).end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-25 18:34:23 +02:00
|
|
|
|
2018-11-30 08:24:22 +01:00
|
|
|
module.exports = ArchiveController;
|