-
-
-
+
+ {% include 'search-form.html' %}
-
-
-
{% if search_res is not none %}
- {% if search_stats is not none %}
-
- {% endif %}
+ {% if search_stats is not none %}
+
+ {% endif %}
+
File name
@@ -110,8 +40,8 @@
{% endif %}
{% if message is not none and message != '' %}
-
{{ message | safe }}
-
- {% endif %}
+
{{ message | safe }}
+
+{% endif %}
{% endblock %}
diff --git a/swh/web/ui/tests/views/test_browse.py b/swh/web/ui/tests/views/test_browse.py
--- a/swh/web/ui/tests/views/test_browse.py
+++ b/swh/web/ui/tests/views/test_browse.py
@@ -7,6 +7,8 @@
from unittest.mock import patch
+from flask import url_for
+
from swh.web.ui.exc import BadInputExc, NotFoundExc
from .. import test_app
@@ -17,6 +19,100 @@
self.filename = filename
+class SearchRedirectsView(test_app.SWHViewTestCase):
+ render_template = False
+
+ @istest
+ def search_origin_simple(self):
+ # when
+ rv = self.client.get('/origin/search/?origin_id=1&meaningless_arg=42')
+
+ # then
+ self.assertRedirects(rv, url_for('browse_origin', origin_id=1))
+
+ @istest
+ def search_origin_type_url(self):
+ # when
+ rv = self.client.get('/origin/search/?origin_type=git'
+ '&origin_url=http://cool/project/url'
+ '&meaningless_arg=42')
+
+ # then
+ self.assertRedirects(rv, url_for('browse_origin',
+ origin_type='git',
+ origin_url='http://cool/project/url'))
+
+ @istest
+ def search_directory_dir_sha1_only(self):
+ # when
+ rv = self.client.get('/directory/search/?sha1_git=some_sha1'
+ '&meaningless_arg=gandalf')
+
+ # then
+ self.assertRedirects(rv, url_for('browse_directory',
+ sha1_git='some_sha1'))
+
+ @istest
+ def search_directory_dir_sha1(self):
+ # when
+ rv = self.client.get('/directory/search/?sha1_git=some_sha1'
+ '&path=some/path/in/folder'
+ '&meaningless_arg=gandalf')
+
+ # then
+ self.assertRedirects(rv, url_for('browse_directory',
+ sha1_git='some_sha1',
+ path='some/path/in/folder'))
+
+ @istest
+ def search_directory_rev_sha1(self):
+ # when
+ rv = self.client.get('/directory/search/?sha1_git=some_sha1'
+ '&dir_path=some/path/in/folder'
+ '&meaningless_arg=gandalf')
+
+ # then
+ self.assertRedirects(rv, url_for('browse_revision_directory',
+ sha1_git='some_sha1',
+ path='some/path/in/folder'))
+
+ @istest
+ def search_directory_dir_time_place(self):
+ # when
+ rv = self.client.get('/directory/search/?origin_id=42'
+ '&branch_name=refs/heads/tail'
+ '&meaningless_arg=gandalf'
+ '&path=some/path')
+
+ # then
+ self.assertRedirects(rv, url_for(
+ 'browse_revision_directory_through_origin',
+ origin_id=42, branch_name='refs/heads/tail',
+ path='some/path', ts=None))
+
+ @istest
+ def search_revision_sha1(self):
+ # when
+ rv = self.client.get('/revision/search/?sha1_git=some_sha1')
+
+ # then
+ self.assertRedirects(rv, url_for('browse_revision',
+ sha1_git='some_sha1'))
+
+ @istest
+ def search_revision_time_place(self):
+ # when
+ rv = self.client.get('/revision/search/?origin_id=42'
+ '&branch_name=big/branch/on/tree'
+ '&ts=meaningful_ts')
+
+ # then
+ self.assertRedirects(rv, url_for('browse_revision_with_origin',
+ origin_id=42,
+ branch_name='big/branch/on/tree',
+ ts='meaningful_ts'))
+
+
class SearchView(test_app.SWHViewTestCase):
render_template = False
diff --git a/swh/web/ui/views/browse.py b/swh/web/ui/views/browse.py
--- a/swh/web/ui/views/browse.py
+++ b/swh/web/ui/views/browse.py
@@ -15,20 +15,57 @@
hash_filter_keys = ALGORITHMS
-@app.route('/api/1/doc/')
-def api_doc():
- """Render the API's documentation.
- """
- routes = apidoc.APIUrls.get_app_endpoints()
- # Return a list of routes with consistent ordering
- env = {
- 'doc_routes': sorted(routes.items())
- }
- return render_template('api.html', **env)
+@app.route('/origin/search/')
+def search_origin():
+ if request.method == 'GET':
+ data = request.args
+ origin_id = data.get('origin_id')
+ if origin_id:
+ return redirect(url_for('browse_origin', origin_id=origin_id))
+ args = ['origin_type', 'origin_url']
+ values = {arg: data.get(arg) for arg in args if data.get(arg)}
+ if 'origin_type' in values and 'origin_url' in values:
+ return redirect(url_for('browse_origin', **values))
+
+
+@app.route('/directory/search/')
+def search_directory():
+ if request.method == 'GET':
+ data = request.args
+ sha1_git = data.get('sha1_git')
+ if sha1_git:
+ path = data.get('path')
+ if 'dir_path' in data:
+ return redirect(url_for('browse_revision_directory',
+ sha1_git=sha1_git,
+ path=data.get('dir_path')))
+ if path:
+ return redirect(url_for('browse_directory',
+ sha1_git=sha1_git,
+ path=path))
+ return redirect(url_for('browse_directory', sha1_git=sha1_git))
+ args = ['origin_id', 'branch_name', 'ts', 'path']
+ values = {arg: data.get(arg) for arg in args if data.get(arg)}
+ if 'origin_id' in values:
+ return redirect(url_for('browse_revision_directory_through_origin',
+ **values))
+
+
+@app.route('/revision/search/')
+def search_revision():
+ if request.method == 'GET':
+ data = request.args
+ sha1_git = data.get('sha1_git')
+ if sha1_git:
+ return redirect(url_for('browse_revision', sha1_git=sha1_git))
+ args = ['origin_id', 'branch_name', 'ts']
+ values = {arg: data.get(arg) for arg in args if data.get(arg)}
+ if 'origin_id' in values:
+ return redirect(url_for('browse_revision_with_origin', **values))
@app.route('/content/search/', methods=['GET', 'POST'])
-def search():
+def search_content():
"""Search for hashes in swh-storage.
One form to submit either:
@@ -81,6 +118,18 @@
return render_template('search.html', **env)
+@app.route('/api/1/doc/')
+def browse_api_doc():
+ """Render the API's documentation.
+ """
+ routes = apidoc.APIUrls.get_app_endpoints()
+ # Return a list of routes with consistent ordering
+ env = {
+ 'doc_routes': sorted(routes.items())
+ }
+ return render_template('api.html', **env)
+
+
@app.route('/browse/content//')
def browse_content(q):
"""Given a hash and a checksum, display the content's meta-data.