Beispiel #1
0
    def _process_POST(self):
        name = request.form.get('contact_name',
                                cephalopod_settings.get('contact_name'))
        email = request.form.get('contact_email',
                                 cephalopod_settings.get('contact_email'))
        enabled = request.form.get('joined', False)
        uuid = cephalopod_settings.get('uuid')
        try:
            if not enabled:
                unregister_instance()
            elif enabled and uuid:
                sync_instance(name, email)
            elif enabled and not uuid:
                register_instance(name, email)
        except HTTPError as err:
            flash(
                _("Operation failed, the community hub returned: {err.message}"
                  ).format(err=err), 'error')
        except Timeout:
            flash(_("The operation timed-out. Please try again in a while."),
                  'error')
        except RequestException as err:
            flash(
                _("Unexpected exception while contacting the Community Hub: {err.message}"
                  ).format(err=err))

        return redirect(url_for('.index'))
Beispiel #2
0
def sync_instance(contact, email):
    contact = contact or cephalopod_settings.get('contact_name')
    email = email or cephalopod_settings.get('contact_email')
    # registration needed if the instance does not have a uuid
    if not cephalopod_settings.get('uuid'):
        logger.warning(
            'unable to synchronize: missing uuid, registering the server instead'
        )
        register_instance(contact, email)
        return

    payload = {
        'enabled': True,
        'url': config.BASE_URL,
        'contact': contact,
        'email': email,
        'organization': core_settings.get('site_organization')
    }
    url = url_join(_get_url(), cephalopod_settings.get('uuid'))
    response = requests.patch(url,
                              data=json.dumps(payload),
                              headers=HEADERS,
                              timeout=TIMEOUT,
                              verify=(not config.DEBUG))
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code == 404:
            logger.warning(
                'unable to synchronize: the server was not registered, registering the server now'
            )
            register_instance(contact, email)
        else:
            logger.error(
                'failed to synchronize the server with the community hub, got: %s',
                err)
            raise
    except Timeout:
        logger.error(
            'failed to synchronize: timeout while contacting the community hub'
        )
        raise
    except RequestException as err:
        logger.error(
            'unexpected exception while synchronizing the server with the Community Hub: %s',
            err)
        raise
    else:
        cephalopod_settings.set_multi({
            'joined': True,
            'contact_name': payload['contact'],
            'contact_email': payload['email']
        })
        logger.info(
            'successfully synchronized the server with the community hub')
Beispiel #3
0
    def _get_cephalopod_data(self):
        if not cephalopod_settings.get('joined'):
            return None, {'enabled': False}

        url = url_join(Config.getInstance().getTrackerURL(), 'api/instance/{}'.format(cephalopod_settings.get('uuid')))
        data = {'enabled': cephalopod_settings.get('joined'),
                'contact': cephalopod_settings.get('contact_name'),
                'email': cephalopod_settings.get('contact_email'),
                'url': Config.getInstance().getBaseURL(),
                'organisation': core_settings.get('site_organization')}
        return url, data
Beispiel #4
0
    def _get_cephalopod_data(self):
        if not cephalopod_settings.get('joined'):
            return None, {'enabled': False}

        url = url_join(config.COMMUNITY_HUB_URL,
                       'api/instance/{}'.format(cephalopod_settings.get('uuid')))
        data = {'enabled': cephalopod_settings.get('joined'),
                'contact': cephalopod_settings.get('contact_name'),
                'email': cephalopod_settings.get('contact_email'),
                'url': config.BASE_URL,
                'organization': core_settings.get('site_organization')}
        return url, data
Beispiel #5
0
    def _get_cephalopod_data(self):
        if not cephalopod_settings.get('joined'):
            return None, {'enabled': False}

        url = url_join(config.COMMUNITY_HUB_URL,
                       'api/instance/{}'.format(cephalopod_settings.get('uuid')))
        data = {'enabled': cephalopod_settings.get('joined'),
                'contact': cephalopod_settings.get('contact_name'),
                'email': cephalopod_settings.get('contact_email'),
                'url': config.BASE_URL,
                'organization': core_settings.get('site_organization')}
        return url, data
Beispiel #6
0
    def _process_form(self, form):
        name = form.contact_name.data
        email = form.contact_email.data
        enabled = form.joined.data
        uuid = cephalopod_settings.get('uuid')
        try:
            if not enabled:
                unregister_instance()
            elif enabled and uuid:
                sync_instance(name, email)
            elif enabled and not uuid:
                register_instance(name, email)
        except HTTPError as err:
            flash(
                _('Operation failed, the community hub returned: {err}').
                format(err=err), 'error')
        except Timeout:
            flash(_('The operation timed-out. Please try again in a while.'),
                  'error')
        except RequestException as err:
            flash(
                _('Unexpected exception while contacting the Community Hub: {err}'
                  ).format(err=err))

        return redirect(url_for('.index'))
Beispiel #7
0
def unregister_instance():
    payload = {'enabled': False}
    url = url_join(_get_url(), cephalopod_settings.get('uuid'))
    response = requests.patch(url,
                              data=json.dumps(payload),
                              headers=HEADERS,
                              timeout=TIMEOUT,
                              verify=(not config.DEBUG))
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code != 404:
            logger.error(
                'failed to unregister the server to the community hub, got: %s',
                err)
            raise
    except Timeout:
        logger.error(
            'failed to unregister: timeout while contacting the community hub')
        raise
    except RequestException as err:
        logger.error(
            'unexpected exception while unregistering the server with the Community Hub: %s',
            err)
        raise
    cephalopod_settings.set('joined', False)
    logger.info('successfully unregistered the server from the community hub')
Beispiel #8
0
 def _process(self):
     form = CephalopodForm(obj=FormDefaults(**cephalopod_settings.get_all()))
     if form.validate_on_submit():
         return self._process_form(form)
     hub_url = url_join(config.COMMUNITY_HUB_URL, 'api/instance/{}'.format(cephalopod_settings.get('uuid')))
     cephalopod_settings.set('show_migration_message', False)
     return WPCephalopod.render_template('cephalopod.html', 'cephalopod',
                                         affiliation=core_settings.get('site_organization'),
                                         enabled=cephalopod_settings.get('joined'),
                                         form=form,
                                         indico_version=indico.__version__,
                                         instance_url=config.BASE_URL,
                                         language=config.DEFAULT_LOCALE,
                                         operating_system=get_os(),
                                         postgres_version=get_postgres_version(),
                                         python_version=platform.python_version(),
                                         hub_url=hub_url)
Beispiel #9
0
    def _process(self):
        if not cephalopod_settings.get('joined'):
            flash(_("Synchronization is not possible if you don't join the community first."),
                  'error')
        else:
            contact_name = cephalopod_settings.get('contact_name')
            contact_email = cephalopod_settings.get('contact_email')
            try:
                sync_instance(contact_name, contact_email)
            except HTTPError as err:
                flash(_('Synchronization failed, the community hub returned: {err}').format(err=err),
                      'error')
            except Timeout:
                flash(_('Synchronization timed-out. Please try again in a while.'), 'error')
            except RequestException as err:
                flash(_('Unexpected exception while contacting the Community Hub: {err}').format(err=err))

            return redirect(url_for('.index'))
Beispiel #10
0
 def _process(self):
     form = CephalopodForm(obj=FormDefaults(**cephalopod_settings.get_all()))
     if form.validate_on_submit():
         return self._process_form(form)
     hub_url = url_join(config.COMMUNITY_HUB_URL, 'api/instance/{}'.format(cephalopod_settings.get('uuid')))
     cephalopod_settings.set('show_migration_message', False)
     return WPCephalopod.render_template('cephalopod.html', 'cephalopod',
                                         affiliation=core_settings.get('site_organization'),
                                         enabled=cephalopod_settings.get('joined'),
                                         form=form,
                                         indico_version=indico.__version__,
                                         instance_url=config.BASE_URL,
                                         language=config.DEFAULT_LOCALE,
                                         operating_system=get_os(),
                                         postgres_version=get_postgres_version(),
                                         python_version=platform.python_version(),
                                         hub_url=hub_url,
                                         show_local_warning=(config.DEBUG or is_private_url(request.url_root)))
Beispiel #11
0
    def _process(self):
        if not cephalopod_settings.get('joined'):
            flash(_("Synchronization is not possible if you don't join the community first."),
                  'error')
        else:
            contact_name = cephalopod_settings.get('contact_name')
            contact_email = cephalopod_settings.get('contact_email')
            try:
                sync_instance(contact_name, contact_email)
            except HTTPError as err:
                flash(_("Synchronization failed, the community hub returned: {err.message}").format(err=err),
                      'error')
            except Timeout:
                flash(_("Synchronization timed-out. Please try again in a while."), 'error')
            except RequestException as err:
                flash(_("Unexpected exception while contacting the Community Hub: {err.message}").format(err=err))

            return redirect(url_for('.index'))
Beispiel #12
0
def sync_instance(contact, email):
    contact = contact or cephalopod_settings.get('contact_name')
    email = email or cephalopod_settings.get('contact_email')
    # registration needed if the instance does not have a uuid
    if not cephalopod_settings.get('uuid'):
        logger.warn('unable to synchronize: missing uuid, registering the server instead')
        register_instance(contact, email)
        return

    payload = {'enabled': True,
               'url': config.BASE_URL,
               'contact': contact,
               'email': email,
               'organization': core_settings.get('site_organization')}
    url = url_join(_get_url(), cephalopod_settings.get('uuid'))
    response = requests.patch(url, data=json.dumps(payload), headers=HEADERS, timeout=TIMEOUT,
                              verify=(not config.DEBUG))
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code == 404:
            logger.warn('unable to synchronize: the server was not registered, registering the server now')
            register_instance(contact, email)
        else:
            logger.error('failed to synchronize the server with the community hub, got: %s', err.message)
            raise
    except Timeout:
        logger.error('failed to synchronize: timeout while contacting the community hub')
        raise
    except RequestException as err:
        logger.error('unexpected exception while synchronizing the server with the Community Hub: %s', err.message)
        raise
    else:
        cephalopod_settings.set_multi({
            'joined': True,
            'contact_name': payload['contact'],
            'contact_email': payload['email']})
        logger.info('successfully synchronized the server with the community hub')
Beispiel #13
0
    def _process_GET(self):
        defaults = FormDefaults(**cephalopod_settings.get_all())
        form = CephalopodForm(request.form, obj=defaults)

        enabled = cephalopod_settings.get('joined')
        config = Config.getInstance()
        instance_url = config.getBaseURL()
        language = config.getDefaultLocale()
        tracker_url = urljoin(
            config.getTrackerURL(),
            'api/instance/{}'.format(cephalopod_settings.get('uuid')))
        return WPCephalopod.render_template(
            'cephalopod.html',
            affiliation=core_settings.get('site_organization'),
            enabled=enabled,
            form=form,
            indico_version=indico.__version__,
            instance_url=instance_url,
            language=language,
            operating_system=get_os(),
            postgres_version=get_postgres_version(),
            python_version=platform.python_version(),
            tracker_url=tracker_url)
Beispiel #14
0
 def _process(self):
     form = CephalopodForm(obj=FormDefaults(
         **cephalopod_settings.get_all()))
     if form.validate_on_submit():
         return self._process_form(form)
     config = Config.getInstance()
     hub_url = url_join(
         config.getCommunityHubURL(),
         'api/instance/{}'.format(cephalopod_settings.get('uuid')))
     cephalopod_settings.set('show_migration_message', False)
     return WPCephalopod.render_template(
         'cephalopod.html',
         'cephalopod',
         affiliation=core_settings.get('site_organization'),
         enabled=cephalopod_settings.get('joined'),
         form=form,
         indico_version=indico.__version__,
         instance_url=config.getBaseURL(),
         language=config.getDefaultLocale(),
         operating_system=get_os(),
         postgres_version=get_postgres_version(),
         python_version=platform.python_version(),
         hub_url=hub_url)
Beispiel #15
0
    def _process(self):
        proxy = PrefixSettingsProxy({'core': core_settings, 'social': social_settings})
        form = SettingsForm(obj=FormDefaults(**proxy.get_all()))
        if form.validate_on_submit():
            proxy.set_multi(form.data)
            flash(_('Settings have been saved'), 'success')
            return redirect(url_for('.settings'))

        cephalopod_url, cephalopod_data = self._get_cephalopod_data()
        show_migration_message = cephalopod_settings.get('show_migration_message')
        return WPSettings.render_template('settings.html', 'settings',
                                          form=form,
                                          core_settings=core_settings.get_all(),
                                          social_settings=social_settings.get_all(),
                                          cephalopod_url=cephalopod_url,
                                          cephalopod_data=cephalopod_data,
                                          show_migration_message=show_migration_message)
Beispiel #16
0
    def _process(self):
        proxy = PrefixSettingsProxy({'core': core_settings, 'social': social_settings})
        form = SettingsForm(obj=FormDefaults(**proxy.get_all()))
        if form.validate_on_submit():
            proxy.set_multi(form.data)
            flash(_('Settings have been saved'), 'success')
            return redirect(url_for('.settings'))

        cephalopod_url, cephalopod_data = self._get_cephalopod_data()
        show_migration_message = cephalopod_settings.get('show_migration_message')
        return WPSettings.render_template('admin/settings.html', 'settings',
                                          form=form,
                                          core_settings=core_settings.get_all(),
                                          social_settings=social_settings.get_all(),
                                          cephalopod_url=cephalopod_url,
                                          cephalopod_data=cephalopod_data,
                                          show_migration_message=show_migration_message)
Beispiel #17
0
def unregister_instance():
    payload = {'enabled': False}
    url = url_join(_get_url(), cephalopod_settings.get('uuid'))
    response = requests.patch(url, data=json.dumps(payload), headers=HEADERS, timeout=TIMEOUT,
                              verify=(not config.DEBUG))
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code != 404:
            logger.error('failed to unregister the server to the community hub, got: %s', err.message)
            raise
    except Timeout:
        logger.error('failed to unregister: timeout while contacting the community hub')
        raise
    except RequestException as err:
        logger.error('unexpected exception while unregistering the server with the Community Hub: %s', err.message)
        raise
    cephalopod_settings.set('joined', False)
    logger.info('successfully unregistered the server from the community hub')
Beispiel #18
0
    def _process_form(self, form):
        name = form.contact_name.data
        email = form.contact_email.data
        enabled = form.joined.data
        uuid = cephalopod_settings.get('uuid')
        try:
            if not enabled:
                unregister_instance()
            elif enabled and uuid:
                sync_instance(name, email)
            elif enabled and not uuid:
                register_instance(name, email)
        except HTTPError as err:
            flash(_("Operation failed, the community hub returned: {err.message}").format(err=err), 'error')
        except Timeout:
            flash(_("The operation timed-out. Please try again in a while."), 'error')
        except RequestException as err:
            flash(_("Unexpected exception while contacting the Community Hub: {err.message}").format(err=err))

        return redirect(url_for('.index'))