-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[permissions] Remove raw queries and restrict its usage #12360
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
base: main
Are you sure you want to change the base?
Conversation
…atasource for control
@@ -3,11 +3,11 @@ import { DataSource } from 'typeorm'; | |||
const tableName = 'billingSubscription'; | |||
|
|||
export const seedBillingSubscriptions = async ( | |||
workspaceDataSource: DataSource, | |||
dataSource: DataSource, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clarifying name here and in other files as Datasource is not equal to WorkspaceDataSource, and does not require shouldBypassPermissionCheck
indication.
For workspaceDataSource we have implemented permissions and overriden createQueryBuilder(). DataSource is not restricted to a workspace and can perform operations on core + on any workspace. Its usage is restricted to "system" operations.
|
||
return isDefined(recordWithMinPosition?.position) | ||
? recordWithMinPosition.position - index - 1 | ||
const recordWithMinPosition = await this.findMinPosition( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomtrp fyi
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:24796 This environment will automatically shut down when the PR is closed or after 5 hours. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR implements a significant security improvement by removing raw SQL queries and enforcing repository usage with proper permission checks throughout the codebase. The changes affect multiple modules and services across the application.
- Replaces
WorkspaceDataSourceService
withTwentyORMGlobalManager
in multiple modules, enforcing permission checks through repositories - Removes
WorkspaceMemberWorkspaceEntity
from several modules, suggesting workspace member access is now handled through dedicated repositories - Adds
shouldBypassPermissionChecks
flag requirement for any remaining raw queries in migration/seed files - Replaces
SelectQueryBuilder
withWorkspaceSelectQueryBuilder
to ensure proper permission handling in GraphQL queries - Removes deprecated utility files like
build-record-position-query.util.ts
in favor of repository-based implementations
46 file(s) reviewed, 13 comment(s)
Edit PR Review Bot Settings | Greptile
...tabase/commands/upgrade-version-command/0-43/0-43-migrate-rich-text-content-patch.command.ts
Show resolved
Hide resolved
...tabase/commands/upgrade-version-command/0-43/0-43-migrate-rich-text-content-patch.command.ts
Show resolved
Hide resolved
...er/src/engine/api/graphql/graphql-query-runner/graphql-query-parsers/graphql-query.parser.ts
Show resolved
Hide resolved
findOneBy: jest.fn(), | ||
update: jest.fn(), | ||
minimum: jest.fn().mockResolvedValue(1), | ||
maximum: jest.fn().mockResolvedValue(1), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Mock repository methods should verify input parameters and return types match the actual repository interface
Closes twentyhq/core-team-issues#748
In the frame of the work on permissions we