Commit 0df39d99 authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

FIX(user): add an "Edit your profile" button on user page

parent d4894499
Pipeline #13563 passed with stage
in 5 minutes and 9 seconds
......@@ -166,3 +166,20 @@ msgstr ""
msgid "User type : "
msgstr ""
#: Template/Api/V1/Users/view.ctp:95
msgid "userProfil.editLink"
msgstr "Edit your profile"
#: Template/Api/V1/Users/view.ctp:96
msgid "userProfil.editLink.title"
msgstr "Edit your profile: name, avatar, website and description"
#: Template/Api/V1/Users/view.ctp:100
msgid "admin.userProfil.editLink"
msgstr "Edit user profil"
#: Template/Api/V1/Users/view.ctp:101
msgid "admin.userProfil.editLink.title"
msgstr "Edit user profil {0}"
......@@ -168,3 +168,19 @@ msgstr ""
#: View/Helper/UserHelper.php:64;70;76;82
msgid "User type : "
msgstr ""
#: Template/Api/V1/Users/view.ctp:95
msgid "userProfil.editLink"
msgstr "Edit your profile"
#: Template/Api/V1/Users/view.ctp:96
msgid "userProfil.editLink.title"
msgstr "Edit your profile: name, avatar, website and description"
#: Template/Api/V1/Users/view.ctp:100
msgid "admin.userProfil.editLink"
msgstr "Edit user profil"
#: Template/Api/V1/Users/view.ctp:101
msgid "admin.userProfil.editLink.title"
msgstr "Edit user profil {0}"
......@@ -169,3 +169,19 @@ msgstr "Aller sur la page de {0}"
#: View/Helper/UserHelper.php:64;70;76;82
msgid "User type : "
msgstr "Type d'utilisateur : "
#: Template/Api/V1/Users/view.ctp:95
msgid "userProfil.editLink"
msgstr "Modifier votre profil"
#: Template/Api/V1/Users/view.ctp:96
msgid "userProfil.editLink.title"
msgstr "Modifier votre profil : nom, avatar, site web et description"
#: Template/Api/V1/Users/view.ctp:100
msgid "admin.userProfil.editLink"
msgstr "Modifier l'utilisateur"
#: Template/Api/V1/Users/view.ctp:101
msgid "admin.userProfil.editLink.title"
msgstr "Modifier l'utilisateur {0}"
......@@ -32,7 +32,6 @@ $this->assign('title', __d("Users", "User {0}", $user->username));
['escape' => false]) ?>
<?php endif; ?>
</div>
</div>
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8">
......@@ -82,6 +81,36 @@ $this->assign('title', __d("Users", "User {0}", $user->username));
'controller' => "Users",
'extraCssClass' => "contact-user inline-block",
]);
// Add link (edit user profil):
// - if ID of connected user is same as ID of the current page user
// - if connected user can edit all users (role = admin)
if ($this->request->session()->read('Auth.User.id') === $user->id
| $this->request->session()->read('Auth.User.role') === 'admin' ) {
$userId = $user->id;
$url = "/fr/users/edit/$userId";
if($this->request->session()->read('Auth.User.id') === $user->id) {
// ID of connected user is same as ID of the current page user.
$linkText = __d("Users", "userProfil.editLink");
$linkTitle = __d("Users", "userProfil.editLink.title");
}
else if ($this->request->session()->read('Auth.User.role') === 'admin' ) {
// Connected user can edit all users (role = admin)
$linkText = __d("Users", "admin.userProfil.editLink");
$linkTitle = __d("Users", "admin.userProfil.editLink.title", $userId);
}
$linkEditUserProfil = $this->Html->link(
$linkText,
$url,
[
'class' => 'btn btn-default btn-info addmore link-user-edit-profil',
'id' => "link-user-edit-profil-$userId",
'title' => $linkTitle,
]
);
echo $linkEditUserProfil;
}
?>
</li>
</ul>
......
......@@ -244,7 +244,6 @@ class UsersControllerTest extends ApiIntegrationTestCase
* @group form
* @group user
* @group anonymous
* @group wippp
* @return void
*/
public function testAnonymousUserCanDisplayAddFormOrLoginForm()
......@@ -1097,6 +1096,195 @@ class UsersControllerTest extends ApiIntegrationTestCase
$this->assertResponseCode('404');
}
/**
* Check, on a user page, that a anonymous user can not see edit user button
*
* @group form
* @group user
* @group anonymous
* @return void
*/
public function testAnonymousUserCanNotDisplayEditButton()
{
$userIdOfCurrentPage = 7;
$this->setAnonymousUserSession();
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertNotContains("link-user-edit-profil", $html);
$this->assertNotContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertNotContains("Modifier l&#039;utilisateur", $html);
$this->assertNotContains("Modifier votre profil", $html);
$this->assertNotContains("/fr/users/edit/$userIdOfCurrentPage", $html);
}
/**
* Check that a connected user can not see edit user button
* on another user's page
*
* @group form
* @group user
* @group anonymous
* @return void
*/
public function testConnectedUserCanNotSeeEditButtonOnAnotherUserPage()
{
$userIdOfCurrentPage = 7;
$this->setConnectedAdministrationSession(); // User ID = 6
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertNotContains("link-user-edit-profil", $html);
$this->assertNotContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertNotContains("Modifier l&#039;utilisateur", $html);
$this->assertNotContains("Modifier votre profil", $html);
$this->assertNotContains("/fr/users/edit/$userIdOfCurrentPage", $html);
$userIdOfCurrentPage = 7;
$this->setConnectedCompanySession(); // User ID = 2
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertNotContains("link-user-edit-profil", $html);
$this->assertNotContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertNotContains("Modifier l&#039;utilisateur", $html);
$this->assertNotContains("Modifier votre profil", $html);
$this->assertNotContains("/fr/users/edit/$userIdOfCurrentPage", $html);
$userIdOfCurrentPage = 7;
$this->setConnectedPersonSession(); // User ID = 4
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertNotContains("link-user-edit-profil", $html);
$this->assertNotContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertNotContains("Modifier l&#039;utilisateur", $html);
$this->assertNotContains("Modifier votre profil", $html);
$this->assertNotContains("/fr/users/edit/$userIdOfCurrentPage", $html);
$userIdOfCurrentPage = 4;
$this->setConnectedAssociationSession(); // User ID = 7
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertNotContains("link-user-edit-profil", $html);
$this->assertNotContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertNotContains("Modifier l&#039;utilisateur", $html);
$this->assertNotContains("Modifier votre profil", $html);
$this->assertNotContains("/fr/users/edit/$userIdOfCurrentPage", $html);
}
/**
* Check that connected users can see edit user button
* on their own page
*
* @group form
* @group user
* @group anonymous
* @return void
*/
public function testConnectedUsersCanSeeEditButtonOnTheirPage()
{
$userIdOfCurrentPage = 6;
$this->setConnectedAdministrationSession(); // User ID = 6
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertContains("link-user-edit-profil", $html);
$this->assertContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertContains("Modifier votre profil", $html);
$this->assertContains("/fr/users/edit/$userIdOfCurrentPage", $html);
$userIdOfCurrentPage = 2;
$this->setConnectedCompanySession(); // User ID = 2
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertContains("link-user-edit-profil", $html);
$this->assertContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertContains("Modifier votre profil", $html);
$this->assertContains("/fr/users/edit/$userIdOfCurrentPage", $html);
$userIdOfCurrentPage = 7;
$this->setConnectedAssociationSession(); // User ID = 7
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertContains("link-user-edit-profil", $html);
$this->assertContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertContains("Modifier votre profil", $html);
$this->assertContains("/fr/users/edit/$userIdOfCurrentPage", $html);
$userIdOfCurrentPage = 4;
$this->setConnectedPersonSession(); // User ID = 4
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertContains("link-user-edit-profil", $html);
$this->assertContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertContains("Modifier votre profil", $html);
$this->assertContains("/fr/users/edit/$userIdOfCurrentPage", $html);
}
/**
* Check that a admin user can see edit user button
* on another user's page
*
* @group form
* @group user
* @group anonymous
* @return void
*/
public function testAdminUsersCanSeeEditButtonOnAnotherUserPage()
{
$userIdOfCurrentPage = 7;
$this->setAdminSessionOfAdministrationType(); // User ID = 5
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertContains("link-user-edit-profil", $html);
$this->assertContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertContains("Modifier l&#039;utilisateur", $html);
$this->assertContains("/fr/users/edit/$userIdOfCurrentPage", $html);
$this->assertNotContains("Modifier votre profil", $html);
$userIdOfCurrentPage = 7;
$this->setAdminSessionOfPersonType(); // User ID = 9
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertContains("link-user-edit-profil", $html);
$this->assertContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertContains("Modifier l&#039;utilisateur", $html);
$this->assertContains("/fr/users/edit/$userIdOfCurrentPage", $html);
$this->assertNotContains("Modifier votre profil", $html);
}
/**
* Check that admin users can see edit user button
* on their own page
*
* @group form
* @group user
* @group anonymous
* @return void
*/
public function testAdminUsersCanSeeEditButtonOnTheirPage()
{
$userIdOfCurrentPage = 9;
$this->setAdminSessionOfPersonType(); // User ID = 9
$r = $this->checkUrlOk("/fr/users/$userIdOfCurrentPage", ['html']);
$html = $r['html']['data'];
$this->assertContains('<html lang="fr">', $html);
$this->assertContains("link-user-edit-profil", $html);
$this->assertContains("id=\"link-user-edit-profil-$userIdOfCurrentPage\"", $html);
$this->assertContains("Modifier votre profil", $html);
$this->assertContains("/fr/users/edit/$userIdOfCurrentPage", $html);
$this->assertNotContains("Modifier l&#039;utilisateur", $html);
}
/**
* Test edit method to change role
......
......@@ -802,6 +802,10 @@ section p {
border: 2px solid #103e10;
}
a.link-user-edit-profil {
margin-right: 1em;
}
.contact-user,
.contact-user:hover {
position: absolute;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment