-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix organization admin check in
firestore.rules
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,9 @@ describe('Test Firestore rules', () => { | |
await users | ||
.doc('[email protected]') | ||
.set({ name: 'Super Admin', superAdmin: true }); | ||
await users | ||
.doc('[email protected]') | ||
.set({ name: 'Org Y Admin', admin: ['organization-y'] }); | ||
await users | ||
.doc('[email protected]') | ||
.set({ name: 'User', admin: ['organization-x'] }); | ||
|
@@ -67,6 +70,11 @@ describe('Test Firestore rules', () => { | |
organization: organizations.doc('organization-x'), | ||
department: departments.doc('department-x1'), | ||
}); | ||
await products.doc('product-y1').set({ | ||
name: 'Product Y1', | ||
organization: organizations.doc('organization-y'), | ||
department: departments.doc('department-y1'), | ||
}); | ||
|
||
await objectives.doc('department-x1-objective-1').set({ | ||
name: 'Department X1 - Objective 1', | ||
|
@@ -159,6 +167,48 @@ describe('Test Firestore rules', () => { | |
}); | ||
}); | ||
|
||
test('users cannot update organizations', async () => { | ||
await withAuthenticatedUser(testEnv, '[email protected]', async (db) => { | ||
const organization = db.collection('organizations').doc('organization-x'); | ||
await expectPermissionDenied(organization.update({ name: 'Org X' })); | ||
}); | ||
}); | ||
|
||
test('users cannot delete organizations', async () => { | ||
await withAuthenticatedUser(testEnv, '[email protected]', async (db) => { | ||
const organization = db.collection('organizations').doc('organization-x'); | ||
await expectPermissionDenied(organization.delete()); | ||
}); | ||
}); | ||
|
||
test('organization admin can update own organization', async () => { | ||
await withAuthenticatedUser(testEnv, '[email protected]', async (db) => { | ||
const organizationX = db.collection('organizations').doc('organization-x'); | ||
const organizationY = db.collection('organizations').doc('organization-y'); | ||
await expectPermissionDenied(organizationX.update({ name: 'Org X' })); | ||
await expectUpdateSucceeds(organizationY.update({ name: 'Org Y' })); | ||
expect((await organizationX.get()).data().name).toBe('Organization X'); | ||
expect((await organizationY.get()).data().name).toBe('Org Y'); | ||
}); | ||
}); | ||
|
||
test('organization admin can update own child departments and products', async () => { | ||
await withAuthenticatedUser(testEnv, '[email protected]', async (db) => { | ||
const departmentX1 = db.collection('departments').doc('department-x1'); | ||
const departmentY1 = db.collection('departments').doc('department-y1'); | ||
const productX1 = db.collection('products').doc('product-x1'); | ||
const productY1 = db.collection('products').doc('product-y1'); | ||
await expectPermissionDenied(departmentX1.update({ name: 'Dep X1' })); | ||
await expectUpdateSucceeds(departmentY1.update({ name: 'Dep Y1' })); | ||
await expectPermissionDenied(productX1.update({ name: 'Prod X1' })); | ||
await expectUpdateSucceeds(productY1.update({ name: 'Prod Y1' })); | ||
expect((await departmentX1.get()).data().name).toBe('Department X1'); | ||
expect((await departmentY1.get()).data().name).toBe('Dep Y1'); | ||
expect((await productX1.get()).data().name).toBe('Product X1'); | ||
expect((await productY1.get()).data().name).toBe('Prod Y1'); | ||
}); | ||
}); | ||
|
||
test('anonymous users cannot read objective contributors', async () => { | ||
await withUnauthenticatedUser(testEnv, async (db) => { | ||
const oc = db.collection('objectiveContributors').doc('objective-contributor-1'); | ||
|