mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-08-20 14:14:30 +00:00
fix(viewer): externalize repos page inline script to comply with CSP (#758)
* move inline scripts from repos.html to repos.js * fixup * fix: include repos.js in embedded assets
This commit is contained in:
parent
3c60eb6af8
commit
6aa3f50033
4 changed files with 21 additions and 22 deletions
|
|
@ -14,7 +14,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
//go:embed templates/*.html static/style.css static/session.js
|
||||
//go:embed templates/*.html static/style.css static/session.js static/repos.js
|
||||
var assets embed.FS
|
||||
|
||||
func StartServer(addr string) error {
|
||||
|
|
|
|||
|
|
@ -84,10 +84,7 @@ func TestRenderTemplate_WithRepos(t *testing.T) {
|
|||
`id="repository-search-input"`,
|
||||
`id="repositories-table"`,
|
||||
"data-repository-name",
|
||||
`addEventListener("input"`,
|
||||
"toLowerCase()",
|
||||
"name.includes(query)",
|
||||
"row.hidden",
|
||||
`src="/static/repos.js"`,
|
||||
} {
|
||||
if !strings.Contains(body, required) {
|
||||
t.Errorf("rendered repository page missing %q", required)
|
||||
|
|
|
|||
18
internal/viewer/static/repos.js
Normal file
18
internal/viewer/static/repos.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2026 alibaba/open-code-review Contributors
|
||||
|
||||
(() => {
|
||||
const input = document.getElementById("repository-search-input");
|
||||
const table = document.getElementById("repositories-table");
|
||||
if (!input || !table) return;
|
||||
|
||||
const rows = table.querySelectorAll("tbody tr");
|
||||
input.addEventListener("input", () => {
|
||||
const query = input.value.trim().toLowerCase();
|
||||
rows.forEach((row) => {
|
||||
const nameCell = row.querySelector("[data-repository-name]");
|
||||
const name = nameCell ? nameCell.textContent.trim().toLowerCase() : "";
|
||||
row.hidden = !name.includes(query);
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
|
@ -28,23 +28,7 @@
|
|||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
<script>
|
||||
(() => {
|
||||
const input = document.getElementById("repository-search-input");
|
||||
const table = document.getElementById("repositories-table");
|
||||
if (!input || !table) return;
|
||||
|
||||
const rows = table.querySelectorAll("tbody tr");
|
||||
input.addEventListener("input", () => {
|
||||
const query = input.value.trim().toLowerCase();
|
||||
rows.forEach((row) => {
|
||||
const nameCell = row.querySelector("[data-repository-name]");
|
||||
const name = nameCell ? nameCell.textContent.trim().toLowerCase() : "";
|
||||
row.hidden = !name.includes(query);
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<script src="/static/repos.js"></script>
|
||||
{{else}}
|
||||
<p>No session data found. Run a code review first.</p>
|
||||
{{end}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue