def unlock_person(request, username):
    person = get_object_or_404(Person, user__username=username)
    person.unlock()
    messages.success(request, "%s's account has been unlocked" % person)
    log(request.user, person, 2, 'Account unlocked')
    
    return HttpResponseRedirect(person.get_absolute_url())
Exemple #2
0
def software_detail(request, package_id):
    package = get_object_or_404(SoftwarePackage, pk=package_id)

    members = package.get_group_members()
    non_ids = []
    member_list = []
    if members:
        for member in members:
            try:
                person = Person.objects.get(user__username=member.uid)
                non_ids.append(person.id)
            except Person.DoesNotExist:
                person = None
            
            member_list.append({
                'username': member.uid,
                'person': person,
                })

    not_member_list = Person.objects.select_related().exclude(id__in=non_ids)

    if request.method == 'POST' and 'member-add' in request.POST:
        person = get_object_or_404(Person, pk=request.POST['member'])
        from karaage.datastores.software import add_member
        add_member(package, person)

        messages.success(request, "User %s added to group" % person)
        log(request.user, package, 1, "User %s added to group manually" % person)
        return HttpResponseRedirect(package.get_absolute_url())

    return render_to_response('software/software_detail.html', locals(), context_instance=RequestContext(request))
Exemple #3
0
def make_default(request, useraccount_id, project_id):

    user_account = get_object_or_404(UserAccount, pk=useraccount_id)
    project = get_object_or_404(Project, pk=project_id)

    access = False
    if request.user.has_perm('machines.change_useraccount'):
        access = True

    if request.user == user_account.user.user:
        access = True

    if not access:
        return HttpResponseForbidden('<h1>Access Denied</h1>')

    user_account = get_object_or_404(UserAccount, pk=useraccount_id)
    project = get_object_or_404(Project, pk=project_id)

    user_account.default_project = project
    user_account.save()
    user_account.user.save()
    
    messages.success(request, "Default project changed succesfully")
    log(request.user, user_account.user, 2, 'Changed default project to %s' % project.pid)

    if 'next' in request.REQUEST:
        return HttpResponseRedirect(request.GET['next'])
    return HttpResponseRedirect(user_account.get_absolute_url())
Exemple #4
0
def projectchunk_add(request, project_id):

    project = get_object_or_404(Project, pk=project_id)
    
    project_chunk = ProjectChunk()
    project_chunk.project = project

    if request.method == 'POST':
        form = ProjectChunkForm(request.POST, instance=project_chunk)
        if form.is_valid():
            mc = form.cleaned_data['machine_category']
            conflicting = ProjectChunk.objects.filter(
                project=project,machine_category=mc)

            if conflicting.count() >= 1:
                form._errors["machine_category"] = util.ErrorList(["Cap already exists with this machine category"])
            else:
                project_chunk = form.save()
                new_cap = project_chunk.cap
                log(request.user, project, 2, 'Added cap of %s' % (new_cap))
                return HttpResponseRedirect(project.get_absolute_url())
    else:
        form = ProjectChunkForm(instance=project_chunk)

    return render_to_response('pbsmoab/projectchunk_form.html', locals(), context_instance=RequestContext(request))
Exemple #5
0
def approve_userapplication(request, application_id):
    application = get_object_or_404(UserApplication, pk=application_id)
    if not request.user.get_profile() in application.project.leaders.all():
        return HttpResponseForbidden('<h1>Access Denied</h1>')
    if application.state != Application.WAITING_FOR_LEADER:
        return render_to_response('applications/unable_to_approve.html', {'application': application}, context_instance=RequestContext(request))

    if request.method == 'POST':
        form = LeaderApproveUserApplicationForm(request.POST, instance=application)
        if form.is_valid():
            application = form.save()

            if settings.ADMIN_APPROVE_ACCOUNTS:
                application.state = Application.WAITING_FOR_ADMIN
                application.save()
                send_notify_admin(application, request.user.get_full_name())
                log(request.user, application.application_ptr, 2, 'Leader approved application')
                return HttpResponseRedirect(reverse('kg_userapplication_pending', args=[application.id]))

            application.approve()
            send_account_approved_email(application)
            log(request.user, application.application_ptr, 2, 'Application fully approved')
            return HttpResponseRedirect(reverse('kg_userapplication_complete', args=[application.id]))
    else:
        form = LeaderApproveUserApplicationForm(instance=application)

    return render_to_response('applications/approve_application.html', {'form': form, 'application': application}, context_instance=RequestContext(request))
Exemple #6
0
def decline_projectapplication(request, application_id):
    application = get_object_or_404(ProjectApplication, pk=application_id)

    if not request.user.get_profile() in application.institute.delegates.all():
        return HttpResponseForbidden('<h1>Access Denied</h1>')
    
    if application.state != Application.WAITING_FOR_DELEGATE:
        return render_to_response('applications/unable_to_approve.html', {'application': application}, context_instance=RequestContext(request))

    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            to_email = application.applicant.email
            subject, body = form.get_data()
            log(request.user, application.application_ptr, 3, 'Application declined')
            application.decline()
            send_mail(subject, body, settings.ACCOUNTS_EMAIL, [to_email], fail_silently=False)
            return HttpResponseRedirect(reverse('kg_application_pendinglist'))

    else:
        subject, body = render_email('project_declined', {'receiver': application.applicant})
        initial_data = {'body': body, 'subject': subject}
        form = EmailForm(initial=initial_data)

    return render_to_response('applications/project_confirm_decline.html', {'application': application, 'form': form}, context_instance=RequestContext(request))
def user_detail(request, username):
    
    person = get_object_or_404(Person, user__username=username)

    my_projects = person.project_set.all()
    my_pids = [p.pid for p in my_projects]
    
    not_project_list = Project.active.exclude(pid__in=my_pids)

    #Add to project form
    if request.method == 'POST' and 'project-add' in request.POST:
        # Post means adding this user to a project
        data = request.POST.copy()
        project = Project.objects.get(pk=data['project'])
        no_account_error = ''
        for mc in project.machine_categories.all():
            if not person.has_account(mc):
                no_account_error = "%s has no account on %s. Please create one first" % (person, project.machine_category)
                break
        if not no_account_error:
            add_user_to_project(person, project)
            messages.success(request, "User '%s' was added to %s succesfully" % (person, project))
            log(request.user, project, 2, '%s added to project' % person)

    #change shell form
    shell_form = ShellForm()
    try:
        shell_form.initial = {'shell': person.loginShell()}
    except:
        pass
    
    return render_to_response('people/person_detail.html', locals(), context_instance=RequestContext(request))
Exemple #8
0
 def delete_account(self, ua):
     if not ua.date_deleted:
         ua.date_deleted = datetime.datetime.now()
         ua.save()
     for project in ua.project_list():
         project.users.remove(ua.user)
         project.save()
     log(get_current_user(), ua.user, 3, 'Deleted account on %s' % ua.machine_category)
Exemple #9
0
 def delete_account(self, ua):
     if not ua.date_deleted:
         ua.date_deleted = datetime.datetime.now()
         ua.save()
     from karaage.projects.utils import remove_user_from_project
     for project in ua.project_list():
         
         remove_user_from_project(ua.user, project)
     log(get_current_user(), ua.user, 3, 'Deleted account on %s' % ua.machine_category)
Exemple #10
0
def delete_application(request, application_id):
    application = get_object_or_404(Application, pk=application_id)

    if request.method == 'POST':
        application.delete()
        log(request.user, application, 3, 'Application deleted')
        messages.success(request, "%s deleted successfully." % application)
        return HttpResponseRedirect(reverse('kg_application_list'))

    return render_to_response('applications/application_confirm_delete.html', {'application': application}, context_instance=RequestContext(request))
Exemple #11
0
def archive_application(request, application_id):
    application = get_object_or_404(Application, pk=application_id)

    if request.method == 'POST':
        application.state = Application.ARCHIVED
        application.save()
        log(request.user, application, 2, 'Application archived')
        messages.success(request, "%s archived successfully." % application)
        return HttpResponseRedirect(application.get_absolute_url())

    return render_to_response('applications/application_archive.html', {'application': application}, context_instance=RequestContext(request))
Exemple #12
0
def delete_project(request, project_id):

    project = get_object_or_404(Project, pk=project_id)

    if request.method == 'POST':
        project.deactivate()
        log(request.user, project, 3, 'Deleted')
        messages.success(request, "Project '%s' deleted succesfully" % project)
        return HttpResponseRedirect(project.get_absolute_url())

    return render_to_response('projects/project_confirm_delete.html', {'project': project}, context_instance=RequestContext(request))
Exemple #13
0
def delete_version(request, package_id, version_id):
    
    version = get_object_or_404(SoftwareVersion, pk=version_id)
    
    if request.method == 'POST':
        version.delete()
        log(request.user, version.package, 3, 'Deleted version: %s' % version)
        
        messages.success(request, "Version '%s' was deleted succesfully" % version)
        return HttpResponseRedirect(version.get_absolute_url())
    
    return render_to_response('software/version_confirm_delete.html', locals(), context_instance=RequestContext(request))
Exemple #14
0
    def create_new_user(self, data, hashed_password=None):
        """Creates a new user (not active)

        Keyword arguments:
        data -- a dictonary of user data
        hashed_password --
    
        """
        # Make sure username isn't taken in Datastore
        random_passwd = User.objects.make_random_password()
        user = User.objects.create_user(data['username'], data['email'], random_passwd)
        
        if hashed_password:
            user.password = hashed_password
        else:
            from karaage.datastores import create_password_hash
            user.password = create_password_hash(data['password1'])
            
        user.is_active = False
        user.save()
    
        #Create Person
        person = Person.objects.create(
            user=user,
            first_name=data['first_name'],
            last_name=data['last_name'],
            institute=data['institute'],
            position=data.get('position', ''),
            department=data.get('department', ''),
            title=data.get('title', ''),
            address=data.get('address', ''),
            country=data.get('country', ''),
            website=data.get('website', ''),
            fax=data.get('fax', ''),
            comment=data.get('comment', ''),
            telephone=data.get('telephone', ''),
            mobile=data.get('mobile', ''),
            supervisor=data.get('supervisor', ''),
            is_systemuser=data.get('is_systemuser', ''),
            saml_id=data.get('saml_id', None),
            )
        
        try:
            current_user = get_current_user()
            if current_user.is_anonymous():
                current_user = person.user
        except:
            current_user = person.user

        log(current_user, person, 1, 'Created')
        
        return person
Exemple #15
0
def add_package(request):

    if request.method == 'POST':
        form = AddPackageForm(request.POST)

        if form.is_valid():
            package = form.save()
            log(request.user, package, 1, "Added")
            return HttpResponseRedirect(package.get_absolute_url())
    else:
        form = AddPackageForm()

    return render_to_response('software/add_package_form.html', locals(), context_instance=RequestContext(request))
Exemple #16
0
def remove_member(request, package_id, user_id):

    package = get_object_or_404(SoftwarePackage, pk=package_id)
    person = get_object_or_404(Person, pk=user_id)

    from karaage.datastores.software import remove_member as ds_remove_member
    ds_remove_member(package, person)

    log(request.user, package, 3, 'Removed %s from group' % person)
    log(request.user, person, 3, 'Removed from software group %s' % package)
        
    messages.success(request, "User '%s' removed successfuly" % person)

    return HttpResponseRedirect(package.get_absolute_url())
def bounced_email(request, username):
    person = get_object_or_404(Person, user__username=username)

    if request.method == 'POST':
        person.lock()
        send_bounced_warning(person)
        messages.success(request, "%s's account has been locked and emails have been sent" % person)
        log(request.user, person, 2, 'Emails sent to project leaders and account locked')
        for ua in person.useraccount_set.all():
            ua.change_shell(ua.previous_shell)
            ua.change_shell(settings.BOUNCED_SHELL)
        return HttpResponseRedirect(person.get_absolute_url())

    return render_to_response('people/bounced_email.html', locals(), context_instance=RequestContext(request))
Exemple #18
0
def remove_user(request, project_id, username):

    project = get_object_or_404(Project, pk=project_id)
    person = get_object_or_404(Person, user__username=username)

    if request.method == 'POST':
        remove_user_from_project(person, project)
        messages.success(request, "User '%s' removed succesfully from project %s" % (person, project.pid))
    
        log(request.user, project, 3, 'Removed %s from project' % person)
        log(request.user, person, 3, 'Removed from project %s' % project)

        return HttpResponseRedirect(project.get_absolute_url())
    
    return render_to_response('projects/remove_user_confirm.html', {'project': project, 'person': person}, context_instance=RequestContext(request))
Exemple #19
0
def send_invitation(request, project_id):
    project = get_object_or_404(Project, pk=project_id)
    if not request.user.get_profile() in project.leaders.all():
        return HttpResponseForbidden('<h1>Access Denied</h1>')
    application = None

    if request.method == 'POST':
        form = LeaderInviteUserApplicationForm(request.POST, instance=application)

        if form.is_valid():
            email = form.cleaned_data['email']
            try:
                existing = Person.active.get(user__email=email)
            except Person.DoesNotExist:
                existing = False
            if existing and not 'existing' in request.REQUEST:
                return render_to_response('applications/userapplication_invite_existing.html',
                                          {'form': form, 'person': existing},
                                          context_instance=RequestContext(request))
            application = form.save(commit=False)

            try:
                applicant = Person.active.get(user__email=email)
            except Person.DoesNotExist:
                applicant, created = Applicant.objects.get_or_create(email=email)

            application.applicant = applicant
            application.project = project
            application.save()
            if application.content_type.model == 'person':
                application.approve()
                send_account_approved_email(application)
                messages.warning(request, "%s was added to project %s directly since they have an existing account." %
                              (application.applicant, application.project))
                log(request.user, application.application_ptr, 1, "%s added directly to %s" % (applicant, project))
                return HttpResponseRedirect(application.applicant.get_absolute_url())

            send_user_invite_email(application)
            messages.success(request, "Invitation sent to %s." % email)
            log(request.user, application.application_ptr, 1, 'Invitation sent')
            return HttpResponseRedirect(reverse('kg_user_profile'))
        
    else:
        form = LeaderInviteUserApplicationForm(instance=application)

    return render_to_response('applications/leaderuserapplication_invite_form.html',
                              {'form': form, 'application': application, 'project': project},
                              context_instance=RequestContext(request))
def password_change(request, username):
    person = get_object_or_404(Person, user__username=username)
    
    if request.POST:
        form = AdminPasswordChangeForm(request.POST)
        
        if form.is_valid():
            form.save(person)
            messages.success(request, "Password changed successfully")
            log(request.user, person, 2, 'Changed password')
            if person.is_locked():
                person.unlock()
            return HttpResponseRedirect(person.get_absolute_url())
    else:
        form = AdminPasswordChangeForm()
        
    return render_to_response('people/password_change_form.html', {'person': person, 'form': form}, context_instance=RequestContext(request))
Exemple #21
0
def send_bounced_warning(person):
    """Sends an email to each project leader for person
    informing them that person's email has bounced"""
    context = CONTEXT.copy()
    context['person'] = person

    for project in person.project_set.all():
        if project.is_active:
            context['project'] = project
            for leader in project.leaders.all():
                context['receiver'] = leader

                to_email = leader.email
                subject = render_to_string('requests/emails/bounced_email_subject.txt', context)
                body = render_to_string('requests/emails/bounced_email_body.txt', context)
                send_mail(subject.replace('\n', ''), body, settings.ACCOUNTS_EMAIL, [to_email])
                active_user = get_current_user()
                log(active_user, leader, 2, 'Sent email about bounced emails from %s' % person)
Exemple #22
0
def remove_user(request, project_id, username):

    project = get_object_or_404(Project, pk=project_id)
    person = get_object_or_404(Person, user__username=username)

    if not request.user.get_profile() in project.leaders.all():
        return HttpResponseForbidden('<h1>Access Denied</h1>')

    if request.method == 'POST':
        project.users.remove(person)
        project.save()
        messages.success(request, "User '%s' removed succesfully from project %s" % (person, project.pid))
    
        log(request.user, project, 3, 'Removed %s from project' % person)
        log(request.user, person, 3, 'Removed from project %s' % project)
        return HttpResponseRedirect(project.get_absolute_url())
    
    return render_to_response('projects/remove_user_confirm.html', {'project': project, 'person': person}, context_instance=RequestContext(request))
Exemple #23
0
    def delete_user(self, person):
        """ Sets Person not active and deletes all UserAccounts"""
        person.user.is_active = False
        person.expires = None
        person.user.save()
    
        deletor = get_current_user()
    
        person.date_deleted = datetime.datetime.today()
        person.deleted_by = deletor.get_profile()
        person.save(update_datastore=False)

        from karaage.datastores import delete_account

        for ua in person.useraccount_set.filter(date_deleted__isnull=True):
            delete_account(ua)

        log(deletor, person, 3, 'Deleted')
Exemple #24
0
def applicant_edit(request, applicant_id):
    
    applicant = get_object_or_404(Applicant, id=applicant_id)

    if request.method == 'POST':
        form = ApplicantForm(request.POST, instance=applicant)
        if form.is_valid():
            applicant = form.save()
            log(request.user, applicant, 2, 'Edited')
            messages.success(request, "%s modified successfully." % applicant)
            try:
                return HttpResponseRedirect(applicant.applications.all()[0].get_absolute_url())
            except IndexError:
                return HttpResponseRedirect(reverse('kg_application_list'))
    else:
        form = ApplicantForm(instance=applicant)
    
    return render_to_response('applications/applicant_form.html', {'applicant': applicant, 'form': form}, context_instance=RequestContext(request))
Exemple #25
0
def add_edit_project(request, project_id):

    project = get_object_or_404(Project, pk=project_id)
    if not request.user.get_profile() in project.leaders.all():
        return HttpResponseForbidden('<h1>Access Denied</h1>')

    if request.method == 'POST':

        form = ProjectForm(request.POST, instance=project)
        
        if form.is_valid():
            project = form.save()
            messages.success(request, "Project edited successfully")
            log(request.user, project, 2, "Edited project")
            return HttpResponseRedirect(project.get_absolute_url())
    else:
        form = ProjectForm(instance=project)

    return render_to_response('projects/user_project_form.html', {'form': form, 'project': project}, context_instance=RequestContext(request))
Exemple #26
0
def approve_userapplication(request, application_id):
    application = get_object_or_404(UserApplication, pk=application_id)

    if application.state != Application.WAITING_FOR_ADMIN:
        raise Http404

    if request.method == 'POST':
        form = LeaderApproveUserApplicationForm(request.POST, instance=application)
        if form.is_valid():
            application = form.save()
            person = application.approve()
            send_account_approved_email(application)
            messages.success(request, "Application approved successfully")
            log(request.user, application.application_ptr, 2, 'Application fully approved')
            return HttpResponseRedirect(person.get_absolute_url())
    else:
        form = LeaderApproveUserApplicationForm(instance=application)

    return render_to_response('applications/approve_application.html', {'form': form, 'application': application}, context_instance=RequestContext(request))
Exemple #27
0
def approve_projectapplication(request, application_id):
    application = get_object_or_404(ProjectApplication, pk=application_id)

    if application.state != Application.WAITING_FOR_ADMIN:
        raise Http404

    if request.method == 'POST':
        form = AdminApproveProjectApplicationForm(request.POST, instance=application)
        if form.is_valid():
            application = form.save()
            project = application.approve(pid=form.cleaned_data['pid'])
            send_project_approved_email(application)
            messages.success(request, "Application approved successfully.")
            log(request.user, application.application_ptr, 2, 'Application fully approved')
            return HttpResponseRedirect(project.get_absolute_url())
    else:
        form = AdminApproveProjectApplicationForm(instance=application)

    return render_to_response('applications/approve_projectapplication.html', {'form': form, 'application': application}, context_instance=RequestContext(request))
Exemple #28
0
    def activate_user(self, person):
        """ Activates a user """
        try:
            current_user = get_current_user()
            if current_user.is_anonymous():
                current_user = person.user
        except:
            current_user = person.user

        person.date_approved = datetime.datetime.today()

        person.approved_by = current_user.get_profile()
        person.deleted_by = None
        person.date_deleted = None
        person.user.is_active = True
        person.user.save()

        log(current_user, person, 1, 'Activated')

        return person
Exemple #29
0
def softwarerequest_approve(request, softwarerequest_id):
    softwarerequest = get_object_or_404(SoftwareAccessRequest, pk=softwarerequest_id)

    if request.method == 'POST':
        
        SoftwareLicenseAgreement.objects.create(
            user=softwarerequest.person,
            license=softwarerequest.software_license,
            date=datetime.datetime.today(),
            )
        from karaage.datastores.software import add_member
        add_member(softwarerequest.software_license.package, softwarerequest.person)

        messages.success(request, "Software request approved successfully")
        send_software_request_approved_email(softwarerequest)
        log(request.user, softwarerequest.software_license.package, 1, "User %s approved" % softwarerequest.person)
        softwarerequest.delete()
        return HttpResponseRedirect(reverse('kg_softwarerequest_list'))

    return render_to_response('software/request_approve.html', {'softwarerequest': softwarerequest}, context_instance=RequestContext(request))
Exemple #30
0
def decline_userapplication(request, application_id):
    application = get_object_or_404(UserApplication, pk=application_id)

    if application.state != Application.WAITING_FOR_ADMIN:
        raise Http404
    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            to_email = application.applicant.email
            subject, body = form.get_data()
            log(request.user, application.application_ptr, 3, 'Application declined')
            messages.success(request, "%s declined successfully." % application)
            application.decline()
            send_mail(subject, body, settings.ACCOUNTS_EMAIL, [to_email], fail_silently=False)
            return HttpResponseRedirect(reverse('kg_application_list'))
    else:
        subject, body = render_email('account_declined', {'receiver': application.applicant, 'project': application.project})
        initial_data = {'body': body, 'subject': subject}
        form = EmailForm(initial=initial_data)

    return render_to_response('applications/confirm_decline.html', {'application': application, 'form': form}, context_instance=RequestContext(request))