mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
PHRAS-508_acl-cache
- fix unit tests
This commit is contained in:
@@ -1153,17 +1153,13 @@ class ACL implements cache_cacheableInterface
|
||||
{
|
||||
$this->load_rights_bas();
|
||||
|
||||
$sql_i = "INSERT INTO basusr (base_id, usr_id, actif) VALUES (:base_id, :usr_id, '1')";
|
||||
$sql_u = "UPDATE basusr SET UPDATE actif='1' WHERE base_id = :base_id AND usr_id = :usr_id";
|
||||
$stmt_i = $this->app->getApplicationBox()->get_connection()->prepare($sql_i);
|
||||
$stmt_u = $this->app->getApplicationBox()->get_connection()->prepare($sql_u);
|
||||
|
||||
$usr_id = $this->user->getId();
|
||||
foreach ($base_ids as $base_id) {
|
||||
if (!isset($this->_rights_bas[$base_id]) || $this->_rights_bas[$base_id][self::ACTIF] === false) {
|
||||
try {
|
||||
$stmt_i->execute([':base_id' => $base_id, ':usr_id' => $usr_id]);
|
||||
if($stmt_i->rowCount() > 0) {
|
||||
if (isset($this->_rights_bas[$base_id]) && $this->_rights_bas[$base_id][self::ACTIF] == true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($this->try_give_access_to_base_insert($base_id, $usr_id) == true) {
|
||||
$this->app['dispatcher']->dispatch(
|
||||
AclEvents::ACCESS_TO_BASE_GRANTED,
|
||||
new AccessToBaseGrantedEvent(
|
||||
@@ -1175,16 +1171,9 @@ class ACL implements cache_cacheableInterface
|
||||
);
|
||||
}
|
||||
else {
|
||||
$stmt_u->execute([':base_id' => $base_id, ':usr_id' => $usr_id]);
|
||||
$this->try_give_access_to_base_update($base_id, $usr_id);
|
||||
}
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
// no-opp
|
||||
}
|
||||
}
|
||||
}
|
||||
$stmt_u->closeCursor();
|
||||
$stmt_i->closeCursor();
|
||||
|
||||
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
|
||||
$this->inject_rights();
|
||||
@@ -1192,6 +1181,45 @@ class ACL implements cache_cacheableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function try_give_access_to_base_insert($base_id, $usr_id)
|
||||
{
|
||||
static $stmt = null;
|
||||
if(!$stmt) {
|
||||
$sql = "INSERT INTO basusr (base_id, usr_id, actif) VALUES (:base_id, :usr_id, '1')";
|
||||
$stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql);
|
||||
}
|
||||
$inserted = false;
|
||||
try {
|
||||
$stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]);
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$inserted = true;
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
catch(DBALException $e) {
|
||||
// no-op, mostly the row did exist
|
||||
}
|
||||
|
||||
return $inserted;
|
||||
}
|
||||
|
||||
private function try_give_access_to_base_update($base_id, $usr_id)
|
||||
{
|
||||
static $stmt = null;
|
||||
if(!$stmt) {
|
||||
$sql = "UPDATE basusr SET UPDATE actif='1' WHERE base_id = :base_id AND usr_id = :usr_id";
|
||||
$stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql);
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt->execute([':base_id' => $base_id, ':usr_id' => $usr_id]);
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
catch(DBALException $e) {
|
||||
// no-op, mostly the row was deleted
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $sbas_ids
|
||||
|
@@ -40,7 +40,7 @@
|
||||
<img src="/assets/common/images/icons/feedback16.png"/>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if app.getAclForUser(app.getAuthenticatedUser()).has_right(cnstant('\\ACL::BAS_CHUPUB')) %}
|
||||
{% if app.getAclForUser(app.getAuthenticatedUser()).has_right(constant('\\ACL::BAS_CHUPUB')) %}
|
||||
<button class="ui-corner-all TOOL_bridge_btn story_window" title="{{ 'action : bridge' | trans }}" data-href="{{ path("prod_bridge_manager") }}">
|
||||
<img src="/assets/common/images/icons/door.png"/>
|
||||
</button>
|
||||
|
@@ -40,11 +40,11 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
|
||||
$aclMock->expects($this->once())->method('give_access_to_sbas')->with($this->equalTo([self::$DI['collection']->get_sbas_id()]));
|
||||
$aclMock->expects($this->once())->method('give_access_to_base')->with($this->equalTo([self::$DI['collection']->get_base_id()]));
|
||||
$aclMock->expects($this->once())->method('update_rights_to_base')->with($this->equalTo(self::$DI['collection']->get_base_id()), $this->equalTo([
|
||||
\ACL::CANPUTINALBUM => '1',
|
||||
\ACL::CANDWNLDHD => '1',
|
||||
\ACL::NOWATERMARK => '0',
|
||||
\ACL::CANDWNLDPREVIEW => '1',
|
||||
\ACL::ACTIF => '1',
|
||||
\ACL::CANPUTINALBUM => true,
|
||||
\ACL::CANDWNLDHD => true,
|
||||
\ACL::NOWATERMARK => false,
|
||||
\ACL::CANDWNLDPREVIEW => true,
|
||||
\ACL::ACTIF => true,
|
||||
]));
|
||||
|
||||
$aclProviderMock = $this->getMockBuilder('Alchemy\Phrasea\Authentication\ACLProvider')->disableOriginalConstructor()->getMock();
|
||||
|
@@ -452,21 +452,21 @@ class ACLTest extends \PhraseanetTestCase
|
||||
'mask_and' => 42
|
||||
]
|
||||
);
|
||||
$this->assertEquals('42', $this->object->get_mask_and($base_id));
|
||||
$this->assertEquals(42, $this->object->get_mask_and($base_id));
|
||||
$this->object->update_rights_to_base(
|
||||
$base_id,
|
||||
[
|
||||
'mask_and' => 1
|
||||
]
|
||||
);
|
||||
$this->assertEquals('1', $this->object->get_mask_and($base_id));
|
||||
$this->assertEquals(1, $this->object->get_mask_and($base_id));
|
||||
$this->object->update_rights_to_base(
|
||||
$base_id,
|
||||
[
|
||||
'mask_and' => 0
|
||||
]
|
||||
);
|
||||
$this->assertEquals('0', $this->object->get_mask_and($base_id));
|
||||
$this->assertEquals(0, $this->object->get_mask_and($base_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -531,8 +531,9 @@ class ACLTest extends \PhraseanetTestCase
|
||||
$this->object->give_access_to_sbas([$databox->get_sbas_id()]);
|
||||
}
|
||||
|
||||
if ($n === 0)
|
||||
if ($n === 0) {
|
||||
$this->fail('Not enough collection to test');
|
||||
}
|
||||
|
||||
$this->object->give_access_to_base($base_ids);
|
||||
$bases = array_keys($this->object->get_granted_base());
|
||||
|
Reference in New Issue
Block a user