mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Fix usrlist unit tests
This commit is contained in:
@@ -393,6 +393,17 @@ class UsrLists implements ControllerProviderInterface
|
||||
$em = $app['Core']->getEntityManager();
|
||||
$user = $app['Core']->getAuthenticatedUser();
|
||||
|
||||
$availableRoles = array(
|
||||
\Entities\UsrListOwner::ROLE_USER,
|
||||
\Entities\UsrListOwner::ROLE_EDITOR,
|
||||
\Entities\UsrListOwner::ROLE_ADMIN,
|
||||
);
|
||||
|
||||
if (!$app['request']->get('role'))
|
||||
throw new \Exception_BadRequest('Missing role parameter');
|
||||
elseif (!in_array($app['request']->get('role'), $availableRoles))
|
||||
throw new \Exception_BadRequest('Role is invalid');
|
||||
|
||||
try
|
||||
{
|
||||
$repository = $em->getRepository('\Entities\UsrList');
|
||||
@@ -423,7 +434,7 @@ class UsrLists implements ControllerProviderInterface
|
||||
$em->merge($list);
|
||||
}
|
||||
|
||||
$role = $app['request']->get('role', \Entities\UsrListOwner::ROLE_USER);
|
||||
$role = $app['request']->get('role');
|
||||
|
||||
$owner->setRole($role);
|
||||
|
||||
@@ -452,7 +463,7 @@ class UsrLists implements ControllerProviderInterface
|
||||
/**
|
||||
* UnShare a list to a user
|
||||
*/
|
||||
$controllers->post('/list/{list_id}/unshare/{owner_id}/', function(Application $app, $list_id, $owner_id)
|
||||
$controllers->post('/list/{list_id}/unshare/{usr_id}/', function(Application $app, $list_id, $usr_id)
|
||||
{
|
||||
$em = $app['Core']->getEntityManager();
|
||||
$user = $app['Core']->getAuthenticatedUser();
|
||||
@@ -464,14 +475,14 @@ class UsrLists implements ControllerProviderInterface
|
||||
$list = $repository->findUserListByUserAndId($user, $list_id);
|
||||
/* @var $list \Entities\UsrList */
|
||||
|
||||
if($list->getOwner($user)->getList() < \Entities\UsrListOwner::ROLE_ADMIN)
|
||||
if ($list->getOwner($user)->getRole() < \Entities\UsrListOwner::ROLE_ADMIN)
|
||||
{
|
||||
throw new \Exception('You are not authorized to do this');
|
||||
}
|
||||
|
||||
$owners_repository = $em->getRepository('\Entities\UsrListOwner');
|
||||
|
||||
$owner = $owners_repository->findByListAndOwner($list, $owner_id);
|
||||
$owner = $owners_repository->findByListAndUsrId($list, $usr_id);
|
||||
|
||||
$em->remove($owner);
|
||||
$em->flush();
|
||||
@@ -483,10 +494,9 @@ class UsrLists implements ControllerProviderInterface
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
||||
$datas = array(
|
||||
'success' => false
|
||||
, 'message' => _('Unable to add usr to list')
|
||||
, 'message' => _('Unable to remove usr from list')
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -127,7 +127,8 @@ class WorkZone implements ControllerProviderInterface
|
||||
'/attachStories/'
|
||||
, function(Application $app, Request $request)
|
||||
{
|
||||
|
||||
if(!$request->get('stories'))
|
||||
throw new \Exception_BadRequest();
|
||||
|
||||
$user = $app['Core']->getAuthenticatedUser();
|
||||
|
||||
@@ -196,7 +197,7 @@ class WorkZone implements ControllerProviderInterface
|
||||
else
|
||||
{
|
||||
$message = sprintf(
|
||||
_('%1$d Story attached to the WorkZone, %2$d already attached')
|
||||
_('%1$d Stories attached to the WorkZone, %2$d already attached')
|
||||
, $done
|
||||
, $alreadyFixed
|
||||
);
|
||||
|
@@ -12,6 +12,7 @@ use Doctrine\ORM\EntityRepository;
|
||||
*/
|
||||
class UsrListOwnerRepository extends EntityRepository
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -37,4 +38,36 @@ class UsrListOwnerRepository extends EntityRepository
|
||||
return $owner;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param \Entities\UsrList $list
|
||||
* @param type $usr_id
|
||||
* @return \Entities\UsrList
|
||||
*/
|
||||
public function findByListAndUsrId(\Entities\UsrList $list, $usr_id)
|
||||
{
|
||||
$dql = 'SELECT o FROM Entities\UsrListOwner o
|
||||
JOIN o.list l
|
||||
WHERE l.id = :list_id AND o.usr_id = :usr_id';
|
||||
|
||||
$params = array(
|
||||
'usr_id' => $usr_id,
|
||||
'list_id' => $list->getId()
|
||||
);
|
||||
|
||||
$query = $this->_em->createQuery($dql);
|
||||
$query->setParameters($params);
|
||||
|
||||
$owner = $query->getSingleResult();
|
||||
|
||||
/* @var $owner \Entities\UsrListOwner */
|
||||
if (null === $owner)
|
||||
{
|
||||
throw new \Exception_NotFound(_('Owner is not found'));
|
||||
}
|
||||
|
||||
return $owner;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user