Пример #1
0
def add_saas_tenant(request, creator, workspace):

    # Sync workspace list before searching it
    creator_user = get_object_or_404(User, username=creator)
    get_workspace_list(creator_user)

    workspace = get_object_or_404(Workspace, creator=creator_user, name=workspace)

    status = 201

    id_4CaaSt = request.GET['message']
    username = parse_username(id_4CaaSt)
    try:
        user = User.objects.create_user(username, '*****@*****.**', username)
    except:
        user = User.objects.get(username=username)

    try:
        user_workspace = UserWorkspace.objects.get(user=user, workspace=workspace)
    except:
        packageLinker = PackageLinker()
        user_workspace = packageLinker.link_workspace(workspace, user, creator_user)

    setActiveWorkspace(user, user_workspace.workspace)

    try:
        user_workspace.profile4caast.id_4CaaSt = id_4CaaSt
        user_workspace.profile4caast.save()
    except:
        Profile4CaaSt.objects.create(user_workspace=user_workspace, id_4CaaSt=id_4CaaSt)

    return HttpResponse(status=status)
Пример #2
0
def get_workspace_list(user):

    from wirecloud.platform.workspace.views import createEmptyWorkspace, setActiveWorkspace

    reload_showcase = sync_base_workspaces(user)

    if Workspace.objects.filter(users=user).count() == 0:
        # create an empty workspace
        createEmptyWorkspace(_('Workspace'), user)

    # Now we can fetch all the workspaces of an user
    workspaces = Workspace.objects.filter(users__id=user.id)

    # if there is no active workspace
    active_workspaces = UserWorkspace.objects.filter(user=user, active=True)
    if len(active_workspaces) == 0:

        # set the first workspace as active
        active_workspace = UserWorkspace.objects.filter(user=user)[0]
        setActiveWorkspace(user, active_workspace.workspace)

    elif len(active_workspaces) > 1:

        active_workspaces[1:].update(active=False)
        active_workspace = active_workspaces[0]

    else:
        active_workspace = active_workspaces[0]

    return workspaces, active_workspace, reload_showcase
Пример #3
0
def get_workspace_list(user):

    from wirecloud.platform.workspace.views import setActiveWorkspace

    if not user.is_authenticated():
        workspaces = Workspace.objects.filter(public=True)
        return workspaces, None

    sync_base_workspaces(user)

    # Now we can fetch all the workspaces for the user
    workspaces = Workspace.objects.filter(Q(public=True) | Q(users__id=user.id))

    # if there is no active workspace
    active_workspaces = UserWorkspace.objects.filter(user=user, active=True)
    if len(active_workspaces) == 0:

        try:
            # set the first workspace as active
            active_workspace = UserWorkspace.objects.filter(user=user)[0]
            setActiveWorkspace(user, active_workspace.workspace)
        except IndexError:
            active_workspace = None

    elif len(active_workspaces) > 1:

        active_workspaces[1:].update(active=False)
        active_workspace = active_workspaces[0]

    else:
        active_workspace = active_workspaces[0]

    return workspaces, active_workspace
Пример #4
0
def get_workspace_list(user):

    from wirecloud.platform.workspace.views import setActiveWorkspace

    if not user.is_authenticated():
        workspaces = Workspace.objects.filter(public=True)
        return workspaces, None

    sync_base_workspaces(user)

    # Now we can fetch all the workspaces for the user
    workspaces = Workspace.objects.filter(
        Q(public=True) | Q(users__id=user.id))

    # if there is no active workspace
    active_workspaces = UserWorkspace.objects.filter(user=user, active=True)
    if len(active_workspaces) == 0:

        try:
            # set the first workspace as active
            active_workspace = UserWorkspace.objects.filter(user=user)[0]
            setActiveWorkspace(user, active_workspace.workspace)
        except IndexError:
            active_workspace = None

    elif len(active_workspaces) > 1:

        active_workspaces[1:].update(active=False)
        active_workspace = active_workspaces[0]

    else:
        active_workspace = active_workspaces[0]

    return workspaces, active_workspace
Пример #5
0
def add_saas_tenant(request, creator, workspace):

    # Sync workspace list before searching it
    creator_user = get_object_or_404(User, username=creator)
    get_workspace_list(creator_user)

    workspace = get_object_or_404(Workspace,
                                  creator=creator_user,
                                  name=workspace)

    status = 201

    id_4CaaSt = request.GET.get('message')

    if id_4CaaSt is None:
        return build_error_response(request, 400, _('Missing 4CaaStID'))

    if not isinstance(id_4CaaSt, string_types) or id_4CaaSt.strip() == '':
        return build_error_response(request, 400, _('Invalid 4CaaStID'))

    username = parse_username(id_4CaaSt)
    try:
        user = User.objects.create_user(username, '*****@*****.**', username)
    except:
        user = User.objects.get(username=username)

    try:
        user_workspace = UserWorkspace.objects.get(user=user,
                                                   workspace=workspace)
    except:
        packageLinker = PackageLinker()
        user_workspace = packageLinker.link_workspace(workspace, user,
                                                      creator_user)

    setActiveWorkspace(user, user_workspace.workspace)

    try:
        user_workspace.profile4caast.id_4CaaSt = id_4CaaSt
        user_workspace.profile4caast.save()
    except:
        Profile4CaaSt.objects.create(user_workspace=user_workspace,
                                     id_4CaaSt=id_4CaaSt)

    return HttpResponse(status=status)
Пример #6
0
def add_saas_tenant(request, creator, workspace):

    # Sync workspace list before searching it
    creator_user = get_object_or_404(User, username=creator)
    get_workspace_list(creator_user)

    workspace = get_object_or_404(Workspace, creator=creator_user, name=workspace)

    status = 201

    id_4CaaSt = request.GET.get('message')

    if id_4CaaSt is None:
        return build_error_response(request, 400, _('Missing 4CaaStID'))

    if not isinstance(id_4CaaSt, basestring) or id_4CaaSt.strip() == '':
        return build_error_response(request, 400, _('Invalid 4CaaStID'))

    username = parse_username(id_4CaaSt)
    try:
        user = User.objects.create_user(username, '*****@*****.**', username)
    except:
        user = User.objects.get(username=username)

    try:
        user_workspace = UserWorkspace.objects.get(user=user, workspace=workspace)
    except:
        packageLinker = PackageLinker()
        user_workspace = packageLinker.link_workspace(workspace, user, creator_user)

    setActiveWorkspace(user, user_workspace.workspace)

    try:
        user_workspace.profile4caast.id_4CaaSt = id_4CaaSt
        user_workspace.profile4caast.save()
    except:
        Profile4CaaSt.objects.create(user_workspace=user_workspace, id_4CaaSt=id_4CaaSt)

    return HttpResponse(status=status)