diff --git a/messages/de.json b/messages/de.json index cfdd29014..3d01e9853 100644 --- a/messages/de.json +++ b/messages/de.json @@ -421,6 +421,8 @@ "Do you really want to delete this client": "Möchten Sie diesen Kunden wirklich löschen?", "Do you really want to delete this obligation": "Möchten Sie diese Verpflichtung wirklich löschen?", "Do you really want to export SBOM": "Möchten Sie SBOM wirklich für das Projekt {ProjectName} ( {ProjectVersion} ) exportieren?", + "Do you really want to import all OSADL license obligations": "Möchten Sie wirklich alle OSADL -Lizenzverpflichtungen importieren?", + "Do you really want to import all SPDX all licenses": "Möchten Sie wirklich alle SPDX alle Lizenzen importieren", "Do you really want to import department": "Möchten Sie die Abteilung wirklich importieren?", "Do you really want to remove the link to release": "Möchten Sie den Link zur Veröffentlichung wirklich entfernen?", "Document Id": "Dokument Id", @@ -664,9 +666,11 @@ "Import Error": "SBOM konnte nicht importiert werden: {fileName}", "Import Export": "Einfuhr und Ausfuhr", "Import OSADL Information": "OSADL Informationen importieren", + "Import OSADL license obligations": "OSADL -Lizenzverpflichtungen importieren", "Import Obligation Element": "Import -Verpflichtungselement", "Import SBOM": "Import SBOM", "Import SPDX Information": "Import SPDX Informationen", + "Import SPDX licenses": "SPDX -Lizenzen importieren", "Importing": "Import", "Importing SBOM file": "SBOM -Datei importieren", "Importing departments": "Importabteilungen", diff --git a/messages/en.json b/messages/en.json index df86e8715..57098a0fd 100644 --- a/messages/en.json +++ b/messages/en.json @@ -421,6 +421,8 @@ "Do you really want to delete this client": "Do you really want to delete this client", "Do you really want to delete this obligation": "Do you really want to delete this obligation", "Do you really want to export SBOM": "Do you really want to export SBOM for the project {projectName} ({projectVersion})?", + "Do you really want to import all OSADL license obligations": "Do you really want to import all OSADL license obligations", + "Do you really want to import all SPDX all licenses": "Do you really want to import all SPDX all licenses", "Do you really want to import department": "Do you really want to import department", "Do you really want to remove the link to release": "Do you really want to remove the link to release", "Document Id": "Document Id", @@ -664,9 +666,11 @@ "Import Error": "Failed to import SBOM: {fileName}", "Import Export": "Import & Export", "Import OSADL Information": "Import OSADL Information", + "Import OSADL license obligations": "Import OSADL license obligations", "Import Obligation Element": "Import Obligation Element", "Import SBOM": "Import SBOM", "Import SPDX Information": "Import SPDX Information", + "Import SPDX licenses": "Import SPDX licenses", "Importing": "Importing", "Importing SBOM file": "Importing of SBOM file is in progress", "Importing departments": "Importing departments", diff --git a/messages/es.json b/messages/es.json index 62f6031c0..2f2f5fb0c 100644 --- a/messages/es.json +++ b/messages/es.json @@ -421,6 +421,8 @@ "Do you really want to delete this client": "¿De verdad quieres eliminar este cliente?", "Do you really want to delete this obligation": "¿De verdad quieres eliminar esta obligación?", "Do you really want to export SBOM": "¿Realmente quieres exportar SBOM para el proyecto {ProjectName} ( {ProjectVersion} )?", + "Do you really want to import all OSADL license obligations": "¿Realmente quieres importar todas las obligaciones de licencia de OSADL?", + "Do you really want to import all SPDX all licenses": "¿Realmente quieres importar todas las licencias SPDX?", "Do you really want to import department": "¿Realmente quieres importar el departamento?", "Do you really want to remove the link to release": "¿Realmente deseas eliminar el enlace para publicar?", "Document Id": "Documento Id", @@ -664,9 +666,11 @@ "Import Error": "No se pudo importar SBOM: {fileName}", "Import Export": "Importación " Export "", "Import OSADL Information": "Importar OSADL Information", + "Import OSADL license obligations": "Importar obligaciones de licencia OSADL", "Import Obligation Element": "Elemento de obligación de importación", "Import SBOM": "Import SBOM", "Import SPDX Information": "Import SPDX Información", + "Import SPDX licenses": "Importar licencias SPDX", "Importing": "Importador", "Importing SBOM file": "Importación del archivo SBOM", "Importing departments": "Importando departamentos", diff --git a/messages/fr.json b/messages/fr.json index ddd56e7fd..26c0ead6d 100644 --- a/messages/fr.json +++ b/messages/fr.json @@ -421,6 +421,8 @@ "Do you really want to delete this client": "Voulez-vous vraiment supprimer ce client", "Do you really want to delete this obligation": "Voulez-vous vraiment supprimer cette obligation", "Do you really want to export SBOM": "Voulez-vous vraiment exporter SBOM pour le projet {projectName} ( {projectVersion} )?", + "Do you really want to import all OSADL license obligations": "Voulez-vous vraiment importer toutes les obligations de licence OSADL", + "Do you really want to import all SPDX all licenses": "Voulez-vous vraiment importer toutes les licences SPDX toutes", "Do you really want to import department": "Voulez-vous vraiment importer le département", "Do you really want to remove the link to release": "Voulez-vous vraiment supprimer le lien pour publier", "Document Id": "Document Id", @@ -664,9 +666,11 @@ "Import Error": "Échec de l'importation du SBOM : {fileName}", "Import Export": "Importer et exporter", "Import OSADL Information": "Importer des informations OSADL", + "Import OSADL license obligations": "Importer des obligations de licence OSADL", "Import Obligation Element": "Élément d'obligation d'importation", "Import SBOM": "Importer SBOM", "Import SPDX Information": "Importer SPDX Informations", + "Import SPDX licenses": "Importer des licences SPDX", "Importing": "Importation", "Importing SBOM file": "Importation de fichier SBOM", "Importing departments": "Départements d'importation", diff --git a/messages/ja.json b/messages/ja.json index de607ad8a..67bab16ca 100644 --- a/messages/ja.json +++ b/messages/ja.json @@ -421,6 +421,8 @@ "Do you really want to delete this client": "本当にこのクライアントを削除したいですか", "Do you really want to delete this obligation": "あなたは本当にこの義務を削除したいですか?", "Do you really want to export SBOM": "プロジェクトのためにSBOMを本当にエクスポートしたいですか {ProjectName} {Projectersion} )?", + "Do you really want to import all OSADL license obligations": "すべてのOSADLライセンス義務を本当に輸入したいですか", + "Do you really want to import all SPDX all licenses": "あなたは本当にすべてのSPDXすべてのライセンスをインポートしたいですか", "Do you really want to import department": "あなたは本当に部門を輸入したいですか?", "Do you really want to remove the link to release": "本当にリリースへのリンクを削除しますか?", "Document Id": "ドキュメントID", @@ -664,9 +666,11 @@ "Import Error": "SBOM のインポートに失敗しました: {fileName}", "Import Export": "輸入", "Import OSADL Information": "インポートOSADL情報", + "Import OSADL license obligations": "OSADLライセンスの義務を輸入します", "Import Obligation Element": "義務要素を輸入します", "Import SBOM": "SBOMのインポート", "Import SPDX Information": "インポートSPDX インフォメーション", + "Import SPDX licenses": "SPDXライセンスをインポートします", "Importing": "インポート", "Importing SBOM file": "SBOMファイルのインポート", "Importing departments": "輸入部門", diff --git a/messages/ko.json b/messages/ko.json index 4de9105d9..291159351 100644 --- a/messages/ko.json +++ b/messages/ko.json @@ -421,6 +421,8 @@ "Do you really want to delete this client": "이 클라이언트를 정말로 삭제하고 싶습니까?", "Do you really want to delete this obligation": "이 의무를 삭제하고 싶습니까?", "Do you really want to export SBOM": "프로젝트 {projectName} ( {projectVersion} )에 대해 SBOM을 내보내고 싶습니까?", + "Do you really want to import all OSADL license obligations": "모든 OSADL 라이센스 의무를 가져오고 싶습니까?", + "Do you really want to import all SPDX all licenses": "모든 SPDX 모든 라이센스를 가져오고 싶습니까?", "Do you really want to import department": "당신은 정말로 부서를 수입하고 싶습니까?", "Do you really want to remove the link to release": "릴리스 링크를 정말로 제거하시겠습니까?", "Document Id": "문서 Id", @@ -664,9 +666,11 @@ "Import Error": "SBOM을 가져오지 못했습니다: {fileName}", "Import Export": "수입 및 수출", "Import OSADL Information": "OSADL 정보 가져오기", + "Import OSADL license obligations": "OSADL 라이센스 의무를 수입합니다", "Import Obligation Element": "의무 요소 가져 오기", "Import SBOM": "SBOM 소개", "Import SPDX Information": "수입 SPDX - 기타", + "Import SPDX licenses": "SPDX 라이센스를 가져옵니다", "Importing": "가져 오기", "Importing SBOM file": "SBOM 파일 가져 오기", "Importing departments": "수입 부서", diff --git a/messages/pt-BR.json b/messages/pt-BR.json index f81f25854..d3051dbda 100644 --- a/messages/pt-BR.json +++ b/messages/pt-BR.json @@ -421,6 +421,8 @@ "Do you really want to delete this client": "Você realmente quer excluir este cliente", "Do you really want to delete this obligation": "Você realmente quer excluir esta obrigação", "Do you really want to export SBOM": "Deseja realmente exportar o SBOM para o projeto {ProjectName} ( {ProjectVersion} )?", + "Do you really want to import all OSADL license obligations": "Você realmente quer importar todas as obrigações de licença OSADL", + "Do you really want to import all SPDX all licenses": "Você realmente quer importar todas as licenças SPDX todas as", "Do you really want to import department": "Você realmente quer importar departamento", "Do you really want to remove the link to release": "Você realmente deseja remover o link para liberar", "Document Id": "ID do documento", @@ -664,9 +666,11 @@ "Import Error": "Falha ao importar SBOM: {FileName} ", "Import Export": "Importar / Exportar", "Import OSADL Information": "Importar informações OSADL", + "Import OSADL license obligations": "Importar obrigações de licença OSADL", "Import Obligation Element": "Elemento de obrigação de importação", "Import SBOM": "Importar SBOM", "Import SPDX Information": "Import SPDX Information", + "Import SPDX licenses": "Importar licenças SPDX", "Importing": "Importação", "Importing SBOM file": "Importando arquivo SBOM", "Importing departments": "Departamentos de importação", diff --git a/messages/vi.json b/messages/vi.json index b09d65741..b31bb5d02 100644 --- a/messages/vi.json +++ b/messages/vi.json @@ -421,6 +421,8 @@ "Do you really want to delete this client": "Bạn có thực sự muốn xóa máy khách này không", "Do you really want to delete this obligation": "Bạn có thực sự muốn xóa nghĩa vụ này không", "Do you really want to export SBOM": "Bạn có thực sự muốn xuất SBOM cho dự án {ProjectName} ( {chiếu} )?", + "Do you really want to import all OSADL license obligations": "Bạn có thực sự muốn nhập tất cả các nghĩa vụ giấy phép OSADL", + "Do you really want to import all SPDX all licenses": "Bạn có thực sự muốn nhập tất cả SPDX tất cả các giấy phép", "Do you really want to import department": "Bạn có thực sự muốn nhập khẩu bộ phận", "Do you really want to remove the link to release": "Bạn có thực sự muốn xóa liên kết để phát hành", "Document Id": "ID tài liệu", @@ -664,9 +666,11 @@ "Import Error": "Không thể nhập SBOM: {fileName", "Import Export": "Nhập khẩu", "Import OSADL Information": "Nhập thông tin OSADL", + "Import OSADL license obligations": "Nhập nghĩa vụ giấy phép OSADL", "Import Obligation Element": "Nhập yếu tố nghĩa vụ", "Import SBOM": "Nhập khẩu SBOM", "Import SPDX Information": "Nhập thông tin SPDX", + "Import SPDX licenses": "Nhập giấy phép SPDX", "Importing": "Nhập khẩu", "Importing SBOM file": "Nhập tệp SBOM", "Importing departments": "Nhập khẩu phòng ban", diff --git a/messages/zh-CN.json b/messages/zh-CN.json index d2e1bb09c..5c8952bdf 100644 --- a/messages/zh-CN.json +++ b/messages/zh-CN.json @@ -421,6 +421,8 @@ "Do you really want to delete this client": "您真的想删除这个客户吗", "Do you really want to delete this obligation": "您真的想删除这项义务吗", "Do you really want to export SBOM": "您是否真的想为项目 {projectName} {projectversion} )导出SBOM?", + "Do you really want to import all OSADL license obligations": "您真的想进口所有OSADL许可证义务吗", + "Do you really want to import all SPDX all licenses": "您真的想导入所有SPDX所有许可证吗", "Do you really want to import department": "你真的想进口部门吗", "Do you really want to remove the link to release": "您确实要删除要发布的链接吗", "Document Id": "文档编号", @@ -664,9 +666,11 @@ "Import Error": "无法导入 SBOM:{fileName}", "Import Export": "进口", "Import OSADL Information": "导入 OSADL 信息", + "Import OSADL license obligations": "进口OSADL许可义务", "Import Obligation Element": "进口义务要素", "Import SBOM": "导入SBOM", "Import SPDX Information": "导入 SPDX 资料", + "Import SPDX licenses": "进口SPDX许可证", "Importing": "输入", "Importing SBOM file": "导入SBOM文件", "Importing departments": "进口部门", diff --git a/messages/zh-TW.json b/messages/zh-TW.json index b521aa2ab..35b3bf7fc 100644 --- a/messages/zh-TW.json +++ b/messages/zh-TW.json @@ -421,6 +421,8 @@ "Do you really want to delete this client": "您真的想刪除這個客戶嗎", "Do you really want to delete this obligation": "您真的想刪除這項義務嗎", "Do you really want to export SBOM": "您是否真的想為項目 {projectName} {projectversion} )導出SBOM?", + "Do you really want to import all OSADL license obligations": "您真的想進口所有OSADL許可證義務嗎", + "Do you really want to import all SPDX all licenses": "您真的想導入所有SPDX所有許可證嗎", "Do you really want to import department": "你真的想進口部門嗎", "Do you really want to remove the link to release": "您確實要刪除要發布的連結嗎", "Document Id": "文件 ID", @@ -664,9 +666,11 @@ "Import Error": "無法匯入 SBOM:{fileName}", "Import Export": "匯出( E)", "Import OSADL Information": "匯入 OSADL 資訊", + "Import OSADL license obligations": "進口OSADL許可義務", "Import Obligation Element": "進口義務要素", "Import SBOM": "匯入 SBOM", "Import SPDX Information": "匯入 SPDX 信息", + "Import SPDX licenses": "進口SPDX許可證", "Importing": "輸入", "Importing SBOM file": "導入SBOM文件", "Importing departments": "進口部門", diff --git a/src/app/[locale]/admin/licenses/components/LicenseAdministration.tsx b/src/app/[locale]/admin/licenses/components/LicenseAdministration.tsx index 59f92ca3b..fa5e50e62 100644 --- a/src/app/[locale]/admin/licenses/components/LicenseAdministration.tsx +++ b/src/app/[locale]/admin/licenses/components/LicenseAdministration.tsx @@ -9,19 +9,116 @@ 'use client' -import { HttpStatus } from '@/object-types' +import { ErrorDetails, HttpStatus } from '@/object-types' import DownloadService from '@/services/download.service' import MessageService from '@/services/message.service' import { ApiUtils } from '@/utils' import { getSession, signOut } from 'next-auth/react' import { useTranslations } from 'next-intl' -import { ReactNode, useRef, useState } from 'react' +import { Dispatch, ReactNode, SetStateAction, useRef, useState } from 'react' +import { Modal } from 'react-bootstrap' +import { FaRegQuestionCircle } from 'react-icons/fa' import DeleteAllLicenseInformationModal from './DeleteAllLicenseInformationModal' +type ModalType = 'OSADL' | 'SPDX' | undefined + +function ConfirmationModal({ type, setType }: { type: ModalType; setType: Dispatch> }) { + const t = useTranslations('default') + const purpose = type === 'OSADL' ? t('Import OSADL license obligations') : t('Import SPDX licenses') + const confirmation = + type === 'OSADL' + ? t('Do you really want to import all OSADL license obligations') + : t('Do you really want to import all SPDX all licenses') + const url = `licenses/import/${type}` + enum ImportState { + IMPORT, + LOADING, + DONE, + } + const [state, setState] = useState(ImportState.IMPORT) + + const handleImport = async () => { + try { + setState(ImportState.LOADING) + const session = await getSession() + if (!session) { + return signOut() + } + const response = await ApiUtils.POST(url, {}, session.user.access_token) + if (response.status !== HttpStatus.OK) { + const err = (await response.json()) as ErrorDetails + setState(ImportState.IMPORT) + throw new Error(err.message) + } + setState(ImportState.DONE) + } catch (error: unknown) { + if (error instanceof DOMException && error.name === 'AbortError') { + return + } + const message = error instanceof Error ? error.message : String(error) + MessageService.error(message) + } + } + + return ( + setType(undefined)} + backdrop='static' + centered + size='lg' + > + + + {purpose}?{' '} + + + {confirmation}? + + {state === ImportState.DONE ? ( + + ) : ( + + )} + {state !== ImportState.DONE && ( + + )} + + + ) +} + export default function LicenseAdministration(): ReactNode { const t = useTranslations('default') const file = useRef(undefined) const [deleteAllLicenseInformationModal, showDeleteAllLicenseInformationModal] = useState(false) + const [overwriteIfExternalIdMatches, setOverwriteIfExternalIdMatches] = useState(false) + const [overwriteIfIdMatchesEvenWithoutExternalIdMatch, setOverwriteIfIdMatchesEvenWithoutExternalIdMatch] = + useState(false) + const [confirmationModalType, setConfirmationModalType] = useState(undefined) const handleFileChange = (e: React.ChangeEvent) => { const files = e.currentTarget.files @@ -44,18 +141,25 @@ export default function LicenseAdministration(): ReactNode { if (!session) { return signOut() } - const response = await ApiUtils.POST('licenses/upload', formData, session.user.access_token) - if (response.status === HttpStatus.UNAUTHORIZED) { - await signOut() - } else if (response.status === HttpStatus.OK) { + const response = await ApiUtils.POST( + `licenses/upload?overwriteIfExternalIdMatches=${ + overwriteIfExternalIdMatches + }&overwriteIfIdMatchesEvenWithoutExternalIdMatch=${overwriteIfIdMatchesEvenWithoutExternalIdMatch}`, + formData, + session.user.access_token, + ) + if (response.status === HttpStatus.OK) { MessageService.success(t('Licenses uploaded successfully')) } else { - const data = (await response.json()) as object - console.log(data) - MessageService.error(t('Something went wrong')) + const err = (await response.json()) as ErrorDetails + throw new Error(err.message) } - } catch (err) { - console.error(err) + } catch (error) { + if (error instanceof DOMException && error.name === 'AbortError') { + return + } + const message = error instanceof Error ? error.message : String(error) + MessageService.error(message) } } @@ -63,9 +167,13 @@ export default function LicenseAdministration(): ReactNode { try { const session = await getSession() if (!session) return signOut() - DownloadService.download('licenses/downloadLicenses', session, `LicensesBackup.lics`) - } catch (e) { - console.error(e) + void DownloadService.download('licenses/downloadLicenses', session, `LicensesBackup.lics`) + } catch (error) { + if (error instanceof DOMException && error.name === 'AbortError') { + return + } + const message = error instanceof Error ? error.message : String(error) + MessageService.error(message) } } @@ -75,27 +183,31 @@ export default function LicenseAdministration(): ReactNode { show={deleteAllLicenseInformationModal} setShow={showDeleteAllLicenseInformationModal} /> +
@@ -124,6 +236,8 @@ export default function LicenseAdministration(): ReactNode { type='checkbox' className='form-check-input' name='overWriteIfExternalIdsMatch' + checked={overwriteIfExternalIdMatches} + onChange={() => setOverwriteIfExternalIdMatches(!overwriteIfExternalIdMatches)} />