-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
198 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,8 @@ x-variables: &variables | |
|
||
GK_SESSION_IN_REDIS: "true" | ||
|
||
GK_SITE_ADMINISTRATORS: "1" | ||
|
||
services: | ||
|
||
adminer: | ||
|
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,100 @@ | ||
*** Settings *** | ||
Resource ../ressources/Authentication.robot | ||
Resource ../ressources/vars/Urls.robot | ||
Resource ../ressources/Moves.robot | ||
Variables ../ressources/vars/users.yml | ||
Variables ../ressources/vars/geokrety.yml | ||
Variables ../ressources/vars/waypoints.yml | ||
Suite Setup Suite Setup | ||
|
||
*** Variables *** | ||
|
||
${PERCENT} = %25 | ||
|
||
*** Test Cases *** | ||
|
||
Anonymous users cannot impersonate | ||
Go To Url ${PAGE_HOME_URL_EN} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
Go To Url ${PAGE_USER_3_PROFILE_URL} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
Go To Url ${PAGE_ADMIN_IMPERSONATE_USER_START} userid=${USER_3.id} redirect=${PAGE_SIGN_IN_URL} | ||
Go To Url ${PAGE_ADMIN_IMPERSONATE_USER_STOP} userid=${USER_3.id} redirect=${PAGE_SIGN_IN_URL} | ||
|
||
|
||
Other users cannot impersonate | ||
Sign In ${USER_2.name} Fast | ||
|
||
Go To Url ${PAGE_HOME_URL_EN} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
Go To Url ${PAGE_USER_3_PROFILE_URL} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
Go To Url ${PAGE_ADMIN_IMPERSONATE_USER_START} userid=${USER_3.id} redirect=${PAGE_HOME_URL_EN} | ||
Page Should Contain HTTP 403 | ||
Go To Url ${PAGE_ADMIN_IMPERSONATE_USER_STOP} userid=${USER_3.id} redirect=${PAGE_HOME_URL_EN} | ||
Page Should Contain HTTP 403 | ||
|
||
|
||
Admin users can impersonate | ||
Sign In ${USER_1.name} Fast | ||
|
||
Go To Url ${PAGE_HOME_URL_EN} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
Go To Url ${PAGE_USER_1_PROFILE_URL} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
Go To Url ${PAGE_USER_3_PROFILE_URL} | ||
Page Should Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
Element Text Should Be ${NAVBAR_PROFILE_LINK} ${USER_1.name} | ||
|
||
Go To Url ${PAGE_ADMIN_IMPERSONATE_USER_START} userid=${USER_3.id} redirect=${PAGE_USER_3_PROFILE_URL} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
Element Text Should Be ${NAVBAR_PROFILE_LINK} ${USER_3.name} | ||
|
||
Go To Url ${PAGE_HOME_URL_EN} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
Go To Url ${PAGE_USER_1_PROFILE_URL} | ||
Page Should Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
Go To Url ${PAGE_USER_2_PROFILE_URL} | ||
Page Should Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
Click Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Element Text Should Be ${NAVBAR_PROFILE_LINK} ${USER_2.name} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
Go To Url ${PAGE_USER_3_PROFILE_URL} | ||
Element Text Should Be ${NAVBAR_PROFILE_LINK} ${USER_2.name} | ||
Page Should Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
Click Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
Location Should Be ${PAGE_USER_2_PROFILE_URL} | ||
Element Text Should Be ${NAVBAR_PROFILE_LINK} ${USER_1.name} | ||
Page Should Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} | ||
Page Should Not Contain Element ${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} | ||
|
||
*** Keywords *** | ||
|
||
Suite Setup | ||
Clear Database And Seed ${3} users | ||
Seed ${1} geokrety owned by ${1} | ||
Sign Out Fast |
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,36 @@ | ||
<?php | ||
|
||
namespace GeoKrety\Controller\Admin; | ||
|
||
use GeoKrety\Controller\Admin\Traits\CurrentAdminLoader; | ||
use GeoKrety\Controller\Base; | ||
use GeoKrety\Model\User; | ||
|
||
class Impersonate extends Base { | ||
use CurrentAdminLoader; | ||
|
||
public function get(\Base $f3) { | ||
$user = new User(); | ||
$user->load(['id = ?', $f3->get('PARAMS.userid')]); | ||
if ($user->dry()) { | ||
$f3->error(404, _('This user does not exist.')); | ||
} | ||
|
||
$f3->set('CURRENT_USER', $user->id); | ||
$f3->set('SESSION.CURRENT_USER', $user->id); | ||
$f3->set('SESSION.CURRENT_USERNAME', $user->username); | ||
$f3->set('SESSION.ADMIN_IMPERSONATING', true); | ||
|
||
$f3->reroute(['user_details', ['userid' => $user->id]]); | ||
} | ||
|
||
public function stop(\Base $f3) { | ||
$user_id = $f3->get('CURRENT_USER'); | ||
$f3->set('CURRENT_USER', $this->currentAdmin->id); | ||
$f3->set('SESSION.CURRENT_USER', $this->currentAdmin->id); | ||
$f3->set('SESSION.CURRENT_USERNAME', $this->currentAdmin->username); | ||
$f3->clear('SESSION.ADMIN_IMPERSONATING'); | ||
|
||
$f3->reroute(['user_details', ['userid' => $user_id]]); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
website/app/GeoKrety/Controller/Admin/Traits/CurrentAdminLoader.php
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,33 @@ | ||
<?php | ||
|
||
namespace GeoKrety\Controller\Admin\Traits; | ||
|
||
use GeoKrety\Model\User; | ||
use GeoKrety\Service\Smarty; | ||
|
||
/** | ||
* Load the currently connected admin into `currentAdmin` variable in php and smarty. | ||
*/ | ||
trait CurrentAdminLoader { | ||
protected User $currentAdmin; | ||
|
||
public function beforeRoute(\Base $f3) { | ||
parent::beforeRoute($f3); | ||
|
||
if (!$f3->get('SESSION.IS_LOGGED_IN')) { | ||
$f3->error(401); | ||
} | ||
|
||
$user = new User(); | ||
$user->load(['id = ?', $f3->get('SESSION.ADMIN_ID')]); | ||
if ($user->dry()) { | ||
$f3->error(404, _('This user does not exist.')); | ||
} | ||
$this->currentAdmin = $user; | ||
Smarty::assign('currentAdmin', $this->currentAdmin); | ||
|
||
if (method_exists($this, '_beforeRoute')) { | ||
$this->_beforeRoute($f3); | ||
} | ||
} | ||
} |
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