Example #1
0
    def doWork(self):
        """
        Delete all the corresponding homes, then the ancillary data.
        """

        oldhome = yield self.transaction.calendarHomeWithUID(self.ownerUID, status=_HOME_STATUS_DISABLED)
        if oldhome is not None:
            # Work items - we need to clean these up before the home goes away because we have an "on delete cascade" on the WorkItem
            # table, and if that ran it would leave orphaned Job rows set to a pause state and those would remain for ever in the table.
            for workType in allScheduleWork:
                items = yield workType.query(self.transaction, workType.homeResourceID == oldhome.id())
                for item in items:
                    yield item.remove()

            yield oldhome.purgeAll()

        oldnotifications = yield self.transaction.notificationsWithUID(self.ownerUID, status=_HOME_STATUS_DISABLED)
        if oldnotifications is not None:
            yield oldnotifications.purge()

        # These are things that reference the home id or the user UID but don't get removed via a cascade

        # iMIP tokens
        cuaddr = "urn:x-uid:{}".format(self.ownerUID)
        yield iMIPTokenRecord.deletesome(
            self.transaction,
            iMIPTokenRecord.organizer == cuaddr,
        )

        # Delegators - individual and group
        yield DelegateRecord.deletesome(self.transaction, DelegateRecord.delegator == self.ownerUID)
        yield DelegateGroupsRecord.deletesome(self.transaction, DelegateGroupsRecord.delegator == self.ownerUID)
        yield ExternalDelegateGroupsRecord.deletesome(self.transaction, ExternalDelegateGroupsRecord.delegator == self.ownerUID)
Example #2
0
    def test_noDuplication(self):
        """
        Make sure addDelegate( ) is idempotent
        """
        delegator = yield self.directory.recordWithUID(u"__wsanchez1__")

        # Delegate users:
        delegate1 = yield self.directory.recordWithUID(u"__sagen1__")

        txn = self.store.newTransaction(label="test_noDuplication")
        yield Delegates.addDelegate(txn, delegator, delegate1, True)
        yield txn.commit()

        txn = self.store.newTransaction(label="test_noDuplication")
        yield Delegates.addDelegate(txn, delegator, delegate1, True)
        yield txn.commit()

        txn = self.store.newTransaction(label="test_noDuplication")
        results = yield DelegateRecord.query(
            txn,
            (DelegateRecord.delegator == delegator.uid.encode("utf-8")).And(
                DelegateRecord.readWrite == 1))
        yield txn.commit()
        self.assertEquals([
            "__sagen1__",
        ], [record.delegate for record in results])

        # Delegate groups:
        group1 = yield self.directory.recordWithUID(u"__top_group_1__")

        txn = self.store.newTransaction(label="test_noDuplication")
        yield Delegates.addDelegate(txn, delegator, group1, True)
        yield txn.commit()

        txn = self.store.newTransaction(label="test_noDuplication")
        yield Delegates.addDelegate(txn, delegator, group1, True)
        yield txn.commit()

        txn = self.store.newTransaction(label="test_noDuplication")
        results = yield DelegateGroupsRecord.delegateGroups(
            txn,
            delegator.uid,
            True,
        )
        yield txn.commit()
        self.assertEquals([
            "__top_group_1__",
        ], [record.groupUID for record in results])
    def test_noDuplication(self):
        """
        Make sure addDelegate( ) is idempotent
        """
        delegator = yield self.directory.recordWithUID(u"__wsanchez1__")

        # Delegate users:
        delegate1 = yield self.directory.recordWithUID(u"__sagen1__")

        txn = self.store.newTransaction(label="test_noDuplication")
        yield Delegates.addDelegate(txn, delegator, delegate1, True)
        yield txn.commit()

        txn = self.store.newTransaction(label="test_noDuplication")
        yield Delegates.addDelegate(txn, delegator, delegate1, True)
        yield txn.commit()

        txn = self.store.newTransaction(label="test_noDuplication")
        results = yield DelegateRecord.query(
            txn,
            (DelegateRecord.delegator == delegator.uid.encode("utf-8")).And(
                DelegateRecord.readWrite == 1
            )
        )
        yield txn.commit()
        self.assertEquals(["__sagen1__", ], [record.delegate for record in results])

        # Delegate groups:
        group1 = yield self.directory.recordWithUID(u"__top_group_1__")

        txn = self.store.newTransaction(label="test_noDuplication")
        yield Delegates.addDelegate(txn, delegator, group1, True)
        yield txn.commit()

        txn = self.store.newTransaction(label="test_noDuplication")
        yield Delegates.addDelegate(txn, delegator, group1, True)
        yield txn.commit()

        txn = self.store.newTransaction(label="test_noDuplication")
        results = yield DelegateGroupsRecord.delegateGroups(
            txn,
            delegator.uid,
            True,
        )
        yield txn.commit()
        self.assertEquals(["__top_group_1__", ], [record.groupUID for record in results])
Example #4
0
    def doWork(self):
        """
        Delete all the corresponding homes, then the ancillary data.
        """

        oldhome = yield self.transaction.calendarHomeWithUID(
            self.ownerUID, status=_HOME_STATUS_DISABLED)
        if oldhome is not None:
            # Work items - we need to clean these up before the home goes away because we have an "on delete cascade" on the WorkItem
            # table, and if that ran it would leave orphaned Job rows set to a pause state and those would remain for ever in the table.
            for workType in allScheduleWork:
                items = yield workType.query(
                    self.transaction, workType.homeResourceID == oldhome.id())
                for item in items:
                    yield item.remove()

            yield oldhome.purgeAll()

        oldnotifications = yield self.transaction.notificationsWithUID(
            self.ownerUID, status=_HOME_STATUS_DISABLED)
        if oldnotifications is not None:
            yield oldnotifications.purge()

        # These are things that reference the home id or the user UID but don't get removed via a cascade

        # iMIP tokens
        cuaddr = "urn:x-uid:{}".format(self.ownerUID)
        yield iMIPTokenRecord.deletesome(
            self.transaction,
            iMIPTokenRecord.organizer == cuaddr,
        )

        # Delegators - individual and group
        yield DelegateRecord.deletesome(
            self.transaction, DelegateRecord.delegator == self.ownerUID)
        yield DelegateGroupsRecord.deletesome(
            self.transaction, DelegateGroupsRecord.delegator == self.ownerUID)
        yield ExternalDelegateGroupsRecord.deletesome(
            self.transaction,
            ExternalDelegateGroupsRecord.delegator == self.ownerUID)