Esempio n. 1
0
def application_apply_project(request):
    application_form = forms.NewProjectApplicationForm 
    mcs = MachineCategory.objects.all()
    application = ProjectApplication()
    application.save()
    application.machine_categories = mcs
    applicant = request.user
    institute = applicant.institute 
    if request.method == 'POST':
        form = application_form(request.POST, instance = application)
        if form.is_valid():
            application = form.save(commit=False)
            mc = MachineCategory.objects.get_default()
            if mc:
                mcs = []
                mcs.append(mc)
                application.machine_categories = mcs
                application.applicant = applicant
                application.make_leader = True 
                application.needs_account = True
                application.state = ProjectApplication.WAITING_FOR_DELEGATE
                group = Group.objects.get(name = "monashcampusclusterapprovals")
                application.institute = Institute.objects.get(group = group.id) 
                application.pid = util.getDefaultProjectPid()
                application.save()
                application_request_email(application, send_to = "delegate")
                emails.send_user_request_email("common", application, "apply for a new project", request.POST.get("name"))
                messages.info(request, "Thanks %s, your new project application is pending for institution delegates approving" %(applicant.username))
                return HttpResponseRedirect(reverse('index'))
            return HttpResponseBadRequest("<h1>Bad Post</h1>") 
        else:
            return HttpResponseBadRequest("<h1>Bad Request</h1>") 
    form = application_form(instance=application, initial={'institute': institute})
    return render_to_response('kgapplications/request_new_project.html', {'form': form, 'application': application}, context_instance=RequestContext(request))
Esempio n. 2
0
def application_request_email(application, send_to = "leader"):
    try:
        if send_to == "admin":
            authorised_text = "an administrator"
            authorised_persons = Person.objects.filter(is_admin = admin)
        elif send_to == "delegate":
            authorised_text = "the delegate"
            authorised_persons = application.institute.delegates.all()
        else:
            authorised_text = "the project leader"
            authorised_persons = application.project.leaders.filter(is_active=True)

        link, is_secret = base.get_registration_email_link(application)
        emails.send_request_email(authorised_text, authorised_persons, application, link, is_secret)

    except:
        util.log("Exception to send project leader email %s" % traceback.format_exc())
Esempio n. 3
0
def application_request_email(application, send_to="leader"):
    try:
        if send_to == "admin":
            authorised_text = "an administrator"
            authorised_persons = Person.objects.filter(is_admin=admin)
        elif send_to == "delegate":
            authorised_text = "the delegate"
            authorised_persons = application.institute.delegates.all()
        else:
            authorised_text = "the project leader"
            authorised_persons = application.project.leaders.filter(
                is_active=True)

        link, is_secret = base.get_registration_email_link(application)
        emails.send_request_email(authorised_text, authorised_persons,
                                  application, link, is_secret)

    except:
        util.log("Exception to send project leader email %s" %
                 traceback.format_exc())
Esempio n. 4
0
def add_edit_project(request, project_id=None):

    if project_id is None:
        project = None
        old_pid = None
        flag = 1
    else:
        project = get_object_or_404(Project, id=project_id)
        old_pid = project.pid
        flag = 2

    if util.is_admin(request):
        # JH add initial pid
        initial_pid = cutil.getDefaultProjectPid()
        form = ProjectForm(instance=project,
                           data=request.POST or None,
                           pid_initial=initial_pid)
    else:
        if not project.can_edit(request):
            return HttpResponseForbidden('<h1>Access Denied</h1>')
        form = UserProjectForm(instance=project, data=request.POST or None)

    if request.method == 'POST':
        if form.is_valid():
            project = form.save(commit=False)
            if project_id is not None:
                # if project is being edited, project_id cannot change.
                project.pid = old_pid
            elif not project.pid:
                # if project was being created, did the user give a project_id
                # we should use? If not, then we have to generate one
                # ourselves.
                project.pid = get_new_pid(project.institute)
            project.save()
            approved_by = request.user
            project.activate(approved_by)
            form.save_m2m()
            if flag == 1:
                messages.success(request,
                                 "Project '%s' created succesfully" % project)
            else:
                messages.success(request,
                                 "Project '%s' edited succesfully" % project)

            return HttpResponseRedirect(project.get_absolute_url())

    return render_to_response('karaage/projects/project_form.html',
                              locals(),
                              context_instance=RequestContext(request))
Esempio n. 5
0
def add_edit_project(request, project_id=None):

    if project_id is None:
        project = None
        old_pid = None
        flag = 1
    else:
        project = get_object_or_404(Project, id=project_id)
        old_pid = project.pid
        flag = 2

    if util.is_admin(request):
# JH add initial pid
        initial_pid = cutil.getDefaultProjectPid()
        form = ProjectForm(instance=project, data=request.POST or None, pid_initial = initial_pid)
    else:
        if not project.can_edit(request):
            return HttpResponseForbidden('<h1>Access Denied</h1>')
        form = UserProjectForm(instance=project, data=request.POST or None)

    if request.method == 'POST':
        if form.is_valid():
            project = form.save(commit=False)
            if project_id is not None:
                # if project is being edited, project_id cannot change.
                project.pid = old_pid
            elif not project.pid:
                # if project was being created, did the user give a project_id
                # we should use? If not, then we have to generate one
                # ourselves.
                project.pid = get_new_pid(project.institute)
            project.save()
            approved_by = request.user
            project.activate(approved_by)
            form.save_m2m()
            if flag == 1:
                messages.success(
                    request, "Project '%s' created succesfully" % project)
            else:
                messages.success(
                    request, "Project '%s' edited succesfully" % project)

            return HttpResponseRedirect(project.get_absolute_url())

    return render_to_response(
        'karaage/projects/project_form.html',
        locals(),
        context_instance=RequestContext(request))
Esempio n. 6
0
    def process_request(self, request):
        # AuthenticationMiddleware is required so that request.user exists.
        if not hasattr(request, "user"):
            raise ImproperlyConfigured(
                "The Django SAML user auth middleware requires the"
                " authentication middleware to be installed.  Edit your"
                " MIDDLEWARE_CLASSES setting to insert"
                " 'django.contrib.auth.middleware.AuthenticationMiddleware'"
                " before the SamlUserMiddleware class."
            )

        # If the user is already authenticated and that user is the user we are
        # getting passed in the headers, then the correct user is already
        # persisted in the session and we don't need to continue.
        if request.user.is_authenticated():
            return

        # Is this a shib session?
        if not saml.is_saml_session(request):
            return

        # Can we get the shib attributes we need?
        attrs, error = util.parseShibAttributes(request)
        #        attrs, error = saml.parse_attributes(request)
        if error:
            return render_to_response(
                "saml_error.html", {"shib_attrs": attrs}, context_instance=RequestContext(request)
            )

        # What is our persistent_id?
        saml_id = attrs["persistent_id"]
        assert saml_id

        # We are seeing this user for the first time in this session, attempt
        # to authenticate the user.
        try:
            person = Person.objects.get(saml_id=saml_id)
        except Person.DoesNotExist:
            return

        # User is valid.  Set request.user and persist user in the session
        # by logging the user in.
        request.user = person
        # We must set the model backend here manually as we skip
        # the call to auth.authenticate().
        request.user.backend = "django.contrib.auth.backends.ModelBackend"
        auth.login(request, person)
Esempio n. 7
0
def application_apply_project(request):
    application_form = forms.NewProjectApplicationForm
    mcs = MachineCategory.objects.all()
    application = ProjectApplication()
    application.save()
    application.machine_categories = mcs
    applicant = request.user
    institute = applicant.institute
    if request.method == 'POST':
        form = application_form(request.POST, instance=application)
        if form.is_valid():
            application = form.save(commit=False)
            mc = MachineCategory.objects.get_default()
            if mc:
                mcs = []
                mcs.append(mc)
                application.machine_categories = mcs
                application.applicant = applicant
                application.make_leader = True
                application.needs_account = True
                application.state = ProjectApplication.WAITING_FOR_DELEGATE
                group = Group.objects.get(name="monashcampusclusterapprovals")
                application.institute = Institute.objects.get(group=group.id)
                application.pid = util.getDefaultProjectPid()
                application.save()
                application_request_email(application, send_to="delegate")
                emails.send_user_request_email("common", application,
                                               "apply for a new project",
                                               request.POST.get("name"))
                messages.info(
                    request,
                    "Thanks %s, your new project application is pending for institution delegates approving"
                    % (applicant.username))
                return HttpResponseRedirect(reverse('index'))
            return HttpResponseBadRequest("<h1>Bad Post</h1>")
        else:
            return HttpResponseBadRequest("<h1>Bad Request</h1>")
    form = application_form(instance=application,
                            initial={'institute': institute})
    return render_to_response('kgapplications/request_new_project.html', {
        'form': form,
        'application': application
    },
                              context_instance=RequestContext(request))
Esempio n. 8
0
def aafbootstrap(request):
    redirect_to = reverse('samlredirect')
    user, attr = util.findUser(request)
    if user:
        return HttpResponseRedirect(redirect_to)
    ids = util.parseUserId(request, attr)
    if ids:
        form = IdForm(ids = ids)
        if request.method == 'POST':
            if request.POST.get("Cancel"):
                return HttpResponseRedirect("/") 
            else:
                id = request.POST.get('id')
                new_user, error, person = util.aafbootstrap(request, id)
                util.log("Create user account username = '******'" % id)
            if error:
                return
            return HttpResponseRedirect(redirect_to)
        return render_to_response('karaage/common/aafid.html', {'form': form}, context_instance=RequestContext(request))        
    new_user, error, person = util.aafbootstrap(request)
    if error:
        return 
    return HttpResponseRedirect(redirect_to)