diff --git a/src/Routes/RouteAdminDeactivate.c b/src/Routes/RouteAdminDeactivate.c index 079ad62..baa73ae 100644 --- a/src/Routes/RouteAdminDeactivate.c +++ b/src/Routes/RouteAdminDeactivate.c @@ -96,7 +96,7 @@ ROUTE_IMPL(RouteAdminDeactivate, path, argp) if (method == HTTP_DELETE) { - UserDeactivateWithInfo(removed, UserGetName(user), reason); + UserDeactivate(removed, UserGetName(user), reason); response = HashMapCreate(); JsonSet(response, JsonValueString(removedLocalpart), 1, "user"); diff --git a/src/Routes/RouteDeactivate.c b/src/Routes/RouteDeactivate.c index 09538f8..66956e6 100644 --- a/src/Routes/RouteDeactivate.c +++ b/src/Routes/RouteDeactivate.c @@ -126,7 +126,7 @@ ROUTE_IMPL(RouteDeactivate, path, argp) goto finish; } - if (!UserDeleteTokens(user, NULL) || !UserDeactivate(user)) + if (!UserDeleteTokens(user, NULL) || !UserDeactivate(user, NULL, NULL)) { HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); response = MatrixErrorCreate(M_UNKNOWN, NULL); diff --git a/src/User.c b/src/User.c index ca87f08..c5dd234 100644 --- a/src/User.c +++ b/src/User.c @@ -429,31 +429,30 @@ UserSetPassword(User * user, char *password) } int -UserDeactivate(User * user) -{ - return UserDeactivateWithInfo(user, NULL, NULL); -} -int -UserDeactivateWithInfo(User * user, char * admin, char * reason) +UserDeactivate(User * user, char * from, char * reason) { HashMap *json; + JsonValue *val; if (!user) { return 0; } + + /* By default, it's the target's username */ + if (!from) + { + from = UserGetName(user); + } json = DbJson(user->ref); JsonValueFree(HashMapSet(json, "deactivated", JsonValueBoolean(1))); - if (admin && reason) + val = JsonValueString(from); + JsonValueFree(JsonSet(json, val, 2, "deactivate", "by")); + if (reason) { - JsonValue * val; - - val = JsonValueString(admin); - JsonValueFree(JsonSet(json, val, 2, "deactivate", "admin")); - val = JsonValueString(reason); JsonValueFree(JsonSet(json, val, 2, "deactivate", "reason")); } diff --git a/src/include/User.h b/src/include/User.h index 7fb720c..a7ce6ff 100644 --- a/src/include/User.h +++ b/src/include/User.h @@ -199,15 +199,12 @@ extern int UserSetPassword(User *, char *); * is to prevent future users from pretending to be a previous user * of a given localpart. The user is logged out; all access tokens are * invalidated. + * Additionally, it stores information on who deactivated the account + * (be it an admin or the user itself), and why. If the user + * responsible for deactivating the target user is NULL, then it is + * set to the target's own name. */ -extern int UserDeactivate(User *); - -/** - * Acts just like - * .Fn UserDeactivate , - * but saves the reason and admin that deactivated the user - */ -extern int UserDeactivateWithInfo(User *, char *, char *); +extern int UserDeactivate(User *, char *, char *); /** * Reactivates the given user account if it has been deactvated with @@ -220,7 +217,6 @@ extern int UserReactivate(User *); * Return a boolean value indicating whether or not the user was * deactivated using * .Fn UserDeactivate . - * Note that once deactivated, users cannot be reactivated. */ extern int UserDeactivated(User *);