Beispiel #1
0
def logout():
    s = get_session()
    if s is not None:
        api_get(("user", "logout"), session=s, return_errors=True)
        stop_session()

    return redirect("root")
Beispiel #2
0
def version_info(content_type, unique_id, upload_date):
    version = api_get(("package", content_type, unique_id, upload_date))
    package = api_get(("package", content_type, unique_id))

    latest = max(package.get("versions", []), default=None, key=lambda v: v.get("upload-date", ""))
    if latest and latest.get("upload-date", "") == version.get("upload-date", ""):
        latest = None

    upgrade = package.get("replaced-by")
    if upgrade and "unique-id" in upgrade:
        upgrade_info, _ = api_get(("package", content_type, upgrade["unique-id"]), return_errors=True)
        if upgrade_info:
            upgrade.update(upgrade_info)

    for dep in version.get("dependencies", []):
        dep_package, _ = api_get(("package", dep.get("content-type", ""), dep.get("unique-id", "")),
                                 return_errors=True)
        if dep_package:
            dep_version = list(filter(lambda v: v.get("md5sum-partial") == dep.get("md5sum-partial"),
                                      dep_package.get("versions", [])))
            dep.update(dep_package)
            if len(dep_version) == 1:
                dep.update(dep_version[0])

    return template("version_info.html", package=package, version=version, latest=latest)
Beispiel #3
0
def manager_version_info(session, content_type, unique_id, upload_date):
    version = api_get(("package", content_type, unique_id, upload_date), session=session)
    package = api_get(("package", content_type, unique_id), session=session)

    for dep in version.get("dependencies", []):
        dep_package, _ = api_get(("package", dep.get("content-type", ""), dep.get("unique-id", "")),
                                 session=session, return_errors=True)
        if dep_package:
            dep_version = list(filter(lambda v: v.get("md5sum-partial") == dep.get("md5sum-partial"),
                                      dep_package.get("versions", [])))
            dep.update(dep_package)
            if len(dep_version) == 1:
                dep.update(dep_version[0])

    return template("manager_version_info.html", session=session, package=package, version=version)
def package_info(content_type, unique_id):
    package = api_get(("package", content_type, unique_id))

    upgrade = package.get("replaced-by")
    if upgrade and "unique-id" in upgrade:
        upgrade_info, _ = api_get(
            ("package", content_type, upgrade["unique-id"]),
            return_errors=True)
        if upgrade_info:
            upgrade.update(upgrade_info)

    package.setdefault("versions",
                       []).sort(reverse=True,
                                key=lambda v: v.get("upload-date", ""))

    return template("package_info.html", package=package)
Beispiel #5
0
def manager_package_list(session):
    packages = api_get(("package", "self"), session=session)

    for p in packages:
        versions = p.setdefault("versions", [])
        newgame = [
            v for v in versions if v.get("availability", "") == "new-games"
        ]
        p["num-all"] = len(versions)
        p["num-newgame"] = len(newgame)
        p["latest-all"] = max(versions,
                              default=None,
                              key=lambda v: v.get("upload-date", ""))
        p["latest-newgame"] = max(newgame,
                                  default=None,
                                  key=lambda v: v.get("upload-date", ""))

    packages.sort(key=lambda p: p.get("name", ""))
    packages.sort(reverse=True,
                  key=lambda p: p["latest-all"].get("upload-date", "")
                  if p["latest-all"] else "")

    return template("manager_package_list.html",
                    session=session,
                    packages=packages)
Beispiel #6
0
def login():
    s = get_session()
    if s is None:
        s = start_session()

    if s.is_auth:
        return redirect("manager_package_list")
    else:
        answer = api_get(
            ("user", "login"),
            params={
                "method": auth_backend.get("method"),
                "redirect-uri": external_url_for("manager_package_list")
            })

        s.api_token = answer.get("bearer-token")

        if auth_backend.get("method") == "developer":
            api_post(("user", "developer"),
                     json={"username": auth_backend.get("username")},
                     session=s,
                     return_errors=True)

        url = answer.get("authorize-url")
        if url:
            return flask.redirect(url)
        else:
            return redirect("manager_package_list")
def manager_package_info(session, content_type, unique_id):
    package = api_get(("package", content_type, unique_id), session=session)
    package.setdefault("versions",
                       []).sort(reverse=True,
                                key=lambda v: v.get("upload-date", ""))

    return template("manager_package_info.html",
                    session=session,
                    package=package)
Beispiel #8
0
def manager_version_edit(session, content_type, unique_id, upload_date):
    csrf_context = ("manager_version_edit", content_type, unique_id, upload_date)
    version = api_get(("package", content_type, unique_id, upload_date), session=session)
    package = api_get(("package", content_type, unique_id), session=session)
    messages = []

    if flask.request.method == 'POST':
        form = flask.request.form
        valid_csrf = session.validate_csrf_token(form.get("csrf_token"), csrf_context)

        valid_data = True
        changes = dict()
        record_change(changes, version, "name", form.get("name").strip(), True)
        record_change(changes, version, "url", form.get("url").strip(), True)
        record_change(changes, version, "version", form.get("version").strip())
        record_change_compatibility(changes, version, form)
        if not record_change_dependencies(changes, version, form, messages):
            valid_data = False
        record_change_tags(changes, version, form.get("tags"))
        record_change_descripton(changes, version, form.get("description"))

        version.update(changes)
        if not valid_csrf:
            messages.append("CSRF token expired. Please reconfirm your changes.")
        elif valid_data and len(changes):
            _, error = api_put(("package", content_type, unique_id, upload_date), json=changes,
                               session=session, return_errors=True)
            if error:
                messages.append(error)
            else:
                messages.append("Data updated")

    deps_editable = True
    compatibility = get_compatibility(version)

    csrf_token = session.create_csrf_token(csrf_context)
    return template("manager_version_edit.html", session=session, package=package, version=version,
                    compatibility=compatibility, deps_editable=deps_editable,
                    messages=messages, csrf_token=csrf_token)
Beispiel #9
0
def package_list(content_type):
    packages = api_get(("package", content_type))

    for p in packages:
        p["latest"] = max(p.get("versions", []),
                          default=None,
                          key=lambda v: v.get("upload-date", ""))

    packages.sort(key=lambda p: p.get("name", ""))
    packages.sort(reverse=True,
                  key=lambda p: p["latest"].get("upload-date", "")
                  if p["latest"] else "")

    return template("package_list.html",
                    content_type=content_type,
                    packages=packages)
def manager_package_edit(session, content_type, unique_id):
    csrf_context = ("manager_package_edit", content_type, unique_id)
    package = api_get(("package", content_type, unique_id), session=session)
    messages = []

    if flask.request.method == 'POST':
        form = flask.request.form
        valid_csrf = session.validate_csrf_token(form.get("csrf_token"),
                                                 csrf_context)

        changes = dict()
        record_change(changes, package, "name", form.get("name").strip())
        record_change(changes, package, "url", form.get("url").strip())

        tags = form.get("tags").strip().splitlines()
        tags = set(t.strip() for t in tags)
        tags.discard("")
        tags = sorted(tags)
        record_change(changes, package, "tags", tags)

        desc = "\n".join(t.rstrip()
                         for t in form.get("description").strip().splitlines())
        record_change(changes, package, "description", desc)

        package.update(changes)
        if not valid_csrf:
            messages.append(
                "CSRF token expired. Please reconfirm your changes.")
        elif len(changes):
            _, error = api_put(("package", content_type, unique_id),
                               json=changes,
                               session=session,
                               return_errors=True)
            if error:
                messages.append(error)
            else:
                messages.append("Data updated")

    csrf_token = session.create_csrf_token(csrf_context)
    return template("manager_package_edit.html",
                    session=session,
                    package=package,
                    messages=messages,
                    csrf_token=csrf_token)
Beispiel #11
0
def manager_new_package_upload(session, token):
    csrf_context = ("manager_new_package_upload", token)
    version = api_get(("new-package", token), session=session)
    accept_tos = False
    messages = []

    if flask.request.method == 'POST':
        form = flask.request.form
        valid_csrf = session.validate_csrf_token(form.get("csrf_token"), csrf_context)
        accept_tos = form.get("tos", "") == "accepted"

        valid_data = True
        changes = dict()
        record_change(changes, version, "name", form.get("name").strip(), True)
        record_change(changes, version, "url", form.get("url").strip(), True)
        record_change(changes, version, "version", form.get("version").strip())
        if form.get("license", "empty") != "empty":
            record_change(changes, version, "license", form.get("license").strip())
        record_change_compatibility(changes, version, form)
        if not record_change_dependencies(changes, version, form, messages):
            valid_data = False
        record_change_tags(changes, version, form.get("tags"))
        record_change_descripton(changes, version, form.get("description"))

        version.update(changes)
        if not valid_csrf:
            messages.append("CSRF token expired. Please reconfirm your changes.")
        elif valid_data and len(changes):
            _, error = api_put(("new-package", token), json=changes, session=session, return_errors=True)
            if error:
                messages.append(error)
            else:
                # rerun validation
                version = api_get(("new-package", token), session=session)
                messages.append("Data updated")

        new_files = []
        for f in version.get("files", []):
            if form.get("delete_{}".format(f["uuid"])) is not None:
                _, error = api_delete(("new-package", token, f["uuid"]), session=session, return_errors=True)
            else:
                new_files.append(f)
        version["files"] = new_files

        if not accept_tos:
            version.setdefault("errors", []).append("TOS not accepted")

        if accept_tos and valid_data and form.get("publish") is not None:
            _, error = api_put(("new-package", token, "publish"), json=changes, session=session, return_errors=True)
            if error:
                messages.append(error)
            else:
                content_type = version.get("content-type")
                unique_id = version.get("unique-id")
                redirect("manager_package_info", content_type=content_type, unique_id=unique_id)

    content_type = version.get("content-type")
    unique_id = version.get("unique-id")
    if content_type and unique_id:
        package = api_get(("package", content_type, unique_id), session=session)
    else:
        package = None

    deps_editable = True
    compatibility = get_compatibility(version)

    csrf_token = session.create_csrf_token(csrf_context)
    return template("manager_new_package.html", session=session, package=package, version=version,
                    compatibility=compatibility, licenses=_licenses, accept_tos=accept_tos, deps_editable=deps_editable,
                    messages=messages, csrf_token=csrf_token)