Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): Enable global project access #580

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions apps/api/src/project/project.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -867,23 +867,26 @@ describe('Project Controller Tests', () => {
await prisma.workspace.deleteMany()
})

// it('should allow any user to access a global project', async () => {
// const response = await app.inject({
// method: 'GET',
// url: `/project/${globalProject.slug}`,
// headers: {
// 'x-e2e-user-email': user2.email // user2 is not a member of workspace1
// }
// })

// expect(response.statusCode).toBe(200)
// expect(response.json()).toEqual({
// ...globalProject,
// lastUpdatedById: user1.id,
// createdAt: expect.any(String),
// updatedAt: expect.any(String)
// })
// })
it('should allow any user to access a global project', async () => {
const response = await app.inject({
method: 'GET',
url: `/project/${globalProject.slug}`,
headers: {
'x-e2e-user-email': user2.email // user2 is not a member of workspace1
}
})

expect(response.statusCode).toBe(200)
expect(response.json()).toEqual({
...globalProject,
lastUpdatedById: user1.id,
environmentCount: 1,
secretCount: 0,
variableCount: 0,
createdAt: expect.any(String),
updatedAt: expect.any(String)
})
})

it('should allow workspace members with READ_PROJECT to access an internal project', async () => {
const response = await app.inject({
13 changes: 8 additions & 5 deletions apps/api/src/project/service/project.service.ts
Original file line number Diff line number Diff line change
@@ -1221,11 +1221,14 @@ export class ProjectService {
await this.authorityCheckerService.checkAuthorityOverEnvironment({
userId: user.id,
entity: { slug: env.slug },
authorities: [
Authority.READ_ENVIRONMENT,
Authority.READ_SECRET,
Authority.READ_VARIABLE
],
authorities:
project.accessLevel == ProjectAccessLevel.GLOBAL
? []
: [
Authority.READ_ENVIRONMENT,
Authority.READ_SECRET,
Authority.READ_VARIABLE
],
prisma: this.prisma
})
if (hasRequiredPermission) {