Félix Malfait and GitHub
9a80164cf3
Add comprehensive permission guard coverage across GraphQL and REST endpoints ( #15739 )
...
This PR enhances our security model by ensuring all GraphQL resolvers
and REST API endpoints have appropriate permission guards.
## Changes
### ESLint Rules
- Enhanced `graphql-resolvers-should-be-guarded` to require permission
guards on all resolvers (Query, Mutation, Subscription), not just
mutations
- Enhanced `rest-api-methods-should-be-guarded` to require permission
guards on all REST endpoints (GET, POST, PUT, PATCH, DELETE), not just
mutating methods
- Both rules now enforce consistent security: authentication guards +
permission guards for all endpoints
### Permission Guards Added
**Public Endpoints** - Added `NoPermissionGuard`:
- Auth-related queries (checkUserExists, findWorkspaceFromInviteHash,
validatePasswordResetToken)
- Billing webhooks (Stripe callbacks)
- SSO callbacks (SAML authentication)
- Workflow webhooks
- Cloudflare webhooks
- Route trigger endpoints
- GraphQL subscriptions
- Current workspace queries
- Geo-map address autocomplete
- View-related read operations (view-field, view-filter, view-group,
view-sort, view-filter-group)
**Settings Permission Guards** - Added `SettingsPermissionGuard`:
- API Keys management: `PermissionFlagType.API_KEYS_AND_WEBHOOKS`
- Webhooks management: `PermissionFlagType.API_KEYS_AND_WEBHOOKS`
- Page Layouts (write operations): `PermissionFlagType.LAYOUTS`
- REST Metadata API: `PermissionFlagType.DATA_MODEL`
- Agent operations: `PermissionFlagType.AI`
- Remote servers: `PermissionFlagType.DATA_MODEL`
- Remote tables: `PermissionFlagType.DATA_MODEL`
- Serverless functions: `PermissionFlagType.WORKFLOWS`
**Custom Permission Guards** - Added `CustomPermissionGuard`:
- REST Core API (permissions checked at query execution layer)
- Timeline calendar events (permission checks in service layer)
- Timeline messaging (permission checks in service layer)
- Search operations (permission checks in service layer)
- View operations (permission checks via dedicated view permission
guards)
### View Permission Guards
- Created dedicated `FindManyViewsPermissionGuard` and
`FindOneViewPermissionGuard` for reading views
- Created `CreateViewPermissionGuard` for view creation with
visibility-based permission checks
- All view child entities (view-field, view-filter, view-sort,
view-group, view-filter-group) use `NoPermissionGuard` for reads
- Write operations on view child entities use dedicated permission
guards that check parent view access
### Page Layout Permissions
- Read operations (GET/Query) now use `NoPermissionGuard` - users can
view layouts without LAYOUTS permission
- Write operations (POST/PATCH/DELETE/Mutation) require
`SettingsPermissionGuard(PermissionFlagType.LAYOUTS)`
- Applied consistently across page-layout, page-layout-tab, and
page-layout-widget endpoints
## Security Model
All endpoints now follow a consistent pattern:
1. **Authentication**: `UserAuthGuard`, `WorkspaceAuthGuard`, or
`PublicEndpointGuard`
2. **Authorization**: One of:
- `SettingsPermissionGuard(PermissionFlagType.XXX)` - for settings/admin
operations
- `CustomPermissionGuard` - when permissions are checked in service/data
layer
- `NoPermissionGuard` - for public or non-sensitive read operations
The ESLint rules automatically enforce this pattern going forward.
## Stats
- 47 files changed
- 603 insertions, 163 deletions
- 3 new guard files created
2025-11-10 12:17:38 +01:00
Félix Malfait and GitHub
b7f5445926
fix: rename SettingsPermissionsGuard to SettingsPermissionGuard for consistency ( #15712 )
...
## Problem
The ESLint rule `graphql-resolvers-should-be-guarded` introduced in
#15392 was failing on main because the guard `SettingsPermissionsGuard`
had inconsistent naming.
## Root Cause
The guard was named `SettingsPermissionsGuard` (with an 's') which was
inconsistent with other permission guards:
- ✅ `CustomPermissionGuard`
- ✅ `NoPermissionGuard`
- ✅ `ImpersonatePermissionGuard`
- ❌ `SettingsPermissionsGuard` (inconsistent!)
The ESLint rule checks if guard names end with `PermissionGuard`, but
`SettingsPermissionsGuard` ends with `sGuard`, so it wasn't recognized
as a permission guard.
## Solution
Renamed the guard to be consistent with the naming convention:
1. ✅ Renamed file: `settings-permissions.guard.ts` →
`settings-permission.guard.ts`
2. ✅ Renamed export: `SettingsPermissionsGuard` →
`SettingsPermissionGuard`
3. ✅ Renamed internal class: `SettingsPermissionsMixin` →
`SettingsPermissionMixin`
4. ✅ Updated all 122 references across 44 files in the codebase
5. ✅ Renamed test file: `settings-permissions.guard.spec.ts` →
`settings-permission.guard.spec.ts`
## Testing
- ✅ `npx nx run twenty-server:lint` passes
- ✅ `npx nx run twenty-server:typecheck` passes
- ✅ No references to the old name remain in the codebase
- ✅ All previously failing resolver files now pass ESLint validation
## Related
Fixes issues introduced in #15392
2025-11-07 18:22:28 +01:00
Paul Rastoin and GitHub
f6f52d676f
Explicitly set workspaceId column as uuid type to ease pg LEFT JOIN ( #15430 )
...
Pg scan was redundant because historically the workspaceId was
`varchar`, even though below migration won't change that we had a look
to workspaceId col declaration across the codebase
2025-10-29 19:08:44 +01:00
c5564d9bd0
[BREAKING CHANGE] refactor: Add Entity suffix to TypeORM entity classes ( #15239 )
...
## Summary
This PR refactors all TypeORM entity classes in the Twenty codebase to
include an 'Entity' suffix (e.g., User → UserEntity, Workspace →
WorkspaceEntity) to improve code clarity and follow TypeORM naming
conventions.
## Changes
### Entity Renaming
- ✅ Renamed **57 core TypeORM entities** with 'Entity' suffix
- ✅ Updated all related imports, decorators, and type references
- ✅ Fixed Repository<T>, @InjectRepository(), and
TypeOrmModule.forFeature() patterns
- ✅ Fixed @ManyToOne/@OneToMany/@OneToOne decorator references
### Backward Compatibility
- ✅ Preserved GraphQL schema names using @ObjectType('OriginalName')
decorators
- ✅ **No breaking changes** to GraphQL API
- ✅ **No database migrations** required
- ✅ File names unchanged (user.entity.ts remains as-is)
### Code Quality
- ✅ Fixed **497 TypeScript errors** (82% reduction from 606 to 109)
- ✅ **All linter checks passing**
- ✅ Improved type safety across the codebase
## Entities Renamed
```
User → UserEntity
Workspace → WorkspaceEntity
ApiKey → ApiKeyEntity
AppToken → AppTokenEntity
UserWorkspace → UserWorkspaceEntity
Webhook → WebhookEntity
FeatureFlag → FeatureFlagEntity
ApprovedAccessDomain → ApprovedAccessDomainEntity
TwoFactorAuthenticationMethod → TwoFactorAuthenticationMethodEntity
WorkspaceSSOIdentityProvider → WorkspaceSSOIdentityProviderEntity
EmailingDomain → EmailingDomainEntity
KeyValuePair → KeyValuePairEntity
PublicDomain → PublicDomainEntity
PostgresCredentials → PostgresCredentialsEntity
...and 43 more entities
```
## Impact
### Files Changed
- **400 files** modified
- **2,575 insertions**, **2,191 deletions**
### Progress
- ✅ **82% complete** (497/606 errors fixed)
- ⚠️ **109 TypeScript errors** remain (18% of original)
## Remaining Work
The 109 remaining TypeScript errors are primarily:
1. **Function signature mismatches** (~15 errors) - Test mocks with
incorrect parameter counts
2. **Entity type mismatches** (~25 errors) - UserEntity vs
UserWorkspaceEntity confusion
3. **Pre-existing issues** (~50 errors) - Null safety and DTO
compatibility (unrelated to refactoring)
4. **Import type issues** (~10 errors) - Entities imported with 'import
type' but used as values
5. **Minor decorator issues** (~9 errors) - onDelete property
configurations
These can be addressed in follow-up PRs without blocking this
refactoring.
## Testing Checklist
- [x] Linter passing
- [ ] Unit tests should be run (CI will verify)
- [ ] Integration tests should be run (CI will verify)
- [ ] Manual testing recommended for critical user flows
## Breaking Changes
**None** - This is a pure refactoring with full backward compatibility:
- GraphQL API unchanged (uses original entity names)
- Database schema unchanged
- External APIs unchanged
## Notes
- Created comprehensive `REFACTORING_STATUS.md` documenting the entire
process
- All temporary scripts have been cleaned up
- Branch: `refactor/add-entity-suffix-to-typeorm-entities`
## Reviewers
Please review especially:
- Entity renaming patterns
- GraphQL backward compatibility
- Any areas where entity types are confused (UserEntity vs
UserWorkspaceEntity)
---------
Co-authored-by: Charles Bochet <charles@twenty.com >
2025-10-22 09:55:20 +02:00
Félix Malfait and GitHub
e577c2d746
Update user friendly errors for translations ( #15000 )
...
Force msg typing instead of string for user friendly errors
2025-10-09 18:17:32 +02:00
2685f4a5b9
Restructure agent chat messages with parts-based architecture ( #14749 )
...
Co-authored-by: Félix Malfait <felix@twenty.com >
2025-09-29 13:31:55 +02:00
nitin and GitHub
4ba1bd24f0
remove IS_API_KEY_ROLES_ENABLED feature flag ( #14366 )
2025-09-09 19:29:29 +02:00
79bcd90d8d
Feat: role applicability controls ( #14239 )
...
Closes [#1404 ](https://github.com/twentyhq/core-team-issues/issues/1404 )
---------
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2025-09-04 08:58:50 +05:30
Weiko and GitHub
533d7fe49a
Deprecate legacy core datasource token ( #14096 )
2025-08-27 20:09:54 +02:00
Félix Malfait and GitHub
0236f79ccf
Fix assert unreachable, remove unused variables ( #13753 )
...
Small code cleanup
2025-08-08 09:04:45 +02:00
Félix Malfait and GitHub
8b4b9ef8da
Change type import rule ( #13751 )
...
Forcing "type" to be explicit, works best will rollup on the frontend to
exclude depdendencies
2025-08-08 01:27:05 +02:00
Abdul Rahman and GitHub
01f25519f6
fix: standardize GraphQL schema UUID field types ( #13550 )
...
Closes [#1264 ](https://github.com/twentyhq/core-team-issues/issues/1264 )
2025-08-04 11:43:48 +02:00
nitin and GitHub
4cd2a87833
Enable roles on api keys ( #13334 )
2025-08-02 23:54:10 +02:00
Antoine Moreaux and GitHub
23353e31e6
feat(domain-manager): refactor custom domain validation and improve c… ( #13388 )
2025-08-01 09:01:27 +02:00
nitin and GitHub
0e561e4ef4
fix: migrate webhook and API key REST endpoints to core schema ( #13318 )
...
## Problem
After migrating webhooks and API keys from workspace to core level, REST
API endpoints were still creating entities in workspace schema
(`workspace_*`) instead of core schema, causing webhooks to not fire.
## Solution
- Added dedicated REST controllers for webhooks (`/rest/webhooks`) and
API keys (`/rest/apiKeys`)
- Updated dynamic controller to block workspace-gated entities from
being processed
- Fixed OpenAPI documentation to exclude these endpoints from playground
- Ensured return formats match GraphQL resolvers exactly
## Testing
✅ All endpoints tested with provided auth token - webhooks and API keys
now correctly stored in `core` schema
2025-07-23 13:11:53 +00:00
484c267aa6
Api keys and webhook migration to core ( #13011 )
...
TODO: check Zapier trigger records work as expected
---------
Co-authored-by: Weiko <corentin@twenty.com >
2025-07-09 17:03:54 +02:00