def put(self, request, org_id): """ Update base info of a 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) # update org name new_name = request.data.get('org_name', None) if new_name: try: ccnet_api.set_org_name(org_id, new_name) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) # update org max user number max_user_number = request.data.get('max_user_number', None) if max_user_number and ORG_MEMBER_QUOTA_ENABLED: try: max_user_number = int(max_user_number) except ValueError: error_msg = 'max_user_number invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) if max_user_number <= 0: error_msg = 'max_user_number invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) try: OrgMemberQuota.objects.set_quota(org_id, max_user_number) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) quota_mb = request.data.get('quota', None) if quota_mb: try: quota_mb = int(quota_mb) except ValueError: error_msg = 'quota invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) if quota_mb < 0: error_msg = 'quota invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) quota = quota_mb * get_file_size_unit('MB') try: seafile_api.set_org_quota(org_id, quota) except Exception as e: logger.error(e) error_msg = 'Internal Server Error' return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) role = request.data.get('role', None) if role: if role not in get_available_roles(): error_msg = 'Role %s invalid.' % role return api_error(status.HTTP_400_BAD_REQUEST, error_msg) OrgSettings.objects.add_or_update(org, role) org = ccnet_api.get_org_by_id(org_id) org_info = get_org_info(org) return Response(org_info)