MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / CollectionChannelGrantedPeriods

Method CollectionChannelGrantedPeriods

auth/user.go:411–506  ·  view source on GitHub ↗

Calculate periods where user had access to the given channel either directly or via a role

(scope, collection, chanName string)

Source from the content-addressed store, hash-verified

409
410// Calculate periods where user had access to the given channel either directly or via a role
411func (user *userImpl) CollectionChannelGrantedPeriods(scope, collection, chanName string) ([]GrantHistorySequencePair, error) {
412 var resultPairs []GrantHistorySequencePair
413
414 // Grab user history and use this to begin the resultPairs
415 userChannelHistory, ok := user.CollectionChannelHistory(scope, collection)[chanName]
416 if ok {
417 resultPairs = userChannelHistory.Entries
418 }
419
420 // Iterate over current user channels and add to resultPairs
421 for channelName, chanInfo := range user.CollectionChannels(scope, collection) {
422 if channelName != chanName {
423 continue
424 }
425 resultPairs = append(resultPairs, GrantHistorySequencePair{
426 StartSeq: chanInfo.Sequence,
427 EndSeq: math.MaxUint64,
428 })
429 }
430
431 // Small function which takes the two start seqs and two end seqs and calculates the intersection
432 compareAndAddPair := func(startSeq1, startSeq2, endSeq1, endSeq2 uint64) {
433 start := base.Max(startSeq1, startSeq2)
434 end := base.Min(endSeq1, endSeq2)
435 if start < end {
436 resultPairs = append(resultPairs, GrantHistorySequencePair{
437 StartSeq: start,
438 EndSeq: end,
439 })
440 }
441 }
442
443 roles, err := user.GetRoles()
444 if err != nil {
445 return nil, err
446 }
447 // Iterate over current roles
448 for _, currentRole := range roles {
449
450 // Grab pairs from channel history on current roles
451 roleChannelHistory, ok := currentRole.CollectionChannelHistory(scope, collection)[chanName]
452 if ok {
453 for _, roleChannelHistoryEntry := range roleChannelHistory.Entries {
454 roleGrantedAt := user.RolesSince_[currentRole.Name()].Sequence
455 compareAndAddPair(roleChannelHistoryEntry.StartSeq, roleGrantedAt, roleChannelHistoryEntry.EndSeq, math.MaxUint64)
456 }
457 }
458
459 // Grab pairs from current channels on current roles
460 if currentRole.CollectionChannels(scope, collection).Contains(chanName) {
461 for _, channelInfo := range currentRole.CollectionChannels(scope, collection) {
462 resultPairs = append(resultPairs, GrantHistorySequencePair{
463 StartSeq: channelInfo.Sequence,
464 EndSeq: math.MaxUint64,
465 })
466 }
467 }
468 }

Callers 1

channelGrantedPeriodsMethod · 0.95

Calls 11

GetRolesMethod · 0.95
RoleHistoryMethod · 0.95
MaxFunction · 0.92
MinFunction · 0.92
WarnfCtxFunction · 0.92
UDFunction · 0.92
GetRoleIncDeletedMethod · 0.80
CollectionChannelsMethod · 0.65
NameMethod · 0.65
ContainsMethod · 0.65

Tested by

no test coverage detected