OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#66132] update group regex tester
Eric Schubertc38768ab748a
diff --git a/config/locales/en.yml b/config/locales/en.ymlindex b1bf372a57b..52acb14b45e 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1377,7 +1377,7 @@ en:odd: "must be odd."regex_match_failed: "does not match the regular expression %{expression}."regex_invalid: "could not be validated with the associated regular expression."- regex_list_invalid: "could not be parsed as regular expression in lines %{invalid_lines}."+ regex_list_invalid: "Lines %{invalid_lines} could not be parsed as regular expression."hexcode_invalid: "is not a valid 6-digit hexadecimal color code."smaller_than_or_equal_to_max_length: "must be smaller than or equal to maximum length."taken: "has already been taken."diff --git a/frontend/src/app/core/turbo/turbo-requests.service.ts b/frontend/src/app/core/turbo/turbo-requests.service.tsindex 046da5d8123..90f2ed38717 100644--- a/frontend/src/app/core/turbo/turbo-requests.service.ts+++ b/frontend/src/app/core/turbo/turbo-requests.service.ts@@ -35,7 +35,7 @@ export class TurboRequestsService {'X-Authentication-Scheme': 'Session',};if(init.method && !(init.method === 'GET' || init.method === 'HEAD')) {- defaultHeaders['X-CSRF-Token'] = (document.querySelector('meta[name="csrf-token"]') as HTMLMetaElement).content;+ defaultHeaders['X-CSRF-Token'] = document.querySelector<HTMLMetaElement>('meta[name="csrf-token"]')?.content;}init.headers = {diff --git a/frontend/src/stimulus/controllers/dynamic/openid-connect/group-sync-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/openid-connect/group-sync-form.controller.tsindex 3ab892b29b4..51d71fefd65 100644--- a/frontend/src/stimulus/controllers/dynamic/openid-connect/group-sync-form.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/openid-connect/group-sync-form.controller.ts@@ -29,8 +29,7 @@*/import { Controller } from '@hotwired/stimulus';-import { MatchPreviewDialogSubmittedEvent } from './match-preview-dialog.controller';-import MatchPreviewDialogController from './match-preview-dialog.controller';+import MatchPreviewDialogController, { MatchPreviewDialogSubmittedEvent } from './match-preview-dialog.controller';export default class GroupSyncFormController extends Controller {static targets = [diff --git a/frontend/src/stimulus/controllers/dynamic/openid-connect/match-preview-dialog.controller.ts b/frontend/src/stimulus/controllers/dynamic/openid-connect/match-preview-dialog.controller.tsindex 42a3e4b6fca..a52a1919ab2 100644--- a/frontend/src/stimulus/controllers/dynamic/openid-connect/match-preview-dialog.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/openid-connect/match-preview-dialog.controller.ts@@ -29,7 +29,10 @@*/import { Controller } from '@hotwired/stimulus';-import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';+import { from, Observable, of } from 'rxjs';+import { tap } from 'rxjs/operators';++import { OpenProjectPluginContext } from 'core-app/features/plugins/plugin-context';export interface MatchPreviewDialogSubmittedEvent {detail:{@@ -52,15 +55,13 @@ export default class MatchPreviewDialogController extends Controller {declare readonly groupNamesInputTarget:HTMLInputElement;declare dialog:HTMLDialogElement;- declare turboRequests:TurboRequestsService;declare updateUrlValue:string;declare updateMatchTimeout:number;- async connect() {- this.dialog = this.element as HTMLDialogElement;- const context = await window.OpenProject.getPluginContext();- this.turboRequests = context.services.turboRequests;+ private pluginContextData:OpenProjectPluginContext|null = null;+ connect() {+ this.dialog = this.element as HTMLDialogElement;this.regexpInputTarget.addEventListener('input', () => { this.updateMatchPreview(); });this.groupNamesInputTarget.addEventListener('input', () => { this.updateMatchPreview(); });}@@ -71,31 +72,47 @@ export default class MatchPreviewDialogController extends Controller {}submitDialog() {- const event:MatchPreviewDialogSubmittedEvent = { detail: {- regularExpressions: this.regexpInputTarget.value,- previewGroups: this.groupNamesInputTarget.value,- }};+ const event:MatchPreviewDialogSubmittedEvent = {+ detail: {+ regularExpressions: this.regexpInputTarget.value,+ previewGroups: this.groupNamesInputTarget.value,+ },+ };this.dispatch('submitted', event);this.dialog.close();}- updateMatchPreview() {+ private updateMatchPreview() {if(this.updateMatchTimeout) clearTimeout(this.updateMatchTimeout);this.updateMatchTimeout = setTimeout(() => { this.doUpdateMatchPreview(); }, 500);}- doUpdateMatchPreview() {- void this.turboRequests.request(this.updateUrlValue, {- method: 'POST',- headers: {- Accept: 'text/vnd.turbo-stream.html',- 'Content-Type': 'application/json',- },- body: JSON.stringify({- preview_group_names: this.groupNamesInputTarget.value,- preview_regular_expressions: this.regexpInputTarget.value- }),+ private doUpdateMatchPreview() {+ this.pluginContext.subscribe((context) => {+ void context.services.turboRequests.request(this.updateUrlValue, {+ method: 'POST',+ headers: {+ Accept: 'text/vnd.turbo-stream.html',+ 'Content-Type': 'application/json',+ },+ body: JSON.stringify({+ preview_group_names: this.groupNamesInputTarget.value,+ preview_regular_expressions: this.regexpInputTarget.value,+ }),+ });});}++ private get pluginContext():Observable<OpenProjectPluginContext> {+ if (this.pluginContextData === null) {+ return from(window.OpenProject.getPluginContext()).pipe(+ tap((context) => {+ this.pluginContextData = context;+ }),+ );+ }++ return of(this.pluginContextData);+ }}diff --git a/modules/openid_connect/app/components/openid_connect/groups/match_preview_component.html.erb b/modules/openid_connect/app/components/openid_connect/groups/match_preview_component.html.erbindex fa04ac9e04a..8e637e74080 100644--- a/modules/openid_connect/app/components/openid_connect/groups/match_preview_component.html.erb+++ b/modules/openid_connect/app/components/openid_connect/groups/match_preview_component.html.erb@@ -28,18 +28,16 @@ See COPYRIGHT and LICENSE files for more details.++#%><%= component_wrapper(tag: "turbo-frame") do %>- <% # TODO: Replace Primer::Box below with an InsetBox, once that component is ready to be used %>+ <%# TODO: Replace Primer::Box below with an InsetBox, once that component is ready to be used %><%= render(Primer::Box.new(border: true, border_radius: 2, bg: :inset, p: 3)) do %>- <%= render(Primer::Beta::Text.new(font_weight: :bold)) { t(".title") } %>+ <%= render(Primer::Beta::Text.new(tag: :p, font_weight: :bold, mb: 2)) { t(".title") } %><% if model.any? %>- <ul>- <% model.each do |match| %>- <%= render(Primer::Beta::Text.new(tag: :li, font_family: :mono)) { match } %>- <% end %>- </ul>+ <% model.each do |match| %>+ <%= render(Primer::Beta::Text.new(tag: :div, font_family: :mono)) { match } %>+ <% end %><% else %>- <%= render(Primer::Beta::Text.new(tag: :i, display: :block)) { t(".placeholder_none") } %>+ <%= render(Primer::Beta::Text.new(tag: :div, color: :muted)) { t(".placeholder_none") } %><% end %><% end %><% end %>diff --git a/modules/openid_connect/app/components/openid_connect/providers/group_mapping_form.rb b/modules/openid_connect/app/components/openid_connect/providers/group_mapping_form.rbindex 420e1a7f1bd..f316961ff20 100644--- a/modules/openid_connect/app/components/openid_connect/providers/group_mapping_form.rb+++ b/modules/openid_connect/app/components/openid_connect/providers/group_mapping_form.rb@@ -73,6 +73,7 @@ module OpenIDConnectgroup.text_area(name: :group_regexes,rows: 5,+ validation_message: custom_validation_message_for(:group_regexes),label: OpenIDConnect::Provider.human_attribute_name(:group_regexes),caption: link_translate("openid_connect.instructions.group_regexes",links: { docs_url: %i[sysadmin_docs oidc_groups] },@@ -85,8 +86,26 @@ module OpenIDConnectinput_width: :large,value: model.group_regexes.join("\n"))++ group.html_content do+ render(+ ::OpPrimer::FlashComponent.new(icon: :info, dismiss_scheme: :none, unique_key: "test_regex_patterns")+ ) do |banner|+ banner.with_action_content { render(OpenIDConnect::Groups::MatchPreviewDialogComponent.new) }++ I18n.t("openid_connect.instructions.group_regexes_testing")+ end+ endendend++ private++ def custom_validation_message_for(attribute)+ return unless model.errors.has_key?(attribute)++ model.errors[attribute].to_sentence+ endendendenddiff --git a/modules/openid_connect/config/locales/en.yml b/modules/openid_connect/config/locales/en.ymlindex 70a42800ee2..0c6b90c4b7d 100644--- a/modules/openid_connect/config/locales/en.yml+++ b/modules/openid_connect/config/locales/en.yml@@ -65,7 +65,7 @@ en:groups:match_preview_component:title: Extracted group names- placeholder_none: None+ placeholder_none: No groups currently match the pattern.match_preview_dialog_component:description: This allows you to test your regular expression pattern against sample data to verify that the group names you want extracted are indeed extracted properly. You can modify your pattern here but the test string and matches themselves will not be saved with the configuration.group_names_label: Test group names@@ -77,6 +77,7 @@ en:endpoint_url: The endpoint URL given to you by the OpenID Connect providergroup_regexes: One regular expression pattern per line. Please read [the documentation](docs_url) for more information on how to do this.group_regexes_detail: Optionally define patterns using regular expressions to match group names from the groups claim. For example, entering a pattern like <code>^Level1/Level2/([\w/]+)$</code> will extract the group “Groupname/SubGroup” from a response including “Level1/Level2/GroupName/SubGroup”. If no pattern matches, the group is ignored. Leave empty to synchronize all groups using their full group name.+ group_regexes_testing: "Click on 'Test pattern' to test your regular expression pattern against sample OIDC userinfo."group_sync: Automatically extract and synchronise group membership information from the identity provider.groups_claim: Specify the name of the claim that's expected to indicate the group names that the user is a member of.metadata_none: I don't have this information