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
Convert password-confirm to stimulus
Oliver Günther652732168c68
diff --git a/app/helpers/password_helper.rb b/app/helpers/password_helper.rbindex 8f4419a583c..70003b97eac 100644--- a/app/helpers/password_helper.rb+++ b/app/helpers/password_helper.rb@@ -47,16 +47,18 @@ module PasswordHelper# when the user is internally authenticated.def password_confirmation_form_tag(url_for_options = {}, options = {}, &)if password_confirmation_required?- data = options.fetch(:data, {})- options[:data] = password_confirmation_data_attribute(data)+ options[:data] ||= {}+ options[:data] = password_confirmation_data_attribute(options[:data])endform_tag(url_for_options, options, &)enddef password_confirmation_data_attribute(with_data = {})+ controller = with_data.fetch(:controller, "")+if password_confirmation_required?- with_data.merge("request-for-confirmation": true)+ with_data.merge("controller": "#{controller} password-confirmation-dialog".strip)elsewith_dataenddiff --git a/app/views/users/deletion_info.html.erb b/app/views/users/deletion_info.html.erbindex cbc04f0e94d..08b4f6cabcc 100644--- a/app/views/users/deletion_info.html.erb+++ b/app/views/users/deletion_info.html.erb@@ -36,7 +36,7 @@ See COPYRIGHT and LICENSE files for more details.:user,url: user_path(@user),html: {- method: :delete, class: 'confirm_required request-for-confirmation form danger-zone',+ method: :delete, class: 'confirm_required form danger-zone',data: password_confirmation_data_attribute}) do %><div class='wiki'>diff --git a/frontend/src/app/core/setup/globals/global-listeners/request-for-confirmation.ts b/frontend/src/app/core/setup/globals/global-listeners/request-for-confirmation.tsdeleted file mode 100644index 44c4a8d3624..00000000000--- a/frontend/src/app/core/setup/globals/global-listeners/request-for-confirmation.ts+++ /dev/null@@ -1,87 +0,0 @@-//-- copyright-// OpenProject is an open source project management software.-// Copyright (C) the OpenProject GmbH-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License version 3.-//-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-// Copyright (C) 2006-2013 Jean-Philippe Lang-// Copyright (C) 2010-2013 the ChiliProject Team-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License-// as published by the Free Software Foundation; either version 2-// of the License, or (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-//-// See COPYRIGHT and LICENSE files for more details.-//++--import { OpModalService } from 'core-app/shared/components/modal/modal.service';-import { PasswordConfirmationModalComponent } from 'core-app/shared/components/modals/request-for-confirmation/password-confirmation.modal';--function registerListener(- form:JQuery,- $event:JQuery.TriggeredEvent,- opModalService:OpModalService,- passwordModal:typeof PasswordConfirmationModalComponent,-) {- const passwordConfirm = form.find('_password_confirmation');-- if (passwordConfirm.length > 0) {- return true;- }-- $event.preventDefault();- opModalService.show(passwordModal, 'global')- .subscribe((modal) => modal.closingEvent.subscribe(() => {- if (!modal.confirmed) {- return;- }-- jQuery('<input>')- .attr({- type: 'hidden',- name: '_password_confirmation',- value: modal.password_confirmation,- })- .appendTo(form);-- form.trigger('submit');- }));-- return false;-}--export function registerRequestForConfirmation($:JQueryStatic) {- window.OpenProject- .getPluginContext()- .then((context) => {- const { opModalService } = context.services;- const passwordConfirmationModal = context.classes.modals.passwordConfirmation;-- $(document).on(- 'submit',- 'form[data-request-for-confirmation]',- function (this:any, $event:JQuery.TriggeredEvent) {- const form = jQuery(this);-- if (form.find('input[name="_password_confirmation"]').length) {- return true;- }-- return registerListener(form, $event, opModalService, passwordConfirmationModal);- },- );- })- .catch(() => {});-}diff --git a/frontend/src/app/features/plugins/plugin-context.ts b/frontend/src/app/features/plugins/plugin-context.tsindex 56550723912..801fca75cab 100644--- a/frontend/src/app/features/plugins/plugin-context.ts+++ b/frontend/src/app/features/plugins/plugin-context.ts@@ -25,15 +25,13 @@ import { HookService } from 'core-app/features/plugins/hook-service';import { PathHelperService } from '../../core/path-helper/path-helper.service';import { HTMLSanitizeService } from '../../core/html-sanitize/html-sanitize.service';import { DynamicContentModalComponent } from '../../shared/components/modals/modal-wrapper/dynamic-content.modal';-import {- PasswordConfirmationModalComponent,-} from '../../shared/components/modals/request-for-confirmation/password-confirmation.modal';import { DomAutoscrollService } from 'core-app/shared/helpers/drag-and-drop/dom-autoscroll.service';import { AttachmentsResourceService } from 'core-app/core/state/attachments/attachments.service';import { HttpClient } from '@angular/common/http';import { TimezoneService } from 'core-app/core/datetime/timezone.service';import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';import { IanCenterService } from 'core-app/features/in-app-notifications/center/state/ian-center.service';+/*** Plugin context bridge for plugins outside the CLI compiler context* in order to access services and parts of the core application@@ -79,7 +77,6 @@ export class OpenProjectPluginContext {// Random collection of classes needed outside of angularpublic readonly classes = {modals: {- passwordConfirmation: PasswordConfirmationModalComponent,dynamicContent: DynamicContentModalComponent,},HalResource,diff --git a/frontend/src/app/shared/components/modal/modal-overlay.component.ts b/frontend/src/app/shared/components/modal/modal-overlay.component.tsindex 009806f6626..7e4d8d422bd 100644--- a/frontend/src/app/shared/components/modal/modal-overlay.component.ts+++ b/frontend/src/app/shared/components/modal/modal-overlay.component.ts@@ -42,6 +42,7 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';import { ModalData, OpModalService } from 'core-app/shared/components/modal/modal.service';import { PortalOutletTarget } from 'core-app/shared/components/modal/portal-outlet-target.enum';+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';@Component({@@ -49,7 +50,7 @@ import { PortalOutletTarget } from 'core-app/shared/components/modal/portal-outltemplateUrl: './modal-overlay.component.html',changeDetection: ChangeDetectionStrategy.OnPush,})-export class OpModalOverlayComponent {+export class OpModalOverlayComponent extends UntilDestroyedMixin {public notFullscreen = false;mobileTopPosition = false;@@ -76,6 +77,7 @@ export class OpModalOverlayComponent {readonly I18n:I18nService,readonly cdRef:ChangeDetectorRef,) {+ super();}setupListener():void {@@ -84,6 +86,7 @@ export class OpModalOverlayComponent {// multiple 'closing' events in a row are squashedthis.activeModalData$.pipe(distinctUntilChanged(), filter(this.isDefaultTarget.bind(this))),])+ .pipe(this.untilDestroyed()).subscribe(([instance, data]) => {if (instance === null && data === null) {// do nothingdiff --git a/frontend/src/stimulus/controllers/password-confirmation-dialog.controller.ts b/frontend/src/stimulus/controllers/password-confirmation-dialog.controller.tsnew file mode 100644index 00000000000..c5c3b71334b--- /dev/null+++ b/frontend/src/stimulus/controllers/password-confirmation-dialog.controller.ts@@ -0,0 +1,92 @@+/*+ * -- copyright+ * OpenProject is an open source project management software.+ * Copyright (C) the OpenProject GmbH+ *+ * This program is free software; you can redistribute it and/or+ * modify it under the terms of the GNU General Public License version 3.+ *+ * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+ * Copyright (C) 2006-2013 Jean-Philippe Lang+ * Copyright (C) 2010-2013 the ChiliProject Team+ *+ * This program is free software; you can redistribute it and/or+ * modify it under the terms of the GNU General Public License+ * as published by the Free Software Foundation; either version 2+ * of the License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program; if not, write to the Free Software+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+ *+ * See COPYRIGHT and LICENSE files for more details.+ * +++ */++import { ApplicationController } from 'stimulus-use';+import {+ PasswordConfirmationModalComponent,+} from 'core-app/shared/components/modals/request-for-confirmation/password-confirmation.modal';++export default class PasswordConfirmationDialogController extends ApplicationController {+ private formListener = this.onFormSubmit.bind(this);++ private activeDialog = false;++ connect() {+ super.connect();++ this.element.addEventListener('submit', this.formListener);+ }++ disconnect() {+ super.disconnect();++ this.element.removeEventListener('submit', this.formListener);+ }++ private async onFormSubmit(event:SubmitEvent) {+ const form = this.element as HTMLFormElement;+ const passwordConfirm = this.element.querySelector('#hidden_password_confirmation');++ if (passwordConfirm !== null) {+ return true;+ }++ event.preventDefault();+ const pluginContext = await window.OpenProject.getPluginContext();+ const opModalService = pluginContext.services.opModalService;++ // If already opened, do not open another dialog+ if (this.activeDialog) {+ return false;+ }++ this.activeDialog = true;+ opModalService+ .show(PasswordConfirmationModalComponent, 'global')+ .subscribe((modal) => modal.closingEvent.subscribe(() => {+ this.activeDialog = false;++ if (!modal.confirmed) {+ return;+ }++ const input = document.createElement('input');+ input.type = 'hidden';+ input.id = 'hidden_password_confirmation';+ input.name = '_password_confirmation';+ input.value = modal.password_confirmation as string;++ form.append(input);+ form.requestSubmit(event?.submitter);+ }));++ return false;+ }+}diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.tsindex 2d170cc8c6b..b1b052b5e8c 100644--- a/frontend/src/stimulus/setup.ts+++ b/frontend/src/stimulus/setup.ts@@ -12,6 +12,7 @@ import OpShowWhenCheckedController from './controllers/show-when-checked.controlimport OpShowWhenValueSelectedController from './controllers/show-when-value-selected.controller';import FlashController from './controllers/flash.controller';import OpProjectsZenModeController from './controllers/dynamic/projects/zen-mode.controller';+import PasswordConfirmationDialogController from './controllers/password-confirmation-dialog.controller';declare global {interface Window {@@ -28,15 +29,15 @@ instance.handleError = (error, message, detail) => {};instance.register('application', OpApplicationController);-instance.register('menus--main', MainMenuController);--instance.register('show-when-checked', OpShowWhenCheckedController);+instance.register('async-dialog', AsyncDialogController);instance.register('disable-when-checked', OpDisableWhenCheckedController);-instance.register('show-when-value-selected', OpShowWhenValueSelectedController);instance.register('flash', FlashController);+instance.register('menus--main', MainMenuController);+instance.register('password-confirmation-dialog', PasswordConfirmationDialogController);+instance.register('poll-for-changes', PollForChangesController);instance.register('print', PrintController);instance.register('refresh-on-form-changes', RefreshOnFormChangesController);-instance.register('async-dialog', AsyncDialogController);-instance.register('poll-for-changes', PollForChangesController);+instance.register('show-when-checked', OpShowWhenCheckedController);+instance.register('show-when-value-selected', OpShowWhenValueSelectedController);instance.register('table-highlighting', TableHighlightingController);instance.register('projects-zen-mode', OpProjectsZenModeController);diff --git a/frontend/src/turbo/turbo-global-listeners.ts b/frontend/src/turbo/turbo-global-listeners.tsindex eaae07ebb2c..f6565353959 100644--- a/frontend/src/turbo/turbo-global-listeners.ts+++ b/frontend/src/turbo/turbo-global-listeners.ts@@ -1,4 +1,3 @@-import { registerRequestForConfirmation } from 'core-app/core/setup/globals/global-listeners/request-for-confirmation';import { DeviceService } from 'core-app/core/browser/device.service';import { scrollHeaderOnMobile } from 'core-app/core/setup/globals/global-listeners/top-menu-scroll';import { detectOnboardingTour } from 'core-app/core/setup/globals/onboarding/onboarding_tour_trigger';@@ -25,10 +24,6 @@ export function addTurboGlobalListeners() {}}- // Allow forms with [request-for-confirmation]- // to show the password confirmation dialog- registerRequestForConfirmation(jQuery);-const deviceService:DeviceService = new DeviceService();// Register scroll handler on mobile headerif (deviceService.isMobile) {