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
|
|
|
|
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 {
|
2021-01-18 12:32:19 +01:00
|
|
|
constructor(config, { featureToggleService }) {
|
2018-12-19 14:50:01 +01:00
|
|
|
super(config);
|
2019-04-30 21:14:23 +02:00
|
|
|
this.logger = config.getLogger('/admin-api/archive.js');
|
2021-01-18 12:32:19 +01:00
|
|
|
this.featureService = featureToggleService;
|
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) {
|
2021-01-18 12:32:19 +01:00
|
|
|
const features = await this.featureService.getArchivedFeatures();
|
2018-11-30 08:24:22 +01:00
|
|
|
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 {
|
2021-01-18 12:32:19 +01:00
|
|
|
await this.featureService.reviveToggle(req.params.name, userName);
|
2020-04-14 22:29:11 +02:00
|
|
|
return res.status(200).end();
|
2018-11-30 08:24:22 +01:00
|
|
|
} 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;
|