-
-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: filter projectless events for normal users (#7914)
Now events that do not have project ( for example user creation, segment creation etc), will not be displayed to non root admins.
- Loading branch information
Showing
15 changed files
with
246 additions
and
44 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,3 @@ | ||
export interface IAccessReadModel { | ||
isRootAdmin(userId: number): Promise<boolean>; | ||
} |
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,28 @@ | ||
import { | ||
ADMIN_TOKEN_USER, | ||
type IAccessStore, | ||
type IUnleashStores, | ||
SYSTEM_USER_ID, | ||
} from '../../types'; | ||
import type { IAccessReadModel } from './access-read-model-type'; | ||
import * as permissions from '../../types/permissions'; | ||
|
||
const { ADMIN } = permissions; | ||
|
||
export class AccessReadModel implements IAccessReadModel { | ||
private store: IAccessStore; | ||
|
||
constructor({ accessStore }: Pick<IUnleashStores, 'accessStore'>) { | ||
this.store = accessStore; | ||
} | ||
|
||
async isRootAdmin(userId: number): Promise<boolean> { | ||
if (userId === SYSTEM_USER_ID || userId === ADMIN_TOKEN_USER.id) { | ||
return true; | ||
} | ||
const roles = await this.store.getRolesForUserId(userId); | ||
return roles.some( | ||
(role) => role.name.toLowerCase() === ADMIN.toLowerCase(), | ||
); | ||
} | ||
} |
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 type { Db, IUnleashConfig } from '../../server-impl'; | ||
import type { IAccessReadModel } from './access-read-model-type'; | ||
import { AccessReadModel } from './access-read-model'; | ||
import { AccessStore } from '../../db/access-store'; | ||
import FakeRoleStore from '../../../test/fixtures/fake-role-store'; | ||
import FakeAccessStore from '../../../test/fixtures/fake-access-store'; | ||
import type { IAccessStore } from '../../types'; | ||
|
||
export const createAccessReadModel = ( | ||
db: Db, | ||
config: IUnleashConfig, | ||
): IAccessReadModel => { | ||
const { eventBus, getLogger } = config; | ||
const accessStore = new AccessStore(db, eventBus, getLogger); | ||
return new AccessReadModel({ accessStore }); | ||
}; | ||
|
||
export const createFakeAccessReadModel = ( | ||
accessStore?: IAccessStore, | ||
): IAccessReadModel => { | ||
const roleStore = new FakeRoleStore(); | ||
const finalAccessStore = accessStore ?? new FakeAccessStore(roleStore); | ||
return new AccessReadModel({ accessStore: finalAccessStore }); | ||
}; |
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
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
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
Oops, something went wrong.