Пример #1
0
def approve_application(application_id, project_id=None, request_user=None,
                        reason=""):
    get_project_lock()
    project = get_project_of_application_for_update(application_id)
    application = get_application(application_id)
    check_app_relevant(application, project, project_id)
    app_check_allowed(application, request_user, level=ADMIN_LEVEL)

    if not application.can_approve():
        m = _(astakos_messages.APPLICATION_CANNOT_APPROVE %
              (application.id, application.state_display()))
        raise ProjectConflict(m)

    if application.name:
        check_conflicting_projects(project, application.name)

    qh_release_pending_app(application.applicant)
    application.approve(actor=request_user, reason=reason)

    if project.state == Project.UNINITIALIZED:
        _fill_from_skeleton(project)
    else:
        _apply_modifications(project, application)
    project.activate(actor=request_user, reason=reason)

    quotas.qh_sync_project(project)
    logger.info("%s has been approved." % (application.log_display))
    project_notif.application_notify(application, "approve")
    return project
Пример #2
0
def deny_application(application_id, project_id=None, request_user=None,
                     reason=""):
    project = get_project_of_application_for_update(application_id)
    application = get_application(application_id)
    check_app_relevant(application, project, project_id)
    app_check_allowed(application, request_user, level=ADMIN_LEVEL)

    if not application.can_deny():
        m = _(astakos_messages.APPLICATION_CANNOT_DENY %
              (application.id, application.state_display()))
        raise ProjectConflict(m)

    qh_release_pending_app(application.applicant)

    application.deny(actor=request_user, reason=reason)
    logger.info("%s has been denied with reason \"%s\"." %
                (application.log_display, reason))
    project_notif.application_notify(application, "deny")
Пример #3
0
def submit_application(owner=None,
                       name=None,
                       project_id=None,
                       homepage=None,
                       description=None,
                       start_date=None,
                       end_date=None,
                       member_join_policy=None,
                       member_leave_policy=None,
                       limit_on_members_number=None,
                       private=False,
                       comments=None,
                       resources=None,
                       request_user=None):

    project = None
    if project_id is not None:
        project = get_project_for_update(project_id)
        project_check_allowed(project, request_user, level=APPLICANT_LEVEL)
        if project.state not in Project.INITIALIZED_STATES:
            raise ProjectConflict("Cannot modify an uninitialized project.")

    policies = validate_resource_policies(resources)

    if name is not None:
        maxlen = ProjectApplication.MAX_NAME_LENGTH
        if len(name) > maxlen:
            raise ProjectBadRequest(
                "'name' value exceeds max length %s" % maxlen)
        if not valid_project_name(name):
            raise ProjectBadRequest("Project name should be in domain format")

    if member_join_policy is not None:
        if member_join_policy not in POLICIES:
            raise ProjectBadRequest("Invalid join policy")

    if member_leave_policy is not None:
        if member_leave_policy not in POLICIES:
            raise ProjectBadRequest("Invalid join policy")

    if homepage is not None:
        maxlen = ProjectApplication.MAX_HOMEPAGE_LENGTH
        if len(homepage) > maxlen:
            raise ProjectBadRequest(
                "'homepage' value exceeds max length %s" % maxlen)
    if description is not None:
        maxlen = MAX_TEXT_INPUT
        if len(description) > maxlen:
            raise ProjectBadRequest(
                "'description' value exceeds max length %s" % maxlen)
    if comments is not None:
        maxlen = MAX_TEXT_INPUT
        if len(comments) > maxlen:
            raise ProjectBadRequest(
                "'comments' value exceeds max length %s" % maxlen)
    if limit_on_members_number is not None:
        if not 0 <= limit_on_members_number <= MAX_BIGINT:
            raise ProjectBadRequest("max_members out of range")

    if start_date is not None:
        start_date = get_date(start_date, "start_date")
    if end_date is not None:
        end_date = get_date(end_date, "end_date")
        if end_date < datetime.now():
            raise ProjectBadRequest(
                "'end_date' must be in the future")

    force = request_user.is_project_admin()
    ok, limit = qh_add_pending_app(request_user, project, force)
    if not ok:
        m = _(astakos_messages.REACHED_PENDING_APPLICATION_LIMIT) % limit
        raise ProjectConflict(m)

    if project is None:
        chain = new_chain()
        project = create_project(
            id=chain.chain,
            owner=owner,
            realname=name,
            homepage=homepage,
            description=description,
            end_date=end_date,
            member_join_policy=member_join_policy,
            member_leave_policy=member_leave_policy,
            limit_on_members_number=limit_on_members_number,
            private=private)
        if policies is not None:
            set_project_resources(project, policies)
    elif project.is_base:
        if [x for x in [owner, name, homepage, description] if x is not None]:
            raise ProjectConflict(
                "Cannot modify fields 'owner', 'name', 'homepage', and "
                "'description' of a system project.")

    application = ProjectApplication.objects.create(
        applicant=request_user,
        chain=project,
        owner=owner,
        name=name,
        homepage=homepage,
        description=description,
        start_date=start_date,
        end_date=end_date,
        member_join_policy=member_join_policy,
        member_leave_policy=member_leave_policy,
        limit_on_members_number=limit_on_members_number,
        private=private,
        comments=comments)
    if policies is not None:
        set_application_resources(application, policies)

    project.last_application = application
    project.save()

    ProjectApplication.objects.\
        filter(chain=project, state=ProjectApplication.PENDING).\
        exclude(id=application.id).\
        update(state=ProjectApplication.REPLACED)

    logger.info("User %s submitted %s." %
                (request_user.log_display, application.log_display))
    action = "submit_new" if project_id is None else "submit_modification"
    project_notif.application_notify(application, action)
    return application