Skip to content

Commit

Permalink
Fix voted for delegation
Browse files Browse the repository at this point in the history
The old version used the meeting_user_id as user_id

Fixes OpenSlides#223
  • Loading branch information
ostcar committed Aug 29, 2023
1 parent a8b1ccf commit 10a58c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
19 changes: 15 additions & 4 deletions vote/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,23 @@ func delegatedUserIDs(ctx context.Context, fetch *dsfetch.Fetch, userID int) ([]
return nil, fmt.Errorf("getting vote_delegation_from values: %w", err)
}

var uids []int
for _, muids := range meetingUserDelegationsIDs {
uids = append(uids, muids...)
var delegatedMeetingUserIDs []int
for i := range meetingUserDelegationsIDs {
for j := range meetingUserDelegationsIDs[i] {
delegatedMeetingUserIDs = append(delegatedMeetingUserIDs, meetingUserDelegationsIDs[i][j])
}
}

userIDs := make([]int, len(delegatedMeetingUserIDs))
for i := range delegatedMeetingUserIDs {
fetch.MeetingUser_UserID(delegatedMeetingUserIDs[i]).Lazy(&userIDs[i])
}

if err := fetch.Execute(ctx); err != nil {
return nil, fmt.Errorf("getting user_ids from meeting_user_ids: %w", err)
}

return uids, nil
return userIDs, nil
}

// Voted tells, on which the requestUser has already voted.
Expand Down
18 changes: 12 additions & 6 deletions vote/vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1257,23 +1257,29 @@ func TestVotedPollsWithDelegation(t *testing.T) {
user/5:
meeting_user_ids: [10]
meeting_user/10:
meeting_id: 8
vote_delegations_from_ids: [11,12]
meeting_user:
10:
meeting_id: 8
vote_delegations_from_ids: [11]
11:
user_id: 6
12:
user_id: 7
`))

backend.Start(ctx, 1)
backend.Vote(ctx, 1, 5, []byte(`"Y"`))
backend.Vote(ctx, 1, 10, []byte(`"Y"`))
backend.Vote(ctx, 1, 11, []byte(`"Y"`))
backend.Vote(ctx, 1, 6, []byte(`"Y"`))
backend.Vote(ctx, 1, 7, []byte(`"Y"`))
v, _, _ := vote.New(ctx, backend, backend, ds, true)

got, err := v.Voted(ctx, []int{1, 2}, 5)
if err != nil {
t.Fatalf("Voted() returned unexected error: %v", err)
}

expect := map[int][]int{1: {5, 11}, 2: nil}
expect := map[int][]int{1: {5, 6}, 2: nil}
if !reflect.DeepEqual(got, expect) {
t.Errorf("Voted() == `%v`, expected `%v`", got, expect)
}
Expand Down

0 comments on commit 10a58c6

Please sign in to comment.