1
0
Fork 0

Modified user config api to resemble the original behaviour

This commit is contained in:
mchacki 2017-07-15 18:58:21 +02:00
parent 2cb82a1507
commit c9f17f5f5e
1 changed files with 24 additions and 5 deletions

View File

@ -346,12 +346,31 @@ RestStatus RestUsersHandler::putRequest(AuthInfo* authInfo) {
if (canAccessUser(user)) {
std::string const& key = suffixes[2];
VPackBuilder conf = authInfo->getConfigData(user);
// The API expects: { value : <toStore> }
// If we get sth else than the above it is translated
// to a remove of the config option.
if (!parsedBody->isEmpty()) {
VPackBuilder b;
b(VPackValue(VPackValueType::Object))(key, parsedBody->slice())();
conf = conf.slice().isObject()
? VPackCollection::merge(conf.slice(), b.slice(), false)
: b;
VPackSlice newVal = parsedBody->slice();
VPackSlice oldConf = conf.slice();
if (!newVal.isObject() || !newVal.hasKey("value")) {
if (!oldConf.isObject() || !oldConf.hasKey(key)) {
// Nothing to do. We do not have a config yet.
// so we do not create a new empty one.
resetResponse(ResponseCode::OK);
return RestStatus::DONE;
}
conf = VPackCollection::remove(oldConf, std::unordered_set<std::string>{key});
} else {
// We need to merge the new key into the config
newVal = newVal.get("value");
VPackBuilder b;
b.openObject();
b.add(key, newVal);
b.close();
conf = oldConf.isObject()
? VPackCollection::merge(oldConf, b.slice(), false)
: b;
}
}
Result r = authInfo->setConfigData(user, conf.slice());