📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
feat: organisation deletion
Blue Mouse98f006e05a81
diff --git a/backend/apps/cloud/src/organisation/organisation.controller.ts b/backend/apps/cloud/src/organisation/organisation.controller.tsindex 295c6eb51..65c03ff92 100644--- a/backend/apps/cloud/src/organisation/organisation.controller.ts+++ b/backend/apps/cloud/src/organisation/organisation.controller.ts@@ -359,6 +359,35 @@ export class OrganisationController {await this.organisationService.deleteMembership(memberId)}+ @ApiBearerAuth()+ @Delete('/:orgId')+ @ApiResponse({ status: 200, type: Organisation })+ @Auth([], true)+ async delete(@Param('orgId') orgId: string, @CurrentUserId() userId: string) {+ this.logger.log({ orgId, userId }, 'DELETE /organisation/:orgId')++ const isOwner = await this.organisationService.isOrganisationOwner(+ orgId,+ userId,+ )++ if (!isOwner) {+ throw new ForbiddenException(+ 'You must be the organisation owner to delete it',+ )+ }++ try {+ await this.organisationService.deleteMemberships({+ organisation: { id: orgId },+ })+ await this.organisationService.delete(orgId)+ } catch (reason) {+ console.error('[ERROR] Failed to delete organisation:', reason)+ throw new BadRequestException('Failed to delete organisation')+ }+ }+@ApiBearerAuth()@Patch('/:orgId')@ApiResponse({ status: 200, type: Organisation })@@ -388,8 +417,8 @@ export class OrganisationController {await this.organisationService.update(orgId, {name: _trim(updateOrgDTO.name),})- } catch (e) {- console.error('[ERROR] Failed to update organisation:', e)+ } catch (reason) {+ console.error('[ERROR] Failed to update organisation:', reason)throw new BadRequestException('Failed to update organisation')}}diff --git a/backend/apps/cloud/src/organisation/organisation.service.ts b/backend/apps/cloud/src/organisation/organisation.service.tsindex 7316641b1..5f7b7f5bc 100644--- a/backend/apps/cloud/src/organisation/organisation.service.ts+++ b/backend/apps/cloud/src/organisation/organisation.service.ts@@ -41,6 +41,14 @@ export class OrganisationService {return this.organisationRepository.find(options)}+ async delete(id: string) {+ return this.organisationRepository.delete(id)+ }++ async deleteMemberships(options: FindOptionsWhere<OrganisationMember>) {+ return this.membershipRepository.delete(options)+ }+async findMemberships(options: FindManyOptions<OrganisationMember>) {return this.membershipRepository.find(options)}@@ -94,6 +102,18 @@ export class OrganisationService {}}+ async isOrganisationOwner(organisationId: string, userId: string) {+ const ownerMembership = await this.findOneMembership({+ where: {+ organisation: { id: organisationId },+ role: OrganisationRole.owner,+ user: { id: userId },+ },+ })++ return !!ownerMembership+ }+async getOrganisationOwner(organisationId: string) {const ownerMembership = await this.findOneMembership({where: {diff --git a/web/app/api/index.ts b/web/app/api/index.tsindex 411f84740..e9b8f94cd 100644--- a/web/app/api/index.ts+++ b/web/app/api/index.ts@@ -290,6 +290,14 @@ export const getOrganisation = (id: string) =>throw _isEmpty(error.response.data?.message) ? error.response.data : error.response.data.message})+export const deleteOrganisation = (id: string) =>+ api+ .delete(`/organisation/${id}`)+ .then((response) => response.data)+ .catch((error) => {+ throw _isEmpty(error.response.data?.message) ? error.response.data : error.response.data.message+ })+export const createOrganisation = (name: string) =>api.post('/organisation', { name })diff --git a/web/app/pages/Organisations/Settings/index.tsx b/web/app/pages/Organisations/Settings/index.tsxindex 56eb2127c..1555e735f 100644--- a/web/app/pages/Organisations/Settings/index.tsx+++ b/web/app/pages/Organisations/Settings/index.tsx@@ -1,4 +1,4 @@-import React, { useState, useEffect, useCallback } from 'react'+import React, { useState, useEffect, useCallback, useMemo } from 'react'import { toast } from 'sonner'import { Link, useNavigate } from '@remix-run/react'import { useTranslation } from 'react-i18next'@@ -8,7 +8,7 @@ import _keys from 'lodash/keys'import { withAuthentication, auth } from 'hoc/protected'import { TITLE_SUFFIX } from 'redux/constants'-import { transferProject, getOrganisation, updateOrganisation } from 'api'+import { transferProject, getOrganisation, updateOrganisation, deleteOrganisation } from 'api'import Input from 'ui/Input'import Button from 'ui/Button'import Loader from 'ui/Loader'@@ -21,7 +21,8 @@ import { DetailedOrganisation } from 'redux/models/Organisation'import { StateType } from 'redux/store'import { useSelector } from 'react-redux'import { Projects } from './Projects'-import { XCircleIcon } from '@heroicons/react/24/outline'+import { TrashIcon, XCircleIcon } from '@heroicons/react/24/outline'+// import { ArrowLeftRight } from 'lucide-react'const MAX_NAME_LENGTH = 50@@ -32,7 +33,7 @@ const OrganisationSettings = () => {const { id } = useRequiredParams<{ id: string }>()const navigate = useNavigate()- const { loading: authLoading } = useSelector((state: StateType) => state.auth)+ const { loading: authLoading, user } = useSelector((state: StateType) => state.auth)const [validated, setValidated] = useState(false)const [errors, setErrors] = useState<{@@ -53,6 +54,16 @@ const OrganisationSettings = () => {name: '',})+ const isOrganisationOwner = useMemo(() => {+ if (!organisation) {+ return false+ }++ const owner = organisation.members.find((member) => member.role === 'owner')++ return owner?.user?.email === user?.email+ }, [organisation, user])+const loadOrganisation = async (organisationId: string) => {if (isLoading) {return@@ -111,21 +122,21 @@ const OrganisationSettings = () => {}const onDelete = async () => {- setShowDelete(false)-- if (!isDeleting) {- setIsDeleting(true)- try {- toast.success(t('project.settings.deleted'))+ if (isDeleting) {+ return+ }- // todo+ setIsDeleting(true)- navigate(routes.organisations)- } catch (reason: any) {- toast.error(reason)- } finally {- setIsDeleting(false)- }+ try {+ await deleteOrganisation(id)+ toast.success(t('apiNotifications.organisationDeleted'))+ navigate(routes.organisations)+ } catch (reason: any) {+ toast.error(reason)+ } finally {+ setIsDeleting(false)+ setShowDelete(false)}}@@ -270,24 +281,18 @@ const OrganisationSettings = () => {{t('common.save')}</Button></div>- {/* {!project?.shared && (+ {isOrganisationOwner ? (<div className='flex flex-wrap justify-center gap-2'>- {!isSelfhosted && (- <Button onClick={() => setShowTransfer(true)} semiDanger semiSmall>- <>- <RocketLaunchIcon className='mr-1 h-5 w-5' />- {t('project.settings.transfer')}- </>- </Button>- )}- <Button onClick={() => !isDeleting && setShowDelete(true)} loading={isDeleting} danger semiSmall>- <>- <ExclamationTriangleIcon className='mr-1 h-5 w-5' />- {t('project.settings.delete')}- </>+ {/* <Button onClick={() => setShowTransfer(true)} semiDanger semiSmall>+ <ArrowLeftRight className='mr-1 h-5 w-5' />+ {t('project.settings.transfer')}+ </Button> */}+ <Button onClick={() => setShowDelete(true)} disabled={isDeleting} danger semiSmall>+ <TrashIcon className='mr-1 h-5 w-5' />+ {t('organisations.delete')}</Button></div>- )} */}+ ) : null}</div><hr className='mt-2 border-gray-200 dark:border-gray-600 sm:mt-5' /><People organisation={organisation} reloadOrganisation={reloadOrganisation} />@@ -296,13 +301,16 @@ const OrganisationSettings = () => {<ModalonClose={() => setShowDelete(false)}onSubmit={onDelete}- submitText={t('project.settings.delete')}+ submitText={t('organisations.delete')}closeText={t('common.close')}- title={t('project.settings.qDelete')}- message={t('project.settings.deleteHint')}+ title={t('organisations.modals.delete.title', {+ organisation: form.name,+ })}+ message={t('organisations.modals.delete.message')}submitType='danger'type='error'isOpened={showDelete}+ isLoading={isDeleting}/><ModalonClose={() => {diff --git a/web/app/pages/Organisations/index.tsx b/web/app/pages/Organisations/index.tsxindex 2e15223db..45df71bbe 100644--- a/web/app/pages/Organisations/index.tsx+++ b/web/app/pages/Organisations/index.tsx@@ -255,12 +255,12 @@ const Organisations = () => {setOrganisations(result.results)setPaginationTotal(result.total)- toast.success(t('organisations.organisationCreated'))+ toast.success(t('apiNotifications.organisationCreated'))closeNewOrganisationModal()} catch (reason: any) {setNewOrganisationError(reason)- toast.error(t('organisations.organisationCreateError'))+ toast.error(t('apiNotifications.organisationCreateError'))} finally {setIsNewOrganisationLoading(false)}diff --git a/web/app/ui/Button.tsx b/web/app/ui/Button.tsxindex baf54efe2..792adc7fb 100644--- a/web/app/ui/Button.tsx+++ b/web/app/ui/Button.tsx@@ -6,7 +6,7 @@ import Spin from './icons/Spin'interface IButton extends React.ComponentPropsWithoutRef<typeof HeadlessButton> {text?: string- children?: JSX.Element | string+ children?: React.ReactNodeprimary?: booleansecondary?: booleandanger?: booleandiff --git a/web/public/locales/en.json b/web/public/locales/en.jsonindex ca12ff27a..18f000297 100644--- a/web/public/locales/en.json+++ b/web/public/locales/en.json@@ -52,6 +52,7 @@"noAIForecastAvailable": "AI forecast is not available for this project yet","organisationCreated": "Organisation has been created","organisationCreateError": "Error occurred while creating the organisation",+ "organisationDeleted": "Organisation has been deleted","projectRemovedFromOrganisation": "The project has been removed from the organisation","projectAddedToOrganisation": "The project has been added to the organisation","projectRemoveError": "Error occurred while removing the project from the organisation",@@ -652,9 +653,14 @@"addProject": {"title": "Add project to {{organisation}}","message": "Select the project you want to add to the organisation. It will be available to all members of the organisation, and the organisation admins will be able to manage the project settings."+ },+ "delete": {+ "title": "Delete {{organisation}}?",+ "message": "Are you sure you want to delete this organisation?\nAll the data related to the organisation will be deleted from our servers. This action is irreversible."}},- "projectOwnedBy": "This project is owned by {{email}}"+ "projectOwnedBy": "This project is owned by {{email}}",+ "delete": "Delete organisation"},"dashboard": {"uptime": "Uptime",