Skip to content

Commit

Permalink
frontend: migrate API projects namespace to flask-restx
Browse files Browse the repository at this point in the history
  • Loading branch information
nikromen committed Aug 17, 2023
1 parent 030dd32 commit 8c1c418
Show file tree
Hide file tree
Showing 4 changed files with 382 additions and 169 deletions.
24 changes: 19 additions & 5 deletions frontend/coprs_frontend/coprs/views/apiv3_ns/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import json

import flask
import wtforms
import sqlalchemy
import inspect
from functools import wraps
from werkzeug.datastructures import ImmutableMultiDict, MultiDict
from werkzeug.exceptions import HTTPException, NotFound, GatewayTimeout
from sqlalchemy.orm.attributes import InstrumentedAttribute
from flask_restx import Api, Namespace, Resource
from coprs import app
from flask_restx import Api
from coprs.exceptions import (
AccessRestricted,
ActionInProgressException,
Expand Down Expand Up @@ -234,7 +233,7 @@ def get(self):

def editable_copr(f):
@wraps(f)
def wrapper(ownername, projectname, **kwargs):
def wrapper(ownername, projectname):
copr = get_copr(ownername, projectname)
if not flask.g.user.can_edit(copr):
raise AccessRestricted(
Expand All @@ -244,10 +243,25 @@ def wrapper(ownername, projectname, **kwargs):
'/'.join([ownername, projectname])
)
)
return f(copr, **kwargs)
return f(copr)
return wrapper


# TODO: sync editable_copr decorator with flask-restx once everything's migrated
def get_editable_copr(func):
"""
Apply @editable_copr decorator on endpoints migrated to flask-restx.
"""
@wraps(func)
def editable_copr_getter(*args, ownername, projectname):
def get_copr_from_dec(return_copr_from_decorator):
return return_copr_from_decorator

copr = editable_copr(get_copr_from_dec)(ownername, projectname)
return func(*args, copr)
return editable_copr_getter


def set_defaults(formdata, form_class):
"""
Take a `formdata` which can be `flask.request.form` or an output from
Expand Down
2 changes: 0 additions & 2 deletions frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
from .json2form import get_form_compatible_data




apiv3_builds_ns = Namespace("build", description="Builds")
api.add_namespace(apiv3_builds_ns)

Expand Down
Loading

0 comments on commit 8c1c418

Please sign in to comment.