# HG changeset patch # User Sylvain Thénault # Date 1449674100 -3600 # Node ID ef1cfc80d51cb2ae3e22a9eb543b595d28dd53d0 # Parent 282880f81311f8b328db6a588d3e6c6482c4d150 action, view and service so managers can start source synchronization from the web ui Closes #5474286 diff -r 282880f81311 -r ef1cfc80d51c server/test/unittest_migractions.py --- a/server/test/unittest_migractions.py Mon Nov 30 14:54:30 2015 +0100 +++ b/server/test/unittest_migractions.py Wed Dec 09 16:15:00 2015 +0100 @@ -526,12 +526,12 @@ # remaining orphan rql expr which should be deleted at commit (composite relation) # unattached expressions -> pending deletion on commit self.assertEqual(cnx.execute('Any COUNT(X) WHERE X is RQLExpression, X exprtype "ERQLExpression",' - 'NOT ET1 read_permission X, NOT ET2 add_permission X, ' - 'NOT ET3 delete_permission X, NOT ET4 update_permission X')[0][0], + 'NOT ET1 read_permission X, NOT ET2 add_permission X, ' + 'NOT ET3 delete_permission X, NOT ET4 update_permission X')[0][0], 7) self.assertEqual(cnx.execute('Any COUNT(X) WHERE X is RQLExpression, X exprtype "RRQLExpression",' - 'NOT ET1 read_permission X, NOT ET2 add_permission X, ' - 'NOT ET3 delete_permission X, NOT ET4 update_permission X')[0][0], + 'NOT ET1 read_permission X, NOT ET2 add_permission X, ' + 'NOT ET3 delete_permission X, NOT ET4 update_permission X')[0][0], 2) # finally self.assertEqual(cnx.execute('Any COUNT(X) WHERE X is RQLExpression')[0][0], diff -r 282880f81311 -r ef1cfc80d51c sobjects/services.py --- a/sobjects/services.py Mon Nov 30 14:54:30 2015 +0100 +++ b/sobjects/services.py Wed Dec 09 16:15:00 2015 +0100 @@ -22,6 +22,7 @@ from six import text_type from yams.schema import role_name + from cubicweb import ValidationError from cubicweb.server import Service from cubicweb.predicates import match_user_groups, match_kwargs @@ -60,6 +61,7 @@ results['threads'] = [t.name for t in threading.enumerate()] return results + class GcStatsService(Service): """Return a dictionary containing some statistics about the repository resources usage. @@ -156,3 +158,17 @@ 'WHERE U login %(login)s', d, build_descr=False) return user + + +class SourceSynchronizationService(Service): + """Force synchronization of a datafeed source""" + __regid__ = 'source-sync' + __select__ = Service.__select__ & match_user_groups('managers') + + def call(self, source_eid): + source_entity = self._cw.entity_from_eid(source_eid) + repo = self._cw.repo # Service are repo side only. + with repo.internal_cnx() as cnx: + source = repo.sources_by_uri[source_entity.name] + source.pull_data(cnx) + diff -r 282880f81311 -r ef1cfc80d51c web/views/cwsources.py --- a/web/views/cwsources.py Mon Nov 30 14:54:30 2015 +0100 +++ b/web/views/cwsources.py Wed Dec 09 16:15:00 2015 +0100 @@ -33,10 +33,10 @@ from cubicweb import Unauthorized, tags from cubicweb.utils import make_uid from cubicweb.predicates import (is_instance, score_entity, has_related_entities, - match_user_groups, match_kwargs, match_view) + match_user_groups, match_kwargs, match_view, one_line_rset) from cubicweb.view import EntityView, StartupView from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, display_name -from cubicweb.web import formwidgets as wdgs, facet +from cubicweb.web import Redirect, formwidgets as wdgs, facet, action from cubicweb.web.views import add_etype_button from cubicweb.web.views import (uicfg, tabs, actions, ibreadcrumbs, navigation, tableview, pyviews) @@ -226,6 +226,36 @@ layout_args = {'display_filter': 'top'} +class CWSourceSyncAction(action.Action): + __regid__ = 'cw.source-sync' + __select__ = (action.Action.__select__ & match_user_groups('managers') + & one_line_rset() & is_instance('CWSource') + & score_entity(lambda x: x.name != 'system')) + + title = _('synchronize') + category = 'mainactions' + order = 20 + + def url(self): + entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) + return entity.absolute_url(vid=self.__regid__) + + +class CWSourceSyncView(EntityView): + __regid__ = 'cw.source-sync' + __select__ = (match_user_groups('managers') + & one_line_rset() & is_instance('CWSource') + & score_entity(lambda x: x.name != 'system')) + + title = _('synchronize') + + def entity_call(self, entity): + self._cw.call_service('source-sync', source_eid=entity.eid) + msg = self._cw._('Source has been synchronized') + url = entity.absolute_url(tab='cwsource-imports', __message=msg) + raise Redirect(url) + + # sources management view ######################################################