Esempio n. 1
0
def submit(name, user_id, project_id=None):
    try:
        owner = AstakosUser.objects.get(id=user_id)
    except AstakosUser.DoesNotExist:
        raise AttributeError('user does not exist')

    project = (Project.objects.get(
        id=project_id) if project_id is not None else None)
    ok, limit = check_pending_app_quota(owner, project=project)
    if not ok:
        raise ProjectForbidden('Limit %s reached', limit)

    resource_policies = {'cyclades.network.private': {'member_capacity': 5}}
    data = {
        'owner': owner,
        'name': name,
        'project_id': project_id,
        'end_date': datetime.now() + timedelta(days=1),
        'member_join_policy': 1,
        'member_leave_policy': 1,
        'resources': resource_policies,
        'request_user': owner
    }

    app = submit_application(**data)
    return app.id, app.chain_id
Esempio n. 2
0
def submit(name, user_id, prec):
    try:
        owner = AstakosUser.objects.get(id=user_id)
    except AstakosUser.DoesNotExist:
        raise AttributeError('user does not exist')

    precursor = (ProjectApplication.objects.get(id=prec)
                 if prec is not None
                 else None)

    ok, limit = check_pending_app_quota(owner, precursor=precursor)
    if not ok:
        raise PermissionDenied('Limit %s reached', limit)

    resource_policies = [('cyclades.network.private', 5)]
    data = {'owner': owner,
            'name': name,
            'precursor_id': prec,
            'end_date': datetime.now() + timedelta(days=1),
            'member_join_policy': 1,
            'member_leave_policy': 1,
            'resource_policies': resource_policies,
            'request_user': owner
            }

    app = submit_application(**data)
    return app.id
Esempio n. 3
0
def submit(name, user_id, project_id=None):
    try:
        owner = AstakosUser.objects.get(id=user_id)
    except AstakosUser.DoesNotExist:
        raise AttributeError('user does not exist')

    project = (Project.objects.get(id=project_id) if project_id is not None
               else None)
    ok, limit = check_pending_app_quota(owner, project=project)
    if not ok:
        raise ProjectForbidden('Limit %s reached', limit)

    resource_policies = {'cyclades.network.private': {'member_capacity': 5,
                                                      'project_capacity': 10}}
    data = {'owner': owner,
            'name': name,
            'project_id': project_id,
            'end_date': datetime.now() + timedelta(days=1),
            'member_join_policy': 1,
            'member_leave_policy': 1,
            'resources': resource_policies,
            'request_user': owner
            }

    app = submit_application(**data)
    return app.id, app.chain_id
Esempio n. 4
0
def submit(name, user_id, prec):
    try:
        owner = AstakosUser.objects.get(id=user_id)
    except AstakosUser.DoesNotExist:
        raise AttributeError('user does not exist')

    precursor = (ProjectApplication.objects.get(
        id=prec) if prec is not None else None)

    ok, limit = check_pending_app_quota(owner, precursor=precursor)
    if not ok:
        raise PermissionDenied('Limit %s reached', limit)

    resource_policies = [('cyclades.network.private', 5)]
    data = {
        'owner': owner,
        'name': name,
        'precursor_id': prec,
        'end_date': datetime.now() + timedelta(days=1),
        'member_join_policy': 1,
        'member_leave_policy': 1,
        'resource_policies': resource_policies,
        'request_user': owner
    }

    app = submit_application(**data)
    return app.id
Esempio n. 5
0
def project_modify(request, application_id):

    try:
        app = ProjectApplication.objects.get(id=application_id)
    except ProjectApplication.DoesNotExist:
        raise Http404

    user = request.user
    if not (user.owns_application(app) or user.is_project_admin(app.id)):
        m = _(astakos_messages.NOT_ALLOWED)
        raise PermissionDenied(m)

    if not user.is_project_admin():
        owner = app.owner
        ok, limit = check_pending_app_quota(owner, precursor=app)
        if not ok:
            m = _(astakos_messages.PENDING_APPLICATION_LIMIT_MODIFY) % limit
            messages.error(request, m)
            next = reverse('astakos.im.views.project_list')
            next = restrict_next(next, domain=settings.COOKIE_DOMAIN)
            return redirect(next)

    details_fields = ["name", "homepage", "description", "start_date",
                      "end_date", "comments"]
    membership_fields = ["member_join_policy", "member_leave_policy",
                         "limit_on_members_number"]
    resource_catalog, resource_groups = _resources_catalog(for_project=True)
    if resource_catalog is False:
        # on fail resource_groups contains the result object
        result = resource_groups
        messages.error(request, 'Unable to retrieve system resources: %s' %
                       result.reason)
    extra_context = {
        'resource_catalog': resource_catalog,
        'resource_groups': resource_groups,
        'show_form': True,
        'details_fields': details_fields,
        'update_form': True,
        'membership_fields': membership_fields
    }

    response = None
    with ExceptionHandler(request):
        response = _update_object(
            request,
            object_id=application_id,
            template_name='im/projects/projectapplication_form.html',
            summary_template_name='im/projects/projectapplication_form_summary.html',
            extra_context=extra_context,
            post_save_redirect=reverse('project_list'),
            form_class=ProjectApplicationForm,
            msg=_("The %(verbose_name)s has been received and is under "
                  "consideration."))

    if response is not None:
        return response

    next = reverse('astakos.im.views.project_list')
    next = restrict_next(next, domain=settings.COOKIE_DOMAIN)
    return redirect(next)
Esempio n. 6
0
def project_modify(request, application_id):

    try:
        app = ProjectApplication.objects.get(id=application_id)
    except ProjectApplication.DoesNotExist:
        raise Http404

    user = request.user
    if not (user.owns_application(app) or user.is_project_admin(app.id)):
        m = _(astakos_messages.NOT_ALLOWED)
        raise PermissionDenied(m)

    if not user.is_project_admin():
        owner = app.owner
        ok, limit = check_pending_app_quota(owner, precursor=app)
        if not ok:
            m = _(astakos_messages.PENDING_APPLICATION_LIMIT_MODIFY) % limit
            messages.error(request, m)
            next = reverse('astakos.im.views.project_list')
            next = restrict_next(next, domain=settings.COOKIE_DOMAIN)
            return redirect(next)

    details_fields = ["name", "homepage", "description", "start_date",
                      "end_date", "comments"]
    membership_fields = ["member_join_policy", "member_leave_policy",
                         "limit_on_members_number"]
    resource_catalog, resource_groups = _resources_catalog(for_project=True)
    if resource_catalog is False:
        # on fail resource_groups contains the result object
        result = resource_groups
        messages.error(request, 'Unable to retrieve system resources: %s' %
                       result.reason)
    extra_context = {
        'resource_catalog': resource_catalog,
        'resource_groups': resource_groups,
        'show_form': True,
        'details_fields': details_fields,
        'update_form': True,
        'membership_fields': membership_fields
    }

    response = None
    with ExceptionHandler(request):
        response = _update_object(
            request,
            object_id=application_id,
            template_name='im/projects/projectapplication_form.html',
            extra_context=extra_context,
            post_save_redirect=reverse('project_list'),
            form_class=ProjectApplicationForm,
            msg=_("The %(verbose_name)s has been received and is under "
                  "consideration."))

    if response is not None:
        return response

    next = reverse('astakos.im.views.project_list')
    next = restrict_next(next, domain=settings.COOKIE_DOMAIN)
    return redirect(next)
Esempio n. 7
0
def project_add(request):
    user = request.user
    if not user.is_project_admin():
        ok, limit = check_pending_app_quota(user)
        if not ok:
            m = _(astakos_messages.PENDING_APPLICATION_LIMIT_ADD) % limit
            messages.error(request, m)
            next = reverse('astakos.im.views.project_list')
            next = restrict_next(next, domain=settings.COOKIE_DOMAIN)
            return redirect(next)

    details_fields = ["name", "homepage", "description", "start_date",
                      "end_date", "comments"]
    membership_fields = ["member_join_policy", "member_leave_policy",
                         "limit_on_members_number"]
    resource_catalog, resource_groups = _resources_catalog(for_project=True)
    if resource_catalog is False:
        # on fail resource_groups contains the result object
        result = resource_groups
        messages.error(request, 'Unable to retrieve system resources: %s' %
                       result.reason)
    extra_context = {
        'resource_catalog': resource_catalog,
        'resource_groups': resource_groups,
        'show_form': True,
        'details_fields': details_fields,
        'membership_fields': membership_fields}

    response = None
    with ExceptionHandler(request):
        response = _create_object(
            request,
            template_name='im/projects/projectapplication_form.html',
            summary_template_name='im/projects/projectapplication_form_summary.html',
            extra_context=extra_context,
            post_save_redirect=reverse('project_list'),
            form_class=ProjectApplicationForm,
            msg=_("The %(verbose_name)s has been received and "
                  "is under consideration."),
            )

    if response is not None:
        return response

    next = reverse('astakos.im.views.project_list')
    next = restrict_next(next, domain=settings.COOKIE_DOMAIN)
    return redirect(next)
Esempio n. 8
0
def project_add(request):
    user = request.user
    if not user.is_project_admin():
        ok, limit = check_pending_app_quota(user)
        if not ok:
            m = _(astakos_messages.PENDING_APPLICATION_LIMIT_ADD) % limit
            messages.error(request, m)
            next = reverse('astakos.im.views.project_list')
            next = restrict_next(next, domain=settings.COOKIE_DOMAIN)
            return redirect(next)

    details_fields = ["name", "homepage", "description", "start_date",
                      "end_date", "comments"]
    membership_fields = ["member_join_policy", "member_leave_policy",
                         "limit_on_members_number"]
    resource_catalog, resource_groups = _resources_catalog(for_project=True)
    if resource_catalog is False:
        # on fail resource_groups contains the result object
        result = resource_groups
        messages.error(request, 'Unable to retrieve system resources: %s' %
                       result.reason)
    extra_context = {
        'resource_catalog': resource_catalog,
        'resource_groups': resource_groups,
        'show_form': True,
        'details_fields': details_fields,
        'membership_fields': membership_fields}

    response = None
    with ExceptionHandler(request):
        response = _create_object(
            request,
            template_name='im/projects/projectapplication_form.html',
            extra_context=extra_context,
            post_save_redirect=reverse('project_list'),
            form_class=ProjectApplicationForm,
            msg=_("The %(verbose_name)s has been received and "
                  "is under consideration."),
            )

    if response is not None:
        return response

    next = reverse('astakos.im.views.project_list')
    next = restrict_next(next, domain=settings.COOKIE_DOMAIN)
    return redirect(next)
Esempio n. 9
0
def project_add(request):
    user = request.user
    if not user.is_project_admin():
        ok, limit = check_pending_app_quota(user)
        if not ok:
            m = _(astakos_messages.PENDING_APPLICATION_LIMIT_ADD) % limit
            messages.error(request, m)
            next = reverse('astakos.im.views.project_list')
            next = restrict_next(next, domain=settings.COOKIE_DOMAIN)
            return redirect(next)

    details_fields = ["name", "homepage", "description", "start_date",
                      "end_date", "comments"]
    membership_fields = ["member_join_policy", "member_leave_policy",
                         "limit_on_members_number"]
    resource_catalog, resource_groups = _resources_catalog()
    if resource_catalog is False:
        # on fail resource_groups contains the result object
        result = resource_groups
        messages.error(request, 'Unable to retrieve system resources: %s' %
                       result.reason)
    extra_context = {
        'resource_catalog': resource_catalog,
        'resource_groups': resource_groups,
        'show_form': True,
        'details_fields': details_fields,
        'membership_fields': membership_fields}

    response = None
    with ExceptionHandler(request):
        response = create_app_object(request, extra_context=extra_context)

    if response is not None:
        return response

    next = reverse('astakos.im.views.project_list')
    next = restrict_next(next, domain=settings.COOKIE_DOMAIN)
    return redirect(next)
Esempio n. 10
0
def project_add_or_modify(request, project_uuid=None):
    user = request.user

    # only check quota for non project admin users
    if not user.is_project_admin():
        ok, limit = check_pending_app_quota(user)
        if not ok:
            m = _(astakos_messages.PENDING_APPLICATION_LIMIT_ADD) % limit
            messages.error(request, m)
            return redirect(restrict_reverse('astakos.im.views.project_list'))

    project = None
    if project_uuid:
        project = get_object_or_404(Project, uuid=project_uuid)

        if not user.owns_project(project) and not user.is_project_admin():
            m = _(astakos_messages.NOT_ALLOWED)
            raise PermissionDenied(m)

    details_fields = [
        "name", "homepage", "description", "start_date", "end_date", "comments"
    ]
    membership_fields = [
        "member_join_policy", "member_leave_policy", "limit_on_members_number"
    ]

    resource_catalog, resource_groups = _resources_catalog()
    resource_catalog_dict, resource_groups_dict = \
        _resources_catalog(as_dict=True)

    extra_context = {
        'resource_catalog': resource_catalog,
        'resource_groups': resource_groups,
        'resource_catalog_dict': resource_catalog_dict,
        'resource_groups_dict': resource_groups_dict,
        'show_form': True,
        'details_fields': details_fields,
        'membership_fields': membership_fields,
        'object': project
    }

    with transaction.atomic():
        template_name = 'im/projects/projectapplication_form.html'
        summary_template_name = \
            'im/projects/projectapplication_form_summary.html'
        success_msg = _("The project application has been received and "
                        "is under consideration.")
        form_class = ProjectApplicationForm

        if project:
            template_name = 'im/projects/projectmodification_form.html'
            summary_template_name = \
                'im/projects/projectmodification_form_summary.html'
            success_msg = _("The project modification has been received and "
                            "is under consideration.")
            form_class = ProjectModificationForm
            details_fields.remove('start_date')

        extra_context['edit'] = 0
        if request.method == 'POST':
            form = form_class(request.POST, request.FILES, instance=project)
            if form.is_valid():
                verify = request.GET.get('verify')
                edit = request.GET.get('edit')
                if verify == '1':
                    extra_context['show_form'] = False
                    extra_context['form_data'] = form.cleaned_data
                    template_name = summary_template_name
                elif edit == '1':
                    extra_context['show_form'] = True
                else:
                    new_object = form.save()
                    messages.success(request, success_msg, fail_silently=True)
                    return redirect(restrict_reverse('project_list'))
        else:
            # handle terminated projects for which the name attribute
            # has been set to null
            if project and not project.name:
                project.name = project.realname
            form = form_class(instance=project)

        extra_context['form'] = form
        return render_to_response(template_name,
                                  extra_context,
                                  context_instance=RequestContext(request))
Esempio n. 11
0
def project_add_or_modify(request, project_uuid=None):
    user = request.user

    # only check quota for non project admin users
    if not user.is_project_admin():
        ok, limit = check_pending_app_quota(user)
        if not ok:
            m = _(astakos_messages.PENDING_APPLICATION_LIMIT_ADD) % limit
            messages.error(request, m)
            return redirect(restrict_reverse(
                'astakos.im.views.project_list'))

    project = None
    if project_uuid:
        project = get_object_or_404(Project, uuid=project_uuid)

        if not user.owns_project(project) and not user.is_project_admin():
            m = _(astakos_messages.NOT_ALLOWED)
            raise PermissionDenied(m)

    details_fields = ["name", "homepage", "description", "start_date",
                      "end_date", "comments"]
    membership_fields = ["member_join_policy", "member_leave_policy",
                         "limit_on_members_number"]

    resource_catalog, resource_groups = _resources_catalog()
    resource_catalog_dict, resource_groups_dict = \
        _resources_catalog(as_dict=True)

    extra_context = {
        'resource_catalog': resource_catalog,
        'resource_groups': resource_groups,
        'resource_catalog_dict': resource_catalog_dict,
        'resource_groups_dict': resource_groups_dict,
        'show_form': True,
        'details_fields': details_fields,
        'membership_fields': membership_fields,
        'object': project
    }

    with transaction.commit_on_success():
        template_name = 'im/projects/projectapplication_form.html'
        summary_template_name = \
            'im/projects/projectapplication_form_summary.html'
        success_msg = _("The project application has been received and "
                        "is under consideration.")
        form_class = ProjectApplicationForm

        if project:
            template_name = 'im/projects/projectmodification_form.html'
            summary_template_name = \
                'im/projects/projectmodification_form_summary.html'
            success_msg = _("The project modification has been received and "
                            "is under consideration.")
            form_class = ProjectModificationForm
            details_fields.remove('start_date')

        extra_context['edit'] = 0
        if request.method == 'POST':
            form = form_class(request.POST, request.FILES, instance=project)
            if form.is_valid():
                verify = request.GET.get('verify')
                edit = request.GET.get('edit')
                if verify == '1':
                    extra_context['show_form'] = False
                    extra_context['form_data'] = form.cleaned_data
                    template_name = summary_template_name
                elif edit == '1':
                    extra_context['show_form'] = True
                else:
                    new_object = form.save()
                    messages.success(request, success_msg,
                                     fail_silently=True)
                    return redirect(restrict_reverse('project_list'))
        else:
            form = form_class(instance=project)

        extra_context['form'] = form
        return render_to_response(template_name, extra_context,
                                  context_instance=RequestContext(request))