Skip to content

fix: return translated role definitions#11466

Merged
LukasHirt merged 1 commit intomasterfrom
fix/role-definitions-translations
Jun 27, 2025
Merged

fix: return translated role definitions#11466
LukasHirt merged 1 commit intomasterfrom
fix/role-definitions-translations

Conversation

@LukasHirt
Copy link
Contributor

Description

Instead of always returning the role definitions in English, we now return the role definitions in the language set in the header if present.

Motivation and Context

Content is delivered to users in their preferred locale.

How Has This Been Tested?

  • test environment: macos
  • test case 1: do request to get role definitions with de Accept-Language header

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

@LukasHirt LukasHirt self-assigned this Jun 26, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the issue of always returning role definitions in English by adding localization support based on the Accept-Language header.

  • Adds translation logic for role definitions in both the GetRoleDefinitions and GetRoleDefinition endpoints.
  • Updates the changelog to document the bugfix.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
services/graph/pkg/service/v0/rolemanagement.go Adds localization support for role definitions by translating the fields based on the Accept-Language header.
changelog/unreleased/fix-return-translated-role-definitions.md Documents the bugfix to return translated role definitions.
Comments suppressed due to low confidence (1)

services/graph/pkg/service/v0/rolemanagement.go:59

  • [nitpick] In the GetRoleDefinition function, consider updating the error message to reflect that it's handling a single role definition rather than multiple, for improved clarity in logs.
			logger.Error().Err(err).Msg("could not translate role definitions")

Comment on lines +21 to +32
locale := r.Header.Get(l10n.HeaderAcceptLanguage)
if locale != "" && locale != "en" {
err := l10n_pkg.TranslateEntity(locale, "en", roles,
l10n.TranslateField("DisplayName"),
l10n.TranslateField("Description"),
)
if err != nil {
logger.Error().Err(err).Msg("could not translate role definitions")
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we use something like

userID := revactx.ContextMustGetUser(ctx).GetUserId()
locale := l10n.MustGetUserLocale(r.Context(), userID, r.Header.Get(l10n.HeaderAcceptLanguage), g.valueService)

This would also take the users language setting into account when the header is not set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't this endpoint be user independent? Why would we authenticate the user to get a definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cleared out in a call - it's a private endpoint so we should use the settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kobergj I adjusted the rolemanagement to use the users language setting and I also added it into the drive API. I had to extend the DriveItemPermissionsApi to get the ValueService in there.

@LukasHirt LukasHirt force-pushed the fix/role-definitions-translations branch 2 times, most recently from 656e35f to ca057b5 Compare June 26, 2025 09:29
Instead of always returning the role definitions in English,
we now return the role definitions in the language set in the  header if present.
@LukasHirt LukasHirt force-pushed the fix/role-definitions-translations branch from ca057b5 to 6c102b4 Compare June 26, 2025 09:42
@sonarqubecloud
Copy link

@LukasHirt LukasHirt merged commit 1c9b04b into master Jun 27, 2025
4 checks passed
ownclouders pushed a commit that referenced this pull request Jun 27, 2025
…ions

fix: return translated role definitions
@github-actions github-actions bot deleted the fix/role-definitions-translations branch October 4, 2025 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants