Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove personal votes #4616

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions server/src/api/event_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api

import (
"encoding/json"

"github.com/google/uuid"
"scrumlr.io/server/common/dto"
"scrumlr.io/server/database/types"
Expand Down Expand Up @@ -312,6 +311,18 @@ func (boardSubscription *BoardSubscription) eventFilter(event *realtime.BoardEve

func eventInitFilter(event InitEvent, clientID uuid.UUID) InitEvent {
isMod := isModerator(clientID, event.Data.BoardSessions)
latestVoting := event.Data.Votings[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this leads to an error on a new board which has no votings yet:

2024-11-20T12:26:03.515343879Z  panic: runtime error: index out of range [0] with length 0
2024-11-20T12:26:03.515345713Z  
2024-11-20T12:26:03.515346963Z  -> scrumlr.io/server/api.eventInitFilter
2024-11-20T12:26:03.515348546Z  ->   /go/src/github.com/inovex/scrumlr.io/api/event_filter.go:314

event.Data.Votings = []*dto.Voting{latestVoting}

latestVotes := make([]*dto.Vote, 0)
for _, v := range event.Data.Votes {
if v.Voting == latestVoting.ID {
latestVotes = append(latestVotes, v)
}
}

event.Data.Votes = latestVotes

if isMod {
return event
}
Expand All @@ -335,9 +346,9 @@ func eventInitFilter(event InitEvent, clientID uuid.UUID) InitEvent {
// Notes
filteredNotes := filterNotes(event.Data.Notes, clientID, event.Data.Board, event.Data.Columns)

// Votes
// Votes -> only from the latest voting
visibleVotes := make([]*dto.Vote, 0)
for _, v := range event.Data.Votes {
for _, v := range latestVotes {
for _, n := range filteredNotes {
if v.Note == n.ID {
aVote := dto.Vote{
Expand All @@ -348,17 +359,16 @@ func eventInitFilter(event InitEvent, clientID uuid.UUID) InitEvent {
}
}
}

// Votings
visibleVotings := make([]*dto.Voting, 0)
for _, v := range event.Data.Votings {
filteredVoting := filterVoting(v, filteredNotes, clientID)
visibleVotings = append(visibleVotings, filteredVoting)
}
visibleVoting := make([]*dto.Voting, 0)
filteredVoting := filterVoting(event.Data.Votings[0], filteredNotes, clientID)
visibleVoting = append(visibleVoting, filteredVoting)

retEvent.Data.Columns = filteredColumns
retEvent.Data.Notes = filteredNotes
retEvent.Data.Votes = visibleVotes
retEvent.Data.Votings = visibleVotings
retEvent.Data.Votings = visibleVoting

return retEvent
}
Loading
Loading