def package_orphan(package, collection): ''' Gives the possibility to orphan or take a package. ''' packagename = package package = None try: package_acl = pkgdblib.get_acl_package(SESSION, packagename) package = pkgdblib.search_package(SESSION, packagename, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') for acl in package_acl: if acl.collection.branchname == collection: try: pkgdblib.update_pkg_poc( session=SESSION, pkg_name=package.name, pkg_branch=acl.collection.branchname, pkg_poc='orphan', user=flask.g.fas_user ) flask.flash( 'You are no longer point of contact on branch: %s' % collection) except pkgdblib.PkgdbException, err: flask.flash(str(err), 'error') SESSION.rollback() break
def package_anitya(namespace, package, full=True): """ Return information anitya integration about this package. """ if str(full).lower() in ['0', 'false']: full = False pkg = None try: pkg = pkgdblib.search_package( SESSION, namespace, package, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') url = '%s/api/project/%s/%s' % ( APP.config['PKGDB2_ANITYA_URL'], APP.config['PKGDB2_ANITYA_DISTRO'], package ) data = {} try: req = requests.get(url) if req.status_code != 200: raise pkgdblib.PkgdbException( 'Querying anitya returned a status %s' % req.status_code) else: data = req.json() except Exception, err: flask.flash(err.message, 'error') pass
def api_packager_list(pattern=None): ''' List packagers -------------- List packagers based on a pattern. If no pattern is provided, return all the packagers. :: /api/packagers/<pattern>/ /api/packagers/?pattern=<pattern> :kwarg pattern: String of the pattern to use to list find packagers. If no pattern is provided, it returns the list of all packagers. Sample response: :: /api/packagers/rem* { "output": "ok", "packagers": [ "remi" ] } /api/packagers/?pattern=pi* { "output": "ok", "packagers": [ "pilcher", "pingou" ] } ''' httpcode = 200 output = {} pattern = flask.request.args.get('pattern', pattern) or '*' if pattern: packagers = pkgdblib.search_packagers( SESSION, pattern=pattern, ) packagers = [pkg[0] for pkg in packagers] SESSION.commit() output['output'] = 'ok' output['packagers'] = packagers else: # pragma: no cover # In theory we can never get here output = {'output': 'notok', 'error': 'Invalid request'} httpcode = 500 jsonout = flask.jsonify(output) jsonout.status_code = httpcode return jsonout
def package_anitya(package, full=True): """ Return information anitya integration about this package. """ if str(full).lower() in ['0', 'false']: full = False pkg = None try: pkg = pkgdblib.search_package(SESSION, package, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') url = '%s/api/project/%s/%s' % ( APP.config['PKGDB2_ANITYA_URL'], APP.config['PKGDB2_ANITYA_DISTRO'], package ) req = requests.get(url) data = req.json() return flask.render_template( 'package_anitya.html', full=full, package=package, pkg=pkg, data=data, )
def collection_new(): ''' Page to create a new collection. ''' clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status'] form = pkgdb2.forms.AddCollectionForm(clt_status=clt_status) if form.validate_on_submit(): clt_name = form.collection_name.data clt_version = form.collection_version.data clt_status = form.collection_status.data clt_branchname = form.collection_branchname.data clt_disttag = form.collection_distTag.data clt_gitbranch = form.collection_git_branch_name.data clt_koji_name = form.collection_kojiname.data try: message = pkgdblib.add_collection( SESSION, clt_name=clt_name, clt_version=clt_version, clt_status=clt_status, clt_branchname=clt_branchname, clt_disttag=clt_disttag, clt_gitbranch=clt_gitbranch, clt_koji_name=clt_koji_name, user=flask.g.fas_user, ) SESSION.commit() flask.flash(message) return flask.redirect(flask.url_for('.list_collections')) # In theory we should never hit this except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'errors')
def api_package_retire(): ''' Retire packages --------------- Retire one or more packages. :: /api/package/retire/ Accept POST queries only. :arg pkgnames: Comma separated list of string of the packages name. :arg branches: Comma separated list of string of the branches name in which these packages will be retire. Sample response: :: { "output": "ok", "messages": ["user: $USER updated package: $PACKAGE status from: " "$PREVIOUS_STATUS to $NEW_STATUS on branch $BRANCH"] } { "output": "notok", "error": ["You are not allowed to retire the package: $PACKAGE " "on branch $BRANCH."] } ''' httpcode = 200 output = {} pkgnames = flask.request.form.getlist('pkgnames', None) branches = flask.request.form.getlist('branches', None) if pkgnames and branches: try: messages = [] for pkg_name, pkg_branch in itertools.product( pkgnames, branches): message = pkgdblib.update_pkg_status( SESSION, pkg_name=pkg_name, pkg_branch=pkg_branch, status='Retired', user=flask.g.fas_user, ) messages.append(message) SESSION.commit() output['output'] = 'ok' output['messages'] = messages except pkgdblib.PkgdbException, err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500
def watch_package(package): ''' Request watch* ACLs on a package. Anyone can request these ACLs, no need to be a packager. ''' try: pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.redirect( flask.url_for('.package_info', package=package)) pkg_acls = ['watchcommits', 'watchbugzilla'] pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings] try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): pkgdblib.set_acl_package( SESSION, pkg_name=package, pkg_branch=collec, pkg_user=flask.g.fas_user.username, acl=acl, status='Approved', user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') # Let's keep this in although we should never see it except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error')
def api_collection_status(collection): ''' Update collection status ------------------------ Update the status of collection. :: /api/collection/<collection branchname>/status/ Accepts POST query only. :arg branch: String of the collection branch name to change. :arg clt_status: String of the status to change the collection to Sample response: :: { "output": "ok", "messages": ["Collection updated to \"EOL\""] } { "output": "notok", "error": ["You are not allowed to edit collections"] } ''' httpcode = 200 output = {} clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status'] form = forms.CollectionStatusForm( csrf_enabled=False, clt_status=clt_status, ) if form.validate_on_submit(): clt_branchname = form.branch.data clt_status = form.clt_status.data if collection == clt_branchname: try: message = pkgdblib.update_collection_status( SESSION, clt_branchname, clt_status, user=flask.g.fas_user) SESSION.commit() output['output'] = 'ok' output['messages'] = [message] except pkgdblib.PkgdbException, err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500 else: output['output'] = 'notok' output['error'] = "You're trying to update the " \ "wrong collection" httpcode = 500
def pending_acl_deny(): ''' Deny all the pending acls for the user logged in. ''' form = pkgdb2.forms.ConfirmationForm() if form.validate_on_submit(): pending_acls = pkgdblib.get_pending_acl_user( SESSION, flask.g.fas_user.username) try: for acl in pending_acls: pkgdblib.set_acl_package( SESSION, namespace=acl['namespace'], pkg_name=acl['package'], pkg_branch=acl['collection'], pkg_user=acl['user'], acl=acl['acl'], status='Denied', user=flask.g.fas_user ) SESSION.commit() flask.flash('All ACLs denied') # Let's keep this in although we should never see it except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error')
def pending_acl_deny(): ''' Deny all the pending acls for the user logged in. ''' form = pkgdb2.forms.ConfirmationForm() if form.validate_on_submit(): pending_acls = pkgdblib.get_pending_acl_user(SESSION, flask.g.fas_user.username) try: for acl in pending_acls: pkgdblib.set_acl_package(SESSION, namespace=acl['namespace'], pkg_name=acl['package'], pkg_branch=acl['collection'], pkg_user=acl['user'], acl=acl['acl'], status='Denied', user=flask.g.fas_user) SESSION.commit() flask.flash('All ACLs denied') # Let's keep this in although we should never see it except PkgdbException as err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error') return flask.redirect(flask.url_for('.pending_acl'))
def admin_action_edit_status(action_id): """ Edit Admin Action status update """ admin_action = pkgdblib.get_admin_action(SESSION, action_id) if not admin_action: flask.flash("No action found with this identifier.", "errors") return flask.render_template("msg.html") action_status = pkgdblib.get_status(SESSION, "admin_status")["admin_status"] form = pkgdb2.forms.EditActionStatusForm(status=action_status, obj=admin_action) form.id.data = action_id if form.validate_on_submit(): try: message = pkgdblib.edit_action_status( SESSION, admin_action, action_status=form.status.data, user=flask.g.fas_user, message=form.message.data ) SESSION.commit() flask.flash(message) except pkgdblib.PkgdbException, err: # pragma: no cover # We can only reach here in two cases: # 1) the user is not an admin, but that's taken care of # by the decorator # 2) we have a SQLAlchemy problem when storing the info # in the DB which we cannot test SESSION.rollback() flask.flash(err, "errors") return flask.render_template("msg.html") return flask.redirect(flask.url_for(".admin_actions"))
def admin_add_namespace(): """ Add a new namespace """ form = pkgdb2.forms.NamespaceForm() if form.validate_on_submit(): try: message = pkgdblib.add_namespace( SESSION, form.namespace.data, user=flask.g.fas_user, ) SESSION.commit() flask.flash(message) except PkgdbException as err: # pragma: no cover # We can only reach here in two cases: # 1) the user is not an admin, but that's taken care of # by the decorator # 2) we have a SQLAlchemy problem when storing the info # in the DB which we cannot test flask.flash(err, 'errors') return flask.render_template('msg.html') return flask.redirect(flask.url_for('.admin_namespaces'))
def package_retire(package, collection): ''' Gives the possibility to orphan or take a package. ''' packagename = package package = None try: package_acl = pkgdblib.get_acl_package(SESSION, packagename) package = pkgdblib.search_package(SESSION, packagename, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') for acl in package_acl: if acl.collection.branchname == collection: if acl.point_of_contact == 'orphan': try: pkgdblib.update_pkg_status( session=SESSION, pkg_name=package.name, pkg_branch=acl.collection.branchname, status='Retired', user=flask.g.fas_user) flask.flash('This package has been retired on branch: %s' % collection) except pkgdblib.PkgdbException, err: flask.flash(str(err), 'error') SESSION.rollback() break else: flask.flash('This package has not been orphaned on ' 'branch: %s' % collection)
def package_retire(package, collection): ''' Gives the possibility to orphan or take a package. ''' packagename = package package = None try: package_acl = pkgdblib.get_acl_package(SESSION, packagename) package = pkgdblib.search_package(SESSION, packagename, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') for acl in package_acl: if acl.collection.branchname == collection: if acl.point_of_contact == 'orphan': try: pkgdblib.update_pkg_status( session=SESSION, pkg_name=package.name, pkg_branch=acl.collection.branchname, status='Retired', user=flask.g.fas_user ) flask.flash( 'This package has been retired on branch: %s' % collection) except pkgdblib.PkgdbException, err: flask.flash(str(err), 'error') SESSION.rollback() break else: flask.flash( 'This package has not been orphaned on ' 'branch: %s' % collection)
def package_orphan(package, collection): ''' Gives the possibility to orphan or take a package. ''' packagename = package package = None try: package_acl = pkgdblib.get_acl_package(SESSION, packagename) package = pkgdblib.search_package(SESSION, packagename, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') for acl in package_acl: if acl.collection.branchname == collection: try: pkgdblib.update_pkg_poc(session=SESSION, pkg_name=package.name, pkg_branch=acl.collection.branchname, pkg_poc='orphan', user=flask.g.fas_user) flask.flash( 'You are no longer point of contact on branch: %s' % collection) except pkgdblib.PkgdbException, err: flask.flash(str(err), 'error') SESSION.rollback() break
def watch_package(package): ''' Request watch* ACLs on a package. Anyone can request these ACLs, no need to be a packager. ''' try: pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.redirect(flask.url_for('.package_info', package=package)) pkg_acls = ['watchcommits', 'watchbugzilla'] pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings] try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): pkgdblib.set_acl_package( SESSION, pkg_name=package, pkg_branch=collec, pkg_user=flask.g.fas_user.username, acl=acl, status='Approved', user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') # Let's keep this in although we should never see it except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error')
def api_package_unretire(): ''' Unretire packages ----------------- Un-retire one or more packages. :: /api/package/unretire/ Accepts POST queries only. :arg pkgnames: Comma separated list of the packages names. :arg branches: Comma separated list of string of the branches names in which these packages will be un-deprecated. Sample response: :: { "output": "ok", "messages": ["user: $USER updated package: $PACKAGE status from: " "$PREVIOUS_STATUS to $NEW_STATUS on branch $BRANCH"] } { "output": "notok", "error": ["You are not allowed to update the status of " "the package: $PACKAGE on branch $BRANCH to $STATUS."] } ''' httpcode = 200 output = {} pkgnames = flask.request.form.getlist('pkgnames', None) branches = flask.request.form.getlist('branches', None) if pkgnames and branches: try: messages = [] for pkg_name, pkg_branch in itertools.product(pkgnames, branches): message = pkgdblib.update_pkg_status( SESSION, pkg_name=pkg_name, pkg_branch=pkg_branch, status='Approved', user=flask.g.fas_user, ) messages.append(message) SESSION.commit() output['output'] = 'ok' output['messages'] = messages except pkgdblib.PkgdbException, err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500
def api_package_orphan(): ''' Orphan package -------------- Orphan one or more packages. :: /api/package/orphan/ Accept POST queries only. :arg pkgnames: Comma separated list of string of the packages name. :arg branches: Comma separated list of string of the branches name in which these packages will be orphaned. Sample response: :: { "output": "ok", "messages": ["User: $USER changed poc of package: $PACKAGE from " "$PREVIOUS_POC to $NEW_POC on branch: $BRANCH"] } { "output": "notok", "error": ["You are not allowed to change the point of contact."] } ''' httpcode = 200 output = {} pkgnames = flask.request.form.getlist('pkgnames', None) branches = flask.request.form.getlist('branches', None) if pkgnames and branches: try: messages = [] for pkg_name, pkg_branch in itertools.product( pkgnames, branches): message = pkgdblib.update_pkg_poc( SESSION, pkg_name=pkg_name, pkg_branch=pkg_branch, pkg_poc='orphan', user=flask.g.fas_user, ) messages.append(message) SESSION.commit() output['output'] = 'ok' output['messages'] = messages except pkgdblib.PkgdbException, err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500
def package_anitya(package, full=True): """ Return information anitya integration about this package. """ if str(full).lower() in ['0', 'false']: full = False pkg = None try: pkg = pkgdblib.search_package(SESSION, package, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') url = '%s/api/project/%s/%s' % (APP.config['PKGDB2_ANITYA_URL'], APP.config['PKGDB2_ANITYA_DISTRO'], package) data = {} try: req = requests.get(url) if req.status_code != 200: raise pkgdblib.PkgdbException( 'Querying anitya returned a status %s' % req.status_code) else: data = req.json() except Exception, err: flask.flash(err.message, 'error') pass
def api_package_orphan(): ''' Orphan package -------------- Orphan one or more packages. :: /api/package/orphan/ Accept POST queries only. :arg pkgnames: Comma separated list of string of the packages name. :arg branches: Comma separated list of string of the branches name in which these packages will be orphaned. Sample response: :: { "output": "ok", "messages": ["User: $USER changed poc of package: $PACKAGE from " "$PREVIOUS_POC to $NEW_POC on branch: $BRANCH"] } { "output": "notok", "error": ["You are not allowed to change the point of contact."] } ''' httpcode = 200 output = {} pkgnames = flask.request.form.getlist('pkgnames', None) branches = flask.request.form.getlist('branches', None) if pkgnames and branches: try: messages = [] for pkg_name, pkg_branch in itertools.product(pkgnames, branches): message = pkgdblib.update_pkg_poc( SESSION, pkg_name=pkg_name, pkg_branch=pkg_branch, pkg_poc='orphan', user=flask.g.fas_user, ) messages.append(message) SESSION.commit() output['output'] = 'ok' output['messages'] = messages except pkgdblib.PkgdbException, err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500
def api_packager_list(pattern=None): ''' List packagers -------------- List packagers based on a pattern. If no pattern is provided, return all the packagers. :: /api/packagers/<pattern>/ /api/packagers/?pattern=<pattern> :kwarg pattern: String of the pattern to use to list find packagers. If no pattern is provided, it returns the list of all packagers. Sample response: :: /api/packagers/rem* { "output": "ok", "packagers": [ "remi" ] } /api/packagers/?pattern=pi* { "output": "ok", "packagers": [ "pilcher", "pingou" ] } ''' httpcode = 200 output = {} pattern = flask.request.args.get('pattern', pattern) or '*' if pattern: packagers = pkgdblib.search_packagers(SESSION, pattern=pattern, ) packagers = [pkg[0] for pkg in packagers] SESSION.commit() output['output'] = 'ok' output['packagers'] = packagers else: # pragma: no cover # In theory we can never get here output = {'output': 'notok', 'error': 'Invalid request'} httpcode = 500 jsonout = flask.jsonify(output) jsonout.status_code = httpcode return jsonout
def package_give_acls(namespace, package): ''' Give acls to a specified user for a specific package. ''' try: pkg = pkgdblib.search_package(SESSION, namespace=namespace, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.redirect(flask.url_for('.list_packages')) collections = [ pkglist.collection for pkglist in pkg.listings if pkglist.collection.status != 'EOL' ] acls = pkgdblib.get_status(SESSION) form = pkgdb2.forms.SetAclPackageForm( collections_obj=collections, pkg_acl=acls['pkg_acl'], acl_status=acls['acl_status'], namespaces=acls['namespaces'], ) form.pkgname.data = package if str(form.namespace.data) in ['None', '']: form.namespace.data = 'rpms' if form.validate_on_submit(): pkg_branchs = form.branches.data pkg_acls = form.acl.data pkg_user = form.user.data acl_status = form.acl_status.data try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): if acl in APP.config['AUTO_APPROVE']: acl_status = 'Approved' pkgdblib.set_acl_package( SESSION, namespace=namespace, pkg_name=package, pkg_branch=collec, pkg_user=pkg_user, acl=acl, status=acl_status, user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') return flask.redirect( flask.url_for('.package_info', namespace=namespace, package=package)) except pkgdblib.PkgdbException, err: SESSION.rollback() flask.flash(str(err), 'error')
def comaintain_package(package): ''' Asks for ACLs to co-maintain a package. You need to be a packager to request co-maintainership. ''' # This is really wearing belt and suspenders, the decorator above # should take care of this if not 'packager' in flask.g.fas_user.groups: # pragma: no cover flask.flash( 'You must be a packager to apply to be a comaintainer', 'errors') return flask.redirect(flask.url_for( '.package_info', package=package)) try: pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.redirect( flask.url_for('.package_info', package=package)) pkg_acls = ['commit', 'watchcommits', 'watchbugzilla'] pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings] # Make sure the requester does not already have commit pkg_branchs2 = [] for pkg_branch in pkg_branchs: if pkgdblib.has_acls(SESSION, flask.g.fas_user.username, pkg.name, pkg_branch, 'commit'): flask.flash( 'You are already a co-maintainer on %s' % pkg_branch, 'error') else: pkg_branchs2.append(pkg_branch) pkg_branchs = pkg_branchs2 if not pkg_branchs: return flask.redirect(flask.url_for('.package_info', package=package)) try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): acl_status = 'Awaiting Review' if acl in APP.config['AUTO_APPROVE']: acl_status = 'Approved' pkgdblib.set_acl_package( SESSION, pkg_name=package, pkg_branch=collec, pkg_user=flask.g.fas_user.username, acl=acl, status=acl_status, user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') # Let's keep this in although we should never see it except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error')
def package_new(): ''' Page to create a new package. ''' collections = pkgdb2.lib.search_collection(SESSION, '*', 'Under Development') collections.extend(pkgdb2.lib.search_collection(SESSION, '*', 'Active')) pkg_status = pkgdb2.lib.get_status(SESSION, 'pkg_status')['pkg_status'] namespaces = pkgdb2.lib.get_status(SESSION, 'namespaces')['namespaces'] form = pkgdb2.forms.AddPackageForm( collections=collections, pkg_status_list=pkg_status, namespaces=namespaces, ) if form.validate_on_submit(): pkg_name = form.pkgname.data pkg_summary = form.summary.data pkg_description = form.description.data pkg_review_url = form.review_url.data pkg_status = form.status.data pkg_critpath = form.critpath.data pkg_collection = form.branches.data pkg_poc = form.poc.data pkg_upstream_url = form.upstream_url.data pkg_namespace = form.namespace.data monitoring_status = form.monitoring_status.data koschei = form.koschei.data try: message = pkgdblib.add_package( SESSION, namespace=pkg_namespace, pkg_name=pkg_name, pkg_summary=pkg_summary, pkg_description=pkg_description, pkg_review_url=pkg_review_url, pkg_status=pkg_status, pkg_critpath=pkg_critpath, pkg_collection=pkg_collection, pkg_poc=pkg_poc, pkg_upstream_url=pkg_upstream_url, monitoring_status=monitoring_status, koschei=koschei, user=flask.g.fas_user, ) SESSION.commit() flask.flash(message) return flask.redirect(flask.url_for('.list_packages')) # Keep it in, but normally we shouldn't hit this except PkgdbException as err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error') return flask.render_template( 'package_new.html', form=form, )
def package_new(): ''' Page to create a new package. ''' collections = pkgdb2.lib.search_collection( SESSION, '*', 'Under Development') collections.extend(pkgdb2.lib.search_collection(SESSION, '*', 'Active')) pkg_status = pkgdb2.lib.get_status(SESSION, 'pkg_status')['pkg_status'] namespaces = pkgdb2.lib.get_status(SESSION, 'namespaces')['namespaces'] form = pkgdb2.forms.AddPackageForm( collections=collections, pkg_status_list=pkg_status, namespaces=namespaces, ) if form.validate_on_submit(): pkg_name = form.pkgname.data pkg_summary = form.summary.data pkg_description = form.description.data pkg_review_url = form.review_url.data pkg_status = form.status.data pkg_critpath = form.critpath.data pkg_collection = form.branches.data pkg_poc = form.poc.data pkg_upstream_url = form.upstream_url.data pkg_namespace = form.namespace.data monitoring_status = form.monitoring_status.data koschei = form.koschei.data try: message = pkgdblib.add_package( SESSION, namespace=pkg_namespace, pkg_name=pkg_name, pkg_summary=pkg_summary, pkg_description=pkg_description, pkg_review_url=pkg_review_url, pkg_status=pkg_status, pkg_critpath=pkg_critpath, pkg_collection=pkg_collection, pkg_poc=pkg_poc, pkg_upstream_url=pkg_upstream_url, monitoring_status=monitoring_status, koschei=koschei, user=flask.g.fas_user, ) SESSION.commit() flask.flash(message) return flask.redirect(flask.url_for('.list_packages')) # Keep it in, but normally we shouldn't hit this except PkgdbException as err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error') return flask.render_template( 'package_new.html', form=form, )
def update_acl(package, user, branch=None): ''' Update the acls for a specific user on a package. ''' pending_acls = pkgdblib.get_acl_user_package(SESSION, user, package, status=None) pending_acls2 = [] if branch is not None: for acls in pending_acls: if acls['collection'] == branch: pending_acls2.append(acls) else: for acls in pending_acls: if acls['collection_status'] != 'EOL': pending_acls2.append(acls) pending_acls = pending_acls2 collections = set([item['collection'] for item in pending_acls]) status = pkgdblib.get_status(SESSION, ['pkg_acl', 'acl_status']) form = pkgdb2.forms.UpdateAclPackageForm( collections=collections, pkg_acl_list=status['pkg_acl'], acl_status=status['acl_status'], ) if form.validate_on_submit(): pkg_branchs = form.pkg_branch.data pkg_acls = form.pkg_acl.data acl_status = form.acl_status.data try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): if acl_status == 'Awaiting Review' and \ acl in APP.config['AUTO_APPROVE']: acl_status = 'Approved' pkgdblib.set_acl_package( SESSION, pkg_name=package, pkg_branch=collec, pkg_user=user, acl=acl, status=acl_status, user=flask.g.fas_user, ) flask.flash('ACLs updated') SESSION.commit() return flask.redirect( flask.url_for('.package_info', package=package)) # Let's keep this in although we should never see it except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'errors')
def api_monitor_package(package, status, namespace='rpms'): ''' Monitoring status ----------------- Set the monitor status on the specified package. :: /api/package/<package>/monitor/<status> Accepts POST queries only. :arg package: The name of the package to update. :arg status: The status to set to the monitoring flag, can be either ``1`` or ``true`` for setting full monitoring, ``nobuild`` to set the monitoring but block scratch builds or ``0`` or ``false`` to stop the monitoring entirely. :kwarg namespace: The namespace of the package to update (default to ``rpms``). Sample response: :: { "output": "ok", "messages": "Monitoring status of guake set to True" } { "output": "notok", "error": "No package found by this name" } ''' httpcode = 200 output = {} if str(status).lower() in ['1', 'true']: status = True elif str(status).lower() == 'nobuild': status = 'nobuild' else: status = False try: msg = pkgdblib.set_monitor_package( SESSION, namespace, package, status, flask.g.fas_user) SESSION.commit() output['output'] = 'ok' output['messages'] = msg except pkgdblib.PkgdbException, err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500
def update_acl(package, user, branch=None): ''' Update the acls for a specific user on a package. ''' pending_acls = pkgdblib.get_acl_user_package( SESSION, user, package, status=None) pending_acls2 = [] if branch is not None: for acls in pending_acls: if acls['collection'] == branch: pending_acls2.append(acls) else: for acls in pending_acls: if acls['collection_status'] != 'EOL': pending_acls2.append(acls) pending_acls = pending_acls2 collections = set([item['collection'] for item in pending_acls]) status = pkgdblib.get_status(SESSION, ['pkg_acl', 'acl_status']) form = pkgdb2.forms.UpdateAclPackageForm( collections=collections, pkg_acl_list=status['pkg_acl'], acl_status=status['acl_status'], ) if form.validate_on_submit(): pkg_branchs = form.pkg_branch.data pkg_acls = form.pkg_acl.data acl_status = form.acl_status.data try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): if acl_status == 'Awaiting Review' and \ acl in APP.config['AUTO_APPROVE']: acl_status = 'Approved' pkgdblib.set_acl_package( SESSION, pkg_name=package, pkg_branch=collec, pkg_user=user, acl=acl, status=acl_status, user=flask.g.fas_user, ) flask.flash('ACLs updated') SESSION.commit() return flask.redirect( flask.url_for('.package_info', package=package)) # Let's keep this in although we should never see it except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'errors')
def package_give_acls(namespace, package): ''' Give acls to a specified user for a specific package. ''' try: pkg = pkgdblib.search_package( SESSION, namespace=namespace, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.redirect( flask.url_for('.list_packages')) collections = [ pkglist.collection for pkglist in pkg.listings if pkglist.collection.status != 'EOL'] acls = pkgdblib.get_status(SESSION) form = pkgdb2.forms.SetAclPackageForm( collections_obj=collections, pkg_acl=acls['pkg_acl'], acl_status=acls['acl_status'], namespaces=acls['namespaces'], ) form.pkgname.data = package if str(form.namespace.data) in ['None', '']: form.namespace.data = 'rpms' if form.validate_on_submit(): pkg_branchs = form.branches.data pkg_acls = form.acl.data pkg_user = form.user.data acl_status = form.acl_status.data try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): if acl in APP.config['AUTO_APPROVE']: acl_status = 'Approved' pkgdblib.set_acl_package( SESSION, namespace=namespace, pkg_name=package, pkg_branch=collec, pkg_user=pkg_user, acl=acl, status=acl_status, user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') return flask.redirect(flask.url_for( '.package_info', namespace=namespace, package=package)) except pkgdblib.PkgdbException, err: SESSION.rollback() flask.flash(str(err), 'error')
def api_package_unretire(): """ Unretire packages ----------------- Un-retire one or more packages. :: /api/package/unretire/ Accepts POST queries only. :arg pkgnames: Comma separated list of the packages names. :arg branches: Comma separated list of string of the branches names in which these packages will be un-deprecated. Sample response: :: { "output": "ok", "messages": ["user: $USER updated package: $PACKAGE status from: " "$PREVIOUS_STATUS to $NEW_STATUS on branch $BRANCH"] } { "output": "notok", "error": ["You are not allowed to update the status of " "the package: $PACKAGE on branch $BRANCH to $STATUS."] } """ httpcode = 200 output = {} pkgnames = flask.request.form.getlist("pkgnames", None) branches = flask.request.form.getlist("branches", None) if pkgnames and branches: try: messages = [] for pkg_name, pkg_branch in itertools.product(pkgnames, branches): message = pkgdblib.update_pkg_status( SESSION, pkg_name=pkg_name, pkg_branch=pkg_branch, status="Approved", user=flask.g.fas_user ) messages.append(message) SESSION.commit() output["output"] = "ok" output["messages"] = messages except pkgdblib.PkgdbException, err: SESSION.rollback() output["output"] = "notok" output["error"] = str(err) httpcode = 500
def request_acl_all_branch(namespace, package, acl): ''' Request the specified ACL on all branches of the specified package. ''' form = pkgdb2.forms.ConfirmationForm() if form.validate_on_submit(): pkg_acl = pkgdblib.get_status(SESSION, 'pkg_acl')['pkg_acl'] if acl not in pkg_acl: flask.flash('Invalid ACL provided %s.' % acl, 'errors') return flask.render_template('msg.html') try: pkg = pkgdblib.search_package( SESSION, namespace=namespace, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.render_template('msg.html') pkg_branchs = set([ pkglist.collection.branchname for pkglist in pkg.listings if pkglist.collection.status in ['Active', 'Under Development'] and pkglist.status == 'Approved' ]) for branch in pkg_branchs: acl_status = 'Awaiting Review' pkger_grp = APP.config.get('PKGER_GROUP', 'packager') if acl in APP.config['AUTO_APPROVE']: acl_status = 'Approved' elif pkger_grp not in flask.g.fas_user.groups: flask.flash( 'You must be a %s to apply to the ACL: %s on %s' % ( pkger_grp, acl, package), 'error') try: pkgdblib.set_acl_package( SESSION, namespace=namespace, pkg_name=package, pkg_branch=branch, pkg_user=flask.g.fas_user.username, acl=acl, status=acl_status, user=flask.g.fas_user, ) flask.flash( 'ACL %s requested on branch %s' % (acl, branch)) SESSION.commit() except PkgdbException as err: SESSION.rollback() flask.flash(str(err), 'error') return flask.redirect(flask.url_for( '.package_info', namespace=namespace, package=package))
def request_acl_all_branch(namespace, package, acl): ''' Request the specified ACL on all branches of the specified package. ''' form = pkgdb2.forms.ConfirmationForm() if form.validate_on_submit(): pkg_acl = pkgdblib.get_status(SESSION, 'pkg_acl')['pkg_acl'] if acl not in pkg_acl: flask.flash('Invalid ACL provided %s.' % acl, 'errors') return flask.render_template('msg.html') try: pkg = pkgdblib.search_package(SESSION, namespace=namespace, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.render_template('msg.html') pkg_branchs = set([ pkglist.collection.branchname for pkglist in pkg.listings if pkglist.collection.status in ['Active', 'Under Development'] and pkglist.status == 'Approved' ]) for branch in pkg_branchs: acl_status = 'Awaiting Review' pkger_grp = APP.config.get('PKGER_GROUP', 'packager') if acl in APP.config['AUTO_APPROVE']: acl_status = 'Approved' elif pkger_grp not in flask.g.fas_user.groups: flask.flash( 'You must be a %s to apply to the ACL: %s on %s' % (pkger_grp, acl, package), 'error') try: pkgdblib.set_acl_package( SESSION, namespace=namespace, pkg_name=package, pkg_branch=branch, pkg_user=flask.g.fas_user.username, acl=acl, status=acl_status, user=flask.g.fas_user, ) flask.flash('ACL %s requested on branch %s' % (acl, branch)) SESSION.commit() except PkgdbException as err: SESSION.rollback() flask.flash(str(err), 'error') return flask.redirect( flask.url_for('.package_info', namespace=namespace, package=package))
def collection_edit(collection): ''' Allows to edit the information about the specified collection. ''' try: collection = pkgdblib.search_collection(SESSION, collection)[0] except IndexError: flask.flash('No collection of this name found.', 'errors') return flask.render_template('msg.html') clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status'] form = pkgdb2.forms.AddCollectionForm( clt_status=clt_status ) if form.validate_on_submit(): clt_name = form.clt_name.data clt_version = form.version.data clt_status = form.clt_status.data clt_branchname = form.branchname.data clt_disttag = form.dist_tag.data clt_koji_name = form.kojiname.data clt_allow_retire = form.allow_retire.data try: pkgdblib.edit_collection( SESSION, collection=collection, clt_name=clt_name, clt_version=clt_version, clt_status=clt_status, clt_branchname=clt_branchname, clt_disttag=clt_disttag, clt_koji_name=clt_koji_name, clt_allow_retire=clt_allow_retire, user=flask.g.fas_user, ) SESSION.commit() flask.flash('Collection "%s" edited' % clt_branchname) return flask.redirect(flask.url_for( '.collection_info', collection=collection.branchname)) # In theory we should never hit this except PkgdbException as err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'errors') elif flask.request.method == 'GET': form = pkgdb2.forms.AddCollectionForm( clt_status=clt_status, collection=collection ) return flask.render_template( 'collection_edit.html', form=form, collection=collection, )
def api_monitor_package(package, status): ''' Monitoring status ----------------- Set the monitor status on the specified package. :: /api/package/<package>/monitor/<status> Accepts POST queries only. :arg package: The name of the package to update. :arg status: The status to set to the monitoring flag, can be either ``1`` or ``true`` for setting full monitoring, ``nobuild`` to set the monitoring but block scratch builds or ``0`` or ``false`` to stop the monitoring entirely. Sample response: :: { "output": "ok", "messages": "Monitoring status of guake set to True" } { "output": "notok", "error": "No package found by this name" } ''' httpcode = 200 output = {} if str(status).lower() in ['1', 'true']: status = True elif str(status).lower() == 'nobuild': status = 'nobuild' else: status = False try: msg = pkgdblib.set_monitor_package(SESSION, package, status, flask.g.fas_user) SESSION.commit() output['output'] = 'ok' output['messages'] = msg except pkgdblib.PkgdbException, err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500
def api_monitor_package(package, status): """ Monitoring status ----------------- Set the monitor status on the specified package. :: /api/package/<package>/monitor/<status> Accepts POST queries only. :arg package: The name of the package to update. :arg status: The status to set to the monitoring flag, can be either ``1`` or ``true`` for setting full monitoring, ``nobuild`` to set the monitoring but block scratch builds or ``0`` or ``false`` to stop the monitoring entirely. Sample response: :: { "output": "ok", "messages": "Monitoring status of guake set to True" } { "output": "notok", "error": "No package found by this name" } """ httpcode = 200 output = {} if str(status).lower() in ["1", "true"]: status = True elif str(status).lower() == "nobuild": status = "nobuild" else: status = False try: msg = pkgdblib.set_monitor_package(SESSION, package, status, flask.g.fas_user) SESSION.commit() output["output"] = "ok" output["messages"] = msg except pkgdblib.PkgdbException, err: SESSION.rollback() output["output"] = "notok" output["error"] = str(err) httpcode = 500
def comaintain_package(package): ''' Asks for ACLs to co-maintain a package. You need to be a packager to request co-maintainership. ''' # This is really wearing belt and suspenders, the decorator above # should take care of this if not 'packager' in flask.g.fas_user.groups: # pragma: no cover flask.flash('You must be a packager to apply to be a comaintainer', 'errors') return flask.redirect(flask.url_for('.package_info', package=package)) try: pkg = pkgdblib.search_package(SESSION, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.redirect(flask.url_for('.package_info', package=package)) pkg_acls = ['commit', 'watchcommits', 'watchbugzilla'] pkg_branchs = [pkglist.collection.branchname for pkglist in pkg.listings] # Make sure the requester does not already have commit pkg_branchs2 = [] for pkg_branch in pkg_branchs: if pkgdblib.has_acls(SESSION, flask.g.fas_user.username, pkg.name, pkg_branch, 'commit'): flask.flash('You are already a co-maintainer on %s' % pkg_branch, 'error') else: pkg_branchs2.append(pkg_branch) pkg_branchs = pkg_branchs2 if not pkg_branchs: return flask.redirect(flask.url_for('.package_info', package=package)) try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): acl_status = 'Awaiting Review' if acl in APP.config['AUTO_APPROVE']: acl_status = 'Approved' pkgdblib.set_acl_package( SESSION, pkg_name=package, pkg_branch=collec, pkg_user=flask.g.fas_user.username, acl=acl, status=acl_status, user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') # Let's keep this in although we should never see it except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error')
def collection_edit(collection): ''' Allows to edit the information about the specified collection. ''' try: collection = pkgdblib.search_collection(SESSION, collection)[0] except IndexError: flask.flash('No collection of this name found.', 'errors') return flask.render_template('msg.html') clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status'] form = pkgdb2.forms.AddCollectionForm(clt_status=clt_status) if form.validate_on_submit(): clt_name = form.clt_name.data clt_version = form.version.data clt_status = form.clt_status.data clt_branchname = form.branchname.data clt_disttag = form.dist_tag.data clt_koji_name = form.kojiname.data clt_allow_retire = form.allow_retire.data try: pkgdblib.edit_collection( SESSION, collection=collection, clt_name=clt_name, clt_version=clt_version, clt_status=clt_status, clt_branchname=clt_branchname, clt_disttag=clt_disttag, clt_koji_name=clt_koji_name, clt_allow_retire=clt_allow_retire, user=flask.g.fas_user, ) SESSION.commit() flask.flash('Collection "%s" edited' % clt_branchname) return flask.redirect( flask.url_for('.collection_info', collection=collection.branchname)) # In theory we should never hit this except PkgdbException as err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'errors') elif flask.request.method == 'GET': form = pkgdb2.forms.AddCollectionForm(clt_status=clt_status, collection=collection) return flask.render_template( 'collection_edit.html', form=form, collection=collection, )
def package_retire(package, full=True): ''' Gives the possibility to orphan or take a package. ''' if not bool(full) or str(full) in ['0', 'False']: full = False try: package_acl = pkgdblib.get_acl_package(SESSION, package) package = pkgdblib.search_package(SESSION, package, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') if not is_pkgdb_admin(flask.g.fas_user): flask.flash( 'Only Admins are allowed to retire package here, ' 'you should use `fedpkg retire`.', 'errors') return flask.redirect( flask.url_for('.package_info', package=package.name)) collections = [ acl.collection.branchname for acl in package_acl if acl.collection.status in ['Active', 'Under Development'] and acl.status == 'Orphaned' ] form = pkgdb2.forms.BranchForm(collections=collections) if form.validate_on_submit(): for acl in package_acl: if acl.collection.branchname in form.branches.data: if acl.point_of_contact == 'orphan': try: pkgdblib.update_pkg_status( session=SESSION, pkg_name=package.name, pkg_branch=acl.collection.branchname, status='Retired', user=flask.g.fas_user) flask.flash( 'This package has been retired on branch: %s' % acl.collection.branchname) except pkgdblib.PkgdbException, err: # pragma: no cover # We should never hit this flask.flash(str(err), 'error') SESSION.rollback() APP.logger.exception(err) else: # pragma: no cover flask.flash('This package has not been orphaned on ' 'branch: %s' % acl.collection.branchname) try: SESSION.commit() # Keep it in, but normally we shouldn't hit this except pkgdblib.PkgdbException, err: # pragma: no cover # We should never hit this SESSION.rollback() APP.logger.exception(err) flask.flash(str(err), 'error')
def admin_action_edit_status(action_id): """ Edit Admin Action status update """ admin_action = pkgdblib.get_admin_action(SESSION, action_id) if not admin_action: flask.flash('No action found with this identifier.', 'errors') return flask.render_template('msg.html') action_status = pkgdblib.get_status( SESSION, 'admin_status')['admin_status'] form = pkgdb2.forms.EditActionStatusForm( status=action_status, obj=admin_action ) form.id.data = action_id if form.validate_on_submit(): try: message = pkgdblib.edit_action_status( SESSION, admin_action, action_status=form.status.data, user=flask.g.fas_user, message=form.message.data, ) SESSION.commit() flask.flash(message) except PkgdbException as err: # pragma: no cover # We can only reach here in two cases: # 1) the user is not an admin, but that's taken care of # by the decorator # 2) we have a SQLAlchemy problem when storing the info # in the DB which we cannot test SESSION.rollback() flask.flash(err, 'errors') return flask.render_template('msg.html') return flask.redirect( flask.url_for('.admin_actions') ) return flask.render_template( 'actions_update.html', admin_action=admin_action, action_id=action_id, form=form, )
def package_request_branch(namespace, package, full=True): ''' Gives the possibility to request a new branch for this package. ''' if not bool(full) or str(full) in ['0', 'False']: full = False try: package_acl = pkgdblib.get_acl_package( SESSION, namespace, package) package = pkgdblib.search_package( SESSION, namespace, package, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') branches = [ pkg.collection.branchname for pkg in package_acl if pkg.collection.status != 'EOL' ] collections = pkgdb2.lib.search_collection( SESSION, '*', 'Under Development') collections.extend(pkgdb2.lib.search_collection(SESSION, '*', 'Active')) # List the possible branches that this package does not already have. branches_possible = [ collec.branchname for collec in collections if collec.branchname not in branches] # Further limit that list to only the branches allowed for this namespace. namespace_policy = APP.config.get('PKGDB2_NAMESPACE_POLICY') policy = namespace_policy.get(pkg.package.namespace) if policy: branches_possible = [b for b in branches_possible if b in policy] form = pkgdb2.forms.BranchForm(collections=branches_possible) if form.validate_on_submit(): for branch in form.branches.data: try: msg = pkgdblib.add_new_branch_request( session=SESSION, namespace=package.namespace, pkg_name=package.name, clt_to=branch, user=flask.g.fas_user) SESSION.commit() flask.flash(msg) except pkgdblib.PkgdbException, err: # pragma: no cover flask.flash(str(err), 'error') SESSION.rollback() except SQLAlchemyError, err: # pragma: no cover APP.logger.exception(err) flask.flash( 'Could not save the request to the database for ' 'branch: %s' % branch, 'error') SESSION.rollback()
def package_request_new(): ''' Page to request a new package. ''' collections = pkgdb2.lib.search_collection(SESSION, '*', 'Under Development') collections.extend(pkgdb2.lib.search_collection(SESSION, '*', 'Active')) pkg_status = pkgdb2.lib.get_status(SESSION, 'pkg_status')['pkg_status'] form = pkgdb2.forms.AddPackageForm( collections=collections, pkg_status_list=pkg_status, ) if form.validate_on_submit(): pkg_name = form.pkgname.data pkg_summary = form.summary.data pkg_description = form.description.data pkg_review_url = form.review_url.data pkg_status = form.status.data pkg_critpath = form.critpath.data pkg_collection = form.branches.data pkg_poc = form.poc.data pkg_upstream_url = form.upstream_url.data try: messages = [] for clt in pkg_collection: message = pkgdblib.add_new_package_request( SESSION, pkg_name=pkg_name, pkg_summary=pkg_summary, pkg_description=pkg_description, pkg_review_url=pkg_review_url, pkg_status=pkg_status, pkg_critpath=pkg_critpath, pkg_collection=clt, pkg_poc=pkg_poc, pkg_upstream_url=pkg_upstream_url, user=flask.g.fas_user, ) if message: messages.append(message) SESSION.commit() for message in messages: flask.flash(message) return flask.redirect(flask.url_for('.index')) # Keep it in, but normally we shouldn't hit this except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error')
def package_take(package, collection): ''' Make someone Point of contact of an orphaned package. ''' try: pkgdblib.unorphan_package(session=SESSION, pkg_name=package, pkg_branch=collection, pkg_user=flask.g.fas_user.username, user=flask.g.fas_user) SESSION.commit() flask.flash('You have taken the package %s on branch %s' % (package, collection)) except pkgdblib.PkgdbException, err: SESSION.rollback() flask.flash(str(err), 'error')
def dropcommit_package(namespace, package): ''' Obsolete commit ACLs on a package. This method can only be used for the user itself. ''' form = pkgdb2.forms.ConfirmationForm() if form.validate_on_submit(): try: pkg = pkgdblib.search_package(SESSION, namespace=namespace, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.redirect( flask.url_for('.package_info', namespace=namespace, package=package)) pkg_acls = ['commit'] pkg_branchs = set() for pkglist in pkg.listings: if pkglist.collection.status in ['Active', 'Under Development']: for acl in pkglist.acls: if acl.fas_name == flask.g.fas_user.username and \ acl.acl == 'commit' and acl.status == 'Approved': pkg_branchs.add(pkglist.collection.branchname) try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): pkgdblib.set_acl_package( SESSION, namespace=namespace, pkg_name=package, pkg_branch=collec, pkg_user=flask.g.fas_user.username, acl=acl, status='Obsolete', user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') # Let's keep this in although we should never see it except PkgdbException as err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error') return flask.redirect( flask.url_for('.package_info', namespace=namespace, package=package))
def package_new(): ''' Page to create a new package. ''' collections = pkgdb2.lib.search_collection( SESSION, '*', 'Under Development') collections.extend(pkgdb2.lib.search_collection(SESSION, '*', 'Active')) pkg_status = pkgdb2.lib.get_status(SESSION, 'pkg_status')['pkg_status'] form = pkgdb2.forms.AddPackageForm( collections=collections, pkg_status_list=pkg_status, ) if form.validate_on_submit(): pkg_name = form.pkg_name.data pkg_summary = form.pkg_summary.data pkg_description = form.pkg_description.data pkg_review_url = form.pkg_reviewURL.data pkg_status = form.pkg_status.data pkg_shouldopen = form.pkg_shouldopen.data pkg_critpath = form.pkg_critpath.data pkg_collection = form.pkg_collection.data pkg_poc = form.pkg_poc.data pkg_upstream_url = form.pkg_upstreamURL.data try: message = pkgdblib.add_package( SESSION, pkg_name=pkg_name, pkg_summary=pkg_summary, pkg_description=pkg_description, pkg_reviewURL=pkg_review_url, pkg_status=pkg_status, pkg_shouldopen=pkg_shouldopen, pkg_critpath=pkg_critpath, pkg_collection=pkg_collection, pkg_poc=pkg_poc, pkg_upstreamURL=pkg_upstream_url, user=flask.g.fas_user, ) SESSION.commit() flask.flash(message) return flask.redirect(flask.url_for('.list_packages')) # Keep it in, but normally we shouldn't hit this except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error')
def package_take(package, collection): ''' Make someone Point of contact of an orphaned package. ''' try: pkgdblib.unorphan_package( session=SESSION, pkg_name=package, pkg_branch=collection, pkg_user=flask.g.fas_user.username, user=flask.g.fas_user ) SESSION.commit() flask.flash('You have taken the package %s on branch %s' % ( package, collection)) except pkgdblib.PkgdbException, err: SESSION.rollback() flask.flash(str(err), 'error')
def dropcommit_package(namespace, package): ''' Obsolete commit ACLs on a package. This method can only be used for the user itself. ''' form = pkgdb2.forms.ConfirmationForm() if form.validate_on_submit(): try: pkg = pkgdblib.search_package( SESSION, namespace=namespace, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.redirect(flask.url_for( '.package_info', namespace=namespace, package=package)) pkg_acls = ['commit'] pkg_branchs = set() for pkglist in pkg.listings: if pkglist.collection.status in [ 'Active', 'Under Development']: for acl in pkglist.acls: if acl.fas_name == flask.g.fas_user.username and \ acl.acl == 'commit' and acl.status == 'Approved': pkg_branchs.add(pkglist.collection.branchname) try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): pkgdblib.set_acl_package( SESSION, namespace=namespace, pkg_name=package, pkg_branch=collec, pkg_user=flask.g.fas_user.username, acl=acl, status='Obsolete', user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') # Let's keep this in although we should never see it except PkgdbException as err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error') return flask.redirect(flask.url_for( '.package_info', namespace=namespace, package=package))
def watch_package(namespace, package): ''' Request watch* ACLs on a package. Anyone can request these ACLs, no need to be a packager. ''' form = pkgdb2.forms.ConfirmationForm() if form.validate_on_submit(): try: pkg = pkgdblib.search_package(SESSION, namespace=namespace, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.redirect( flask.url_for('.package_info', namespace=namespace, package=package)) pkg_acls = ['watchcommits', 'watchbugzilla'] pkg_branchs = set([ pkglist.collection.branchname for pkglist in pkg.listings if pkglist.collection.status in ['Active', 'Under Development'] and pkglist.status == 'Approved' ]) try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): pkgdblib.set_acl_package( SESSION, namespace=namespace, pkg_name=package, pkg_branch=collec, pkg_user=flask.g.fas_user.username, acl=acl, status='Approved', user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') # Let's keep this in although we should never see it except PkgdbException as err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error') return flask.redirect( flask.url_for('.package_info', namespace=namespace, package=package))
def package_take(namespace, package, full=True): ''' Make someone Point of contact of an orphaned package. ''' if not bool(full) or str(full) in ['0', 'False']: full = False try: package_acl = pkgdblib.get_acl_package( SESSION, namespace, package) package = pkgdblib.search_package( SESSION, namespace, package, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') collections = [ acl.collection.branchname for acl in package_acl if acl.collection.status in ['Active', 'Under Development'] and acl.status == 'Orphaned' ] if not collections: flask.flash('No branches orphaned found', 'error') return flask.redirect(flask.url_for( '.package_info', namespace=package.namespace, package=package.name) ) form = pkgdb2.forms.BranchForm(collections=collections) if form.validate_on_submit(): for branch in form.branches.data: try: pkgdblib.unorphan_package( session=SESSION, namespace=package.namespace, pkg_name=package.name, pkg_branch=branch, pkg_user=flask.g.fas_user.username, user=flask.g.fas_user ) SESSION.commit() flask.flash('You have taken the package %s on branch %s' % ( package.name, branch)) except pkgdblib.PkgdbBugzillaException, err: # pragma: no cover APP.logger.exception(err) flask.flash(str(err), 'error') SESSION.rollback() except pkgdblib.PkgdbException, err: # pragma: no cover flask.flash(str(err), 'error') SESSION.rollback()
def request_acl(package): ''' Request acls for a specific package. ''' collections = pkgdblib.search_collection( SESSION, '*', 'Under Development') collections.extend(pkgdblib.search_collection(SESSION, '*', 'Active')) pkg_acl = pkgdblib.get_status(SESSION, 'pkg_acl')['pkg_acl'] form = pkgdb2.forms.RequestAclPackageForm( collections=collections, pkg_acl_list=pkg_acl ) if form.validate_on_submit(): pkg_branchs = form.pkg_branch.data pkg_acls = form.pkg_acl.data try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): acl_status = 'Awaiting Review' if acl in APP.config['AUTO_APPROVE']: acl_status = 'Approved' elif 'packager' not in flask.g.fas_user.groups: flask.flash( 'You must be a packager to apply to the' ' ACL: %s on %s' % (acl, collec), 'errors') continue pkgdblib.set_acl_package( SESSION, pkg_name=package, pkg_branch=collec, pkg_user=flask.g.fas_user.username, acl=acl, status=acl_status, user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') return flask.redirect( flask.url_for('.package_info', package=package)) except pkgdblib.PkgdbException, err: SESSION.rollback() flask.flash(str(err), 'error')
def watch_package(namespace, package): ''' Request watch* ACLs on a package. Anyone can request these ACLs, no need to be a packager. ''' form = pkgdb2.forms.ConfirmationForm() if form.validate_on_submit(): try: pkg = pkgdblib.search_package( SESSION, namespace=namespace, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.redirect(flask.url_for( '.package_info', namespace=namespace, package=package)) pkg_acls = ['watchcommits', 'watchbugzilla'] pkg_branchs = set([ pkglist.collection.branchname for pkglist in pkg.listings if pkglist.collection.status in ['Active', 'Under Development'] and pkglist.status == 'Approved' ]) try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): pkgdblib.set_acl_package( SESSION, namespace=namespace, pkg_name=package, pkg_branch=collec, pkg_user=flask.g.fas_user.username, acl=acl, status='Approved', user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') # Let's keep this in although we should never see it except PkgdbException as err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error') return flask.redirect(flask.url_for( '.package_info', namespace=namespace, package=package))
def admin_drop_namespace(): """ Drop an existing namespace """ form = pkgdb2.forms.NamespaceForm() if form.validate_on_submit(): try: message = pkgdblib.drop_namespace(SESSION, form.namespace.data, user=flask.g.fas_user) SESSION.commit() flask.flash(message) except pkgdblib.PkgdbException, err: # pragma: no cover # We can only reach here in two cases: # 1) the user is not an admin, but that's taken care of # by the decorator # 2) we have a SQLAlchemy problem when storing the info # in the DB which we cannot test SESSION.rollback() flask.flash(err, "errors") return flask.render_template("msg.html")
def api_package_unorphan(): ''' Unorphan packages ----------------- Unorphan one or more packages. :: /api/package/unorphan/ Accepts POST queries only. :arg pkgnames: Comma separated list of string of the packages name. :arg branches: Comma separated list of string of the branches name in which these packages will be unorphaned. :arg poc: String of the name of the user taking ownership of this package. If you are not an admin, this name must be None. Sample response: :: { "output": "ok", "messages": ["Package $PACKAGE has been unorphaned for $BRANCH " "by $USER"] } { "output": "notok", "error": ["You must be a packager to take a package."] } ''' httpcode = 200 output = {} pkgnames = flask.request.form.getlist('pkgnames', None) branches = flask.request.form.getlist('branches', None) poc = flask.request.form.get('poc', None) if pkgnames and branches and poc: messages = [] errors = set() for pkg_name, pkg_branch in itertools.product(pkgnames, branches): try: message = pkgdblib.unorphan_package(session=SESSION, pkg_name=pkg_name, pkg_branch=pkg_branch, pkg_user=poc, user=flask.g.fas_user) messages.append(message) SESSION.commit() except pkgdblib.PkgdbBugzillaException, err: # pragma: no cover APP.logger.exception(err) SESSION.rollback() errors.add(str(err)) except pkgdblib.PkgdbException, err: SESSION.rollback() errors.add(str(err))
def request_acl(package): ''' Request acls for a specific package. ''' collections = pkgdblib.search_collection(SESSION, '*', 'Under Development') collections.extend(pkgdblib.search_collection(SESSION, '*', 'Active')) pkg_acl = pkgdblib.get_status(SESSION, 'pkg_acl')['pkg_acl'] form = pkgdb2.forms.RequestAclPackageForm(collections=collections, pkg_acl_list=pkg_acl) if form.validate_on_submit(): pkg_branchs = form.pkg_branch.data pkg_acls = form.pkg_acl.data try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): acl_status = 'Awaiting Review' if acl in APP.config['AUTO_APPROVE']: acl_status = 'Approved' elif 'packager' not in flask.g.fas_user.groups: flask.flash( 'You must be a packager to apply to the' ' ACL: %s on %s' % (acl, collec), 'errors') continue pkgdblib.set_acl_package( SESSION, pkg_name=package, pkg_branch=collec, pkg_user=flask.g.fas_user.username, acl=acl, status=acl_status, user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') return flask.redirect( flask.url_for('.package_info', package=package)) except pkgdblib.PkgdbException, err: SESSION.rollback() flask.flash(str(err), 'error')
def package_request_branch(namespace, package, full=True): ''' Gives the possibility to request a new branch for this package. ''' if not bool(full) or str(full) in ['0', 'False']: full = False try: package_acl = pkgdblib.get_acl_package(SESSION, namespace, package) package = pkgdblib.search_package(SESSION, namespace, package, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') branches = [ pkg.collection.branchname for pkg in package_acl if pkg.collection.status != 'EOL' ] collections = pkgdb2.lib.search_collection(SESSION, '*', 'Under Development') collections.extend(pkgdb2.lib.search_collection(SESSION, '*', 'Active')) branches_possible = [ collec.branchname for collec in collections if collec.branchname not in branches ] form = pkgdb2.forms.BranchForm(collections=branches_possible) if form.validate_on_submit(): for branch in form.branches.data: try: msg = pkgdblib.add_new_branch_request( session=SESSION, namespace=package.namespace, pkg_name=package.name, clt_to=branch, user=flask.g.fas_user) SESSION.commit() flask.flash(msg) except pkgdblib.PkgdbException, err: # pragma: no cover flask.flash(str(err), 'error') SESSION.rollback() except SQLAlchemyError, err: # pragma: no cover APP.logger.exception(err) flask.flash( 'Could not save the request to the database for ' 'branch: %s' % branch, 'error') SESSION.rollback()
def monitor_package(package, status): ''' Set the monitor status on the specified package. ''' httpcode = 200 output = {} if str(status).lower() not in ['1', 'true']: status = False else: status = True try: msg = pkgdblib.set_monitor_package( SESSION, package, status, flask.g.fas_user) SESSION.commit() output['output'] = 'ok' output['messages'] = msg except pkgdblib.PkgdbException, err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500
def package_take(namespace, package, full=True): ''' Make someone Point of contact of an orphaned package. ''' if not bool(full) or str(full) in ['0', 'False']: full = False try: package_acl = pkgdblib.get_acl_package(SESSION, namespace, package) package = pkgdblib.search_package(SESSION, namespace, package, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') collections = [ acl.collection.branchname for acl in package_acl if acl.collection.status in ['Active', 'Under Development'] and acl.status == 'Orphaned' ] if not collections: flask.flash('No branches orphaned found', 'error') return flask.redirect( flask.url_for('.package_info', namespace=package.namespace, package=package.name)) form = pkgdb2.forms.BranchForm(collections=collections) if form.validate_on_submit(): for branch in form.branches.data: try: pkgdblib.unorphan_package(session=SESSION, namespace=package.namespace, pkg_name=package.name, pkg_branch=branch, pkg_user=flask.g.fas_user.username, user=flask.g.fas_user) SESSION.commit() flask.flash('You have taken the package %s on branch %s' % (package.name, branch)) except pkgdblib.PkgdbBugzillaException, err: # pragma: no cover APP.logger.exception(err) flask.flash(str(err), 'error') SESSION.rollback() except pkgdblib.PkgdbException, err: # pragma: no cover flask.flash(str(err), 'error') SESSION.rollback()
def monitor_package(package, status): ''' Set the monitor status on the specified package. ''' httpcode = 200 output = {} if str(status).lower() not in ['1', 'true']: status = False else: status = True try: msg = pkgdblib.set_monitor_package(SESSION, package, status, flask.g.fas_user) SESSION.commit() output['output'] = 'ok' output['messages'] = msg except pkgdblib.PkgdbException, err: SESSION.rollback() output['output'] = 'notok' output['error'] = str(err) httpcode = 500
def unwatch_package(package): ''' Obsolete watch* ACLs on a package. This method can only be used for the user itself. ''' form = pkgdb2.forms.ConfirmationForm() if form.validate_on_submit(): try: pkg = pkgdblib.search_package( SESSION, pkg_name=package, limit=1)[0] except IndexError: flask.flash('No package found by this name', 'error') return flask.redirect( flask.url_for('.package_info', package=package)) pkg_acls = ['watchcommits', 'watchbugzilla'] pkg_branchs = set([ pkglist.collection.branchname for pkglist in pkg.listings if pkglist.collection.status in ['Active', 'Under Development']]) try: for (collec, acl) in itertools.product(pkg_branchs, pkg_acls): pkgdblib.set_acl_package( SESSION, pkg_name=package, pkg_branch=collec, pkg_user=flask.g.fas_user.username, acl=acl, status='Obsolete', user=flask.g.fas_user, ) SESSION.commit() flask.flash('ACLs updated') # Let's keep this in although we should never see it except pkgdblib.PkgdbException, err: # pragma: no cover SESSION.rollback() flask.flash(str(err), 'error')