def delete_distro(distro_name): """ Delete a distro """ distro = models.Distro.by_name(Session, distro_name) if not distro: flask.abort(404) if not is_admin(): flask.abort(401) form = anitya.forms.ConfirmationForm() if form.validate_on_submit(): utilities.log( Session, distro=distro.__json__(), topic="distro.remove", message=dict(agent=flask.g.user.username, distro=distro.name), ) Session.delete(distro) Session.commit() flask.flash("Distro %s has been removed" % distro_name) return flask.redirect(flask.url_for("anitya_ui.distros")) return flask.render_template( "distro_delete.html", current="distros", distro=distro, form=form )
def delete_distro(distro_name): """ Delete a distro """ distro = models.Distro.by_name(Session, distro_name) if not distro: flask.abort(404) if not is_admin(): flask.abort(401) form = anitya.forms.ConfirmationForm() if form.validate_on_submit(): utilities.log( Session, distro=distro.__json__(), topic="distro.remove", message=dict(agent=flask.g.user.username, distro=distro.name), ) Session.delete(distro) Session.commit() flask.flash("Distro %s has been removed" % distro_name) return flask.redirect(flask.url_for("anitya_ui.distros")) return flask.render_template("distro_delete.html", current="distros", distro=distro, form=form)
def integrity_error_handler(error): """ Flask error handler for unhandled IntegrityErrors. Args: error (IntegrityError): The exception to be handled. Returns: tuple: A tuple of (message, HTTP error code). """ # Because social auth provides the route and raises the exception, this is # the simplest way to turn the error into a nicely formatted error message # for the user. if 'email' in error.params: Session.rollback() other_user = models.User.query.filter_by(email=error.params['email']).one() try: social_auth_user = other_user.social_auth.filter_by(user_id=other_user.id).one() msg = ("Error: There's already an account associated with your email, " "authenticate with {}.".format(social_auth_user.provider)) return msg, 400 # This error happens only if there is account without provider info except NoResultFound: Session.delete(other_user) Session.commit() msg = ( "Error: There was already an existing account with missing provider. " "So we removed it. " "Please try to log in again.") return msg, 500 return 'The server encountered an unexpected error', 500
def delete_project_version(project_id, version): project = models.Project.get(Session, project_id) if not project: flask.abort(404) version_obj = None for vers in project.versions_obj: if version == vers.version: version_obj = vers break if version_obj is None: flask.abort( 404, "Version %s not found for project %s" % (version, project.name)) if not is_admin(): flask.abort(401) form = anitya.forms.ConfirmationForm() confirm = flask.request.form.get("confirm", False) if form.validate_on_submit(): if confirm: utilities.log( Session, project=project.__json__(), topic="project.version.remove", message=dict(agent=flask.g.user.username, project=project.name, version=version), ) # Delete the record of the version for this project Session.delete(version_obj) # Adjust the latest_version if needed sorted_versions = project.get_sorted_version_objects() if len(sorted_versions ) > 1 and sorted_versions[0].version == version: project.latest_version = sorted_versions[1].parse() Session.add(project) elif len(sorted_versions) == 1: project.latest_version = None Session.add(project) Session.commit() flask.flash("Version for %s has been removed" % version) return flask.redirect( flask.url_for("anitya_ui.project", project_id=project.id)) return flask.render_template( "version_delete.html", current="projects", project=project, version=version, form=form, )
def delete_token(token): """Delete the API token provided for current user.""" form = anitya.forms.TokenForm() if form.validate_on_submit(): t = models.ApiToken.query.filter_by(user=flask.g.user, token=token).first() if t is None: flask.abort(404) Session.delete(t) Session.commit() return flask.redirect(flask.url_for("anitya_ui.settings")) else: flask.abort(400)
def delete_project_version(project_id, version): project = models.Project.get(Session, project_id) if not project: flask.abort(404) version_obj = None for vers in project.versions_obj: if version == vers.version: version_obj = vers break if version_obj is None: flask.abort( 404, "Version %s not found for project %s" % (version, project.name) ) if not is_admin(): flask.abort(401) form = anitya.forms.ConfirmationForm() confirm = flask.request.form.get("confirm", False) if form.validate_on_submit(): if confirm: utilities.log( Session, project=project.__json__(), topic="project.version.remove", message=dict( agent=flask.g.user.username, project=project.name, version=version ), ) # Delete the record of the version for this project Session.delete(version_obj) # Adjust the latest_version if needed if project.latest_version == version: project.latest_version = None Session.add(project) Session.commit() flask.flash("Version for %s has been removed" % version) return flask.redirect(flask.url_for("anitya_ui.project", project_id=project.id)) return flask.render_template( "version_delete.html", current="projects", project=project, version=version, form=form, )
def delete_project_version(project_id, version): project = models.Project.get(Session, project_id) if not project: flask.abort(404) version_obj = None for vers in project.versions_obj: if version == vers.version: version_obj = vers break if version_obj is None: flask.abort( 404, 'Version %s not found for project %s' % (version, project.name)) if not is_admin(): flask.abort(401) form = anitya.forms.ConfirmationForm() confirm = flask.request.form.get('confirm', False) if form.validate_on_submit(): if confirm: utilities.log(Session, project=project.__json__(), topic='project.version.remove', message=dict( agent=flask.g.user.username, project=project.name, version=version, )) # Delete the record of the version for this project Session.delete(version_obj) # Adjust the latest_version if needed if project.latest_version == version: project.latest_version = None Session.add(project) Session.commit() flask.flash('Version for %s has been removed' % version) return flask.redirect( flask.url_for('anitya_ui.project', project_id=project.id)) return flask.render_template('version_delete.html', current='projects', project=project, version=version, form=form)
def delete_project_mapping(project_id, distro_name, pkg_name): project = models.Project.get(Session, project_id) if not project: flask.abort(404) distro = models.Distro.get(Session, distro_name) if not distro: flask.abort(404) package = models.Packages.get(Session, project.id, distro.name, pkg_name) if not package: flask.abort(404) if not is_admin(): flask.abort(401) form = anitya.forms.ConfirmationForm() confirm = flask.request.form.get("confirm", False) if form.validate_on_submit(): if confirm: utilities.log( Session, project=project.__json__(), topic="project.map.remove", message=dict( agent=flask.g.user.username, project=project.name, distro=distro.name, ), ) Session.delete(package) Session.commit() flask.flash("Mapping for %s has been removed" % project.name) return flask.redirect( flask.url_for("anitya_ui.project", project_id=project.id)) return flask.render_template( "regex_delete.html", current="projects", project=project, package=package, form=form, )
def delete_project_versions(project_id): """ Delete all versions on the project. """ project = models.Project.get(Session, project_id) if not project: flask.abort(404) if not is_admin(): flask.abort(401) form = anitya.forms.ConfirmationForm() confirm = flask.request.form.get("confirm", False) if form.validate_on_submit(): if confirm: for version in project.versions_obj: # Delete the record of the version for this project Session.delete(version) utilities.log( Session, project=project.__json__(), topic="project.version.remove", message=dict( agent=flask.g.user.username, project=project.name, version=str(version), ), ) project.latest_version = None project.latest_version_cursor = None Session.add(project) Session.commit() flask.flash("All versions were removed") return flask.redirect( flask.url_for("anitya_ui.project", project_id=project.id)) return flask.render_template( "project_versions_delete.html", current="projects", project=project, form=form, )
def delete_project_mapping(project_id, distro_name, pkg_name): project = models.Project.get(Session, project_id) if not project: flask.abort(404) distro = models.Distro.get(Session, distro_name) if not distro: flask.abort(404) package = models.Packages.get(Session, project.id, distro.name, pkg_name) if not package: flask.abort(404) if not is_admin(): flask.abort(401) form = anitya.forms.ConfirmationForm() confirm = flask.request.form.get("confirm", False) if form.validate_on_submit(): if confirm: utilities.log( Session, project=project.__json__(), topic="project.map.remove", message=dict( agent=flask.g.user.username, project=project.name, distro=distro.name, ), ) Session.delete(package) Session.commit() flask.flash("Mapping for %s has been removed" % project.name) return flask.redirect(flask.url_for("anitya_ui.project", project_id=project.id)) return flask.render_template( "regex_delete.html", current="projects", project=project, package=package, form=form, )
def delete_project(project_id): project = models.Project.get(Session, project_id) if not project: flask.abort(404) if not is_admin(): flask.abort(401) project_name = project.name form = anitya.forms.ConfirmationForm() confirm = flask.request.form.get("confirm", False) if form.validate_on_submit(): if confirm: utilities.log( Session, project=project.__json__(), topic="project.remove", message=dict(agent=flask.g.user.username, project=project.name), ) for version in project.versions_obj: Session.delete(version) Session.delete(project) Session.commit() flask.flash("Project %s has been removed" % project_name) return flask.redirect(flask.url_for("anitya_ui.projects")) else: return flask.redirect( flask.url_for("anitya_ui.project", project_id=project.id)) return flask.render_template("project_delete.html", current="projects", project=project, form=form)
def delete_project(project_id): project = models.Project.get(Session, project_id) if not project: flask.abort(404) if not is_admin(): flask.abort(401) project_name = project.name form = anitya.forms.ConfirmationForm() confirm = flask.request.form.get("confirm", False) if form.validate_on_submit(): if confirm: utilities.log( Session, project=project.__json__(), topic="project.remove", message=dict(agent=flask.g.user.username, project=project.name), ) for version in project.versions_obj: Session.delete(version) Session.delete(project) Session.commit() flask.flash("Project %s has been removed" % project_name) return flask.redirect(flask.url_for("anitya_ui.projects")) else: return flask.redirect( flask.url_for("anitya_ui.project", project_id=project.id) ) return flask.render_template( "project_delete.html", current="projects", project=project, form=form )
def integrity_error_handler(error): """ Flask error handler for unhandled IntegrityErrors. Args: error (IntegrityError): The exception to be handled. Returns: tuple: A tuple of (message, HTTP error code). """ # Because social auth provides the route and raises the exception, this is # the simplest way to turn the error into a nicely formatted error message # for the user. if "email" in error.params: Session.rollback() other_user = models.User.query.filter_by(email=error.params["email"]).one() try: social_auth_user = other_user.social_auth.filter_by( user_id=other_user.id ).one() msg = ( "Error: There's already an account associated with your email, " "authenticate with {}.".format(social_auth_user.provider) ) return msg, 400 # This error happens only if there is account without provider info except NoResultFound: Session.delete(other_user) Session.commit() msg = ( "Error: There was already an existing account with missing provider. " "So we removed it. " "Please try to log in again." ) return msg, 500 return "The server encountered an unexpected error", 500