diff --git a/docker-compose.local.yml b/docker-compose.local.yml index 9f3497329d..9f4805adcf 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -53,6 +53,8 @@ x-variables: &variables GK_SESSION_IN_REDIS: "true" + GK_SITE_ADMINISTRATORS: "1" + services: adminer: diff --git a/tests-qa/acceptance/120_admin/10_impersonation.robot b/tests-qa/acceptance/120_admin/10_impersonation.robot new file mode 100644 index 0000000000..00e705e532 --- /dev/null +++ b/tests-qa/acceptance/120_admin/10_impersonation.robot @@ -0,0 +1,98 @@ +*** 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 *** + +*** 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 diff --git a/tests-qa/acceptance/ressources/ComponentsLocator.robot b/tests-qa/acceptance/ressources/ComponentsLocator.robot index 66f937199a..fcb52176f3 100644 --- a/tests-qa/acceptance/ressources/ComponentsLocator.robot +++ b/tests-qa/acceptance/ressources/ComponentsLocator.robot @@ -22,6 +22,8 @@ ${NAVBAR_ACTIONS_CREATE_GEOKRET_LINK} //*[@id="navbar-actions-create"] ${NAVBAR_ACTIONS_CLAIM_GEOKRET_LINK} //*[@id="navbar-actions-claim"] ${NAVBAR_ACTIONS_SEARCH_LINK} //*[@id="navbar-actions-search"] ${NAVBAR_ACTIONS_PHOTO_GALLERY_LINK} //*[@id="navbar-actions-gallery"] +${NAVBAR_ACTIONS_IMPERSONATE_USER_START_LINK} //*[@id="navbar-impersonate-start"] +${NAVBAR_ACTIONS_IMPERSONATE_USER_STOP_LINK} //*[@id="navbar-impersonate-stop"] ################ diff --git a/tests-qa/acceptance/ressources/vars/Urls.robot b/tests-qa/acceptance/ressources/vars/Urls.robot index 5a2faf0bd4..024207cbec 100644 --- a/tests-qa/acceptance/ressources/vars/Urls.robot +++ b/tests-qa/acceptance/ressources/vars/Urls.robot @@ -107,6 +107,13 @@ ${PAGE_LEGACY_API_EXPORT_URL} ${GK_URL}/api/v1/export ${PAGE_LEGACY_API_EXPORT2_URL} ${GK_URL}/api/v1/export2 ${PAGE_LEGACY_API_EXPORT_OC_URL} ${GK_URL}/api/v1/export_oc +# ADMIN +${PAGE_ADMIN_HOME} ${PAGE_HOME_URL}/admin + +# IMPERSONATION +${PAGE_ADMIN_IMPERSONATE_USER_START} ${PAGE_ADMIN_HOME}/impersonate/\${params.userid}/start +${PAGE_ADMIN_IMPERSONATE_USER_STOP} ${PAGE_ADMIN_HOME}/impersonate/stop + *** Keywords *** Go To Url diff --git a/website/app-templates/smarty/navbar-profile.tpl b/website/app-templates/smarty/navbar-profile.tpl index ad276d4168..94c4d203f2 100644 --- a/website/app-templates/smarty/navbar-profile.tpl +++ b/website/app-templates/smarty/navbar-profile.tpl @@ -1,6 +1,15 @@ {if $f3->get('SESSION.IS_LOGGED_IN') && !is_null($current_user)} + {if $f3->get('SESSION.IS_ADMIN')} -