예제 #1
0
 def _process(self, url):
     if editing_settings.get(self.event, 'service_url'):
         raise BadRequest('Service URL already set')
     url = url.rstrip('/')
     info = check_service_url(url)
     if info['error'] is not None:
         abort(422, messages={'url': [info['error']]})
     if not editing_settings.get(self.event, 'service_event_identifier'):
         editing_settings.set(self.event, 'service_event_identifier',
                              make_event_identifier(self.event))
     editing_settings.set_multi(self.event, {
         'service_url': url,
         'service_token': unicode(uuid4()),
     })
     # we need to commit the token so the service can already use it when processing
     # the enabled event in case it wants to set up tags etc
     db.session.commit()
     try:
         service_handle_enabled(self.event)
     except ServiceRequestFailed as exc:
         editing_settings.delete(self.event, 'service_url', 'service_token')
         db.session.commit()
         raise ServiceUnavailable(
             _('Could not register event with service: {}').format(exc))
     except Exception:
         editing_settings.delete(self.event, 'service_url', 'service_token')
         db.session.commit()
         raise
     return '', 204
예제 #2
0
파일: service.py 프로젝트: javfg/indico
 def _process(self, force):
     if not editing_settings.get(self.event, 'service_url'):
         raise BadRequest('Service URL not set')
     status = service_get_status(self.event)
     notify_service = True
     if status['error']:
         if not force:
             # this only happens if the service went down between loading
             # the page and sending the disconnect request
             raise BadRequest('Cannot disconnect service')
         notify_service = False
     elif not status['status']['can_disconnect']:
         raise BadRequest('Cannot disconnect service')
     if notify_service:
         try:
             service_handle_disconnected(self.event)
         except ServiceRequestFailed as exc:
             raise ServiceUnavailable(_('Could not disconnect event from service: {}').format(exc))
     editing_settings.delete(self.event, 'service_url', 'service_token')
     return '', 204