Fixed exception throw in UserModel
This commit is contained in:
parent
b8bb2c865e
commit
5514ed4fd6
2 changed files with 64 additions and 1 deletions
|
@ -109,7 +109,7 @@ final class UserEntity extends AbstractEntity implements IValidatable
|
||||||
$this->accessRank->validate();
|
$this->accessRank->validate();
|
||||||
|
|
||||||
if ($this->accessRank->toInteger() == AccessRank::Nobody)
|
if ($this->accessRank->toInteger() == AccessRank::Nobody)
|
||||||
throw new Exception('Cannot set special access rank "%s"', $this->accessRank->toString());
|
throw new Exception(sprintf('Cannot set special access rank "%s"', $this->accessRank->toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validateEmails()
|
private function validateEmails()
|
||||||
|
|
63
tests/JobTests/EditUserAccessRankJobTest.php
Normal file
63
tests/JobTests/EditUserAccessRankJobTest.php
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
class EditUserAccessRankJobTest extends AbstractTest
|
||||||
|
{
|
||||||
|
public function testEditing()
|
||||||
|
{
|
||||||
|
$this->grantAccess('changeUserAccessRank');
|
||||||
|
$user = $this->mockUser();
|
||||||
|
|
||||||
|
$this->assert->areEqual(AccessRank::Registered, $user->getAccessRank()->toInteger());
|
||||||
|
|
||||||
|
$user = $this->assert->doesNotThrow(function() use ($user)
|
||||||
|
{
|
||||||
|
return Api::run(
|
||||||
|
new EditUserAccessRankJob(),
|
||||||
|
[
|
||||||
|
JobArgs::ARG_USER_NAME => $user->getName(),
|
||||||
|
JobArgs::ARG_NEW_ACCESS_RANK => AccessRank::PowerUser,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->assert->areEqual(AccessRank::PowerUser, $user->getAccessRank()->toInteger());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSettingToNobodyDenial()
|
||||||
|
{
|
||||||
|
$this->grantAccess('changeUserAccessRank');
|
||||||
|
$user = $this->mockUser();
|
||||||
|
|
||||||
|
$this->assert->areEqual(AccessRank::Registered, $user->getAccessRank()->toInteger());
|
||||||
|
|
||||||
|
$this->assert->throws(function() use ($user)
|
||||||
|
{
|
||||||
|
Api::run(
|
||||||
|
new EditUserAccessRankJob(),
|
||||||
|
[
|
||||||
|
JobArgs::ARG_USER_NAME => $user->getName(),
|
||||||
|
JobArgs::ARG_NEW_ACCESS_RANK => AccessRank::Nobody,
|
||||||
|
]);
|
||||||
|
}, 'Cannot set special access rank');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHigherThanMyselfDenial()
|
||||||
|
{
|
||||||
|
getConfig()->privileges->changeUserAccessRank = 'power-user';
|
||||||
|
Access::init();
|
||||||
|
|
||||||
|
$user = $this->mockUser();
|
||||||
|
$user->setAccessRank(new AccessRank(AccessRank::PowerUser));
|
||||||
|
UserModel::save($user);
|
||||||
|
|
||||||
|
$this->assert->areEqual(AccessRank::PowerUser, $user->getAccessRank()->toInteger());
|
||||||
|
|
||||||
|
$this->assert->throws(function() use ($user)
|
||||||
|
{
|
||||||
|
Api::run(
|
||||||
|
new EditUserAccessRankJob(),
|
||||||
|
[
|
||||||
|
JobArgs::ARG_USER_NAME => $user->getName(),
|
||||||
|
JobArgs::ARG_NEW_ACCESS_RANK => AccessRank::Admin,
|
||||||
|
]);
|
||||||
|
}, 'Insufficient privileges');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue