mirror of https://gitee.com/bigwinds/arangodb
Modified user config api to resemble the original behaviour
This commit is contained in:
parent
2cb82a1507
commit
c9f17f5f5e
|
@ -346,12 +346,31 @@ RestStatus RestUsersHandler::putRequest(AuthInfo* authInfo) {
|
||||||
if (canAccessUser(user)) {
|
if (canAccessUser(user)) {
|
||||||
std::string const& key = suffixes[2];
|
std::string const& key = suffixes[2];
|
||||||
VPackBuilder conf = authInfo->getConfigData(user);
|
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()) {
|
if (!parsedBody->isEmpty()) {
|
||||||
VPackBuilder b;
|
VPackSlice newVal = parsedBody->slice();
|
||||||
b(VPackValue(VPackValueType::Object))(key, parsedBody->slice())();
|
VPackSlice oldConf = conf.slice();
|
||||||
conf = conf.slice().isObject()
|
if (!newVal.isObject() || !newVal.hasKey("value")) {
|
||||||
? VPackCollection::merge(conf.slice(), b.slice(), false)
|
if (!oldConf.isObject() || !oldConf.hasKey(key)) {
|
||||||
: b;
|
// 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());
|
Result r = authInfo->setConfigData(user, conf.slice());
|
||||||
|
|
Loading…
Reference in New Issue