Skip to content

Commit

Permalink
Replace unmaintained flask-restful with flask-restx
Browse files Browse the repository at this point in the history
JIRA: RHELWF-8897
  • Loading branch information
hluk committed Aug 24, 2023
1 parent cb2b0e2 commit 781210d
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 24 deletions.
21 changes: 12 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ python = ">=3.8,<3.11"

flask = "^2.2.5"
flask-oidc = "^1.4.0"
Flask-RESTful = "^0.3.9"
Flask-SQLAlchemy = "^3.0.3"
Flask-Cors = "^4.0.0"
Flask-Migrate = "^4.0.4"
Expand Down Expand Up @@ -83,6 +82,7 @@ markupsafe = {version = "==2.1.3", optional = true}
Werkzeug = {version = "<2.4", optional = true}
pydantic = "^1.10.7"
Flask-Pydantic = "^0.11.0"
flask-restx = "^1.1.0"

[tool.poetry.extras]
test = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""This module contains tests for :mod:`waiverdb.events`."""
from __future__ import unicode_literals
from fedora_messaging import api, testing
from flask_restful import marshal
from flask_restx import marshal
from waiverdb.models import Waiver
from waiverdb.fields import waiver_fields

Expand Down
10 changes: 5 additions & 5 deletions waiverdb/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from flask_oidc import OpenIDConnect
from flask_pydantic import validate
from flask_restful import Resource, Api, marshal_with, marshal
from flask_restx import Resource, Api, marshal_with, marshal
from werkzeug.exceptions import (
BadRequest,
Forbidden,
Expand Down Expand Up @@ -110,7 +110,7 @@ def _verify_authorization(user, testcase):


def _authorization_warning_from_exception(e: Unauthorized, testcase: str):
permissions_url = url_for('api_v1.permissionsresource', testcase=testcase)
permissions_url = url_for('api_v1.permissions_resource', testcase=testcase)
return (
f"{escape(str(e))}<br>"
f"<a href={permissions_url}>See who has permission to"
Expand Down Expand Up @@ -388,7 +388,7 @@ def get(self):
new_waiver_id = request.args.get("new_waiver_id")
new_waiver_url = None
if new_waiver_id is not None:
new_waiver_url = url_for('api_v1.waiverresource', waiver_id=new_waiver_id)
new_waiver_url = url_for('api_v1.waiver_resource', waiver_id=new_waiver_id)
html = render_template(
'new_waiver.html',
warning=warning,
Expand All @@ -409,7 +409,7 @@ def get(self, query: CreateWaiver):
except Unauthorized as e:
error = _authorization_warning_from_exception(e, query.testcase)
url = url_for(
"api_v1.waiversnewresource",
"api_v1.waivers_new_resource",
error=error,
**request.args,
)
Expand All @@ -419,7 +419,7 @@ def get(self, query: CreateWaiver):
db.session.commit()

url = url_for(
"api_v1.waiversnewresource",
"api_v1.waivers_new_resource",
new_waiver_id=result.id,
**request.args,
)
Expand Down
8 changes: 5 additions & 3 deletions waiverdb/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ class Config(object):
SECRET_KEY = 'replace-me-with-something-random' # nosec

RESULTSDB_API_URL = 'https://taskotron.fedoraproject.org/resultsdb_api/api/v2.0'
# need to explicitly turn this off
# https://github.com/flask-restful/flask-restful/issues/449
ERROR_404_HELP = False

# Disable 404 error message with suggestions of other endpoints that
# closely match the requested endpoint.
RESTX_ERROR_404_HELP = False

AUTH_METHOD = 'OIDC' # Specify OIDC, Kerberos or SSL for authentication
OIDC_USERNAME_FIELD = 'preferred_username'
# Set this to True or False to enable publishing to a message bus
Expand Down
2 changes: 1 addition & 1 deletion waiverdb/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import logging
import time

from flask_restful import marshal
from flask_restx import marshal
import stomp
import json
import waiverdb.monitor as monitor
Expand Down
4 changes: 2 additions & 2 deletions waiverdb/fields.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# SPDX-License-Identifier: GPL-2.0+

from flask_restful import fields
from flask_restx import fields

from waiverdb.models.waivers import subject_type_identifier_to_dict


class BackwardsCompatibleSubjectField(fields.Raw):
def output(self, key, obj):
def output(self, key, obj, **kwargs):
waiver = obj
return subject_type_identifier_to_dict(waiver.subject_type, waiver.subject_identifier)

Expand Down
2 changes: 1 addition & 1 deletion waiverdb/templates/new_waiver.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{% if new_waiver_url %}
<div class="alert alert-success" role="alert"><a href="{{ new_waiver_url | safe }}">New waiver created.</a></div>
{% endif %}
<form method="get" action="{{ url_for('api_v1.waiverscreateresource') }}">
<form method="get" action="{{ url_for('api_v1.waivers_create_resource') }}">
<div class="mb-3">
<label for="subject_type" class="form-label">Subject Type</label>
<input type="text" class="form-control" name="subject_type"
Expand Down
2 changes: 1 addition & 1 deletion waiverdb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import functools
import stomp
from flask import request, url_for, jsonify, current_app
from flask_restful import marshal
from flask_restx import marshal
from waiverdb.fields import waiver_fields
from werkzeug.exceptions import NotFound, HTTPException
from contextlib import contextmanager
Expand Down

0 comments on commit 781210d

Please sign in to comment.