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
14 changes: 10 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ steps:
commands:
- wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh
- bash ./before_install.sh $APP_NAME $CORE_BRANCH $DATABASEHOST
- cd ../server
- cd ../server/apps/$APP_NAME
- composer install
- ./lib/composer/bin/parallel-lint apps/$APP_NAME/
- ./vendor/bin/parallel-lint --exclude ./vendor/ .
- name: syntax-php7.4
image: nextcloudci/php7.4:2
environment:
Expand All @@ -23,9 +23,9 @@ steps:
commands:
- wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh
- bash ./before_install.sh $APP_NAME $CORE_BRANCH $DATABASEHOST
- cd ../server
- cd ../server/apps/$APP_NAME
- composer install
- ./lib/composer/bin/parallel-lint apps/$APP_NAME/
- ./vendor/bin/parallel-lint --exclude ./vendor/ .
- name: app-code-check
image: nextcloudci/php7.3:php7.3-5
environment:
Expand All @@ -47,6 +47,8 @@ trigger:
- pull_request
- push

type: docker

---
kind: pipeline
name: unit-sqlite-php7.2
Expand Down Expand Up @@ -77,6 +79,8 @@ trigger:
- pull_request
- push

type: docker

---
kind: pipeline
name: unit-sqlite-php7.3
Expand Down Expand Up @@ -107,6 +111,8 @@ trigger:
- pull_request
- push

type: docker

---
kind: pipeline
name: unit-sqlite-php7.4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build
/vendor/
33 changes: 0 additions & 33 deletions appinfo/app.php

This file was deleted.

5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2"
}
}
25 changes: 16 additions & 9 deletions js/admin_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
*
*/

$(document).ready(function() {
var $authorized = $('#impersonate .authorized');
/* global OC, OCA */
(function(OC, OCA) {
OCA.Impersonate = {
initSettings: function() {
var $authorized = $('#impersonate .authorized')

OC.Settings.setupGroupsSelect($authorized);
$authorized.change(function(event) {
var groups = event.val || ['admin'];
groups = JSON.stringify(groups);
OCP.AppConfig.setValue('impersonate', 'authorized', groups);
});
});
OC.Settings.setupGroupsSelect($authorized)
$authorized.change(function(event) {
var groups = event.val || ['admin']
groups = JSON.stringify(groups)
OCP.AppConfig.setValue('impersonate', 'authorized', groups)
})
}
}

document.addEventListener('DOMContentLoaded', OCA.Impersonate.initSettings)
})(OC, OCA)
90 changes: 47 additions & 43 deletions js/impersonate.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,52 @@
/* global OC, $ */
(function(OC, $){

$(document).ready(function() {
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'));
});
}

function impersonateDialog(event) {
let userId = event.target.closest('.row').dataset.id;
OC.dialogs.confirm(
t('impersonate', 'Are you sure you want to impersonate "{userId}"?', {userId: userId}),
t('impersonate', 'Impersonate user' ),
function(result) {
if (result) {
impersonate(userId);
}
},
true
);
/* global OC */
(function(OC) {
function impersonate(userId) {
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function(data) {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 0 || (xhr.status >= 200 && xhr.status < 300)) {
window.location = OC.generateUrl('/')
} else {
OC.dialogs.alert(JSON.parse(xhr.response).message, t('impersonate', 'Could not impersonate user'), undefined, undefined)
}
}
}
xhr.open('POST', OC.generateUrl('apps/impersonate/user'))
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
xhr.send('userId=' + encodeURIComponent(userId) + '&requesttoken=' + encodeURIComponent(OC.requestToken))
}

let registerFunction = function (delay) {
if(OCA.Settings === undefined) {
delay = delay * 2;
if(delay === 0) {
delay = 15;
function impersonateDialog(event) {
var userId = event.target.closest('.row').dataset.id
OC.dialogs.confirm(
t('impersonate', 'Are you sure you want to impersonate "{userId}"?', { userId: userId }),
t('impersonate', 'Impersonate user'),
function(result) {
if (result) {
impersonate(userId)
}
if(delay > 500) {
console.warn("Could not register impersonate script");
return;
}
setTimeout(function() {registerFunction(delay)}, delay);
} else {
OCA.Settings.UserList.registerAction('icon-user', t('impersonate', 'Impersonate'), impersonateDialog)
},
true
)
}

var registerFunction = function(delay) {
delay = delay || 0
if (OCA.Settings === undefined) {
delay = delay * 2
if (delay === 0) {
delay = 15
}
if (delay > 500) {
console.error('Could not register impersonate script')
return
}
};
registerFunction(0);
});
setTimeout(function() { registerFunction(delay) }, delay)
} else {
OCA.Settings.UserList.registerAction('icon-user', t('impersonate', 'Impersonate'), impersonateDialog)
}
}

document.addEventListener('DOMContentLoaded', registerFunction)

})(OC, $);
})(OC)
14 changes: 7 additions & 7 deletions js/impersonate_logout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$(document).ready(function () {
document.addEventListener('DOMContentLoaded', function() {

$("#logout").attr("href","#");

Expand All @@ -18,16 +18,16 @@ $(document).ready(function () {
var promisObj = $.post(
OC.generateUrl('apps/impersonate/logout'),
{userId: userId}
).promise();
).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);
});
});
event.preventDefault()
var userId = $("#expandDisplayName").text()
logoutHandler(userId)
})
})
55 changes: 55 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Arthur Schiwon <[email protected]>
*
* @author Arthur Schiwon <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Impersonate\AppInfo;

use OCA\Impersonate\Listener\BeforeTemplateRenderedListener;
use OCA\Settings\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\ISession;
use OCP\Util;

class Application extends App implements IBootstrap {
public const APP_ID = 'impersonate';

public function __construct() {
parent::__construct(self::APP_ID);
}

public function register(IRegistrationContext $context): void {
$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
}

public function boot(IBootContext $context): void {
$session = $context->getServerContainer()->get(ISession::class);

if($session->get('oldUserId') !== null) {
Util::addScript(self::APP_ID,'impersonate_logout');
}
}
}
67 changes: 67 additions & 0 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Arthur Schiwon <[email protected]>
*
* @author Arthur Schiwon <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Impersonate\Listener;

use OCA\Impersonate\AppInfo\Application;
use OCA\Settings\Events\BeforeTemplateRenderedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUserSession;
use OCP\Util;

class BeforeTemplateRenderedListener implements IEventListener {

/** @var IConfig */
private $config;
/** @var IGroupManager */
private $groupManager;
/** @var IUserSession */
private $userSession;

public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) {
$this->config = $config;
$this->groupManager = $groupManager;
$this->userSession = $userSession;
}

public function handle(Event $event): void {
if (!$event instanceof BeforeTemplateRenderedEvent) {
return;
}

$authorized = json_decode($this->config->getAppValue(Application::APP_ID, 'authorized', '["admin"]'));

if (!empty($authorized)) {
$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
if (!array_intersect($userGroups, $authorized)) {
return;
}
}
Util::addScript(Application::APP_ID, 'impersonate');
}
}