mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Adjust new getter / setter for order masters
This commit is contained in:
@@ -1510,34 +1510,48 @@ class ACL implements cache_cacheableInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get array of base_id's on which the user is 'order master'
|
* Returns an array of collections on which the user is 'order master'
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_order_master_bids()
|
public function get_order_master_collections()
|
||||||
{
|
{
|
||||||
$sql = 'SELECT base_id FROM basusr WHERE order_master=\'1\' AND usr_id= :id ';
|
$sql = 'SELECT base_id FROM basusr WHERE order_master="1" AND usr_id= :usr_id ';
|
||||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||||
$stmt->execute(array(':id' => $this->user->get_id()));
|
$stmt->execute(array(':usr_id' => $this->user->get_id()));
|
||||||
$row = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
foreach($row as $k=>$v) {
|
|
||||||
$row[$k] = (int)$v;
|
$collections = array();
|
||||||
|
|
||||||
|
foreach($rs as $row) {
|
||||||
|
$collections[] = \collection::get_from_base_id($row['base_id']);
|
||||||
}
|
}
|
||||||
return $row;
|
|
||||||
|
return $collections;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the user as "order_master" on a collection
|
* Sets the user as "order_master" on a collection
|
||||||
*
|
*
|
||||||
* @param int $bid
|
* @param \collection $collection The collection to apply
|
||||||
|
* @param Boolean $bool Wheter the user is order master or not
|
||||||
|
*
|
||||||
|
* @return ACL
|
||||||
*/
|
*/
|
||||||
public function set_order_master($bid, $flag)
|
public function set_order_master(\collection $collection, $bool)
|
||||||
{
|
{
|
||||||
$sql = 'UPDATE basusr SET order_master= :flag WHERE usr_id= :id AND base_id= :bid';
|
$sql = 'UPDATE basusr SET order_master = :master
|
||||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
WHERE usr_id = :usr_id AND base_id = :base_id';
|
||||||
$r = $stmt->execute(array(':flag' => $flag, ':id' => $this->user->get_id(), 'bid' => $bid));
|
|
||||||
$stmt->closeCursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||||
|
$stmt->execute(array(
|
||||||
|
':master' => $bool ? 1 : 0,
|
||||||
|
':usr_id' => $this->user->get_id(),
|
||||||
|
':base_id' => $collection->get_base_id()
|
||||||
|
));
|
||||||
|
$stmt->closeCursor();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -246,22 +246,20 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \ACL::get_order_master_bids
|
* @covers \ACL::get_order_master_collections
|
||||||
* @covers \ACL::set_order_master_bids
|
* @covers \ACL::set_order_master
|
||||||
*/
|
*/
|
||||||
|
public function testGetSetOrder_master()
|
||||||
public function testOrder_master_bids()
|
|
||||||
{
|
{
|
||||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||||
$acl = self::$user->ACL();
|
$acl = self::$user->ACL();
|
||||||
|
|
||||||
foreach ($appbox->get_databoxes() as $databox) {
|
foreach ($appbox->get_databoxes() as $databox) {
|
||||||
foreach ($databox->get_collections() as $collection) {
|
foreach ($databox->get_collections() as $collection) {
|
||||||
$base_id = $collection->get_base_id();
|
$acl->set_order_master($collection, false);
|
||||||
$acl->set_order_master($base_id, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->assertEquals(0, count($acl->get_order_master_bids()));
|
$this->assertEquals(0, count($acl->get_order_master_collections()));
|
||||||
|
|
||||||
$tbas = array();
|
$tbas = array();
|
||||||
foreach ($appbox->get_databoxes() as $databox) {
|
foreach ($appbox->get_databoxes() as $databox) {
|
||||||
@@ -270,15 +268,16 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
if(!$acl->has_access_to_base($bid)) {
|
if(!$acl->has_access_to_base($bid)) {
|
||||||
$acl->give_access_to_base(array($bid));
|
$acl->give_access_to_base(array($bid));
|
||||||
}
|
}
|
||||||
$acl->set_order_master($bid, true);
|
$acl->set_order_master($collection, true);
|
||||||
$tbas[] = $bid;
|
$tbas[] = $bid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$tbas = array_diff($tbas, $acl->get_order_master_bids());
|
$tbas = array_diff($tbas, array_map(function (\collection $collection) {
|
||||||
|
return $collection->get_base_id();
|
||||||
|
}, $acl->get_order_master_collections()));
|
||||||
$this->assertEquals(0, count($tbas));
|
$this->assertEquals(0, count($tbas));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testIs_restricted_download()
|
public function testIs_restricted_download()
|
||||||
{
|
{
|
||||||
$this->testSet_quotas_on_base();
|
$this->testSet_quotas_on_base();
|
||||||
|
Reference in New Issue
Block a user