Commit 89357e81 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[datafeed, entities] url for entities from a datafeed source should be on...

[datafeed, entities] url for entities from a datafeed source should be on their origin site. Closes #1769391
parent 92fd4b777016
......@@ -433,9 +433,11 @@ class Entity(AppObject):
use_ext_id = False
if 'base_url' not in kwargs and \
getattr(self._cw, 'search_state', ('normal',))[0] == 'normal':
baseurl = self.cw_metainformation()['source'].get('base-url')
if baseurl:
kwargs['base_url'] = baseurl
sourcemeta = self.cw_metainformation()['source']
if sourcemeta.get('use-cwuri-as-url'):
return self.cwuri # XXX consider kwargs?
if sourcemeta.get('base-url'):
kwargs['base_url'] = sourcemeta['base-url']
use_ext_id = True
if method in (None, 'view'):
try:
......
......@@ -110,6 +110,10 @@ class AbstractSource(object):
# force deactivation (configuration error for instance)
disabled = False
# boolean telling if cwuri of entities from this source is the url that
# should be used as entity's absolute url
use_cwuri_as_url = False
# source configuration options
options = ()
......@@ -119,6 +123,7 @@ class AbstractSource(object):
self.support_relations['identity'] = False
self.eid = eid
self.public_config = source_config.copy()
self.public_config.setdefault('use-cwuri-as-url', self.use_cwuri_as_url)
self.remove_sensitive_information(self.public_config)
self.uri = source_config.pop('uri')
set_log_methods(self, getLogger('cubicweb.sources.'+self.uri))
......@@ -213,7 +218,7 @@ class AbstractSource(object):
"""
pass
PUBLIC_KEYS = ('type', 'uri')
PUBLIC_KEYS = ('type', 'uri', 'use-cwuri-as-url')
def remove_sensitive_information(self, sourcedef):
"""remove sensitive information such as login / password from source
definition
......
......@@ -35,6 +35,7 @@ from cubicweb.appobject import AppObject
class DataFeedSource(AbstractSource):
copy_based_source = True
use_cwuri_as_url = True
options = (
('synchronize',
......
......@@ -67,6 +67,7 @@ class DataFeedTC(CubicWebTC):
'source': {'uri': 'myfeed', 'type': 'datafeed'},
'extid': 'http://www.cubicweb.org/'}
)
self.assertEqual(entity.absolute_url(), 'extid': 'http://www.cubicweb.org/')
# test repo cache keys
self.assertEqual(self.repo._type_source_cache[entity.eid],
('Card', 'system', 'http://www.cubicweb.org/', 'myfeed'))
......
......@@ -164,11 +164,13 @@ class CWEntityXMLParserTC(CubicWebTC):
self.assertEqual(user.modification_date, datetime(2011, 01, 25, 14, 14, 06))
self.assertEqual(user.cwuri, 'http://pouet.org/5')
self.assertEqual(user.cw_source[0].name, 'myfeed')
self.assertEqual(user.absolute_url(), 'http://pouet.org/5')
self.assertEqual(len(user.use_email), 1)
# copy action
email = user.use_email[0]
self.assertEqual(email.address, 'syt@logilab.fr')
self.assertEqual(email.cwuri, 'http://pouet.org/6')
self.assertEqual(email.absolute_url(), 'http://pouet.org/6')
self.assertEqual(email.cw_source[0].name, 'myfeed')
# link action
self.assertFalse(self.execute('CWGroup X WHERE X name "unknown"'))
......@@ -200,7 +202,8 @@ class CWEntityXMLParserTC(CubicWebTC):
self.assertEqual(len(rset), 1)
e = rset.get_entity(0, 0)
self.assertEqual(e.eid, email.eid)
self.assertEqual(e.cw_metainformation(), {'source': {'type': u'native', 'uri': u'system'},
self.assertEqual(e.cw_metainformation(), {'source': {'type': u'native', 'uri': u'system',
'use-cwuri-as-url': False},
'type': 'EmailAddress',
'extid': None})
self.assertEqual(e.cw_source[0].name, 'system')
......@@ -213,7 +216,8 @@ class CWEntityXMLParserTC(CubicWebTC):
self.assertEqual(len(rset), 1)
e = rset.get_entity(0, 0)
self.assertEqual(e.eid, email.eid)
self.assertEqual(e.cw_metainformation(), {'source': {'type': u'native', 'uri': u'system'},
self.assertEqual(e.cw_metainformation(), {'source': {'type': u'native', 'uri': u'system',
'use-cwuri-as-url': False},
'type': 'EmailAddress',
'extid': None})
self.assertEqual(e.cw_source[0].name, 'system')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment