forked from Telodendria/Telodendria
[MOD] Delete id relation when DELETE is requested.
This commit is contained in:
parent
48ffd86553
commit
ad1901017f
1 changed files with 27 additions and 3 deletions
|
@ -190,22 +190,46 @@ ROUTE_IMPL(RouteAliasDirectory, path, argp)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!JsonGet(aliases, 2, "alias", alias))
|
||||
HashMap *roomAlias;
|
||||
char *id;
|
||||
|
||||
if (!(val = JsonGet(aliases, 2, "alias", alias)))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND, "Room alias not found.");
|
||||
goto finish;
|
||||
}
|
||||
roomAlias = JsonValueAsObject(val);
|
||||
id = StrDuplicate(JsonValueAsString(HashMapGet(roomAlias, "id")));
|
||||
Log(LOG_INFO, "id: %s", id);
|
||||
|
||||
if (!(UserGetPrivileges(user) & USER_ALIAS) && !StrEquals(UserGetName(user), JsonValueAsString(JsonGet(aliases, 3, "alias", alias, "createdBy"))))
|
||||
if (!(UserGetPrivileges(user) & USER_ALIAS) && !StrEquals(UserGetName(user), JsonValueAsString(JsonGet(roomAlias, 1, "createdBy"))))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||
response = MatrixErrorCreate(M_UNAUTHORIZED, NULL);
|
||||
Free(id);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
JsonValueFree(HashMapDelete(JsonValueAsObject(HashMapGet(aliases, "alias")), alias));
|
||||
/* TODO: Delete from "id" objects when putting aliases. */
|
||||
|
||||
idObject = JsonValueAsObject(JsonGet(aliases, 2, "id", id));
|
||||
if (idObject)
|
||||
{
|
||||
size_t i;
|
||||
val = HashMapGet(idObject, "aliases");
|
||||
arr = JsonValueAsArray(val);
|
||||
for (i = 0; i < ArraySize(arr); i++)
|
||||
{
|
||||
if (StrEquals(JsonValueAsString(ArrayGet(arr, i)), alias))
|
||||
{
|
||||
JsonValueFree(ArrayDelete(arr, i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Free(id);
|
||||
|
||||
}
|
||||
response = HashMapCreate();
|
||||
|
||||
|
|
Loading…
Reference in a new issue