RequiresCollectionAccessUpdate returns true if the provided map of CollectionAccessConfig requires an update to the principal
(ctx context.Context, princ auth.Principal, updates map[string]map[string]*auth.CollectionAccessConfig)
| 266 | |
| 267 | // RequiresCollectionAccessUpdate returns true if the provided map of CollectionAccessConfig requires an update to the principal |
| 268 | func (dbc *DatabaseContext) RequiresCollectionAccessUpdate(ctx context.Context, princ auth.Principal, updates map[string]map[string]*auth.CollectionAccessConfig) (bool, error) { |
| 269 | requiresUpdate := false |
| 270 | for scopeName, scope := range updates { |
| 271 | if scope != nil { |
| 272 | for collectionName, updatedCollectionAccess := range scope { |
| 273 | _, err := dbc.GetDatabaseCollection(scopeName, collectionName) |
| 274 | if err != nil { |
| 275 | return false, base.HTTPErrorf(http.StatusNotFound, "keyspace specified in collection_access (%s) not found", fmt.Sprintf("%s.%s.%s", dbc.Name, scopeName, collectionName)) |
| 276 | } |
| 277 | if updatedCollectionAccess.Channels_ != nil { |
| 278 | return false, base.HTTPErrorf(http.StatusBadRequest, "collection_access.all_channels is read-only") |
| 279 | } |
| 280 | if updatedCollectionAccess.JWTChannels_ != nil { |
| 281 | return false, base.HTTPErrorf(http.StatusBadRequest, "collection_access.jwt_channels is read-only") |
| 282 | } |
| 283 | if updatedCollectionAccess.JWTLastUpdated != nil { |
| 284 | return false, base.HTTPErrorf(http.StatusBadRequest, "collection_access.jwt_last_updated is read-only") |
| 285 | } |
| 286 | if updatedCollectionAccess == nil { |
| 287 | if princ.CollectionExplicitChannels(scopeName, collectionName) != nil { |
| 288 | requiresUpdate = true |
| 289 | } |
| 290 | } else { |
| 291 | if !princ.CollectionExplicitChannels(scopeName, collectionName).Equals(updatedCollectionAccess.ExplicitChannels_) { |
| 292 | requiresUpdate = true |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | return requiresUpdate, nil |
| 300 | } |
no test coverage detected