mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 13:03:20 +00:00
Merge branch '3.7'
This commit is contained in:
@@ -1591,4 +1591,50 @@ class ACL implements cache_cacheableInterface
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of collections on which the user is 'order master'
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_order_master_collections()
|
||||||
|
{
|
||||||
|
$sql = 'SELECT base_id FROM basusr WHERE order_master="1" AND usr_id= :usr_id ';
|
||||||
|
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||||
|
$stmt->execute(array(':usr_id' => $this->user->get_id()));
|
||||||
|
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
$stmt->closeCursor();
|
||||||
|
|
||||||
|
$collections = array();
|
||||||
|
|
||||||
|
foreach($rs as $row) {
|
||||||
|
$collections[] = \collection::get_from_base_id($row['base_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $collections;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the user as "order_master" on a collection
|
||||||
|
*
|
||||||
|
* @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(\collection $collection, $bool)
|
||||||
|
{
|
||||||
|
$sql = 'UPDATE basusr SET order_master = :master
|
||||||
|
WHERE usr_id = :usr_id AND base_id = :base_id';
|
||||||
|
|
||||||
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -256,6 +256,39 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \ACL::get_order_master_collections
|
||||||
|
* @covers \ACL::set_order_master
|
||||||
|
*/
|
||||||
|
public function testGetSetOrder_master()
|
||||||
|
{
|
||||||
|
$appbox = \appbox::get_instance(\bootstrap::getCore());
|
||||||
|
$acl = self::$user->ACL();
|
||||||
|
|
||||||
|
foreach ($appbox->get_databoxes() as $databox) {
|
||||||
|
foreach ($databox->get_collections() as $collection) {
|
||||||
|
$acl->set_order_master($collection, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->assertEquals(0, count($acl->get_order_master_collections()));
|
||||||
|
|
||||||
|
$tbas = array();
|
||||||
|
foreach ($appbox->get_databoxes() as $databox) {
|
||||||
|
foreach ($databox->get_collections() as $collection) {
|
||||||
|
$bid = $collection->get_base_id();
|
||||||
|
if(!$acl->has_access_to_base($bid)) {
|
||||||
|
$acl->give_access_to_base(array($bid));
|
||||||
|
}
|
||||||
|
$acl->set_order_master($collection, true);
|
||||||
|
$tbas[] = $bid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$tbas = array_diff($tbas, array_map(function (\collection $collection) {
|
||||||
|
return $collection->get_base_id();
|
||||||
|
}, $acl->get_order_master_collections()));
|
||||||
|
$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