Skip to content

Commit

Permalink
Remove current user from list
Browse files Browse the repository at this point in the history
Display "no user" label in case there is no one to select
DIsplay "you ned admin rihts" on non-admin users
  • Loading branch information
mikecp committed Oct 28, 2023
1 parent b4ccc5e commit 6915cb6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
7 changes: 4 additions & 3 deletions src/Our.Umbraco.Impersonator/wwwroot/lang/da-DK.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<language alias="da" intName="Danish" localName="dansk" lcid="6" culture="da-DK">
<creator>
<name>Søren Kottal</name>
Expand All @@ -15,6 +15,7 @@
<key alias="notSignedIn">Du skal være logget ind i Umbraco for at kunne imitere en anden bruger</key>
<key alias="userNotFound">Den valgte bruger kunne ikke findes</key>
<key alias="invalidUserId">Det valgte bruger ID er ikke gyldigt</key>
<key alias="notAdministrator">Du skal have administratorrettigheder for at kunne imitere en anden bruger</key>
<key alias="notAdministrator">Du skal have brugeradministratorrettigheder for at kunne imitere en anden bruger</key>
<kay alias="noUser">Der er ingen aktive brugere at imiterer.</kay>
</area>
</language>
</language>
7 changes: 4 additions & 3 deletions src/Our.Umbraco.Impersonator/wwwroot/lang/en-US.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<language alias="en_us" intName="English (US)" localName="English (US)" lcid="" culture="en-US">
<creator>
<name>Søren Kottal</name>
Expand All @@ -15,6 +15,7 @@
<key alias="notSignedIn">You need to be signed in to Umbraco, to be able to impersonate another user.</key>
<key alias="userNotFound">The selected user could not be found.</key>
<key alias="invalidUserId">The selected user id is invalid.</key>
<key alias="notAdministrator">You need administrator rights, to be able to impersonate another user.</key>
<key alias="notAdministrator">You need users administrator rights, to be able to impersonate another user.</key>
<key alias="noUser">There are no active users to impersonate.</key>
</area>
</language>
</language>
13 changes: 8 additions & 5 deletions src/Our.Umbraco.Impersonator/wwwroot/user.controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function () {
(function () {
"use strict";

function ImpersonatorUserController(
Expand All @@ -12,7 +12,6 @@
var vm = this;

vm.isImpersonating = false;
vm.isLoading = false;
vm.users = [];
vm.loadingUsers = true;
vm.impersonateUserButtonState = "init";
Expand All @@ -25,19 +24,23 @@
// Get users
usersResource
.getPagedResults({
pageSize: 2147483647,
userStates: ["Active"],
pageSize: 2147483647,
userStates: ["Active"],
})
.then(
function (data) {
vm.users = data.items;
vm.users = data.items.filter(function (u) { return u.id != user.id }); // remove current user from impersonation list
vm.loadingUsers = false;
},
function (error) {
vm.loadingUsers = false;
}
);
}
else {
// No users to load, we're done
vm.loadingUsers = false;
}
});

vm.impersonateUser = function () {
Expand Down
32 changes: 24 additions & 8 deletions src/Our.Umbraco.Impersonator/wwwroot/user.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<div ng-controller="Impersonator.User.Controller as vm">
<umb-box ng-if="vm.isImpersonating && !vm.isLoading">
<div ng-controller="Impersonator.User.Controller as vm">
<umb-box ng-if="vm.isImpersonating && !vm.loadingUsers">
<umb-box-content>
<div class="mb2">
<localize key="impersonator_impersonatingDescription"
>You are impersonating the current user.</localize
>
>You are impersonating the current user.</localize>
</div>
<div class="text-right">
<umb-button
Expand All @@ -13,14 +12,14 @@
label-key="impersonator_endImpersonation"
button-style="primary"
state="vm.endImpersonationButtonState"
></umb-button>
</div>
></umb-button>
</div>
</umb-box-content>
</umb-box>
<umb-box
ng-if="vm.canImpersonateUsers && !vm.isImpersonating && !vm.isLoading"
ng-if="vm.canImpersonateUsers && !vm.isImpersonating && !vm.loadingUsers"
>
<umb-box-content>
<umb-box-content ng-if="vm.users.length > 0">
<div class="flex">
<select
class="umb-dropdown flx-g1 mb0"
Expand All @@ -33,8 +32,25 @@
label-key="impersonator_impersonate"
button-style="primary"
state="vm.impersonateUserButtonState"
disabled="!vm.userToImpersonate"
></umb-button>
</div>
</umb-box-content>
<umb-box-content ng-if="vm.users.length <= 0">
<div class="mb2">
<localize key="impersonator_noUser">
There are no active users to impersonate
</localize>
</div>
</umb-box-content>
</umb-box>
<umb-box ng-if="!vm.canImpersonateUsers && !vm.isImpersonating && !vm.loadingUsers">
<umb-box-content>
<div class="mb2">
<localize key="impersonator_notAdministrator">
You need users administrator rights, to be able to impersonate another user.
</localize>
</div>
</umb-box-content>
</umb-box>
</div>

0 comments on commit 6915cb6

Please sign in to comment.