-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Set up endpoint for all existing roles with license flag (#…
- Loading branch information
Showing
9 changed files
with
124 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { License } from '@/License'; | ||
import { Get, RestController } from '@/decorators'; | ||
import { RoleService } from '@/services/role.service'; | ||
import { Service } from 'typedi'; | ||
|
||
@Service() | ||
@RestController('/roles') | ||
export class RoleController { | ||
constructor( | ||
private readonly roleService: RoleService, | ||
private readonly license: License, | ||
) {} | ||
|
||
@Get('/') | ||
async listRoles() { | ||
return this.roleService.listRoles().map((role) => { | ||
if (role.scope === 'global' && role.name === 'admin') { | ||
return { ...role, isAvailable: this.license.isAdvancedPermissionsLicensed() }; | ||
} | ||
|
||
return { ...role, isAvailable: 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
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,82 @@ | ||
import { License } from '@/License'; | ||
|
||
import * as utils from './shared/utils/'; | ||
import * as testDb from './shared/testDb'; | ||
import { mockInstance } from '../shared/mocking'; | ||
import { createAdmin, createMember, createOwner } from './shared/db/users'; | ||
|
||
import type { SuperAgentTest } from 'supertest'; | ||
import type { User } from '@db/entities/User'; | ||
|
||
const testServer = utils.setupTestServer({ endpointGroups: ['role'] }); | ||
|
||
const license = mockInstance(License, { | ||
isAdvancedPermissionsLicensed: jest.fn().mockReturnValue(true), | ||
isWithinUsersLimit: jest.fn().mockReturnValue(true), | ||
}); | ||
|
||
describe('GET /roles', () => { | ||
let owner: User; | ||
let admin: User; | ||
let member: User; | ||
|
||
let ownerAgent: SuperAgentTest; | ||
let adminAgent: SuperAgentTest; | ||
let memberAgent: SuperAgentTest; | ||
|
||
let toAgent: Record<string, SuperAgentTest> = {}; | ||
|
||
beforeAll(async () => { | ||
await testDb.truncate(['User']); | ||
|
||
owner = await createOwner(); | ||
admin = await createAdmin(); | ||
member = await createMember(); | ||
|
||
ownerAgent = testServer.authAgentFor(owner); | ||
adminAgent = testServer.authAgentFor(admin); | ||
memberAgent = testServer.authAgentFor(member); | ||
|
||
toAgent = { | ||
owner: ownerAgent, | ||
admin: adminAgent, | ||
member: memberAgent, | ||
}; | ||
}); | ||
|
||
describe('with advanced permissions licensed', () => { | ||
test.each(['owner', 'admin', 'member'])('should return all roles to %s', async (user) => { | ||
license.isAdvancedPermissionsLicensed.mockReturnValue(true); | ||
|
||
const response = await toAgent[user].get('/roles').expect(200); | ||
|
||
expect(response.body.data).toEqual([ | ||
{ scope: 'global', name: 'owner', isAvailable: true }, | ||
{ scope: 'global', name: 'member', isAvailable: true }, | ||
{ scope: 'global', name: 'admin', isAvailable: true }, | ||
{ scope: 'workflow', name: 'owner', isAvailable: true }, | ||
{ scope: 'credential', name: 'owner', isAvailable: true }, | ||
{ scope: 'credential', name: 'user', isAvailable: true }, | ||
{ scope: 'workflow', name: 'editor', isAvailable: true }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('with advanced permissions not licensed', () => { | ||
test.each(['owner', 'admin', 'member'])('should return all roles to %s', async (user) => { | ||
license.isAdvancedPermissionsLicensed.mockReturnValue(false); | ||
|
||
const response = await toAgent[user].get('/roles').expect(200); | ||
|
||
expect(response.body.data).toEqual([ | ||
{ scope: 'global', name: 'owner', isAvailable: true }, | ||
{ scope: 'global', name: 'member', isAvailable: true }, | ||
{ scope: 'global', name: 'admin', isAvailable: false }, | ||
{ scope: 'workflow', name: 'owner', isAvailable: true }, | ||
{ scope: 'credential', name: 'owner', isAvailable: true }, | ||
{ scope: 'credential', name: 'user', isAvailable: true }, | ||
{ scope: 'workflow', name: 'editor', isAvailable: 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
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