Skip to content

Commit 945c3e0

Browse files
authored
cms: Fix DCC support/oppose id update (#1468)
1 parent 78a1d93 commit 945c3e0

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

politeiawww/convert.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,13 +1338,17 @@ func convertDCCDatabaseToRecord(dbDCC *cmsdatabase.DCC) cms.DCCRecord {
13381338
supportUserIDs := strings.Split(dbDCC.SupportUserIDs, ",")
13391339
cleanedSupport := make([]string, 0, len(supportUserIDs))
13401340
for _, support := range supportUserIDs {
1341-
cleanedSupport = append(cleanedSupport, strings.TrimSpace(support))
1341+
if len(support) > 0 {
1342+
cleanedSupport = append(cleanedSupport, strings.TrimSpace(support))
1343+
}
13421344
}
13431345
dccRecord.SupportUserIDs = cleanedSupport
13441346
oppositionUserIDs := strings.Split(dbDCC.OppositionUserIDs, ",")
13451347
cleanedOpposed := make([]string, 0, len(oppositionUserIDs))
13461348
for _, oppose := range oppositionUserIDs {
1347-
cleanedOpposed = append(cleanedOpposed, strings.TrimSpace(oppose))
1349+
if len(oppose) > 0 {
1350+
cleanedOpposed = append(cleanedOpposed, strings.TrimSpace(oppose))
1351+
}
13481352
}
13491353
dccRecord.OppositionUserIDs = cleanedOpposed
13501354

politeiawww/dcc.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/decred/politeia/politeiawww/user"
3030
wwwutil "github.com/decred/politeia/politeiawww/util"
3131
"github.com/decred/politeia/util"
32+
"github.com/google/uuid"
3233
)
3334

3435
const (
@@ -445,21 +446,29 @@ func (p *politeiawww) getDCC(token string) (*cms.DCCRecord, error) {
445446
opposeUsernames := make([]string, 0, len(i.OppositionUserIDs))
446447
for _, v := range i.SupportUserIDs {
447448
// Fill in userID and username fields
448-
u, err := p.db.UserGetByPubKey(v)
449+
vid, err := uuid.Parse(v)
449450
if err != nil {
450-
log.Errorf("getDCC: getUserByPubKey: token:%v "+
451-
"pubKey:%v err:%v", token, v, err)
451+
continue
452+
}
453+
u, err := p.db.UserGetById(vid)
454+
if err != nil {
455+
log.Errorf("getDCC support: UserGetById: token: %v "+
456+
"id: %v err: %v", token, v, err)
452457
} else {
453458
supportUserIDs = append(supportUserIDs, u.ID.String())
454459
supportUsernames = append(supportUsernames, u.Username)
455460
}
456461
}
457462
for _, v := range i.OppositionUserIDs {
458463
// Fill in userID and username fields
459-
u, err := p.db.UserGetByPubKey(v)
464+
vid, err := uuid.Parse(v)
465+
if err != nil {
466+
continue
467+
}
468+
u, err := p.db.UserGetById(vid)
460469
if err != nil {
461-
log.Errorf("getDCC: getUserByPubKey: token:%v "+
462-
"pubKey:%v err:%v", token, v, err)
470+
log.Errorf("getDCC oppose: UserGetById: token: %v "+
471+
"id: %v err: %v", token, v, err)
463472
} else {
464473
opposeUserIDs = append(opposeUserIDs, u.ID.String())
465474
opposeUsernames = append(opposeUsernames, u.Username)
@@ -677,9 +686,9 @@ func (p *politeiawww) processSupportOpposeDCC(ctx context.Context, sd cms.Suppor
677686
}
678687

679688
if sd.Vote == supportString {
680-
dcc.SupportUserIDs = append(dcc.SupportUserIDs, sd.PublicKey)
689+
dcc.SupportUserIDs = append(dcc.SupportUserIDs, u.ID.String())
681690
} else if sd.Vote == opposeString {
682-
dcc.OppositionUserIDs = append(dcc.OppositionUserIDs, sd.PublicKey)
691+
dcc.OppositionUserIDs = append(dcc.OppositionUserIDs, u.ID.String())
683692
}
684693
dbDcc := convertDCCDatabaseFromDCCRecord(*dcc)
685694
if err != nil {

0 commit comments

Comments
 (0)