()
| 126 | } |
| 127 | |
| 128 | func (bh *blipHandler) refreshUser() error { |
| 129 | |
| 130 | bc := bh.BlipSyncContext |
| 131 | if bc.userName != "" { |
| 132 | // Check whether user needs to be refreshed |
| 133 | bc.dbUserLock.Lock() |
| 134 | defer bc.dbUserLock.Unlock() |
| 135 | userChanged := bc.userChangeWaiter.RefreshUserCount() |
| 136 | |
| 137 | // If changed, refresh the user and db while holding the lock |
| 138 | if userChanged { |
| 139 | // Refresh the BlipSyncContext database |
| 140 | err := bc.blipContextDb.ReloadUser(bh.loggingCtx) |
| 141 | if err != nil { |
| 142 | return base.NewHTTPError(CBLReconnectErrorCode, err.Error()) |
| 143 | } |
| 144 | newUser := bc.blipContextDb.User() |
| 145 | err = newUser.InitializeRoles() |
| 146 | if err != nil { |
| 147 | return base.NewHTTPError(CBLReconnectErrorCode, err.Error()) |
| 148 | } |
| 149 | bc.userChangeWaiter.RefreshUserKeys(newUser, bc.blipContextDb.MetadataKeys) |
| 150 | // refresh the handler's database with the new BlipSyncContext database |
| 151 | bh.db = bh._copyContextDatabase() |
| 152 | if bh.collection != nil { |
| 153 | bh.collection = &DatabaseCollectionWithUser{ |
| 154 | DatabaseCollection: bh.collection.DatabaseCollection, |
| 155 | user: bh.db.User(), |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | return nil |
| 161 | } |
| 162 | |
| 163 | // collectionBlipHandler wraps another blip handler to specify a collection |
| 164 | func collectionBlipHandler(next blipHandlerFunc) blipHandlerFunc { |
no test coverage detected