(user auth.User)
| 30 | } |
| 31 | |
| 32 | func (h *handler) getAllUserChannelsResponse(user auth.User) (map[string]map[string]channelHistory, error) { |
| 33 | resp := make(map[string]map[string]channelHistory) |
| 34 | |
| 35 | _, err := h.db.Authenticator(h.ctx()).RebuildChannels(user) |
| 36 | if err != nil { |
| 37 | return nil, err |
| 38 | } |
| 39 | err = h.db.Authenticator(h.ctx()).RebuildRoles(user) |
| 40 | if err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | |
| 44 | for _, dsName := range h.db.DataStoreNames() { |
| 45 | keyspace := dsName.ScopeName() + "." + dsName.CollectionName() |
| 46 | currentChannels, err := user.InheritedCollectionChannels(dsName.ScopeName(), dsName.CollectionName()) |
| 47 | if err != nil { |
| 48 | return nil, fmt.Errorf("error retrieving inherited user channels: %w", err) |
| 49 | } |
| 50 | chanHistory := user.CollectionChannelHistory(dsName.ScopeName(), dsName.CollectionName()) |
| 51 | |
| 52 | // If no channels aside from public and no channels in history, don't make a key for this keyspace |
| 53 | if len(currentChannels) == 1 && len(chanHistory) == 0 { |
| 54 | continue |
| 55 | } |
| 56 | resp[keyspace] = make(map[string]channelHistory) |
| 57 | for chanName, chanEntry := range currentChannels { |
| 58 | if chanName == channels.DocumentStarChannel { |
| 59 | continue |
| 60 | } |
| 61 | resp[keyspace][chanName] = channelHistory{Entries: []auth.GrantHistorySequencePair{{StartSeq: chanEntry.Sequence, EndSeq: 0}}} |
| 62 | } |
| 63 | |
| 64 | for chanName, chanEntry := range chanHistory { |
| 65 | chanHistoryEntry := channelHistory{Entries: chanEntry.Entries} |
| 66 | // if channel is also in history, append current entry to history entries |
| 67 | if _, chanCurrentlyAssigned := resp[keyspace][chanName]; chanCurrentlyAssigned { |
| 68 | var newEntries []auth.GrantHistorySequencePair |
| 69 | newEntries = append(chanEntry.Entries, resp[keyspace][chanName].Entries...) |
| 70 | chanHistoryEntry.Entries = newEntries |
| 71 | } |
| 72 | resp[keyspace][chanName] = chanHistoryEntry |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | for roleName, roleVbSeq := range user.RoleNames() { |
| 77 | role, err := h.db.Authenticator(h.ctx()).GetRoleIncDeleted(roleName) |
| 78 | if err != nil { |
| 79 | return nil, fmt.Errorf("error getting role: %w", err) |
| 80 | } |
| 81 | if role == nil { |
| 82 | continue |
| 83 | } |
| 84 | |
| 85 | // default keyspace chan history |
| 86 | defaultKs := "_default._default" |
| 87 | if _, ok := resp[defaultKs]; !ok && len(maps.Keys(role.ChannelHistory())) != 0 { |
| 88 | resp[defaultKs] = make(map[string]channelHistory) |
| 89 | } |
no test coverage detected