Example #1
0
def api_order_screenshots(token: APIToken, package: Package, order: [any]):
    if not token.canOperateOnPackage(package):
        error(403, "API token does not have access to the package")

    guard(do_order_screenshots)(token.owner, package, order)

    return jsonify({"success": True})
Example #2
0
def api_edit_package(token: APIToken, package: Package, data: dict, reason: str = "API"):
	if not token.canOperateOnPackage(package):
		error(403, "API token does not have access to the package")

	reason += ", token=" + token.name

	package = guard(do_edit_package)(token.owner, package, False, data, reason)

	return jsonify({
		"success": True,
		"package": package.getAsDictionary(current_app.config["BASE_URL"])
	})
Example #3
0
def api_create_screenshot(token: APIToken, package: Package, title: str, file, reason="API"):
	if not token.canOperateOnPackage(package):
		error(403, "API token does not have access to the package")

	reason += ", token=" + token.name

	ss : PackageScreenshot = guard(do_create_screenshot)(token.owner, package, title, file, reason)

	return jsonify({
		"success": True,
		"screenshot": ss.getAsDictionary()
	})
Example #4
0
def api_create_zip_release(token: APIToken, package: Package, title: str, file,
		min_v: MinetestRelease = None, max_v: MinetestRelease = None, reason="API", commit_hash:str=None):
	if not token.canOperateOnPackage(package):
		error(403, "API token does not have access to the package")

	reason += ", token=" + token.name

	rel = guard(do_create_zip_release)(token.owner, package, title, file, min_v, max_v, reason, commit_hash)

	return jsonify({
		"success": True,
		"task": url_for("tasks.check", id=rel.task_id),
		"release": rel.getAsDictionary()
	})
Example #5
0
def order_screenshots(token: APIToken, package: Package):
    if not token:
        error(401, "Authentication needed")

    if not package.checkPerm(token.owner, Permission.ADD_SCREENSHOTS):
        error(403, "You do not have the permission to delete screenshots")

    if not token.canOperateOnPackage(package):
        error(403, "API token does not have access to the package")

    json = request.json
    if json is None or not isinstance(json, list):
        error(400, "Expected order body to be array")

    return api_order_screenshots(token, package, request.json)
Example #6
0
def delete_release(token: APIToken, package: Package, id: int):
    release = PackageRelease.query.get(id)
    if release is None or release.package != package:
        error(404, "Release not found")

    if not token:
        error(401, "Authentication needed")

    if not token.canOperateOnPackage(package):
        error(403, "API token does not have access to the package")

    if not release.checkPerm(token.owner, Permission.DELETE_RELEASE):
        error(
            403,
            "Unable to delete the release, make sure there's a newer release available"
        )

    db.session.delete(release)
    db.session.commit()

    return jsonify({"success": True})
Example #7
0
def delete_screenshot(token: APIToken, package: Package, id: int):
    ss = PackageScreenshot.query.get(id)
    if ss is None or ss.package != package:
        error(404, "Screenshot not found")

    if not token:
        error(401, "Authentication needed")

    if not package.checkPerm(token.owner, Permission.ADD_SCREENSHOTS):
        error(403, "You do not have the permission to delete screenshots")

    if not token.canOperateOnPackage(package):
        error(403, "API token does not have access to the package")

    if package.cover_image == ss:
        package.cover_image = None
        db.session.merge(package)

    db.session.delete(ss)
    db.session.commit()

    return jsonify({"success": True})