コード例 #1
0
ファイル: models.py プロジェクト: russell/karaage
    def save(self, *args, **kwargs):
        # save the object
        super(Machine, self).save(*args, **kwargs)

        # log message
        log(None, self, 2, 'Saved machine')
        log(None, self.category, 2, 'Saved machine %s' % self)
コード例 #2
0
ファイル: models.py プロジェクト: russell/karaage
 def deactivate(self, deleted_by):
     self.is_active = False
     self.deleted_by = deleted_by
     self.date_deleted = datetime.datetime.today()
     self.group.members.clear()
     self.save()
     log(None, self, 2, 'Deactivated by %s'%deleted_by)
コード例 #3
0
ファイル: admin.py プロジェクト: NeCTAR-RC/karaage
def remove_user(request, project_id, username):

    project = get_object_or_404(Project, pid=project_id)
    person = get_object_or_404(Person, username=username)

    query = person.account_set.filter(date_deleted__isnull=True, default_project=project)

    error = None
    if query.count() > 0:
        error = "The person has accounts that use this project as the default_project."

    elif 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())

    del query

    return render_to_response('projects/remove_user_confirm.html',
        { 'project': project, 'person': person, 'error': error, },
        context_instance=RequestContext(request))
コード例 #4
0
ファイル: models.py プロジェクト: russell/karaage
 def change_name(self, new_name):
     old_name = self.name
     if old_name != new_name:
         self.name = new_name
         # we call super.save() to avoid calling datastore save needlessly
         super(Group, self).save()
         from karaage.datastores import set_group_name
         set_group_name(self, old_name, new_name)
         log(None, self, 2, "Renamed group")
コード例 #5
0
ファイル: models.py プロジェクト: russell/karaage
 def activate(self, approved_by):
     if self.is_active == True:
         return
     self.is_active = True
     self.is_approved = True
     self.date_approved = datetime.datetime.today()
     self.approved_by = approved_by
     self.save()
     log(None, self, 2, 'Activated by %s'%approved_by)
コード例 #6
0
ファイル: models.py プロジェクト: russell/karaage
 def delete(self):
     # delete the object
     super(Account, self).delete()
     if self.date_deleted is None:
         # delete the datastore
         from karaage.datastores import delete_account
         delete_account(self)
         log(None, self.machine_category, 2,
             'Deleted account %s' % self)
コード例 #7
0
ファイル: models.py プロジェクト: russell/karaage
 def set_password(self, password):
     if self.date_deleted is not None:
         raise RuntimeError("Account is deactivated")
     from karaage.datastores import set_account_password
     set_account_password(self, password)
     log(None, self.machine_category, 2,
         'Changed Password of %s' % self)
     log(None, self.person, 2,
         'Changed Password of %s' % self)
コード例 #8
0
ファイル: models.py プロジェクト: russell/karaage
 def set_password(self, password):
     super(Person, self).set_password(password)
     if self.legacy_ldap_password is not None:
         self.legacy_ldap_password = None
     super(Person, self).save()
     from karaage.datastores import set_person_password
     set_person_password(self, password)
     for ua in self.account_set.filter(date_deleted__isnull=True):
         ua.set_password(password)
     log(None, self, 2, 'Changed Password')
コード例 #9
0
ファイル: models.py プロジェクト: russell/karaage
    def save(self, *args, **kwargs):
        # save the object
        super(Group, self).save(*args, **kwargs)

        # update the datastore
        from karaage.datastores import save_group
        save_group(self)

        # log message
        log(None, self, 2, "Saved group")
コード例 #10
0
ファイル: admin.py プロジェクト: NeCTAR-RC/karaage
def delete_version(request, version_id):
    version = get_object_or_404(SoftwareVersion, pk=version_id)

    if request.method == 'POST':
        version.delete()
        log(request.user, version.software, 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))
コード例 #11
0
ファイル: admin.py プロジェクト: NeCTAR-RC/karaage
def add_license(request, software_id):
    software = get_object_or_404(Software, pk=software_id)

    form = LicenseForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            l = form.save()
            log(request.user, software, 1, "license: %s added" % l)
            return HttpResponseRedirect(software.get_absolute_url())

    return render_to_response('software/license_form.html', locals(), context_instance=RequestContext(request))
コード例 #12
0
ファイル: models.py プロジェクト: NeCTAR-RC/karaage
    def activate(self, approved_by):
        if not self.is_active:
            self.date_approved = datetime.datetime.today()

            self.approved_by = approved_by
            self.deleted_by = None
            self.date_deleted = None
            self.is_active = True
            self.save()

            log(None, self, 2, "Activated by %s" % approved_by)
コード例 #13
0
ファイル: admin.py プロジェクト: russell/karaage
def make_default(request, account_id, project_id):
    account = get_object_or_404(Account, pk=account_id)
    project = get_object_or_404(Project, pid=project_id)

    if request.method != "POST":
        return HttpResponseRedirect(account.get_absolute_url())

    account.default_project = project
    account.save()
    messages.success(request, "Default project changed succesfully")
    log(request.user, account.person, 2, "Changed default project to %s" % project.pid)
    return HttpResponseRedirect(account.get_absolute_url())
コード例 #14
0
ファイル: admin.py プロジェクト: NeCTAR-RC/karaage
def add_package(request):

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

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

    return render_to_response('software/add_package_form.html', locals(), context_instance=RequestContext(request))
コード例 #15
0
def bounced_email(request, username):
    person = get_object_or_404(Person, 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.account_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))
コード例 #16
0
ファイル: views.py プロジェクト: NeCTAR-RC/karaage-user
def make_project_default(request, account_id, project_id):
    person = request.user
    account = get_object_or_404(Account, pk=account_id, person=person)
    project = get_object_or_404(Project, pid=project_id)

    if request.method != 'POST':
        return HttpResponseRedirect(reverse('kg_user_profile'))

    account.default_project = project
    account.save()
    log(request.user, account, 2, 'Changed default project to %s' % project.pid)
    messages.success(request, "Default project changed succesfully")
    return HttpResponseRedirect(request.POST.get('next', reverse('kg_user_profile')))
コード例 #17
0
ファイル: models.py プロジェクト: NeCTAR-RC/karaage
    def deactivate(self, deleted_by):
        """ Sets Person not active and deletes all Accounts"""
        self.is_active = False
        self.expires = None

        self.date_deleted = datetime.datetime.today()
        self.deleted_by = deleted_by
        self.groups.clear()
        self.save()

        for ua in self.account_set.filter(date_deleted__isnull=True):
            ua.deactivate()

        log(None, self, 2, "Deactivated by %s" % deleted_by)
コード例 #18
0
ファイル: admin.py プロジェクト: NeCTAR-RC/karaage
def applicant_edit(request, applicant_id):
    
    applicant = get_object_or_404(Applicant, id=applicant_id)

    form = ApplicantForm(request.POST or None, instance=applicant)
    if request.method == 'POST':
        if form.is_valid():
            applicant = form.save()
            log(request.user, applicant, 2, 'Edited')
            messages.success(request, "%s modified successfully." % applicant)
            return HttpResponseRedirect(reverse('kg_application_list'))

    return render_to_response('applications/applicant_form.html',
            {'form': form}, context_instance=RequestContext(request))
コード例 #19
0
ファイル: views.py プロジェクト: NeCTAR-RC/karaage-user
def make_project_default(request, account_id, project_id):
    person = request.user
    account = get_object_or_404(Account, pk=account_id, person=person)
    project = get_object_or_404(Project, pid=project_id)

    if request.method != 'POST':
        return HttpResponseRedirect(reverse('kg_user_profile'))

    account.default_project = project
    account.save()
    log(request.user, account, 2,
        'Changed default project to %s' % project.pid)
    messages.success(request, "Default project changed succesfully")
    return HttpResponseRedirect(
        request.POST.get('next', reverse('kg_user_profile')))
コード例 #20
0
ファイル: admin.py プロジェクト: NeCTAR-RC/karaage
def remove_member(request, software_id, person_id):
    software = get_object_or_404(Software, pk=software_id)
    person = get_object_or_404(Person, pk=person_id)

    if request.method == 'POST':
        person.remove_group(software.group)

        log(request.user, software, 3, 'Removed %s from group' % person)
        log(request.user, person, 3, 'Removed from software group %s' % software)

        messages.success(request, "User '%s' removed successfuly" % person)

        return HttpResponseRedirect(software.get_absolute_url())

    return render_to_response('software/person_confirm_remove.html', locals(), context_instance=RequestContext(request))
コード例 #21
0
ファイル: models.py プロジェクト: russell/karaage
    def save(self, *args, **kwargs):
        # save the object
        super(MachineCategory, self).save(*args, **kwargs)

        # check if datastore changed
        moved = False
        old_datastore = self._datastore
        new_datastore = self.datastore
        if old_datastore != new_datastore:
            from karaage.datastores import set_mc_datastore
            set_mc_datastore(self, old_datastore, new_datastore)

        # log message
        log(None, self, 2, 'Saved machine category')

        self._datastore = self.datastore
コード例 #22
0
ファイル: managers.py プロジェクト: NeCTAR-RC/karaage
    def _create_user(self, username, email, short_name, full_name,
            institute, password, is_admin, **extra_fields):
        """Creates a new active person. """

        #Create Person
        person = self.model(
            username=username, email=email,
            short_name=short_name, full_name=full_name,
            is_admin=is_admin, is_active=True,
            institute=institute,
            **extra_fields
            )
        person.set_password(password)
        person.save(self._db)

        log(None, person, 1, 'Created person')
        return person
コード例 #23
0
ファイル: user.py プロジェクト: NeCTAR-RC/karaage
def remove_user(request, project_id, username):

    project = get_object_or_404(Project, pid=project_id)
    person = get_object_or_404(Person, username=username)

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

    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))
コード例 #24
0
ファイル: models.py プロジェクト: russell/karaage
    def create(cls, person, default_project, machine_category):
        """Creates a Account (if needed) and activates person.
        """
        ua = Account.objects.create(
            person=person, username=person.username,
            shell=settings.DEFAULT_SHELL,
            machine_category=machine_category,
            default_project=default_project,
            date_created=datetime.datetime.today())

        if default_project is not None:
            person.add_group(default_project.group)

        log(None, person, 1,
            'Created account on %s' % machine_category)
        log(None, machine_category, 1,
            'Created account')
        return ua
コード例 #25
0
ファイル: user.py プロジェクト: NeCTAR-RC/karaage
def add_edit_project(request, project_id):

    project = get_object_or_404(Project, pid=project_id)
    if not request.user 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))
コード例 #26
0
ファイル: admin.py プロジェクト: NeCTAR-RC/karaage
def projectquota_edit(request, projectquota_id):

    project_chunk = get_object_or_404(ProjectQuota, pk=projectquota_id)
    old_cap = project_chunk.cap
    old_mc = project_chunk.machine_category

    form = ProjectQuotaForm(request.POST or None, instance=project_chunk)
    if request.method == 'POST':
        if form.is_valid():
            mc = form.cleaned_data['machine_category']
            if old_mc.pk != mc.pk:
                form._errors["machine_category"] = ErrorList(["Please don't change the machine category; it confuses me"])
            else:
                project_chunk = form.save()
                new_cap = project_chunk.cap
                if old_cap != new_cap:
                    log(request.user, project_chunk.project, 2, 'Changed cap from %s to %s' % (old_cap, new_cap))
                return HttpResponseRedirect(project_chunk.project.get_absolute_url())

    return render_to_response('projects/projectquota_form.html', locals(), context_instance=RequestContext(request))
コード例 #27
0
def user_detail(request, username):
    
    person = get_object_or_404(Person, username=username)

    my_projects = person.projects.all()
    my_pids = [p.pid for p in my_projects]
    
    #Add to project form
    form = AddProjectForm(request.POST or None)
    if request.method == 'POST':
        # Post means adding this user to a project
        if form.is_valid():
            project = form.cleaned_data['project']
            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)

            return HttpResponseRedirect(person.get_absolute_url())

    return render_to_response('people/person_detail.html', locals(), context_instance=RequestContext(request))
コード例 #28
0
ファイル: xmlrpc.py プロジェクト: russell/karaage
def change_default_project(user, project):
    """
    Change default project
    """
    person = user
    try:
        project = Project.objects.get(pid=project, projectquota__machine_category=machine.category)
    except Project.DoesNotExist:
        return -1, "Project %s does not exist" % project

    if not person in project.group.members.all():
        return -2, "User %s not a member of project %s" % (user, project.pid)

    account = Account.objects.get(username=username, machine_category=machine.category, date_deleted__isnull=True)

    account.default_project = project
    account.save()

    log(user.user, user, 2, "Changed default project to %s" % project.pid)

    return 0, "Default project changed"
コード例 #29
0
ファイル: admin.py プロジェクト: NeCTAR-RC/karaage
def add_edit_project(request, project_id=None):

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

    if request.method == 'POST':
        form = ProjectForm(request.POST, instance=project)

        if form.is_valid():
            project = form.save(commit=False)
            if project_id is not None:
                # if project is being edited, project_id cannot change, so we
                # should always use the value supplied on the URL.
                project.pid = project_id
            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)
                log(None, project, 1, 'Created')
            else:
                messages.success(request, "Project '%s' edited succesfully" % project)
                log(None, project, 2, 'Edited')

            return HttpResponseRedirect(project.get_absolute_url())
    else:
        form = ProjectForm(instance=project)

    return render_to_response('projects/project_form.html', locals(), context_instance=RequestContext(request))
コード例 #30
0
ファイル: admin.py プロジェクト: NeCTAR-RC/karaage
def delete_project(request, project_id):

    project = get_object_or_404(Project, pid=project_id)

    query = Account.objects.filter(date_deleted__isnull=True, default_project=project)

    error = None
    if query.count() > 0:
        error = "There are accounts that use this project as the default_project."

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

    del query

    return render_to_response('projects/project_confirm_delete.html',
            { 'project': project, 'error': error },
            context_instance=RequestContext(request))
コード例 #31
0
ファイル: lock_expired.py プロジェクト: NeCTAR-RC/karaage
    def handle(self, **options):
        from karaage.common import log
        from karaage.people.models import Person
        from django.core.mail import mail_admins
        import datetime
        today = datetime.date.today()

        verbose = int(options.get('verbosity'))

        for p in Person.objects.filter(expires__lte=today):
            try:
                if not p.is_locked():
                    p.lock()
                    p.expires = None
                    p.save()
                    message = "%s's account has expired and their account has been locked. %s does not know this" % (p, p)
                    mail_admins('Locked expired user %s' % p,  message, fail_silently=False)
                    log(p.user, p, 2, 'Account auto expired')
                    if verbose >= 1:
                        print "Locked account for %s - %s" % (p.username, p)
            except:
                print "Failed to lock %s" % p