Skip to content

feat: add branchingEnabled to API key endpoint (chrome-extension) - #3536

Merged
JanCizmar merged 3 commits into
mainfrom
dkrizan/chrome-plugin-branching
Mar 17, 2026
Merged

feat: add branchingEnabled to API key endpoint (chrome-extension)#3536
JanCizmar merged 3 commits into
mainfrom
dkrizan/chrome-plugin-branching

Conversation

@dkrizan

@dkrizan dkrizan commented Mar 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Add branchingEnabled boolean to /v2/api-keys/current response (ApiKeyWithLanguagesModel) so clients can conditionally show branch-related UI
  • Use ProjectFeatureGuard.isFeatureEnabled(Feature.BRANCHING) which checks both org-level feature flag and project-level useBranching setting
  • Rename BRANCHING_NOT_ENABLED_FOR_PROJECT to generic FEATURE_NOT_ENABLED_FOR_PROJECT with feature name as parameter
  • Switch ProjectFeatureGuard from ValidationException to BadRequestException for consistency with OrganizationFeatureGuard
  • Add frontend error translation for feature_not_enabled_for_project

Related PRs

Test plan

  • Verify /v2/api-keys/current response includes branchingEnabled: true when branching is enabled
  • Verify branchingEnabled: false when branching feature is disabled at org level
  • Verify branchingEnabled: false when project has useBranching = false
  • Verify FEATURE_NOT_ENABLED_FOR_PROJECT error includes the feature name
  • Verify frontend displays translated error message for feature_not_enabled_for_project

Summary by CodeRabbit

  • New Features

    • API key info now includes whether branching is enabled for the project (visible in API responses and client schema).
  • Improvements

    • Error reporting for disabled features renamed and clarified; messages now indicate which feature is unavailable and client error codes/translations were updated accordingly.

@coderabbitai

coderabbitai Bot commented Mar 16, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Inject ProjectFeatureGuard into ApiKeyController to surface project branching state in API responses, add branchingEnabled to ApiKeyWithLanguagesModel, rename an error code constant and switch ProjectFeatureGuard to throw BadRequestException, and add frontend translation/schema updates for the new error code and field.

Changes

Cohort / File(s) Summary
API controller & response model
backend/api/src/main/kotlin/io/tolgee/api/v2/controllers/ApiKeyController.kt, backend/api/src/main/kotlin/io/tolgee/hateoas/apiKey/ApiKeyWithLanguagesModel.kt
Injects ProjectFeatureGuard into ApiKeyController; sets branchingEnabled on the API response model and exposes branchingEnabled: Boolean in the model.
Feature error messages & guard
backend/data/src/main/kotlin/io/tolgee/constants/Message.kt, backend/data/src/main/kotlin/io/tolgee/service/project/ProjectFeatureGuard.kt
Renames enum BRANCHING_NOT_ENABLED_FOR_PROJECTFEATURE_NOT_ENABLED_FOR_PROJECT; ProjectFeatureGuard now throws BadRequestException with payload [feature.name] when a feature is disabled.
Frontend schema & translations
webapp/src/translationTools/useErrorTranslation.ts, webapp/src/service/apiSchema.generated.ts
Adds translation handling for feature_not_enabled_for_project (uses feature param) and updates generated API schema to include branchingEnabled: boolean; replaces branching_not_enabled_for_project code with feature_not_enabled_for_project.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • bdshadow

Poem

🐇 I sniff the guard, I hop with glee,

A flag, a field — now all can see.
If branching sleeps or branching sings,
I tell the API the fluttering things.
Hooray — a rabbit's tiny spring. 🌱

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change—adding branchingEnabled to the API key endpoint—which is the primary objective visible across multiple file changes (ApiKeyController, ApiKeyWithLanguagesModel, and related error handling).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dkrizan/chrome-plugin-branching
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
webapp/src/translationTools/useErrorTranslation.ts (1)

216-219: Missing defaultValue in t() call.

Per coding guidelines, always provide a defaultValue when using the t() 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 defaultValue when using the T component or t() 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

📥 Commits

Reviewing files that changed from the base of the PR and between 569eb6d and 6279077.

📒 Files selected for processing (5)
  • backend/api/src/main/kotlin/io/tolgee/api/v2/controllers/ApiKeyController.kt
  • backend/api/src/main/kotlin/io/tolgee/hateoas/apiKey/ApiKeyWithLanguagesModel.kt
  • backend/data/src/main/kotlin/io/tolgee/constants/Message.kt
  • backend/data/src/main/kotlin/io/tolgee/service/project/ProjectFeatureGuard.kt
  • webapp/src/translationTools/useErrorTranslation.ts

dkrizan added 3 commits March 16, 2026 19:15
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.
@dkrizan
dkrizan force-pushed the dkrizan/chrome-plugin-branching branch from 4155c9f to 9fb71b3 Compare March 16, 2026 18:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
backend/data/src/main/kotlin/io/tolgee/service/project/ProjectFeatureGuard.kt (1)

24-39: Optional: de-duplicate checkEnabled logic.

checkEnabled(feature) can delegate to checkEnabled(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 for branchingEnabled to enforce explicit mapping.

Keeping = false makes 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4155c9f and 9fb71b3.

📒 Files selected for processing (6)
  • backend/api/src/main/kotlin/io/tolgee/api/v2/controllers/ApiKeyController.kt
  • backend/api/src/main/kotlin/io/tolgee/hateoas/apiKey/ApiKeyWithLanguagesModel.kt
  • backend/data/src/main/kotlin/io/tolgee/constants/Message.kt
  • backend/data/src/main/kotlin/io/tolgee/service/project/ProjectFeatureGuard.kt
  • webapp/src/service/apiSchema.generated.ts
  • webapp/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

@dkrizan dkrizan changed the title feat: add branchingEnabled to API key endpoint and fix feature guard feat: add branchingEnabled to API key endpoint for chrome-extension Mar 16, 2026
@dkrizan dkrizan changed the title feat: add branchingEnabled to API key endpoint for chrome-extension feat: add branchingEnabled to API key endpoint (chrome-extension) Mar 16, 2026
@JanCizmar
JanCizmar merged commit 2533a0a into main Mar 17, 2026
43 checks passed
@JanCizmar
JanCizmar deleted the dkrizan/chrome-plugin-branching branch March 17, 2026 11:24
TolgeeMachine added a commit that referenced this pull request Mar 17, 2026
# [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))
dkrizan added a commit to tolgee/tolgee-js that referenced this pull request Mar 19, 2026
## 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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants