1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
package models
import (
"glsamaker/pkg/database/connection"
"glsamaker/pkg/models/bugzilla"
"glsamaker/pkg/models/cve"
"glsamaker/pkg/models/gpackage"
"glsamaker/pkg/models/users"
"time"
)
type Glsa struct {
// Id string
Id int64 `pg:",pk,unique"`
Alias string
Type string
Title string
Synopsis string
Packages []gpackage.Package
Description string
Impact string
Workaround string
Resolution string
References []Reference
Permission string
Access string
Severity string
Keyword string
Background string
Bugs []bugzilla.Bug `pg:"many2many:glsa_to_bugs,joinFK:bug_id"`
Comments []cve.Comment `pg:",fk:glsa_id"`
Revision string
ApprovedBy []int64
DeclinedBy []int64
CreatorId int64
Creator *users.User
Created time.Time
Updated time.Time
Status Status `pg:"-"`
}
type GlsaToBug struct {
GlsaId int64 `pg:",unique:glsa_to_bug"`
BugId int64 `pg:",unique:glsa_to_bug"`
}
type Reference struct {
Title string
URL string
}
type Status struct {
BugReady bool
Approval string
WorkflowStatus string
Permission string
}
func (glsa *Glsa) IsBugReady() bool {
bugReady := true
for _, bug := range glsa.Bugs {
bugReady = bugReady && bug.IsReady()
}
return bugReady
}
func (glsa *Glsa) ComputeStatus(user *users.User) {
status := Status{
BugReady: glsa.IsBugReady(),
Approval: "none",
WorkflowStatus: "todo",
Permission: glsa.Permission,
}
if glsa.DeclinedBy != nil && len(glsa.DeclinedBy) > 0 {
status.Approval = "declined"
} else if glsa.ApprovedBy != nil && len(glsa.ApprovedBy) > 0 {
status.Approval = "approved"
} else if glsa.Comments != nil && len(glsa.Comments) > 0 {
status.Approval = "comments"
}
if glsa.CreatorId == user.Id {
status.WorkflowStatus = "own"
} else if contains(glsa.ApprovedBy, user.Id) {
status.WorkflowStatus = "approved"
} else {
for _, comment := range glsa.Comments {
if comment.User == user.Id {
status.WorkflowStatus = "commented"
break
}
}
}
glsa.Status = status
}
func (glsa *Glsa) ComputeCommentBadges() {
for _, comment := range glsa.Comments {
user := new(users.User)
connection.DB.Model(user).Where("id = ?", comment.User).Select()
comment.UserBadge = user.Badge
}
}
func contains(arr []int64, element int64) bool {
for _, a := range arr {
if a == element {
return true
}
}
return false
}
|