diff --git a/frontend/src/components/dialog/org-admin-delete-org-dialog.js b/frontend/src/components/dialog/org-admin-delete-org-dialog.js
new file mode 100644
index 0000000000..e94b7d43f1
--- /dev/null
+++ b/frontend/src/components/dialog/org-admin-delete-org-dialog.js
@@ -0,0 +1,79 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { Button, Modal, Input, ModalBody, ModalFooter, Label, Form, FormGroup } from 'reactstrap';
+import { gettext } from '../../utils/constants';
+import SeahubModalHeader from '@/components/common/seahub-modal-header';
+
+const propTypes = {
+ organizationName: PropTypes.string.isRequired,
+ toggle: PropTypes.func.isRequired,
+ handleSubmit: PropTypes.func.isRequired,
+};
+
+class OrgAdminDeleteOrgDialog extends React.Component {
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ name: '',
+ errMessage: '',
+ };
+ }
+
+ toggle = () => {
+ this.props.toggle();
+ };
+
+ inputName = (e) => {
+ let name = e.target.value;
+ this.setState({ name: name });
+ };
+
+ validateInputParams() {
+ let errMessage;
+ let name = this.state.name.trim();
+ if (!name.length) {
+ errMessage = gettext('Name is required');
+ this.setState({ errMessage: errMessage });
+ return false;
+ }
+
+ if (name !== this.props.organizationName) {
+ errMessage = gettext('Names don\'t match');
+ this.setState({ errMessage: errMessage });
+ return false;
+ }
+ return true;
+ }
+
+ handleSubmit = () => {
+ let isValid = this.validateInputParams();
+ if (isValid) {
+ this.props.handleSubmit();
+ }
+ };
+
+ render() {
+ return (
+
+ {gettext('Delete Team')}
+
+
+ {this.state.errMessage && }
+
+
+
+
+
+ );
+ }
+}
+
+OrgAdminDeleteOrgDialog.propTypes = propTypes;
+
+export default OrgAdminDeleteOrgDialog;
diff --git a/frontend/src/pages/org-admin/web-settings/web-settings.js b/frontend/src/pages/org-admin/web-settings/web-settings.js
index 7e4295014d..71cf717ec6 100644
--- a/frontend/src/pages/org-admin/web-settings/web-settings.js
+++ b/frontend/src/pages/org-admin/web-settings/web-settings.js
@@ -2,7 +2,7 @@ import React, { Component, Fragment } from 'react';
import { InputGroupText } from 'reactstrap';
import { Utils } from '../../../utils/utils';
import { orgAdminAPI } from '../../../utils/org-admin-api';
-import { gettext, mediaUrl, logoPath, orgID, orgEnableAdminCustomLogo, orgEnableAdminCustomName, enableMultiADFS } from '../../../utils/constants';
+import { gettext, mediaUrl, logoPath, orgID, orgEnableAdminCustomLogo, orgEnableAdminCustomName, orgEnableAdminDeleteOrg, enableMultiADFS } from '../../../utils/constants';
import Loading from '../../../components/loading';
import toaster from '../../../components/toast';
import MainPanelTopbar from '../main-panel-topbar';
@@ -10,6 +10,7 @@ import Section from '../../common-admin/web-settings/section';
import CheckboxItem from '../../common-admin/web-settings/checkbox-item';
import FileItem from '../../common-admin/web-settings/file-item';
import InputItem from './input-item';
+import DeleteOrganizationDialog from '../../../components/dialog/org-admin-delete-org-dialog';
import '../../../css/system-admin-web-settings.css';
@@ -29,7 +30,8 @@ class OrgWebSettings extends Component {
force_adfs_login: false,
disable_org_encrypted_library: false,
disable_org_user_clean_trash: false,
- user_default_quota: 0
+ user_default_quota: 0,
+ isDeleteOrganizationDialogShow: false,
};
}
@@ -104,6 +106,19 @@ class OrgWebSettings extends Component {
});
};
+ toggleDeleteOrganization = () => {
+ this.setState({ isDeleteOrganizationDialogShow: !this.state.isDeleteOrganizationDialogShow });
+ };
+
+ deleteOrganization = () => {
+ orgAdminAPI.orgAdminDeleteOrg(orgID).then((res) => {
+ window.location.href = '/';
+ }).catch((error) => {
+ let errMessage = Utils.getErrorMsg(error);
+ toaster.danger(errMessage);
+ });
+ };
+
render() {
const { loading, errorMsg, config_dict, file_ext_white_list, force_adfs_login, disable_org_encrypted_library, disable_org_user_clean_trash, user_default_quota } = this.state;
let logoPath = this.state.logoPath;
@@ -206,11 +221,27 @@ class OrgWebSettings extends Component {
/>
+ {orgEnableAdminDeleteOrg &&
+
+
+
+
+
+ }
}
+ {this.state.isDeleteOrganizationDialogShow &&
+
+ }
);
}
diff --git a/frontend/src/utils/constants.js b/frontend/src/utils/constants.js
index 5776fdea6e..a1e6fcbc56 100644
--- a/frontend/src/utils/constants.js
+++ b/frontend/src/utils/constants.js
@@ -176,6 +176,7 @@ export const orgMemberQuotaEnabled = window.org ? window.org.pageOptions.orgMemb
export const orgEnableAdminCustomLogo = window.org ? window.org.pageOptions.orgEnableAdminCustomLogo === 'True' : false;
export const orgEnableAdminCustomName = window.org ? window.org.pageOptions.orgEnableAdminCustomName === 'True' : false;
export const orgEnableAdminInviteUser = window.org ? window.org.pageOptions.orgEnableAdminInviteUser === 'True' : false;
+export const orgEnableAdminDeleteOrg = window.org ? window.org.pageOptions.orgEnableAdminDeleteOrg === 'True' : false;
export const enableMultiADFS = window.org ? window.org.pageOptions.enableMultiADFS === 'True' : false;
export const enableSubscription = window.org ? window.org.pageOptions.enableSubscription : false;
export const enableExternalBillingService = window.org ? window.org.pageOptions.enableExternalBillingService : false;
diff --git a/frontend/src/utils/org-admin-api.js b/frontend/src/utils/org-admin-api.js
index c6d3e21fd0..a915d44081 100644
--- a/frontend/src/utils/org-admin-api.js
+++ b/frontend/src/utils/org-admin-api.js
@@ -566,6 +566,11 @@ class OrgAdminAPI {
return this.req.put(url, form);
}
+ orgAdminDeleteOrg(orgID) {
+ const url = this.server + '/api/v2.1/org/' + orgID + '/admin/delete-org/';
+ return this.req.delete(url);
+ }
+
}
let orgAdminAPI = new OrgAdminAPI();
diff --git a/seahub/api2/endpoints/admin/organizations.py b/seahub/api2/endpoints/admin/organizations.py
index 55d835a4ca..3092f5f67a 100644
--- a/seahub/api2/endpoints/admin/organizations.py
+++ b/seahub/api2/endpoints/admin/organizations.py
@@ -15,6 +15,7 @@ from seaserv import ccnet_api, seafile_api
from seahub.auth.utils import get_virtual_id_by_email
from seahub.organizations.settings import ORG_MEMBER_QUOTA_DEFAULT, \
ORG_ENABLE_REACTIVATE
+from seahub.organizations.signals import org_deleted
from seahub.organizations.utils import generate_org_reactivate_link
from seahub.utils import is_valid_email, IS_EMAIL_CONFIGURED, send_html_email
from seahub.utils.file_size import get_file_size_unit
@@ -472,12 +473,12 @@ class AdminOrganization(APIView):
# remove org repos
seafile_api.remove_org_repo_by_org_id(org_id)
-
- # remove org saml config
- OrgSAMLConfig.objects.filter(org_id=org_id).delete()
-
+
# remove org
ccnet_api.remove_org(org_id)
+
+ # handle signal
+ org_deleted.send(sender=None, org_id=org_id)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
diff --git a/seahub/organizations/api/admin/delete_org.py b/seahub/organizations/api/admin/delete_org.py
new file mode 100644
index 0000000000..a156336ee0
--- /dev/null
+++ b/seahub/organizations/api/admin/delete_org.py
@@ -0,0 +1,73 @@
+import logging
+
+from seaserv import ccnet_api, seafile_api
+
+from rest_framework.authentication import SessionAuthentication
+from rest_framework.response import Response
+from rest_framework.views import APIView
+from rest_framework import status
+
+from seahub.api2.permissions import IsProVersion, IsOrgAdminUser
+from seahub.api2.authentication import TokenAuthentication
+from seahub.api2.throttling import UserRateThrottle
+from seahub.api2.utils import api_error
+
+from seahub.base.accounts import User
+from seahub.organizations.signals import org_deleted
+from seahub.organizations.settings import ORG_ENABLE_ADMIN_DELETE_ORG
+
+try:
+ from seahub.settings import MULTI_TENANCY
+except ImportError:
+ MULTI_TENANCY = False
+
+logger = logging.getLogger(__name__)
+
+
+class OrgAdminDeleteOrg(APIView):
+
+ authentication_classes = (TokenAuthentication, SessionAuthentication)
+ throttle_classes = (UserRateThrottle,)
+ permission_classes = (IsProVersion, IsOrgAdminUser)
+
+ def delete(self, request, org_id):
+
+ if not MULTI_TENANCY or not ORG_ENABLE_ADMIN_DELETE_ORG:
+ error_msg = 'Feature is not enabled.'
+ return api_error(status.HTTP_403_FORBIDDEN, error_msg)
+
+ org_id = int(org_id)
+ if org_id == 0:
+ error_msg = 'org_id invalid.'
+ return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
+
+ org = ccnet_api.get_org_by_id(org_id)
+ if not org:
+ error_msg = 'Organization %s not found.' % org_id
+ return api_error(status.HTTP_404_NOT_FOUND, error_msg)
+
+ try:
+ # remove org users
+ users = ccnet_api.get_org_emailusers(org.url_prefix, -1, -1)
+ for u in users:
+ ccnet_api.remove_org_user(org_id, u.email)
+ User.objects.get(email=u.email).delete()
+
+ # remove org groups
+ groups = ccnet_api.get_org_groups(org_id, -1, -1)
+ for g in groups:
+ ccnet_api.remove_org_group(org_id, g.gid)
+
+ # remove org repos
+ seafile_api.remove_org_repo_by_org_id(org_id)
+ # remove org
+ ccnet_api.remove_org(org_id)
+
+ # handle signal
+ org_deleted.send(sender=None, org_id=org_id)
+ except Exception as e:
+ logger.error(e)
+ error_msg = 'Internal Server Error'
+ return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
+
+ return Response({'success': True})
diff --git a/seahub/organizations/api_urls.py b/seahub/organizations/api_urls.py
index 8191a7da46..9943614e16 100644
--- a/seahub/organizations/api_urls.py
+++ b/seahub/organizations/api_urls.py
@@ -26,6 +26,7 @@ from .api.admin.user_repos import OrgAdminUserRepos, OrgAdminUserBesharedRepos
from .api.admin.devices import OrgAdminDevices, OrgAdminDevicesErrors
from .api.admin.logo import OrgAdminLogo
+from .api.admin.delete_org import OrgAdminDeleteOrg
from .api.admin.statistics import OrgFileOperationsView, OrgTotalStorageView, \
OrgActiveUsersView, OrgSystemTrafficView, OrgUserTrafficView, \
@@ -65,6 +66,7 @@ urlpatterns = [
OrgVerifyDomain.as_view(),
name='api-v2.1-org-admin-verify-domain'),
+ path('/admin/delete-org/', OrgAdminDeleteOrg.as_view(), name='api-v2.1-org-admin-delete-org'),
path('/admin/logo/', OrgAdminLogo.as_view(), name='api-v2.1-org-admin-logo'),
path('/admin/devices/', OrgAdminDevices.as_view(), name='api-v2.1-org-admin-devices'),
path('/admin/devices-errors/', OrgAdminDevicesErrors.as_view(), name='api-v2.1-org-admin-devices-errors'),
diff --git a/seahub/organizations/models.py b/seahub/organizations/models.py
index e4514bd4c7..c5bd3794bd 100644
--- a/seahub/organizations/models.py
+++ b/seahub/organizations/models.py
@@ -3,14 +3,16 @@ import os
import uuid
import logging
from django.db import models
+from django.dispatch import receiver
+from seahub.base.models import OrgQuotaUsage, OrgLastActivityTime
from .settings import ORG_MEMBER_QUOTA_DEFAULT
from seahub.constants import DEFAULT_ORG
from seahub.role_permissions.utils import get_available_roles
from seahub.avatar.util import get_avatar_file_storage
from seahub.avatar.settings import AVATAR_STORAGE_DIR
-from seahub.organizations.signals import org_operation_signal
+from seahub.organizations.signals import org_operation_signal, org_deleted
logger = logging.getLogger(__name__)
@@ -206,3 +208,17 @@ class OrgAdminSettings(models.Model):
class Meta:
unique_together = [('org_id', 'key')]
+
+
+# handle signal
+
+@receiver(org_deleted)
+def org_deleted_cb(sender, **kwargs):
+ org_id = kwargs['org_id']
+
+ OrgSAMLConfig.objects.filter(org_id=org_id).delete()
+ OrgAdminSettings.objects.filter(org_id=org_id).delete()
+ OrgSettings.objects.filter(org_id=org_id).delete()
+ OrgMemberQuota.objects.filter(org_id=org_id).delete()
+ OrgQuotaUsage.objects.filter(org_id=org_id).delete()
+ OrgLastActivityTime.objects.filter(org_id=org_id).delete()
diff --git a/seahub/organizations/settings.py b/seahub/organizations/settings.py
index a3b4cf9570..3c379c7693 100644
--- a/seahub/organizations/settings.py
+++ b/seahub/organizations/settings.py
@@ -22,3 +22,5 @@ ORG_ENABLE_REACTIVATE = getattr(settings, 'ORG_ENABLE_REACTIVATE', False)
ORG_ENABLE_ADMIN_INVITE_USER = getattr(settings, 'ORG_ENABLE_ADMIN_INVITE_USER', True)
ORG_ENABLE_ADMIN_CUSTOM_NAME = getattr(settings, 'ORG_ENABLE_ADMIN_CUSTOM_NAME', True)
ORG_ENABLE_ADMIN_CUSTOM_LOGO = getattr(settings, 'ORG_ENABLE_ADMIN_CUSTOM_LOGO', True)
+
+ORG_ENABLE_ADMIN_DELETE_ORG = getattr(settings, 'ORG_ENABLE_ADMIN_DELETE_ORG', False)
diff --git a/seahub/organizations/signals.py b/seahub/organizations/signals.py
index 5ff913d55e..01c5d0e2d2 100644
--- a/seahub/organizations/signals.py
+++ b/seahub/organizations/signals.py
@@ -4,3 +4,4 @@ from django.dispatch import Signal
# A new org is created
org_operation_signal = Signal()
org_last_activity = Signal()
+org_deleted = Signal()
diff --git a/seahub/organizations/templates/organizations/org_admin_react.html b/seahub/organizations/templates/organizations/org_admin_react.html
index 03c4738a59..a1e4376f1b 100644
--- a/seahub/organizations/templates/organizations/org_admin_react.html
+++ b/seahub/organizations/templates/organizations/org_admin_react.html
@@ -17,6 +17,7 @@
orgEnableAdminCustomLogo: '{{ org_enable_admin_custom_logo }}',
orgEnableAdminCustomName: '{{ org_enable_admin_custom_name }}',
orgEnableAdminInviteUser: '{{ org_enable_admin_invite_user }}',
+ orgEnableAdminDeleteOrg: '{{ org_enable_admin_delete_org }}',
enableMultiADFS: '{{ enable_multi_adfs }}',
isOrgContext: true,
enableSubscription: {% if enable_subscription %} true {% else %} false {% endif %},
diff --git a/seahub/organizations/views.py b/seahub/organizations/views.py
index 6007b21511..4bc3f9d46a 100644
--- a/seahub/organizations/views.py
+++ b/seahub/organizations/views.py
@@ -34,7 +34,7 @@ from seahub.organizations.forms import OrgRegistrationForm
from seahub.organizations.settings import ORG_AUTO_URL_PREFIX, \
ORG_MEMBER_QUOTA_ENABLED, ORG_ENABLE_ADMIN_INVITE_USER_VIA_WEIXIN, \
ORG_ENABLE_ADMIN_CUSTOM_LOGO, ORG_ENABLE_ADMIN_CUSTOM_NAME, \
- ORG_ENABLE_ADMIN_INVITE_USER
+ ORG_ENABLE_ADMIN_INVITE_USER, ORG_ENABLE_ADMIN_DELETE_ORG
from seahub.organizations.utils import get_or_create_invitation_link, \
can_use_sso_in_multi_tenancy
from seahub.subscription.utils import subscription_check
@@ -300,6 +300,7 @@ def react_fake_view(request, **kwargs):
'org_enable_admin_custom_logo': ORG_ENABLE_ADMIN_CUSTOM_LOGO,
'org_enable_admin_custom_name': ORG_ENABLE_ADMIN_CUSTOM_NAME,
'org_enable_admin_invite_user': ORG_ENABLE_ADMIN_INVITE_USER,
+ 'org_enable_admin_delete_org': ORG_ENABLE_ADMIN_DELETE_ORG,
'group_id': group_id,
'invitation_link': invitation_link,
'enable_multi_adfs': ENABLE_MULTI_ADFS and can_use_sso_in_multi_tenancy(org.org_id),