Пример #1
0
    def testDeleteNamespace(self):
        """L{Facade.deleteNamespace} deletes a L{Namespace}."""
        namespaces = NamespaceAPI(self.user)
        namespaces.create([(u'username/name', u'A namespace.')])
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            yield self.facade.deleteNamespace(session, u'username/name')

        self.store.rollback()
        self.assertEqual({}, namespaces.get([u'username/name']))
Пример #2
0
    def testDeleteNamespace(self):
        """L{Facade.deleteNamespace} deletes a L{Namespace}."""
        namespaces = NamespaceAPI(self.user)
        namespaces.create([(u'username/name', u'A namespace.')])
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            yield self.facade.deleteNamespace(session, u'username/name')

        self.store.rollback()
        self.assertEqual({}, namespaces.get([u'username/name']))
Пример #3
0
def apply(store):
    # Using model code in a patch isn't ideal, but writing this patch with
    # pure SQL will be heinous.
    for user in getUsers():
        if user.username in ('fluiddb', 'anon'):
            continue
        namespaces = NamespaceAPI(user)
        path = '%s/private' % user.username
        if not namespaces.get([path]):
            namespaces.create([
                (path, u'Private namespace for user %s' % user.username)
            ])
            namespace = getNamespaces(paths=[path]).one()
            permission = namespace.permission
            permission.set(Operation.LIST_NAMESPACE, Policy.CLOSED, [user.id])
Пример #4
0
    def testUpdateNamespace(self):
        """
        L{Facade.updateNamespace} updates the description for an existing
        L{Namespace}.
        """
        namespaces = NamespaceAPI(self.user)
        namespaces.create([(u'username/name', u'A namespace.')])
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            yield self.facade.updateNamespace(session, u'username/name',
                                              u'A new description.')

        self.store.rollback()
        result = namespaces.get([u'username/name'], withDescriptions=True)
        self.assertEqual(u'A new description.',
                         result[u'username/name']['description'])
Пример #5
0
    def testUpdateNamespace(self):
        """
        L{Facade.updateNamespace} updates the description for an existing
        L{Namespace}.
        """
        namespaces = NamespaceAPI(self.user)
        namespaces.create([(u'username/name', u'A namespace.')])
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            yield self.facade.updateNamespace(session, u'username/name',
                                              u'A new description.')

        self.store.rollback()
        result = namespaces.get([u'username/name'], withDescriptions=True)
        self.assertEqual(u'A new description.',
                         result[u'username/name']['description'])
Пример #6
0
class CachingNamespaceAPI(object):
    """The public API to cached namespace-related logic in the model.

    @param user: The L{User} to perform operations on behalf of.
    """
    def __init__(self, user):
        self._api = NamespaceAPI(user, factory=CachingAPIFactory())

    def create(self, values):
        """See L{NamespaceAPI.create}."""
        return self._api.create(values)

    def delete(self, paths):
        """See L{NamespaceAPI.delete}.

        Permissions for deleted L{Namespace}s are removed from the cache.
        """
        if isgenerator(paths):
            paths = list(paths)
        cache = PermissionCache()
        cache.clearNamespacePermissions(paths)
        return self._api.delete(paths)

    def get(self,
            paths,
            withDescriptions=None,
            withNamespaces=None,
            withTags=None):
        """See L{NamespaceAPI.get}."""
        return self._api.get(paths,
                             withDescriptions=withDescriptions,
                             withNamespaces=withNamespaces,
                             withTags=withTags)

    def set(self, values):
        """Set or update L{Namespace}s.

        @param values: A C{dict} mapping L{Namespace.path}s to descriptions.
        @return: A C{list} of C{(objectID, Namespace.path)} 2-tuples
            representing the L{Namespace}s that were updated.
        """
        return self._api.set(values)
Пример #7
0
class CachingNamespaceAPI(object):
    """The public API to cached namespace-related logic in the model.

    @param user: The L{User} to perform operations on behalf of.
    """

    def __init__(self, user):
        self._api = NamespaceAPI(user, factory=CachingAPIFactory())

    def create(self, values):
        """See L{NamespaceAPI.create}."""
        return self._api.create(values)

    def delete(self, paths):
        """See L{NamespaceAPI.delete}.

        Permissions for deleted L{Namespace}s are removed from the cache.
        """
        if isgenerator(paths):
            paths = list(paths)
        cache = PermissionCache()
        cache.clearNamespacePermissions(paths)
        return self._api.delete(paths)

    def get(self, paths, withDescriptions=None, withNamespaces=None,
            withTags=None):
        """See L{NamespaceAPI.get}."""
        return self._api.get(paths, withDescriptions=withDescriptions,
                             withNamespaces=withNamespaces, withTags=withTags)

    def set(self, values):
        """Set or update L{Namespace}s.

        @param values: A C{dict} mapping L{Namespace.path}s to descriptions.
        @return: A C{list} of C{(objectID, Namespace.path)} 2-tuples
            representing the L{Namespace}s that were updated.
        """
        return self._api.set(values)