Skip to content

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

Show a warning if inviting new users would exceed the user limit

Henriette Darge92e1cf894427
diff --git a/app/components/_index.sass b/app/components/_index.sass
index c5e83ef50bf..03df4c8193e 100644
--- a/app/components/_index.sass
+++ b/app/components/_index.sass
@@ -1 +1,2 @@
@import "work_packages/share/modal_body_component"
+@import "work_packages/share/invite_user_form_component"
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.erb
index 2113ff7b1b7..6e3981998d5 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,24 +1,41 @@
<%=
- component_wrapper do
+ component_wrapper(data: { controller: "work-packages--share--user-limit",
+ 'application-target': "dynamic" }) do
if sharing_manageable?
primer_form_with(
model: new_share,
url: work_package_shares_path(@work_package)
) do |form|
- flex_layout do |new_user_row|
- new_user_row.with_column(flex: :auto, mr: 2) do
+ grid_layout('invite-user-form',
+ tag: :div,
+ data: { 'work-packages--share--user-limit-target': 'inviteUserForm' }) do |invite_form|
+ invite_form.with_area('invitee') do
render(WorkPackages::Share::Invitee.new(form))
end
- new_user_row.with_column(mr: 2) do
+ invite_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' }))
end
- new_user_row.with_column do
+ invite_form.with_area('submit') do
render(Primer::Beta::Button.new(scheme: :primary, type: :submit)) { I18n.t('work_package.sharing.share') }
end
+
+ unless OpenProject::Enterprise.user_limit.nil?
+ invite_form.with_area('userLimit', data: { 'work-packages--share--user-limit-target': 'limitWarning' }, display: :none) do
+ flex_layout do |user_limit_row|
+ user_limit_row.with_column(mr: 2) do
+ render(Primer::Beta::Octicon.new(icon: :'alert-fill', color: :danger))
+ end
+
+ user_limit_row.with_column do
+ render(Primer::Beta::Text.new(color: :danger)) { I18n.t('work_package.sharing.text_user_limit_reached', count: OpenProject::Enterprise.open_seats_count) }
+ end
+ end
+ end
+ end
end
end
else
diff --git a/app/components/work_packages/share/invite_user_form_component.sass b/app/components/work_packages/share/invite_user_form_component.sass
new file mode 100644
index 00000000000..94c844d8f7a
--- /dev/null
+++ b/app/components/work_packages/share/invite_user_form_component.sass
@@ -0,0 +1,5 @@
+.invite-user-form
+ display: grid
+ grid-template-columns: 1fr auto auto
+ grid-template-areas: "invitee permission submit" "userLimit userLimit userLimit"
+ grid-column-gap: 0.5rem
diff --git a/app/forms/work_packages/share/invitee.rb b/app/forms/work_packages/share/invitee.rb
index 4a515770042..034b0dc43d3 100644
--- a/app/forms/work_packages/share/invitee.rb
+++ b/app/forms/work_packages/share/invitee.rb
@@ -32,6 +32,7 @@ module WorkPackages::Share
name: :user_id,
label: I18n.t('work_package.sharing.label_search'),
visually_hide_label: true,
+ data: { 'work-packages--share--user-limit-target': 'autocompleter' },
autocomplete_options: {
id: "op-share-wp-invite-autocomplete",
placeholder: I18n.t('work_package.sharing.label_search_placeholder'),
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 3e69e844065..5f5a133c40b 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3265,6 +3265,10 @@ en:
share: "Share"
text_empty_state_description: "The work package has not been shared with anyone yet."
text_empty_state_header: "No shared users"
+ text_user_limit_reached:
+ zero: "This instance has reached its user limit, you can’t share with new users. Please contact your administrator to add more members."
+ one: "Only 1 member left to reach the user limit of the instance. Please contact your administrator."
+ other: "Only %{count} members left to reach the user limit of the instance. Please contact your administrator."
working_days:
info: >
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/share/user-limit.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/share/user-limit.controller.ts
new file mode 100644
index 00000000000..ec5d96fc84e
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/share/user-limit.controller.ts
@@ -0,0 +1,69 @@
+/*
+ * -- 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 UserLimitController extends Controller {
+ static targets = [
+ 'limitWarning',
+ 'inviteUserForm',
+ ];
+
+ declare readonly limitWarningTarget:HTMLElement;
+ declare readonly hasLimitWarningTarget:HTMLElement;
+ declare readonly inviteUserFormTarget:HTMLElement;
+
+ private autocompleter:HTMLElement;
+ private autocompleterListener = this.triggerLimitWarningIfReached.bind(this);
+
+ connect() {
+ this.autocompleter = this.inviteUserFormTarget.querySelector('opce-user-autocompleter') as HTMLElement;
+ this.autocompleter.addEventListener('change', this.autocompleterListener);
+ }
+
+ disconnect() {
+ this.autocompleter.removeEventListener('change', this.autocompleterListener);
+ }
+
+ triggerLimitWarningIfReached(evt:CustomEvent) {
+ const values = evt.detail as IUserAutocompleteItem[];
+
+ if (this.hasLimitWarningTarget) {
+ if (values.find(({ id }) => typeof (id) === 'string' && id.includes('@'))) {
+ this.limitWarningTarget.classList.remove('d-none');
+ } else {
+ this.limitWarningTarget.classList.add('d-none');
+ }
+ }
+ }
+}
diff --git a/lib/open_project/enterprise.rb b/lib/open_project/enterprise.rb
index 3724c4fb1f4..ea42aaa0162 100644
--- a/lib/open_project/enterprise.rb
+++ b/lib/open_project/enterprise.rb
@@ -49,6 +49,10 @@ module OpenProject
User.human.active.count
end
+ def open_seats_count
+ user_limit - active_user_count if user_limit
+ end
+
##
# Indicates if there are more active users than the support token allows for.
#