mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
Merge pull request #285 from Unleash/fix_create_archived_toggle
Should not allow creation of archived toggle
This commit is contained in:
commit
8b77b21813
@ -7,7 +7,7 @@ env:
|
|||||||
- DATABASE_URL=postgres://postgres@localhost:5432/unleash_test TEST_DATABASE_URL=postgres://postgres@localhost:5432/unleash_test
|
- DATABASE_URL=postgres://postgres@localhost:5432/unleash_test TEST_DATABASE_URL=postgres://postgres@localhost:5432/unleash_test
|
||||||
global:
|
global:
|
||||||
secure: HyWYh1dbUfe2yPF9ZdcdA/IVGyNWmJmpuaRvRGnnpO63/5Y0KT6/hyL6nZ4YJ7Wr/KEt4eMJBJsnzaCFtiqNA3cWyyprzXJButw0o8C6dfd/9jOleisuvdqndu92RqDKIIq2EjHVq3sd6B8uGyiOlkMsyFH57O/V+xHW8MYLnaQ=
|
secure: HyWYh1dbUfe2yPF9ZdcdA/IVGyNWmJmpuaRvRGnnpO63/5Y0KT6/hyL6nZ4YJ7Wr/KEt4eMJBJsnzaCFtiqNA3cWyyprzXJButw0o8C6dfd/9jOleisuvdqndu92RqDKIIq2EjHVq3sd6B8uGyiOlkMsyFH57O/V+xHW8MYLnaQ=
|
||||||
before_install: yarn global add greenkeeper-lockfile@1
|
before_install: npm install -g greenkeeper-lockfile@1
|
||||||
before_script:
|
before_script:
|
||||||
- psql -c 'create database unleash_test;' -U postgres
|
- psql -c 'create database unleash_test;' -U postgres
|
||||||
- greenkeeper-lockfile-update
|
- greenkeeper-lockfile-update
|
||||||
|
@ -51,6 +51,14 @@ class FeatureToggleStore {
|
|||||||
.then(this.rowToFeature);
|
.then(this.rowToFeature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasFeatureName(name) {
|
||||||
|
return this.db
|
||||||
|
.first('name')
|
||||||
|
.from(TABLE)
|
||||||
|
.where({ name })
|
||||||
|
.then(n => !!n);
|
||||||
|
}
|
||||||
|
|
||||||
getArchivedFeatures() {
|
getArchivedFeatures() {
|
||||||
return this.db
|
return this.db
|
||||||
.select(FEATURE_COLUMNS)
|
.select(FEATURE_COLUMNS)
|
||||||
|
@ -97,12 +97,13 @@ module.exports.router = function(config) {
|
|||||||
|
|
||||||
function validateUniqueName(req) {
|
function validateUniqueName(req) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
featureToggleStore
|
featureToggleStore.hasFeatureName(req.body.name).then(hasName => {
|
||||||
.getFeature(req.body.name)
|
if (hasName) {
|
||||||
.then(() =>
|
reject(new NameExistsError('Feature name already exist'));
|
||||||
reject(new NameExistsError('Feature name already exist'))
|
} else {
|
||||||
)
|
resolve(req);
|
||||||
.catch(() => resolve(req));
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,3 +193,18 @@ test.serial(
|
|||||||
.then(destroy);
|
.then(destroy);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test.serial('should not be possible to create archived toggle', async t => {
|
||||||
|
t.plan(0);
|
||||||
|
const { request, destroy } = await setupApp('feature_api_serial');
|
||||||
|
return request
|
||||||
|
.post('/api/admin/features')
|
||||||
|
.send({
|
||||||
|
name: 'featureArchivedX',
|
||||||
|
enabled: false,
|
||||||
|
strategies: [{ name: 'default' }],
|
||||||
|
})
|
||||||
|
.set('Content-Type', 'application/json')
|
||||||
|
.expect(403)
|
||||||
|
.then(destroy);
|
||||||
|
});
|
||||||
|
1
test/fixtures/fake-feature-toggle-store.js
vendored
1
test/fixtures/fake-feature-toggle-store.js
vendored
@ -12,6 +12,7 @@ module.exports = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
getFeatures: () => Promise.resolve(_features),
|
getFeatures: () => Promise.resolve(_features),
|
||||||
|
hasFeatureName: () => Promise.resolve(false),
|
||||||
addFeature: feature => _features.push(feature),
|
addFeature: feature => _features.push(feature),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user