def test_etag_value_invalidates_on_delete_favorite(self):
        self.login(self.regular_user)

        userid = self.regular_user.getId()
        favorite = FavoriteManager().add(userid, self.branch_repofolder)
        value = self.get_etag_value_for(self.portal)
        FavoriteManager().delete(userid, favorite.favorite_id)

        self.assertNotEqual(value, self.get_etag_value_for(self.portal))
Exemplo n.º 2
0
    def test_titles_of_favorites_get_truncated_on_creation(self, browser):
        self.login(self.regular_user, browser=browser)

        browser.open(self.dossier, view='edit')
        long_title = u''.join(u"\xe4" for i in range(400))
        browser.fill({u'Title': long_title})
        browser.click_on('Save')

        manager = FavoriteManager()
        fav = manager.add(self.regular_user.getId(), self.dossier)

        self.assertEquals(long_title[:CONTENT_TITLE_LENGTH],
                          Favorite.query.get(fav.favorite_id).title)
Exemplo n.º 3
0
    def test_titles_of_favorites_get_truncated_on_creation(self, browser):
        self.login(self.regular_user, browser=browser)

        browser.open(self.dossier, view='edit')
        long_title = u''.join(u"\xe4" for i in range(400))
        browser.fill({u'Title': long_title})
        browser.click_on('Save')

        manager = FavoriteManager()
        fav = manager.add(self.regular_user.getId(), self.dossier)

        self.assertEquals(long_title[:CONTENT_TITLE_LENGTH],
                          Favorite.query.get(fav.favorite_id).title)
Exemplo n.º 4
0
    def reply(self):
        userid = self.validate_user(self.get_userid())
        data = self.validate_data(json_body(self.request))
        obj = self.lookup_object(data)

        favorite = FavoriteManager().get_favorite(obj, api.user.get_current())
        if favorite:
            # favorite already exists
            self.request.response.setStatus(409)
            return favorite.serialize(api.portal.get().absolute_url())

        favorite = FavoriteManager().add(userid, obj)
        self.request.response.setStatus(201)
        url = favorite.api_url(api.portal.get().absolute_url())
        self.request.response.setHeader('Location', url)

        return favorite.serialize(api.portal.get().absolute_url())
Exemplo n.º 5
0
    def __call__(self):
        if api.user.is_anonymous():
            # Anonymous users can't have repository favorites - short circuit
            # cache key generation, no need to ask the view
            return ''

        return FavoriteManager().get_repository_favorites_cache_key(
            api.user.get_current().getId())
    def test_etag_value_invalidates_on_add_favorite(self):
        self.login(self.regular_user)

        value = self.get_etag_value_for(self.portal)
        FavoriteManager().add(self.regular_user.getId(),
                              self.branch_repofolder)

        self.assertNotEqual(value, self.get_etag_value_for(self.portal))
    def reply(self):
        self.set_cache_header()
        userid = self.get_userid()
        if userid != api.user.get_current().getId():
            raise Unauthorized(
                "It's not allowed to delete favorites of other users.")

        favorites = FavoriteManager().list_all_repository_favorites(userid)

        return [fav.plone_uid for fav in favorites]
Exemplo n.º 8
0
    def reply(self):
        userid, fav_id = self.read_params()
        if userid != api.user.get_current().getId():
            raise Unauthorized(
                "It's not allowed to delete favorites of other users.")

        FavoriteManager().delete(userid, fav_id)

        self.request.response.setStatus(204)
        return None
Exemplo n.º 9
0
 def drop_existing(self, objs, userid):
     """It's possible, that the current user has already defined new style
     favorites. To prevent conflicts, we do not migrate already existing
     favorites.
     """
     current_favorites = FavoriteManager().list_all_repository_favorites(
         userid)
     oguids = [
         current_favorite.oguid for current_favorite in current_favorites
     ]
     return [obj for obj in objs if Oguid.for_object(obj) not in oguids]
Exemplo n.º 10
0
    def migrate(self):
        for repo in self.repository_roots():
            storage = self.storage(repo)
            if not storage:
                continue

            for userid, uuids in storage.items():
                objs = map(uuidToObject, uuids)
                for obj in self.drop_existing(objs, userid):
                    if not obj:
                        # Object does no longer existng - skip it
                        continue

                    FavoriteManager().add(userid, obj)

            self.remove_storage(repo)
Exemplo n.º 11
0
    def reply(self):
        userid = self.validate_user(self.get_userid())
        data = self.validate_data(json_body(self.request))
        obj = self.lookup_object(data)

        favorite = FavoriteManager().get_favorite(obj, api.user.get_current())
        if favorite:
            # favorite already exists
            self.request.response.setStatus(409)
            return favorite.serialize(api.portal.get().absolute_url())

        favorite = FavoriteManager().add(userid, obj)
        self.request.response.setStatus(201)
        url = favorite.api_url(api.portal.get().absolute_url())
        self.request.response.setHeader('Location', url)

        return favorite.serialize(api.portal.get().absolute_url())
Exemplo n.º 12
0
    def reply(self):
        userid, fav_id = self.read_params()

        if userid != api.user.get_current().getId():
            raise Unauthorized(
                "It's not allowed to access favorites of other users.")

        portal_url = api.portal.get().absolute_url()

        if fav_id:
            favorite = Favorite.query.by_userid_and_id(fav_id, userid).first()
            if not favorite:
                # inexistent favorite-id or not ownded by given user
                raise NotFound

            return favorite.serialize(portal_url)
        else:
            favorites = FavoriteManager().list_all(userid)
            return [fav.serialize(portal_url) for fav in favorites]
Exemplo n.º 13
0
    def reply(self):
        userid, fav_id = self.read_params()

        if userid != api.user.get_current().getId():
            raise Unauthorized(
                "It's not allowed to update favorites of other users.")

        data = json_body(self.request)
        if data.get('title') is None and data.get('position') is None:
            raise BadRequest('Missing parameter title or position')

        FavoriteManager().update(userid,
                                 fav_id,
                                 title=data.get('title'),
                                 position=data.get('position'))

        prefer = self.request.getHeader('Prefer')
        if prefer == 'return=representation':
            self.request.response.setStatus(200)
            favorite = Favorite.query.get(fav_id)
            return favorite.serialize(api.portal.get().absolute_url())

        self.request.response.setStatus(204)
        return None
    def lookup_fav_id(self, uuid):
        obj = uuidToObject(uuid)
        favorite = FavoriteManager().get_favorite(obj, api.user.get_current())

        return favorite.favorite_id if favorite else ''
Exemplo n.º 15
0
 def favorites_cache_key(self):
     return FavoriteManager().get_repository_favorites_cache_key(
         api.user.get_current().getId())