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)) {
|
||||
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());
|
||||
|
|
Loading…
Reference in New Issue