-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: automatically trigger clear_local when permissions changed (#131)
closes #7
- Loading branch information
Showing
7 changed files
with
128 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AdminController } from './admin.controller'; | ||
import { CouchdbService } from '../couchdb/couchdb.service'; | ||
import { authGuardMockProviders } from '../auth/auth-guard-mock.providers'; | ||
import { AdminService } from './admin.service'; | ||
|
||
describe('AdminController', () => { | ||
let controller: AdminController; | ||
let mockAdminService: CouchdbService; | ||
|
||
beforeEach(async () => { | ||
mockAdminService = { | ||
clearLocal: () => Promise.resolve(), | ||
} as any; | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [AdminController], | ||
providers: [ | ||
...authGuardMockProviders, | ||
{ provide: AdminService, useValue: mockAdminService }, | ||
], | ||
}).compile(); | ||
|
||
controller = module.get(AdminController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Controller, Param, Post, UseGuards } from '@nestjs/common'; | ||
import { CombinedAuthGuard } from '../auth/guards/combined-auth/combined-auth.guard'; | ||
import { OnlyAuthenticated } from '../auth/only-authenticated.decorator'; | ||
import { AdminService } from './admin.service'; | ||
|
||
/** | ||
* This controller provides some general administrative endpoints. | ||
*/ | ||
@OnlyAuthenticated() | ||
@UseGuards(CombinedAuthGuard) | ||
@Controller('admin') | ||
export class AdminController { | ||
constructor(private adminService: AdminService) {} | ||
|
||
@Post('/clear_local/:db') | ||
async clearLocal(@Param('db') db: string): Promise<any> { | ||
await this.adminService.clearLocal(db); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AdminController } from './admin/admin.controller'; | ||
import { AdminController } from './admin.controller'; | ||
import { PermissionModule } from '../permissions/permission.module'; | ||
import { CouchdbModule } from '../couchdb/couchdb.module'; | ||
import { AuthModule } from '../auth/auth.module'; | ||
import { AdminService } from './admin.service'; | ||
|
||
@Module({ | ||
controllers: [AdminController], | ||
imports: [PermissionModule, CouchdbModule, AuthModule], | ||
providers: [AdminService], | ||
}) | ||
export class AdminModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters