fix(licenses): confirm a licence before its review; one row per package (#571)
This commit is contained in:
1 parent
41c337138d
commit
99ce3675b2
4 files changed
+127
-14
No files matched your search
@@ -424,6 +424,19 @@ async fn judged_components(
|
||||
(entries, policy)
|
||||
}
|
||||
|
||||
/// Whether a legal review can decide about `entry`: a licence was confirmed
|
||||
/// for it, or the scan found an SPDX licence that a review confirms as it is.
|
||||
/// Anything else needs its licence confirmed first.
|
||||
fn decidable(entry: &SbomEntry) -> bool {
|
||||
entry.concluded.is_some()
|
||||
|| entry
|
||||
.license
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|l| !l.is_empty())
|
||||
.is_some_and(|l| spdx_license::is_spdx_expression(&spdx_license::normalise(l)))
|
||||
}
|
||||
|
||||
/// The query of [`check`] and [`notices`].
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CheckQuery {
|
||||
@@ -443,7 +456,11 @@ pub async fn check(
|
||||
let db = tenant_db(&agent, &tenant).await?;
|
||||
let (entries, policy) = judged_components(&db, query.repo_id.as_deref()).await;
|
||||
let mut counts = VerdictCounts::default();
|
||||
let mut items = Vec::new();
|
||||
// One row per package and version: a confirmation and a review are made
|
||||
// for the package, whichever target it is in.
|
||||
let mut items: Vec<serde_json::Value> = Vec::new();
|
||||
let mut rows: std::collections::HashMap<(String, String, String), usize> =
|
||||
std::collections::HashMap::new();
|
||||
for e in &entries {
|
||||
let Some(verdict) = e.policy.as_ref() else {
|
||||
continue;
|
||||
@@ -456,11 +473,21 @@ pub async fn check(
|
||||
if !(verdict.is_open() || expiring || verdict.required != PolicyAction::Allow) {
|
||||
continue;
|
||||
}
|
||||
let row = (e.package_manager.clone(), e.name.clone(), e.version.clone());
|
||||
if let Some(&at) = rows.get(&row) {
|
||||
if let Some(item) = items.get_mut(at) {
|
||||
let targets = item["targets"].as_u64().unwrap_or(1);
|
||||
item["targets"] = serde_json::json!(targets + 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if items.len() >= MAX_CHECK_ITEMS {
|
||||
continue;
|
||||
}
|
||||
rows.insert(row, items.len());
|
||||
items.push(serde_json::json!({
|
||||
"repo_id": e.repo_id,
|
||||
"targets": 1,
|
||||
"name": e.name,
|
||||
"version": e.version,
|
||||
"package_manager": e.package_manager,
|
||||
@@ -469,6 +496,7 @@ pub async fn check(
|
||||
"detected": e.license,
|
||||
"conclusion_id": e.concluded.as_ref().map(|c| c.id.clone()),
|
||||
"review": e.concluded.as_ref().and_then(|c| c.review.clone()),
|
||||
"decidable": decidable(e),
|
||||
"verdict": verdict,
|
||||
}));
|
||||
}
|
||||
@@ -487,6 +515,8 @@ pub async fn check(
|
||||
"truncated": listed >= MAX_CHECK_ITEMS,
|
||||
"policy": policy,
|
||||
"may_decide": may_decide(&tenant),
|
||||
"may_confirm": tenant.0.api_key.is_none()
|
||||
&& tenant.0.product_access() == compliance_core::ProductAccess::Full,
|
||||
}
|
||||
})))
|
||||
}
|
||||
@@ -932,4 +962,25 @@ mod tests {
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_a_confirmed_or_spdx_licence_can_be_decided() {
|
||||
let entry = |license: Option<&str>| {
|
||||
let mut e = SbomEntry::new("r".into(), "lib".into(), "1".into(), "npm".into());
|
||||
e.license = license.map(String::from);
|
||||
e
|
||||
};
|
||||
assert!(decidable(&entry(Some("Apache License, Version 2.0"))));
|
||||
assert!(decidable(&entry(Some("MIT OR GPL-3.0-only"))));
|
||||
assert!(!decidable(&entry(None)));
|
||||
assert!(!decidable(&entry(Some(
|
||||
"http://go.microsoft.com/fwlink/?LinkID=262998"
|
||||
))));
|
||||
let mut confirmed = entry(None);
|
||||
confirmed.concluded = conclusions_of(req(Some("MIT"), None), &tenant())
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.next();
|
||||
assert!(decidable(&confirmed));
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ use compliance_core::models::license_policy::{
|
||||
};
|
||||
use compliance_core::models::{LegalReview, LicenseCategory, LicensePolicy, LicenseVerdict};
|
||||
|
||||
use crate::components::license_editor::category_class;
|
||||
use crate::components::license_editor::{category_class, LicenseEditor};
|
||||
use crate::components::toast::{ToastType, Toasts};
|
||||
use crate::i18n::texts::{common, license_edit as lx, license_review as tx};
|
||||
use crate::i18n::{use_lang, Lang};
|
||||
@@ -107,6 +107,8 @@ pub fn LicenseCheckPanel(
|
||||
// The components a decision is being made for, and which decision.
|
||||
let mut deciding = use_signal(|| Option::<(Vec<LicenseTarget>, ReviewDecision)>::None);
|
||||
let mut policy_open = use_signal(|| false);
|
||||
// The component whose licence is being confirmed before a review.
|
||||
let mut confirming = use_signal(|| Option::<LicenseTarget>::None);
|
||||
let mut notices_busy = use_signal(|| false);
|
||||
|
||||
// Copies of the handles, so the closure only reads what it captures
|
||||
@@ -124,6 +126,8 @@ pub fn LicenseCheckPanel(
|
||||
Some(Ok(resp)) => {
|
||||
let data = resp.data.clone();
|
||||
let may = data.may_decide;
|
||||
let may_confirm = data.may_confirm;
|
||||
let acts = may || may_confirm;
|
||||
let counts = data.counts.clone();
|
||||
let summary = tx::SUMMARY
|
||||
.get(lang)
|
||||
@@ -134,7 +138,7 @@ pub fn LicenseCheckPanel(
|
||||
let open: Vec<LicenseCheckItem> = data.items.clone();
|
||||
let reviewable: Vec<LicenseCheckItem> = open
|
||||
.iter()
|
||||
.filter(|i| i.verdict.action == PolicyAction::Review)
|
||||
.filter(|i| i.verdict.action == PolicyAction::Review && i.decidable)
|
||||
.cloned()
|
||||
.collect();
|
||||
let all_keys: Vec<String> = reviewable.iter().map(LicenseCheckItem::key).collect();
|
||||
@@ -195,7 +199,7 @@ pub fn LicenseCheckPanel(
|
||||
th { {tx::LICENSE.get(lang)} }
|
||||
th { {tx::STATUS.get(lang)} }
|
||||
th { {tx::WHY.get(lang)} }
|
||||
if may { th {} }
|
||||
if acts { th {} }
|
||||
}
|
||||
}
|
||||
tbody {
|
||||
@@ -207,6 +211,9 @@ pub fn LicenseCheckPanel(
|
||||
let target = item.target();
|
||||
let approve_target = target.clone();
|
||||
let reject_target = target.clone();
|
||||
let confirm_target = target.clone();
|
||||
let decidable = item.decidable;
|
||||
let in_targets = item.targets;
|
||||
let review = item.review.clone();
|
||||
let undo_id = item.conclusion_id.clone().filter(|_| review.is_some());
|
||||
let action = item.verdict.action;
|
||||
@@ -215,7 +222,7 @@ pub fn LicenseCheckPanel(
|
||||
tr { key: "{row_key}",
|
||||
if may {
|
||||
td {
|
||||
if action == PolicyAction::Review {
|
||||
if action == PolicyAction::Review && decidable {
|
||||
input {
|
||||
r#type: "checkbox",
|
||||
checked: checked,
|
||||
@@ -237,6 +244,11 @@ pub fn LicenseCheckPanel(
|
||||
if !item.version.is_empty() {
|
||||
span { class: "license-check-version", " {item.version}" }
|
||||
}
|
||||
if in_targets > 1 {
|
||||
span { class: "license-check-version",
|
||||
{format!(" · {}", tx::IN_TARGETS.get(lang).replace("{n}", &in_targets.to_string()))}
|
||||
}
|
||||
}
|
||||
}
|
||||
td {
|
||||
span { class: "sbom-license-badge {category_class(category)}",
|
||||
@@ -255,23 +267,34 @@ pub fn LicenseCheckPanel(
|
||||
}
|
||||
}
|
||||
td { class: "license-check-why", "{reasons_text(&item.verdict, lang)}" }
|
||||
if may {
|
||||
if acts {
|
||||
td { class: "license-check-actions",
|
||||
if action == PolicyAction::Review {
|
||||
if !decidable && may_confirm {
|
||||
button {
|
||||
class: "btn btn-secondary btn-sm",
|
||||
title: tx::CONFIRM_FIRST_HINT.get(lang),
|
||||
onclick: move |_| confirming.set(Some(confirm_target.clone())),
|
||||
{tx::CONFIRM_FIRST.get(lang)}
|
||||
}
|
||||
}
|
||||
if !decidable && !may_confirm {
|
||||
span { class: "license-check-version", {tx::CONFIRM_FIRST_OTHERS.get(lang)} }
|
||||
}
|
||||
if may && decidable && action == PolicyAction::Review {
|
||||
button {
|
||||
class: "btn btn-primary btn-sm",
|
||||
onclick: move |_| deciding.set(Some((vec![approve_target.clone()], ReviewDecision::Approved))),
|
||||
{tx::APPROVE.get(lang)}
|
||||
}
|
||||
}
|
||||
if review.is_none() {
|
||||
if may && decidable && review.is_none() {
|
||||
button {
|
||||
class: "btn btn-ghost btn-sm",
|
||||
onclick: move |_| deciding.set(Some((vec![reject_target.clone()], ReviewDecision::Rejected))),
|
||||
{tx::REJECT.get(lang)}
|
||||
}
|
||||
}
|
||||
if let Some(id) = undo_id {
|
||||
if let Some(id) = undo_id.filter(|_| may) {
|
||||
button {
|
||||
class: "btn btn-ghost btn-sm",
|
||||
onclick: move |_| {
|
||||
@@ -361,6 +384,18 @@ pub fn LicenseCheckPanel(
|
||||
}
|
||||
{body}
|
||||
}
|
||||
if let Some(component) = confirming() {
|
||||
LicenseEditor {
|
||||
components: vec![component],
|
||||
existing: None,
|
||||
on_close: move |saved: bool| {
|
||||
confirming.set(None);
|
||||
if saved {
|
||||
reload();
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
if let Some((components, decision)) = deciding() {
|
||||
ReviewDialog {
|
||||
components,
|
||||
|
||||
@@ -4087,6 +4087,22 @@ pub mod license_review {
|
||||
de: "Entscheidung zurücknehmen",
|
||||
en: "Withdraw decision",
|
||||
};
|
||||
pub const CONFIRM_FIRST: Text = Text {
|
||||
de: "Lizenz bestätigen",
|
||||
en: "Confirm licence",
|
||||
};
|
||||
pub const CONFIRM_FIRST_HINT: Text = Text {
|
||||
de: "Für diese Komponente ist keine Lizenz bekannt. Bestätigen Sie zuerst ihre Lizenz; danach kann sie freigegeben oder abgelehnt werden.",
|
||||
en: "No licence is known for this component. Confirm its licence first; then it can be approved or rejected.",
|
||||
};
|
||||
pub const CONFIRM_FIRST_OTHERS: Text = Text {
|
||||
de: "Lizenz zuerst bestätigen (IT_ADMIN oder USER)",
|
||||
en: "Licence to be confirmed first (IT_ADMIN or USER)",
|
||||
};
|
||||
pub const IN_TARGETS: Text = Text {
|
||||
de: "in {n} Prüfobjekten",
|
||||
en: "in {n} targets",
|
||||
};
|
||||
pub const APPROVE_SELECTED: Text = Text {
|
||||
de: "Auswahl freigeben",
|
||||
en: "Approve selection",
|
||||
|
||||
@@ -149,9 +149,20 @@ pub struct LicenseCheckItem {
|
||||
pub conclusion_id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub review: Option<compliance_core::models::LegalReview>,
|
||||
/// Whether a legal review can decide about it; otherwise its licence
|
||||
/// has to be confirmed first.
|
||||
#[serde(default)]
|
||||
pub decidable: bool,
|
||||
/// In how many targets the package is (one row for all of them).
|
||||
#[serde(default = "one")]
|
||||
pub targets: u64,
|
||||
pub verdict: compliance_core::models::LicenseVerdict,
|
||||
}
|
||||
|
||||
fn one() -> u64 {
|
||||
1
|
||||
}
|
||||
|
||||
impl LicenseCheckItem {
|
||||
/// The component, for a review.
|
||||
pub fn target(&self) -> LicenseTarget {
|
||||
@@ -164,12 +175,9 @@ impl LicenseCheckItem {
|
||||
}
|
||||
}
|
||||
|
||||
/// A key unique in the list.
|
||||
/// A key unique in the list: one row per package and version.
|
||||
pub fn key(&self) -> String {
|
||||
format!(
|
||||
"{}|{}|{}|{}",
|
||||
self.repo_id, self.package_manager, self.name, self.version
|
||||
)
|
||||
format!("{}|{}|{}", self.package_manager, self.name, self.version)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +193,9 @@ pub struct LicenseCheckData {
|
||||
/// Whether the requester may decide reviews and change the policy.
|
||||
#[serde(default)]
|
||||
pub may_decide: bool,
|
||||
/// Whether the requester may confirm licences (IT_ADMIN, USER).
|
||||
#[serde(default)]
|
||||
pub may_confirm: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
|
||||
Reference in new issue
Block a user