示例#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
文件: utils.py 项目: ciniguez/FIREWA
def sync_base_workspaces(user):

    from wirecloud.platform.workspace.mashupTemplateParser import buildWorkspaceFromTemplate

    packageLinker = PackageLinker()
    reload_showcase = False
    managers = get_workspace_managers()

    workspaces_by_manager = {}
    workspaces_by_ref = {}
    for manager in managers:
        workspaces_by_manager[manager.get_id()] = []
        workspaces_by_ref[manager.get_id()] = {}

    workspaces = UserWorkspace.objects.filter(user=user)
    for workspace in workspaces:
        if workspace.manager != '':
            workspaces_by_manager[workspace.manager].append(workspace.reason_ref)
            workspaces_by_ref[workspace.manager][workspace.reason_ref] = workspace

    for manager in managers:
        current_workspaces = workspaces_by_manager[manager.get_id()]
        result = manager.update_base_workspaces(user, current_workspaces)

        for workspace_to_remove in result[0]:
            user_workspace = workspaces_by_ref[manager.get_id()][workspace_to_remove]
            workspace = user_workspace.workspace
            user_workspace.delete()

            if workspace.userworkspace_set.count() == 0:
                workspace.delete()

        for workspace_to_add in result[1]:
            from_workspace = workspace_to_add[1]

            if isinstance(from_workspace, Workspace):
                user_workspace = packageLinker.link_workspace(from_workspace, user, from_workspace.creator)
            elif isinstance(from_workspace, PublishedWorkspace):
                _junk, user_workspace = buildWorkspaceFromTemplate(from_workspace.template, user)
            else:
                # TODO warning
                continue

            user_workspace.manager = manager.get_id()
            user_workspace.reason_ref = workspace_to_add[0]
            user_workspace.save()
            reload_showcase = True

    return reload_showcase
示例#3
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)
示例#4
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)
示例#5
0
def linkWorkspaceObject(user, workspace, creator, link_variable_values=True):
    packageLinker = PackageLinker()

    return packageLinker.link_workspace(workspace, user, creator, link_variable_values)