From fa12923d5b3585b5dd2a5b43565254433c3f22f9 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Nov 02 2023 22:29:57 +0000
Subject: [PATCH 1/4] handle some basic module filters


---

diff --git a/mbsweb/__init__.py b/mbsweb/__init__.py
index 440dc5c..8f0d678 100644
--- a/mbsweb/__init__.py
+++ b/mbsweb/__init__.py
@@ -3,7 +3,10 @@ from .util import config_from_env
 
 
 def url_for_self(**args):
-    return url_for(request.endpoint, **dict(request.view_args, **args))
+    kwargs = dict(**request.args)
+    kwargs.update(request.view_args)
+    kwargs.update(args)
+    return url_for(request.endpoint, **kwargs)
 
 
 def create_app(test_config=None):
diff --git a/mbsweb/ui.py b/mbsweb/ui.py
index 1c8d142..087e79c 100644
--- a/mbsweb/ui.py
+++ b/mbsweb/ui.py
@@ -44,6 +44,18 @@ def module_list(page=None):
     per_page = 50
     page_arg = f'&page={page}' if page else ''
     api_url = f'{current_app.config["MBS_API"]}/module-builds/?short=True&per_page={per_page}{page_arg}'
+    allowed_filters = (
+            'name',
+            'stream',
+            'version',
+            'context',
+            'scmurl',
+            'scratch',
+            'owner',
+            )
+    for key in allowed_filters:
+        if key in request.args:
+            api_url += f'&{key}={request.args[key]}'  # XXX
     r = requests.get(api_url)
     r.raise_for_status()
     data = r.json()

From ccb0f5aaea4e08401a316705d8717ac9a3dff57f Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Nov 02 2023 22:38:26 +0000
Subject: [PATCH 2/4] ui links for name filter


---

diff --git a/mbsweb/templates/module.html b/mbsweb/templates/module.html
index bf4905d..8af5eef 100644
--- a/mbsweb/templates/module.html
+++ b/mbsweb/templates/module.html
@@ -47,7 +47,11 @@
                 <td>ID</td>
                 <td><a href="{{ config['MBS_API'] }}/module-builds/{{ info.id|urlencode }}">{{ info.id }}</a></td>
             </tr>
-            {% for key in "name", "stream", "version", "context", "owner", "scmurl", "scratch", "rebuild_strategy"  %}
+            <tr>
+                <td>Name</td>
+                <td><a href="{{ url_for('ui.module_list', name=info.name) }}">{{ info.name }}</a></td>
+            </tr>
+            {% for key in "stream", "version", "context", "owner", "scmurl", "scratch", "rebuild_strategy"  %}
             <tr>
                 <td>{{ key|capitalize }}</td>
                 <td>{{ info.get(key) }}</td>
diff --git a/mbsweb/templates/modules.html b/mbsweb/templates/modules.html
index a3ea226..65b27a4 100644
--- a/mbsweb/templates/modules.html
+++ b/mbsweb/templates/modules.html
@@ -18,7 +18,7 @@
             {% for mod in modules  %}
             <tr class="table-bordered">
                 <td><a href="{{ url_for('ui.module_info', moduleid=mod.id) }}">{{ mod.id }}</a></td>
-                <td>{{ mod.name }}</td>
+                <td><a href="{{ url_for('ui.module_list', name=mod.name) }}">{{ mod.name }}</a></td>
                 <td>{{ mod.stream }}</td>
                 <td>{{ mod.version }}</td>
                 <td>{{ mod.context }}</td>

From 0dfc2d7caebaeb2ff0f337b41d0a81d7fba2a3e3 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Nov 03 2023 15:45:29 +0000
Subject: [PATCH 3/4] encode api url args


---

diff --git a/mbsweb/ui.py b/mbsweb/ui.py
index 087e79c..abe9a92 100644
--- a/mbsweb/ui.py
+++ b/mbsweb/ui.py
@@ -1,3 +1,5 @@
+from urllib.parse import quote_plus
+
 from flask import Flask, abort, redirect, url_for, render_template, request, Blueprint
 
 from flask import current_app  # for config
@@ -55,7 +57,7 @@ def module_list(page=None):
             )
     for key in allowed_filters:
         if key in request.args:
-            api_url += f'&{key}={request.args[key]}'  # XXX
+            api_url += f'&{key}={quote_plus(request.args[key])}'
     r = requests.get(api_url)
     r.raise_for_status()
     data = r.json()

From dba63aeadd59bb2ecfda135b8b0a04bb497cd4a2 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: Nov 03 2023 17:55:32 +0000
Subject: [PATCH 4/4] add a few more helpful query links


---

diff --git a/mbsweb/templates/module.html b/mbsweb/templates/module.html
index 8af5eef..5e14ee4 100644
--- a/mbsweb/templates/module.html
+++ b/mbsweb/templates/module.html
@@ -51,7 +51,17 @@
                 <td>Name</td>
                 <td><a href="{{ url_for('ui.module_list', name=info.name) }}">{{ info.name }}</a></td>
             </tr>
-            {% for key in "stream", "version", "context", "owner", "scmurl", "scratch", "rebuild_strategy"  %}
+            {% for key in "stream", "version", "context" %}
+            <tr>
+                <td>{{ key|capitalize }}</td>
+                <td><a href="{{ url_for('ui.module_list', name=info.name, **{key:info[key]}) }}">{{ info[key] }}</a></td>
+            </tr>
+            {% endfor %}
+            <tr>
+                <td>Owner</td>
+                <td><a href="{{ url_for('ui.module_list', owner=info.owner) }}">{{ info.owner }}</a></td>
+            </tr>
+            {% for key in "scmurl", "scratch", "rebuild_strategy" %}
             <tr>
                 <td>{{ key|capitalize }}</td>
                 <td>{{ info.get(key) }}</td>

