mirror of
https://github.com/ysoftdevs/odc-analyzer.git
synced 2026-05-01 04:44:23 +02:00
Added support for mail notifications and WIP JIRA export.
This commit is contained in:
5
app/models/EmailMessageId.scala
Normal file
5
app/models/EmailMessageId.scala
Normal file
@@ -0,0 +1,5 @@
|
||||
package models
|
||||
|
||||
case class EmailMessageId(messageId: String) extends AnyVal {
|
||||
def validIdOption = Some(messageId).filterNot(_ == "") // Prevents using invalid empty string when using mock
|
||||
}
|
||||
9
app/models/ExportPlatformTables.scala
Normal file
9
app/models/ExportPlatformTables.scala
Normal file
@@ -0,0 +1,9 @@
|
||||
package models
|
||||
|
||||
import models.profile.api._
|
||||
|
||||
abstract class ExportPlatformTables[T, U] private[models] () {
|
||||
val tickets: TableQuery[_ <: ExportedVulnerabilities[T, U]]
|
||||
val projects: TableQuery[_ <: ExportedVulnerabilityProjects]
|
||||
def schema = tickets.schema ++ projects.schema
|
||||
}
|
||||
19
app/models/ExportedVulnerability.scala
Normal file
19
app/models/ExportedVulnerability.scala
Normal file
@@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import models.profile.api._
|
||||
import slick.lifted.{MappedProjection, Tag}
|
||||
|
||||
|
||||
case class ExportedVulnerability[T] (vulnerabilityName: String, ticket: T, ticketFormatVersion: Int/*, maintainedAutomatically: Boolean*/)
|
||||
|
||||
abstract class ExportedVulnerabilities[T, U](tag: Tag, tableNamePart: String) extends Table[(Int, ExportedVulnerability[T])](tag, s"exported_${tableNamePart}_vulnerabilities"){
|
||||
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
|
||||
def vulnerabilityName = column[String]("vulnerability_name")
|
||||
def ticketFormatVersion = column[Int]("ticket_format_version")
|
||||
//def maintainedAutomatically = column[Boolean]("maintained_automatically")
|
||||
|
||||
def base: MappedProjection[ExportedVulnerability[T], U]// = (vulnerabilityName, ticket, ticketFormatVersion) <> ((ExportedVulnerability.apply[T] _).tupled, ExportedVulnerability.unapply[T])
|
||||
def * = (id, base)
|
||||
|
||||
def idx_vulnerabilityName = index(s"idx_${tableName}_vulnerabilityName", vulnerabilityName, unique = true)
|
||||
}
|
||||
15
app/models/ExportedVulnerabilityProject.scala
Normal file
15
app/models/ExportedVulnerabilityProject.scala
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import models.profile.MappedJdbcType
|
||||
import models.profile.api._
|
||||
import slick.lifted.ProvenShape
|
||||
|
||||
case class ExportedVulnerabilityProject(exportedVulnerabilityId: Int, projectFullId: String)
|
||||
|
||||
abstract class ExportedVulnerabilityProjects(tag: Tag, tableNamePart: String) extends Table[ExportedVulnerabilityProject](tag, s"exported_${tableNamePart}_vulnerability_projects"){
|
||||
def exportedVulnerabilityId = column[Int]("exported_vulnerability_id")
|
||||
def fullProjectId = column[String]("full_project_id")
|
||||
def idx_all = index(s"idx_${tableName}_all", shape, unique = true)
|
||||
private def shape = (exportedVulnerabilityId, fullProjectId)
|
||||
override def * = shape <> (ExportedVulnerabilityProject.tupled, ExportedVulnerabilityProject.unapply)
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package models
|
||||
|
||||
import models.profile.MappedJdbcType
|
||||
import models.profile.api._
|
||||
import slick.lifted.Tag
|
||||
|
||||
abstract sealed class LibraryType(val name: String){
|
||||
override final def toString: String = name
|
||||
|
||||
22
app/models/VulnerabilitySubscription.scala
Normal file
22
app/models/VulnerabilitySubscription.scala
Normal file
@@ -0,0 +1,22 @@
|
||||
package models
|
||||
|
||||
import models.profile.api._
|
||||
import slick.lifted.Tag
|
||||
import com.mohiva.play.silhouette.api.LoginInfo
|
||||
|
||||
case class VulnerabilitySubscription(user: LoginInfo, project: String)
|
||||
|
||||
class LoginInfoColumns(prefix: String, table: Table[_]) {
|
||||
import table.column
|
||||
def providerId = column[String](s"${prefix}_provider_id")
|
||||
def providerKey = column[String](s"${prefix}_provider_key")
|
||||
def apply() = (providerId, providerKey) <> (LoginInfo.tupled, LoginInfo.unapply)
|
||||
def === (other: LoginInfo): Rep[Boolean] = (providerId === other.providerID) && (providerKey === other.providerKey)
|
||||
}
|
||||
|
||||
class VulnerabilitySubscriptions(tag: Tag) extends Table[VulnerabilitySubscription](tag, "vulnerability_subscription"){
|
||||
val user = new LoginInfoColumns("subscriber", this)
|
||||
def project = column[String]("project")
|
||||
def * = (user(), project) <> (VulnerabilitySubscription.tupled, VulnerabilitySubscription.unapply)
|
||||
def idx = index("all", (user(), project), unique = true)
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
import slick.lifted.TableQuery
|
||||
|
||||
/**
|
||||
* Created by user on 8/12/15.
|
||||
*/
|
||||
import java.nio.file.{Paths, Files}
|
||||
|
||||
import scala.language.reflectiveCalls
|
||||
|
||||
package object models {
|
||||
|
||||
val profile = slick.driver.PostgresDriver
|
||||
|
||||
val jodaSupport = com.github.tototoshi.slick.PostgresJodaSupport
|
||||
import profile.api._
|
||||
import profile.MappedJdbcType
|
||||
|
||||
|
||||
object tables {
|
||||
val libraries = TableQuery[Libraries]
|
||||
@@ -15,6 +17,50 @@ package object models {
|
||||
val tags = TableQuery[LibraryTags]
|
||||
val snoozesTable = TableQuery[Snoozes]
|
||||
val authTokens = TableQuery[CookieAuthenticators]
|
||||
val vulnerabilitySubscriptions = TableQuery[VulnerabilitySubscriptions]
|
||||
|
||||
val issueTrackerExportTables = new ExportPlatformTables[String, (String, String, Int)](){
|
||||
val tableNamePart = "issue_tracker"
|
||||
class IssueTrackerVulnerabilities(tag: Tag) extends ExportedVulnerabilities[String, (String, String, Int)](tag, tableNamePart){
|
||||
def ticket = column[String]("ticket")
|
||||
override def base = (vulnerabilityName, ticket, ticketFormatVersion) <> ((ExportedVulnerability.apply[String] _).tupled, ExportedVulnerability.unapply[String])
|
||||
def idx_ticket = index("idx_ticket", ticket, unique = true)
|
||||
}
|
||||
class IssueTrackerVulnerabilityProject(tag: Tag) extends ExportedVulnerabilityProjects(tag, tableNamePart)
|
||||
override val tickets = TableQuery[IssueTrackerVulnerabilities]
|
||||
override val projects: profile.api.TableQuery[_ <: ExportedVulnerabilityProjects] = TableQuery[IssueTrackerVulnerabilityProject]
|
||||
}
|
||||
type EmailExportedVulnerabilitiesShape = (String, EmailMessageId, Int)
|
||||
val mailExportTables = new ExportPlatformTables[EmailMessageId, EmailExportedVulnerabilitiesShape](){
|
||||
val tableNamePart = "email"
|
||||
class EmailExportedVulnerabilities(tag: Tag) extends ExportedVulnerabilities[EmailMessageId, EmailExportedVulnerabilitiesShape](tag, tableNamePart){
|
||||
private implicit val mmiMapper = MappedJdbcType.base[EmailMessageId, String](_.messageId, EmailMessageId)
|
||||
def messageId = column[EmailMessageId]("message_id") // Unlike ticket, message id is not required to be unique in order to handle some edge cases like play.mailer.mock = true
|
||||
override def base = (vulnerabilityName, messageId, ticketFormatVersion) <> ( (ExportedVulnerability.apply[EmailMessageId] _).tupled, ExportedVulnerability.unapply[EmailMessageId])
|
||||
}
|
||||
class EmailVulnerabilityProject(tag: Tag) extends ExportedVulnerabilityProjects(tag, tableNamePart)
|
||||
|
||||
override val projects = TableQuery[EmailVulnerabilityProject]
|
||||
override val tickets = TableQuery[EmailExportedVulnerabilities]
|
||||
}
|
||||
|
||||
/*{
|
||||
import profile.SchemaDescription
|
||||
val schema = Seq[Any{def schema: SchemaDescription}](
|
||||
vulnerabilitySubscriptions, issueTrackerExportTables, mailExportTables
|
||||
).map(_.schema).foldLeft(profile.DDL(Seq(), Seq()))(_ ++ _)
|
||||
|
||||
val sql = Seq(
|
||||
"# --- !Ups",
|
||||
schema.createStatements.toSeq.map(_+";").mkString("\n").dropWhile(_ == "\n"),
|
||||
"",
|
||||
"# --- !Downs",
|
||||
schema.dropStatements.toSeq.map(_+";").mkString("\n").dropWhile(_ == "\n"),
|
||||
"\n"
|
||||
).mkString("\n")
|
||||
Files.write(Paths.get("conf/evolutions/default/6.sql"), sql.getBytes("utf-8"))
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user