-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14160 from opf/implementation/50730-show-warning-…
…if-you-cannot-add-new-users-due-to-user-limit [50730] Show warning if you cannot add new users due to user limit
- Loading branch information
Showing
14 changed files
with
225 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
@import "work_packages/share/modal_body_component" | ||
@import "work_packages/share/invite_user_form_component" |
34 changes: 29 additions & 5 deletions
34
app/components/work_packages/share/invite_user_form_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/components/work_packages/share/invite_user_form_component.sass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3200,8 +3200,9 @@ en: | |
The activation email has expired. We sent you a new one to %{email}. | ||
Please click the link inside of it to activate your account. | ||
warning_user_limit_reached: > | ||
User limit reached. You cannot activate any more users. | ||
Please <a href="%{upgrade_url}">upgrade your plan</a> or block members to allow for additional users. | ||
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 instance. | ||
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 instance. | ||
warning_user_limit_reached_instructions: > | ||
You reached your user limit (%{current}/%{max} active users). | ||
Please contact [email protected] to upgrade your Enterprise edition plan and add additional users. | ||
|
@@ -3265,6 +3266,12 @@ 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: "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." | ||
text_user_limit_reached_admins: 'Adding additional users will exceed the current limit. Please <a href="%{upgrade_url}">upgrade your plan</a> to be able to add more users.' | ||
warning_user_limit_reached: > | ||
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. | ||
working_days: | ||
info: > | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
frontend/src/stimulus/controllers/dynamic/user-limit.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* -- 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', | ||
]; | ||
|
||
static values = { | ||
openSeats: Number, | ||
// Special case, that the autocompleter is a members-autocompleter, instead of the normal user-autocompleter | ||
memberAutocompleter: Boolean, | ||
}; | ||
|
||
declare readonly limitWarningTarget:HTMLElement; | ||
declare readonly hasLimitWarningTarget:HTMLElement; | ||
declare readonly inviteUserFormTarget:HTMLElement; | ||
|
||
declare readonly openSeatsValue:number; | ||
declare readonly hasOpenSeatsValue:number; | ||
declare readonly memberAutocompleterValue:boolean; | ||
|
||
private autocompleter:HTMLElement; | ||
private autocompleterListener = this.triggerLimitWarningIfReached.bind(this); | ||
|
||
connect() { | ||
if (this.memberAutocompleterValue) { | ||
this.autocompleter = this.inviteUserFormTarget.querySelector('opce-members-autocompleter') as HTMLElement; | ||
} else { | ||
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 && this.hasOpenSeatsValue) { | ||
const numberOfNewUsers = values.filter(({ id }) => typeof (id) === 'string' && id.includes('@')).length; | ||
if (numberOfNewUsers > 0 && numberOfNewUsers > this.openSeatsValue) { | ||
this.limitWarningTarget.classList.remove('d-none'); | ||
} else { | ||
this.limitWarningTarget.classList.add('d-none'); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,32 @@ | |
members_page.visit! | ||
expect(members_page).to have_user 'finkelstein @openproject.com' | ||
end | ||
|
||
context 'with an instance with a user limit (regression)' do | ||
before do | ||
allow(OpenProject::Enterprise).to receive_messages( | ||
user_limit: 10, | ||
open_seats_count: 1 | ||
) | ||
end | ||
|
||
it 'shows a warning when the limit is reached' do | ||
members_page.visit! | ||
click_button 'Add member' | ||
|
||
members_page.search_and_select_principal! '[email protected]', | ||
'Send invite to [email protected]' | ||
|
||
expect(members_page).not_to have_text sanitize_string(I18n.t(:warning_user_limit_reached)), | ||
normalize_ws: true | ||
|
||
members_page.search_and_select_principal! '[email protected]', | ||
'Send invite to [email protected]' | ||
|
||
expect(members_page).to have_text sanitize_string(I18n.t(:warning_user_limit_reached)), | ||
normalize_ws: true | ||
end | ||
end | ||
end | ||
|
||
context 'with a registered user' do | ||
|
Oops, something went wrong.