Skip to content

Commit

Permalink
Merge 8e2325a into 6411fc2
Browse files Browse the repository at this point in the history
  • Loading branch information
tcurvelo committed Jul 25, 2017
2 parents 6411fc2 + 8e2325a commit 1b9b757
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
5 changes: 2 additions & 3 deletions sc/social/like/browser/canonicalurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sc.social.like.behaviors import ISocialMedia
from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.logger import logger
from sc.social.like.utils import get_path_to_virtual_path
from sc.social.like.utils import get_valid_objects
from sc.social.like.utils import validate_canonical_domain
from z3c.form import button
Expand Down Expand Up @@ -106,9 +107,7 @@ def update_canonical_url(self, data):
logger.info(u'{0} objects will have their canonical URL updated'.format(total))

for obj in get_valid_objects(results):
# FIXME: we're currently ignoring the Plone site id
# https://github.com/collective/sc.social.like/issues/119
path = '/'.join(obj.getPhysicalPath()[2:])
path = get_path_to_virtual_path(self.request, obj)
if obj.effective_date < DateTime(published_before):
# use the canonical domain defined in this form
obj.canonical_url = '{0}/{1}'.format(old_canonical_domain, path)
Expand Down
5 changes: 2 additions & 3 deletions sc/social/like/subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from sc.social.like.config import PROJECTNAME
from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.logger import logger
from sc.social.like.utils import get_path_to_virtual_path
from zope.component import getUtility
from zope.schema.interfaces import WrongType

Expand Down Expand Up @@ -97,9 +98,7 @@ def assign_canonical_url(obj, event):

# we can't assign a canonical URL without a canonical domain
if canonical_domain:
# FIXME: we're currently ignoring the Plone site id
# https://github.com/collective/sc.social.like/issues/119
path = '/'.join(obj.getPhysicalPath()[2:])
path = get_path_to_virtual_path(event.request, obj)
obj.canonical_url = '{0}/{1}'.format(canonical_domain, path)
logger.info('canonical_url set for {0}'.format(obj.canonical_url))
else:
Expand Down
1 change: 0 additions & 1 deletion sc/social/like/tests/test_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def setUp(self):
def test_socialmedia_behavior(self):
self.assertTrue(ISocialMedia.providedBy(self.obj))

@unittest.expectedFailure # FIXME: https://github.com/collective/sc.social.like/issues/119
def test_canonical_url(self):
# canonical URL is empty after creation
self.assertIsNone(self.obj.canonical_url)
Expand Down
33 changes: 32 additions & 1 deletion sc/social/like/tests/test_canonicalurl_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"""Test for the canonical URL updater form."""
from DateTime import DateTime
from plone import api
from Products.SiteAccess.VirtualHostMonster import manage_addVirtualHostMonster
from sc.social.like.interfaces import ISocialLikeSettings
from sc.social.like.testing import HAS_DEXTERITY
from sc.social.like.testing import INTEGRATION_TESTING
from sc.social.like.tests.utils import enable_social_media_behavior
from sc.social.like.utils import get_path_to_virtual_path

import unittest

Expand Down Expand Up @@ -47,7 +49,6 @@ def setup_content(self):
self.portal['baz'].effective_date = DateTime()
self.portal['baz'].reindexObject()

@unittest.expectedFailure # FIXME: https://github.com/collective/sc.social.like/issues/119
def test_update_canonical_url(self):
# canonical URL is None as we did not set up a canonical domain
self.assertIsNone(self.portal['foo'].canonical_url)
Expand All @@ -72,3 +73,33 @@ def test_update_canonical_url(self):
# canonical URL unchaged
self.assertEqual(
self.portal['baz'].canonical_url, 'https://example.org/plone/baz')


class UtilPathToVirtualPathTestCase(unittest.TestCase):

layer = INTEGRATION_TESTING

def setUp(self):
app = self.layer['app']
portal = self.layer['portal']
self.request = self.layer['request']

if 'virtual_hosting' not in app.objectIds():
manage_addVirtualHostMonster(app, 'virtual_hosting')

with api.env.adopt_roles(['Manager']):
self.obj = api.content.create(portal, type='News Item', id='foo')
api.content.transition(self.obj, 'publish')

def test_get_path_to_virtual_path(self):
self.request.traverse('/plone/')
self.assertEqual(
get_path_to_virtual_path(self.request, self.obj),
'plone/foo')

def test_get_path_to_virtual_path_using_virtualhostmonster(self):
self.request.traverse(
'/VirtualHostBase/http/bar.com/plone/VirtualHostRoot/')
self.assertEqual(
get_path_to_virtual_path(self.request, self.obj),
'foo')
8 changes: 8 additions & 0 deletions sc/social/like/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,11 @@ def get_valid_objects(brains):
logger.warn(msg.format(b.getPath()))
continue
yield obj


def get_path_to_virtual_path(request, item):
return '/'.join(
request.physicalPathToVirtualPath(
item.getPhysicalPath()
)
)

0 comments on commit 1b9b757

Please sign in to comment.