summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-04-20 02:49:26 +0200
committerMax Magorsch <arzano@gentoo.org>2020-04-20 02:49:26 +0200
commitafbef434b514b90a134f93ed043edd44bf564b64 (patch)
tree483124213a01ae6f101288aaffa0e9877ac98344
parentMake the domain configurable (diff)
downloadglsamaker-afbef434b514b90a134f93ed043edd44bf564b64.tar.gz
glsamaker-afbef434b514b90a134f93ed043edd44bf564b64.tar.bz2
glsamaker-afbef434b514b90a134f93ed043edd44bf564b64.zip
Correctly display the user name in comments
Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r--pkg/app/handler/cvetool/comments.go8
-rw-r--r--pkg/app/handler/cvetool/index.go2
-rw-r--r--pkg/app/handler/cvetool/state.go2
-rw-r--r--pkg/app/handler/dashboard/index.go2
-rw-r--r--pkg/app/handler/glsa/comments.go3
-rw-r--r--pkg/app/handler/glsa/edit.go1
-rw-r--r--pkg/app/handler/glsa/view.go3
-rw-r--r--pkg/app/handler/requests/index.go3
-rw-r--r--pkg/models/cve/feed.go3
-rw-r--r--pkg/models/glsa.go4
-rw-r--r--web/packs/glsa.js2
-rw-r--r--web/packs/src/javascript/cvetool.js7
-rw-r--r--web/templates/dashboard/dashboard.tmpl2
-rw-r--r--web/templates/glsa/edit.tmpl3
-rw-r--r--web/templates/glsa/show.tmpl2
15 files changed, 26 insertions, 21 deletions
diff --git a/pkg/app/handler/cvetool/comments.go b/pkg/app/handler/cvetool/comments.go
index d36122a..37649a1 100644
--- a/pkg/app/handler/cvetool/comments.go
+++ b/pkg/app/handler/cvetool/comments.go
@@ -7,6 +7,7 @@ import (
"glsamaker/pkg/logger"
"glsamaker/pkg/models/cve"
"encoding/json"
+ "glsamaker/pkg/models/users"
"net/http"
"time"
)
@@ -23,7 +24,7 @@ func AddComment(w http.ResponseWriter, r *http.Request) {
id, comment, err := getParams(r)
- newComment, err := addNewCommment(id, user.Id, comment)
+ newComment, err := addNewCommment(id, user, comment)
if err != nil {
logger.Info.Println("Err")
@@ -38,7 +39,7 @@ func AddComment(w http.ResponseWriter, r *http.Request) {
}
-func addNewCommment(id string, userID int64, comment string) (cve.Comment, error) {
+func addNewCommment(id string, user *users.User, comment string) (cve.Comment, error) {
cveItem := &cve.DefCveItem{Id: id}
err := connection.DB.Select(cveItem)
@@ -49,7 +50,8 @@ func addNewCommment(id string, userID int64, comment string) (cve.Comment, error
newComment := cve.Comment{
CVEId: id,
- User: userID,
+ UserId: user.Id,
+ User: user,
Message: comment,
Date: time.Now(),
}
diff --git a/pkg/app/handler/cvetool/index.go b/pkg/app/handler/cvetool/index.go
index 9c54a01..bf70536 100644
--- a/pkg/app/handler/cvetool/index.go
+++ b/pkg/app/handler/cvetool/index.go
@@ -98,7 +98,7 @@ func CveData(w http.ResponseWriter, r *http.Request) {
q = q.WhereOr("description LIKE " + "'%" + search_value + "%'").
WhereOr("id LIKE " + "'%" + search_value + "%'")
return q, nil
- }).Relation("Bugs").Relation("Comments").Select()
+ }).Relation("Bugs").Relation("Comments").Relation("Comments.User").Select()
if err != nil || len(cves) == 0 {
logger.Info.Println("Error finding cves:")
diff --git a/pkg/app/handler/cvetool/state.go b/pkg/app/handler/cvetool/state.go
index 608691c..8ff46cb 100644
--- a/pkg/app/handler/cvetool/state.go
+++ b/pkg/app/handler/cvetool/state.go
@@ -48,7 +48,7 @@ func ChangeState(w http.ResponseWriter, r *http.Request) {
return
}
- newComment, err := addNewCommment(id, user.Id, "Changed status to "+newState+": "+reason)
+ newComment, err := addNewCommment(id, user, "Changed status to "+newState+": "+reason)
if err != nil {
logger.Error.Println("Err")
diff --git a/pkg/app/handler/dashboard/index.go b/pkg/app/handler/dashboard/index.go
index 82fd858..8d9966e 100644
--- a/pkg/app/handler/dashboard/index.go
+++ b/pkg/app/handler/dashboard/index.go
@@ -29,7 +29,7 @@ func Show(w http.ResponseWriter, r *http.Request) {
connection.DB.Model(&cves).Order("last_modified_date DESC").Limit(5).Select()
var comments []*cve.Comment
- connection.DB.Model(&comments).Order("date DESC").Limit(5).Select()
+ connection.DB.Model(&comments).Relation("User").Order("date DESC").Limit(5).Select()
requests, _ := connection.DB.Model((*models.Glsa)(nil)).Where("type = ?", "request").Count()
drafts, _ := connection.DB.Model((*models.Glsa)(nil)).Where("type = ?", "draft").Count()
diff --git a/pkg/app/handler/glsa/comments.go b/pkg/app/handler/glsa/comments.go
index 9412b62..a3afe0b 100644
--- a/pkg/app/handler/glsa/comments.go
+++ b/pkg/app/handler/glsa/comments.go
@@ -82,7 +82,8 @@ func AddNewCommment(id string, user *users.User, comment string, commentType str
newComment := cve.Comment{
GlsaId: glsaID,
- User: user.Id,
+ UserId: user.Id,
+ User: user,
UserBadge: user.Badge,
Type: commentType,
Message: comment,
diff --git a/pkg/app/handler/glsa/edit.go b/pkg/app/handler/glsa/edit.go
index 04e67b3..c89e68f 100644
--- a/pkg/app/handler/glsa/edit.go
+++ b/pkg/app/handler/glsa/edit.go
@@ -45,6 +45,7 @@ func Edit(w http.ResponseWriter, r *http.Request) {
Relation("Bugs").
Relation("Creator").
Relation("Comments").
+ Relation("Comments.User").
WherePK()).
Select()
diff --git a/pkg/app/handler/glsa/view.go b/pkg/app/handler/glsa/view.go
index d84273c..945af2d 100644
--- a/pkg/app/handler/glsa/view.go
+++ b/pkg/app/handler/glsa/view.go
@@ -26,7 +26,8 @@ func View(w http.ResponseWriter, r *http.Request) {
err := user.CanAccess(connection.DB.Model(glsa).
Relation("Bugs").
Relation("Creator").
- Relation("Comments").WherePK()).
+ Relation("Comments").
+ Relation("Comments.User").WherePK()).
Select()
if err != nil {
diff --git a/pkg/app/handler/requests/index.go b/pkg/app/handler/requests/index.go
index fddbd86..d57ecc5 100644
--- a/pkg/app/handler/requests/index.go
+++ b/pkg/app/handler/requests/index.go
@@ -26,7 +26,8 @@ func Show(w http.ResponseWriter, r *http.Request) {
Where("type = ?", "request").
Relation("Bugs").
Relation("Creator").
- Relation("Comments")).
+ Relation("Comments").
+ Relation("Comments.User")).
Select()
if err != nil {
diff --git a/pkg/models/cve/feed.go b/pkg/models/cve/feed.go
index 527f233..598c3ab 100644
--- a/pkg/models/cve/feed.go
+++ b/pkg/models/cve/feed.go
@@ -73,7 +73,8 @@ type Comment struct {
Id int64 `pg:",pk,unique"`
GlsaId int64
CVEId string
- User int64
+ UserId int64
+ User *users.User
UserBadge users.Badge
Type string
Message string
diff --git a/pkg/models/glsa.go b/pkg/models/glsa.go
index 9f8c3ec..1a6cddc 100644
--- a/pkg/models/glsa.go
+++ b/pkg/models/glsa.go
@@ -86,7 +86,7 @@ func (glsa *Glsa) ComputeStatus(user *users.User) {
status.WorkflowStatus = "approved"
} else {
for _, comment := range glsa.Comments {
- if comment.User == user.Id {
+ if comment.UserId == user.Id {
status.WorkflowStatus = "commented"
break
}
@@ -99,7 +99,7 @@ func (glsa *Glsa) ComputeStatus(user *users.User) {
func (glsa *Glsa) ComputeCommentBadges() {
for _, comment := range glsa.Comments {
user := new(users.User)
- connection.DB.Model(user).Where("id = ?", comment.User).Select()
+ connection.DB.Model(user).Where("id = ?", comment.UserId).Select()
comment.UserBadge = user.Badge
}
diff --git a/web/packs/glsa.js b/web/packs/glsa.js
index 0490db0..8677dd7 100644
--- a/web/packs/glsa.js
+++ b/web/packs/glsa.js
@@ -66,7 +66,7 @@ function commentGLSA(glsaid, comment, commentType){
'<div class="row">' +
'<div class="col-sm-12">' +
'<span style="color:#000!important;">' +
- '<span class="vcard"><a class="email" href="mailto:' + comment.User + '"> <b class="text-dark">' + comment.User + '</b></a></span>' +
+ '<span class="vcard"><a class="email" href="mailto:' + comment.User.Email + '"> <b class="text-dark">' + comment.User.Name + '</b></a></span>' +
'</span>' +
'<span class="ml-2">' +
'<span class="badge badge-secondary" title="' + comment.UserBadge.Description + '" style="background: none;border: 1px solid ' + comment.UserBadge.Color + ';">' +
diff --git a/web/packs/src/javascript/cvetool.js b/web/packs/src/javascript/cvetool.js
index 6158714..2a04c5b 100644
--- a/web/packs/src/javascript/cvetool.js
+++ b/web/packs/src/javascript/cvetool.js
@@ -218,7 +218,7 @@ function format ( d ) {
comments = '';
commentsObjects.forEach(function (comment, index) {
var commentDate = '<small class="text-muted">' + comment.Date.split("T")[0] + ' ' + comment.Date.split("T")[1].split(".")[0] + ' UTC</small>';
- comments = comments + '<div class="col-3 text-right mb-3"><b>' + comment.User + '</b><br/>' + commentDate + '</div><div class="col-9 mb-3"><div class="card" style="background: none;"><div class="card-body">' + comment.Message + '</div></div></div>';
+ comments = comments + '<div class="col-3 text-right mb-3"><b>' + comment.User.Name + '</b><br/>' + commentDate + '</div><div class="col-9 mb-3"><div class="card" style="background: none;"><div class="card-body">' + comment.Message + '</div></div></div>';
});
}
@@ -315,9 +315,6 @@ function registerCommentListener(){
$( ".save-new-comment" ).click(function() {
var cveid = $(this).data( "cveid" );
var comment = $('textarea.new-comment[data-cveid="' + cveid + '"]').val();
- console.log('textarea:');
- console.log();
-
$.post(
'/cve/comment/add',
@@ -332,7 +329,7 @@ function registerCommentListener(){
console.log(data);
var comment = JSON.parse(data);
var commentDate = '<small class="text-muted">' + comment.Date.split("T")[0] + ' ' + comment.Date.split("T")[1].split(".")[0] + ' UTC</small>';
- var newComment = '<div class="col-3 text-right mb-3"><b>' + comment.User + '</b><br/>' + commentDate + '</div><div class="col-9 mb-3"><div class="card" style="background: none;"><div class="card-body">' + comment.Message + '</div></div></div>';
+ var newComment = '<div class="col-3 text-right mb-3"><b>' + comment.User.Name + '</b><br/>' + commentDate + '</div><div class="col-9 mb-3"><div class="card" style="background: none;"><div class="card-body">' + comment.Message + '</div></div></div>';
$('.comments-section[data-cveid="' + cveid + '"]').append(newComment);
}
return
diff --git a/web/templates/dashboard/dashboard.tmpl b/web/templates/dashboard/dashboard.tmpl
index d77fd73..b6d3d2c 100644
--- a/web/templates/dashboard/dashboard.tmpl
+++ b/web/templates/dashboard/dashboard.tmpl
@@ -87,7 +87,7 @@
<a href="{{if .GlsaId}}/glsa/{{.GlsaId}}{{end}}">{{.Message}}</a>
</td>
<td class="text-right">
- {{.User}}
+ {{.User.Name}}
</td>
<td class="text-right">
{{.Date}}
diff --git a/web/templates/glsa/edit.tmpl b/web/templates/glsa/edit.tmpl
index 4318d86..eed5c44 100644
--- a/web/templates/glsa/edit.tmpl
+++ b/web/templates/glsa/edit.tmpl
@@ -679,7 +679,7 @@
<div class="row">
<div class="col-sm-12">
<span style="color:#000!important;">
- <span class="vcard"><a class="email" href="mailto:max@magorsch.de" title="Max Magorsch <max@magorsch.de>"> <b class="text-dark">{{.User}}</b></a></span>
+ <span class="vcard"><a class="email" href="mailto:{{.User.Email}}" title="{{.User.Name}} <{{.User.Email}}>"> <b class="text-dark">{{.User.Name}}</b></a></span>
</span>
<span class="ml-2">
@@ -731,6 +731,7 @@
</div>
<textarea name="comment" id="comment" class="form-control comment-textarea" rows="10" cols="60" onfocusout="this.rows=10" onfocus="this.rows=15"></textarea>
<br><div class="knob-buttons">
+ <input class="btn btn-outline-primary btn-sm float-right" type="button" value="Add Comment" id="save-new-glsa-comment">
{{if .User.Permissions.Glsa.Approve}}
{{if eq .Glsa.CreatorId .User.Id}}
{{if .User.Permissions.Glsa.ApproveOwnGlsa}}
diff --git a/web/templates/glsa/show.tmpl b/web/templates/glsa/show.tmpl
index c9a9591..a07d471 100644
--- a/web/templates/glsa/show.tmpl
+++ b/web/templates/glsa/show.tmpl
@@ -412,7 +412,7 @@
<div class="row">
<div class="col-sm-12">
<span style="color:#000!important;">
- <span class="vcard"><a class="email" href="mailto:max@magorsch.de" title="Max Magorsch <max@magorsch.de>"> <b class="text-dark">{{.User}}</b></a></span>
+ <span class="vcard"><a class="email" href="mailto:{{.User.Email}}" title="{{.User.Name}} <{{.User.Email}}>"> <b class="text-dark">{{.User.Name}}</b></a></span>
</span>
<span class="ml-2">