From 72d5cceda8f7462f897a380ec819f9c0a9ca7ce0 Mon Sep 17 00:00:00 2001 From: guerler Date: Fri, 10 Nov 2023 23:35:51 +0300 Subject: [PATCH] Add mail activation operation to api --- .../src/components/Grid/configs/adminUsers.ts | 31 +++++++++++++++---- lib/galaxy/webapps/galaxy/api/users.py | 18 ++++++++++- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/client/src/components/Grid/configs/adminUsers.ts b/client/src/components/Grid/configs/adminUsers.ts index 372e2d9e229..59bc5988770 100644 --- a/client/src/components/Grid/configs/adminUsers.ts +++ b/client/src/components/Grid/configs/adminUsers.ts @@ -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)}.`, }; } }, diff --git a/lib/galaxy/webapps/galaxy/api/users.py b/lib/galaxy/webapps/galaxy/api/users.py index 1ab00769302..bb42f4a2fe4 100644 --- a/lib/galaxy/webapps/galaxy/api/users.py +++ b/lib/galaxy/webapps/galaxy/api/users.py @@ -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)