示例#1
0
    def test_redirect_if_correct_client(self):
        absolute_url = 'http://anyhost/client1/somedossier'
        obj = self.mocker.mock()
        self.expect(obj.absolute_url()).result(absolute_url)

        context = object()

        request = self.mocker.mock()
        self.expect(request.get('oguid')).result('client1:444')
        self.expect(request.RESPONSE.redirect(absolute_url)).result(
            'redirected')

        intids = self.mocker.mock()
        self.expect(intids.getObject(444)).result(obj)
        self.mock_utility(intids, IIntIds)

        mtool = self.mocker.mock()
        self.expect(mtool.getAuthenticatedMember().checkPermission(
                'View', obj)).result(True)
        self.mock_tool(mtool, 'portal_membership')

        self.replay()

        view = ResolveOGUIDView(context, request)
        self.assertEqual(view.render(), 'redirected')
示例#2
0
    def test_check_permissions_fails_with_nobody(self):
        mtool = self.mocker.mock()
        self.expect(mtool.getAuthenticatedMember()).result(
            SpecialUsers.nobody)
        self.mock_tool(mtool, 'portal_membership')

        self.replay()

        view = ResolveOGUIDView(object(), object())

        with TestCase.assertRaises(self, Unauthorized):
            view._check_permissions(object())
示例#3
0
    def test_check_permission_fails_without_view_permission(self):
        obj = self.mocker.mock()

        mtool = self.mocker.mock()
        self.expect(mtool.getAuthenticatedMember().checkPermission(
                'View', obj)).result(False)
        self.mock_tool(mtool, 'portal_membership')

        self.replay()

        view = ResolveOGUIDView(object(), object())

        with TestCase.assertRaises(self, Unauthorized):
            view._check_permissions(obj)
    def test_check_permissions_fails_with_nobody(self, browser):
        self.login(self.regular_user)
        url = ResolveOGUIDView.url_for(
            Oguid.for_object(self.task), get_current_admin_unit())

        with browser.expect_unauthorized():
            browser.open(url)
示例#5
0
    def test_check_permissions_fails_with_nobody(self, browser):
        self.login(self.regular_user)
        url = ResolveOGUIDView.url_for(Oguid.for_object(self.task),
                                       get_current_admin_unit())

        with browser.expect_unauthorized():
            browser.open(url)
示例#6
0
    def test_redirect_if_correct_client(self, browser):
        self.login(self.regular_user, browser=browser)

        url = ResolveOGUIDView.url_for(Oguid.for_object(self.task),
                                       get_current_admin_unit())

        browser.open(url)
        self.assertEqual(self.task.absolute_url(), browser.url)
    def test_redirect_if_correct_client(self, browser):
        self.login(self.regular_user, browser=browser)

        url = ResolveOGUIDView.url_for(
            Oguid.for_object(self.task), get_current_admin_unit())

        browser.open(url)
        self.assertEqual(self.task.absolute_url(), browser.url)
示例#8
0
    def test_redirect_to_other_client(self):
        oguid = 'client2:5'
        client2_url = 'http://otherhost/client2'
        target_url = '%s/@@resolve_oguid?oguid=%s' % (client2_url, oguid)

        info = self.mocker.mock()
        self.mock_utility(info, IContactInformation)
        self.expect(info.get_client_by_id('client2').public_url).result(
            client2_url)

        request = self.mocker.mock()
        self.expect(request.get('oguid')).result('client2:5')
        self.expect(request.RESPONSE.redirect(target_url)).result('REDIRECT')

        self.replay()

        view = ResolveOGUIDView(object(), request)
        self.assertEqual(view.render(), 'REDIRECT')
示例#9
0
 def prepare_data(self, notifications):
     items = []
     language = self.get_users_language()
     data = self.group_by_resource(notifications).items()
     for resource, notifications in data:
         activities = [
             self.serialize_activity(notification.activity, language)
             for notification in notifications]
         items.append({
             'title': activities[0]['title'],
             'url': ResolveOGUIDView.url_for(resource.oguid),
             'activities': activities})
     return items
示例#10
0
    def redirect(self):
        """Redirect to the affected resource. If the resource is stored
        in an other admin_unit than the current one, it redirects to the
        resolve_oguid view on this admin_unit."""

        oguid = self.notification.activity.resource.oguid

        if oguid.is_on_current_admin_unit:
            url = oguid.resolve_object().absolute_url()

        else:
            admin_unit = ogds_service().fetch_admin_unit(oguid.admin_unit_id)
            url = ResolveOGUIDView.url_for(oguid, admin_unit)

        return self.request.RESPONSE.redirect(url)
示例#11
0
    def redirect(self):
        """Redirect to the affected resource. If the resource is stored
        in an other admin_unit than the current one, it redirects to the
        resolve_oguid view on this admin_unit."""

        oguid = self.notification.activity.resource.oguid

        if oguid.is_on_current_admin_unit:
            url = oguid.resolve_object().absolute_url()

        else:
            admin_unit = ogds_service().fetch_admin_unit(oguid.admin_unit_id)
            url = ResolveOGUIDView.url_for(oguid, admin_unit)

        return self.request.RESPONSE.redirect(url)
示例#12
0
 def prepare_data(self, notifications):
     items = []
     language = self.get_users_language()
     data = self.group_by_resource(notifications).items()
     for resource, notifications in data:
         activities = [
             self.serialize_activity(notification.activity, language)
             for notification in notifications
         ]
         items.append({
             'title': activities[0]['title'],
             'url': ResolveOGUIDView.url_for(resource.oguid),
             'activities': activities
         })
     return items
示例#13
0
    def get_url(self):
        """Return an url to the object represented by this Oguid.

        Resolves the object and returns its absolute_url for objects on the
        same admin-unit.
        Returns an url to the resolve_oguid view for objects on foreign
        admin-units.

        """
        obj = self.resolve_object()
        if obj:
            return obj.absolute_url()
        admin_unit = ogds_service().fetch_admin_unit(self.admin_unit_id)

        # XXX have some kind ouf routes to avoid cyclic dependecies
        from opengever.base.browser.resolveoguid import ResolveOGUIDView
        return ResolveOGUIDView.url_for(self, admin_unit=admin_unit)
示例#14
0
    def get_url(self):
        """Return an url to the object represented by this Oguid.

        Resolves the object and returns its absolute_url for objects on the
        same admin-unit.
        Returns an url to the resolve_oguid view for objects on foreign
        admin-units.

        """
        obj = self.resolve_object()
        if obj:
            return obj.absolute_url()
        admin_unit = ogds_service().fetch_admin_unit(self.admin_unit_id)

        # XXX have some kind ouf routes to avoid cyclic dependecies
        from opengever.base.browser.resolveoguid import ResolveOGUIDView
        return ResolveOGUIDView.url_for(self, admin_unit=admin_unit)
示例#15
0
    def redirect(self):
        """Redirect to the affected resource. If the resource is stored
        in an other admin_unit than the current one, it redirects to the
        resolve_oguid view on this admin_unit."""
        oguid = self.notification.activity.resource.oguid

        if oguid.is_on_current_admin_unit:
            try:
                url = oguid.resolve_object().absolute_url()
            except KeyError:
                raise NotFound('Requested object has been deleted')

        else:
            admin_unit = ogds_service().fetch_admin_unit(oguid.admin_unit_id)
            url = ResolveOGUIDView.url_for(oguid, admin_unit)

        return self.request.RESPONSE.redirect(self.preserve_query_string(url))
示例#16
0
 def test_redirect_if_correct_client(self, browser):
     url = ResolveOGUIDView.url_for('client1:{}'.format(self.task_id),
                                    self.admin_unit)
     browser.login().open(url)
     self.assertEqual(self.task.absolute_url(), browser.url)
示例#17
0
 def test_check_permissions_fails_with_nobody(self, browser):
     logout()
     url = ResolveOGUIDView.url_for('client1:{}'.format(self.task_id),
                                    self.admin_unit)
     with self.assertRaises(Unauthorized):
         browser.open(url)
示例#18
0
 def test_check_permissions_fails_with_nobody(self, browser):
     logout()
     url = ResolveOGUIDView.url_for('client1:{}'.format(self.task_id),
                                    self.admin_unit)
     with browser.expect_unauthorized():
         browser.open(url)
示例#19
0
 def test_redirect_if_correct_client(self, browser):
     url = ResolveOGUIDView.url_for('client1:{}'.format(self.task_id),
                                    self.admin_unit)
     browser.login().open(url)
     self.assertEqual(self.task.absolute_url(), browser.url)