web: use GET for ident search form
With POST, if Anubis triggers on search request, user will be redirected back to home page.
This commit is contained in:
parent
11b6632d5d
commit
5ff8c70166
2 changed files with 22 additions and 14 deletions
|
|
@ -271,34 +271,42 @@ def stringify_ident_path(project, version, family, ident) -> str:
|
||||||
path = f'{ get_ident_base_url(project, version, family) }/{ parse.quote(ident, safe="") }'
|
path = f'{ get_ident_base_url(project, version, family) }/{ parse.quote(ident, safe="") }'
|
||||||
return path.rstrip('/')
|
return path.rstrip('/')
|
||||||
|
|
||||||
# Handles redirect on a POST to ident resource
|
# Handles redirect from ident with form (POST/GET with query parameters)
|
||||||
|
# to default ident URL format
|
||||||
class IdentPostRedirectResource:
|
class IdentPostRedirectResource:
|
||||||
def on_get(self, req, resp, project, version, family=None, ident=None):
|
def on_get(self, req, resp, project: str, version: str, family: str|None = None, _ident: str|None = None):
|
||||||
project, version, _ = validate_project_and_version(req.context, project, version)
|
get_ident = req.get_param('i', required=False)
|
||||||
resp.status = falcon.HTTP_FOUND
|
get_family = req.get_param('f', required=False)
|
||||||
resp.location = stringify_source_path(project, version, "")
|
if get_ident is None:
|
||||||
|
project, version, _ = validate_project_and_version(req.context, project, version)
|
||||||
|
resp.status = falcon.HTTP_FOUND
|
||||||
|
resp.location = stringify_source_path(project, version, "")
|
||||||
|
else:
|
||||||
|
return self.handle(req, resp, project, version, get_ident, get_family)
|
||||||
|
|
||||||
def on_post(self, req, resp, project: str, version: str, family: str|None = None, _ident: str|None = None):
|
def on_post(self, req, resp, project: str, version: str, family: str|None = None, _ident: str|None = None):
|
||||||
project, version, query = validate_project_and_version(req.context, project, version)
|
|
||||||
|
|
||||||
form = req.get_media()
|
form = req.get_media()
|
||||||
post_ident = form.get('i')
|
post_ident = form.get('i')
|
||||||
post_family = form.get('f')
|
post_family = form.get('f')
|
||||||
|
return self.handle(req, resp, project, version, post_ident, post_family)
|
||||||
|
|
||||||
if not validFamily(post_family):
|
def handle(self, req, resp, project: str, version: str, ident: str, family: str):
|
||||||
post_family = 'C'
|
project, version, query = validate_project_and_version(req.context, project, version)
|
||||||
|
|
||||||
if not post_ident:
|
if not validFamily(family):
|
||||||
|
family = 'C'
|
||||||
|
|
||||||
|
if not ident:
|
||||||
raise ElixirProjectError('Error', 'Invalid identifier',
|
raise ElixirProjectError('Error', 'Invalid identifier',
|
||||||
project=project, version=version, query=query,
|
project=project, version=version, query=query,
|
||||||
extra_template_args={
|
extra_template_args={
|
||||||
'searched_ident': parse.unquote(form.get('i')),
|
'searched_ident': parse.unquote(ident),
|
||||||
'current_family': family,
|
'current_family': family,
|
||||||
})
|
})
|
||||||
|
|
||||||
post_ident = post_ident.strip()
|
ident = ident.strip()
|
||||||
resp.status = falcon.HTTP_MOVED_PERMANENTLY
|
resp.status = falcon.HTTP_MOVED_PERMANENTLY
|
||||||
resp.location = stringify_ident_path(project, version, post_family, post_ident)
|
resp.location = stringify_ident_path(project, version, family, ident)
|
||||||
|
|
||||||
query.close()
|
query.close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div class="search">
|
<div class="search">
|
||||||
<form method="post" action="{{ ident_base_url }}" id="search-form">
|
<form method="GET" action="{{ ident_base_url }}" id="search-form">
|
||||||
<select name="f" title="Restricts search to specific file families">
|
<select name="f" title="Restricts search to specific file families">
|
||||||
{% for id, description in topbar_families.items() %}
|
{% for id, description in topbar_families.items() %}
|
||||||
<option value="{{ id }}" {{ 'selected' if (current_family == id or current_family is not defined) else '' }}>
|
<option value="{{ id }}" {{ 'selected' if (current_family == id or current_family is not defined) else '' }}>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue