views.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:mist.api 作者: mistio 项目源码 文件源码
def create_organization(request):
    """
    Create organization.
    The user creating it will be assigned to the
    owners team. For now owner has only org
    ---
    name:
      description: The new org  name (id)
      type: string
      required: true
    """
    auth_context = auth_context_from_request(request)

    user = auth_context.user
    # SEC
    if not user.can_create_org:
        raise OrganizationAuthorizationFailure('Unauthorized to '
                                               'create organization')
    params = params_from_request(request)

    name = params.get('name')
    super_org = params.get('super_org')

    if not name:
        raise RequiredParameterMissingError()
    if Organization.objects(name=name):
        raise OrganizationNameExistsError()

    org = Organization()
    org.add_member_to_team('Owners', user)
    org.name = name

    # mechanism for sub-org creation
    # the owner of super-org has the ability to create a sub-org
    if super_org:
        org.parent = auth_context.org

    try:
        org.save()
    except me.ValidationError as e:
        raise BadRequestError({"msg": e.message, "errors": e.to_dict()})
    except me.OperationError:
        raise OrganizationOperationError()

    trigger_session_update(auth_context.user, ['user'])
    return org.as_dict()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号