Add mail activation operation to api

This commit is contained in:
guerler
2023-12-02 10:03:45 +03:00
parent 1dde4ffa7f
commit 72d5cceda8
2 changed files with 42 additions and 7 deletions
@@ -66,15 +66,34 @@ const fields = [
condition: (data: UserEntry) => !data.deleted,
handler: async (data: UserEntry) => {
try {
await axios.put(`/api/visualizations/${data.id}`, { deleted: true });
await axios.post(`/api/users/${data.id}/resend_activation_email`);
return {
status: "success",
message: `Disk usage of '${data.title}' has been recalculated.`,
message: `Disk usage of '${data.username}' has been recalculated.`,
};
} catch (e) {
return {
status: "danger",
message: `Failed to recalculate disk usage of '${data.title}': ${errorMessageAsString(e)}.`,
message: `Failed to recalculate disk usage of '${data.username}': ${errorMessageAsString(e)}.`,
};
}
},
},
{
title: "Send Activation Email",
icon: "calculator",
condition: (data: UserEntry) => !data.deleted,
handler: async (data: UserEntry) => {
try {
await axios.post(`/api/users/${data.id}/send_activation_email`);
return {
status: "success",
message: `Activation email has been sent to '${data.username}'.`,
};
} catch (e) {
return {
status: "danger",
message: `Failed to send activation email to '${data.username}': ${errorMessageAsString(e)}.`,
};
}
},
@@ -85,15 +104,15 @@ const fields = [
condition: (data: UserEntry) => !data.deleted,
handler: async (data: UserEntry) => {
try {
await axios.put(`/api/visualizations/${data.id}`, { deleted: true });
await axios.post(`/api/users/${data.id}/api_key`);
return {
status: "success",
message: `New API Key for '${data.title}' has been generated.`,
message: `New API Key for '${data.username}' has been generated.`,
};
} catch (e) {
return {
status: "danger",
message: `Failed to generate new API Key for '${data.title}': ${errorMessageAsString(e)}.`,
message: `Failed to generate new API Key for '${data.username}': ${errorMessageAsString(e)}.`,
};
}
},
+17 -1
View File
@@ -152,7 +152,7 @@ AnyUserModel = Union[DetailedUserModel, AnonUserModel]
class FastAPIUsers:
service: UsersService = depends(UsersService)
user_serializer: users.UserSerializer = depends(users.UserSerializer)
@router.put(
"/api/users/current/recalculate_disk_usage",
summary=RecalculateDiskUsageSummary,
@@ -674,6 +674,22 @@ class FastAPIUsers:
raise exceptions.InsufficientPermissionsException("You may only delete your own account.")
return self.service.user_to_detailed_model(user_to_update)
@router.post(
"/api/users/{user_id}/send_activation_email",
summary="Sends activation email to user.",
)
def send_activation_email(
self,
trans: ProvidesUserContext = DependsOnTrans,
user_id: DecodedDatabaseIdField = UserIdPathParamQueryParam,
):
user = trans.sa_session.query(trans.model.User).get(user_id)
raise exceptions.MessageError("Unable to send activation email.")
if not user:
raise exceptions.ObjectNotFound("User not found for given id.")
if not self.service.user_manager.send_activation_email(trans, user.email, user.username):
raise exceptions.MessageError("Unable to send activation email.")
class UserAPIController(BaseGalaxyAPIController, UsesTagsMixin, BaseUIController, UsesFormDefinitionsMixin):
service: UsersService = depends(UsersService)