Revert "[Broken] Revert changes to UserEncodePrivileges() and UserDecodePrivileges()"

This reverts commit 9b3b62ff30.
This commit is contained in:
Jordan Bancino 2023-11-08 09:50:14 -05:00
parent 9b3b62ff30
commit a5c5dee375
5 changed files with 13 additions and 17 deletions

View file

@ -238,7 +238,6 @@ RegTokenCreate(Db * db, char *name, char *owner, UInt64 expires, Int64 uses, int
ret->uses = uses;
ret->created_on = timestamp;
ret->expires_on = expires;
/* TODO: #37 type mismatch: UserEncodePrivileges() returns a JsonValue */
ret->grants = UserEncodePrivileges(privileges);
return ret;

View file

@ -98,15 +98,15 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
switch (HttpRequestMethodGet(args->context))
{
case HTTP_POST:
privileges = UserDecodePrivileges(val);
privileges = UserDecodePrivileges(JsonValueAsArray(val));
break;
case HTTP_PUT:
privileges = UserGetPrivileges(user);
privileges |= UserDecodePrivileges(val);
privileges |= UserDecodePrivileges(JsonValueAsArray(val));
break;
case HTTP_DELETE:
privileges = UserGetPrivileges(user);
privileges &= ~UserDecodePrivileges(val);
privileges &= ~UserDecodePrivileges(JsonValueAsArray(val));
break;
default:
/* Impossible */
@ -124,7 +124,7 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
/* Fall through */
case HTTP_GET:
response = HashMapCreate();
HashMapSet(response, "privileges", UserEncodePrivileges(UserGetPrivileges(user)));
HashMapSet(response, "privileges", JsonValueArray(UserEncodePrivileges(UserGetPrivileges(user))));
break;
default:
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);

View file

@ -276,7 +276,6 @@ ROUTE_IMPL(RouteRegister, path, argp)
if (info)
{
/* TODO: #37 type mismatch: info->grants is a string array. */
UserSetPrivileges(user, UserDecodePrivileges(info->grants));
RegTokenClose(info);
RegTokenFree(info);

View file

@ -749,7 +749,7 @@ UserGetPrivileges(User * user)
return USER_NONE;
}
return UserDecodePrivileges(HashMapGet(DbJson(user->ref), "privileges"));
return UserDecodePrivileges(JsonValueAsArray(HashMapGet(DbJson(user->ref), "privileges")));
}
int
@ -768,7 +768,7 @@ UserSetPrivileges(User * user, int privileges)
return 1;
}
val = UserEncodePrivileges(privileges);
val = JsonValueArray(UserEncodePrivileges(privileges));
if (!val)
{
return 0;
@ -779,19 +779,17 @@ UserSetPrivileges(User * user, int privileges)
}
int
UserDecodePrivileges(JsonValue * val)
UserDecodePrivileges(Array * arr)
{
int privileges = USER_NONE;
Array *arr;
size_t i;
if (!val || JsonValueType(val) != JSON_ARRAY)
if (!arr)
{
goto finish;
}
arr = JsonValueAsArray(val);
for (i = 0; i < ArraySize(arr); i++)
{
JsonValue *val = ArrayGet(arr, i);
@ -848,7 +846,7 @@ UserDecodePrivilege(const char *p)
}
}
JsonValue *
Array *
UserEncodePrivileges(int privileges)
{
Array *arr = ArrayCreate();
@ -880,7 +878,7 @@ UserEncodePrivileges(int privileges)
#undef A
finish:
return JsonValueArray(arr);
return arr;
}
UserId *

View file

@ -286,13 +286,13 @@ extern int UserSetPrivileges(User *, int);
* Decode the JSON that represents the user privileges into a packed
* bit field for simple manipulation.
*/
extern int UserDecodePrivileges(JsonValue *);
extern int UserDecodePrivileges(Array *);
/**
* Encode the packed bit field that represents user privileges as a
* JSON value.
*/
extern JsonValue *UserEncodePrivileges(int);
extern Array *UserEncodePrivileges(int);
/**
* Convert a string privilege into its bit in the bit field. This is