Ejemplo n.º 1
0
def create_site_admin(session):
    ''' Create some site admins to play with for the tests
    '''
    item = model.SiteAdmin(
        username='******',
        site_id=1,
    )
    session.add(item)
    item = model.SiteAdmin(
        username='******',
        site_id=1,
    )
    session.add(item)

    item = model.SiteAdmin(
        username='******',
        site_id=2,
    )
    session.add(item)
    item = model.SiteAdmin(
        username='******',
        site_id=2,
    )
    session.add(item)

    item = model.SiteAdmin(
        username='******',
        site_id=3,
    )
    session.add(item)

    session.commit()
Ejemplo n.º 2
0
def siteadmin_new(site_id):
    """ Create a new site_admin.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

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

    form = forms.LostPasswordForm()
    if form.validate_on_submit():
        site_admin = model.SiteAdmin()
        SESSION.add(site_admin)
        site_admin.site_id = siteobj.id
        form.populate_obj(obj=site_admin)

        try:
            SESSION.flush()
            flask.flash('Site Admin added')
        except SQLAlchemyError as err:
            SESSION.rollback()
            flask.flash('Could not add Site Admin')
            APP.logger.debug('Could not add Site Admin')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    return flask.render_template(
        'site_admin_new.html',
        form=form,
        site=siteobj,
    )
Ejemplo n.º 3
0
def siteadmin_new(site_id):
    """ Create a new site_admin.
    """
    siteobj = mmlib.get_site(SESSION, site_id)

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

    form = login_forms.LostPasswordForm()
    if form.validate_on_submit():
        site_admin = model.SiteAdmin()
        SESSION.add(site_admin)
        site_admin.site_id = siteobj.id
        form.populate_obj(obj=site_admin)

        try:
            SESSION.flush()
            flask.flash('Site Admin 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 add Site Admin')
            APP.logger.debug('Could not add Site Admin')
            APP.logger.exception(err)

        SESSION.commit()
        return flask.redirect(flask.url_for('site_view', site_id=site_id))

    return flask.render_template(
        'site_admin_new.html',
        form=form,
        site=siteobj,
    )
Ejemplo n.º 4
0
def add_admin_to_site(session, site, admin):
    ''' Add an admin to the specified site.

    :arg session: the session with which to connect to the database.

    '''
    query = session.query(
        model.SiteAdmin
    ).filter(
        model.SiteAdmin.site_id == site_id
    )

    admins = [sa.username for sa in query.all()]

    if admin in admins:
        return '%s was already listed as an admin' % admin
    else:
        sa = model.SiteAdmin(site_id=site_id, username=admin)
        session.add(sa)
        session.flush()
        return '%s added as an admin' % admin