Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle components/releases subscriptions #354

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@
"UPLOAD SBOM HEADER": "Bitte laden Sie das SBOM-Dokument <strong>{fileFormats</strong> hoch.",
"URL": "URL",
"Unknown": "Unbekannt",
"Unsubscribe": "Abbestellen",
"Update": "Aktualisierung",
"Update Component": "Update Component",
"Update External Link Failed!": "",
Expand Down
1 change: 1 addition & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@
"UPLOAD SBOM HEADER": "Please upload the <strong>{fileFormats}</strong> SBOM document.",
"URL": "URL",
"Unknown": "Unknown",
"Unsubscribe": "Unsubscribe",
"Update": "Update",
"Update Component": "Update Component",
"Update External Link Failed!": "Update External Link Failed!",
Expand Down
1 change: 1 addition & 0 deletions messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@
"UPLOAD SBOM HEADER": "Cargue el documento SBOM <strong>{fileFormats}</strong>.",
"URL": "URL",
"Unknown": "Desconocido",
"Unsubscribe": "Darse de baja",
"Update": "Actualización",
"Update Component": "Componente de actualización",
"Update External Link Failed!": "",
Expand Down
1 change: 1 addition & 0 deletions messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@
"UPLOAD SBOM HEADER": "Veuillez télécharger le document SBOM <strong>{fileFormats></strong>.",
"URL": "URL",
"Unknown": "Inconnu",
"Unsubscribe": "Se désabonner",
"Update": "Mise à jour",
"Update Component": "Composante mise à jour",
"Update External Link Failed!": "",
Expand Down
1 change: 1 addition & 0 deletions messages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@
"UPLOAD SBOM HEADER": "<strong>{fileFormats}</strong> SBOM ドキュメントをアップロードしてください。",
"URL": "URL",
"Unknown": "未知",
"Unsubscribe": "購読を解除する",
"Update": "アップデート",
"Update Component": "コンポーネントの更新",
"Update External Link Failed!": "",
Expand Down
1 change: 1 addition & 0 deletions messages/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@
"UPLOAD SBOM HEADER": "<strong>{fileFormats}</strong> SBOM 문서를 업로드하세요.",
"URL": "사이트 맵",
"Unknown": "이름 *",
"Unsubscribe": "구독 취소",
"Update": "(주)",
"Update Component": "업데이트 구성",
"Update External Link Failed!": "",
Expand Down
1 change: 1 addition & 0 deletions messages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@
"UPLOAD SBOM HEADER": "Faça upload do documento SBOM <strong>{fileFormats}</strong>.",
"URL": "URL",
"Unknown": "Desconhecido",
"Unsubscribe": "Cancelar inscrição",
"Update": "Atualização",
"Update Component": "Atualizar componente",
"Update External Link Failed!": "",
Expand Down
1 change: 1 addition & 0 deletions messages/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@
"UPLOAD SBOM HEADER": "Vui lòng tải lên tài liệu SBOM <strong>{fileFormats</strong>.",
"URL": "URL",
"Unknown": "không xác định",
"Unsubscribe": "Hủy đăng ký",
"Update": "Cập nhật",
"Update Component": "Cập nhật thành phần",
"Update External Link Failed!": "",
Expand Down
1 change: 1 addition & 0 deletions messages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@
"UPLOAD SBOM HEADER": "请上传<strong>{fileFormats}</strong> SBOM 文档。",
"URL": "网址",
"Unknown": "未知",
"Unsubscribe": "退订",
"Update": "更新",
"Update Component": "更新组件",
"Update External Link Failed!": "",
Expand Down
1 change: 1 addition & 0 deletions messages/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@
"UPLOAD SBOM HEADER": "請上傳<strong>{fileFormats}</strong> SBOM 文件。",
"URL": "網址",
"Unknown": "未知",
"Unsubscribe": "退訂",
"Update": "更新",
"Update Component": "更新元件",
"Update External Link Failed!": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import {
Embedded,
HttpStatus,
LinkedVulnerability,
User,
} from '@/object-types'
import DownloadService from '@/services/download.service'
import { ApiUtils, CommonUtils } from '@/utils'
import ReleaseOverview from './ReleaseOverview'
import Summary from './Summary'
import MessageService from '@/services/message.service'

type EmbeddedChangelogs = Embedded<Changelogs, 'sw360:changeLogs'>
type EmbeddedVulnerabilities = Embedded<LinkedVulnerability, 'sw360:vulnerabilityDTOes'>
Expand Down Expand Up @@ -73,6 +75,8 @@ const DetailOverview = ({ componentId }: Props) : ReactNode => {
const [changeLogList, setChangeLogList] = useState<Array<Changelogs>>([])
const [vulnerData, setVulnerData] = useState<Array<LinkedVulnerability>>([])
const [attachmentNumber, setAttachmentNumber] = useState<number>(0)
const [subscribers, setSubscribers] = useState<Array<string>>([])
const [userEmail, setUserEmail] = useState<string | undefined>(undefined)

const fetchData = useCallback(
async (url: string) => {
Expand Down Expand Up @@ -103,11 +107,20 @@ const DetailOverview = ({ componentId }: Props) : ReactNode => {
)
}

const extractUserEmailFromSession = async () => {
const session = await getSession()
if (CommonUtils.isNullOrUndefined(session))
return
setUserEmail(session.user.email)
}

useEffect(() => {
void extractUserEmailFromSession()
fetchData(`components/${componentId}`)
.then((component: Component | undefined) => {
if (component === undefined) return
setComponent(component)
setSubscribers(getSubcribersEmail(component))
if (
!CommonUtils.isNullOrUndefined(component['_embedded']) &&
!CommonUtils.isNullOrUndefined(component['_embedded']['sw360:attachments'])
Expand Down Expand Up @@ -139,11 +152,42 @@ const DetailOverview = ({ componentId }: Props) : ReactNode => {
.catch((err) => console.error(err))
}, [componentId, fetchData])

const getSubcribersEmail = (component: Component) => {
return (component._embedded !== undefined && component._embedded['sw360:subscribers'] !== undefined)
? Object.values(component._embedded['sw360:subscribers'].map((user: User) => user.email))
: []
}

const isUserSubscribed = () => {
if (userEmail === undefined) return false
return subscribers.includes(userEmail)
}

const handleSubcriptions = async () => {
const session = await getSession()
if (CommonUtils.isNullOrUndefined(session)) {
MessageService.error(t('Session has expired'))
return
}
await ApiUtils.POST(`components/${componentId}/subscriptions`, {}, session.user.access_token)
fetchData(`components/${componentId}`)
.then((component: Component | undefined) => {
if (component === undefined) return
setComponent(component)
setSubscribers(getSubcribersEmail(component))
}).catch((e) => console.error(e))
}

const headerButtons = {
Edit: { link: `/components/edit/${componentId}`, type: 'primary', name: t('Edit component') },
Merge: { link: '', type: 'secondary', name: t('Merge') },
Split: { link: '', type: 'secondary', name: t('Split') },
Subscribe: { link: '', type: 'outline-success', name: t('Subscribe') },
Subscribe: {
link: '',
type: isUserSubscribed() ? 'outline-danger' : 'outline-success',
name: isUserSubscribed() ? t('Unsubscribe') : t('Subscribe'),
onClick: handleSubcriptions
}
}

return (
Expand Down
Loading
Loading