Fix show_if ordering and add a check that fails if misordered
Before this change, these endpoints still existed even if the flag was off
This commit is contained in:
parent
8552f7f6e6
commit
3e8bc07b6c
4 changed files with 16 additions and 4 deletions
|
@ -56,6 +56,7 @@ def resource(*urls, **kwargs):
|
|||
if not api_resource:
|
||||
return None
|
||||
|
||||
api_resource.registered = True
|
||||
api.add_resource(api_resource, *urls, **kwargs)
|
||||
return api_resource
|
||||
return wrapper
|
||||
|
@ -63,6 +64,11 @@ def resource(*urls, **kwargs):
|
|||
|
||||
def show_if(value):
|
||||
def f(inner):
|
||||
if hasattr(inner, 'registered') and inner.registered:
|
||||
msg = ('API endpoint %s is already registered; please switch the ' +
|
||||
'@show_if to be *below* the @resource decorator')
|
||||
raise Exception(msg % inner)
|
||||
|
||||
if not value:
|
||||
return None
|
||||
|
||||
|
@ -72,6 +78,11 @@ def show_if(value):
|
|||
|
||||
def hide_if(value):
|
||||
def f(inner):
|
||||
if hasattr(inner, 'registered') and inner.registered:
|
||||
msg = ('API endpoint %s is already registered; please switch the ' +
|
||||
'@hide_if to be *below* the @resource decorator')
|
||||
raise Exception(msg % inner)
|
||||
|
||||
if value:
|
||||
return None
|
||||
|
||||
|
@ -195,6 +206,7 @@ def parse_repository_name(func):
|
|||
|
||||
|
||||
class ApiResource(Resource):
|
||||
registered = False
|
||||
method_decorators = [check_anon_protection]
|
||||
|
||||
def options(self):
|
||||
|
|
Reference in a new issue