Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions addon/components/modals/invite-user.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Modal::Default @modalIsOpened={{@modalIsOpened}} @options={{@options}} @confirm={{@onConfirm}} @decline={{@onDecline}}>
<div class="modal-body-container">
<InfoBlock class="mb-4">
{{t "iam.users.invite.description"}}
</InfoBlock>
<div class="grid grid-cols-1">
<InputGroup @name={{t "iam.common.email"}} @type="email" @value={{@options.email}} @placeholder={{t "iam.users.invite.email-placeholder"}} />
<InputGroup @name={{t "iam.common.name"}} @value={{@options.name}} @placeholder={{t "iam.users.invite.name-placeholder"}} @helpText={{t "iam.users.invite.name-help"}} />
<InputGroup @name={{t "iam.common.role"}}>
<ModelSelect
@modelName="role"
@selectedModel={{@options.role}}
@placeholder={{t "iam.common.role"}}
@triggerClass="form-select form-input truncate w-full"
@infiniteScroll={{false}}
@renderInPlace={{true}}
@onChange={{fn (mut @options.role)}}
as |model|
>
{{model.name}}
</ModelSelect>
</InputGroup>
</div>
</div>
</Modal::Default>
10 changes: 10 additions & 0 deletions addon/components/modals/invite-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Component from '@glimmer/component';

/**
* Invite User modal component.
*
* This is a data-driven modal — all state lives in the options hash passed by
* the modalsManager. The component itself needs no tracked properties or
* actions; the confirm callback in UsersIndexController handles the submission.
*/
export default class ModalsInviteUserComponent extends Component {}
67 changes: 65 additions & 2 deletions addon/controllers/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export default class UsersIndexController extends Controller {
onClick: () => this.hostRouter.refresh(),
helpText: this.intl.t('common.refresh'),
},
{
text: this.intl.t('iam.users.index.invite-user'),
type: 'default',
icon: 'paper-plane',
permission: 'iam create user',
onClick: this.inviteUser,
},
{
text: this.intl.t('common.new'),
type: 'primary',
Expand Down Expand Up @@ -288,6 +295,61 @@ export default class UsersIndexController extends Controller {
});
}

/**
* Opens the Invite User dialog.
*
* Sends only an email (and optional name / role) to POST users/invite-user.
* The backend handles both cases transparently:
* - Email already in the system → cross-organisation invite issued.
* - Brand-new email → pending user created and invite email sent.
*
* The response includes `invited: true` when an existing user was invited,
* allowing the frontend to display the appropriate success message.
*
* @void
*/
@action inviteUser() {
this.modalsManager.show('modals/invite-user', {
title: this.intl.t('iam.users.invite.title'),
acceptButtonText: this.intl.t('iam.users.invite.send-invitation'),
acceptButtonIcon: 'paper-plane',
email: '',
name: '',
role: null,
confirm: async (modal) => {
modal.startLoading();

const email = modal.getOption('email');
const name = modal.getOption('name');
const role = modal.getOption('role');

if (!email) {
this.notifications.warning(this.intl.t('iam.users.invite.email-required'));
return modal.stopLoading();
}

try {
const response = await this.fetch.post('users/invite-user', {
user: {
email,
name,
role_uuid: role ? role.id : undefined,
},
});

const wasExistingUser = response && response.invited === true;
this.notifications.success(wasExistingUser ? this.intl.t('iam.users.invite.invitation-sent-existing') : this.intl.t('iam.users.invite.invitation-sent-new'));

modal.done();
return this.hostRouter.refresh();
} catch (error) {
this.notifications.serverError(error);
modal.stopLoading();
}
},
});
}

/**
* Toggles modal to create a new API key
*
Expand Down Expand Up @@ -316,8 +378,9 @@ export default class UsersIndexController extends Controller {

try {
await user.save();
this.notifications.success(this.intl.t('iam.users.index.user-changes-saved-success'));
return this.hostRouter.refresh();
this.notifications.success(this.intl.t('iam.users.index.new-user-created'));
this.hostRouter.refresh();
modal.done();
} catch (error) {
this.notifications.serverError(error);
modal.stopLoading();
Expand Down
1 change: 1 addition & 0 deletions app/components/modals/invite-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/iam-engine/components/modals/invite-user';
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/iam-engine",
"version": "0.1.8",
"version": "0.1.9",
"description": "Fleetbase IAM extension provides identity and access management module for managing users, permissions and policies.",
"fleetbase": {
"route": "iam"
Expand Down Expand Up @@ -42,8 +42,8 @@
},
"dependencies": {
"@babel/core": "^7.23.2",
"@fleetbase/ember-core": "^0.3.17",
"@fleetbase/ember-ui": "^0.3.25",
"@fleetbase/ember-core": "^0.3.18",
"@fleetbase/ember-ui": "^0.3.26",
"@fortawesome/ember-fontawesome": "^2.0.0",
"@fortawesome/fontawesome-svg-core": "6.4.0",
"@fortawesome/free-brands-svg-icons": "6.4.0",
Expand Down
Loading
Loading