Example #1
0
def _remove_person_from_group(person, group):
    """ Call datastores after removing a person from a group. """
    from karaage.datastores import remove_person_from_group
    from karaage.datastores import remove_person_from_project
    from karaage.datastores import remove_person_from_institute
    from karaage.datastores import remove_person_from_software
    from karaage.datastores import remove_account_from_group
    from karaage.datastores import remove_account_from_project
    from karaage.datastores import remove_account_from_institute
    from karaage.datastores import remove_account_from_software

    a_list = list(person.account_set.filter(date_deleted__isnull=True))
    remove_person_from_group(person, group)
    for account in a_list:
        remove_account_from_group(account, group)
    for project in group.project_set.all():
        remove_person_from_project(person, project)
        for account in a_list:
            remove_account_from_project(account, project)
    for institute in group.institute_set.all():
        remove_person_from_institute(person, institute)
        for account in a_list:
            remove_account_from_institute(account, institute)
    for software in group.software_set.all():
        remove_person_from_software(person, software)
        for account in a_list:
            remove_account_from_software(account, software)
Example #2
0
    def delete(self, *args, **kwargs):
        # Get list of accounts.
        # This must happen before we call the super method,
        # as this will delete accounts that use this institute.
        old_group_pk = self._tracker.previous("group_id")
        if old_group_pk is not None:
            old_group = Group.objects.get(pk=old_group_pk)
            query = Account.objects.filter(person__groups=old_group)
            query = query.filter(date_deleted__isnull=True)
            accounts = list(query)
        else:
            accounts = []

        # delete the object
        log.delete(self, 'Deleted')
        super(Institute, self).delete(*args, **kwargs)

        # update datastore associations
        for account in accounts:
            from karaage.datastores import remove_account_from_institute
            remove_account_from_institute(account, self)

        # update the datastore
        from karaage.datastores import delete_institute
        delete_institute(self)
Example #3
0
    def delete(self, *args, **kwargs):
        # Get list of accounts.
        # This must happen before we call the super method,
        # as this will delete accounts that use this institute.
        old_group_pk = self._tracker.previous("group_id")
        if old_group_pk is not None:
            old_group = Group.objects.get(pk=old_group_pk)
            query = Account.objects.filter(person__groups=old_group)
            query = query.filter(date_deleted__isnull=True)
            accounts = list(query)
        else:
            accounts = []

        # delete the object
        log.delete(self, 'Deleted')
        super(Institute, self).delete(*args, **kwargs)

        # update datastore associations
        for account in accounts:
            from karaage.datastores import remove_account_from_institute
            remove_account_from_institute(account, self)

        # update the datastore
        from karaage.datastores import delete_institute
        delete_institute(self)
Example #4
0
    def save(self, *args, **kwargs):
        # save the object
        super(Person, self).save(*args, **kwargs)

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

        # update account datastores
        from karaage.datastores import save_account
        for ua in self.account_set.filter(date_deleted__isnull=True):
            save_account(ua)

        # has username changed?
        old_username = self._username
        new_username = self.username
        if old_username != new_username:
            from karaage.datastores import set_person_username
            set_person_username(self, old_username, new_username)

        # has locked status changed?
        old_login_enabled = self._login_enabled
        new_login_enabled = self.login_enabled
        if old_login_enabled != new_login_enabled:
            if new_login_enabled:
                for ua in self.account_set.filter(date_deleted__isnull=True):
                    ua.unlock()
                log(None, self, 2, 'Unlocked person')
            else:
                for ua in self.account_set.filter(date_deleted__isnull=True):
                    ua.lock()
                log(None, self, 2, 'Locked person')

        # has the institute changed?
        old_institute = self._institute
        new_institute = self.institute
        if old_institute != new_institute:
            if old_institute is not None:
                from karaage.datastores import remove_person_from_institute
                remove_person_from_institute(self, old_institute)
                from karaage.datastores import remove_account_from_institute
                for account in self.account_set.filter(date_deleted__isnull=True):
                    remove_account_from_institute(account, old_institute)
            if new_institute is not None:
                from karaage.datastores import add_person_to_institute
                add_person_to_institute(self, new_institute)
                from karaage.datastores import add_account_to_institute
                for account in self.account_set.filter(date_deleted__isnull=True):
                    add_account_to_institute(account, new_institute)

        # log message
        log(None, self, 2, 'Saved person')

        # save current state
        self._username = self.username
        self._login_enabled = self.login_enabled
        self._institute = self.institute
Example #5
0
    def delete(self, *args, **kwargs):
        # delete the object
        super(Institute, self).delete(*args, **kwargs)

        # update datastore associations
        old_group = self._group
        if old_group is not None:
            from karaage.datastores import remove_person_from_institute
            for person in Person.objects.filter(groups=old_group):
                remove_person_from_institute(person, self)
            from karaage.datastores import remove_account_from_institute
            for account in Account.objects.filter(person__groups=old_group, date_deleted__isnull=True):
                remove_account_from_institute(account, self)

        # update the datastore
        from karaage.datastores import delete_institute
        delete_institute(self)
Example #6
0
    def save(self, *args, **kwargs):
        # set group if not already set
        if self.group_id is None:
            name = str(self.name.lower().replace(' ', ''))
            self.group,_ = Group.objects.get_or_create(name=name)

        # save the object
        super(Institute, self).save(*args, **kwargs)

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

        # has group changed?
        old_group = self._group
        new_group = self.group
        if old_group != new_group:
            if old_group is not None:
                from karaage.datastores import remove_person_from_institute
                for person in Person.objects.filter(groups=old_group):
                    remove_person_from_institute(person, self)
                from karaage.datastores import remove_account_from_institute
                for account in Account.objects.filter(person__groups=old_group, date_deleted__isnull=True):
                    remove_account_from_institute(account, self)
            if new_group is not None:
                from karaage.datastores import add_person_to_institute
                for person in Person.objects.filter(groups=new_group):
                    add_person_to_institute(person, self)
                from karaage.datastores import add_account_to_institute
                for account in Account.objects.filter(person__groups=new_group, date_deleted__isnull=True):
                    add_account_to_institute(account, self)

        # log message
        log(None, self, 2, 'Saved institute')

        # save the current state
        self._group = self.group