Mark push as enabled in serverInfo endpoint

This commit is contained in:
Drew Gross
2016-03-23 12:33:26 -07:00
parent 7738d33399
commit 19e6293638
5 changed files with 52 additions and 137 deletions

View File

@@ -1,33 +1,9 @@
'use strict';
var features = require('../src/features');
const request = require("request");
describe('features', () => {
it('set and get features', (done) => {
features.setFeature('push', {
testOption1: true,
testOption2: false
});
var _features = features.getFeatures();
var expected = {
testOption1: true,
testOption2: false
};
expect(_features.push).toEqual(expected);
done();
});
it('get features that does not exist', (done) => {
var _features = features.getFeatures();
expect(_features.test).toBeUndefined();
done();
});
it('requires the master key to get all schemas', done => {
it('requires the master key to get features', done => {
request.get({
url: 'http://localhost:8378/1/serverInfo',
json: true,

View File

@@ -18,12 +18,8 @@ export class AdaptableController {
this.options = options;
this.appId = appId;
this.adapter = adapter;
this.setFeature();
}
// sets features for Dashboard to consume from features router
setFeature() {}
set adapter(adapter) {
this.validateAdapter(adapter);
this[_adapter] = adapter;

View File

@@ -4,7 +4,6 @@ import rest from '../rest';
import AdaptableController from './AdaptableController';
import { PushAdapter } from '../Adapters/Push/PushAdapter';
import deepcopy from 'deepcopy';
import features from '../features';
import RestQuery from '../RestQuery';
import pushStatusHandler from '../pushStatusHandler';
@@ -13,10 +12,6 @@ const UNSUPPORTED_BADGE_KEY = "unsupported";
export class PushController extends AdaptableController {
setFeature() {
features.setFeature(FEATURE_NAME, this.adapter.feature || {});
}
/**
* Check whether the deviceType parameter in qury condition is valid or not.
* @param {Object} where A query condition
@@ -39,9 +34,13 @@ export class PushController extends AdaptableController {
}
}
pushIsAvailable() {
return !!this.adapter;
}
sendPush(body = {}, where = {}, config, auth, wait) {
var pushAdapter = this.adapter;
if (!pushAdapter) {
if (!this.pushIsAvailable()) {
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
'Push adapter is not available');
}

View File

@@ -1,13 +1,49 @@
import { version } from '../../package.json';
import PromiseRouter from '../PromiseRouter';
import * as middleware from "../middlewares";
import { getFeatures } from '../features';
export class FeaturesRouter extends PromiseRouter {
mountRoutes() {
this.route('GET','/serverInfo', middleware.promiseEnforceMasterKeyAccess, () => {
this.route('GET','/serverInfo', middleware.promiseEnforceMasterKeyAccess, req => {
const features = {
globalConfig: {
create: false,
read: false,
update: false,
delete: false,
},
hooks: {
create: false,
read: false,
update: false,
delete: false,
},
logs: {
level: false,
size: false,
order: false,
until: false,
from: false,
},
push: {
immediatePush: req.config.pushController.pushIsAvailable(),
scheduledPush: false,
storedPushData: false,
pushAudiences: false,
},
schemas: {
addField: true,
removeField: true,
addClass: true,
removeClass: true,
clearAllDataFromClass: false,
exportClass: false,
editClassLevelPermissions: true,
},
};
return { response: {
features: getFeatures(),
features: features,
parseServerVersion: version,
} };
});

View File

@@ -1,92 +0,0 @@
/**
* features.js
* Feature config file that holds information on the features that are currently
* available on Parse Server. This is primarily created to work with an UI interface
* like the web dashboard. The list of features will change depending on the your
* app, choice of adapter as well as Parse Server version. This approach will enable
* the dashboard to be built independently and still support these use cases.
*
*
* Default features and feature options are listed in the features object.
*
* featureSwitch is a convenient way to turn on/off features without changing the config
*
* Features that use Adapters should specify the feature options through
* the setFeature method in your controller and feature
* Reference PushController and ParsePushAdapter as an example.
*
* NOTE: When adding new endpoints be sure to update this list both (features, featureSwitch)
* if you are planning to have a UI consume it.
*/
// default features
let features = {
globalConfig: {
create: false,
read: false,
update: false,
delete: false,
},
hooks: {
create: false,
read: false,
update: false,
delete: false,
},
logs: {
level: false,
size: false,
order: false,
until: false,
from: false,
},
push: {
immediatePush: false,
scheduledPush: false,
storedPushData: false,
pushAudiences: false,
},
schemas: {
addField: true,
removeField: true,
addClass: true,
removeClass: true,
clearAllDataFromClass: false,
exportClass: false,
editClassLevelPermissions: true,
},
};
// master switch for features
let featuresSwitch = {
globalConfig: true,
hooks: true,
logs: true,
push: true,
schemas: true,
};
/**
* set feature config options
*/
function setFeature(key, value) {
features[key] = value;
}
/**
* get feature config options
*/
function getFeatures() {
let result = {};
Object.keys(features).forEach((key) => {
if (featuresSwitch[key] && features[key]) {
result[key] = features[key];
}
});
return result;
}
module.exports = {
getFeatures,
setFeature,
};