-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvise impersonate app with changes
Below are the changes implemented: 1) Support of groups which can be impersonated. 2) Support of logout which switches back to orignal user. 3) Support to display the user logged as information as notification. 4) Removed the confirmation dialog to impersonate. Signed-off-by: Sujith H <sharidasan@owncloud.com>
- Loading branch information
Showing
11 changed files
with
211 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace OCA\Impersonate\Controller; | ||
|
||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\ILogger; | ||
use OCP\IRequest; | ||
use OCP\AppFramework\Controller; | ||
use OCP\IUser; | ||
use OCP\IUserManager; | ||
use OCP\IUserSession; | ||
|
||
|
||
class LogoutController extends Controller { | ||
/** @var IUserManager */ | ||
private $userManager; | ||
/** @var IUserSession */ | ||
private $userSession; | ||
/** @var ILogger */ | ||
private $logger; | ||
|
||
/** | ||
* @NoAdminRequired | ||
* | ||
* @param string $appName | ||
* @param IRequest $request | ||
* @param IUserManager $userManager | ||
* @param IUserSession $userSession | ||
* @param ILogger $logger | ||
*/ | ||
|
||
public function __construct($appName, IRequest $request, IUserManager $userManager, IUserSession $userSession, ILogger $logger) { | ||
parent::__construct($appName, $request); | ||
$this->userManager = $userManager; | ||
$this->userSession = $userSession; | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* | ||
* @param string userid | ||
* @UseSession | ||
* @return JSONResponse | ||
*/ | ||
public function logoutcontroller($userid) { | ||
$user = \OC::$server->getSession()->get('oldUserId'); | ||
$user = $this->userManager->get($user); | ||
|
||
if($user === null) { | ||
return new JSONResponse("No user found for $user", Http::STATUS_NOT_FOUND); | ||
} else { | ||
$this->userSession->setUser($user); | ||
$this->logger->info("Going to switch to a different user $userid", ['app' => 'impersonate']); | ||
//Swap old and new user id's for next logout. | ||
$newUserId = \OC::$server->getSession()->get('newUserId'); | ||
$oldUserId = \OC::$server->getSession()->get('oldUserId'); | ||
\OC::$server->getSession()->set('newUserId',$oldUserId); | ||
\OC::$server->getSession()->set('oldUserId',$newUserId); | ||
} | ||
return new JSONResponse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
$(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, | ||
} | ||
); | ||
|
||
var timeout = 15; | ||
OC.Notification.showHtml( | ||
text, | ||
{ | ||
isHTML: true, timeout | ||
} | ||
); | ||
|
||
function logoutHandler(userid) { | ||
var promisObj = $.post( | ||
OC.generateUrl('apps/impersonate/logout'), | ||
{userid: userid} | ||
).promise(); | ||
|
||
promisObj.done(function () { | ||
OC.redirect('apps/files'); | ||
}); | ||
} | ||
|
||
$("#logout").on('click', function () { | ||
var userid = $("#expandDisplayName").text(); | ||
logoutHandler(userid); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
$(document).ready(function () { | ||
$("#impersonateIncludeGroups").change(function () { | ||
$("#selectIncludedGroups").toggleClass('hidden', !this.checked); | ||
var val = $("#impersonateIncludeGroups").is(":checked"); | ||
OC.AppConfig.setValue('impersonate',$(this).attr('name'),val); | ||
}); | ||
|
||
$('#includedGroups').each(function (index, element) { | ||
OC.Settings.setupGroupsSelect($(element)); | ||
$(element).change(function(ev) { | ||
var groups = ev.val || []; | ||
groups = JSON.stringify(groups); | ||
OC.AppConfig.setValue('impersonate', $(this).attr('name'), groups); | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
\OC_Util::checkAdminUser(); | ||
|
||
\OCP\Util::addStyle('impersonate', 'settings-admin'); | ||
\OCP\Util::addScript('impersonate', 'settings-admin'); | ||
|
||
$tmpl = new OCP\Template( 'impersonate', 'settings-admin' ); | ||
return $tmpl->fetchPage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div class="section" id="impersonateTemplateSettings" > | ||
|
||
<h2><?php p($l->t('Impersonate Settings'));?></h2> | ||
|
||
<p class="<?php if (\OC::$server->getAppConfig()->getValue('impersonate', 'enabled','no') === 'no') p('hidden');?>"> | ||
<input type="checkbox" name="impersonate_include_groups" id="impersonateIncludeGroups" class="checkbox" | ||
value="1" <?php if (\OC::$server->getAppConfig()->getValue('impersonate', 'impersonate_include_groups','false') !== 'false') print_unescaped('checked="checked"'); ?> /> | ||
<label for="impersonateIncludeGroups"><?php p($l->t('Include groups for impersonate'));?></label><br/> | ||
</p> | ||
<p id="selectIncludedGroups" class="indent <?php if (\OC::$server->getAppConfig()->getValue('impersonate', 'impersonate_include_groups','false') === 'false') p('hidden'); ?>"> | ||
<input name="impersonate_include_groups_list" type="hidden" id="includedGroups" value="<?php | ||
$includeGroupList = \OC::$server->getAppConfig()->getValue('impersonate', 'impersonate_include_groups_list',[]); | ||
$includeGroupList = json_decode($includeGroupList); | ||
$listToPrint = count($includeGroupList) > 0 ? implode('|',$includeGroupList) : ''; | ||
p($listToPrint); | ||
?>" style="width: 400px"/> | ||
<br /> | ||
<em><?php p($l->t('These groups will be able to impersonate.')); ?></em> | ||
</p> | ||
|
||
</div> | ||
|