mirror of
https://github.com/Combodo/iTop.git
synced 2026-06-03 14:42:16 +02:00
Compare commits
1 Commits
feature/95
...
feature/70
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41726b0cc9 |
@@ -85,6 +85,21 @@
|
|||||||
<class id="Attachment"/>
|
<class id="Attachment"/>
|
||||||
</classes>
|
</classes>
|
||||||
</group>
|
</group>
|
||||||
|
<group id="Ticket" _delta="define">
|
||||||
|
<classes>
|
||||||
|
<class id="Ticket"/>
|
||||||
|
</classes>
|
||||||
|
</group>
|
||||||
|
<group id="FunctionalCI" _delta="define">
|
||||||
|
<classes>
|
||||||
|
<class id="FunctionalCI"/>
|
||||||
|
</classes>
|
||||||
|
</group>
|
||||||
|
<group id="ServiceFamily" _delta="define">
|
||||||
|
<classes>
|
||||||
|
<class id="ServiceFamily"/>
|
||||||
|
</classes>
|
||||||
|
</group>
|
||||||
<group id="Portal" _delta="define">
|
<group id="Portal" _delta="define">
|
||||||
<classes>
|
<classes>
|
||||||
<class id="lnkFunctionalCIToTicket"/>
|
<class id="lnkFunctionalCIToTicket"/>
|
||||||
@@ -205,6 +220,42 @@
|
|||||||
</group>
|
</group>
|
||||||
</groups>
|
</groups>
|
||||||
<profiles>
|
<profiles>
|
||||||
|
<profile id="5500" _delta="define">
|
||||||
|
<name>ReadOnlyCI</name>
|
||||||
|
<description>This read-only profile allows to see CIs objects.</description>
|
||||||
|
<groups>
|
||||||
|
<group id="FunctionalCI">
|
||||||
|
<actions>
|
||||||
|
<action id="action:read">allow</action>
|
||||||
|
<action id="action:bulk read">allow</action>
|
||||||
|
</actions>
|
||||||
|
</group>
|
||||||
|
</groups>
|
||||||
|
</profile>
|
||||||
|
<profile id="5501" _delta="define">
|
||||||
|
<name>ReadOnlyTicket</name>
|
||||||
|
<description>This read-only profile allows to see Ticket objects.</description>
|
||||||
|
<groups>
|
||||||
|
<group id="Ticket">
|
||||||
|
<actions>
|
||||||
|
<action id="action:read">allow</action>
|
||||||
|
<action id="action:bulk read">allow</action>
|
||||||
|
</actions>
|
||||||
|
</group>
|
||||||
|
</groups>
|
||||||
|
</profile>
|
||||||
|
<profile id="5502" _delta="define">
|
||||||
|
<name>ReadOnlyCatalog</name>
|
||||||
|
<description>This read-only profile allows to see ServiceFamily objects.</description>
|
||||||
|
<groups>
|
||||||
|
<group id="ServiceFamily">
|
||||||
|
<actions>
|
||||||
|
<action id="action:read">allow</action>
|
||||||
|
<action id="action:bulk read">allow</action>
|
||||||
|
</actions>
|
||||||
|
</group>
|
||||||
|
</groups>
|
||||||
|
</profile>
|
||||||
<profile id="117" _delta="define">
|
<profile id="117" _delta="define">
|
||||||
<name>SuperUser</name>
|
<name>SuperUser</name>
|
||||||
<description>This profile allows all actions which are not Administrator restricted.</description>
|
<description>This profile allows all actions which are not Administrator restricted.</description>
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ use DBObject;
|
|||||||
use DBObjectSearch;
|
use DBObjectSearch;
|
||||||
use DBObjectSet;
|
use DBObjectSet;
|
||||||
use DeleteException;
|
use DeleteException;
|
||||||
|
use Dict;
|
||||||
use MetaModel;
|
use MetaModel;
|
||||||
use UserLocal;
|
use UserLocal;
|
||||||
use UserRights;
|
use UserRights;
|
||||||
@@ -96,6 +97,127 @@ class UserRightsTest extends ItopDataTestCase
|
|||||||
return $oUser;
|
return $oUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $aProfileIds
|
||||||
|
* @param array $aShouldBeAllowedToSeeClass
|
||||||
|
* @param array $aShouldBeAllowedToEditClass
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws \ArchivedObjectException
|
||||||
|
* @throws \CoreCannotSaveObjectException
|
||||||
|
* @throws \CoreException
|
||||||
|
* @throws \CoreUnexpectedValue
|
||||||
|
* @throws \CoreWarning
|
||||||
|
* @throws \DictExceptionUnknownLanguage
|
||||||
|
* @throws \MySQLException
|
||||||
|
* @throws \OQLException
|
||||||
|
* @dataProvider ReadOnlyProvider
|
||||||
|
*/
|
||||||
|
public function testReadOnlyUser(array $aProfileIds, array $aShouldBeAllowedToSeeClass, array $aShouldBeAllowedToEditClass): void
|
||||||
|
{
|
||||||
|
|
||||||
|
$oUser = $this->GivenUserWithProfiles('test1', $aProfileIds);
|
||||||
|
$oUser->DBInsert();
|
||||||
|
$_SESSION = [];
|
||||||
|
UserRights::Login($oUser->Get('login'));
|
||||||
|
|
||||||
|
$aClassesToTest = ['FunctionalCI', 'Ticket', 'ServiceFamily'];
|
||||||
|
|
||||||
|
foreach ($aClassesToTest as $sClass) {
|
||||||
|
$bShouldBeAllowedToSee = in_array($sClass, $aShouldBeAllowedToSeeClass);
|
||||||
|
$bIsAllowedReading = (bool)UserRights::IsActionAllowed($sClass, UR_ACTION_READ);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$bShouldBeAllowedToSee,
|
||||||
|
$bIsAllowedReading,
|
||||||
|
"User with profiles ".implode(',', $aProfileIds)." should ".($bShouldBeAllowedToSee ? "" : "NOT ")."be allowed to see class $sClass"
|
||||||
|
);
|
||||||
|
|
||||||
|
$bShouldBeAllowedToEdit = in_array($sClass, $aShouldBeAllowedToEditClass);
|
||||||
|
|
||||||
|
$bIsAllowedEditing = (bool)UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY);
|
||||||
|
|
||||||
|
$this->assertSame($bIsAllowedEditing, $bShouldBeAllowedToEdit,
|
||||||
|
"User with profiles ".implode(',', $aProfileIds)." should ".($bShouldBeAllowedToEdit ? "" : "NOT ")."be allowed to edit class $sClass"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected function ReadOnlyProvider() : array {
|
||||||
|
return [
|
||||||
|
'CI' => [
|
||||||
|
'ProfilesId' => [
|
||||||
|
5500,
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToSeeClasses' => [
|
||||||
|
'FunctionalCI',
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToEditClasses' => []
|
||||||
|
],
|
||||||
|
'Tickets' => [
|
||||||
|
'ProfilesId' => [
|
||||||
|
5501,
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToSeeClasses' => [
|
||||||
|
'Ticket',
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToEditClasses' => []
|
||||||
|
],
|
||||||
|
'Catalog' => [
|
||||||
|
'ProfilesId' => [
|
||||||
|
5502,
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToSeeClasses' => [
|
||||||
|
'ServiceFamily',
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToEditClasses' => []
|
||||||
|
],
|
||||||
|
'CI and Tickets' => [
|
||||||
|
'ProfilesId' => [
|
||||||
|
5500, 5501,
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToSeeClasses' => [
|
||||||
|
'FunctionalCI', 'Ticket',
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToEditClasses' => []
|
||||||
|
],
|
||||||
|
'CI and Catalog' => [
|
||||||
|
'ProfilesId' => [
|
||||||
|
5500, 5502,
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToSeeClasses' => [
|
||||||
|
'FunctionalCI', 'ServiceFamily',
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToEditClasses' => []
|
||||||
|
],
|
||||||
|
'Tickets and Catalog' => [
|
||||||
|
'ProfilesId' => [
|
||||||
|
5501, 5502,
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToSeeClasses' => [
|
||||||
|
'Ticket', 'ServiceFamily',
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToEditClasses' => []
|
||||||
|
],
|
||||||
|
'Tickets and Catalog + profile Ccnfiguration Manager' => [
|
||||||
|
'ProfilesId' => [
|
||||||
|
5501, 5502, 3
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToSeeClasses' => [
|
||||||
|
'FunctionalCI', 'Ticket', 'ServiceFamily',
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToEditClasses' => ['FunctionalCI']
|
||||||
|
],
|
||||||
|
'CI, Tickets and Catalog' => [
|
||||||
|
'ProfilesId' => [
|
||||||
|
5500, 5501, 5502,
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToSeeClasses' => [
|
||||||
|
'FunctionalCI', 'Ticket', 'ServiceFamily',
|
||||||
|
],
|
||||||
|
'ShouldBeAllowedToEditClasses' => []
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
public function testIsLoggedIn()
|
public function testIsLoggedIn()
|
||||||
{
|
{
|
||||||
$this->assertFalse(UserRights::IsLoggedIn());
|
$this->assertFalse(UserRights::IsLoggedIn());
|
||||||
@@ -433,7 +555,7 @@ class UserRightsTest extends ItopDataTestCase
|
|||||||
$oUser = $this->GivenUserWithProfiles('test1', [$iProfileId, 2]);
|
$oUser = $this->GivenUserWithProfiles('test1', [$iProfileId, 2]);
|
||||||
|
|
||||||
$this->expectException(CoreCannotSaveObjectException::class);
|
$this->expectException(CoreCannotSaveObjectException::class);
|
||||||
$this->expectExceptionMessage('Profile "Portal user" cannot be given to privileged Users (Administrators, SuperUsers and REST Services Users)');
|
$this->expectExceptionMessage(Dict::Format('Class:User/Error:PrivilegedUserMustHaveAccessToBackOffice', PORTAL_PROFILE_NAME));
|
||||||
$oUser->DBInsert();
|
$oUser->DBInsert();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user