feat: add branchingEnabled to API key endpoint (chrome-extension) - #3536
Conversation
📝 WalkthroughWalkthroughInject ProjectFeatureGuard into ApiKeyController to surface project branching state in API responses, add Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ApiKeyController
participant ProjectFeatureGuard
participant ResponseModel
Client->>ApiKeyController: GET /api/v2/projects/:id/apikey/current
ApiKeyController->>ProjectFeatureGuard: isFeatureEnabled(Feature.BRANCHING, project)
ProjectFeatureGuard-->>ApiKeyController: true / false (or throws BadRequestException)
ApiKeyController->>ResponseModel: build ApiKeyWithLanguagesModel(branchingEnabled = result)
ApiKeyController-->>Client: 200 OK + ApiKeyWithLanguagesModel
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
webapp/src/translationTools/useErrorTranslation.ts (1)
216-219: MissingdefaultValueint()call.Per coding guidelines, always provide a
defaultValuewhen using thet()function to ensure the UI displays meaningful text before translations are uploaded.♻️ Suggested fix
case 'feature_not_enabled_for_project': return t('feature_not_enabled_for_project', { feature: params?.[0] || '', + }, { defaultValue: 'Feature {feature} is not enabled for this project' }); - });As per coding guidelines: "Always provide
defaultValuewhen using theTcomponent ort()function to ensure the UI displays meaningful text before translations are uploaded to Tolgee"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@webapp/src/translationTools/useErrorTranslation.ts` around lines 216 - 219, The t() call in the 'feature_not_enabled_for_project' branch inside useErrorTranslation.ts is missing a defaultValue; update the t('feature_not_enabled_for_project', { feature: params?.[0] || '' }) invocation to include a defaultValue string that mirrors the intended fallback UI text (e.g., "Feature {feature} is not enabled for this project") so the UI shows meaningful text before translations are available; locate the case labeled 'feature_not_enabled_for_project' and add the defaultValue property to the options passed to t().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@webapp/src/translationTools/useErrorTranslation.ts`:
- Around line 216-219: The t() call in the 'feature_not_enabled_for_project'
branch inside useErrorTranslation.ts is missing a defaultValue; update the
t('feature_not_enabled_for_project', { feature: params?.[0] || '' }) invocation
to include a defaultValue string that mirrors the intended fallback UI text
(e.g., "Feature {feature} is not enabled for this project") so the UI shows
meaningful text before translations are available; locate the case labeled
'feature_not_enabled_for_project' and add the defaultValue property to the
options passed to t().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5e89ac7c-5d80-4b05-a515-9beec6cb4331
📒 Files selected for processing (5)
backend/api/src/main/kotlin/io/tolgee/api/v2/controllers/ApiKeyController.ktbackend/api/src/main/kotlin/io/tolgee/hateoas/apiKey/ApiKeyWithLanguagesModel.ktbackend/data/src/main/kotlin/io/tolgee/constants/Message.ktbackend/data/src/main/kotlin/io/tolgee/service/project/ProjectFeatureGuard.ktwebapp/src/translationTools/useErrorTranslation.ts
Include branchingEnabled boolean in the /v2/api-keys/current response so clients like the chrome extension can conditionally show branch selection UI only when branching is enabled on the project.
Rename BRANCHING_NOT_ENABLED_FOR_PROJECT to FEATURE_NOT_ENABLED_FOR_PROJECT and include the feature name as a parameter. Switch from ValidationException to BadRequestException for consistency with OrganizationFeatureGuard.
4155c9f to
9fb71b3
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
backend/data/src/main/kotlin/io/tolgee/service/project/ProjectFeatureGuard.kt (1)
24-39: Optional: de-duplicatecheckEnabledlogic.
checkEnabled(feature)can delegate tocheckEnabled(feature, projectHolder.projectEntity)to keep one source of truth.Suggested patch
fun checkEnabled(feature: Feature) { - val project = projectHolder.projectEntity - enabledFeaturesProvider.checkFeatureEnabled(project.organizationOwner.id, feature) - if (!ProjectFeatureRegistry.isEnabledOnProject(feature, project)) { - throw BadRequestException(Message.FEATURE_NOT_ENABLED_FOR_PROJECT, listOf(feature.name)) - } + checkEnabled(feature, projectHolder.projectEntity) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/data/src/main/kotlin/io/tolgee/service/project/ProjectFeatureGuard.kt` around lines 24 - 39, The two overloaded methods checkEnabled(feature) and checkEnabled(feature, project) duplicate logic; refactor by having checkEnabled(feature) obtain the project via projectHolder.projectEntity and delegate to checkEnabled(feature, project) so the validation (enabledFeaturesProvider.checkFeatureEnabled, ProjectFeatureRegistry.isEnabledOnProject and throwing BadRequestException) lives only in the latter; update checkEnabled(feature) to simply call checkEnabled(feature, projectHolder.projectEntity) and remove the duplicated checks from it.backend/api/src/main/kotlin/io/tolgee/hateoas/apiKey/ApiKeyWithLanguagesModel.kt (1)
17-20: Consider removing the default forbranchingEnabledto enforce explicit mapping.Keeping
= falsemakes missing assignments at future instantiation sites silent. Requiring the argument makes regressions compile-time visible.Suggested patch
- val branchingEnabled: Boolean = false, + val branchingEnabled: Boolean,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/api/src/main/kotlin/io/tolgee/hateoas/apiKey/ApiKeyWithLanguagesModel.kt` around lines 17 - 20, ApiKeyWithLanguagesModel currently declares branchingEnabled with a default value (= false) which hides missing mappings; remove the default from the property declaration so branchingEnabled becomes a required constructor parameter in ApiKeyWithLanguagesModel, update any code constructing ApiKeyWithLanguagesModel (e.g., mappers/constructors that set branchingEnabled) to pass an explicit Boolean, and run compilation to find any sites needing adjustment; reference the property name branchingEnabled and the class ApiKeyWithLanguagesModel when making these changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@backend/api/src/main/kotlin/io/tolgee/hateoas/apiKey/ApiKeyWithLanguagesModel.kt`:
- Around line 17-20: ApiKeyWithLanguagesModel currently declares
branchingEnabled with a default value (= false) which hides missing mappings;
remove the default from the property declaration so branchingEnabled becomes a
required constructor parameter in ApiKeyWithLanguagesModel, update any code
constructing ApiKeyWithLanguagesModel (e.g., mappers/constructors that set
branchingEnabled) to pass an explicit Boolean, and run compilation to find any
sites needing adjustment; reference the property name branchingEnabled and the
class ApiKeyWithLanguagesModel when making these changes.
In
`@backend/data/src/main/kotlin/io/tolgee/service/project/ProjectFeatureGuard.kt`:
- Around line 24-39: The two overloaded methods checkEnabled(feature) and
checkEnabled(feature, project) duplicate logic; refactor by having
checkEnabled(feature) obtain the project via projectHolder.projectEntity and
delegate to checkEnabled(feature, project) so the validation
(enabledFeaturesProvider.checkFeatureEnabled,
ProjectFeatureRegistry.isEnabledOnProject and throwing BadRequestException)
lives only in the latter; update checkEnabled(feature) to simply call
checkEnabled(feature, projectHolder.projectEntity) and remove the duplicated
checks from it.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 78b478d6-93a1-4303-80a7-a2363761f4b6
📒 Files selected for processing (6)
backend/api/src/main/kotlin/io/tolgee/api/v2/controllers/ApiKeyController.ktbackend/api/src/main/kotlin/io/tolgee/hateoas/apiKey/ApiKeyWithLanguagesModel.ktbackend/data/src/main/kotlin/io/tolgee/constants/Message.ktbackend/data/src/main/kotlin/io/tolgee/service/project/ProjectFeatureGuard.ktwebapp/src/service/apiSchema.generated.tswebapp/src/translationTools/useErrorTranslation.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- backend/data/src/main/kotlin/io/tolgee/constants/Message.kt
- webapp/src/service/apiSchema.generated.ts
# [3.169.0](v3.168.1...v3.169.0) (2026-03-17) ### Features * add branchingEnabled to API key endpoint (chrome-extension) ([#3536](#3536)) ([2533a0a](2533a0a))
## Summary - Add `branch` to `DevCredentials` type so `overrideCredentials` can pass branch to the SDK - Read `__tolgee_branch` from sessionStorage in `BrowserExtensionPlugin` and include it in credentials - Add `branch` to `LibConfig` type so the SDK sends its configured branch in the `TOLGEE_READY` handshake message - Clear `__tolgee_branch` from sessionStorage on credential reset ## Related PRs - chrome-plugin: tolgee/chrome-plugin#38 - tolgee-platform: tolgee/tolgee-platform#3536 ## Test plan - [x] Verify SDK reads branch from sessionStorage when set by chrome extension - [x] Verify `?branch=X` query parameter is appended to translation API calls - [x] Verify SDK's own branch config is not overridden when sessionStorage key is absent - [x] Verify branch is included in `TOLGEE_READY` handshake message to the extension <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added an optional "branch" configuration to the SDK and browser extension so users can target specific content branches and have that choice persist across sessions. * **Tests** * Expanded test coverage to validate branch handling, propagation, and session persistence. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
branchingEnabledboolean to/v2/api-keys/currentresponse (ApiKeyWithLanguagesModel) so clients can conditionally show branch-related UIProjectFeatureGuard.isFeatureEnabled(Feature.BRANCHING)which checks both org-level feature flag and project-leveluseBranchingsettingBRANCHING_NOT_ENABLED_FOR_PROJECTto genericFEATURE_NOT_ENABLED_FOR_PROJECTwith feature name as parameterProjectFeatureGuardfromValidationExceptiontoBadRequestExceptionfor consistency withOrganizationFeatureGuardfeature_not_enabled_for_projectRelated PRs
Test plan
/v2/api-keys/currentresponse includesbranchingEnabled: truewhen branching is enabledbranchingEnabled: falsewhen branching feature is disabled at org levelbranchingEnabled: falsewhen project hasuseBranching = falseFEATURE_NOT_ENABLED_FOR_PROJECTerror includes the feature namefeature_not_enabled_for_projectSummary by CodeRabbit
New Features
Improvements