Compare commits
22
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd61c00ad1 | ||
|
|
d8f422f98d | ||
|
|
7f200df1ac | ||
|
|
9b38ed65c0 | ||
|
|
25c20e5093 | ||
|
|
ec8a441649 | ||
|
|
04a91dc71a | ||
|
|
2023926a3a | ||
|
|
75465ac4bf | ||
|
|
2dbd0b3832 | ||
|
|
3b7d97b194 | ||
|
|
a1fab0e744 | ||
|
|
87331f0a3a | ||
|
|
6cd4f1fcaa | ||
|
|
6b84dc09a7 | ||
|
|
d125064430 | ||
|
|
39490b6883 | ||
|
|
e45f9c5a13 | ||
|
|
9ceb5ea3c5 | ||
|
|
16bd52148e | ||
|
|
9a2705c84c | ||
|
|
6c069a4afe |
@@ -0,0 +1,82 @@
|
||||
# Cal.com Development Guide for AI Agents
|
||||
|
||||
This directory contains comprehensive documentation for AI agents working on the Cal.com codebase.
|
||||
|
||||
## Quick Navigation
|
||||
|
||||
- **[Commands](commands.md)** - Build, test, and development commands
|
||||
- **[Knowledge Base](knowledge-base.md)** - Knowledge base & best practices
|
||||
- **[Architecture Overview](#architecture-overview)** - System structure and patterns
|
||||
|
||||
## Getting Started
|
||||
|
||||
Cal.com is a monorepo using Yarn workspaces and Turbo for build orchestration. The main application is in `apps/web/` with shared packages in `packages/`.
|
||||
|
||||
### Key Directories
|
||||
|
||||
- `apps/web/` - Main Next.js application
|
||||
- `packages/prisma/` - Database schema and migrations
|
||||
- `packages/trpc/` - API layer using tRPC
|
||||
- `packages/ui/` - Shared UI components
|
||||
- `packages/features/` - Feature-specific code
|
||||
- `packages/app-store/` - Third-party app integrations
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
### Database Layer
|
||||
|
||||
- **Prisma ORM** with PostgreSQL
|
||||
- Schema in `packages/prisma/schema.prisma`
|
||||
- Always use `select` instead of `include` for better performance
|
||||
- Never expose `credential.key` field in API responses
|
||||
|
||||
### API Layer
|
||||
|
||||
- **tRPC** for type-safe APIs
|
||||
- Routers in `packages/trpc/server/routers/`
|
||||
- Authentication handled via NextAuth.js
|
||||
|
||||
### Frontend
|
||||
|
||||
- **Next.js 13+** with App Router in some areas
|
||||
- **React 18** with TypeScript
|
||||
- **Tailwind CSS** for styling
|
||||
- Internationalization with `next-i18next`
|
||||
|
||||
## Common Patterns
|
||||
|
||||
### Error Handling
|
||||
|
||||
- Use early returns to reduce nesting
|
||||
- Throw descriptive errors with proper error codes
|
||||
- Prefer composition over prop drilling
|
||||
|
||||
### Performance
|
||||
|
||||
- Avoid O(n²) logic in backend code
|
||||
- Minimize Day.js usage in performance-critical paths
|
||||
- Use `select` queries to only fetch needed data
|
||||
- Consider using `.utc()` for Day.js operations
|
||||
|
||||
### Security
|
||||
|
||||
- Never commit secrets or API keys
|
||||
- Always validate input data
|
||||
- Use proper authentication checks
|
||||
- Never expose sensitive credential fields
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
- **Unit tests** with Vitest
|
||||
- **Integration tests** for complex workflows
|
||||
- **E2E tests** with Playwright
|
||||
- Test files use `.test.ts` or `.spec.ts` extensions
|
||||
|
||||
## Pull Request Guidelines
|
||||
|
||||
For large PRs (>500 lines or >10 files):
|
||||
|
||||
- Split by feature boundaries
|
||||
- Separate database migrations, backend logic, frontend components
|
||||
- Create dependency chains that can be merged sequentially
|
||||
- Pattern: Database → Backend → Frontend → Tests
|
||||
@@ -0,0 +1,56 @@
|
||||
# Coding Standards & Best Practices
|
||||
|
||||
|
||||
|
||||
## Import Guidelines
|
||||
|
||||
### Type Imports
|
||||
|
||||
```typescript
|
||||
// ✅ Good - Use type imports for TypeScript types
|
||||
import type { User } from "@prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
// ❌ Bad - Regular import for types
|
||||
import { User } from "@prisma/client";
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Code Structure
|
||||
|
||||
### Early Returns
|
||||
|
||||
- Prefer early returns to reduce nesting: `if (!booking) return null;`
|
||||
|
||||
### Composition Over Prop Drilling
|
||||
|
||||
- Use React children and context instead of passing props through multiple components
|
||||
|
||||
### Security Rules
|
||||
|
||||
```typescript
|
||||
// ❌ NEVER expose credential keys
|
||||
const user = await prisma.user.findFirst({
|
||||
select: {
|
||||
credentials: {
|
||||
select: {
|
||||
key: true, // ❌ NEVER do this
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ✅ Good - Never select credential.key field
|
||||
const user = await prisma.user.findFirst({
|
||||
select: {
|
||||
credentials: {
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
// key field is excluded for security
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
@@ -0,0 +1,83 @@
|
||||
# Build, Test & Development Commands
|
||||
|
||||
## Development Commands
|
||||
|
||||
- `yarn dev` - Start development server for web app
|
||||
- `yarn dev:all` - Start web, website, and console apps
|
||||
- `yarn dev:api` - Start web app with API proxy and API
|
||||
- `yarn dev:console` - Start web app with console
|
||||
- `yarn dx` - Start development with database setup
|
||||
|
||||
## Build Commands
|
||||
|
||||
- `yarn build` - Build all packages and apps
|
||||
- `yarn build:ai` - Build AI package specifically
|
||||
- `yarn clean` - Remove build artifacts (node_modules, .next, .turbo, dist)
|
||||
|
||||
## Lint & Type Check
|
||||
|
||||
- `yarn lint` - Run ESLint on codebase
|
||||
- `yarn lint:fix` - Run ESLint and fix issues
|
||||
- `yarn lint:report` - Generate lint report
|
||||
- `yarn type-check` - Run TypeScript type checking
|
||||
- `yarn format` - Format code with Prettier
|
||||
|
||||
## Testing Commands
|
||||
|
||||
### Unit Tests
|
||||
|
||||
- `yarn test` - Run unit tests (vitest)
|
||||
- `yarn test <filename>` - Run tests for specific file
|
||||
- `yarn test <filename> -- --integrationTestsOnly` - Run integration tests for specific file
|
||||
- `yarn test <filename> -t "<testName>" -- --integrationTestsOnly` - Run specific test by name
|
||||
- `yarn tdd` - Run tests in watch mode
|
||||
- `yarn test:ui` - Run tests with UI interface
|
||||
|
||||
### End-to-End Tests
|
||||
|
||||
- `yarn e2e` - Run end-to-end tests (Playwright)
|
||||
- `yarn e2e <filename>` - Run E2E tests for specific file
|
||||
- `yarn e2e <filename> --grep "<testName>"` - Run specific E2E test by name
|
||||
- `yarn e2e:app-store` - Run app store E2E tests
|
||||
- `yarn e2e:embed` - Run embed E2E tests
|
||||
- `yarn test-e2e` - Run database seed + E2E tests
|
||||
|
||||
## Database Commands
|
||||
|
||||
- `yarn prisma` - Run Prisma CLI commands
|
||||
- `yarn db-seed` - Seed database with test data
|
||||
- `yarn db-deploy` - Deploy database migrations
|
||||
- `yarn db-studio` - Open Prisma Studio
|
||||
- `psql "postgresql://postgres:@localhost:5432/calendso"` - Connect to local PostgreSQL database
|
||||
|
||||
## App Store Commands
|
||||
|
||||
- `yarn create-app` - Create new app store integration
|
||||
- `yarn edit-app` - Edit existing app
|
||||
- `yarn delete-app` - Delete app
|
||||
- `yarn app-store:build` - Build app store
|
||||
- `yarn app-store:watch` - Watch app store for changes
|
||||
|
||||
## Useful Development Patterns
|
||||
|
||||
### Running Single Tests
|
||||
|
||||
```bash
|
||||
# Unit test specific file
|
||||
yarn vitest run packages/lib/some-file.test.ts
|
||||
|
||||
# Integration test specific file
|
||||
yarn test routing-form-response-denormalized.integration-test.ts -- --integrationTestsOnly
|
||||
|
||||
# E2E test specific file
|
||||
yarn e2e tests/booking-flow.e2e.ts
|
||||
|
||||
# Run specific test by name
|
||||
yarn e2e tests/booking-flow.e2e.ts --grep "should create booking"
|
||||
```
|
||||
|
||||
### Environment Setup
|
||||
|
||||
- Copy `.env.example` to `.env` and configure
|
||||
- Copy `.env.appStore.example` to `.env.appStore` for app store development
|
||||
- Run `yarn dx` for initial development setup with database
|
||||
@@ -0,0 +1,320 @@
|
||||
# Knowledge Base - Product & Domain-Specific Information
|
||||
|
||||
## Repo note for calcom/cal.com
|
||||
|
||||
The whole thing is a monorepo. You need to be working in the apps/web folder.
|
||||
|
||||
Linting and Formatting
|
||||
- Run lint with report generation: `yarn lint:report`
|
||||
- Run type checking: `yarn type-check:ci --force`
|
||||
- Run auto-fix: `yarn lint -- --fix`
|
||||
|
||||
Development
|
||||
- Install dependencies: `yarn`
|
||||
- Set up environment:
|
||||
- Copy `.env.example` to `.env`
|
||||
- Generate keys with `openssl rand -base64 32` for both `NEXTAUTH_SECRET` and `CALENDSO_ENCRYPTION_KEY`
|
||||
- Configure Postgres database URL in `.env`
|
||||
- Set DATABASE_DIRECT_URL to the same value as DATABASE_URL
|
||||
|
||||
Database Setup
|
||||
- Development: `yarn workspace @calcom/prisma db-migrate`
|
||||
- Production: `yarn workspace @calcom/prisma db-deploy`
|
||||
|
||||
When setting up local development database, it'll create a bunch of users for you. The passwords are the same as the username. e.g. 'free:free' and 'pro:pro'
|
||||
|
||||
PR Requirements
|
||||
- PR title must follow Conventional Commits specification
|
||||
- For most PRs, you only need to run linting and type checking
|
||||
- E2E tests will only run if PR has "ready-for-e2e" label
|
||||
|
||||
Logging
|
||||
- Control logging verbosity by setting `NEXT_PUBLIC_LOGGER_LEVEL` in .env:
|
||||
- 0: silly
|
||||
- 1: trace
|
||||
- 2: debug
|
||||
- 3: info
|
||||
- 4: warn
|
||||
- 5: error
|
||||
- 6: fatal
|
||||
|
||||
## When addressing issues in the Cal.com repository
|
||||
|
||||
When working on the Cal.com repository, prioritize fixing type issues before addressing failing tests. Running `yarn type-check:ci --force` to identify and fix TypeScript errors should be done first, as these errors are often the root cause of test failures. Only after resolving type issues should you move on to fixing failing tests with `TZ=UTC yarn test`.
|
||||
|
||||
## When creating pull requests
|
||||
|
||||
Create pull requests in draft mode by default, so that actual human can mark it as ready for review only when it is.
|
||||
|
||||
## When developing Playwright tests in the Cal.com repository
|
||||
|
||||
Always ensure Playwright tests pass locally before pushing code. The user requires fast local e2e feedback loops instead of relying on CI, which is too slow for development iteration. Never push test code until those tests are passing locally first.
|
||||
|
||||
## When fixing failing tests in the Cal.com repository
|
||||
|
||||
When fixing failing tests in the Cal.com repository, take an incremental approach by addressing one file at a time rather than attempting to fix all issues simultaneously. This methodical approach makes it easier to identify and resolve specific issues without getting overwhelmed by the complexity of multiple failing tests across different files. Focus on getting each file's tests passing completely before moving on to the next file.
|
||||
|
||||
To identify and fix issues in the Cal.com codebase:
|
||||
|
||||
1. Run `yarn type-check:ci --force` to identify TypeScript type errors and get fresh results always, bypassing any caching issues
|
||||
2. Run `yarn test` to identify failing unit tests
|
||||
3. Address both type errors and failing tests before considering the task complete
|
||||
4. Type errors often need to be fixed first as they may be causing the test failures
|
||||
|
||||
## When implementing mock services in the Cal.com test files
|
||||
|
||||
When mocking calendar services in Cal.com test files, implement the Calendar interface rather than adding individual properties from each specific calendar service type (like FeishuCalendarService). Since all calendar services implement the Calendar interface and are stored in a map, the mock service should also implement this interface to ensure type compatibility. This approach is more maintainable than trying to add all properties from each specific calendar service implementation. For complex mocks that cause type compatibility issues with deep mocks, consider using simpler fake implementations that directly implement the required interfaces instead of trying to match all properties of the original service classes. When needed, you can modify other mock files to support your implementation rather than trying to force compatibility with existing mocks.
|
||||
|
||||
## When implementing mocks for Cal.com app-store integrations
|
||||
|
||||
When mocking app-store resources in Cal.com tests, prefer implementing simpler mock designs that directly implement the required interfaces rather than trying to match complex deep mock structures created with mockDeep. This approach is more maintainable and helps resolve type compatibility issues. The user encourages creative solutions and refactoring to better designs when the standard mocking approach causes persistent type errors.
|
||||
|
||||
## When implementing workflow triggers in the Cal.com repository
|
||||
|
||||
To trigger workflows in Cal.com, use the `scheduleWorkflowReminders` function. This is the standard approach used throughout the codebase for triggering any workflow. Before implementing new workflow triggers, examine existing implementations in the codebase to understand the pattern. The function filters workflows by trigger type and processes each workflow step. Key locations where this is used include booking handlers, confirmation processes, and other booking-related events.
|
||||
|
||||
## When making changes to Prisma schema in Cal.com
|
||||
|
||||
After making changes to the Prisma schema in Cal.com and creating migrations, you need to run `yarn prisma generate` to update the TypeScript types. This is especially important when switching Node.js versions, after adding new fields to models, or after pulling changes that include Prisma schema updates, as it ensures the TypeScript compiler recognizes the updated schema structure. If you encounter errors related to missing enum values (like CreationSource.WEBAPP), running `yarn prisma generate` will typically resolve these issues by regenerating the TypeScript types from the schema.
|
||||
|
||||
If you encounter enum generator errors during the Prisma generate step (like "Cannot find module './enum-generator.ts'"), run `yarn install` first before trying to generate. This ensures all dependencies are properly installed before the generation process.
|
||||
|
||||
Whenever you change the schema.prisma file, remember to always consolidate migrations by squashing them as declared in the Prisma docs: https://www.prisma.io/docs/orm/prisma-migrate/workflows/squashing-migrations. This helps maintain a clean migration history and prevents accumulation of multiple migration files.
|
||||
|
||||
## When reviewing PRs in the Cal.com repository
|
||||
|
||||
When asked to review a PR, focus on providing a clear summary of what the PR is doing and its core functionality. Avoid getting sidetracked by CI failures, testing issues, or technical implementation details unless specifically requested. The user prefers concise, focused reviews that prioritize understanding the main purpose and changes of the PR.
|
||||
|
||||
## When running Playwright tests in the Cal.com repository
|
||||
|
||||
Use the command format `PLAYWRIGHT_HEADLESS=1 yarn e2e [test-file.e2e.ts]` to run Playwright tests instead of the standard `yarn playwright test` command. This format includes the proper timezone setting, virtual display server, and uses the repository's e2e runner.
|
||||
|
||||
## When running tests in the Cal.com repository
|
||||
|
||||
When running tests in the Cal.com repository, use the TZ=UTC environment variable (e.g., `TZ=UTC yarn test`) to ensure consistent timezone handling. This prevents timezone-related test failures that might occur when tests are run in different environments or by different developers with varying local timezone settings.
|
||||
|
||||
## When working on calendar cache features in the Cal.com codebase
|
||||
|
||||
The calendar cache system follows specific patterns in `packages/features/calendar-cache-sql`. When implementing provider-specific calendar cache services (like for Outlook/Office365), the provider-specific code should be placed in the corresponding provider directory (e.g., `packages/app-store/office365calendar`).
|
||||
|
||||
## When working on PRs in the Cal.com repository
|
||||
|
||||
When making changes to the Cal.com codebase, always run type checks locally using `yarn type-check:ci` before concluding that CI failures are unrelated to your changes. Even if errors appear in files you haven't directly modified, your changes might still be causing type issues through dependencies or type inference. Compare type check results between the main branch and your feature branch to confirm whether you've introduced new type errors.
|
||||
|
||||
## When working on type issues in the Cal.com repository
|
||||
|
||||
Type casting with "as any" is strictly forbidden in the Cal.com codebase. When encountering Prisma type incompatibilities or other TypeScript type issues, proper type-safe solutions must be used instead, such as Prisma extensions system, type parameter constraints, repository pattern isolation, explicit type definitions, and extension composition patterns that are already established in the codebase.
|
||||
|
||||
## When working on UI layout changes in the Cal.com web application
|
||||
|
||||
The event types page UI components are located in `apps/web/modules/event-types/views/event-types-listing-view.tsx`. This file contains the layout implementation for the search bar and team tabs components on the event types listing page.
|
||||
|
||||
Changes to shared UI patterns (like tab layouts and button alignments) need to be checked across multiple views to maintain consistency:
|
||||
- Event types page layout: `apps/web/modules/event-types/views/event-types-listing-view.tsx`
|
||||
- Bookings page layout: `apps/web/modules/bookings/views/bookings-listing-view.tsx`
|
||||
- Common elements like tabs, search bars, and filter buttons should maintain consistent alignment across views
|
||||
|
||||
## When working on workflow triggers or similar enum-based features in the Cal.com codebase
|
||||
|
||||
To add new workflow triggers:
|
||||
|
||||
1. Check packages/prisma/schema.prisma for existing webhooks and workflow trigger enums as reference
|
||||
2. Add the same enums to workflows (only when asked by user specifically, or else focus on users requirement)
|
||||
3. Add enums to packages/features/ee/workflows/lib/constants.ts for UI display
|
||||
4. Add translations to en/locale.json using the format {enum}_trigger (all lowercase). Webhook triggers serve as the reference implementation pattern for workflow triggers.
|
||||
|
||||
## When working with app-store integrations in Cal.com
|
||||
|
||||
The Cal.com repository uses generated files (*.generated.ts) for app-store integrations. These files are created by the app-store-cli tool. When making structural changes to how integrations are imported or used, you need to update CLI code that generates these files. Typically manual changes to the *.generated.ts files are not made. That was only for PR 19771 for a proof-of-concept. Recent changes have moved from dynamic imports to static map-based imports for better performance. When working with browser components in the app-store, static imports should be used rather than dynamic imports (using Next.js' dynamic function) to maintain consistency with the performance improvements.
|
||||
|
||||
When modifying the app-store-cli build.ts file, you must ensure it correctly handles all types of generated files:
|
||||
1. Regular service files (calendar.services.generated.ts, crm.services.generated.ts, etc.) need default imports
|
||||
2. Browser component files (apps.browser-addon.generated.tsx, etc.) may require dynamic imports with Next.js
|
||||
3. After making changes to build.ts, always verify all generated files have the correct imports by checking each file type
|
||||
|
||||
The lazyImport parameter in getExportedObject() determines whether to use dynamic imports (for browser components) or static imports (for server-side services).
|
||||
|
||||
## When working with branches in the Cal.com repository
|
||||
|
||||
When asked to move changes to a different branch in the Cal.com repository, use git commands to commit existing changes to the specified branch rather than redoing the work. This is more efficient and prevents duplication of effort. The user prefers direct branch operations over reimplementing the same changes multiple times.
|
||||
|
||||
## When working with calendar events in the Cal.com codebase
|
||||
|
||||
Cal.com events in Google Calendar can be identified by checking if the iCalUID ends with "@Cal.com" (e.g., "2GBXSdEixretciJfKVmYN8@Cal.com"). This identifier is used to distinguish Cal.com bookings from other calendar events for data storage and privacy purposes.
|
||||
|
||||
## When working with CI/CD in the Cal.com repository
|
||||
|
||||
When reviewing CI check failures in Cal.com:
|
||||
1. E2E tests can be flaky and may fail intermittently
|
||||
2. Focus only on CI failures that are directly related to your code changes
|
||||
3. Infrastructure-related failures (like dependency installation issues) can be disregarded if all code-specific checks (type checking, linting, unit tests) are passing
|
||||
|
||||
## When working with database models in Cal.com
|
||||
|
||||
Database models in Cal.com are defined in `packages/prisma/schema.prisma`. When adding new fields to models:
|
||||
|
||||
1. For timestamp fields like `createdAt` and `updatedAt`:
|
||||
- Do not set default values if you want existing records to have null values
|
||||
- Only new records should get timestamps automatically
|
||||
- For `updatedAt` fields, ensure they're updated when records are modified
|
||||
|
||||
2. Create a migration using `npx prisma migrate dev --name migration_name` to update the database schema
|
||||
|
||||
3. When implementing cache-related features that require timestamp tracking, always update the database schema first before modifying application code that references those fields. The schema changes must be completed and migrated before the application can successfully query or use the new fields.
|
||||
|
||||
## When working with generated files in the Cal.com repository
|
||||
|
||||
When fixing imports in Cal.com's generated files (like packages/app-store/apps.browser-*.generated.tsx), always check the actual exports in the source files first. For EventTypeAppCardInterface components, they likely use named exports rather than default exports, requiring imports like `import * as ComponentName from "./path"` instead of `import ComponentName from "./path"`. This verification step is crucial when working with browser-addon, browser-appsettings, browser-eventtypesettings, and browser-install generated files. For these files, if you're seeing import errors, check whether the components are exported as default exports in their source files and adjust your import statements accordingly.
|
||||
|
||||
## When working with git and CI systems
|
||||
|
||||
Always push committed changes to the remote repository before waiting for or checking CI status. Waiting for CI checks on unpushed local commits is backwards - the CI runs on the remote repository state, not local commits. The proper sequence is: commit locally, run local checks, push to remote, then monitor CI status.
|
||||
|
||||
## When working with imports/exports in the Cal.com codebase
|
||||
|
||||
When working with imports in the Cal.com codebase, particularly in app-store integrations, pay attention to whether modules use named exports or default exports. Many services like VideoApiAdapter, CalendarService, and PaymentService are exported as named exports, but the actual export name may differ from the generic service type (e.g., `export class AppleCalendarService` instead of `export class CalendarService`). When importing these services, verify the actual export name in the source file and use the appropriate named import syntax (e.g., `import { AppleCalendarService } from "./applecalendar/lib/CalendarService"` or with renaming `import { AppleCalendarService as ApplecalendarCalendarService } from "./applecalendar/lib/CalendarService"`). Always check the actual export pattern and name in the source file to determine the correct import syntax.
|
||||
|
||||
## When working with tRPC components in the Cal.com repository
|
||||
|
||||
When making changes that affect tRPC components or after pulling updates that modify tRPC-related files, you need to follow a specific build order:
|
||||
1. First run `yarn prisma generate` to ensure all database types are up-to-date
|
||||
2. Then run `cd packages/trpc && yarn build` to rebuild the tRPC package
|
||||
This sequence ensures that type definitions are properly generated before building the tRPC components that depend on them, preventing type errors during compilation.
|
||||
|
||||
## When working with workflows or webhooks in the Cal.com repository
|
||||
|
||||
Workflows and webhooks are two completely separate features in Cal.com with different implementations and file structures. The workflow constants file is located at `packages/features/ee/workflows/lib/constants.ts`, not in the webhooks directory. When working on workflow triggers, do not reference or use webhook trigger implementations - they are distinct systems that should not be confused or mixed.
|
||||
|
||||
## When adding new feature flags to the Cal.com repository
|
||||
|
||||
To seed new feature flags in Cal.com, create a Prisma migration using the command `yarn prisma migrate dev --create-only --name seed_[feature_name]_feature`. The migration file should be placed in `packages/prisma/migrations/` with a timestamp prefix format like `20250724210733_seed_calendar_cache_sql_features/migration.sql`. Follow the pattern from existing feature seeding migrations like `packages/prisma/migrations/20241216000000_add_calendar_cache_serve/migration.sql` for the SQL structure. The migration should INSERT the new features into the `Feature` table with appropriate type (like `OPERATIONAL`) and default `enabled` status for manual team enablement.
|
||||
|
||||
## When adding new UI elements or text strings to Cal.com
|
||||
|
||||
All UI strings in Cal.com must be properly translated using the i18n system. This includes:
|
||||
- Labels for new UI elements (like dropdown labels, settings headers)
|
||||
- Option values that are displayed to users
|
||||
- Any text that appears in the interface
|
||||
|
||||
Even if some related strings are already translated (like "Bookings" and "Insights"), new strings must be explicitly added to the translation system.
|
||||
|
||||
## When creating a pull request
|
||||
|
||||
### Title
|
||||
|
||||
- Use conventional commits: `feat:`, `fix:`, `refactor:`
|
||||
- Be specific: `fix: handle timezone edge case in booking creation`
|
||||
- Not generic: `fix: booking bug`
|
||||
|
||||
### Size Limits
|
||||
|
||||
- **Large PRs** (>500 lines or >10 files) are not recommended.
|
||||
- Guide the user how to split large PRs into smaller ones.
|
||||
|
||||
## When handling errors
|
||||
|
||||
### Descriptive Errors
|
||||
|
||||
```typescript
|
||||
// ✅ Good - Descriptive error with context
|
||||
throw new Error(`Unable to create booking: User ${userId} has no available time slots for ${date}`);
|
||||
|
||||
// ❌ Bad - Generic error
|
||||
throw new Error("Booking failed");
|
||||
```
|
||||
|
||||
### Error Types
|
||||
|
||||
```typescript
|
||||
// ✅ Good - Use proper error classes
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Invalid booking time slot",
|
||||
});
|
||||
```
|
||||
|
||||
## Basic Performance Guidelines
|
||||
|
||||
- Aim for O(n) or O(n log n) complexity, avoid O(n²)
|
||||
- Use database-level filtering instead of JavaScript filtering
|
||||
- Consider pagination for large datasets
|
||||
- Use database transactions for related operations
|
||||
|
||||
## When querying database
|
||||
|
||||
Prefer Select over Include:
|
||||
|
||||
```typescript
|
||||
// ✅ Good - Use select for performance and security
|
||||
const booking = await prisma.booking.findFirst({
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ❌ Bad - Include fetches all fields
|
||||
const booking = await prisma.booking.findFirst({
|
||||
include: {
|
||||
user: true, // This gets ALL user fields
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Avoid barrel imports
|
||||
|
||||
```typescript
|
||||
// ❌ Bad - Avoid importing from index.ts barrel files
|
||||
import { BookingService, UserService } from "./services";
|
||||
|
||||
// ✅ Good - Import directly from source files
|
||||
import { BookingService } from "./services/BookingService";
|
||||
import { UserService } from "./services/UserService";
|
||||
|
||||
|
||||
// ❌ Bad
|
||||
import { Button } from "@calcom/ui";
|
||||
|
||||
// ✅ Good - Import directly from source files
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
```
|
||||
|
||||
## File Naming Conventions
|
||||
|
||||
### Repository Files
|
||||
|
||||
- **Must** include `Repository` suffix, PascalCase matching class: `PrismaBookingRepository.ts`
|
||||
|
||||
### Service Files
|
||||
|
||||
- **Must** include `Service` suffix, PascalCase matching class, avoid generic names: `MembershipService.ts`
|
||||
|
||||
### General Files
|
||||
|
||||
- **Components**: PascalCase (e.g., `BookingForm.tsx`)
|
||||
- **Utilities**: kebab-case (e.g., `date-utils.ts`)
|
||||
- **Types**: PascalCase with `.types.ts` suffix (e.g., `Booking.types.ts`)
|
||||
- **Tests**: Same as source file + `.test.ts` or `.spec.ts`
|
||||
- **Avoid**: Dot-suffixes like `.service.ts`, `.repository.ts` (except for tests, types, specs)
|
||||
|
||||
## When using Day.js
|
||||
|
||||
```typescript
|
||||
// ⚠️ Slow in performance-critical code (loops)
|
||||
dates.map((date) => dayjs(date).add(1, "day").format());
|
||||
|
||||
// ✅ Better - Use .utc() for performance
|
||||
dates.map((date) => dayjs.utc(date).add(1, "day").format());
|
||||
|
||||
// ✅ Best - Use native Date when possible
|
||||
dates.map((date) => new Date(date.valueOf() + 24 * 60 * 60 * 1000));
|
||||
```
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"@calcom/atoms": minor
|
||||
---
|
||||
|
||||
feat: italian language support
|
||||
@@ -2,4 +2,22 @@
|
||||
/** @type {import("eslint").Linter.Config} */
|
||||
module.exports = {
|
||||
extends: ["./packages/config/eslint-preset.js"],
|
||||
plugins: ["import"],
|
||||
rules: {
|
||||
"import/no-cycle": ["warn", { maxDepth: Infinity }],
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ["packages/lib/**/*.{ts,tsx,js,jsx}", "packages/prisma/**/*.{ts,tsx,js,jsx}"],
|
||||
rules: {
|
||||
"no-restricted-imports": [
|
||||
"warn",
|
||||
{
|
||||
paths: ["@calcom/app-store"],
|
||||
patterns: ["@calcom/app-store/*"],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
/packages/lib/slots.ts @calcom/Foundation
|
||||
/packages/platform/atoms/**/*WebWrapper.tsx @calcom/Consumer
|
||||
/packages/platform/**/* @calcom/Platform @calcom/Foundation
|
||||
/packages/prisma/**/* @calcom/DBA
|
||||
/packages/prisma/**/* @calcom/Foundation
|
||||
/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts @calcom/Foundation
|
||||
/packages/trpc/server/routers/viewer/bookings/get.handler.ts @calcom/Foundation
|
||||
/packages/trpc/server/routers/viewer/slots/**/* @calcom/Foundation
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: Atoms E2E Tests
|
||||
name: E2E Atoms
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
@@ -19,7 +19,7 @@ env:
|
||||
jobs:
|
||||
e2e-atoms:
|
||||
timeout-minutes: 15
|
||||
name: Atoms E2E Tests
|
||||
name: E2E Atoms
|
||||
runs-on: buildjet-4vcpu-ubuntu-2204
|
||||
steps:
|
||||
- uses: docker/login-action@v3
|
||||
@@ -30,7 +30,7 @@ jobs:
|
||||
- uses: ./.github/actions/dangerous-git-checkout
|
||||
- uses: ./.github/actions/yarn-install
|
||||
- uses: ./.github/actions/yarn-playwright-install
|
||||
- name: Run Atoms E2E Tests
|
||||
- name: Run E2E Atoms Tests
|
||||
working-directory: packages/platform/examples/base
|
||||
run: yarn test:e2e
|
||||
- name: Upload Test Results
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# Cal.com Development Guide for AI Agents
|
||||
|
||||
**📖 Complete documentation is in the [.agents/](.agents/) directory.**
|
||||
|
||||
## Quick Reference
|
||||
|
||||
### Essential Commands
|
||||
|
||||
- `yarn dev` - Start development server
|
||||
- `yarn build` - Build all packages
|
||||
- `yarn lint:fix` - Lint and fix code
|
||||
- `yarn type-check` - TypeScript checking
|
||||
- `yarn test <filename> -- --integrationTestsOnly` - Run integration tests
|
||||
- `yarn e2e <filename> --grep "<testName>"` - Run specific E2E test
|
||||
|
||||
## 📚 Detailed Documentation
|
||||
|
||||
- **[.agents/README.md](.agents/README.md)** - Complete development guide
|
||||
- **[.agents/commands.md](.agents/commands.md)** - All build, test & dev commands
|
||||
- **[.agents/knowledge-base.md](.agents/knowledge-base.md)** - Knowledge base & best practices
|
||||
+2
-2
@@ -90,7 +90,7 @@ function getBaseProperties(field: InputBookingField): CustomField | SystemField
|
||||
}
|
||||
|
||||
if (fieldIsCustomSystemName(field)) {
|
||||
const systemName = { ...systemBeforeFieldName };
|
||||
const systemName = structuredClone(systemBeforeFieldName);
|
||||
if (systemName.variantsConfig?.variants?.fullName?.fields?.[0]) {
|
||||
systemName.variantsConfig.variants.fullName.fields[0].label = field.label;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ function getBaseProperties(field: InputBookingField): CustomField | SystemField
|
||||
}
|
||||
|
||||
if (fieldIsCustomSystemNameSplit(field)) {
|
||||
const systemNameSplit = { ...systemBeforeFieldNameSplit };
|
||||
const systemNameSplit = structuredClone(systemBeforeFieldNameSplit);
|
||||
|
||||
const firstNameField = systemNameSplit.variantsConfig?.variants?.firstAndLastName?.fields?.find(
|
||||
(field) => field.name === "firstName"
|
||||
|
||||
+1
-2
@@ -520,8 +520,7 @@ export const systemBeforeFieldName: NameSystemField = {
|
||||
name: "fullName",
|
||||
type: "text",
|
||||
required: true,
|
||||
label: "",
|
||||
placeholder: "",
|
||||
label: "your_name",
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
+2
-2
@@ -292,8 +292,8 @@ describe("transformBookingFieldsInternalToApi", () => {
|
||||
isDefault: true,
|
||||
required: true,
|
||||
disableOnPrefill: false,
|
||||
label: "",
|
||||
placeholder: "",
|
||||
label: "your_name",
|
||||
placeholder: undefined,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
+2
-4
@@ -725,8 +725,7 @@ describe("Organizations Event Types Endpoints", () => {
|
||||
isDefault: true,
|
||||
type: "name",
|
||||
slug: "name",
|
||||
label: "",
|
||||
placeholder: "",
|
||||
label: "your_name",
|
||||
required: true,
|
||||
disableOnPrefill: false,
|
||||
},
|
||||
@@ -823,9 +822,8 @@ describe("Organizations Event Types Endpoints", () => {
|
||||
isDefault: true,
|
||||
type: "name",
|
||||
slug: "name",
|
||||
label: "",
|
||||
placeholder: "",
|
||||
required: true,
|
||||
label: "your_name",
|
||||
disableOnPrefill: false,
|
||||
},
|
||||
{
|
||||
|
||||
+16
-12
@@ -181,14 +181,18 @@ const organizationAdminKeys = [
|
||||
"delegation_credential",
|
||||
];
|
||||
|
||||
export interface SettingsPermissions {
|
||||
canViewRoles?: boolean;
|
||||
}
|
||||
|
||||
const useTabs = ({
|
||||
isDelegationCredentialEnabled,
|
||||
isPbacEnabled,
|
||||
canViewRoles,
|
||||
permissions,
|
||||
}: {
|
||||
isDelegationCredentialEnabled: boolean;
|
||||
isPbacEnabled: boolean;
|
||||
canViewRoles?: boolean;
|
||||
permissions?: SettingsPermissions;
|
||||
}) => {
|
||||
const session = useSession();
|
||||
const { data: user } = trpc.viewer.me.get.useQuery({ includePasswordAdded: true });
|
||||
@@ -227,7 +231,7 @@ const useTabs = ({
|
||||
|
||||
// Add pbac menu item only if feature flag is enabled AND user has permission to view roles
|
||||
// This prevents showing the menu item when user has no organization permissions
|
||||
if (isPbacEnabled && canViewRoles) {
|
||||
if (isPbacEnabled && permissions?.canViewRoles) {
|
||||
newArray.push({
|
||||
name: "roles_and_permissions",
|
||||
href: "/settings/organizations/roles",
|
||||
@@ -294,7 +298,7 @@ interface SettingsSidebarContainerProps {
|
||||
navigationIsOpenedOnMobile?: boolean;
|
||||
bannersHeight?: number;
|
||||
teamFeatures?: Record<number, TeamFeatures>;
|
||||
canViewRoles?: boolean;
|
||||
permissions?: SettingsPermissions;
|
||||
}
|
||||
|
||||
const TeamRolesNavItem = ({
|
||||
@@ -487,7 +491,7 @@ const SettingsSidebarContainer = ({
|
||||
navigationIsOpenedOnMobile,
|
||||
bannersHeight,
|
||||
teamFeatures,
|
||||
canViewRoles,
|
||||
permissions,
|
||||
}: SettingsSidebarContainerProps) => {
|
||||
const searchParams = useCompatSearchParams();
|
||||
const orgBranding = useOrgBranding();
|
||||
@@ -517,7 +521,7 @@ const SettingsSidebarContainer = ({
|
||||
const tabsWithPermissions = useTabs({
|
||||
isDelegationCredentialEnabled,
|
||||
isPbacEnabled,
|
||||
canViewRoles,
|
||||
permissions,
|
||||
});
|
||||
|
||||
const { data: otherTeams } = trpc.viewer.organizations.listOtherTeams.useQuery(undefined, {
|
||||
@@ -792,13 +796,13 @@ export type SettingsLayoutProps = {
|
||||
children: React.ReactNode;
|
||||
containerClassName?: string;
|
||||
teamFeatures?: Record<number, TeamFeatures>;
|
||||
canViewRoles?: boolean;
|
||||
permissions?: SettingsPermissions;
|
||||
} & ComponentProps<typeof Shell>;
|
||||
|
||||
export default function SettingsLayoutAppDirClient({
|
||||
children,
|
||||
teamFeatures,
|
||||
canViewRoles,
|
||||
permissions,
|
||||
...rest
|
||||
}: SettingsLayoutProps) {
|
||||
const pathname = usePathname();
|
||||
@@ -833,7 +837,7 @@ export default function SettingsLayoutAppDirClient({
|
||||
sideContainerOpen={sideContainerOpen}
|
||||
setSideContainerOpen={setSideContainerOpen}
|
||||
teamFeatures={teamFeatures}
|
||||
canViewRoles={canViewRoles}
|
||||
permissions={permissions}
|
||||
/>
|
||||
}
|
||||
drawerState={state}
|
||||
@@ -856,7 +860,7 @@ type SidebarContainerElementProps = {
|
||||
bannersHeight?: number;
|
||||
setSideContainerOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
teamFeatures?: Record<number, TeamFeatures>;
|
||||
canViewRoles?: boolean;
|
||||
permissions?: SettingsPermissions;
|
||||
};
|
||||
|
||||
const SidebarContainerElement = ({
|
||||
@@ -864,7 +868,7 @@ const SidebarContainerElement = ({
|
||||
bannersHeight,
|
||||
setSideContainerOpen,
|
||||
teamFeatures,
|
||||
canViewRoles,
|
||||
permissions,
|
||||
}: SidebarContainerElementProps) => {
|
||||
const { t } = useLocale();
|
||||
return (
|
||||
@@ -881,7 +885,7 @@ const SidebarContainerElement = ({
|
||||
navigationIsOpenedOnMobile={sideContainerOpen}
|
||||
bannersHeight={bannersHeight}
|
||||
teamFeatures={teamFeatures}
|
||||
canViewRoles={canViewRoles}
|
||||
permissions={permissions}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -67,7 +67,11 @@ export default async function SettingsLayoutAppDir(props: SettingsLayoutProps) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<SettingsLayoutAppDirClient {...props} teamFeatures={teamFeatures ?? {}} canViewRoles={canViewRoles} />
|
||||
<SettingsLayoutAppDirClient
|
||||
{...props}
|
||||
teamFeatures={teamFeatures ?? {}}
|
||||
permissions={{ canViewRoles }}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { SkeletonLoader } from "@calcom/atoms/connect/conferencing-apps/ConferencingAppsViewWebWrapper";
|
||||
|
||||
export default function Loading() {
|
||||
return <SkeletonLoader />;
|
||||
}
|
||||
+21
-1
@@ -1,6 +1,9 @@
|
||||
import { createRouterCaller } from "app/_trpc/context";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
|
||||
import { ConferencingAppsViewWebWrapper } from "@calcom/atoms/connect/conferencing-apps/ConferencingAppsViewWebWrapper";
|
||||
import { appsRouter } from "@calcom/trpc/server/routers/viewer/apps/_router";
|
||||
import { eventTypesRouter } from "@calcom/trpc/server/routers/viewer/eventTypes/_router";
|
||||
|
||||
export const generateMetadata = async () =>
|
||||
await _generateMetadata(
|
||||
@@ -12,7 +15,24 @@ export const generateMetadata = async () =>
|
||||
);
|
||||
|
||||
const Page = async () => {
|
||||
return <ConferencingAppsViewWebWrapper />;
|
||||
const [appsCaller, eventTypesCaller] = await Promise.all([
|
||||
createRouterCaller(appsRouter),
|
||||
createRouterCaller(eventTypesRouter),
|
||||
]);
|
||||
|
||||
const [integrations, defaultConferencingApp, eventTypesQueryData] = await Promise.all([
|
||||
appsCaller.integrations({ variant: "conferencing", onlyInstalled: true }),
|
||||
appsCaller.getUsersDefaultConferencingApp(),
|
||||
eventTypesCaller.bulkEventFetch(),
|
||||
]);
|
||||
|
||||
return (
|
||||
<ConferencingAppsViewWebWrapper
|
||||
integrations={integrations}
|
||||
defaultConferencingApp={defaultConferencingApp}
|
||||
eventTypes={eventTypesQueryData?.eventTypes ?? []}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page;
|
||||
|
||||
+66
-50
@@ -3,7 +3,11 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import type { Resource } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { PERMISSION_REGISTRY, CrudAction } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import {
|
||||
Scope,
|
||||
CrudAction,
|
||||
getPermissionsForScope,
|
||||
} from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import classNames from "@calcom/ui/classNames";
|
||||
import { Checkbox, Label } from "@calcom/ui/components/form";
|
||||
@@ -17,6 +21,7 @@ interface AdvancedPermissionGroupProps {
|
||||
selectedPermissions: string[];
|
||||
onChange: (permissions: string[]) => void;
|
||||
disabled?: boolean;
|
||||
scope?: Scope;
|
||||
}
|
||||
|
||||
const INTERNAL_DATAACCESS_KEY = "_resource";
|
||||
@@ -26,21 +31,31 @@ export function AdvancedPermissionGroup({
|
||||
selectedPermissions,
|
||||
onChange,
|
||||
disabled,
|
||||
scope = Scope.Organization,
|
||||
}: AdvancedPermissionGroupProps) {
|
||||
const { t } = useLocale();
|
||||
const { toggleSinglePermission, toggleResourcePermissionLevel } = usePermissions();
|
||||
const resourceConfig = PERMISSION_REGISTRY[resource];
|
||||
const { toggleSinglePermission, toggleResourcePermissionLevel } = usePermissions(scope);
|
||||
const scopedRegistry = getPermissionsForScope(scope);
|
||||
const resourceConfig = scopedRegistry[resource];
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
|
||||
const isAllResources = resource === "*";
|
||||
|
||||
// Early return if resource is not in the scoped registry (and not the special "*" resource)
|
||||
if (!isAllResources && !resourceConfig) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const allResourcesSelected = selectedPermissions.includes("*.*");
|
||||
|
||||
// Get all possible permissions for this resource
|
||||
const allPermissions = isAllResources
|
||||
? ["*.*"]
|
||||
: Object.entries(resourceConfig)
|
||||
: resourceConfig
|
||||
? Object.entries(resourceConfig)
|
||||
.filter(([action]) => action !== INTERNAL_DATAACCESS_KEY)
|
||||
.map(([action]) => `${resource}.${action}`);
|
||||
.map(([action]) => `${resource}.${action}`)
|
||||
: [];
|
||||
|
||||
// Check if all permissions for this resource are selected
|
||||
const isAllSelected = isAllResources
|
||||
@@ -99,7 +114,7 @@ export function AdvancedPermissionGroup({
|
||||
<span
|
||||
className="text-default cursor-pointer text-sm font-medium leading-none"
|
||||
onClick={() => setIsExpanded(!isExpanded)}>
|
||||
{t(resourceConfig._resource?.i18nKey || "")}
|
||||
{t(resourceConfig?._resource?.i18nKey || "")}
|
||||
</span>
|
||||
<span
|
||||
className="text-muted cursor-pointer text-sm font-medium leading-none"
|
||||
@@ -113,56 +128,57 @@ export function AdvancedPermissionGroup({
|
||||
className="bg-default border-muted m-1 flex flex-col gap-2.5 rounded-xl border p-3"
|
||||
onClick={(e) => e.stopPropagation()} // Stop clicks in the permission list from affecting parent
|
||||
>
|
||||
{Object.entries(resourceConfig).map(([action, actionConfig]) => {
|
||||
const permission = `${resource}.${action}`;
|
||||
{resourceConfig &&
|
||||
Object.entries(resourceConfig).map(([action, actionConfig]) => {
|
||||
const permission = `${resource}.${action}`;
|
||||
|
||||
if (action === INTERNAL_DATAACCESS_KEY) {
|
||||
return null;
|
||||
}
|
||||
if (action === INTERNAL_DATAACCESS_KEY) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const isChecked = selectedPermissions.includes(permission);
|
||||
const isReadPermission = action === CrudAction.Read;
|
||||
const isAutoEnabled = isReadAutoEnabled(action);
|
||||
const isChecked = selectedPermissions.includes(permission);
|
||||
const isReadPermission = action === CrudAction.Read;
|
||||
const isAutoEnabled = isReadAutoEnabled(action);
|
||||
|
||||
return (
|
||||
<div key={action} className="flex items-center">
|
||||
<Checkbox
|
||||
id={permission}
|
||||
checked={isChecked}
|
||||
className="mr-2"
|
||||
onCheckedChange={(checked) => {
|
||||
if (!disabled) {
|
||||
onChange(toggleSinglePermission(permission, !!checked, selectedPermissions));
|
||||
}
|
||||
}}
|
||||
onClick={(e) => e.stopPropagation()} // Stop checkbox clicks from affecting parent
|
||||
disabled={disabled}
|
||||
/>
|
||||
<div
|
||||
className="flex items-center gap-2"
|
||||
onClick={(e) => e.stopPropagation()} // Stop label clicks from affecting parent
|
||||
>
|
||||
<Label htmlFor={permission} className="mb-0">
|
||||
<span className={classNames(isAutoEnabled && "text-muted-foreground")}>
|
||||
{t(actionConfig?.i18nKey || "")}
|
||||
return (
|
||||
<div key={action} className="flex items-center">
|
||||
<Checkbox
|
||||
id={permission}
|
||||
checked={isChecked}
|
||||
className="mr-2"
|
||||
onCheckedChange={(checked) => {
|
||||
if (!disabled) {
|
||||
onChange(toggleSinglePermission(permission, !!checked, selectedPermissions));
|
||||
}
|
||||
}}
|
||||
onClick={(e) => e.stopPropagation()} // Stop checkbox clicks from affecting parent
|
||||
disabled={disabled}
|
||||
/>
|
||||
<div
|
||||
className="flex items-center gap-2"
|
||||
onClick={(e) => e.stopPropagation()} // Stop label clicks from affecting parent
|
||||
>
|
||||
<Label htmlFor={permission} className="mb-0">
|
||||
<span className={classNames(isAutoEnabled && "text-muted-foreground")}>
|
||||
{t(actionConfig?.i18nKey || "")}
|
||||
</span>
|
||||
</Label>
|
||||
<span className="text-sm text-gray-500">
|
||||
{t(
|
||||
actionConfig && "descriptionI18nKey" in actionConfig
|
||||
? actionConfig.descriptionI18nKey
|
||||
: ""
|
||||
)}
|
||||
</span>
|
||||
</Label>
|
||||
<span className="text-sm text-gray-500">
|
||||
{t(
|
||||
actionConfig && "descriptionI18nKey" in actionConfig
|
||||
? actionConfig.descriptionI18nKey
|
||||
: ""
|
||||
{isAutoEnabled && (
|
||||
<Tooltip content={t("read_permission_auto_enabled_tooltip")}>
|
||||
<Icon name="info" className="text-muted-foreground h-3 w-3" />
|
||||
</Tooltip>
|
||||
)}
|
||||
</span>
|
||||
{isAutoEnabled && (
|
||||
<Tooltip content={t("read_permission_auto_enabled_tooltip")}>
|
||||
<Icon name="info" className="text-muted-foreground h-3 w-3" />
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}{" "}
|
||||
);
|
||||
})}{" "}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
+2
-4
@@ -145,10 +145,6 @@ export function RoleSheet({ role, open, onOpenChange, teamId, scope = Scope.Orga
|
||||
});
|
||||
|
||||
const onSubmit = (values: FormValues) => {
|
||||
// Store the color in localStorage
|
||||
const roleKey = isEditing && role ? role.id : `new_role_${values.name}`;
|
||||
localStorage.setItem(`role_color_${roleKey}`, values.color);
|
||||
|
||||
if (isEditing && role) {
|
||||
updateMutation.mutate({
|
||||
teamId,
|
||||
@@ -224,6 +220,7 @@ export function RoleSheet({ role, open, onOpenChange, teamId, scope = Scope.Orga
|
||||
selectedPermissions={permissions}
|
||||
onChange={(newPermissions) => form.setValue("permissions", newPermissions)}
|
||||
disabled={isSystemRole}
|
||||
scope={scope}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -247,6 +244,7 @@ export function RoleSheet({ role, open, onOpenChange, teamId, scope = Scope.Orga
|
||||
permissions={permissions}
|
||||
onChange={(newPermissions) => form.setValue("permissions", newPermissions)}
|
||||
disabled={isSystemRole}
|
||||
scope={scope}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
+4
-2
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import type { Resource } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import type { Resource, Scope } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { PERMISSION_REGISTRY } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { ToggleGroup } from "@calcom/ui/components/form";
|
||||
@@ -13,6 +13,7 @@ interface SimplePermissionItemProps {
|
||||
permissions: string[];
|
||||
onChange: (permissions: string[]) => void;
|
||||
disabled?: boolean;
|
||||
scope?: Scope;
|
||||
}
|
||||
|
||||
export function SimplePermissionItem({
|
||||
@@ -20,9 +21,10 @@ export function SimplePermissionItem({
|
||||
permissions,
|
||||
onChange,
|
||||
disabled,
|
||||
scope,
|
||||
}: SimplePermissionItemProps) {
|
||||
const { t } = useLocale();
|
||||
const { getResourcePermissionLevel, toggleResourcePermissionLevel } = usePermissions();
|
||||
const { getResourcePermissionLevel, toggleResourcePermissionLevel } = usePermissions(scope);
|
||||
|
||||
const isAllResources = resource === "*";
|
||||
const options = isAllResources
|
||||
|
||||
+12
-6
@@ -1,5 +1,8 @@
|
||||
import { CrudAction } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { PERMISSION_REGISTRY } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { CrudAction, Scope } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import {
|
||||
PERMISSION_REGISTRY,
|
||||
getPermissionsForScope,
|
||||
} from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import {
|
||||
getTransitiveDependencies,
|
||||
getTransitiveDependents,
|
||||
@@ -18,10 +21,11 @@ interface UsePermissionsReturn {
|
||||
toggleSinglePermission: (permission: string, enabled: boolean, currentPermissions: string[]) => string[];
|
||||
}
|
||||
|
||||
export function usePermissions(): UsePermissionsReturn {
|
||||
export function usePermissions(scope: Scope = Scope.Organization): UsePermissionsReturn {
|
||||
const getAllPossiblePermissions = () => {
|
||||
const permissions: string[] = [];
|
||||
Object.entries(PERMISSION_REGISTRY).forEach(([resource, config]) => {
|
||||
const scopedRegistry = getPermissionsForScope(scope);
|
||||
Object.entries(scopedRegistry).forEach(([resource, config]) => {
|
||||
if (resource !== "*") {
|
||||
Object.keys(config)
|
||||
.filter((action) => !action.startsWith("_"))
|
||||
@@ -34,7 +38,8 @@ export function usePermissions(): UsePermissionsReturn {
|
||||
};
|
||||
|
||||
const hasAllPermissions = (permissions: string[]) => {
|
||||
return Object.entries(PERMISSION_REGISTRY).every(([resource, config]) => {
|
||||
const scopedRegistry = getPermissionsForScope(scope);
|
||||
return Object.entries(scopedRegistry).every(([resource, config]) => {
|
||||
if (resource === "*") return true;
|
||||
return Object.keys(config)
|
||||
.filter((action) => !action.startsWith("_"))
|
||||
@@ -85,7 +90,8 @@ export function usePermissions(): UsePermissionsReturn {
|
||||
} else {
|
||||
// Filter out current resource permissions
|
||||
newPermissions = newPermissions.filter((p) => !p.startsWith(`${resource}.`));
|
||||
const resourceConfig = PERMISSION_REGISTRY[resource as keyof typeof PERMISSION_REGISTRY];
|
||||
const scopedRegistry = getPermissionsForScope(scope);
|
||||
const resourceConfig = scopedRegistry[resource as keyof typeof scopedRegistry];
|
||||
|
||||
if (!resourceConfig) return currentPermissions;
|
||||
|
||||
|
||||
+69
-2
@@ -1,13 +1,21 @@
|
||||
import { createRouterCaller } from "app/_trpc/context";
|
||||
import { _generateMetadata, getTranslate } from "app/_utils";
|
||||
import { unstable_cache } from "next/cache";
|
||||
import { headers, cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { Resource, CustomAction } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { getSpecificPermissions } from "@calcom/features/pbac/lib/resource-permissions";
|
||||
import { RoleManagementFactory } from "@calcom/features/pbac/services/role-management.factory";
|
||||
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
|
||||
import { PrismaAttributeRepository } from "@calcom/lib/server/repository/PrismaAttributeRepository";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { viewerTeamsRouter } from "@calcom/trpc/server/routers/viewer/teams/_router";
|
||||
|
||||
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
|
||||
import { TeamMembersView } from "~/teams/team-members-view";
|
||||
|
||||
export const generateMetadata = async ({ params }: { params: Promise<{ id: string }> }) =>
|
||||
@@ -54,6 +62,12 @@ const Page = async ({ params }: { params: Promise<{ id: string }> }) => {
|
||||
const { id } = await params;
|
||||
const teamId = parseInt(id);
|
||||
|
||||
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
|
||||
|
||||
if (!session?.user.id) {
|
||||
return redirect("/auth/login");
|
||||
}
|
||||
|
||||
const teamCaller = await createRouterCaller(viewerTeamsRouter);
|
||||
const team = await teamCaller.get({ teamId });
|
||||
|
||||
@@ -70,6 +84,54 @@ const Page = async ({ params }: { params: Promise<{ id: string }> }) => {
|
||||
getCachedTeamAttributes(organizationId),
|
||||
]);
|
||||
|
||||
const fallbackRolesCanListMembers: MembershipRole[] = [MembershipRole.ADMIN, MembershipRole.OWNER];
|
||||
|
||||
// If the team is not private we allow members to list other members
|
||||
if (!team.isPrivate) {
|
||||
fallbackRolesCanListMembers.push(MembershipRole.MEMBER);
|
||||
}
|
||||
|
||||
// Get specific PBAC permissions for team member actions
|
||||
const permissions = await getSpecificPermissions({
|
||||
userId: session.user.id,
|
||||
teamId: teamId,
|
||||
resource: Resource.Team,
|
||||
userRole: team.membership.role,
|
||||
actions: [
|
||||
CustomAction.Invite,
|
||||
CustomAction.ChangeMemberRole,
|
||||
CustomAction.Remove,
|
||||
CustomAction.ListMembers,
|
||||
CustomAction.Impersonate,
|
||||
],
|
||||
fallbackRoles: {
|
||||
[CustomAction.Invite]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
[CustomAction.ChangeMemberRole]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
[CustomAction.Remove]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
[CustomAction.ListMembers]: {
|
||||
roles: fallbackRolesCanListMembers,
|
||||
},
|
||||
[CustomAction.Impersonate]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Map specific permissions to member actions
|
||||
const memberPermissions = {
|
||||
canListMembers: permissions[CustomAction.ListMembers],
|
||||
canInvite: permissions[CustomAction.Invite],
|
||||
canChangeMemberRole: permissions[CustomAction.ChangeMemberRole],
|
||||
canRemove: permissions[CustomAction.Remove],
|
||||
canImpersonate: permissions[CustomAction.Impersonate],
|
||||
};
|
||||
|
||||
const facetedTeamValues = {
|
||||
roles,
|
||||
teams: [team],
|
||||
@@ -84,7 +146,12 @@ const Page = async ({ params }: { params: Promise<{ id: string }> }) => {
|
||||
|
||||
return (
|
||||
<SettingsHeader title={t("team_members")} description={t("members_team_description")}>
|
||||
<TeamMembersView team={team} facetedTeamValues={facetedTeamValues} attributes={attributes} />
|
||||
<TeamMembersView
|
||||
team={team}
|
||||
facetedTeamValues={facetedTeamValues}
|
||||
attributes={attributes}
|
||||
permissions={memberPermissions}
|
||||
/>
|
||||
</SettingsHeader>
|
||||
);
|
||||
};
|
||||
|
||||
+69
-2
@@ -1,12 +1,20 @@
|
||||
import { createRouterCaller } from "app/_trpc/context";
|
||||
import { _generateMetadata } from "app/_utils";
|
||||
import { unstable_cache } from "next/cache";
|
||||
import { headers, cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { Resource, CustomAction } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { getSpecificPermissions } from "@calcom/features/pbac/lib/resource-permissions";
|
||||
import { RoleManagementFactory } from "@calcom/features/pbac/services/role-management.factory";
|
||||
import { PrismaAttributeRepository } from "@calcom/lib/server/repository/PrismaAttributeRepository";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { viewerOrganizationsRouter } from "@calcom/trpc/server/routers/viewer/organizations/_router";
|
||||
|
||||
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
|
||||
import { MembersView } from "~/members/members-view";
|
||||
|
||||
export const generateMetadata = async () =>
|
||||
@@ -38,10 +46,63 @@ const getCachedRoles = unstable_cache(
|
||||
);
|
||||
|
||||
const Page = async () => {
|
||||
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
|
||||
|
||||
if (!session?.user.id || !session?.user.profile?.organizationId || !session?.user.org) {
|
||||
return redirect("/settings/profile");
|
||||
}
|
||||
|
||||
const orgCaller = await createRouterCaller(viewerOrganizationsRouter);
|
||||
const [org, teams] = await Promise.all([orgCaller.listCurrent(), orgCaller.getTeams()]);
|
||||
const [attributes, roles] = await Promise.all([getCachedAttributes(org.id), getCachedRoles(org.id)]);
|
||||
|
||||
const fallbackRolesThatCanSeeMembers: MembershipRole[] = [MembershipRole.ADMIN, MembershipRole.OWNER];
|
||||
|
||||
if (!org?.isPrivate) {
|
||||
fallbackRolesThatCanSeeMembers.push(MembershipRole.MEMBER);
|
||||
}
|
||||
|
||||
// Get specific PBAC permissions for organization member actions
|
||||
const permissions = await getSpecificPermissions({
|
||||
userId: session.user.id,
|
||||
teamId: session.user.profile.organizationId,
|
||||
resource: Resource.Organization,
|
||||
userRole: session.user.org.role,
|
||||
actions: [
|
||||
CustomAction.ListMembers,
|
||||
CustomAction.Invite,
|
||||
CustomAction.ChangeMemberRole,
|
||||
CustomAction.Remove,
|
||||
CustomAction.Impersonate,
|
||||
],
|
||||
fallbackRoles: {
|
||||
[CustomAction.ListMembers]: {
|
||||
roles: fallbackRolesThatCanSeeMembers,
|
||||
},
|
||||
[CustomAction.Invite]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
[CustomAction.ChangeMemberRole]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
[CustomAction.Remove]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
[CustomAction.Impersonate]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Map specific permissions to member actions
|
||||
const memberPermissions = {
|
||||
canListMembers: permissions[CustomAction.ListMembers],
|
||||
canInvite: permissions[CustomAction.Invite],
|
||||
canChangeMemberRole: permissions[CustomAction.ChangeMemberRole],
|
||||
canRemove: permissions[CustomAction.Remove],
|
||||
canImpersonate: permissions[CustomAction.Impersonate],
|
||||
};
|
||||
|
||||
const facetedTeamValues = {
|
||||
roles,
|
||||
teams,
|
||||
@@ -55,7 +116,13 @@ const Page = async () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<MembersView org={org} teams={teams} facetedTeamValues={facetedTeamValues} attributes={attributes} />
|
||||
<MembersView
|
||||
org={org}
|
||||
teams={teams}
|
||||
facetedTeamValues={facetedTeamValues}
|
||||
attributes={attributes}
|
||||
permissions={memberPermissions}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useRouter } from "next/navigation";
|
||||
import type { IframeHTMLAttributes } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
import { isRedirectApp } from "@calcom/app-store/_utils/redirectApps";
|
||||
import useAddAppMutation from "@calcom/app-store/_utils/useAddAppMutation";
|
||||
import { AppDependencyComponent, InstallAppButton } from "@calcom/app-store/components";
|
||||
import { doesAppSupportTeamInstall, isConferencing } from "@calcom/app-store/utils";
|
||||
@@ -112,6 +113,11 @@ export const AppPage = ({
|
||||
});
|
||||
|
||||
const handleAppInstall = () => {
|
||||
if (isRedirectApp(slug)) {
|
||||
setIsLoading(true);
|
||||
mutation.mutate({ type, variant, slug });
|
||||
return;
|
||||
}
|
||||
setIsLoading(true);
|
||||
if (isConferencing(categories) && !concurrentMeetings) {
|
||||
mutation.mutate({
|
||||
@@ -185,6 +191,19 @@ export const AppPage = ({
|
||||
}, []);
|
||||
|
||||
const installOrDisconnectAppButton = () => {
|
||||
if (isRedirectApp(slug)) {
|
||||
return (
|
||||
<Button
|
||||
onClick={() => handleAppInstall()}
|
||||
className="mt-2"
|
||||
StartIcon="external-link"
|
||||
loading={isLoading}
|
||||
disabled={isLoading}>
|
||||
{t("visit")}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
if (appDbQuery.isPending) {
|
||||
return <SkeletonButton className="h-10 w-24" />;
|
||||
}
|
||||
|
||||
@@ -4,17 +4,22 @@ import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
|
||||
import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired";
|
||||
import { UserListTable } from "@calcom/features/users/components/UserTable/UserListTable";
|
||||
import type { UserListTableProps } from "@calcom/features/users/components/UserTable/UserListTable";
|
||||
import type { MemberPermissions } from "@calcom/features/users/components/UserTable/types";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
export const MembersView = (props: UserListTableProps) => {
|
||||
export const MembersView = (props: UserListTableProps & { permissions?: MemberPermissions }) => {
|
||||
const { t } = useLocale();
|
||||
const { permissions, ...tableProps } = props;
|
||||
|
||||
// Use PBAC permissions if available, otherwise fall back to role-based check
|
||||
const isOrgAdminOrOwner = props.org && checkAdminOrOwner(props.org.user.role);
|
||||
const canLoggedInUserSeeMembers =
|
||||
(props.org?.isPrivate && isOrgAdminOrOwner) || isOrgAdminOrOwner || !props.org?.isPrivate;
|
||||
permissions?.canListMembers ??
|
||||
((props.org?.isPrivate && isOrgAdminOrOwner) || isOrgAdminOrOwner || !props.org?.isPrivate);
|
||||
|
||||
return (
|
||||
<LicenseRequired>
|
||||
<div>{canLoggedInUserSeeMembers && <UserListTable {...props} />}</div>
|
||||
<div>{canLoggedInUserSeeMembers && <UserListTable {...tableProps} permissions={permissions} />}</div>
|
||||
{!canLoggedInUserSeeMembers && (
|
||||
<div className="border-subtle rounded-xl border p-6" data-testid="members-privacy-warning">
|
||||
<h2 className="text-default">{t("only_admin_can_see_members_of_org")}</h2>
|
||||
|
||||
@@ -83,6 +83,17 @@ const FEATURES = [
|
||||
},
|
||||
];
|
||||
|
||||
function truncateDomain(domain: string) {
|
||||
const maxLength = 25;
|
||||
const cleanDomain = domain.replace(URL_PROTOCOL_REGEX, "");
|
||||
|
||||
if (cleanDomain.length <= maxLength) {
|
||||
return cleanDomain;
|
||||
}
|
||||
|
||||
return `${cleanDomain.substring(0, maxLength - 3)}.../`;
|
||||
}
|
||||
|
||||
function UsernameField({
|
||||
username,
|
||||
setPremium,
|
||||
@@ -398,11 +409,15 @@ export default function Signup({
|
||||
setPremium={(value) => setPremiumUsername(value)}
|
||||
addOnLeading={
|
||||
orgSlug
|
||||
? `${getOrgFullOrigin(orgSlug, { protocol: true }).replace(
|
||||
URL_PROTOCOL_REGEX,
|
||||
""
|
||||
)}/`
|
||||
: `${process.env.NEXT_PUBLIC_WEBSITE_URL.replace(URL_PROTOCOL_REGEX, "")}/`
|
||||
? truncateDomain(
|
||||
`${getOrgFullOrigin(orgSlug, { protocol: true }).replace(
|
||||
URL_PROTOCOL_REGEX,
|
||||
""
|
||||
)}/`
|
||||
)
|
||||
: truncateDomain(
|
||||
`${process.env.NEXT_PUBLIC_WEBSITE_URL.replace(URL_PROTOCOL_REGEX, "")}/`
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
|
||||
import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired";
|
||||
import { MemberInvitationModalWithoutMembers } from "@calcom/features/ee/teams/components/MemberInvitationModal";
|
||||
import MemberList from "@calcom/features/ee/teams/components/MemberList";
|
||||
import type { MemberPermissions } from "@calcom/features/users/components/UserTable/types";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
|
||||
@@ -23,15 +24,17 @@ interface TeamMembersViewProps {
|
||||
}[];
|
||||
};
|
||||
attributes?: any[];
|
||||
permissions: MemberPermissions;
|
||||
}
|
||||
|
||||
export const TeamMembersView = ({ team, facetedTeamValues }: TeamMembersViewProps) => {
|
||||
export const TeamMembersView = ({ team, facetedTeamValues, permissions }: TeamMembersViewProps) => {
|
||||
const { t } = useLocale();
|
||||
const [showMemberInvitationModal, setShowMemberInvitationModal] = useState(false);
|
||||
const [showInviteLinkSettingsModal, setShowInviteLinkSettingsModal] = useState(false);
|
||||
|
||||
// Use PBAC permissions if available, otherwise fall back to role-based check
|
||||
const isTeamAdminOrOwner = checkAdminOrOwner(team.membership.role);
|
||||
const canLoggedInUserSeeMembers = !team.isPrivate || isTeamAdminOrOwner;
|
||||
const canLoggedInUserSeeMembers = permissions?.canListMembers ?? (!team.isPrivate || isTeamAdminOrOwner);
|
||||
|
||||
return (
|
||||
<LicenseRequired>
|
||||
@@ -43,6 +46,7 @@ export const TeamMembersView = ({ team, facetedTeamValues }: TeamMembersViewProp
|
||||
isOrgAdminOrOwner={false}
|
||||
setShowMemberInvitationModal={setShowMemberInvitationModal}
|
||||
facetedTeamValues={facetedTeamValues}
|
||||
permissions={permissions}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -4,10 +4,10 @@ import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import handleNewBooking from "@calcom/features/bookings/lib/handleNewBooking";
|
||||
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import getIP from "@calcom/lib/getIP";
|
||||
import { piiHasher } from "@calcom/lib/server/PiiHasher";
|
||||
import { checkCfTurnstileToken } from "@calcom/lib/server/checkCfTurnstileToken";
|
||||
import { defaultResponder } from "@calcom/lib/server/defaultResponder";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { piiHasher } from "@calcom/lib/server/PiiHasher";
|
||||
|
||||
async function handler(req: NextApiRequest & { userId?: number }) {
|
||||
const userIp = getIP(req);
|
||||
@@ -37,7 +37,24 @@ async function handler(req: NextApiRequest & { userId?: number }) {
|
||||
hostname: req.headers.host || "",
|
||||
forcedSlug: req.headers["x-cal-force-slug"] as string | undefined,
|
||||
});
|
||||
// const booking = await createBookingThroughFactory();
|
||||
return booking;
|
||||
|
||||
// To be added in the follow-up PR
|
||||
// async function createBookingThroughFactory() {
|
||||
// console.log("Creating booking through factory");
|
||||
// const regularBookingService = getRegularBookingService();
|
||||
|
||||
// const booking = await regularBookingService.createBooking({
|
||||
// bookingData: req.body,
|
||||
// bookingMeta: {
|
||||
// userId: session?.user?.id || -1,
|
||||
// hostname: req.headers.host || "",
|
||||
// forcedSlug: req.headers["x-cal-force-slug"] as string | undefined,
|
||||
// },
|
||||
// });
|
||||
// return booking;
|
||||
// }
|
||||
}
|
||||
|
||||
export default defaultResponder(handler, "/api/book/event");
|
||||
|
||||
@@ -4,9 +4,9 @@ import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import handleInstantMeeting from "@calcom/features/instant-meeting/handleInstantMeeting";
|
||||
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import getIP from "@calcom/lib/getIP";
|
||||
import { piiHasher } from "@calcom/lib/server/PiiHasher";
|
||||
import { defaultResponder } from "@calcom/lib/server/defaultResponder";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
import { piiHasher } from "@calcom/lib/server/PiiHasher";
|
||||
|
||||
async function handler(req: NextApiRequest & { userId?: number }) {
|
||||
const userIp = getIP(req);
|
||||
|
||||
@@ -5,9 +5,9 @@ import { handleNewRecurringBooking } from "@calcom/features/bookings/lib/handleN
|
||||
import type { BookingResponse } from "@calcom/features/bookings/types";
|
||||
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import getIP from "@calcom/lib/getIP";
|
||||
import { piiHasher } from "@calcom/lib/server/PiiHasher";
|
||||
import { checkCfTurnstileToken } from "@calcom/lib/server/checkCfTurnstileToken";
|
||||
import { defaultResponder } from "@calcom/lib/server/defaultResponder";
|
||||
import { piiHasher } from "@calcom/lib/server/PiiHasher";
|
||||
|
||||
// @TODO: Didn't look at the contents of this function in order to not break old booking page.
|
||||
|
||||
|
||||
@@ -1004,8 +1004,13 @@ export async function apiLogin(
|
||||
*/
|
||||
await page.goto(navigateToUrl || "/settings/my-account/profile");
|
||||
|
||||
// Wait for the session to be fully established
|
||||
await page.waitForLoadState();
|
||||
// Wait for the session API call to complete to ensure session is fully established
|
||||
// Only wait if we're on a protected page that would trigger the session API call
|
||||
try {
|
||||
await page.waitForResponse("/api/auth/session", { timeout: 2000 });
|
||||
} catch (error) {
|
||||
// Session API call not made (likely on a public page), continue anyway
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -3403,6 +3403,7 @@
|
||||
"pbac_action_read_team_bookings": "View Team Bookings",
|
||||
"pbac_action_read_org_bookings": "View Organization Bookings",
|
||||
"pbac_action_read_recordings": "View Recordings",
|
||||
"pbac_action_impersonate": "Impersonate",
|
||||
"role_created_successfully": "Role created successfully",
|
||||
"role_updated_successfully": "Role updated successfully",
|
||||
"delete_role": "Delete role",
|
||||
@@ -3437,7 +3438,8 @@
|
||||
"pbac_desc_invite_team_members": "Invite team members",
|
||||
"pbac_desc_remove_team_members": "Remove team members",
|
||||
"pbac_desc_change_team_member_role": "Change role of team members",
|
||||
"pbac_desc_manage_teams": "All actions on teams",
|
||||
"pbac_desc_impersonate_team_members": "Impersonate team members",
|
||||
"pbac_desc_manage_teams": "All actions on teams across organization teams",
|
||||
"pbac_desc_create_organization": "Create organization",
|
||||
"pbac_desc_view_organization_details": "View organization details",
|
||||
"pbac_desc_list_organization_members": "List organization members",
|
||||
@@ -3445,6 +3447,7 @@
|
||||
"pbac_desc_remove_organization_members": "Remove organization members",
|
||||
"pbac_desc_manage_organization_billing": "Manage organization billing",
|
||||
"pbac_desc_change_organization_member_role": "Change role of organization members",
|
||||
"pbac_desc_impersonate_organization_members": "Impersonate organization members",
|
||||
"pbac_desc_edit_organization_settings": "Edit organization settings",
|
||||
"pbac_desc_manage_organizations": "All actions on organizations",
|
||||
"pbac_desc_view_bookings": "View bookings",
|
||||
@@ -3573,6 +3576,7 @@
|
||||
"webhook_metadata": "Metadata",
|
||||
"stats": "Stats",
|
||||
"booking_status": "Booking status",
|
||||
"visit": "Visit",
|
||||
"location_custom_label_input_label": "Custom label on booking page",
|
||||
"meeting_link": "Meeting link",
|
||||
"my_bookings": "My Bookings",
|
||||
|
||||
+1
-1
@@ -9,7 +9,6 @@
|
||||
"packages/embeds/*",
|
||||
"packages/features/*",
|
||||
"packages/app-store/*",
|
||||
"packages/app-store/ee/*",
|
||||
"packages/platform/*",
|
||||
"packages/platform/examples/base",
|
||||
"example-apps/*"
|
||||
@@ -96,6 +95,7 @@
|
||||
"c8": "^7.13.0",
|
||||
"checkly": "latest",
|
||||
"dotenv-checker": "^1.1.5",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"husky": "^8.0.0",
|
||||
"i18n-unused": "^0.13.0",
|
||||
"jest-diff": "^29.5.0",
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
export const REDIRECT_APPS = [
|
||||
"amie",
|
||||
"autocheckin",
|
||||
"bolna",
|
||||
"chatbase",
|
||||
"clic",
|
||||
"deel",
|
||||
"elevenlabs",
|
||||
"granola",
|
||||
"greetmate-ai",
|
||||
"lindy",
|
||||
"linear",
|
||||
"millis-ai",
|
||||
"monobot",
|
||||
"retell-ai",
|
||||
"synthflow",
|
||||
"telli",
|
||||
"vimcal",
|
||||
"wordpress",
|
||||
];
|
||||
|
||||
export const isRedirectApp = (slug: string): boolean => {
|
||||
return REDIRECT_APPS.includes(slug);
|
||||
};
|
||||
@@ -0,0 +1,451 @@
|
||||
// This script is used to delete recordings older than 6 months from Daily.co
|
||||
//
|
||||
// Commands to run:
|
||||
// 1. Fetch recordings older than 6 months and save to JSON:
|
||||
// ts-node packages/app-store/dailyvideo/lib/scripts/deleteRecordings.ts
|
||||
//
|
||||
// 2. Delete recordings from the JSON file (shows preview first, then prompts for confirmation):
|
||||
// ts-node packages/app-store/dailyvideo/lib/scripts/deleteRecordings.ts delete
|
||||
|
||||
interface Recording {
|
||||
id: string;
|
||||
room_name: string;
|
||||
mtgSessionId: string;
|
||||
status: string;
|
||||
start_ts: number;
|
||||
duration: number;
|
||||
max_participants?: number;
|
||||
share_token?: string;
|
||||
s3key?: string;
|
||||
isVttEnabled?: boolean;
|
||||
tracks?: unknown[];
|
||||
}
|
||||
|
||||
interface RecordingsResponse {
|
||||
data: Recording[];
|
||||
total_count: number;
|
||||
}
|
||||
|
||||
async function getAllRecordingsOlderThan6Months(): Promise<Recording[]> {
|
||||
const apiKey = process.env.DAILY_API_KEY;
|
||||
|
||||
if (!apiKey) {
|
||||
console.error("DAILY_API_KEY environment variable is required");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const baseUrl = "https://api.daily.co/v1/recordings";
|
||||
const allRecordings: Recording[] = [];
|
||||
const limit = 100;
|
||||
|
||||
// Calculate date 6 months ago
|
||||
const cutoffDate = new Date();
|
||||
cutoffDate.setUTCMonth(cutoffDate.getUTCMonth() - 6);
|
||||
cutoffDate.setUTCHours(0, 0, 0, 0);
|
||||
const cutoffTimestamp = Math.floor(cutoffDate.getTime() / 1000);
|
||||
|
||||
console.log(
|
||||
`Fetching all recordings older than 6 months (before ${
|
||||
cutoffDate.toISOString().split("T")[0]
|
||||
}, timestamp: ${cutoffTimestamp})...`
|
||||
);
|
||||
|
||||
let hasMoreRecordings = true;
|
||||
let requestCount = 0;
|
||||
const startTime = Date.now();
|
||||
let endingBefore = "OLDEST";
|
||||
|
||||
while (hasMoreRecordings) {
|
||||
requestCount++;
|
||||
const elapsedTime = Date.now() - startTime;
|
||||
const expectedMinTime = (requestCount - 1) * 50;
|
||||
|
||||
if (elapsedTime < expectedMinTime) {
|
||||
const delayTime = expectedMinTime - elapsedTime;
|
||||
console.log(`Rate limiting: waiting ${delayTime}ms before next request...`);
|
||||
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
||||
}
|
||||
|
||||
const url = new URL(baseUrl);
|
||||
url.searchParams.append("limit", limit.toString());
|
||||
|
||||
if (endingBefore) {
|
||||
url.searchParams.append("ending_before", endingBefore);
|
||||
}
|
||||
|
||||
let retries = 0;
|
||||
const maxRetries = 5;
|
||||
let response: Response | undefined;
|
||||
|
||||
while (retries <= maxRetries) {
|
||||
try {
|
||||
console.log("url", url.toString());
|
||||
response = await fetch(url.toString(), {
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (response.status === 404) {
|
||||
console.log("No recordings found or endpoint not available");
|
||||
return [];
|
||||
}
|
||||
|
||||
if (response.status === 429) {
|
||||
if (retries < maxRetries) {
|
||||
const backoffDelay = Math.pow(2, retries) * 1000;
|
||||
console.log(
|
||||
`Rate limit exceeded (429). Retrying in ${backoffDelay / 1000}s... (attempt ${retries + 1}/${
|
||||
maxRetries + 1
|
||||
})`
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, backoffDelay));
|
||||
retries++;
|
||||
continue;
|
||||
} else {
|
||||
throw new Error(`Rate limit exceeded after ${maxRetries + 1} attempts`);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
} catch (error) {
|
||||
if (retries < maxRetries && (error as Error).message.includes("fetch")) {
|
||||
const backoffDelay = Math.pow(2, retries) * 1000;
|
||||
console.log(
|
||||
`Network error. Retrying in ${backoffDelay / 1000}s... (attempt ${retries + 1}/${maxRetries + 1})`
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, backoffDelay));
|
||||
retries++;
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
if (!response?.ok) {
|
||||
throw new Error(`Failed to fetch recordings after ${maxRetries + 1} attempts`);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as RecordingsResponse;
|
||||
|
||||
if (!data.data || data.data.length === 0) {
|
||||
console.log("No more recordings available, ending pagination");
|
||||
hasMoreRecordings = false;
|
||||
break;
|
||||
}
|
||||
|
||||
const filteredRecordings = data.data.filter((recording) => {
|
||||
return recording.start_ts < cutoffTimestamp;
|
||||
});
|
||||
|
||||
allRecordings.push(...filteredRecordings);
|
||||
console.log(
|
||||
`Fetched ${data.data.length} recordings, ${filteredRecordings.length} older than 6 months (total: ${allRecordings.length})`
|
||||
);
|
||||
|
||||
endingBefore = data.data[0].id;
|
||||
console.log("endingBefore", endingBefore);
|
||||
console.log("first recording in batch", data.data[0]);
|
||||
console.log("last recording in batch", data.data[data.data.length - 1]);
|
||||
|
||||
if (data.data.length < limit) {
|
||||
console.log("Received fewer results than limit, reached end of data");
|
||||
hasMoreRecordings = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (filteredRecordings.length === 0 && data.data.every((r) => r.start_ts >= cutoffTimestamp)) {
|
||||
console.log("Reached recordings newer than 6 months, stopping");
|
||||
hasMoreRecordings = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return allRecordings;
|
||||
}
|
||||
|
||||
async function saveRecordingsToJson(recordings: Recording[]): Promise<void> {
|
||||
const fs = await import("fs/promises");
|
||||
const path = await import("path");
|
||||
|
||||
const simplifiedRecordings = recordings.map((recording) => ({
|
||||
id: recording.id,
|
||||
room_name: recording.room_name,
|
||||
start_ts: recording.start_ts,
|
||||
start_date: new Date(recording.start_ts * 1000).toISOString(),
|
||||
duration: recording.duration,
|
||||
status: recording.status,
|
||||
mtgSessionId: recording.mtgSessionId,
|
||||
max_participants: recording.max_participants,
|
||||
share_token: recording.share_token,
|
||||
s3key: recording.s3key,
|
||||
isVttEnabled: recording.isVttEnabled,
|
||||
}));
|
||||
|
||||
const outputPath = path.join(process.cwd(), "recordings_older_than_6_months.json");
|
||||
|
||||
try {
|
||||
await fs.writeFile(outputPath, JSON.stringify(simplifiedRecordings, null, 2), "utf-8");
|
||||
console.log(`\nRecordings saved to: ${outputPath}`);
|
||||
} catch (error) {
|
||||
console.error("Error saving recordings to JSON:", error);
|
||||
}
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
console.log("Fetching all recordings older than 6 months...");
|
||||
|
||||
const recordings = await getAllRecordingsOlderThan6Months();
|
||||
|
||||
const totalDurationSeconds = recordings.reduce(
|
||||
(total: number, recording: Recording) => total + recording.duration,
|
||||
0
|
||||
);
|
||||
|
||||
const totalHours = Math.floor(totalDurationSeconds / 3600);
|
||||
const remainingMinutes = Math.floor((totalDurationSeconds % 3600) / 60);
|
||||
const remainingSeconds = totalDurationSeconds % 60;
|
||||
|
||||
console.log(`\nFinal result: ${recordings.length} recordings found older than 6 months`);
|
||||
console.log(
|
||||
`Total duration: ${totalDurationSeconds} seconds (${totalHours}h ${remainingMinutes}m ${remainingSeconds}s)`
|
||||
);
|
||||
|
||||
await saveRecordingsToJson(recordings);
|
||||
|
||||
console.log("\nLast 10 recordings (oldest first):");
|
||||
|
||||
const lastTen = recordings.slice(-10);
|
||||
lastTen.forEach((recording: Recording, index: number) => {
|
||||
const startTime = new Date(recording.start_ts * 1000).toISOString();
|
||||
const durationMinutes = Math.floor(recording.duration / 60);
|
||||
const durationSeconds = recording.duration % 60;
|
||||
|
||||
console.log(
|
||||
`${index + 1}. ${recording.room_name} (${
|
||||
recording.id
|
||||
}) - Started: ${startTime} - Duration: ${durationMinutes}m ${durationSeconds}s - Status: ${
|
||||
recording.status
|
||||
}`
|
||||
);
|
||||
});
|
||||
|
||||
if (recordings.length > 10) {
|
||||
console.log(`\n... and ${recordings.length - 10} more recordings before these`);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteRecording(recordingId: string, apiKey: string): Promise<boolean> {
|
||||
const url = `https://api.daily.co/v1/recordings/${recordingId}`;
|
||||
const maxRetries = 5;
|
||||
let retries = 0;
|
||||
|
||||
while (retries <= maxRetries) {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const result = await response.json();
|
||||
return result.deleted === true;
|
||||
}
|
||||
|
||||
if (response.status === 404) {
|
||||
console.log(`Recording ${recordingId} not found (may have been already deleted)`);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (response.status === 429) {
|
||||
if (retries < maxRetries) {
|
||||
const backoffDelay = Math.pow(2, retries) * 1000;
|
||||
console.log(
|
||||
`Rate limit for ${recordingId}. Retrying in ${backoffDelay / 1000}s... (attempt ${retries + 1}/${
|
||||
maxRetries + 1
|
||||
})`
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, backoffDelay));
|
||||
retries++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
console.error(`Failed to delete recording ${recordingId}: HTTP ${response.status}`);
|
||||
return false;
|
||||
} catch (error) {
|
||||
const errorMessage = (error as Error).message;
|
||||
|
||||
if (
|
||||
retries < maxRetries &&
|
||||
(errorMessage.includes("fetch failed") || errorMessage.includes("TIMEOUT"))
|
||||
) {
|
||||
const backoffDelay = Math.pow(2, retries) * 1000;
|
||||
console.log(
|
||||
`Network error for ${recordingId}. Retrying in ${backoffDelay / 1000}s... (attempt ${retries + 1}/${
|
||||
maxRetries + 1
|
||||
})`
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, backoffDelay));
|
||||
retries++;
|
||||
continue;
|
||||
}
|
||||
|
||||
console.error(`Error deleting recording ${recordingId} after ${retries + 1} attempts:`, error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
console.error(`Failed to delete recording ${recordingId} after ${maxRetries + 1} attempts`);
|
||||
return false;
|
||||
}
|
||||
|
||||
async function deleteRecordingsFromJson(dryRun = false): Promise<void> {
|
||||
const apiKey = process.env.DAILY_API_KEY;
|
||||
|
||||
if (!apiKey) {
|
||||
console.error("DAILY_API_KEY environment variable is required");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const fs = await import("fs/promises");
|
||||
const path = await import("path");
|
||||
|
||||
const filePath = path.join(process.cwd(), "recordings_older_than_6_months.json");
|
||||
|
||||
try {
|
||||
const fileContent = await fs.readFile(filePath, "utf-8");
|
||||
const recordings = JSON.parse(fileContent) as Array<{
|
||||
id: string;
|
||||
room_name: string;
|
||||
start_date: string;
|
||||
duration: number;
|
||||
status: string;
|
||||
}>;
|
||||
|
||||
console.log(`\nFound ${recordings.length} recordings to delete`);
|
||||
|
||||
if (recordings.length === 0) {
|
||||
console.log("No recordings to delete");
|
||||
return;
|
||||
}
|
||||
|
||||
const totalDuration = recordings.reduce((sum, rec) => sum + rec.duration, 0);
|
||||
const totalHours = Math.floor(totalDuration / 3600);
|
||||
const totalMinutes = Math.floor((totalDuration % 3600) / 60);
|
||||
|
||||
console.log(`Total duration: ${totalHours}h ${totalMinutes}m`);
|
||||
console.log(`Date range: ${recordings[0].start_date} to ${recordings[recordings.length - 1].start_date}`);
|
||||
|
||||
if (dryRun) {
|
||||
console.log("\n🔸 DRY RUN MODE - No recordings will be deleted");
|
||||
console.log("First 5 recordings that would be deleted:");
|
||||
recordings.slice(0, 5).forEach((rec, idx) => {
|
||||
console.log(` ${idx + 1}. ${rec.id} - ${rec.room_name} (${rec.start_date})`);
|
||||
});
|
||||
if (recordings.length > 5) {
|
||||
console.log(` ... and ${recordings.length - 5} more`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
const startTime = Date.now();
|
||||
const batchSize = 10;
|
||||
|
||||
for (let i = 0; i < recordings.length; i += batchSize) {
|
||||
const batch = recordings.slice(i, Math.min(i + batchSize, recordings.length));
|
||||
const batchPromises = [];
|
||||
|
||||
for (const recording of batch) {
|
||||
const elapsedTime = Date.now() - startTime;
|
||||
const expectedMinTime = (successCount + failCount) * 50;
|
||||
|
||||
if (elapsedTime < expectedMinTime) {
|
||||
const delayTime = expectedMinTime - elapsedTime;
|
||||
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
||||
}
|
||||
|
||||
const deletePromise = deleteRecording(recording.id, apiKey).then((success) => {
|
||||
if (success) {
|
||||
successCount++;
|
||||
} else {
|
||||
failCount++;
|
||||
}
|
||||
|
||||
if ((successCount + failCount) % 10 === 0) {
|
||||
const progress = (((successCount + failCount) / recordings.length) * 100).toFixed(1);
|
||||
console.log(
|
||||
`Progress: ${progress}% (${successCount + failCount}/${recordings.length}), recording-id:${
|
||||
recording.id
|
||||
}`
|
||||
);
|
||||
}
|
||||
|
||||
return success;
|
||||
});
|
||||
|
||||
batchPromises.push(deletePromise);
|
||||
}
|
||||
|
||||
await Promise.all(batchPromises);
|
||||
}
|
||||
|
||||
console.log("\n✅ Deletion complete!");
|
||||
console.log(`Successfully deleted: ${successCount}`);
|
||||
console.log(`Failed to delete: ${failCount}`);
|
||||
console.log(`Total processed: ${successCount + failCount}`);
|
||||
|
||||
if (failCount > 0) {
|
||||
console.log("\n⚠️ Some recordings failed to delete. Check the logs above for details.");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error reading or processing recordings file:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function mainDelete(): Promise<void> {
|
||||
const readline = (await import("readline")).createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
|
||||
console.log("🗑️ Daily Video Recording Deletion Tool");
|
||||
console.log("=====================================");
|
||||
console.log("This tool will delete all recordings listed in recordings_older_than_6_months.json");
|
||||
console.log("\n⚠️ WARNING: This action cannot be undone!");
|
||||
console.log("Note: Recordings in custom S3 buckets will NOT be deleted from S3.\n");
|
||||
|
||||
await deleteRecordingsFromJson(true);
|
||||
|
||||
const question = (query: string): Promise<string> =>
|
||||
new Promise((resolve) => readline.question(query, resolve));
|
||||
|
||||
const answer = await question("\nDo you want to proceed with deletion? (yes/no): ");
|
||||
|
||||
if (answer.toLowerCase() === "yes") {
|
||||
console.log("\nStarting deletion process...\n");
|
||||
await deleteRecordingsFromJson(false);
|
||||
} else {
|
||||
console.log("\nDeletion cancelled.");
|
||||
}
|
||||
|
||||
readline.close();
|
||||
}
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
if (args[0] === "delete") {
|
||||
mainDelete();
|
||||
} else {
|
||||
main();
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { TeamRepository } from "@calcom/lib/server/repository/team";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
@@ -10,6 +11,21 @@ import { getStripeCustomerIdFromUserId } from "../lib/customer";
|
||||
import stripe from "../lib/server";
|
||||
import { getSubscriptionFromId } from "../lib/subscriptions";
|
||||
|
||||
const getBillingPortalUrl = async (customerId: string, return_url: string) => {
|
||||
const log = logger.getSubLogger({ prefix: ["getBillingPortalUrl"] });
|
||||
try {
|
||||
const portalSession = await stripe.billingPortal.sessions.create({
|
||||
customer: customerId,
|
||||
return_url,
|
||||
});
|
||||
|
||||
return portalSession.url;
|
||||
} catch (e) {
|
||||
log.error(`Failed to create billing portal session for ${customerId}: ${e}`);
|
||||
throw new Error("Failed to create billing portal session");
|
||||
}
|
||||
};
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method !== "POST" && req.method !== "GET")
|
||||
return res.status(405).json({ message: "Method not allowed" });
|
||||
@@ -18,9 +34,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
const userId = req.session.user.id;
|
||||
const teamId = req.query.teamId ? parseInt(req.query.teamId as string) : null;
|
||||
|
||||
let return_url = `${WEBAPP_URL}/settings/billing`;
|
||||
if (!teamId) {
|
||||
return res.status(400).json({ message: "Team ID is required" });
|
||||
const customerId = await getStripeCustomerIdFromUserId(userId);
|
||||
if (!customerId) return res.status(404).json({ message: "CustomerId not found" });
|
||||
|
||||
const billingPortalUrl = await getBillingPortalUrl(customerId, return_url);
|
||||
|
||||
return res.redirect(302, billingPortalUrl);
|
||||
}
|
||||
|
||||
const teamRepository = new TeamRepository(prisma);
|
||||
@@ -28,25 +49,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
teamId,
|
||||
userId,
|
||||
});
|
||||
let return_url = `${WEBAPP_URL}/settings/billing`;
|
||||
|
||||
if (!team) return res.status(404).json({ message: "Team not found" });
|
||||
|
||||
if (typeof req.query.returnTo === "string") {
|
||||
const safeRedirectUrl = getSafeRedirectUrl(req.query.returnTo);
|
||||
if (safeRedirectUrl) return_url = safeRedirectUrl;
|
||||
}
|
||||
|
||||
if (!team) {
|
||||
const customerId = await getStripeCustomerIdFromUserId(userId);
|
||||
if (!customerId) return res.status(404).json({ message: "CustomerId not found" });
|
||||
|
||||
const portalSession = await stripe.billingPortal.sessions.create({
|
||||
customer: customerId,
|
||||
return_url,
|
||||
});
|
||||
|
||||
return res.status(200).json({ url: portalSession.url });
|
||||
}
|
||||
|
||||
const teamMetadataParsed = teamMetadataSchema.safeParse(team.metadata);
|
||||
|
||||
if (!teamMetadataParsed.success) {
|
||||
@@ -71,10 +81,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
if (!customerId) return res.status(400).json({ message: "CustomerId not found in stripe" });
|
||||
|
||||
const stripeSession = await stripe.billingPortal.sessions.create({
|
||||
customer: customerId,
|
||||
return_url,
|
||||
});
|
||||
const billingPortalUrl = await getBillingPortalUrl(customerId, return_url);
|
||||
|
||||
res.redirect(302, stripeSession.url);
|
||||
res.redirect(302, billingPortalUrl);
|
||||
}
|
||||
|
||||
@@ -358,9 +358,14 @@ export class PaymentService implements IAbstractPaymentService {
|
||||
paymentData: Payment,
|
||||
eventTypeMetadata?: EventTypeMetadata
|
||||
): Promise<void> {
|
||||
const attendeesToEmail = event.attendeeSeatId
|
||||
? event.attendees.filter(attendee => attendee.bookingSeat?.referenceUid === event.attendeeSeatId)
|
||||
: event.attendees;
|
||||
|
||||
await sendAwaitingPaymentEmailAndSMS(
|
||||
{
|
||||
...event,
|
||||
attendees: attendeesToEmail,
|
||||
paymentInfo: {
|
||||
link: createPaymentLink({
|
||||
paymentUid: paymentData.uid,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { isRedirectApp } from "@calcom/app-store/_utils/redirectApps";
|
||||
import useAddAppMutation from "@calcom/app-store/_utils/useAddAppMutation";
|
||||
import { InstallAppButton } from "@calcom/app-store/components";
|
||||
import { doesAppSupportTeamInstall, isConferencing } from "@calcom/app-store/utils";
|
||||
@@ -56,6 +57,10 @@ export function AppCard({ app, credentials, searchText, userAdminTeams }: AppCar
|
||||
}, [app.name, searchText]);
|
||||
|
||||
const handleAppInstall = () => {
|
||||
if (isRedirectApp(app.slug)) {
|
||||
mutation.mutate({ type: app.type, variant: app.variant, slug: app.slug });
|
||||
return;
|
||||
}
|
||||
if (isConferencing(app.categories) && !app.concurrentMeetings) {
|
||||
mutation.mutate({
|
||||
type: app.type,
|
||||
@@ -148,7 +153,9 @@ export function AppCard({ app, credentials, searchText, userAdminTeams }: AppCar
|
||||
loading: mutation.isPending,
|
||||
};
|
||||
}
|
||||
return <InstallAppButtonChild paid={app.paid} {...props} />;
|
||||
return (
|
||||
<InstallAppButtonChild paid={app.paid} isRedirect={isRedirectApp(app.slug)} {...props} />
|
||||
);
|
||||
}}
|
||||
/>
|
||||
)
|
||||
@@ -170,7 +177,9 @@ export function AppCard({ app, credentials, searchText, userAdminTeams }: AppCar
|
||||
loading: mutation.isPending,
|
||||
};
|
||||
}
|
||||
return <InstallAppButtonChild paid={app.paid} {...props} />;
|
||||
return (
|
||||
<InstallAppButtonChild paid={app.paid} isRedirect={isRedirectApp(app.slug)} {...props} />
|
||||
);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
@@ -192,11 +201,25 @@ export function AppCard({ app, credentials, searchText, userAdminTeams }: AppCar
|
||||
|
||||
const InstallAppButtonChild = ({
|
||||
paid,
|
||||
isRedirect = false,
|
||||
...props
|
||||
}: {
|
||||
paid: App["paid"];
|
||||
isRedirect?: boolean;
|
||||
} & ButtonProps) => {
|
||||
const { t } = useLocale();
|
||||
if (isRedirect) {
|
||||
return (
|
||||
<Button
|
||||
color="secondary"
|
||||
className="[@media(max-width:260px)]:w-full [@media(max-width:260px)]:justify-center"
|
||||
StartIcon="external-link"
|
||||
{...props}
|
||||
size="base">
|
||||
{t("visit")}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
// Paid apps don't support team installs at the moment
|
||||
// Also, cal.ai(the only paid app at the moment) doesn't support team install either
|
||||
if (paid) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { createContainer } from "@evyweb/ioctopus";
|
||||
|
||||
import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
||||
|
||||
import type { InstantBookingCreateService } from "../modules/InstantBookingCreateServiceModule";
|
||||
import { instantBookingCreateServiceModule } from "../modules/InstantBookingCreateServiceModule";
|
||||
|
||||
const container = createContainer();
|
||||
container.load(DI_TOKENS.INSTANT_BOOKING_CREATE_SERVICE_MODULE, instantBookingCreateServiceModule);
|
||||
|
||||
export function getInstantBookingCreateService(): InstantBookingCreateService {
|
||||
return container.get<InstantBookingCreateService>(DI_TOKENS.INSTANT_BOOKING_CREATE_SERVICE);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { createContainer } from "@evyweb/ioctopus";
|
||||
|
||||
import { bookingRepositoryModule } from "@calcom/lib/di/modules/Booking";
|
||||
import { cacheModule } from "@calcom/lib/di/modules/Cache";
|
||||
import { checkBookingAndDurationLimitsModule } from "@calcom/lib/di/modules/CheckBookingAndDurationLimits";
|
||||
import { checkBookingLimitsModule } from "@calcom/lib/di/modules/CheckBookingLimits";
|
||||
import { featuresRepositoryModule } from "@calcom/lib/di/modules/Features";
|
||||
import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
||||
import { prismaModule } from "@calcom/prisma/prisma.module";
|
||||
|
||||
import type { RecurringBookingService } from "../modules/RecurringBookingServiceModule";
|
||||
import { recurringBookingServiceModule } from "../modules/RecurringBookingServiceModule";
|
||||
|
||||
const container = createContainer();
|
||||
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
||||
container.load(DI_TOKENS.BOOKING_REPOSITORY_MODULE, bookingRepositoryModule);
|
||||
container.load(DI_TOKENS.CACHE_SERVICE_MODULE, cacheModule);
|
||||
container.load(DI_TOKENS.CHECK_BOOKING_LIMITS_SERVICE_MODULE, checkBookingLimitsModule);
|
||||
container.load(DI_TOKENS.FEATURES_REPOSITORY_MODULE, featuresRepositoryModule);
|
||||
container.load(
|
||||
DI_TOKENS.CHECK_BOOKING_AND_DURATION_LIMITS_SERVICE_MODULE,
|
||||
checkBookingAndDurationLimitsModule
|
||||
);
|
||||
container.load(DI_TOKENS.RECURRING_BOOKING_SERVICE_MODULE, recurringBookingServiceModule);
|
||||
|
||||
export function getRecurringBookingService(): RecurringBookingService {
|
||||
return container.get<RecurringBookingService>(DI_TOKENS.RECURRING_BOOKING_SERVICE);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { createContainer } from "@evyweb/ioctopus";
|
||||
|
||||
import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
||||
|
||||
import type { RegularBookingService } from "../modules/RegularBookingServiceModule";
|
||||
import {
|
||||
regularBookingServiceModule,
|
||||
loadModuleDeps,
|
||||
moduleToken,
|
||||
} from "../modules/RegularBookingServiceModule";
|
||||
|
||||
const regularBookingServiceContainer = createContainer();
|
||||
|
||||
regularBookingServiceContainer.load(DI_TOKENS.REGULAR_BOOKING_SERVICE_MODULE, regularBookingServiceModule);
|
||||
|
||||
export function getRegularBookingService(): RegularBookingService {
|
||||
loadModuleDeps(regularBookingServiceContainer);
|
||||
|
||||
return regularBookingServiceContainer.get<RegularBookingService>(moduleToken);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { createModule } from "@evyweb/ioctopus";
|
||||
|
||||
import { InstantBookingCreateService } from "@calcom/features/instant-meeting/handleInstantMeeting";
|
||||
import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
||||
|
||||
export const instantBookingCreateServiceModule = createModule();
|
||||
|
||||
instantBookingCreateServiceModule
|
||||
.bind(DI_TOKENS.INSTANT_BOOKING_CREATE_SERVICE)
|
||||
.toClass(InstantBookingCreateService);
|
||||
export type { InstantBookingCreateService };
|
||||
@@ -0,0 +1,13 @@
|
||||
import { createModule } from "@evyweb/ioctopus";
|
||||
|
||||
import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
||||
|
||||
import { RecurringBookingService } from "../../handleNewRecurringBooking";
|
||||
|
||||
export const recurringBookingServiceModule = createModule();
|
||||
|
||||
recurringBookingServiceModule.bind(DI_TOKENS.RECURRING_BOOKING_SERVICE).toClass(RecurringBookingService, {
|
||||
regularBookingService: DI_TOKENS.REGULAR_BOOKING_SERVICE,
|
||||
});
|
||||
|
||||
export type { RecurringBookingService };
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { Container } from "@evyweb/ioctopus";
|
||||
import { createModule } from "@evyweb/ioctopus";
|
||||
|
||||
import { bookingRepositoryModule } from "@calcom/lib/di/modules/Booking";
|
||||
import { cacheModule } from "@calcom/lib/di/modules/Cache";
|
||||
import { checkBookingAndDurationLimitsModule } from "@calcom/lib/di/modules/CheckBookingAndDurationLimits";
|
||||
import { checkBookingLimitsModule } from "@calcom/lib/di/modules/CheckBookingLimits";
|
||||
import { featuresRepositoryModule } from "@calcom/lib/di/modules/Features";
|
||||
import { DI_TOKENS } from "@calcom/lib/di/tokens";
|
||||
import { prismaModule } from "@calcom/prisma/prisma.module";
|
||||
|
||||
import { RegularBookingService } from "../../handleNewBooking";
|
||||
|
||||
export const regularBookingServiceModule = createModule();
|
||||
const moduleToken = DI_TOKENS.REGULAR_BOOKING_SERVICE;
|
||||
regularBookingServiceModule.bind(moduleToken).toClass(RegularBookingService, {
|
||||
cacheService: DI_TOKENS.CACHE_SERVICE,
|
||||
checkBookingAndDurationLimitsService: DI_TOKENS.CHECK_BOOKING_AND_DURATION_LIMITS_SERVICE,
|
||||
prismaClient: DI_TOKENS.PRISMA_CLIENT,
|
||||
bookingRepository: DI_TOKENS.BOOKING_REPOSITORY,
|
||||
featuresRepository: DI_TOKENS.FEATURES_REPOSITORY,
|
||||
checkBookingLimitsService: DI_TOKENS.CHECK_BOOKING_LIMITS_SERVICE,
|
||||
});
|
||||
|
||||
// Load the dependencies defined for the module above
|
||||
function loadModuleDeps(container: Container) {
|
||||
container.load(DI_TOKENS.CACHE_SERVICE_MODULE, cacheModule);
|
||||
container.load(
|
||||
DI_TOKENS.CHECK_BOOKING_AND_DURATION_LIMITS_SERVICE_MODULE,
|
||||
checkBookingAndDurationLimitsModule
|
||||
);
|
||||
container.load(DI_TOKENS.PRISMA_MODULE, prismaModule);
|
||||
container.load(DI_TOKENS.BOOKING_REPOSITORY_MODULE, bookingRepositoryModule);
|
||||
container.load(DI_TOKENS.FEATURES_REPOSITORY_MODULE, featuresRepositoryModule);
|
||||
container.load(DI_TOKENS.CHECK_BOOKING_LIMITS_SERVICE_MODULE, checkBookingLimitsModule);
|
||||
}
|
||||
|
||||
export { loadModuleDeps, moduleToken };
|
||||
export type { RegularBookingService };
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Domain types for BookingCreateService
|
||||
* These types are framework-agnostic and contain only the data required for booking operations
|
||||
*/
|
||||
import type { z } from "zod";
|
||||
|
||||
import type getBookingDataSchema from "@calcom/features/bookings/lib/getBookingDataSchema";
|
||||
import type getBookingDataSchemaForApi from "@calcom/features/bookings/lib/getBookingDataSchemaForApi";
|
||||
import type { BookingCreateBody as BaseCreateBookingData } from "@calcom/prisma/zod/custom/booking";
|
||||
import type { extendedBookingCreateBody } from "@calcom/prisma/zod/custom/booking";
|
||||
|
||||
export type ExtendedBookingCreateData = z.input<typeof extendedBookingCreateBody>;
|
||||
export type BookingDataSchemaGetter = typeof getBookingDataSchema | typeof getBookingDataSchemaForApi;
|
||||
|
||||
export type CreateRegularBookingData = BaseCreateBookingData;
|
||||
|
||||
export type CreateInstantBookingData = BaseCreateBookingData;
|
||||
|
||||
export type CreateRecurringBookingData = (BaseCreateBookingData & {
|
||||
schedulingType?: SchedulingType;
|
||||
})[];
|
||||
|
||||
export type PlatformParams = {
|
||||
platformClientId?: string;
|
||||
platformCancelUrl?: string;
|
||||
platformBookingUrl?: string;
|
||||
platformRescheduleUrl?: string;
|
||||
platformBookingLocation?: string;
|
||||
areCalendarEventsEnabled?: boolean;
|
||||
};
|
||||
|
||||
export type CreateBookingMeta = {
|
||||
userId?: number;
|
||||
// These used to come from headers but now we're passing them as params
|
||||
hostname?: string;
|
||||
forcedSlug?: string;
|
||||
noEmail?: boolean;
|
||||
} & PlatformParams;
|
||||
|
||||
export type BookingHandlerInput = {
|
||||
bookingData: CreateRegularBookingData;
|
||||
} & CreateBookingMeta;
|
||||
|
||||
export type CreateInstantBookingResponse = {
|
||||
message: string;
|
||||
meetingTokenId: number;
|
||||
bookingId: number;
|
||||
bookingUid: string;
|
||||
expires: Date;
|
||||
userId: number | null;
|
||||
};
|
||||
@@ -25,14 +25,19 @@ import {
|
||||
} from "@calcom/emails";
|
||||
import getICalUID from "@calcom/emails/lib/getICalUID";
|
||||
import { CalendarEventBuilder } from "@calcom/features/CalendarEventBuilder";
|
||||
import type { BookingDataSchemaGetter } from "@calcom/features/bookings/lib/dto/types";
|
||||
import type { CreateRegularBookingData, CreateBookingMeta } from "@calcom/features/bookings/lib/dto/types";
|
||||
import type { CheckBookingAndDurationLimitsService } from "@calcom/features/bookings/lib/handleNewBooking/checkBookingAndDurationLimits";
|
||||
import { handleWebhookTrigger } from "@calcom/features/bookings/lib/handleWebhookTrigger";
|
||||
import { isEventTypeLoggingEnabled } from "@calcom/features/bookings/lib/isEventTypeLoggingEnabled";
|
||||
import type { CacheService } from "@calcom/features/calendar-cache/lib/getShouldServeCache";
|
||||
import AssignmentReasonRecorder from "@calcom/features/ee/round-robin/assignmentReason/AssignmentReasonRecorder";
|
||||
import {
|
||||
allowDisablingAttendeeConfirmationEmails,
|
||||
allowDisablingHostConfirmationEmails,
|
||||
} from "@calcom/features/ee/workflows/lib/allowDisablingStandardEmails";
|
||||
import { scheduleWorkflowReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
|
||||
import type { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
||||
import { getFullName } from "@calcom/features/form-builder/utils";
|
||||
import { UsersRepository } from "@calcom/features/users/users.repository";
|
||||
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
|
||||
@@ -64,6 +69,7 @@ import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
|
||||
import { getPaymentAppData } from "@calcom/lib/getPaymentAppData";
|
||||
import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
|
||||
import { HttpError } from "@calcom/lib/http-error";
|
||||
import type { CheckBookingLimitsService } from "@calcom/lib/intervalLimits/server/checkBookingLimits";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { handlePayment } from "@calcom/lib/payment/handlePayment";
|
||||
import { getPiiFreeCalendarEvent, getPiiFreeEventType } from "@calcom/lib/piiFreeData";
|
||||
@@ -73,6 +79,7 @@ import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||
import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
|
||||
import { HashedLinkService } from "@calcom/lib/server/service/hashedLinkService";
|
||||
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { AssignmentReasonEnum } from "@calcom/prisma/enums";
|
||||
import { BookingStatus, SchedulingType, WebhookTriggerEvents } from "@calcom/prisma/enums";
|
||||
@@ -121,6 +128,7 @@ import type { IEventTypePaymentCredentialType, Invitee, IsFixedAwareUser } from
|
||||
import { validateBookingTimeIsNotOutOfBounds } from "./handleNewBooking/validateBookingTimeIsNotOutOfBounds";
|
||||
import { validateEventLength } from "./handleNewBooking/validateEventLength";
|
||||
import handleSeats from "./handleSeats/handleSeats";
|
||||
import type { IBookingService } from "./interfaces/IBookingService";
|
||||
|
||||
const translator = short();
|
||||
const log = logger.getSubLogger({ prefix: ["[api] book:user"] });
|
||||
@@ -150,10 +158,6 @@ function getICalSequence(originalRescheduledBooking: BookingType | null) {
|
||||
return originalRescheduledBooking.iCalSequence + 1;
|
||||
}
|
||||
|
||||
type BookingDataSchemaGetter =
|
||||
| typeof getBookingDataSchema
|
||||
| typeof import("@calcom/features/bookings/lib/getBookingDataSchemaForApi").default;
|
||||
|
||||
type CreatedBooking = Booking & { appsStatus?: AppsStatus[]; paymentUid?: string; paymentId?: number };
|
||||
type ReturnTypeCreateBooking = Awaited<ReturnType<typeof createBooking>>;
|
||||
export const buildDryRunBooking = ({
|
||||
@@ -2455,3 +2459,38 @@ async function handler(
|
||||
}
|
||||
|
||||
export default handler;
|
||||
|
||||
export interface IBookingServiceDependencies {
|
||||
cacheService: CacheService;
|
||||
checkBookingAndDurationLimitsService: CheckBookingAndDurationLimitsService;
|
||||
prismaClient: PrismaClient;
|
||||
bookingRepository: BookingRepository;
|
||||
featuresRepository: FeaturesRepository;
|
||||
checkBookingLimitsService: CheckBookingLimitsService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes care of creating/rescheduling non-recurring, non-instant bookings. Such bookings could be TeamBooking, UserBooking, SeatedUserBooking, SeatedTeamBooking, etc.
|
||||
* We can't name it CoreBookingService because non-instant booking also creates a booking but it is entirely different from the regular booking.
|
||||
* We are open to renaming it to something more descriptive.
|
||||
*/
|
||||
export class RegularBookingService implements IBookingService {
|
||||
constructor(private readonly deps: IBookingServiceDependencies) {}
|
||||
|
||||
async createBooking(input: { bookingData: CreateRegularBookingData; bookingMeta?: CreateBookingMeta }) {
|
||||
// deps to be passed to handler in follow-up PR
|
||||
return handler({ bookingData: input.bookingData, ...input.bookingMeta });
|
||||
}
|
||||
|
||||
async rescheduleBooking(input: { bookingData: CreateRegularBookingData; bookingMeta?: CreateBookingMeta }) {
|
||||
return handler({ bookingData: input.bookingData, ...input.bookingMeta });
|
||||
}
|
||||
|
||||
async rescheduleBookingForApiV1(input: {
|
||||
bookingData: CreateRegularBookingData;
|
||||
bookingMeta?: CreateBookingMeta;
|
||||
bookingDataSchemaGetter: BookingDataSchemaGetter;
|
||||
}) {
|
||||
return handler({ bookingData: input.bookingData, ...input.bookingMeta }, input.bookingDataSchemaGetter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,6 +249,7 @@ function buildNewBookingData(params: CreateBookingParams) {
|
||||
dynamicEventSlugRef: !eventType.id ? eventType.slug : null,
|
||||
dynamicGroupSlugRef: !eventType.id ? (reqBody.user as string).toLowerCase() : null,
|
||||
iCalUID: evt.iCalUID ?? "",
|
||||
iCalSequence: originalRescheduledBooking ? evt.iCalSequence || 1 : 0,
|
||||
user: {
|
||||
connect: {
|
||||
id: eventType.organizerUser.id,
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
import type { CreateBookingMeta, CreateRecurringBookingData } from "@calcom/features/bookings/lib/dto/types";
|
||||
import handleNewBooking from "@calcom/features/bookings/lib/handleNewBooking";
|
||||
import type { BookingResponse } from "@calcom/features/bookings/types";
|
||||
import { SchedulingType } from "@calcom/prisma/client";
|
||||
import type { AppsStatus } from "@calcom/types/Calendar";
|
||||
|
||||
export type PlatformParams = {
|
||||
platformClientId?: string;
|
||||
platformCancelUrl?: string;
|
||||
platformBookingUrl?: string;
|
||||
platformRescheduleUrl?: string;
|
||||
platformBookingLocation?: string;
|
||||
areCalendarEventsEnabled?: boolean;
|
||||
};
|
||||
import type { RegularBookingService } from "./handleNewBooking";
|
||||
import type { IBookingService } from "./interfaces/IBookingService";
|
||||
|
||||
export type BookingHandlerInput = {
|
||||
bookingData: Record<string, any>[];
|
||||
userId?: number;
|
||||
// These used to come from headers but now we're passing them as params
|
||||
hostname?: string;
|
||||
forcedSlug?: string;
|
||||
noEmail?: boolean;
|
||||
} & PlatformParams;
|
||||
bookingData: CreateRecurringBookingData;
|
||||
} & CreateBookingMeta;
|
||||
|
||||
export const handleNewRecurringBooking = async (input: BookingHandlerInput): Promise<BookingResponse[]> => {
|
||||
const data = input.bookingData;
|
||||
@@ -115,7 +105,7 @@ export const handleNewRecurringBooking = async (input: BookingHandlerInput): Pro
|
||||
|
||||
if (!thirdPartyRecurringEventId) {
|
||||
if (eachRecurringBooking.references && eachRecurringBooking.references.length > 0) {
|
||||
for (const reference of eachRecurringBooking.references!) {
|
||||
for (const reference of eachRecurringBooking.references) {
|
||||
if (reference.thirdPartyRecurringEventId) {
|
||||
thirdPartyRecurringEventId = reference.thirdPartyRecurringEventId;
|
||||
break;
|
||||
@@ -126,3 +116,32 @@ export const handleNewRecurringBooking = async (input: BookingHandlerInput): Pro
|
||||
}
|
||||
return createdBookings;
|
||||
};
|
||||
|
||||
export interface IRecurringBookingServiceDependencies {
|
||||
regularBookingService: RegularBookingService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recurring Booking Service takes care of creating/rescheduling recurring bookings.
|
||||
*/
|
||||
export class RecurringBookingService implements IBookingService {
|
||||
constructor(private readonly deps: IRecurringBookingServiceDependencies) {}
|
||||
|
||||
async createBooking(input: {
|
||||
bookingData: CreateRecurringBookingData;
|
||||
bookingMeta?: CreateBookingMeta;
|
||||
}): Promise<BookingResponse[]> {
|
||||
const handlerInput = { bookingData: input.bookingData, ...(input.bookingMeta || {}) };
|
||||
// FOLLOW-UP: Pass on dependencies to the handler
|
||||
return handleNewRecurringBooking(handlerInput);
|
||||
}
|
||||
|
||||
async rescheduleBooking(input: {
|
||||
bookingData: CreateRecurringBookingData;
|
||||
bookingMeta?: CreateBookingMeta;
|
||||
}): Promise<BookingResponse[]> {
|
||||
const handlerInput = { bookingData: input.bookingData, ...(input.bookingMeta || {}) };
|
||||
// FOLLOW-UP: Pass on dependencies to the handler
|
||||
return handleNewRecurringBooking(handlerInput);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Defines an interface that could be used by any type of Booking Service
|
||||
// "Any" types are used because this inteface is used by RecurringBookingService which accepts an array of bookingData and RegularBookingService which accepts a single bookingData
|
||||
// So, this interface enforces just the methods that must be present but not their parameters and return types
|
||||
export interface IBookingCreateService {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
createBooking: (...args: any[]) => Promise<any>;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// Defines an interface that could be used by any type of Booking Service
|
||||
// "Any" types are used because this inteface is used by RecurringBookingService which accepts an array of bookingData and RegularBookingService which accepts a single bookingData
|
||||
// So, this interface enforces just the methods that must be present but not their parameters and return types
|
||||
export interface IBookingService {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
createBooking: (...args: any[]) => Promise<any>;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
rescheduleBooking: (...args: any[]) => Promise<any>;
|
||||
}
|
||||
@@ -2,12 +2,14 @@ import type { Session } from "next-auth";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { UserPermissionRole } from "@calcom/prisma/enums";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import {
|
||||
parseTeamId,
|
||||
checkSelfImpersonation,
|
||||
checkUserIdentifier,
|
||||
checkGlobalPermission,
|
||||
checkPBACImpersonationPermission,
|
||||
} from "./ImpersonationProvider";
|
||||
|
||||
const session: Session = {
|
||||
@@ -79,3 +81,41 @@ describe("checkPermission", () => {
|
||||
expect(() => checkGlobalPermission(session)).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkPBACImpersonationPermission", () => {
|
||||
it("should return true for admin users", async () => {
|
||||
const result = await checkPBACImpersonationPermission({
|
||||
userId: 123,
|
||||
teamId: 456,
|
||||
userRole: MembershipRole.ADMIN,
|
||||
});
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for owner users", async () => {
|
||||
const result = await checkPBACImpersonationPermission({
|
||||
userId: 123,
|
||||
teamId: 456,
|
||||
userRole: MembershipRole.OWNER,
|
||||
});
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false for member users", async () => {
|
||||
const result = await checkPBACImpersonationPermission({
|
||||
userId: 123,
|
||||
teamId: 456,
|
||||
userRole: MembershipRole.MEMBER,
|
||||
});
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it("should handle organization context", async () => {
|
||||
const result = await checkPBACImpersonationPermission({
|
||||
userId: 123,
|
||||
organizationId: 789,
|
||||
userRole: MembershipRole.ADMIN,
|
||||
});
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,12 +5,16 @@ import { z } from "zod";
|
||||
|
||||
import { ensureOrganizationIsReviewed } from "@calcom/ee/organizations/lib/ensureOrganizationIsReviewed";
|
||||
import { getSession } from "@calcom/features/auth/lib/getSession";
|
||||
import { getSpecificPermissions } from "@calcom/features/pbac/lib/resource-permissions";
|
||||
import { ProfileRepository } from "@calcom/lib/server/repository/profile";
|
||||
import prisma from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { Membership } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { OrgProfile, PersonalProfile, UserAsPersonalProfile } from "@calcom/types/UserProfile";
|
||||
|
||||
import { Resource, CustomAction } from "../../../pbac/domain/types/permission-registry";
|
||||
|
||||
const teamIdschema = z.object({
|
||||
teamId: z.preprocess((a) => parseInt(z.string().parse(a), 10), z.number().positive()),
|
||||
});
|
||||
@@ -113,6 +117,69 @@ export function checkGlobalPermission(session: Session | null) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check PBAC permissions for impersonation
|
||||
* This function integrates with the new PBAC system to determine impersonation permissions
|
||||
*/
|
||||
export async function checkPBACImpersonationPermission({
|
||||
userId,
|
||||
teamId,
|
||||
userRole,
|
||||
organizationId,
|
||||
}: {
|
||||
userId: number;
|
||||
teamId?: number;
|
||||
userRole: MembershipRole;
|
||||
organizationId?: number | null;
|
||||
}): Promise<boolean> {
|
||||
try {
|
||||
// For organization-level impersonation
|
||||
if (organizationId) {
|
||||
const orgPermissions = await getSpecificPermissions({
|
||||
userId,
|
||||
teamId: organizationId,
|
||||
resource: Resource.Organization,
|
||||
userRole,
|
||||
actions: [CustomAction.Impersonate],
|
||||
fallbackRoles: {
|
||||
[CustomAction.Impersonate]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (orgPermissions[CustomAction.Impersonate]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// For team-level impersonation
|
||||
if (teamId) {
|
||||
const teamPermissions = await getSpecificPermissions({
|
||||
userId,
|
||||
teamId,
|
||||
resource: Resource.Team,
|
||||
userRole,
|
||||
actions: [CustomAction.Impersonate],
|
||||
fallbackRoles: {
|
||||
[CustomAction.Impersonate]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return teamPermissions[CustomAction.Impersonate] ?? false;
|
||||
}
|
||||
|
||||
// Fallback to role-based check if no team/org context
|
||||
return userRole === MembershipRole.ADMIN || userRole === MembershipRole.OWNER;
|
||||
} catch (error) {
|
||||
console.error("Error checking PBAC impersonation permission:", error);
|
||||
// Fallback to role-based check on error
|
||||
return userRole === MembershipRole.ADMIN || userRole === MembershipRole.OWNER;
|
||||
}
|
||||
}
|
||||
|
||||
async function getImpersonatedUser({
|
||||
session,
|
||||
teamId,
|
||||
@@ -295,11 +362,6 @@ const ImpersonationProvider = CredentialsProvider({
|
||||
teams: {
|
||||
where: {
|
||||
AND: [
|
||||
{
|
||||
role: {
|
||||
in: ["ADMIN", "OWNER"],
|
||||
},
|
||||
},
|
||||
{
|
||||
team: {
|
||||
id: teamId,
|
||||
@@ -318,6 +380,19 @@ const ImpersonationProvider = CredentialsProvider({
|
||||
throw new Error("Error-UserHasNoTeams: You do not have permission to do this.");
|
||||
}
|
||||
|
||||
// Check PBAC permissions for impersonation
|
||||
const hasImpersonationPermission = await checkPBACImpersonationPermission({
|
||||
userId: session?.user.id as number,
|
||||
teamId,
|
||||
userRole: sessionUserFromDb?.teams[0].role as MembershipRole,
|
||||
organizationId: session?.user.org?.id,
|
||||
});
|
||||
|
||||
if (!hasImpersonationPermission) {
|
||||
throw new Error("You do not have permission to impersonate this user.");
|
||||
}
|
||||
|
||||
// Legacy role check as additional safeguard (PBAC should handle this but keeping for backwards compatibility)
|
||||
// We find team by ID so we know there is only one team in the array
|
||||
if (sessionUserFromDb?.teams[0].role === "ADMIN" && impersonatedUser.teams[0].role === "OWNER") {
|
||||
throw new Error("You do not have permission to do this.");
|
||||
|
||||
@@ -15,7 +15,6 @@ import { useQueryState, parseAsBoolean } from "nuqs";
|
||||
import { useMemo, useReducer, useRef, useState } from "react";
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
|
||||
import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
|
||||
import { Dialog } from "@calcom/features/components/controlled-dialog";
|
||||
import {
|
||||
DataTableProvider,
|
||||
@@ -30,10 +29,10 @@ import {
|
||||
} from "@calcom/features/data-table";
|
||||
import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";
|
||||
import { DynamicLink } from "@calcom/features/users/components/UserTable/BulkActions/DynamicLink";
|
||||
import type { MemberPermissions } from "@calcom/features/users/components/UserTable/types";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import { trpc } from "@calcom/trpc";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import { Avatar } from "@calcom/ui/components/avatar";
|
||||
@@ -163,6 +162,7 @@ interface Props {
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
permissions: MemberPermissions;
|
||||
}
|
||||
|
||||
export default function MemberList(props: Props) {
|
||||
@@ -292,8 +292,6 @@ function MemberListContent(props: Props) {
|
||||
// return owners.length;
|
||||
// };
|
||||
|
||||
const isAdminOrOwner = checkAdminOrOwner(props.team.membership.role);
|
||||
|
||||
const removeMember = () =>
|
||||
removeMemberMutation.mutate({
|
||||
teamIds: [props.team?.id],
|
||||
@@ -429,17 +427,19 @@ function MemberListContent(props: Props) {
|
||||
cell: ({ row }) => {
|
||||
const user = row.original;
|
||||
const isSelf = user.id === session?.user.id;
|
||||
// TODO(SEAN) In a follow up can we rename canChangeMemberRole to canEditMembers - role is a bit specific.
|
||||
const canChangeRole = props.permissions?.canChangeMemberRole ?? false;
|
||||
const canRemove = props.permissions?.canRemove ?? false;
|
||||
const canImpersonate = props.permissions?.canImpersonate ?? false;
|
||||
const canResendInvitation = props.permissions?.canInvite ?? false;
|
||||
const editMode =
|
||||
(props.team.membership?.role === MembershipRole.OWNER &&
|
||||
(user.role !== MembershipRole.OWNER || !isSelf)) ||
|
||||
(props.team.membership?.role === MembershipRole.ADMIN && user.role !== MembershipRole.OWNER) ||
|
||||
props.isOrgAdminOrOwner;
|
||||
[canChangeRole, canRemove, canImpersonate, canResendInvitation].some(Boolean) && !isSelf;
|
||||
|
||||
const impersonationMode =
|
||||
editMode &&
|
||||
canImpersonate &&
|
||||
!user.disableImpersonation &&
|
||||
user.accepted &&
|
||||
process.env.NEXT_PUBLIC_TEAM_IMPERSONATION === "true";
|
||||
const resendInvitation = editMode && !user.accepted;
|
||||
return (
|
||||
<>
|
||||
{props.team.membership?.accepted && (
|
||||
@@ -495,22 +495,24 @@ function MemberListContent(props: Props) {
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuPortal>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem>
|
||||
<DropdownItem
|
||||
type="button"
|
||||
onClick={() =>
|
||||
dispatch({
|
||||
type: "EDIT_USER_SHEET",
|
||||
payload: {
|
||||
user,
|
||||
showModal: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
StartIcon="pencil">
|
||||
{t("edit")}
|
||||
</DropdownItem>
|
||||
</DropdownMenuItem>
|
||||
{canChangeRole ? (
|
||||
<DropdownMenuItem>
|
||||
<DropdownItem
|
||||
type="button"
|
||||
onClick={() =>
|
||||
dispatch({
|
||||
type: "EDIT_USER_SHEET",
|
||||
payload: {
|
||||
user,
|
||||
showModal: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
StartIcon="pencil">
|
||||
{t("edit")}
|
||||
</DropdownItem>
|
||||
</DropdownMenuItem>
|
||||
) : null}
|
||||
{impersonationMode && (
|
||||
<>
|
||||
<DropdownMenuItem>
|
||||
@@ -532,7 +534,7 @@ function MemberListContent(props: Props) {
|
||||
<DropdownMenuSeparator />
|
||||
</>
|
||||
)}
|
||||
{resendInvitation && (
|
||||
{canResendInvitation && (
|
||||
<DropdownMenuItem>
|
||||
<DropdownItem
|
||||
type="button"
|
||||
@@ -548,23 +550,25 @@ function MemberListContent(props: Props) {
|
||||
</DropdownItem>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem>
|
||||
<DropdownItem
|
||||
type="button"
|
||||
onClick={() =>
|
||||
dispatch({
|
||||
type: "SET_DELETE_ID",
|
||||
payload: {
|
||||
user,
|
||||
showModal: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
color="destructive"
|
||||
StartIcon="user-x">
|
||||
{t("remove")}
|
||||
</DropdownItem>
|
||||
</DropdownMenuItem>
|
||||
{canRemove ? (
|
||||
<DropdownMenuItem>
|
||||
<DropdownItem
|
||||
type="button"
|
||||
onClick={() =>
|
||||
dispatch({
|
||||
type: "SET_DELETE_ID",
|
||||
payload: {
|
||||
user,
|
||||
showModal: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
color="destructive"
|
||||
StartIcon="user-x">
|
||||
{t("remove")}
|
||||
</DropdownItem>
|
||||
</DropdownMenuItem>
|
||||
) : null}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenuPortal>
|
||||
</Dropdown>
|
||||
@@ -713,7 +717,7 @@ function MemberListContent(props: Props) {
|
||||
ToolbarRight={
|
||||
<>
|
||||
<DataTableFilters.ClearFiltersButton />
|
||||
{isAdminOrOwner && (
|
||||
{props.permissions.canInvite && (
|
||||
<DataTableToolbar.CTA
|
||||
type="button"
|
||||
color="primary"
|
||||
|
||||
@@ -8,6 +8,7 @@ import { v4 as uuidv4 } from "uuid";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import generateIcsString from "@calcom/emails/lib/generateIcsString";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import { SENDER_NAME } from "@calcom/lib/constants";
|
||||
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
@@ -352,7 +353,9 @@ export async function handler(req: NextRequest) {
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
sender: reminder.workflowStep.sender,
|
||||
sender: reminder.booking?.eventType?.hideOrganizerEmail
|
||||
? SENDER_NAME
|
||||
: reminder.workflowStep.sender,
|
||||
...(!reminder.booking?.eventType?.hideOrganizerEmail && {
|
||||
replyTo:
|
||||
reminder.booking?.eventType?.customReplyToEmail ??
|
||||
@@ -441,7 +444,9 @@ export async function handler(req: NextRequest) {
|
||||
subject: emailContent.emailSubject,
|
||||
to: [sendTo],
|
||||
html: emailContent.emailBody,
|
||||
sender: reminder.workflowStep?.sender,
|
||||
sender: reminder.booking?.eventType?.hideOrganizerEmail
|
||||
? SENDER_NAME
|
||||
: reminder.workflowStep?.sender,
|
||||
...(!reminder.booking?.eventType?.hideOrganizerEmail && {
|
||||
replyTo:
|
||||
reminder.booking?.eventType?.customReplyToEmail ||
|
||||
|
||||
@@ -6,7 +6,7 @@ import generateIcsString from "@calcom/emails/lib/generateIcsString";
|
||||
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
||||
import { preprocessNameFieldDataWithVariant } from "@calcom/features/form-builder/utils";
|
||||
import tasker from "@calcom/features/tasker";
|
||||
import { WEBSITE_URL } from "@calcom/lib/constants";
|
||||
import { SENDER_NAME, WEBSITE_URL } from "@calcom/lib/constants";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import prisma from "@calcom/prisma";
|
||||
@@ -270,7 +270,7 @@ export const scheduleEmailReminder = async (args: scheduleEmailReminderArgs) =>
|
||||
html: emailContent.emailBody,
|
||||
...(!evt.hideOrganizerEmail && { replyTo: evt?.eventType?.customReplyToEmail || evt.organizer.email }),
|
||||
attachments,
|
||||
sender,
|
||||
sender: evt.hideOrganizerEmail ? SENDER_NAME : sender,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,16 @@ import short from "short-uuid";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type {
|
||||
CreateInstantBookingData,
|
||||
CreateInstantBookingResponse,
|
||||
} from "@calcom/features/bookings/lib/dto/types";
|
||||
import getBookingDataSchema from "@calcom/features/bookings/lib/getBookingDataSchema";
|
||||
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
|
||||
import { getBookingData } from "@calcom/features/bookings/lib/handleNewBooking/getBookingData";
|
||||
import { getCustomInputsResponses } from "@calcom/features/bookings/lib/handleNewBooking/getCustomInputsResponses";
|
||||
import { getEventTypesFromDB } from "@calcom/features/bookings/lib/handleNewBooking/getEventTypesFromDB";
|
||||
import type { IBookingCreateService } from "@calcom/features/bookings/lib/interfaces/IBookingCreateService";
|
||||
import { getFullName } from "@calcom/features/form-builder/utils";
|
||||
import { sendNotification } from "@calcom/features/notifications/sendNotification";
|
||||
import { sendGenericWebhookPayload } from "@calcom/features/webhooks/lib/sendPayload";
|
||||
@@ -151,17 +156,8 @@ const triggerBrowserNotifications = async (args: {
|
||||
await Promise.allSettled(promises);
|
||||
};
|
||||
|
||||
export type HandleInstantMeetingResponse = {
|
||||
message: string;
|
||||
meetingTokenId: number;
|
||||
bookingId: number;
|
||||
bookingUid: string;
|
||||
expires: Date;
|
||||
userId: number | null;
|
||||
};
|
||||
|
||||
async function handler(req: NextApiRequest) {
|
||||
let eventType = await getEventTypesFromDB(req.body.eventTypeId);
|
||||
async function _handler(bookingData: CreateInstantBookingData) {
|
||||
let eventType = await getEventTypesFromDB(bookingData.eventTypeId);
|
||||
const isOrgTeamEvent = !!eventType?.team && !!eventType?.team?.parentId;
|
||||
eventType = {
|
||||
...eventType,
|
||||
@@ -173,11 +169,11 @@ async function handler(req: NextApiRequest) {
|
||||
}
|
||||
|
||||
const schema = getBookingDataSchema({
|
||||
view: req.body?.rescheduleUid ? "reschedule" : "booking",
|
||||
view: bookingData?.rescheduleUid ? "reschedule" : "booking",
|
||||
bookingFields: eventType.bookingFields,
|
||||
});
|
||||
const reqBody = await getBookingData({
|
||||
reqBody: req.body,
|
||||
reqBody: bookingData,
|
||||
eventType,
|
||||
schema,
|
||||
});
|
||||
@@ -257,7 +253,7 @@ async function handler(req: NextApiRequest) {
|
||||
data: attendeesList,
|
||||
},
|
||||
},
|
||||
creationSource: req.body.creationSource,
|
||||
creationSource: bookingData.creationSource,
|
||||
};
|
||||
|
||||
const createBookingObj = {
|
||||
@@ -275,7 +271,7 @@ async function handler(req: NextApiRequest) {
|
||||
|
||||
const eventTypeWithExpiryTimeOffset = await prisma.eventType.findUniqueOrThrow({
|
||||
where: {
|
||||
id: req.body.eventTypeId,
|
||||
id: bookingData.eventTypeId,
|
||||
},
|
||||
select: {
|
||||
instantMeetingExpiryTimeOffsetInSeconds: true,
|
||||
@@ -334,7 +330,21 @@ async function handler(req: NextApiRequest) {
|
||||
bookingUid: newBooking.uid,
|
||||
expires: instantMeetingToken.expires,
|
||||
userId: newBooking.userId,
|
||||
} satisfies HandleInstantMeetingResponse;
|
||||
} satisfies CreateInstantBookingResponse;
|
||||
}
|
||||
|
||||
export default handler;
|
||||
/**
|
||||
* Instant booking service that handles instant/immediate bookings
|
||||
*/
|
||||
export class InstantBookingCreateService implements IBookingCreateService {
|
||||
async createBooking(input: {
|
||||
bookingData: CreateInstantBookingData;
|
||||
}): Promise<CreateInstantBookingResponse> {
|
||||
return _handler(input.bookingData);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove it in a follow-up PR
|
||||
export default async function handler(req: NextApiRequest) {
|
||||
return _handler(req.body);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ export enum CustomAction {
|
||||
ReadTeamBookings = "readTeamBookings",
|
||||
ReadOrgBookings = "readOrgBookings",
|
||||
ReadRecordings = "readRecordings",
|
||||
Impersonate = "impersonate",
|
||||
}
|
||||
|
||||
export enum Scope {
|
||||
@@ -263,21 +264,34 @@ export const PERMISSION_REGISTRY: PermissionRegistry = {
|
||||
category: "team",
|
||||
i18nKey: "pbac_action_invite",
|
||||
descriptionI18nKey: "pbac_desc_invite_team_members",
|
||||
dependsOn: ["team.read"],
|
||||
dependsOn: ["team.read", "team.listMembers"],
|
||||
},
|
||||
[CustomAction.Remove]: {
|
||||
description: "Remove team members",
|
||||
category: "team",
|
||||
i18nKey: "pbac_action_remove",
|
||||
descriptionI18nKey: "pbac_desc_remove_team_members",
|
||||
dependsOn: ["team.read"],
|
||||
dependsOn: ["team.read", "team.listMembers"],
|
||||
},
|
||||
[CustomAction.ListMembers]: {
|
||||
description: "List team members",
|
||||
category: "team",
|
||||
i18nKey: "pbac_action_list_members",
|
||||
descriptionI18nKey: "pbac_desc_list_team_members",
|
||||
},
|
||||
[CustomAction.ChangeMemberRole]: {
|
||||
description: "Change role of team members",
|
||||
category: "team",
|
||||
i18nKey: "pbac_action_change_member_role",
|
||||
descriptionI18nKey: "pbac_desc_change_team_member_role",
|
||||
dependsOn: ["team.read"],
|
||||
dependsOn: ["team.read", "team.listMembers"],
|
||||
},
|
||||
[CustomAction.Impersonate]: {
|
||||
description: "Impersonate team members",
|
||||
category: "team",
|
||||
i18nKey: "pbac_action_impersonate",
|
||||
descriptionI18nKey: "pbac_desc_impersonate_team_members",
|
||||
dependsOn: ["team.read", "team.listMembers"],
|
||||
},
|
||||
},
|
||||
[Resource.Organization]: {
|
||||
@@ -338,6 +352,13 @@ export const PERMISSION_REGISTRY: PermissionRegistry = {
|
||||
scope: [Scope.Organization],
|
||||
dependsOn: ["organization.listMembers", "role.read"],
|
||||
},
|
||||
[CustomAction.Impersonate]: {
|
||||
description: "Impersonate organization members",
|
||||
category: "org",
|
||||
i18nKey: "pbac_action_impersonate",
|
||||
descriptionI18nKey: "pbac_desc_impersonate_organization_members",
|
||||
scope: [Scope.Organization],
|
||||
},
|
||||
[CrudAction.Update]: {
|
||||
description: "Edit organization settings",
|
||||
category: "org",
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { PermissionMapper } from "../domain/mappers/PermissionMapper";
|
||||
import type { Resource } from "../domain/types/permission-registry";
|
||||
import { CrudAction } from "../domain/types/permission-registry";
|
||||
import { CrudAction, CustomAction } from "../domain/types/permission-registry";
|
||||
import { PermissionCheckService } from "../services/permission-check.service";
|
||||
|
||||
interface RoleMapping {
|
||||
@@ -85,3 +85,58 @@ export const getResourcePermissions = async ({
|
||||
canCreate: roleActions[CrudAction.Create] ?? false,
|
||||
};
|
||||
};
|
||||
|
||||
// Enhanced function to get specific custom action permissions
|
||||
type ActionType = CrudAction | CustomAction;
|
||||
|
||||
interface SpecificActionMapping {
|
||||
[key: string]: RoleMapping;
|
||||
}
|
||||
|
||||
interface SpecificPermissionsOptions {
|
||||
userId: number;
|
||||
teamId: number;
|
||||
resource: Resource;
|
||||
userRole: MembershipRole;
|
||||
actions: ActionType[];
|
||||
fallbackRoles?: SpecificActionMapping;
|
||||
}
|
||||
|
||||
export const getSpecificPermissions = async ({
|
||||
userId,
|
||||
teamId,
|
||||
resource,
|
||||
userRole,
|
||||
actions,
|
||||
fallbackRoles = {},
|
||||
}: SpecificPermissionsOptions): Promise<Record<string, boolean>> => {
|
||||
const featureRepo = new FeaturesRepository(prisma);
|
||||
const permissionService = new PermissionCheckService();
|
||||
|
||||
const pbacEnabled = await featureRepo.checkIfTeamHasFeature(teamId, "pbac");
|
||||
|
||||
// If PBAC is disabled, use fallback role configuration
|
||||
if (!pbacEnabled) {
|
||||
const permissions: Record<string, boolean> = {};
|
||||
for (const action of actions) {
|
||||
permissions[action] = checkRoleAccess(userRole, fallbackRoles[action]);
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
// PBAC is enabled, get permissions from the service
|
||||
const resourcePermissions = await permissionService.getResourcePermissions({
|
||||
userId,
|
||||
teamId,
|
||||
resource,
|
||||
});
|
||||
|
||||
const roleActions = PermissionMapper.toActionMap(resourcePermissions, resource);
|
||||
|
||||
const permissions: Record<string, boolean> = {};
|
||||
for (const action of actions) {
|
||||
permissions[action] = roleActions[action] ?? false;
|
||||
}
|
||||
|
||||
return permissions;
|
||||
};
|
||||
|
||||
@@ -13,20 +13,31 @@ export function CellHighlightContainer({ children }: { children: React.ReactNode
|
||||
|
||||
const [isAnimating, setIsAnimating] = useState(false);
|
||||
const componentContainerRef = useRef<HTMLDivElement>(null);
|
||||
const { x, y, height, isHover, updateDimensions, setContainerRef } = useStore(store, (state) => state);
|
||||
const { x, y, height, isHover, updateDimensions, setContainerRef, browsingDate, emitCellPosition } =
|
||||
useStore(store, (state) => state);
|
||||
const prevBrowsingDateRef = useRef(browsingDate);
|
||||
|
||||
useEffect(() => {
|
||||
let timeout: NodeJS.Timeout | null = null;
|
||||
if (isHover) {
|
||||
setIsAnimating(true);
|
||||
} else {
|
||||
timeout = setTimeout(() => setIsAnimating(false), 1000);
|
||||
timeout = setTimeout(() => setIsAnimating(false), 300);
|
||||
}
|
||||
return () => {
|
||||
timeout && clearTimeout(timeout);
|
||||
};
|
||||
}, [isHover]);
|
||||
|
||||
useEffect(() => {
|
||||
if (prevBrowsingDateRef.current?.getTime() !== browsingDate.getTime()) {
|
||||
setIsAnimating(false);
|
||||
// Clear hover state and position when date changes
|
||||
emitCellPosition(-1);
|
||||
prevBrowsingDateRef.current = browsingDate;
|
||||
}
|
||||
}, [browsingDate, emitCellPosition]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const handleUpdate = () => {
|
||||
updateDimensions();
|
||||
@@ -50,13 +61,16 @@ export function CellHighlightContainer({ children }: { children: React.ReactNode
|
||||
return (
|
||||
<LazyMotion features={domAnimation}>
|
||||
<div
|
||||
className="relative -mx-2 w-[calc(100%+16px)] overflow-x-scroll px-2 lg:-mx-6 lg:w-[calc(100%+48px)] lg:px-6"
|
||||
className="relative -mx-2 w-[calc(100%+16px)] overflow-hidden overflow-x-scroll px-2 lg:-mx-6 lg:w-[calc(100%+48px)] lg:px-6"
|
||||
ref={componentContainerRef}>
|
||||
{children}
|
||||
|
||||
<m.div
|
||||
className="border-subtle opcaity-0 pointer-events-none absolute left-0 top-0 h-full rounded-lg border-2"
|
||||
animate={{ x: [null, x], opacity: isAnimating || isHover ? 1 : 0.1 }}
|
||||
className="border-subtle pointer-events-none absolute left-0 top-0 h-full rounded-lg border-2 opacity-0"
|
||||
animate={{
|
||||
x: [null, x],
|
||||
opacity: isAnimating || isHover ? 1 : 0,
|
||||
}}
|
||||
style={{ y, height, width: DAY_CELL_WIDTH }}
|
||||
transition={{ type: "spring", stiffness: 300, damping: 30 }}
|
||||
/>
|
||||
|
||||
@@ -50,7 +50,7 @@ import { EditUserSheet } from "./EditSheet/EditUserSheet";
|
||||
import { ImpersonationMemberModal } from "./ImpersonationMemberModal";
|
||||
import { InviteMemberModal } from "./InviteMemberModal";
|
||||
import { TableActions } from "./UserTableActions";
|
||||
import type { UserTableState, UserTableAction, UserTableUser } from "./types";
|
||||
import type { UserTableState, UserTableAction, UserTableUser, MemberPermissions } from "./types";
|
||||
|
||||
const initialState: UserTableState = {
|
||||
changeMemberRole: {
|
||||
@@ -122,6 +122,7 @@ export type UserListTableProps = {
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
permissions?: MemberPermissions;
|
||||
};
|
||||
|
||||
export function UserListTable(props: UserListTableProps) {
|
||||
@@ -132,7 +133,13 @@ export function UserListTable(props: UserListTableProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function UserListTableContent({ org, attributes, teams, facetedTeamValues }: UserListTableProps) {
|
||||
function UserListTableContent({
|
||||
org,
|
||||
attributes,
|
||||
teams,
|
||||
facetedTeamValues,
|
||||
permissions,
|
||||
}: UserListTableProps) {
|
||||
const [dynamicLinkVisible, setDynamicLinkVisible] = useQueryState("dynamicLink", parseAsBoolean);
|
||||
const orgBranding = useOrgBranding();
|
||||
const domain = orgBranding?.fullDomain ?? WEBAPP_URL;
|
||||
@@ -169,11 +176,12 @@ function UserListTableContent({ org, attributes, teams, facetedTeamValues }: Use
|
||||
const flatData = useMemo<UserTableUser[]>(() => data?.rows ?? [], [data]);
|
||||
|
||||
const memorisedColumns = useMemo(() => {
|
||||
const permissions = {
|
||||
canEdit: adminOrOwner,
|
||||
canRemove: adminOrOwner,
|
||||
canResendInvitation: adminOrOwner,
|
||||
canImpersonate: false,
|
||||
// Use PBAC permissions if available, otherwise fall back to role-based check
|
||||
const tablePermissions = {
|
||||
canEdit: permissions?.canChangeMemberRole ?? adminOrOwner,
|
||||
canRemove: permissions?.canRemove ?? adminOrOwner,
|
||||
canResendInvitation: permissions?.canInvite ?? adminOrOwner,
|
||||
canImpersonate: permissions?.canImpersonate ?? adminOrOwner,
|
||||
};
|
||||
const generateAttributeColumns = () => {
|
||||
if (!attributes?.length) {
|
||||
@@ -445,14 +453,18 @@ function UserListTableContent({ org, attributes, teams, facetedTeamValues }: Use
|
||||
size: 80,
|
||||
cell: ({ row }) => {
|
||||
const user = row.original;
|
||||
const permissionsRaw = permissions;
|
||||
const permissionsRaw = tablePermissions;
|
||||
const isSelf = user.id === session?.user.id;
|
||||
|
||||
const permissionsForUser = {
|
||||
canEdit: permissionsRaw.canEdit && user.accepted && !isSelf,
|
||||
canRemove: permissionsRaw.canRemove && !isSelf,
|
||||
canImpersonate:
|
||||
user.accepted && !user.disableImpersonation && !isSelf && !!org?.canAdminImpersonate,
|
||||
user.accepted &&
|
||||
!user.disableImpersonation &&
|
||||
!isSelf &&
|
||||
!!org?.canAdminImpersonate &&
|
||||
permissionsRaw.canImpersonate,
|
||||
canLeave: user.accepted && isSelf,
|
||||
canResendInvitation: permissionsRaw.canResendInvitation && !user.accepted,
|
||||
};
|
||||
@@ -470,7 +482,7 @@ function UserListTableContent({ org, attributes, teams, facetedTeamValues }: Use
|
||||
];
|
||||
|
||||
return cols;
|
||||
}, [session?.user.id, adminOrOwner, dispatch, domain, attributes, org?.canAdminImpersonate]);
|
||||
}, [session?.user.id, adminOrOwner, dispatch, domain, attributes, org?.canAdminImpersonate, permissions]);
|
||||
|
||||
const table = useReactTable({
|
||||
data: flatData,
|
||||
@@ -619,7 +631,7 @@ function UserListTableContent({ org, attributes, teams, facetedTeamValues }: Use
|
||||
</p>
|
||||
{!isPlatformUser ? (
|
||||
<>
|
||||
{adminOrOwner && <TeamListBulkAction table={table} />}
|
||||
{permissions?.canChangeMemberRole && <TeamListBulkAction table={table} />}
|
||||
{numberOfSelectedRows >= 2 && (
|
||||
<DataTableSelectionBar.Button
|
||||
color="secondary"
|
||||
@@ -628,11 +640,15 @@ function UserListTableContent({ org, attributes, teams, facetedTeamValues }: Use
|
||||
{t("group_meeting")}
|
||||
</DataTableSelectionBar.Button>
|
||||
)}
|
||||
{adminOrOwner && <MassAssignAttributesBulkAction table={table} filters={columnFilters} />}
|
||||
{adminOrOwner && <EventTypesList table={table} orgTeams={teams} />}
|
||||
{(permissions?.canChangeMemberRole ?? adminOrOwner) && (
|
||||
<MassAssignAttributesBulkAction table={table} filters={columnFilters} />
|
||||
)}
|
||||
{(permissions?.canChangeMemberRole ?? adminOrOwner) && (
|
||||
<EventTypesList table={table} orgTeams={teams} />
|
||||
)}
|
||||
</>
|
||||
) : null}
|
||||
{adminOrOwner && (
|
||||
{(permissions?.canRemove ?? adminOrOwner) && (
|
||||
<DeleteBulkUsers
|
||||
users={table.getSelectedRowModel().flatRows.map((row) => row.original)}
|
||||
onRemove={() => table.toggleAllPageRowsSelected(false)}
|
||||
@@ -660,7 +676,7 @@ function UserListTableContent({ org, attributes, teams, facetedTeamValues }: Use
|
||||
data-testid="export-members-button">
|
||||
{t("download")}
|
||||
</DataTableToolbar.CTA>
|
||||
{adminOrOwner && (
|
||||
{(permissions?.canInvite ?? adminOrOwner) && (
|
||||
<DataTableToolbar.CTA
|
||||
type="button"
|
||||
color="primary"
|
||||
|
||||
@@ -52,3 +52,11 @@ export type PlatformManagedUserTableAction =
|
||||
| {
|
||||
type: "CLOSE_MODAL";
|
||||
};
|
||||
|
||||
export interface MemberPermissions {
|
||||
canListMembers: boolean;
|
||||
canInvite: boolean;
|
||||
canChangeMemberRole: boolean;
|
||||
canRemove: boolean;
|
||||
canImpersonate: boolean;
|
||||
}
|
||||
|
||||
@@ -51,4 +51,10 @@ export const DI_TOKENS = {
|
||||
HOST_REPOSITORY_MODULE: Symbol("HostRepositoryModule"),
|
||||
ATTRIBUTE_REPOSITORY: Symbol("AttributeRepository"),
|
||||
ATTRIBUTE_REPOSITORY_MODULE: Symbol("AttributeRepositoryModule"),
|
||||
REGULAR_BOOKING_SERVICE: Symbol("RegularBookingService"),
|
||||
REGULAR_BOOKING_SERVICE_MODULE: Symbol("RegularBookingServiceModule"),
|
||||
RECURRING_BOOKING_SERVICE: Symbol("RecurringBookingService"),
|
||||
RECURRING_BOOKING_SERVICE_MODULE: Symbol("RecurringBookingServiceModule"),
|
||||
INSTANT_BOOKING_CREATE_SERVICE: Symbol("InstantBookingCreateService"),
|
||||
INSTANT_BOOKING_CREATE_SERVICE_MODULE: Symbol("InstantBookingCreateServiceModule"),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
## 1.1.2
|
||||
|
||||
## 1.7.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#23445](https://github.com/calcom/cal.com/pull/23445) [`9724bc0`](https://github.com/calcom/cal.com/commit/9724bc07a6d9bfe3ff32fa4e5657de2da3068d85) Thanks [@supalarry](https://github.com/supalarry)! - feat: italian language support
|
||||
|
||||
## 1.6.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
+46
-27
@@ -1,12 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { useReducer, Suspense } from "react";
|
||||
import { useReducer } from "react";
|
||||
|
||||
import { AppList } from "@calcom/features/apps/components/AppList";
|
||||
import DisconnectIntegrationModal from "@calcom/features/apps/components/DisconnectIntegrationModal";
|
||||
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { EmptyScreen } from "@calcom/ui/components/empty-screen";
|
||||
import { SkeletonText, SkeletonContainer } from "@calcom/ui/components/skeleton";
|
||||
@@ -22,39 +23,46 @@ export type UpdateUsersDefaultConferencingAppParams = {
|
||||
export type BulkUpdatParams = { eventTypeIds: number[]; callback: () => void };
|
||||
type RemoveAppParams = { credentialId: number; teamId?: number; callback: () => void };
|
||||
|
||||
const SkeletonLoader = () => {
|
||||
export const SkeletonLoader = () => {
|
||||
const { t } = useLocale();
|
||||
return (
|
||||
<SkeletonContainer>
|
||||
<div className="divide-subtle border-subtle space-y-6 rounded-b-lg border border-t-0 px-6 py-4">
|
||||
<SkeletonText className="h-8 w-full" />
|
||||
<SkeletonText className="h-8 w-full" />
|
||||
</div>
|
||||
</SkeletonContainer>
|
||||
<SettingsHeader
|
||||
title={t("conferencing")}
|
||||
description={t("conferencing_description")}
|
||||
CTA={<AddConferencingButton />}
|
||||
borderInShellHeader={true}>
|
||||
<SkeletonContainer>
|
||||
<div className="divide-subtle border-subtle space-y-6 rounded-b-lg border border-t-0 px-6 py-4">
|
||||
<SkeletonText className="h-8 w-full" />
|
||||
<SkeletonText className="h-8 w-full" />
|
||||
</div>
|
||||
</SkeletonContainer>
|
||||
</SettingsHeader>
|
||||
);
|
||||
};
|
||||
|
||||
const InstalledConferencingApps = ({
|
||||
type IntegrationsOutput = RouterOutputs["viewer"]["apps"]["integrations"];
|
||||
type DefaultConferencingApp = RouterOutputs["viewer"]["apps"]["getUsersDefaultConferencingApp"] | undefined;
|
||||
type EventTypesList = RouterOutputs["viewer"]["eventTypes"]["bulkEventFetch"]["eventTypes"];
|
||||
|
||||
export const InstalledConferencingApps = ({
|
||||
disconnectIntegrationModalCtrl,
|
||||
integrations,
|
||||
defaultConferencingApp,
|
||||
eventTypes,
|
||||
}: {
|
||||
disconnectIntegrationModalCtrl: ReturnType<typeof useDisconnectIntegrationModalController>;
|
||||
integrations: IntegrationsOutput;
|
||||
defaultConferencingApp: DefaultConferencingApp;
|
||||
eventTypes: EventTypesList;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useUtils();
|
||||
|
||||
const { data: defaultConferencingApp } = trpc.viewer.apps.getUsersDefaultConferencingApp.useQuery();
|
||||
|
||||
const updateDefaultAppMutation = trpc.viewer.apps.updateUserDefaultConferencingApp.useMutation();
|
||||
|
||||
const updateLocationsMutation = trpc.viewer.eventTypes.bulkUpdateToDefaultLocation.useMutation();
|
||||
|
||||
const { data: eventTypesQueryData, isFetching: isEventTypesFetching } =
|
||||
trpc.viewer.eventTypes.bulkEventFetch.useQuery();
|
||||
|
||||
const [result] = trpc.viewer.apps.integrations.useSuspenseQuery({
|
||||
variant: "conferencing",
|
||||
onlyInstalled: true,
|
||||
});
|
||||
|
||||
const handleConnectDisconnectIntegrationMenuToggle = () => {
|
||||
utils.viewer.apps.integrations.invalidate();
|
||||
};
|
||||
@@ -99,7 +107,7 @@ const InstalledConferencingApps = ({
|
||||
);
|
||||
};
|
||||
|
||||
if (result.items.length === 0) {
|
||||
if (integrations.items.length === 0) {
|
||||
return (
|
||||
<EmptyScreen
|
||||
Icon="calendar"
|
||||
@@ -123,14 +131,14 @@ const InstalledConferencingApps = ({
|
||||
<AppList
|
||||
listClassName="rounded-lg rounded-t-none border-t-0 max-w-full"
|
||||
handleDisconnect={disconnectIntegrationModalCtrl.disconnect}
|
||||
data={result}
|
||||
data={integrations}
|
||||
variant="conferencing"
|
||||
defaultConferencingApp={defaultConferencingApp}
|
||||
handleUpdateUserDefaultConferencingApp={handleUpdateUserDefaultConferencingApp}
|
||||
handleBulkUpdateDefaultLocation={handleBulkUpdateDefaultLocation}
|
||||
isBulkUpdateDefaultLocationPending={updateDefaultAppMutation.isPending}
|
||||
eventTypes={eventTypesQueryData?.eventTypes}
|
||||
isEventTypesFetching={isEventTypesFetching}
|
||||
eventTypes={eventTypes}
|
||||
isEventTypesFetching={false}
|
||||
handleConnectDisconnectIntegrationMenuToggle={handleConnectDisconnectIntegrationMenuToggle}
|
||||
handleBulkEditDialogToggle={handleBulkEditDialogToggle}
|
||||
/>
|
||||
@@ -179,7 +187,15 @@ const AddConferencingButton = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export const ConferencingAppsViewWebWrapper = () => {
|
||||
export const ConferencingAppsViewWebWrapper = ({
|
||||
integrations,
|
||||
defaultConferencingApp,
|
||||
eventTypes,
|
||||
}: {
|
||||
integrations: IntegrationsOutput;
|
||||
defaultConferencingApp: DefaultConferencingApp;
|
||||
eventTypes: EventTypesList;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useUtils();
|
||||
|
||||
@@ -213,9 +229,12 @@ export const ConferencingAppsViewWebWrapper = () => {
|
||||
borderInShellHeader={true}>
|
||||
<>
|
||||
<div className="bg-default w-full sm:mx-0 xl:mt-0">
|
||||
<Suspense fallback={<SkeletonLoader />}>
|
||||
<InstalledConferencingApps disconnectIntegrationModalCtrl={disconnectIntegrationModalCtrl} />
|
||||
</Suspense>
|
||||
<InstalledConferencingApps
|
||||
disconnectIntegrationModalCtrl={disconnectIntegrationModalCtrl}
|
||||
integrations={integrations}
|
||||
defaultConferencingApp={defaultConferencingApp}
|
||||
eventTypes={eventTypes}
|
||||
/>
|
||||
</div>
|
||||
<DisconnectIntegrationModal
|
||||
handleModelClose={disconnectIntegrationModalCtrl.close}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"type": "module",
|
||||
"description": "Customizable UI components to integrate scheduling into your product.",
|
||||
"authors": "Cal.com, Inc.",
|
||||
"version": "1.6.0",
|
||||
"version": "1.7.0",
|
||||
"scripts": {
|
||||
"dev": "yarn vite build --watch & npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify --watch",
|
||||
"build": "NODE_OPTIONS='--max_old_space_size=12288' rm -rf dist && yarn vite build && npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify && mkdir ./dist/packages/prisma-client && cp -rf ../../../node_modules/.prisma/client/*.d.ts ./dist/packages/prisma-client",
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
-- Add team.listMembers permission to admin role
|
||||
INSERT INTO "RolePermission" (id, "roleId", resource, action, "createdAt")
|
||||
SELECT
|
||||
gen_random_uuid(), 'admin_role', resource, action, NOW()
|
||||
FROM (
|
||||
VALUES
|
||||
('team', 'listMembers')
|
||||
) AS permissions(resource, action)
|
||||
ON CONFLICT ("roleId", resource, action) DO NOTHING;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
-- Add impersonate permissions to admin role
|
||||
-- These permissions allow administrators to impersonate team and organization members
|
||||
|
||||
-- Insert impersonate permissions for admin role
|
||||
INSERT INTO "RolePermission" (id, "roleId", resource, action, "createdAt")
|
||||
SELECT
|
||||
gen_random_uuid(), 'admin_role', resource, action, NOW()
|
||||
FROM (
|
||||
VALUES
|
||||
-- Team impersonate permission
|
||||
('team', 'impersonate'),
|
||||
|
||||
-- Organization impersonate permission
|
||||
('organization', 'impersonate')
|
||||
) AS permissions(resource, action)
|
||||
ON CONFLICT ("roleId", resource, action) DO NOTHING;
|
||||
|
||||
-- Note: Owner role already has wildcard permissions (*.*) so it inherits all impersonate permissions automatically
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
INSERT INTO "RolePermission" (id, "roleId", resource, action, "createdAt")
|
||||
SELECT
|
||||
gen_random_uuid(), 'member_role', resource, action, NOW()
|
||||
FROM (
|
||||
VALUES
|
||||
('team', 'listMembers')
|
||||
) AS permissions(resource, action);
|
||||
@@ -3,6 +3,7 @@ import z, { ZodNullable, ZodObject, ZodOptional } from "zod";
|
||||
import { timeZoneSchema } from "@calcom/lib/dayjs/timeZone.schema";
|
||||
// TODO: Move this out of here. Importing from app-store is a circular package dependency.
|
||||
import { routingFormResponseInDbSchema } from "@calcom/app-store/routing-forms/zod";
|
||||
import { CreationSource } from "@calcom/prisma/enums";
|
||||
|
||||
export const bookingCreateBodySchema = z.object({
|
||||
end: z.string().optional(),
|
||||
@@ -47,7 +48,8 @@ export const bookingCreateBodySchema = z.object({
|
||||
utm_term: z.string().optional(),
|
||||
utm_content: z.string().optional(),
|
||||
}).optional(),
|
||||
dub_id: z.string().nullish()
|
||||
dub_id: z.string().nullish(),
|
||||
creationSource: z.nativeEnum(CreationSource).optional(),
|
||||
});
|
||||
|
||||
export type BookingCreateBody = z.input<typeof bookingCreateBodySchema>;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { TeamBilling } from "@calcom/ee/billing/teams";
|
||||
import { isOrganisationAdmin } from "@calcom/lib/server/queries/organisations";
|
||||
import { Resource, CustomAction } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { getSpecificPermissions } from "@calcom/features/pbac/lib/resource-permissions";
|
||||
import { ProfileRepository } from "@calcom/lib/server/repository/profile";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
@@ -21,9 +23,38 @@ export async function bulkDeleteUsersHandler({ ctx, input }: BulkDeleteUsersHand
|
||||
|
||||
if (!currentUserOrgId) throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
|
||||
// check if user is admin of organization
|
||||
if (!(await isOrganisationAdmin(currentUser?.id, currentUserOrgId)))
|
||||
// Get user's membership role in the organization
|
||||
const membership = await prisma.membership.findFirst({
|
||||
where: {
|
||||
userId: currentUser.id,
|
||||
teamId: currentUserOrgId,
|
||||
},
|
||||
select: {
|
||||
role: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!membership) {
|
||||
throw new TRPCError({ code: "UNAUTHORIZED", message: "User is not a member of this organization." });
|
||||
}
|
||||
|
||||
// Check PBAC permissions for removing organization members
|
||||
const permissions = await getSpecificPermissions({
|
||||
userId: currentUser.id,
|
||||
teamId: currentUserOrgId,
|
||||
resource: Resource.Organization,
|
||||
userRole: membership.role,
|
||||
actions: [CustomAction.Remove],
|
||||
fallbackRoles: {
|
||||
[CustomAction.Remove]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!permissions[CustomAction.Remove]) {
|
||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
}
|
||||
|
||||
// Loop over all users in input.userIds and remove all memberships for the organization including child teams
|
||||
const deleteMany = prisma.membership.deleteMany({
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { isOrganisationAdmin } from "@calcom/lib/server/queries/organisations";
|
||||
import { Resource, CustomAction } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { getSpecificPermissions } from "@calcom/features/pbac/lib/resource-permissions";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
@@ -18,9 +20,42 @@ export async function getUserHandler({ input, ctx }: AdminVerifyOptions) {
|
||||
|
||||
if (!currentUser.organizationId) throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
|
||||
// check if user is admin of organization
|
||||
if (!(await isOrganisationAdmin(currentUser?.id, currentUser.organizationId)))
|
||||
// Get user's membership role in the organization
|
||||
const currentUserMembership = await prisma.membership.findFirst({
|
||||
where: {
|
||||
userId: currentUser.id,
|
||||
teamId: currentUser.organizationId,
|
||||
},
|
||||
select: {
|
||||
role: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!currentUserMembership) {
|
||||
throw new TRPCError({ code: "UNAUTHORIZED", message: "User is not a member of this organization." });
|
||||
}
|
||||
|
||||
// Check PBAC permissions for viewing/editing organization members
|
||||
const permissions = await getSpecificPermissions({
|
||||
userId: currentUser.id,
|
||||
teamId: currentUser.organizationId,
|
||||
resource: Resource.Organization,
|
||||
userRole: currentUserMembership.role,
|
||||
actions: [CustomAction.ListMembers, CustomAction.ChangeMemberRole],
|
||||
fallbackRoles: {
|
||||
[CustomAction.ListMembers]: {
|
||||
roles: [MembershipRole.MEMBER, MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
[CustomAction.ChangeMemberRole]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// User needs either ListMembers (to view) or ChangeMemberRole (to edit) permission
|
||||
if (!permissions[CustomAction.ListMembers] || !permissions[CustomAction.ChangeMemberRole]) {
|
||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
}
|
||||
|
||||
// get requested user from database and ensure they are in the same organization
|
||||
const [requestedUser, membership, teams] = await prisma.$transaction([
|
||||
|
||||
@@ -9,6 +9,7 @@ const prismaMock = {
|
||||
membership: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
count: vi.fn().mockResolvedValue(0),
|
||||
findFirst: vi.fn().mockResolvedValue({ role: "ADMIN" }),
|
||||
},
|
||||
attributeOption: {
|
||||
findMany: vi.fn().mockResolvedValue([
|
||||
@@ -16,11 +17,16 @@ const prismaMock = {
|
||||
{ id: "2", value: "value2", isGroup: false },
|
||||
]),
|
||||
},
|
||||
attributeToUser: {
|
||||
findMany: vi.fn().mockResolvedValue([]),
|
||||
},
|
||||
};
|
||||
|
||||
vi.spyOn(prisma.membership, "findMany").mockImplementation(prismaMock.membership.findMany);
|
||||
vi.spyOn(prisma.membership, "count").mockImplementation(prismaMock.membership.count);
|
||||
vi.spyOn(prisma.membership, "findFirst").mockImplementation(prismaMock.membership.findFirst);
|
||||
vi.spyOn(prisma.attributeOption, "findMany").mockImplementation(prismaMock.attributeOption.findMany);
|
||||
vi.spyOn(prisma.attributeToUser, "findMany").mockImplementation(prismaMock.attributeToUser.findMany);
|
||||
|
||||
// Mock FeaturesRepository
|
||||
const mockCheckIfTeamHasFeature = vi.fn();
|
||||
@@ -30,6 +36,20 @@ vi.mock("@calcom/features/flags/features.repository", () => ({
|
||||
})),
|
||||
}));
|
||||
|
||||
// Mock PBAC permissions
|
||||
vi.mock("@calcom/features/pbac/lib/resource-permissions", () => ({
|
||||
getSpecificPermissions: vi.fn().mockResolvedValue({
|
||||
listMembers: true,
|
||||
}),
|
||||
}));
|
||||
|
||||
// Mock UserRepository
|
||||
vi.mock("@calcom/lib/server/repository/user", () => ({
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
enrichUserWithItsProfile: vi.fn().mockImplementation(({ user }) => user),
|
||||
})),
|
||||
}));
|
||||
|
||||
const ORGANIZATION_ID = 123;
|
||||
|
||||
const mockUser = {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { makeWhereClause } from "@calcom/features/data-table/lib/server";
|
||||
import { type TypedColumnFilter, ColumnFilterType } from "@calcom/features/data-table/lib/types";
|
||||
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
||||
import { Resource, CustomAction } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { getSpecificPermissions } from "@calcom/features/pbac/lib/resource-permissions";
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
@@ -69,7 +72,38 @@ export const listMembersHandler = async ({ ctx, input }: GetOptions) => {
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: "User is not part of any organization." });
|
||||
}
|
||||
|
||||
if (ctx.user.organization.isPrivate && !ctx.user.organization.isOrgAdmin) {
|
||||
// Get user's membership role in the organization
|
||||
const membership = await prisma.membership.findFirst({
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
teamId: organizationId,
|
||||
},
|
||||
select: {
|
||||
role: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!membership) {
|
||||
throw new TRPCError({ code: "UNAUTHORIZED", message: "User is not a member of this organization." });
|
||||
}
|
||||
|
||||
// Check PBAC permissions for listing organization members
|
||||
const permissions = await getSpecificPermissions({
|
||||
userId: ctx.user.id,
|
||||
teamId: organizationId,
|
||||
resource: Resource.Organization,
|
||||
userRole: membership.role,
|
||||
actions: [CustomAction.ListMembers],
|
||||
fallbackRoles: {
|
||||
[CustomAction.ListMembers]: {
|
||||
roles: ctx.user.organization.isPrivate
|
||||
? [MembershipRole.ADMIN, MembershipRole.OWNER]
|
||||
: [MembershipRole.MEMBER, MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!permissions[CustomAction.ListMembers]) {
|
||||
return {
|
||||
canUserGetMembers: false,
|
||||
rows: [],
|
||||
@@ -78,7 +112,6 @@ export const listMembersHandler = async ({ ctx, input }: GetOptions) => {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const { limit, offset } = input;
|
||||
|
||||
const roleFilter = filters.find((filter) => filter.id === "role") as
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
|
||||
import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
|
||||
import { Resource, CustomAction } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { getSpecificPermissions } from "@calcom/features/pbac/lib/resource-permissions";
|
||||
import { RoleManagementFactory } from "@calcom/features/pbac/services/role-management.factory";
|
||||
import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";
|
||||
import { TeamRepository } from "@calcom/lib/server/repository/team";
|
||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
@@ -146,26 +148,17 @@ export const listMembersHandler = async ({ ctx, input }: ListMembersHandlerOptio
|
||||
};
|
||||
|
||||
const checkCanAccessMembers = async (ctx: ListMembersHandlerOptions["ctx"], teamId: number) => {
|
||||
const isOrgPrivate = ctx.user.profile?.organization?.isPrivate;
|
||||
const isOrgAdminOrOwner = ctx.user.organization?.isOrgAdmin;
|
||||
const orgId = ctx.user.organizationId;
|
||||
const isTargetingOrg = teamId === ctx.user.organizationId;
|
||||
|
||||
if (isTargetingOrg) {
|
||||
return isOrgAdminOrOwner || !isOrgPrivate;
|
||||
}
|
||||
// Get team info to check if it's private
|
||||
const team = await prisma.team.findUnique({
|
||||
where: {
|
||||
id: teamId,
|
||||
},
|
||||
where: { id: teamId },
|
||||
select: { isPrivate: true },
|
||||
});
|
||||
|
||||
if (!team) return false;
|
||||
|
||||
if (isOrgAdminOrOwner && team?.parentId === orgId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get user's membership in the team
|
||||
const membership = await prisma.membership.findFirst({
|
||||
where: {
|
||||
teamId,
|
||||
@@ -176,12 +169,26 @@ const checkCanAccessMembers = async (ctx: ListMembersHandlerOptions["ctx"], team
|
||||
|
||||
if (!membership) return false;
|
||||
|
||||
const isTeamAdminOrOwner = checkAdminOrOwner(membership?.role);
|
||||
// Determine the resource type based on whether this is an org or team
|
||||
const resource = isTargetingOrg ? Resource.Organization : Resource.Team;
|
||||
|
||||
if (team?.isPrivate && !isTeamAdminOrOwner) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
// Check PBAC permissions for listing members
|
||||
const permissions = await getSpecificPermissions({
|
||||
userId: ctx.user.id,
|
||||
teamId: teamId,
|
||||
resource: resource,
|
||||
userRole: membership.role,
|
||||
actions: [CustomAction.ListMembers],
|
||||
fallbackRoles: {
|
||||
[CustomAction.ListMembers]: {
|
||||
roles: team.isPrivate
|
||||
? [MembershipRole.ADMIN, MembershipRole.OWNER]
|
||||
: [MembershipRole.MEMBER, MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return permissions[CustomAction.ListMembers];
|
||||
};
|
||||
|
||||
export default listMembersHandler;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
||||
import { Resource, CustomAction } from "@calcom/features/pbac/domain/types/permission-registry";
|
||||
import { getSpecificPermissions } from "@calcom/features/pbac/lib/resource-permissions";
|
||||
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import { isTeamAdmin, isTeamOwner } from "@calcom/lib/server/queries/teams";
|
||||
import { isTeamOwner } from "@calcom/lib/server/queries/teams";
|
||||
import { TeamService } from "@calcom/lib/server/service/teamService";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { MembershipRole } from "@calcom/prisma/enums";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
@@ -22,42 +27,93 @@ export const removeMemberHandler = async ({ ctx, input }: RemoveMemberOptions) =
|
||||
|
||||
const { memberIds, teamIds, isOrg } = input;
|
||||
|
||||
const isAdmin = await Promise.all(
|
||||
teamIds.map(async (teamId) => await isTeamAdmin(ctx.user.id, teamId))
|
||||
// Check PBAC permissions for each team
|
||||
const hasRemovePermission = await Promise.all(
|
||||
teamIds.map(async (teamId) => {
|
||||
// Get user's membership role in this team
|
||||
const membership = await prisma.membership.findFirst({
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
teamId: teamId,
|
||||
},
|
||||
select: {
|
||||
role: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!membership) return false;
|
||||
|
||||
// Check PBAC permissions for removing team members
|
||||
const permissions = await getSpecificPermissions({
|
||||
userId: ctx.user.id,
|
||||
teamId: teamId,
|
||||
resource: isOrg ? Resource.Organization : Resource.Team,
|
||||
userRole: membership.role,
|
||||
actions: [CustomAction.Remove],
|
||||
fallbackRoles: {
|
||||
[CustomAction.Remove]: {
|
||||
roles: [MembershipRole.ADMIN, MembershipRole.OWNER],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return permissions[CustomAction.Remove];
|
||||
})
|
||||
).then((results) => results.every((result) => result));
|
||||
|
||||
const isOrgAdmin = ctx.user.profile?.organizationId
|
||||
? await isTeamAdmin(ctx.user.id, ctx.user.profile?.organizationId)
|
||||
: false;
|
||||
// Check if user is trying to remove themselves (allowed for non-owners)
|
||||
const isRemovingSelf = memberIds.length === 1 && memberIds[0] === ctx.user.id;
|
||||
|
||||
if (!(isAdmin || isOrgAdmin) && memberIds.every((memberId) => ctx.user.id !== memberId))
|
||||
// Allow if user has remove permission OR if they're removing themselves
|
||||
if (!hasRemovePermission && !isRemovingSelf) {
|
||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||
|
||||
// Only a team owner can remove another team owner.
|
||||
const isAnyMemberOwnerAndCurrentUserNotOwner = await Promise.all(
|
||||
memberIds.map(async (memberId) => {
|
||||
const isAnyTeamOwnerAndCurrentUserNotOwner = await Promise.all(
|
||||
teamIds.map(async (teamId) => {
|
||||
return (await isTeamOwner(memberId, teamId)) && !(await isTeamOwner(ctx.user.id, teamId));
|
||||
})
|
||||
).then((results) => results.some((result) => result));
|
||||
|
||||
return isAnyTeamOwnerAndCurrentUserNotOwner;
|
||||
})
|
||||
).then((results) => results.some((result) => result));
|
||||
|
||||
if (isAnyMemberOwnerAndCurrentUserNotOwner) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "Only a team owner can remove another team owner.",
|
||||
});
|
||||
}
|
||||
|
||||
if (memberIds.some((memberId) => ctx.user.id === memberId) && isAdmin && !isOrgAdmin)
|
||||
throw new TRPCError({
|
||||
code: "FORBIDDEN",
|
||||
message: "You can not remove yourself from a team you own.",
|
||||
});
|
||||
// TODO(SEAN): Remove this after PBAC is rolled out.
|
||||
// Check if any team has PBAC enabled
|
||||
const featuresRepository = new FeaturesRepository(prisma);
|
||||
const pbacEnabledForTeams = await Promise.all(
|
||||
teamIds.map(async (teamId) => await featuresRepository.checkIfTeamHasFeature(teamId, "pbac"))
|
||||
);
|
||||
const isAnyTeamPBACEnabled = pbacEnabledForTeams.some((enabled) => enabled);
|
||||
|
||||
// Only apply traditional owner-based logic if PBAC is not enabled for any teams
|
||||
if (!isAnyTeamPBACEnabled) {
|
||||
// Only a team owner can remove another team owner.
|
||||
const isAnyMemberOwnerAndCurrentUserNotOwner = await Promise.all(
|
||||
memberIds.map(async (memberId) => {
|
||||
const isAnyTeamOwnerAndCurrentUserNotOwner = await Promise.all(
|
||||
teamIds.map(async (teamId) => {
|
||||
return (await isTeamOwner(memberId, teamId)) && !(await isTeamOwner(ctx.user.id, teamId));
|
||||
})
|
||||
).then((results) => results.some((result) => result));
|
||||
|
||||
return isAnyTeamOwnerAndCurrentUserNotOwner;
|
||||
})
|
||||
).then((results) => results.some((result) => result));
|
||||
|
||||
if (isAnyMemberOwnerAndCurrentUserNotOwner) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "Only a team owner can remove another team owner.",
|
||||
});
|
||||
}
|
||||
|
||||
// Check if user is trying to remove themselves from a team they own (prevent this)
|
||||
if (isRemovingSelf && hasRemovePermission) {
|
||||
// Additional check: ensure they're not an owner trying to remove themselves
|
||||
const isOwnerOfAnyTeam = await Promise.all(
|
||||
teamIds.map(async (teamId) => await isTeamOwner(ctx.user.id, teamId))
|
||||
).then((results) => results.some((result) => result));
|
||||
|
||||
if (isOwnerOfAnyTeam) {
|
||||
throw new TRPCError({
|
||||
code: "FORBIDDEN",
|
||||
message: "You can not remove yourself from a team you own.",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await TeamService.removeMembers({ teamIds, userIds: memberIds, isOrg });
|
||||
};
|
||||
|
||||
@@ -70,7 +70,7 @@ const ColorPicker = (props: ColorPickerProps) => {
|
||||
{resetDefaultValue && color != resetDefaultValue && (
|
||||
<div className="px-1">
|
||||
<Button
|
||||
color={resetDefaultValue == "#292929" ? "primary" : "secondary"}
|
||||
color="secondary"
|
||||
target="_blank"
|
||||
variant="icon"
|
||||
rel="noreferrer"
|
||||
|
||||
@@ -21256,6 +21256,22 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"array-includes@npm:^3.1.9":
|
||||
version: 3.1.9
|
||||
resolution: "array-includes@npm:3.1.9"
|
||||
dependencies:
|
||||
call-bind: ^1.0.8
|
||||
call-bound: ^1.0.4
|
||||
define-properties: ^1.2.1
|
||||
es-abstract: ^1.24.0
|
||||
es-object-atoms: ^1.1.1
|
||||
get-intrinsic: ^1.3.0
|
||||
is-string: ^1.1.1
|
||||
math-intrinsics: ^1.1.0
|
||||
checksum: b58dc526fe415252e50319eaf88336e06e75aa673e3b58d252414739a4612dbe56e7b613fdcc7c90561dc9cf9202bbe5ca029ccd8c08362746459475ae5a8f3e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"array-timsort@npm:^1.0.3":
|
||||
version: 1.0.3
|
||||
resolution: "array-timsort@npm:1.0.3"
|
||||
@@ -21323,7 +21339,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"array.prototype.findlastindex@npm:^1.2.5":
|
||||
"array.prototype.findlastindex@npm:^1.2.5, array.prototype.findlastindex@npm:^1.2.6":
|
||||
version: 1.2.6
|
||||
resolution: "array.prototype.findlastindex@npm:1.2.6"
|
||||
dependencies:
|
||||
@@ -21350,6 +21366,18 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"array.prototype.flat@npm:^1.3.3":
|
||||
version: 1.3.3
|
||||
resolution: "array.prototype.flat@npm:1.3.3"
|
||||
dependencies:
|
||||
call-bind: ^1.0.8
|
||||
define-properties: ^1.2.1
|
||||
es-abstract: ^1.23.5
|
||||
es-shim-unscopables: ^1.0.2
|
||||
checksum: 5d5a7829ab2bb271a8d30a1c91e6271cef0ec534593c0fe6d2fb9ebf8bb62c1e5326e2fddcbbcbbe5872ca04f5e6b54a1ecf092e0af704fb538da9b2bfd95b40
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"array.prototype.flatmap@npm:^1.3.0":
|
||||
version: 1.3.0
|
||||
resolution: "array.prototype.flatmap@npm:1.3.0"
|
||||
@@ -22701,6 +22729,7 @@ __metadata:
|
||||
date-fns-tz: ^3.2.0
|
||||
dotenv-checker: ^1.1.5
|
||||
eslint: ^8.34.0
|
||||
eslint-plugin-import: ^2.32.0
|
||||
husky: ^8.0.0
|
||||
i18n-unused: ^0.13.0
|
||||
jest-diff: ^29.5.0
|
||||
@@ -26502,6 +26531,68 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"es-abstract@npm:^1.24.0":
|
||||
version: 1.24.0
|
||||
resolution: "es-abstract@npm:1.24.0"
|
||||
dependencies:
|
||||
array-buffer-byte-length: ^1.0.2
|
||||
arraybuffer.prototype.slice: ^1.0.4
|
||||
available-typed-arrays: ^1.0.7
|
||||
call-bind: ^1.0.8
|
||||
call-bound: ^1.0.4
|
||||
data-view-buffer: ^1.0.2
|
||||
data-view-byte-length: ^1.0.2
|
||||
data-view-byte-offset: ^1.0.1
|
||||
es-define-property: ^1.0.1
|
||||
es-errors: ^1.3.0
|
||||
es-object-atoms: ^1.1.1
|
||||
es-set-tostringtag: ^2.1.0
|
||||
es-to-primitive: ^1.3.0
|
||||
function.prototype.name: ^1.1.8
|
||||
get-intrinsic: ^1.3.0
|
||||
get-proto: ^1.0.1
|
||||
get-symbol-description: ^1.1.0
|
||||
globalthis: ^1.0.4
|
||||
gopd: ^1.2.0
|
||||
has-property-descriptors: ^1.0.2
|
||||
has-proto: ^1.2.0
|
||||
has-symbols: ^1.1.0
|
||||
hasown: ^2.0.2
|
||||
internal-slot: ^1.1.0
|
||||
is-array-buffer: ^3.0.5
|
||||
is-callable: ^1.2.7
|
||||
is-data-view: ^1.0.2
|
||||
is-negative-zero: ^2.0.3
|
||||
is-regex: ^1.2.1
|
||||
is-set: ^2.0.3
|
||||
is-shared-array-buffer: ^1.0.4
|
||||
is-string: ^1.1.1
|
||||
is-typed-array: ^1.1.15
|
||||
is-weakref: ^1.1.1
|
||||
math-intrinsics: ^1.1.0
|
||||
object-inspect: ^1.13.4
|
||||
object-keys: ^1.1.1
|
||||
object.assign: ^4.1.7
|
||||
own-keys: ^1.0.1
|
||||
regexp.prototype.flags: ^1.5.4
|
||||
safe-array-concat: ^1.1.3
|
||||
safe-push-apply: ^1.0.0
|
||||
safe-regex-test: ^1.1.0
|
||||
set-proto: ^1.0.0
|
||||
stop-iteration-iterator: ^1.1.0
|
||||
string.prototype.trim: ^1.2.10
|
||||
string.prototype.trimend: ^1.0.9
|
||||
string.prototype.trimstart: ^1.0.8
|
||||
typed-array-buffer: ^1.0.3
|
||||
typed-array-byte-length: ^1.0.3
|
||||
typed-array-byte-offset: ^1.0.4
|
||||
typed-array-length: ^1.0.7
|
||||
unbox-primitive: ^1.1.0
|
||||
which-typed-array: ^1.1.19
|
||||
checksum: 06b3d605e56e3da9d16d4db2629a42dac1ca31f2961a41d15c860422a266115e865b43e82d6b9da81a0fabbbb65ebc12fb68b0b755bc9dbddacb6bf7450e96df
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"es-array-method-boxes-properly@npm:^1.0.0":
|
||||
version: 1.0.0
|
||||
resolution: "es-array-method-boxes-properly@npm:1.0.0"
|
||||
@@ -27342,6 +27433,18 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"eslint-module-utils@npm:^2.12.1":
|
||||
version: 2.12.1
|
||||
resolution: "eslint-module-utils@npm:2.12.1"
|
||||
dependencies:
|
||||
debug: ^3.2.7
|
||||
peerDependenciesMeta:
|
||||
eslint:
|
||||
optional: true
|
||||
checksum: 2f074670d8c934687820a83140048776b28bbaf35fc37f35623f63cc9c438d496d11f0683b4feabb9a120435435d4a69604b1c6c567f118be2c9a0aba6760fc1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"eslint-module-utils@npm:^2.8.0":
|
||||
version: 2.8.1
|
||||
resolution: "eslint-module-utils@npm:2.8.1"
|
||||
@@ -27410,6 +27513,35 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"eslint-plugin-import@npm:^2.32.0":
|
||||
version: 2.32.0
|
||||
resolution: "eslint-plugin-import@npm:2.32.0"
|
||||
dependencies:
|
||||
"@rtsao/scc": ^1.1.0
|
||||
array-includes: ^3.1.9
|
||||
array.prototype.findlastindex: ^1.2.6
|
||||
array.prototype.flat: ^1.3.3
|
||||
array.prototype.flatmap: ^1.3.3
|
||||
debug: ^3.2.7
|
||||
doctrine: ^2.1.0
|
||||
eslint-import-resolver-node: ^0.3.9
|
||||
eslint-module-utils: ^2.12.1
|
||||
hasown: ^2.0.2
|
||||
is-core-module: ^2.16.1
|
||||
is-glob: ^4.0.3
|
||||
minimatch: ^3.1.2
|
||||
object.fromentries: ^2.0.8
|
||||
object.groupby: ^1.0.3
|
||||
object.values: ^1.2.1
|
||||
semver: ^6.3.1
|
||||
string.prototype.trimend: ^1.0.9
|
||||
tsconfig-paths: ^3.15.0
|
||||
peerDependencies:
|
||||
eslint: ^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8 || ^9
|
||||
checksum: 8cd40595b5e4346d3698eb577014b4b6d0ba57b7b9edf975be4f052a89330ec202d0cc5c3861d37ebeafa151b6264821410243889b0c31710911a6b625bcf76b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"eslint-plugin-jsx-a11y@npm:^6.10.0":
|
||||
version: 6.10.2
|
||||
resolution: "eslint-plugin-jsx-a11y@npm:6.10.2"
|
||||
@@ -32037,7 +32169,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"is-core-module@npm:^2.15.1, is-core-module@npm:^2.16.0":
|
||||
"is-core-module@npm:^2.15.1, is-core-module@npm:^2.16.0, is-core-module@npm:^2.16.1":
|
||||
version: 2.16.1
|
||||
resolution: "is-core-module@npm:2.16.1"
|
||||
dependencies:
|
||||
@@ -32689,7 +32821,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"is-weakref@npm:^1.1.0":
|
||||
"is-weakref@npm:^1.1.0, is-weakref@npm:^1.1.1":
|
||||
version: 1.1.1
|
||||
resolution: "is-weakref@npm:1.1.1"
|
||||
dependencies:
|
||||
@@ -38398,7 +38530,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"object-inspect@npm:^1.13.3":
|
||||
"object-inspect@npm:^1.13.3, object-inspect@npm:^1.13.4":
|
||||
version: 1.13.4
|
||||
resolution: "object-inspect@npm:1.13.4"
|
||||
checksum: 582810c6a8d2ef988ea0a39e69e115a138dad8f42dd445383b394877e5816eb4268489f316a6f74ee9c4e0a984b3eab1028e3e79d62b1ed67c726661d55c7a8b
|
||||
@@ -42463,7 +42595,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"regexp.prototype.flags@npm:^1.5.3":
|
||||
"regexp.prototype.flags@npm:^1.5.3, regexp.prototype.flags@npm:^1.5.4":
|
||||
version: 1.5.4
|
||||
resolution: "regexp.prototype.flags@npm:1.5.4"
|
||||
dependencies:
|
||||
@@ -45122,6 +45254,16 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"stop-iteration-iterator@npm:^1.1.0":
|
||||
version: 1.1.0
|
||||
resolution: "stop-iteration-iterator@npm:1.1.0"
|
||||
dependencies:
|
||||
es-errors: ^1.3.0
|
||||
internal-slot: ^1.1.0
|
||||
checksum: be944489d8829fb3bdec1a1cc4a2142c6b6eb317305eeace1ece978d286d6997778afa1ae8cb3bd70e2b274b9aa8c69f93febb1e15b94b1359b11058f9d3c3a1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"stoppable@npm:^1.1.0":
|
||||
version: 1.1.0
|
||||
resolution: "stoppable@npm:1.1.0"
|
||||
@@ -49355,7 +49497,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"which-typed-array@npm:^1.1.16, which-typed-array@npm:^1.1.18":
|
||||
"which-typed-array@npm:^1.1.16, which-typed-array@npm:^1.1.18, which-typed-array@npm:^1.1.19":
|
||||
version: 1.1.19
|
||||
resolution: "which-typed-array@npm:1.1.19"
|
||||
dependencies:
|
||||
|
||||
Reference in New Issue
Block a user