Ending impersonations via Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2016 01:52 AM
Hi All
I just want to share a little feature I made.
We have enabled the automatic redirect of users without roles to the Service Portal - Redirect to Service Portal after login
This however has a conquence when impersonating an end user - you will not be able to get back to the normal UI to end the impersonation without first logging out of the syste.
This could be quite annoying when performing tests in the system where you need to verify someting in the Service Portal as an end user.
So I have created a new menu item in the header menu, to end any active impersonation. It ends the impersonation and reloads the service portal as "your self".
The feature is added to a modified version of the Stock Header.
Service Script
//Check if we are impersonating a user
if (gs.getImpersonatingUserName() !== gs.getUserName() && gs.getImpersonatingUserName() !== null) {
data.is_impersonating = true;
data.impersonating = gs.getImpersonatingUserName();
}
else
data.is_impersonating = false;
Client Script
$scope.impersonate = function(user_name) {
if (!user_name)
return;
$http.post('/api/now/ui/impersonate/' + user_name, {}).success(function() {
$scope.show_error = false;
window.location = "/sp";
}).error(function(response) {
if (response.error) {
$scope.show_error = true;
$scope.error = response.error;
$log.error("Impersonate failed", response.error);
}
});
}
New line added to the div containing the dropdown menu (code below does not generate the menu shown in my screen shot but is taken from the Stock Header widget)
<ul class="dropdown-menu">
<li><a ng-href="?id=user_profile&sys_id={{::user.sys_id}}">${Profile}</a></li>
<li><a href="{{::portal.logoutUrl}}">${Logout}</a></li>
<!-- Line below is the new line to add -->
<li><a ng-if="data.is_impersonating" ng-click="impersonate(data.impersonating)"><i class="fa fa-reply" style = "margin-right: 5px;"></i>${End Impersonation}</a></li>
</ul>
- Labels:
-
Service Portal
- 8,798 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 04:03 AM
Hi
you have to add the $http service to the function definition in the client script in your header widget. If you have an OOTB header widget you will need to clone it and point to this new header under Service Portal > Portals
function ($rootScope, $scope, snRecordWatcher, spUtil, $location, $uibModal, cabrillo, $timeout,$http,$sce) {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2017 04:56 AM
Hi Lars,
Thanks for the answer. I was distracted to not put it on the function definition.
I am wondering if you have a widget that allows admin to impersonate a user from the SSP. Do you ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2017 05:19 AM
I have tried to reverse-engineer the impersonation function but did not succeed. So I don't have any solution for this in Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2017 10:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2017 12:07 PM
Hi
The function is also available in Istanbul, even though you don't see it in the typeahead in the IDE.
Try impersonating another admin and run it in a background script - you will see that it runs fine
gs.print(gs.getImpersonatingUserName());