MXS-1220: Interpret no relationships as old relationships

When a PATCH request to a resource is made with no relationships defined,
it should be interpreted to be the same as the old relationships. Removal
of relationships can still be done by defining an empty relationships
object.
This commit is contained in:
Markus Mäkelä
2017-07-07 12:00:19 +03:00
parent 731d19ba70
commit 46339d620a
2 changed files with 13 additions and 0 deletions

View File

@ -45,6 +45,7 @@ MXS_BEGIN_DECLS
#define MXS_JSON_PTR_PARAMETERS "/data/attributes/parameters"
/** Pointers to relation lists */
#define MXS_JSON_PTR_RELATIONSHIPS "/data/relationships"
#define MXS_JSON_PTR_RELATIONSHIPS_SERVERS "/data/relationships/servers/data"
#define MXS_JSON_PTR_RELATIONSHIPS_SERVICES "/data/relationships/services/data"
#define MXS_JSON_PTR_RELATIONSHIPS_MONITORS "/data/relationships/monitors/data"

View File

@ -1093,6 +1093,12 @@ SERVER* runtime_create_server_from_json(json_t* json)
bool server_to_object_relations(SERVER* server, json_t* old_json, json_t* new_json)
{
if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS) == NULL)
{
/** No change to relationships */
return true;
}
bool rval = false;
set<string> old_relations;
set<string> new_relations;
@ -1270,6 +1276,12 @@ MXS_MONITOR* runtime_create_monitor_from_json(json_t* json)
bool object_to_server_relations(const char* target, json_t* old_json, json_t* new_json)
{
if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS) == NULL)
{
/** No change to relationships */
return true;
}
bool rval = false;
set<string> old_relations;
set<string> new_relations;