def siteadmin_delete(site_id, admin_id): """ Delete a site_admin. """ siteobj = mmlib.get_site(SESSION, site_id) if siteobj is None: flask.abort(404, 'Site not found') siteadminobj = mmlib.get_siteadmin(SESSION, admin_id) if siteadminobj is None: flask.abort(404, 'Site Admin not found') if siteadminobj not in siteobj.admins: flask.abort(404, 'Site Admin not related to this Site') if len(siteobj.admins) <= 1: flask.flash('There is only one admin set, you cannot delete it.', 'error') return flask.redirect(flask.url_for('site_view', site_id=site_id)) SESSION.delete(siteadminobj) try: SESSION.commit() flask.flash('Site Admin deleted') except SQLAlchemyError as err: SESSION.rollback() flask.flash('Could not delete Site Admin', 'error') APP.logger.debug('Could not delete Site Admin') APP.logger.exception(err) return flask.redirect(flask.url_for('site_view', site_id=site_id))
def siteadmin_delete(site_id, admin_id): """ Delete a site_admin. """ siteobj = mmlib.get_site(SESSION, site_id) if siteobj is None: flask.abort(404, 'Site not found') siteadminobj = mmlib.get_siteadmin(SESSION, admin_id) if siteadminobj is None: flask.abort(404, 'Site Admin not found') if siteadminobj not in siteobj.admins: flask.abort(404, 'Site Admin not related to this Site') if len(siteobj.admins) <= 1: flask.flash( 'There is only one admin set, you cannot delete it.', 'error') return flask.redirect(flask.url_for('site_view', site_id=site_id)) SESSION.delete(siteadminobj) try: SESSION.commit() flask.flash('Site Admin deleted') except SQLAlchemyError as err: SESSION.rollback() flask.flash('Could not delete Site Admin', 'error') APP.logger.debug('Could not delete Site Admin') APP.logger.exception(err) return flask.redirect(flask.url_for('site_view', site_id=site_id))
def siteadmin_delete(site_id, admin_id): """ Delete a site_admin. """ form = forms.ConfirmationForm() if form.validate_on_submit(): 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') siteadminobj = mmlib.get_siteadmin(SESSION, admin_id) if siteadminobj is None: flask.abort(404, 'Site Admin not found') if siteadminobj not in siteobj.admins: flask.abort(404, 'Site Admin not related to this Site') if len(siteobj.admins) <= 1: flask.flash('There is only one admin set, you cannot delete it.', 'error') return flask.redirect(flask.url_for('site_view', site_id=site_id)) SESSION.delete(siteadminobj) try: SESSION.commit() flask.flash('Site Admin deleted') except SQLAlchemyError as err: # pragma: no cover # We check everything before deleting so the only error we could # run in is DB server related, and that we can't fake in our # tests SESSION.rollback() flask.flash('Could not delete Site Admin', 'error') APP.logger.debug('Could not delete Site Admin') APP.logger.exception(err) return flask.redirect(flask.url_for('site_view', site_id=site_id))
def siteadmin_delete(site_id, admin_id): """ Delete a site_admin. """ form = forms.ConfirmationForm() if form.validate_on_submit(): 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') siteadminobj = mmlib.get_siteadmin(SESSION, admin_id) if siteadminobj is None: flask.abort(404, 'Site Admin not found') if siteadminobj not in siteobj.admins: flask.abort(404, 'Site Admin not related to this Site') if len(siteobj.admins) <= 1: flask.flash( 'There is only one admin set, you cannot delete it.', 'error') return flask.redirect(flask.url_for('site_view', site_id=site_id)) SESSION.delete(siteadminobj) try: SESSION.commit() flask.flash('Site Admin deleted') except SQLAlchemyError as err: # pragma: no cover # We check everything before deleting so the only error we could # run in is DB server related, and that we can't fake in our # tests SESSION.rollback() flask.flash('Could not delete Site Admin', 'error') APP.logger.debug('Could not delete Site Admin') APP.logger.exception(err) return flask.redirect(flask.url_for('site_view', site_id=site_id))