#PHRAS-741 #time 5h

add back-office events : account, acl
This commit is contained in:
Jean-Yves Gaulier
2015-09-28 17:31:52 +02:00
parent 89f705eebe
commit 808b0d7fa9
18 changed files with 489 additions and 72 deletions

View File

@@ -0,0 +1,9 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AccountCreatedEvent extends AccountRelatedEvent
{
}

View File

@@ -4,57 +4,6 @@ namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AccountDeletedEvent extends Event
class AccountDeletedEvent extends AccountRelatedEvent
{
/**
* @var int
*/
private $userId;
/**
* @var string
*/
private $login;
/**
* @var string
*/
private $emailAddress;
/**
* @param int $userId
* @param $login
* @param string $emailAddress
*/
public function __construct($userId, $login, $emailAddress)
{
$this->userId = $userId;
$this->login = $login;
$this->emailAddress = $emailAddress;
}
/**
* @return int
*/
public function getUserId()
{
return $this->userId;
}
/**
* @return string
*/
public function getLogin()
{
return $this->login;
}
/**
* @return string
*/
public function getEmailAddress()
{
return $this->emailAddress;
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AccountRelatedEvent extends Event
{
/**
* @var int
*/
private $userId;
/**
* @var string
*/
private $login;
/**
* @var string
*/
private $emailAddress;
/**
* @param int $userId
* @param $login
* @param string $emailAddress
*/
public function __construct($userId, $login, $emailAddress)
{
$this->userId = $userId;
$this->login = $login;
$this->emailAddress = $emailAddress;
}
/**
* @return int
*/
public function getUserId()
{
return $this->userId;
}
/**
* @return string
*/
public function getLogin()
{
return $this->login;
}
/**
* @return string
*/
public function getEmailAddress()
{
return $this->emailAddress;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclGiveAccessToBaseEvent extends AclRelatedEvent
{
public function getBaseId()
{
return $this->parms['base_id'];
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclGiveAccessToSbasEvent extends AclRelatedEvent
{
public function getSbasId()
{
return $this->parms['sbas_id'];
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclRelatedEvent extends Event
{
/**
* @var int
*/
private $userId;
/**
* @var string
*/
private $login;
/**
* @var string
*/
private $emailAddress;
/**
* @var array|null
* supplemental parameters specific to an inherited event class
*/
protected $parms;
/**
* @param int $userId
* @param $login
* @param string $emailAddress
*/
public function __construct($userId, $login, $emailAddress, array $parms = null)
{
$this->userId = $userId;
$this->login = $login;
$this->emailAddress = $emailAddress;
$this->parms = $parms;
}
/**
* @return int
*/
public function getUserId()
{
return $this->userId;
}
/**
* @return string
*/
public function getLogin()
{
return $this->login;
}
/**
* @return string
*/
public function getEmailAddress()
{
return $this->emailAddress;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclRemoveQuotasOnBaseEvent extends AclRelatedEvent
{
public function getBaseId()
{
return $this->parms['base_id'];
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclRevokeAccessFromBaseEvent extends AclRelatedEvent
{
public function getBaseId()
{
return $this->parms['base_id'];
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclSetAdminEvent extends AclRelatedEvent
{
public function isAdmin()
{
return $this->parms['is_admin'];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclSetLimitsEvent extends AclRelatedEvent
{
public function getBaseId()
{
return $this->parms['base_id'];
}
public function getLimit()
{
return $this->parms['limit'];
}
public function getLimitFrom()
{
return $this->parms['limit_from'];
}
public function getLimitTo()
{
return $this->parms['limit_to'];
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclSetMasksOnBaseEvent extends AclRelatedEvent
{
public function getBaseId()
{
return $this->parms['base_id'];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclSetQuotasOnBaseEvent extends AclRelatedEvent
{
public function getBaseId()
{
return $this->parms['base_id'];
}
public function getRemainingDownloads()
{
return $this->parms['remain_dwnld'];
}
public function getMonthDownloadMax()
{
return $this->parms['month_dwnld_max'];
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclUpdateDownloadRestrictionsEvent extends AclRelatedEvent
{
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclUpdateRightsToBaseEvent extends AclRelatedEvent
{
public function getBaseId()
{
return $this->parms['base_id'];
}
public function getRights()
{
return $this->parms['rights'];
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Alchemy\Phrasea\Core\Event;
use Symfony\Component\EventDispatcher\Event;
class AclUpdateRightsToSbasEvent extends AclRelatedEvent
{
public function getSbasId()
{
return $this->parms['sbas_id'];
}
public function getRights()
{
return $this->parms['rights'];
}
}

View File

@@ -30,4 +30,17 @@ final class PhraseaEvents
const RECORD_UPLOAD = 'record.upload';
const ACCOUNT_DELETED = 'account.deleted';
const ACCOUNT_CREATED = 'account.created';
const ACL_SET_ADMIN = 'acl.set.admin';
const ACL_REVOKE_ACCESS_FROM_BASE = 'acl.revoke.access.from.base';
const ACL_GIVE_ACCESS_TO_BASE = 'acl.give.acces.to.base';
const ACL_GIVE_ACCESS_TO_SBAS = 'acl.give.acces.to.sbas';
const ACL_UPDATE_RIGHTS_TO_BASE = 'acl.update.rights.to.base';
const ACL_UPDATE_RIGHTS_TO_SBAS = 'acl.update.rights.to.sbas';
const ACL_REMOVE_QUOTAS_ON_BASE = 'acl.remove.quotas.on.base';
const ACL_UPDATE_DOWNLOAD_RESTRICTIONS = 'acl.update.download.restrictions';
const ACL_SET_QUOTAS_ON_BASE = 'acl.set.quotas.on.base';
const ACL_SET_MASKS_ON_BASE = 'acl.set.masks.on.base';
const ACL_SET_LIMITS = 'acl.set.limits';
}

View File

@@ -802,6 +802,18 @@ class ACL implements cache_cacheableInterface
$this->is_admin = null;
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACL_SET_ADMIN,
new AclSetAdminEvent(
$this->user->get_id(),
$this->user->get_login(),
$this->user->get_email(),
array(
'is_admin'=>$boolean
)
)
);
return $this;
}
@@ -1153,6 +1165,17 @@ class ACL implements cache_cacheableInterface
if (!$stmt_del->execute(array(':base_id' => $base_id, ':usr_id' => $usr_id))) {
throw new Exception('Error while deleteing some rights');
}
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACL_REVOKE_ACCESS_FROM_BASE,
new AclRevokeAccessFromBaseEvent(
$this->user->get_id(),
$this->user->get_login(),
$this->user->get_email(),
array(
'base_id'=>$base_id
)
)
);
}
$stmt_del->closeCursor();
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
@@ -1188,6 +1211,18 @@ class ACL implements cache_cacheableInterface
$stmt_upd = $this->app['phraseanet.appbox']->get_connection()->prepare($sql_upd);
foreach ($to_update as $base_id) {
$stmt_upd->execute(array(':usr_id' => $usr_id, ':base_id' => $base_id));
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACL_GIVE_ACCESS_TO_BASE,
new AclGiveAccessToBaseEvent(
$this->user->get_id(),
$this->user->get_login(),
$this->user->get_email(),
array(
'base_id'=>$base_id
)
)
);
}
$stmt_upd->closeCursor();
@@ -1210,8 +1245,21 @@ class ACL implements cache_cacheableInterface
$usr_id = $this->user->get_id();
foreach ($sbas_ids as $sbas_id) {
if (!$this->has_access_to_sbas($sbas_id))
$stmt_ins->execute(array(':sbas_id' => $sbas_id, ':usr_id' => $usr_id));
if (!$this->has_access_to_sbas($sbas_id)) {
$stmt_ins->execute(array(':sbas_id' => $sbas_id, ':usr_id' => $usr_id));
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACL_GIVE_ACCESS_TO_SBAS,
new AclGiveAccessToSbasEvent(
$this->user->get_id(),
$this->user->get_login(),
$this->user->get_email(),
array(
'sbas_id'=>$sbas_id
)
)
);
}
}
$stmt_ins->closeCursor();
$this->delete_data_from_cache(self::CACHE_RIGHTS_SBAS);
@@ -1229,7 +1277,6 @@ class ACL implements cache_cacheableInterface
*/
public function update_rights_to_base($base_id, $rights)
{
if (!$this->has_access_to_base($base_id) && (!isset($rights['actif']) || $rights['actif'] == '1')) {
$this->give_access_to_base(array($base_id));
}
@@ -1270,6 +1317,19 @@ class ACL implements cache_cacheableInterface
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACL_UPDATE_RIGHTS_TO_BASE,
new AclUpdateRightsToBaseEvent(
$this->user->get_id(),
$this->user->get_login(),
$this->user->get_email(),
array(
'base_id'=>$base_id,
'rights'=>$rights
)
)
);
return $this;
}
@@ -1305,8 +1365,9 @@ class ACL implements cache_cacheableInterface
*/
public function update_rights_to_sbas($sbas_id, $rights)
{
if (!$this->has_access_to_sbas($sbas_id))
if (!$this->has_access_to_sbas($sbas_id)) {
$this->give_access_to_sbas(array($sbas_id));
}
$sql_up = "UPDATE sbasusr SET ";
@@ -1334,6 +1395,19 @@ class ACL implements cache_cacheableInterface
$stmt_up->closeCursor();
$this->delete_data_from_cache(self::CACHE_RIGHTS_SBAS);
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACL_UPDATE_RIGHTS_TO_SBAS,
new AclUpdateRightsToSbasEvent(
$this->user->get_id(),
$this->user->get_login(),
$this->user->get_email(),
array(
'sbas_id'=>$sbas_id,
'rights'=>$rights
)
)
);
return $this;
}
@@ -1345,8 +1419,8 @@ class ACL implements cache_cacheableInterface
public function remove_quotas_on_base($base_id)
{
$sql = 'UPDATE basusr
SET remain_dwnld = 0, restrict_dwnld = 0, month_dwnld_max = 0
WHERE usr_id = :usr_id AND base_id = :base_id ';
SET remain_dwnld = 0, restrict_dwnld = 0, month_dwnld_max = 0
WHERE usr_id = :usr_id AND base_id = :base_id ';
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array(':usr_id' => $this->user->get_id(), ':base_id' => $base_id));
@@ -1355,6 +1429,18 @@ class ACL implements cache_cacheableInterface
unset($stmt);
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACL_REMOVE_QUOTAS_ON_BASE,
new AclRemoveQuotasOnBaseEvent(
$this->user->get_id(),
$this->user->get_login(),
$this->user->get_email(),
array(
'base_id'=>$base_id
)
)
);
return $this;
}
@@ -1377,6 +1463,16 @@ class ACL implements cache_cacheableInterface
unset($stmt);
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACL_UPDATE_DOWNLOAD_RESTRICTIONS,
new AclUpdateDownloadRestrictionsEvent(
$this->user->get_id(),
$this->user->get_login(),
$this->user->get_email(),
array()
)
);
return $this;
}
@@ -1407,6 +1503,20 @@ class ACL implements cache_cacheableInterface
unset($stmt);
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACL_SET_QUOTAS_ON_BASE,
new AclSetQuotasOnBaseEvent(
$this->user->get_id(),
$this->user->get_login(),
$this->user->get_email(),
array(
'base_id'=>$base_id,
'remain_dwnld'=>$restes,
'month_dwnld_max'=>$droits
)
)
);
return $this;
}
@@ -1577,6 +1687,18 @@ class ACL implements cache_cacheableInterface
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACL_SET_MASKS_ON_BASE,
new AclSetMasksOnBaseEvent(
$this->user->get_id(),
$this->user->get_login(),
$this->user->get_email(),
array(
'base_id'=>$base_id
)
)
);
return $this;
}
@@ -1609,25 +1731,18 @@ class ACL implements cache_cacheableInterface
public function set_limits($base_id, $limit, DateTime $limit_from = null, DateTime $limit_to = null)
{
if ($limit) {
$sql = 'UPDATE basusr
SET time_limited = 1
$sql = 'UPDATE basusr
SET time_limited = :time_limited
, limited_from = :limited_from
, limited_to = :limited_to
WHERE base_id = :base_id AND usr_id = :usr_id';
} else {
$sql = 'UPDATE basusr
SET time_limited = 0
, limited_from = :limited_from
, limited_to = :limited_to
WHERE base_id = :base_id AND usr_id = :usr_id';
}
$params = array(
':usr_id' => $this->user->get_id()
, ':base_id' => $base_id
, 'limited_from' => ($limit_from ? $limit_from->format(DATE_ISO8601) : null)
, 'limited_to' => ($limit_to ? $limit_to->format(DATE_ISO8601) : null)
, ':time_limited'=> $limit ? 1 : 0
, ':limited_from' => ($limit_from ? $limit_from->format(DATE_ISO8601) : null)
, ':limited_to' => ($limit_to ? $limit_to->format(DATE_ISO8601) : null)
);
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
@@ -1638,6 +1753,21 @@ class ACL implements cache_cacheableInterface
$this->delete_data_from_cache(self::CACHE_LIMITS_BAS);
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACL_SET_LIMITS,
new AclSetLimitsEvent(
$this->user->get_id(),
$this->user->get_login(),
$this->user->get_email(),
array(
'base_id'=>$base_id,
'limit'=>$limit,
'limit_from'=>$limit_from,
'limit_to'=>$limit_to
)
)
);
return $this;
}

View File

@@ -1002,7 +1002,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
public function delete()
{
$repo = $this->app['EM']->getRepository('Entities\UsrAuthProvider');
$event = new AccountDeletedEvent($this->get_id(), $this->get_login(), $this->get_email());
foreach ($repo->findByUser($this) as $provider) {
$this->app['EM']->remove($provider);
@@ -1088,7 +1087,14 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
unset(self::$_instance[$this->get_id()]);
$this->app['dispatcher']->dispatch(PhraseaEvents::ACCOUNT_DELETED, $event);
$this->app['dispatcher']->dispatch(
PhraseaEvents::ACCOUNT_DELETED,
new AccountDeletedEvent(
$this->get_id(),
$this->get_login(),
$this->get_email()
)
);
return;
}
@@ -1823,6 +1829,15 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
$stmt->closeCursor();
}
$app['dispatcher']->dispatch(
PhraseaEvents::ACCOUNT_CREATED,
new AccountCreatedEvent(
$usr_id,
$login,
($email ? $email : null)
)
);
return self::getInstance($usr_id, $app);
}