diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-04-26 15:29:59 +0300 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2017-04-26 15:29:59 +0300 |
commit | 06308261b00a57b45b9876371cd169f7b8d9e104 (patch) | |
tree | 9966c14d742f34b3f489459dc65ba039a118fa44 /js |
Initial importv1.0.0
Diffstat (limited to 'js')
-rw-r--r-- | js/impersonate.js | 42 | ||||
-rw-r--r-- | js/impersonate_logout.js | 38 |
2 files changed, 80 insertions, 0 deletions
diff --git a/js/impersonate.js b/js/impersonate.js new file mode 100644 index 0000000..a49f5e2 --- /dev/null +++ b/js/impersonate.js @@ -0,0 +1,42 @@ +(function(){ + + $(document).ready(function() { + if(!OC.isUserAdmin()) { + return; + } + + function impersonate(userId) { + $.post( + OC.generateUrl('apps/impersonate/user'), + { userId: userId } + ).done(function() { + window.location = OC.generateUrl('apps/files'); + }).fail(function( result ) { + OC.dialogs.alert(result.responseJSON.message, t('impersonate', 'Could not impersonate user')); + }); + } + var $newColumn = $("#userlist").find("tr:first-child"); + $('<th id="impersonateId" scope="col">'+t('impersonate', 'Impersonate') +'</th>').insertAfter($newColumn.find("#headerName")); + $('<td><a class="action permanent impersonate" href="#" title="' + + t('impersonate', 'Impersonate') + '">' + + '<img class="svg permanent action" src="' + OC.imagePath('core','actions/user.svg') + '" />' + + '</a></td>') + .insertAfter('#userlist .name'); + + $('#userlist').on('click', '.impersonate', function() { + var userId = $(this).parents('tr').find('.name').text(); + OCdialogs.confirm( + t('impersonate', 'Are you sure you want to impersonate "{userId}"?', {userId: userId}), + t('impersonate', 'Impersonate user' ), + function(result) { + if (result) { + impersonate(userId); + } + }, + true + ); + }); + + }); + +})(); diff --git a/js/impersonate_logout.js b/js/impersonate_logout.js new file mode 100644 index 0000000..66d4e8b --- /dev/null +++ b/js/impersonate_logout.js @@ -0,0 +1,38 @@ +$(document).ready(function () { + + $("#logout").attr("href","#"); + + var text = t( + 'core', + '<a href="{docUrl}">{displayText}</a>', + { + docUrl: OC.generateUrl('apps/files'), + displayText: "Logged in as " + OC.getCurrentUser().uid + } + ); + + OC.Notification.showHtml( + text, + { + isHTML: true, + timeout: 15 + } + ); + + function logoutHandler(userId) { + var promisObj = $.post( + OC.generateUrl('apps/impersonate/logout'), + {userId: userId} + ).promise(); + + promisObj.done(function () { + OC.redirect(OC.generateUrl('settings/users')) + }); + } + + $('#settings ul li:last').on('click', function (event) { + event.preventDefault(); + var userId = $("#expandDisplayName").text(); + logoutHandler(userId); + }); +}); |