Exemple #1
0
def site_view(site_id):
    """ View information about a given site.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = forms.AddSiteForm(obj=siteobj)
    if form.validate_on_submit():
        obj = form.populate_obj(obj=siteobj)

        try:
            SESSION.flush()
            flask.flash('Site Updated')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code check before adding the
            # new SiteAdmin and therefore the only situation where it could
            # fail is a failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update the Site')
            APP.logger.debug('Could not update the Site')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site.html',
        site=siteobj,
        form=form,
    )
Exemple #2
0
def site_view(site_id):
    """ View information about a given site.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    if not (is_site_admin(flask.g.fas_user, siteobj)
            or is_mirrormanager_admin(flask.g.fas_user)):
        flask.abort(403, 'Access denied')

    form = forms.AddSiteForm(obj=siteobj)
    if form.validate_on_submit():
        admin_active = siteobj.admin_active
        private = siteobj.private
        obj = form.populate_obj(obj=siteobj)

        # If the user is *not* an admin, keep the current admin_active flag
        if not is_mirrormanager_admin(flask.g.fas_user):
            siteobj.admin_active = admin_active

        # If the private flag has been changed, invalidate mirrors
        if siteobj.private != private:
            for host in siteobj.hosts:
                host.set_not_up2date(SESSION)

        try:
            SESSION.flush()
            flask.flash('Site Updated')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code check before adding the
            # new SiteAdmin and therefore the only situation where it could
            # fail is a failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not update the Site')
            APP.logger.debug('Could not update the Site')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site.html',
        site=siteobj,
        form=form,
    )
Exemple #3
0
def site_new():
    """ Create a new site.
    """
    form = forms.AddSiteForm()
    if form.validate_on_submit():
        site = model.Site()
        SESSION.add(site)
        form.populate_obj(obj=site)
        site.admin_active = True
        site.created_by = flask.g.fas_user.username
        if site.org_url.endswith('/'):
            site.org_url = site.org_url[:-1]

        try:
            SESSION.flush()
            flask.flash('Site added')
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this as there is no unique constraint in the
            # Site table. So the only situation where it could fail is a
            # failure at the DB server level itself.
            SESSION.rollback()
            flask.flash('Could not create the new site')
            APP.logger.debug('Could not create the new site')
            APP.logger.exception(err)
            return flask.redirect(flask.url_for('index'))

        try:
            msg = mmlib.add_admin_to_site(
                SESSION, site, flask.g.fas_user.username)
            flask.flash(msg)
        except SQLAlchemyError as err:  # pragma: no cover
            # We cannot check this because the code check before adding the
            # new SiteAdmin and therefore the only situation where it could
            # fail is a failure at the DB server level itself.
            SESSION.rollback()
            APP.logger.debug(
                'Could not add admin "%s" to site "%s"' % (
                    flask.g.fas_user.username, site))
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site_new.html',
        form=form,
    )
def site_view(site_id):
    """ View information about a given site.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

    if siteobj is None:
        flask.abort(404, 'Site not found')

    form = forms.AddSiteForm(obj=siteobj)
    if form.validate_on_submit():
        obj = form.populate_obj(obj=siteobj)
        SESSION.commit()
        flask.flash('Site Updated')
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site.html',
        site=siteobj,
        form=form,
    )
def site_new():
    """ Create a new site.
    """
    form = forms.AddSiteForm()
    if form.validate_on_submit():
        site = model.Site()
        SESSION.add(site)
        form.populate_obj(obj=site)
        site.created_by = flask.g.fas_user.username

        try:
            SESSION.flush()
            flask.flash('Site added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not create the new site')
            APP.logger.debug('Could not create the new site')
            APP.logger.exception(err)
            return flask.redirect(flask.url_for('index'))

        try:
            msg = add_admin_to_site(SESSION, site, flask.g.fas_user.username)
            fask.flash(msg)
        except SQLAlchemyError as err:
            SESSION.rollback()
            APP.logger.debug('Could not add admin "%s" to site "%s"' %
                             (flask.g.fas_user.username, site))
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('index'))

    return flask.render_template(
        'site_new.html',
        form=form,
    )