Add link to ticket on 404 page

This commit is contained in:
Šesták Vít
2016-12-08 09:31:41 +01:00
parent b4e7bd251e
commit bda2debd6d
2 changed files with 18 additions and 8 deletions

View File

@@ -6,7 +6,7 @@ import com.google.inject.name.Named
import com.ysoft.odc.statistics.{LibDepStatistics, TagStatistics} import com.ysoft.odc.statistics.{LibDepStatistics, TagStatistics}
import com.ysoft.odc.{ArtifactFile, ArtifactItem} import com.ysoft.odc.{ArtifactFile, ArtifactItem}
import controllers.DependencyCheckReportsParser.ResultWithSelection import controllers.DependencyCheckReportsParser.ResultWithSelection
import models.LibraryTag import models.{ExportedVulnerability, LibraryTag}
import org.joda.time.DateTime import org.joda.time.DateTime
import play.api.i18n.MessagesApi import play.api.i18n.MessagesApi
import play.twirl.api.Txt import play.twirl.api.Txt
@@ -146,6 +146,13 @@ class Statistics @Inject() (
} }
def vulnerability(name: String, selectorOption: Option[String]) = ReadAction.async { implicit req => def vulnerability(name: String, selectorOption: Option[String]) = ReadAction.async { implicit req =>
val ticketOptionFuture = vulnerabilityNotificationService.issueTrackerExport.ticketForVulnerability(name)
val issueOptionFuture = ticketOptionFuture.map(ticketOption =>
for{
ticket <- ticketOption
issueTrackerService <- issueTrackerServiceOption
} yield ticket -> issueTrackerService.ticketLink(ticket)
)
val (lastRefreshTime, resultsFuture) = projectReportsProvider.resultsForVersions(versions) val (lastRefreshTime, resultsFuture) = projectReportsProvider.resultsForVersions(versions)
resultsFuture flatMap { allResults => resultsFuture flatMap { allResults =>
select(allResults, selectorOption).fold(Future.successful(notFound())){ selection => select(allResults, selectorOption).fold(Future.successful(notFound())){ selection =>
@@ -158,16 +165,18 @@ class Statistics @Inject() (
vulns.get(name).fold{ vulns.get(name).fold{
for{ for{
vulnOption <- odcService.getVulnerabilityDetails(name) vulnOption <- odcService.getVulnerabilityDetails(name)
issueOption <- issueOptionFuture
} yield Ok(views.html.statistics.vulnerabilityNotFound( // TODO: the not found page might be replaced by some page explaining that there is no project affected by that vulnerability } yield Ok(views.html.statistics.vulnerabilityNotFound( // TODO: the not found page might be replaced by some page explaining that there is no project affected by that vulnerability
name = name, name = name,
projectsWithSelection = selection.projectsWithSelection, projectsWithSelection = selection.projectsWithSelection,
failedProjects = selection.result.failedProjects failedProjects = selection.result.failedProjects,
issueOption = issueOption
)) ))
}{ vulnerableDependencies => }{ vulnerableDependencies =>
for { for {
vulnOption <- odcService.getVulnerabilityDetails(name) vulnOption <- odcService.getVulnerabilityDetails(name)
plainLibs <- librariesService.byPlainLibraryIdentifiers(vulnerableDependencies.flatMap(_.plainLibraryIdentifiers)).map(_.keySet) plainLibs <- librariesService.byPlainLibraryIdentifiers(vulnerableDependencies.flatMap(_.plainLibraryIdentifiers)).map(_.keySet)
ticketOption <- vulnerabilityNotificationService.issueTrackerExport.ticketForVulnerability(name) issueOption <- issueOptionFuture
} yield vulnOption.fold{ } yield vulnOption.fold{
sys.error("The vulnerability is not in the database, you seem to have outdated the local vulnerability database") // TODO: consider fallback or more friendly error message sys.error("The vulnerability is not in the database, you seem to have outdated the local vulnerability database") // TODO: consider fallback or more friendly error message
}{vuln => Ok(views.html.statistics.vulnerability( }{vuln => Ok(views.html.statistics.vulnerability(
@@ -177,10 +186,7 @@ class Statistics @Inject() (
vulnerableDependencies = vulnerableDependencies, vulnerableDependencies = vulnerableDependencies,
affectedLibraries = plainLibs, affectedLibraries = plainLibs,
projectsWithSelection = selection.projectsWithSelection, projectsWithSelection = selection.projectsWithSelection,
issueOption = for{ issueOption = issueOption
ticket <- ticketOption
issueTrackerService <- issueTrackerServiceOption
} yield ticket -> issueTrackerService.ticketLink(ticket)
))} ))}
} }

View File

@@ -2,7 +2,8 @@
@( @(
projectsWithSelection: ProjectsWithSelection, projectsWithSelection: ProjectsWithSelection,
name: String, name: String,
failedProjects: FailedProjects failedProjects: FailedProjects,
issueOption: Option[(ExportedVulnerability[String], String)]
)(implicit header: DefaultRequest) )(implicit header: DefaultRequest)
@main( @main(
@@ -19,6 +20,9 @@
<a class="btn btn-success" href="@routes.Statistics.vulnerability(name, None)">Look at all the projects!</a> <a class="btn btn-success" href="@routes.Statistics.vulnerability(name, None)">Look at all the projects!</a>
</li> </li>
} }
@for((ticket, issueLink) <- issueOption){
<li>See the <a href="@issueLink">related ticket @ticket.ticket</a>.</li>
}
<li> <li>
Maybe the vulnerability does not affect any of the projects.<br> Maybe the vulnerability does not affect any of the projects.<br>
<a href="https://web.nvd.nist.gov/view/vuln/detail?vulnId=@helper.urlEncode(name)" class="btn btn-default">Look at NVD</a> <a href="https://web.nvd.nist.gov/view/vuln/detail?vulnId=@helper.urlEncode(name)" class="btn btn-default">Look at NVD</a>