Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.tags.Tag
import io.tolgee.constants.Feature
import io.tolgee.constants.Message
import io.tolgee.dtos.cacheable.isAdmin
import io.tolgee.dtos.request.apiKey.CreateApiKeyDto
Expand All @@ -31,6 +32,7 @@ import io.tolgee.security.authentication.AuthTokenType
import io.tolgee.security.authentication.AuthenticationFacade
import io.tolgee.security.authentication.RequiresSuperAuthentication
import io.tolgee.security.authorization.RequiresProjectPermissions
import io.tolgee.service.project.ProjectFeatureGuard
import io.tolgee.service.project.ProjectService
import io.tolgee.service.security.ApiKeyService
import io.tolgee.service.security.PermissionService
Expand Down Expand Up @@ -67,6 +69,7 @@ class ApiKeyController(
private val pagedResourcesAssembler: PagedResourcesAssembler<ApiKey>,
private val permissionService: PermissionService,
private val simpleProjectModelAssembler: SimpleProjectModelAssembler,
private val projectFeatureGuard: ProjectFeatureGuard,
) {
@PostMapping(path = ["/api-keys"])
@Operation(summary = "Create API key", description = "Creates new API key with provided scopes")
Expand Down Expand Up @@ -133,6 +136,7 @@ class ApiKeyController(
return ApiKeyWithLanguagesModel(
apiKeyModelAssembler.toModel(apiKey),
permittedLanguageIds = translateLanguageIds,
branchingEnabled = projectFeatureGuard.isFeatureEnabled(Feature.BRANCHING, apiKey.project),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ open class ApiKeyWithLanguagesModel(
deprecated = true,
)
val permittedLanguageIds: Set<Long>?,
@Schema(
description = "Whether branching is enabled and active on this project.",
)
val branchingEnabled: Boolean = false,
) : RepresentationModel<ApiKeyWithLanguagesModel>(),
IApiKeyModel by apiKeyModel
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ enum class Message {
BRANCH_MERGE_REVISION_NOT_VALID,
BRANCH_MERGE_CONFLICTS_NOT_RESOLVED,
BRANCH_MERGE_ALREADY_MERGED,
BRANCHING_NOT_ENABLED_FOR_PROJECT,
FEATURE_NOT_ENABLED_FOR_PROJECT,
EXPORT_KEY_PLURAL_SUFFIX_COLLISION,
TRANSLATION_EXCEEDS_CHAR_LIMIT,
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.tolgee.service.project
import io.tolgee.component.enabledFeaturesProvider.EnabledFeaturesProvider
import io.tolgee.constants.Feature
import io.tolgee.constants.Message
import io.tolgee.dtos.request.validators.exceptions.ValidationException
import io.tolgee.exceptions.BadRequestException
import io.tolgee.model.Project
import io.tolgee.security.ProjectHolder
import org.springframework.stereotype.Service
Expand All @@ -25,7 +25,7 @@ class ProjectFeatureGuard(
val project = projectHolder.projectEntity
enabledFeaturesProvider.checkFeatureEnabled(project.organizationOwner.id, feature)
if (!ProjectFeatureRegistry.isEnabledOnProject(feature, project)) {
throw ValidationException(Message.BRANCHING_NOT_ENABLED_FOR_PROJECT)
throw BadRequestException(Message.FEATURE_NOT_ENABLED_FOR_PROJECT, listOf(feature.name))
}
}

Expand All @@ -35,7 +35,7 @@ class ProjectFeatureGuard(
) {
enabledFeaturesProvider.checkFeatureEnabled(project.organizationOwner.id, feature)
if (!ProjectFeatureRegistry.isEnabledOnProject(feature, project)) {
throw ValidationException(Message.BRANCHING_NOT_ENABLED_FOR_PROJECT)
throw BadRequestException(Message.FEATURE_NOT_ENABLED_FOR_PROJECT, listOf(feature.name))
}
}

Expand Down
6 changes: 4 additions & 2 deletions webapp/src/service/apiSchema.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,8 @@ export interface components {
viewLanguageIds?: number[];
};
ApiKeyWithLanguagesModel: {
/** @description Whether branching is enabled and active on this project. */
branchingEnabled: boolean;
description: string;
/** Format: int64 */
expiresAt?: number;
Expand Down Expand Up @@ -2942,7 +2944,7 @@ export interface components {
| "branch_merge_revision_not_valid"
| "branch_merge_conflicts_not_resolved"
| "branch_merge_already_merged"
| "branching_not_enabled_for_project"
| "feature_not_enabled_for_project"
| "export_key_plural_suffix_collision"
| "translation_exceeds_char_limit";
params?: unknown[];
Expand Down Expand Up @@ -6378,7 +6380,7 @@ export interface components {
| "branch_merge_revision_not_valid"
| "branch_merge_conflicts_not_resolved"
| "branch_merge_already_merged"
| "branching_not_enabled_for_project"
| "feature_not_enabled_for_project"
| "export_key_plural_suffix_collision"
| "translation_exceeds_char_limit";
params?: unknown[];
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/translationTools/useErrorTranslation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ export function useErrorTranslation() {
return t('operation_not_permitted_in_read_only_mode');
case 'cannot_delete_branch_with_children':
return t('cannot_delete_branch_with_children');
case 'feature_not_enabled_for_project':
return t('feature_not_enabled_for_project', {
feature: params?.[0] || '',
});
case 'export_key_plural_suffix_collision':
return t('export_key_plural_suffix_collision', {
pluralKey: params?.[0] || '',
Expand Down
Loading