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
Ensure a user is selected when trying to Share
Aaron Contreras823d807d970d
diff --git a/app/components/work_packages/share/invite_user_form_component.html.erb b/app/components/work_packages/share/invite_user_form_component.html.erbindex 0b8653bd243..fadfa70da4a 100644--- a/app/components/work_packages/share/invite_user_form_component.html.erb+++ b/app/components/work_packages/share/invite_user_form_component.html.erb@@ -1,35 +1,39 @@<%=- component_wrapper(data: { controller: "user-limit",- 'user-limit-open-seats-value': OpenProject::Enterprise.open_seats_count,- 'application-target': "dynamic" }) do+ component_wrapper doif sharing_manageable?primer_form_with(model: new_share,- url: work_package_shares_path(@work_package)+ url: work_package_shares_path(@work_package),+ data: { controller: 'user-limit ' \+ 'work-packages--share--user-selected',+ 'application-target': 'dynamic',+ 'user-limit-open-seats-value': OpenProject::Enterprise.open_seats_count,+ action: 'submit->work-packages--share--user-selected#ensureUsersSelected' }) do |form|grid_layout('invite-user-form',- tag: :div,- data: { 'user-limit-target': 'inviteUserForm' }) do |invite_form|+ tag: :div) do |invite_form|invite_form.with_area('invitee') dorender(WorkPackages::Share::Invitee.new(form))endinvite_form.with_area('permission') do- render(WorkPackages::Share::PermissionButtonComponent.new(share: new_share,- form_arguments: { builder: form, name: "role_id" },- data: { 'test-selector': 'op-share-wp-invite-role' }))+ render(WorkPackages::Share::PermissionButtonComponent.new(+ share: new_share,+ form_arguments: { builder: form, name: "role_id" },+ data: { 'test-selector': 'op-share-wp-invite-role' })+ )endinvite_form.with_area('submit') do- render(Primer::Beta::Button.new(scheme: :primary, type: :submit)) { I18n.t('work_package.sharing.share') }+ render(Primer::Beta::Button.new(scheme: :primary, type: :submit)) do+ I18n.t('work_package.sharing.share')+ endendif OpenProject::Enterprise.user_limit.present?- invite_form.with_area('userLimit',- data: {- 'user-limit-target': 'limitWarning',- 'test-selector': 'op-share-wp-user-limit'- },+ invite_form.with_area('userLimitWarning',+ data: { 'user-limit-target': 'limitWarning',+ 'test-selector': 'op-share-wp-user-limit' },display: :none) doflex_layout do |user_limit_row|user_limit_row.with_column(mr: 2) do@@ -37,8 +41,29 @@enduser_limit_row.with_column do- render(Primer::Beta::Text.new(color: :danger)) { I18n.t("work_package.sharing.warning_user_limit_reached#{'_admin' if User.current.admin?}",- upgrade_url: OpenProject::Enterprise.upgrade_url).html_safe }+ render(Primer::Beta::Text.new(color: :danger)) do+ I18n.t(+ "work_package.sharing.warning_user_limit_reached#{'_admin' if User.current.admin?}",+ upgrade_url: OpenProject::Enterprise.upgrade_url+ ).html_safe+ end+ end+ end+ end+ end++ invite_form.with_area('userSelectedWarning',+ data: { 'work-packages--share--user-selected-target': 'error',+ 'test-selector': 'op-share-wp-no-user-selected' },+ display: :none) do+ flex_layout do |no_selected_user_row|+ no_selected_user_row.with_column(mr: 2) do+ render(Primer::Beta::Octicon.new(icon: :'alert-fill', color: :danger))+ end++ no_selected_user_row.with_column do+ render(Primer::Beta::Text.new(color: :danger)) do+ I18n.t("work_package.sharing.warning_no_selected_user")endendenddiff --git a/app/components/work_packages/share/invite_user_form_component.sass b/app/components/work_packages/share/invite_user_form_component.sassindex 94c844d8f7a..c57deceab1d 100644--- a/app/components/work_packages/share/invite_user_form_component.sass+++ b/app/components/work_packages/share/invite_user_form_component.sass@@ -1,5 +1,13 @@.invite-user-formdisplay: gridgrid-template-columns: 1fr auto auto- grid-template-areas: "invitee permission submit" "userLimit userLimit userLimit"+ grid-template-areas: "invitee permission submit" "userLimitWarning userLimitWarning userLimitWarning" "userSelectedWarning userSelectedWarning userSelectedWarning"+ //+ // There's no multiline tokens support in SASS due to the indentation parsing engine.+ // For a quick grok of the template areas structure above, here's a diagram:+ //+ // invitee permission submit+ // userLimitWarning userLimitWarning userLimitWarning+ // userSelectedWarning userSelectedWarning userSelectedWarning+ //grid-column-gap: 0.5remdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 413d4ec4502..d5ab141cfa6 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3282,6 +3282,7 @@ en:Adding additional users will exceed the current limit. Please contact an administrator to increase the user limit to ensure external users are able to access this work package.warning_user_limit_reached_admin: >Adding additional users will exceed the current limit. Please <a href="%{upgrade_url}">upgrade your plan</a> to be able to ensure external users are able to access this work package.+ warning_no_selected_user: "Please select users to share this work package with"user_details:locked: "Locked user"invited: "Invite sent. "diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/share/user-selected.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/share/user-selected.controller.tsnew file mode 100644index 00000000000..0600b901c2f--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/share/user-selected.controller.ts@@ -0,0 +1,84 @@+/*+ * -- copyright+ * OpenProject is an open source project management software.+ * Copyright (C) 2023 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 { Controller } from '@hotwired/stimulus';+import {+ IUserAutocompleteItem,+} from 'core-app/shared/components/autocompleter/user-autocompleter/user-autocompleter.component';++export default class UserSelectedController extends Controller {+ static targets = [+ 'shareButton',+ 'error',+ ];++ declare readonly errorTarget:HTMLElement;++ private selectedValues:IUserAutocompleteItem[] = [];++ connect() {+ this.autocompleterElement.addEventListener('change', this.handleValueSelected.bind(this));+ }++ disconnect() {+ this.autocompleterElement.removeEventListener('change', this.handleValueSelected.bind(this));+ }++ ensureUsersSelected(evt:CustomEvent):void {+ if (this.selectedValues.length === 0) {+ evt.preventDefault(); // Don't submit+ this.showError();+ } else {+ this.hideError();+ }+ }++ // Private methods+ handleValueSelected(evt:CustomEvent) {+ this.selectedValues = evt.detail as IUserAutocompleteItem[];++ if (this.selectedValues.length !== 0) {+ this.hideError();+ }+ }++ private showError() {+ this.errorTarget.classList.remove('d-none');+ }++ private hideError() {+ this.errorTarget.classList.add('d-none');+ }++ // Accessors+ private get autocompleterElement():HTMLElement {+ return this.element.querySelector('opce-user-autocompleter') as HTMLElement;+ }+}