Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Comptoir
Comptoir-srv
Commits
0df39d99
Commit
0df39d99
authored
Apr 04, 2021
by
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
Changes
6
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/Locale/Users.pot
View file @
0df39d99
...
...
@@ -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}"
src/Locale/en/Users.po
View file @
0df39d99
...
...
@@ -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}"
src/Locale/fr/Users.po
View file @
0df39d99
...
...
@@ -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}"
src/Template/Api/V1/Users/view.ctp
View file @
0df39d99
...
...
@@ -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>
...
...
tests/TestCase/Controller/Api/V1/UsersControllerTest.php
View file @
0df39d99
...
...
@@ -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'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'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'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'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'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'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'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'utilisateur"
,
$html
);
}
/**
* Test edit method to change role
...
...
webroot/css/comptoir.css
View file @
0df39d99
...
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment