diff --git a/cypress/integration/origin-search.spec.js b/cypress/integration/origin-search.spec.js
--- a/cypress/integration/origin-search.spec.js
+++ b/cypress/integration/origin-search.spec.js
@@ -227,6 +227,17 @@
cy.xhrShouldBeCalled('searchOrigin', 1);
});
+ it('should add query language support for staff users', function() {
+ cy.get('#swh-search-use-ql')
+ .should('not.exist');
+
+ cy.adminLogin();
+ cy.visit(url);
+
+ cy.get('#swh-search-use-ql')
+ .should('exist');
+ });
+
context('Test pagination', function() {
it('should not paginate if there are not many results', function() {
// Setup search
diff --git a/swh/web/browse/urls.py b/swh/web/browse/urls.py
--- a/swh/web/browse/urls.py
+++ b/swh/web/browse/urls.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2019 The Software Heritage developers
+# Copyright (C) 2017-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -6,7 +6,6 @@
from django.conf.urls import url
from django.shortcuts import redirect, render
-from swh.web import config
from swh.web.browse.browseurls import BrowseUrls
from swh.web.browse.identifiers import swhid_browse
import swh.web.browse.views.content # noqa
@@ -30,7 +29,6 @@
"browse/search.html",
{
"heading": "Search software origins to browse",
- "enable_ql": config.get_config()["search_config"].get("enable_ql", False),
"visit_types": origin_visit_types(),
},
)
diff --git a/swh/web/common/archive.py b/swh/web/common/archive.py
--- a/swh/web/common/archive.py
+++ b/swh/web/common/archive.py
@@ -11,7 +11,7 @@
from urllib.parse import urlparse
from swh.model import hashutil
-from swh.model.identifiers import ObjectType, CoreSWHID
+from swh.model.identifiers import CoreSWHID, ObjectType
from swh.model.model import OriginVisit, Revision
from swh.storage.algos import diff, revisions_walker
from swh.storage.algos.origin import origin_get_latest_visit_status
@@ -323,7 +323,7 @@
assert isinstance(page_token, str)
if search:
- if config.get_config()["search_config"].get("enable_ql") and use_ql:
+ if use_ql:
page_result = search.origin_search(
query=url_pattern,
page_token=page_token,
diff --git a/swh/web/config.py b/swh/web/config.py
--- a/swh/web/config.py
+++ b/swh/web/config.py
@@ -44,10 +44,7 @@
),
"search_config": (
"dict",
- {
- "metadata_backend": "swh-indexer-storage", # or "swh-search"
- "enable_ql": False,
- },
+ {"metadata_backend": "swh-indexer-storage",}, # or "swh-search"
),
"log_dir": ("string", "/tmp/swh/log"),
"debug": ("bool", False),
diff --git a/swh/web/templates/includes/origin-search-form.html b/swh/web/templates/includes/origin-search-form.html
--- a/swh/web/templates/includes/origin-search-form.html
+++ b/swh/web/templates/includes/origin-search-form.html
@@ -48,14 +48,18 @@
search in metadata (instead of URL)
- {% if enable_ql %}
-
+ {% if user.is_staff %}
+
{% endif %}
diff --git a/swh/web/tests/api/views/test_origin.py b/swh/web/tests/api/views/test_origin.py
--- a/swh/web/tests/api/views/test_origin.py
+++ b/swh/web/tests/api/views/test_origin.py
@@ -547,11 +547,6 @@
def test_api_origin_search_use_ql(api_client, mocker):
- mock_config = mocker.patch("swh.web.common.archive.config")
- mock_config.get_config.return_value = {
- "search_config": {"metadata_backend": "swh-search", "enable_ql": True}
- }
-
expected_origins = {
"https://github.com/wcoder/highlightjs-line-numbers.js",
"https://github.com/memononen/libtess2",
@@ -564,14 +559,20 @@
results=ORIGINS, next_page_token=None,
)
+ query = "origin = 'github.com'"
+
url = reverse(
"api-1-origin-search",
- url_args={"url_pattern": "origin = 'github.com'",},
+ url_args={"url_pattern": query},
query_params={"visit_type": "git", "use_ql": "true"},
)
rv = check_api_get_responses(api_client, url, status_code=200)
assert {origin["url"] for origin in rv.data} == expected_origins
+ mock_archive_search.origin_search.assert_called_with(
+ query=query, page_token=None, with_visit=False, visit_types=["git"], limit=70
+ )
+
@pytest.mark.parametrize("backend", ["swh-search", "swh-storage"])
@pytest.mark.parametrize("limit", [1, 2, 3, 10])
diff --git a/swh/web/tests/common/test_archive.py b/swh/web/tests/common/test_archive.py
--- a/swh/web/tests/common/test_archive.py
+++ b/swh/web/tests/common/test_archive.py
@@ -4,7 +4,6 @@
# See top-level LICENSE file for more information
from collections import defaultdict
-from copy import deepcopy
import hashlib
import itertools
import random
@@ -28,7 +27,6 @@
from swh.web.common import archive
from swh.web.common.exc import BadInputExc, NotFoundExc
from swh.web.common.typing import OriginInfo, PagedResult
-from swh.web.config import get_config
from swh.web.tests.conftest import ctags_json_missing, fossology_missing
from swh.web.tests.data import random_content, random_sha1
from swh.web.tests.strategies import (
@@ -1026,10 +1024,6 @@
@given(origin())
def test_search_origin_use_ql(mocker, origin):
- config = deepcopy(get_config())
- config["search_config"]["enable_ql"] = True
- mock_get_config = mocker.patch("swh.web.config.get_config")
- mock_get_config.return_value = config
ORIGIN = [{"url": origin["url"]}]
@@ -1038,11 +1032,15 @@
results=ORIGIN, next_page_token=None,
)
- results = archive.search_origin(
- url_pattern=f"origin = '{origin['url']}'", use_ql=True
- )[0]
+ query = f"origin = '{origin['url']}'"
+
+ results = archive.search_origin(url_pattern=query, use_ql=True)[0]
assert results == ORIGIN
+ mock_archive_search.origin_search.assert_called_with(
+ query=query, page_token=None, with_visit=False, visit_types=None, limit=50
+ )
+
@given(snapshot())
def test_lookup_snapshot_sizes(archive_data, snapshot):
diff --git a/swh/web/urls.py b/swh/web/urls.py
--- a/swh/web/urls.py
+++ b/swh/web/urls.py
@@ -38,14 +38,7 @@
def _default_view(request):
- return render(
- request,
- "homepage.html",
- {
- "enable_ql": swh_web_config["search_config"].get("enable_ql", False),
- "visit_types": origin_visit_types(),
- },
- )
+ return render(request, "homepage.html", {"visit_types": origin_visit_types()})
urlpatterns = [