Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/impersonate.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2017-04-26 15:29:59 +0300
committerLukas Reschke <lukas@statuscode.ch>2017-04-26 15:29:59 +0300
commit06308261b00a57b45b9876371cd169f7b8d9e104 (patch)
tree9966c14d742f34b3f489459dc65ba039a118fa44 /js
Initial importv1.0.0
Diffstat (limited to 'js')
-rw-r--r--js/impersonate.js42
-rw-r--r--js/impersonate_logout.js38
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);
+ });
+});