Skip to content

Commit 6940403

Browse files
Add permission reset logic with configurable timeout in RequestPermis… (#221)
…sionPolicy ## Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. Fixes # (issue) ## Type of change Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Intermediate change (work in progress) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [ ] Test A - [ ] Test B ## Checklist: - [ ] Performed a self-review of my own code - [ ] npm test passes on your machine - [ ] New tests added or existing tests modified to cover all changes - [ ] Code conforms with the style guide - [ ] API Documentation in code was updated - [ ] Any dependent changes have been merged and published in downstream modules
1 parent c7a6bdf commit 6940403

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

packages/backend/src/plugins/permission.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class RequestPermissionPolicy implements PermissionPolicy {
4242
//type "(string & {})" used to provide auto complate in the typescript
4343
Record<string, ('admin' | 'write' | 'read' | 'none') | (string & {})> //NOSONAR
4444
> = {};
45+
readonly permissionResetOffset = 1000 * 60 * 60 * 0.5; // 1/5 hour
4546

4647
constructor(
4748
protected readonly tokenManager: AuthService,
@@ -230,6 +231,13 @@ class RequestPermissionPolicy implements PermissionPolicy {
230231
this.logger.debug('Permission resolution benchmark', {
231232
totalTimeInMilliSeconds: startTimeBenchmark - performance.now(),
232233
});
234+
235+
if (_.size(this.userRepoPermissions[userEntityRef]) !== 0) {
236+
setTimeout(() => {
237+
// after time delete the permission to refetch it
238+
delete this.userRepoPermissions[userEntityRef];
239+
}, this.permissionResetOffset);
240+
}
233241
return this.userRepoPermissions[userEntityRef];
234242
}
235243

0 commit comments

Comments
 (0)