def delete(self, request, org_id): """ Delete an organization Permission checking: 1. only admin can perform this action. """ if not MULTI_TENANCY: error_msg = 'Feature is not enabled.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) if not request.user.admin_permissions.other_permission(): return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.') 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) 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})
def remove_org(org_id): org_id = int(org_id) org = ccnet_api.get_org_by_id(org_id) if org: users = ccnet_api.get_org_emailusers(org.url_prefix, -1, -1) for u in users: ccnet_api.remove_org_user(org_id, u.email) groups = ccnet_api.get_org_groups(org.org_id, -1, -1) for g in groups: ccnet_api.remove_org_group(org_id, g.gid) # remove org repos seafserv_threaded_rpc.remove_org_repo_by_org_id(org_id) # remove org ccnet_api.remove_org(org_id)
def delete(self, request, org_id): """ Delete an organization Permission checking: 1. only admin can perform this action. """ if not (CLOUD_MODE and MULTI_TENANCY): 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) # 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) 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})
def delete(self, request, org_id, email): """ Delete an user from org Permission checking: 1. only admin can perform this action. """ org = ccnet_api.get_org_by_id(org_id) if org.creator == email: error_msg = 'Failed to delete: %s is an organization creator.' % email return api_error(status.HTTP_403_FORBIDDEN, error_msg) try: ccnet_api.remove_org_user(org_id, email) User.objects.get(email=email).delete() 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})
def delete(self, request, org_id, email): """ Delete an user from org Permission checking: 1. only admin can perform this action. """ org = ccnet_api.get_org_by_id(org_id) if org.creator == email: error_msg = 'Failed to delete: %s is an organization creator.' % email return api_error(status.HTTP_403_FORBIDDEN, error_msg) try: ccnet_api.remove_org_user(org_id, email) User.objects.get(email=email).delete() 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})
def delete(self, request, org_id, email): """ Delete an user from org Permission checking: 1. only admin can perform this action. """ # argument check 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 %d not found.' % org_id return api_error(status.HTTP_404_NOT_FOUND, error_msg) try: user = User.objects.get(email=email) except User.DoesNotExist: error_msg = 'User %s not found.' % email return api_error(status.HTTP_404_NOT_FOUND, error_msg) # permission check if org.creator == email: error_msg = 'Failed to delete: %s is an organization creator.' % email return api_error(status.HTTP_403_FORBIDDEN, error_msg) try: ccnet_api.remove_org_user(org_id, email) user.delete() 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})
def unset_org_user(org_id, username): return ccnet_api.remove_org_user(org_id, username)
def tearDown(self, ): users = ccnet_api.get_org_emailusers(self.org.url_prefix, -1, -1) for u in users: ccnet_api.remove_org_user(self.org.org_id, u.email) ccnet_api.remove_org(self.org.org_id)