Merge branch '3.6' of github.com:alchemy-fr/Phraseanet into 3.6

This commit is contained in:
Nicolas Le Goff
2012-01-04 17:55:16 +01:00
17 changed files with 286 additions and 34 deletions

View File

@@ -217,7 +217,7 @@ class UsrLists implements ControllerProviderInterface
$em->merge($list); $em->merge($list);
$em->flush(); $em->flush();
$datas = array( $datas = array(
'success' => true 'success' => true
, 'message' => '' , 'message' => ''
@@ -246,7 +246,7 @@ class UsrLists implements ControllerProviderInterface
$em = $app['Core']->getEntityManager(); $em = $app['Core']->getEntityManager();
$repository = $em->getRepository('\Entities\Usr'); $repository = $em->getRepository('\Entities\Usr');
try try
{ {
$repository = $em->getRepository('\Entities\UsrList'); $repository = $em->getRepository('\Entities\UsrList');
@@ -255,13 +255,18 @@ class UsrLists implements ControllerProviderInterface
$em->remove($list); $em->remove($list);
$em->flush(); $em->flush();
$datas = array(
'success' => true
, 'message' => sprintf(_('List has been deleted'))
);
} }
catch (\Exception $e) catch (\Exception $e)
{ {
$datas = array( $datas = array(
'success' => false 'success' => false
, 'message' => sprintf(_('Unable to create list %s'), $list_name) , 'message' => sprintf(_('Unable to delete list'))
); );
} }
@@ -275,11 +280,41 @@ class UsrLists implements ControllerProviderInterface
/** /**
* Remove a usr_id from a list * Remove a usr_id from a list
*/ */
$controllers->post('/list/{list_id}/remove/{usr_id}/', function() use ($app) $controllers->post('/list/{list_id}/remove/{entry_id}/', function() use ($app)
{ {
$em = $app['Core']->getEntityManager(); $em = $app['Core']->getEntityManager();
$repository = $em->getRepository('\Entities\Usr'); try
{
$repository = $em->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id);
/* @var $list \Entities\UsrList */
$entry_repository = $em->getRepository('\Entities\UsrListEntry');
$user_entry = $entry_repository->findEntryByListAndEntryId($list, $entry_id);
$em->remove($user_entry);
$em->flush();
$datas = array(
'success' => false
, 'message' => _('Entry removed from list')
);
}
catch (\Exception $e)
{
$datas = array(
'success' => false
, 'message' => _('Unable to remove entry from list')
);
}
$Json = $app['Core']['Serializer']->serialize($datas, 'json');
return new Response($Json, 200, array('Content-Type' => 'application/json'));
} }
); );
@@ -290,7 +325,42 @@ class UsrLists implements ControllerProviderInterface
{ {
$em = $app['Core']->getEntityManager(); $em = $app['Core']->getEntityManager();
$repository = $em->getRepository('\Entities\Usr'); try
{
$repository = $em->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id);
/* @var $list \Entities\UsrList */
$user_entry = \User_Adapter::getInstance($usr_id, appbox::get_instance());
$entry = new \Entities\UsrListEntry();
$entry->setUser($user_entry);
$entry->setList($list);
$list->addUsrListEntry($entry);
$em->persist($entry);
$em->merge($list);
$em->flush();
$datas = array(
'success' => false
, 'message' => _('Usr added to list')
);
}
catch (\Exception $e)
{
$datas = array(
'success' => false
, 'message' => _('Unable to add usr to list')
);
}
$Json = $app['Core']['Serializer']->serialize($datas, 'json');
return new Response($Json, 200, array('Content-Type' => 'application/json'));
} }
); );
@@ -300,18 +370,108 @@ class UsrLists implements ControllerProviderInterface
$controllers->post('/list/{list_id}/share/{usr_id}/', function() use ($app) $controllers->post('/list/{list_id}/share/{usr_id}/', function() use ($app)
{ {
$em = $app['Core']->getEntityManager(); $em = $app['Core']->getEntityManager();
$user = $app['Core']->getAuthenticatedUser();
$repository = $em->getRepository('\Entities\Usr'); try
{
$repository = $em->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id);
/* @var $list \Entities\UsrList */
if($list->getOwner($user)->getList() < \Entities\UsrListOwner::ROLE_EDITOR)
{
throw new \Exception('You are not authorized to do this');
}
$new_owner = \User_Adapter::getInstance($usr_id, appbox::get_instance());
if($list->hasAccess($new_owner))
{
$owner = $list->getOwner($new_owner);
}
else
{
$owner = new \Entities\UsrListOwner();
$owner->setList($list);
$owner->setUser($new_owner);
$list->addUsrListOwner($owner);
$em->persist($owner);
$em->merge($list);
}
$role = $app['request']->get('role', \Entities\UsrListOwner::ROLE_USER);
$owner->setRole($role);
$em->merge($owner);
$em->flush();
$datas = array(
'success' => false
, 'message' => _('Usr added to list')
);
}
catch (\Exception $e)
{
$datas = array(
'success' => false
, 'message' => _('Unable to add usr to list')
);
}
$Json = $app['Core']['Serializer']->serialize($datas, 'json');
return new Response($Json, 200, array('Content-Type' => 'application/json'));
} }
); );
/** /**
* UnShare a list to a user * UnShare a list to a user
*/ */
$controllers->post('/list/{list_id}/unshare/{usr_id}/', function() use ($app) $controllers->post('/list/{list_id}/unshare/{owner_id}/', function() use ($app)
{ {
$em = $app['Core']->getEntityManager(); $em = $app['Core']->getEntityManager();
$user = $app['Core']->getAuthenticatedUser();
$repository = $em->getRepository('\Entities\Usr'); try
{
$repository = $em->getRepository('\Entities\UsrList');
$list = $repository->findUserListByUserAndId($user, $list_id);
/* @var $list \Entities\UsrList */
if($list->getOwner($user)->getList() < \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);
$em->remove($owner);
$em->flush();
$datas = array(
'success' => false
, 'message' => _('Owner removed from list')
);
}
catch (\Exception $e)
{
$datas = array(
'success' => false
, 'message' => _('Unable to add usr to list')
);
}
$Json = $app['Core']['Serializer']->serialize($datas, 'json');
return new Response($Json, 200, array('Content-Type' => 'application/json'));
} }
); );

View File

@@ -18,13 +18,14 @@ use Alchemy\Phrasea\Core\Configuration;
require_once __DIR__ . '/../../vendor/Silex/vendor/pimple/lib/Pimple.php'; require_once __DIR__ . '/../../vendor/Silex/vendor/pimple/lib/Pimple.php';
/** /**
*
* Phraseanet Core Container
* *
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Core extends \Pimple class Core extends \Pimple
{ {
protected static $availableLanguages = array( protected static $availableLanguages = array(
'ar_SA' => 'العربية' 'ar_SA' => 'العربية'
@@ -358,7 +359,6 @@ class Core extends \Pimple
public static function initAutoloads() public static function initAutoloads()
{ {
require_once __DIR__ . '/../../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php'; require_once __DIR__ . '/../../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
require_once __DIR__ . '/../../vendor/Twig/lib/Twig/Autoloader.php'; require_once __DIR__ . '/../../vendor/Twig/lib/Twig/Autoloader.php';
require_once __DIR__ . '/../../vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php'; require_once __DIR__ . '/../../vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php';

View File

@@ -156,6 +156,22 @@ class UsrList
return false; return false;
} }
/**
*
* @param \User_Adapter $user
* @return \Entities\UsrListOwner
*/
public function getOwner(\User_Adapter $user)
{
foreach ($this->getOwners() as $owner)
{
if ($owner->getUser()->get_id() == $user->get_id())
return $owner;
}
throw new \Exception('This user is not an owner of the list');
}
/** /**
* Add users * Add users
* *

View File

@@ -138,5 +138,9 @@ class UsrListEntry
{ {
return \User_Adapter::getInstance($this->getUsrId(), \appbox::get_instance()); return \User_Adapter::getInstance($this->getUsrId(), \appbox::get_instance());
} }
public function setUser(\User_Adapter $user)
{
return $this->setUsrId($user->get_id());
}
} }

View File

@@ -18,9 +18,9 @@ namespace Entities;
*/ */
class UsrListOwner class UsrListOwner
{ {
const ROLE_USER = 'user'; const ROLE_USER = 1;
const ROLE_EDITOR = 'editor'; const ROLE_EDITOR = 2;
const ROLE_ADMIN = 'admin'; const ROLE_ADMIN = 3;
/** /**
* @var integer $id * @var integer $id

View File

@@ -96,6 +96,12 @@ class EntitiesUsrListEntryProxy extends \Entities\UsrListEntry implements \Doctr
return parent::getUser(); return parent::getUser();
} }
public function setUser(\User_Adapter $user)
{
$this->__load();
return parent::setUser($user);
}
public function __sleep() public function __sleep()
{ {

View File

@@ -102,6 +102,12 @@ class EntitiesUsrListOwnerProxy extends \Entities\UsrListOwner implements \Doctr
return parent::getList(); return parent::getList();
} }
public function setUser(\User_Adapter $user)
{
$this->__load();
return parent::setUser($user);
}
public function getUser() public function getUser()
{ {
$this->__load(); $this->__load();

View File

@@ -90,6 +90,18 @@ class EntitiesUsrListProxy extends \Entities\UsrList implements \Doctrine\ORM\Pr
return parent::getOwners(); return parent::getOwners();
} }
public function hasAccess(\User_Adapter $user)
{
$this->__load();
return parent::hasAccess($user);
}
public function getOwner(\User_Adapter $user)
{
$this->__load();
return parent::getOwner($user);
}
public function addUsrListEntry(\Entities\UsrListEntry $users) public function addUsrListEntry(\Entities\UsrListEntry $users)
{ {
$this->__load(); $this->__load();

View File

@@ -34,4 +34,22 @@ class UsrListEntryRepository extends EntityRepository
return $query->getResult(); return $query->getResult();
} }
public function findEntryByListAndEntryId(\Entities\UsrList $list, $entry_id)
{
$entry = $this->find($entry_id);
if(!$entry)
{
throw new \Exception_NotFound('Entry not found');
}
/* @var $entry \Entities\UsrListEntry */
if($entry->getList()->getId() != $list->getId())
{
throw new \Exception_Forbidden('Entry mismatch list');
}
return $entry;
}
} }

View File

@@ -12,4 +12,29 @@ use Doctrine\ORM\EntityRepository;
*/ */
class UsrListOwnerRepository extends EntityRepository class UsrListOwnerRepository extends EntityRepository
{ {
/**
*
*
* @param \Entities\UsrList $list
* @param type $owner_id
* @return \Entities\UsrList
*/
public function findByListAndOwner(\Entities\UsrList $list, $owner_id)
{
$owner = $this->find($owner_id);
/* @var $owner \Entities\UsrListOwner */
if (null === $owner)
{
throw new \Exception_NotFound(_('Owner is not found'));
}
if (!$owner->getList()->getid() != $list->getId())
{
throw new \Exception_Forbidden(_('Owner and list mismatch'));
}
return $owner;
}
} }

View File

@@ -321,7 +321,7 @@ class ACL implements cache_cacheableInterface
$this->give_access_to_base($bas_to_acces); $this->give_access_to_base($bas_to_acces);
foreach ($rights_to_give as $sbas_id => $rights) foreach ($rights_to_give as $base_id => $rights)
{ {
$this->update_rights_to_base($base_id, $rights); $this->update_rights_to_base($base_id, $rights);
} }

View File

@@ -110,7 +110,7 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
'name' => $user_from->get_display_name() 'name' => $user_from->get_display_name()
); );
if (self::mail($to, $from, $params['ssel_id'])) if (self::mail($to, $from, $params['ssel_id'], $params['url']))
$mailed = true; $mailed = true;
} }
@@ -192,7 +192,7 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
* @param int $ssel_id * @param int $ssel_id
* @return boolean * @return boolean
*/ */
function mail($to, $from, $ssel_id) function mail($to, $from, $ssel_id, $url)
{ {
try try
{ {
@@ -217,7 +217,7 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
$from['name'] $from['name']
) . "</div>\n"; ) . "</div>\n";
$body .= "<br/>\n" . $this->registry->get('GV_ServerName') . 'lightbox/validate/' . $ssel_id; $body .= "<br/>\n" . $url;
return mail::send_mail($subject, $body, $to, $from, array()); return mail::send_mail($subject, $body, $to, $from, array());
} }

View File

@@ -76,7 +76,6 @@ class gatekeeper
$session = $appbox->get_session(); $session = $appbox->get_session();
if (http_request::is_command_line()) if (http_request::is_command_line())
return; return;
if (isset($_SERVER['PHP_SELF']) && trim($_SERVER['PHP_SELF'])) if (isset($_SERVER['PHP_SELF']) && trim($_SERVER['PHP_SELF']))
@@ -105,7 +104,7 @@ class gatekeeper
} }
catch (Exception $e) catch (Exception $e)
{ {
} }
} }
@@ -122,7 +121,6 @@ class gatekeeper
if ($this->_PHP_SELF == '/thesaurus2/xmlhttp/getterm.x.php' if ($this->_PHP_SELF == '/thesaurus2/xmlhttp/getterm.x.php'
|| $this->_PHP_SELF == '/thesaurus2/xmlhttp/searchcandidate.x.php' || $this->_PHP_SELF == '/thesaurus2/xmlhttp/searchcandidate.x.php'
|| $this->_PHP_SELF == '/thesaurus2/xmlhttp/getsy.x.php') || $this->_PHP_SELF == '/thesaurus2/xmlhttp/getsy.x.php')
return; return;
phrasea::redirect('/login/?redirect=/thesaurus2'); phrasea::redirect('/login/?redirect=/thesaurus2');
break; break;
@@ -131,7 +129,6 @@ class gatekeeper
break; break;
case 'admin': case 'admin':
if ($this->_script_name === 'runscheduler.php') if ($this->_script_name === 'runscheduler.php')
return; return;
phrasea::redirect('/login/?redirect=' . $_SERVER['REQUEST_URI']); phrasea::redirect('/login/?redirect=' . $_SERVER['REQUEST_URI']);
break; break;
@@ -151,7 +148,6 @@ class gatekeeper
return; return;
case 'setup': case 'setup':
if ($appbox->upgradeavailable()) if ($appbox->upgradeavailable())
return; return;
else else
phrasea::redirect('/login/'); phrasea::redirect('/login/');
@@ -161,7 +157,7 @@ class gatekeeper
break; break;
case 'lightbox': case 'lightbox':
$this->token_access(); $this->token_access();
if(!$session->is_authenticated()) if (!$session->is_authenticated())
{ {
phrasea::redirect('/login/?redirect=' . $_SERVER['REQUEST_URI']); phrasea::redirect('/login/?redirect=' . $_SERVER['REQUEST_URI']);
} }
@@ -268,13 +264,12 @@ class gatekeeper
$parm = $request->get_parms('LOG'); $parm = $request->get_parms('LOG');
if (is_null($parm["LOG"])) if (is_null($parm["LOG"]))
return $this; return $this;
try try
{ {
if($session->is_authenticated()) if ($session->is_authenticated())
$session->logout (); $session->logout();
$auth = new Session_Authentication_Token($appbox, $parm['LOG']); $auth = new Session_Authentication_Token($appbox, $parm['LOG']);
$session->authenticate($auth); $session->authenticate($auth);
} }
@@ -286,10 +281,11 @@ class gatekeeper
try try
{ {
$datas = random::helloToken($parm['LOG']); $datas = random::helloToken($parm['LOG']);
return phrasea::redirect("/lightbox/validate/" . $datas['datas'] . "/");
} }
catch (Exception_NotFound $e) catch (Exception_NotFound $e)
{ {
} }
return $this; return $this;

View File

@@ -381,8 +381,14 @@ class record_preview extends record_adapter
$tab[$hour][$site][$action] = array(); $tab[$hour][$site][$action] = array();
if (!isset($tab[$hour][$site][$action][$row['usr_id']])) if (!isset($tab[$hour][$site][$action][$row['usr_id']]))
{
$tab[$hour][$site][$action][$row['usr_id']] = $tab[$hour][$site][$action][$row['usr_id']] =
array('final' => array(), 'comment' => array()); array(
'final' => array()
, 'comment' => array()
, 'user' => \User_Adapter::getInstance($row['usr_id'], $appbox)
);
}
if (!in_array($row['final'], $tab[$hour][$site][$action][$row['usr_id']]['final'])) if (!in_array($row['final'], $tab[$hour][$site][$action][$row['usr_id']]['final']))
$tab[$hour][$site][$action][$row['usr_id']]['final'][] = $tab[$hour][$site][$action][$row['usr_id']]['final'][] =

View File

@@ -2,6 +2,9 @@ Entities\UsrListOwner:
type: entity type: entity
repositoryClass: Repositories\UsrListOwnerRepository repositoryClass: Repositories\UsrListOwnerRepository
table: UsrListOwners table: UsrListOwners
uniqueConstraints:
unique_owner:
columns: usr_id,id
id: id:
id: id:
type: integer type: integer

View File

@@ -3,7 +3,7 @@
{% for hour, sites in record.get_short_history() %} {% for hour, sites in record.get_short_history() %}
{% for site, actions in sites %} {% for site, actions in sites %}
{% for action, users in actions %} {% for action, users in actions %}
{% for current_user, done in users %} {% for done in users %}
<div style="margin:3px 0"> <div style="margin:3px 0">
@@ -55,9 +55,9 @@
{% endif %} {% endif %}
<span class="actor"> <span class="actor">
{% if user.ACL().has_right_on_base(record.get_base_id(), 'canreport') %} {% if user.ACL().has_right_on_base(record.get_base_id(), 'canreport') %}
{% set user_infos = user.getInfos(current_user) %} {% if done['user'].get_id() != session.get_usr_id() %}
{% if current_user != session.get_usr_id() and user_infos %} {% set user_infos = done['user'].get_display_name() %}
{% trans %}report:: par {{user_infos}}{% endtrans %} {% trans %}report:: par {{ user_infos }}{% endtrans %}
{% endif %} {% endif %}
{% endif %} {% endif %}

View File

@@ -366,7 +366,7 @@ function manageSession(data, showMessages)
if($('.notification.unread',box).length > 0) if($('.notification.unread',box).length > 0)
{ {
var trigger = $('#notification_trigger') ; var trigger = $('#notification_trigger') ;
$('.counter div',trigger) $('.counter',trigger)
.empty() .empty()
.append($('.notification.unread',box).length); .append($('.notification.unread',box).length);
$('.counter',trigger).css('visibility','visible'); $('.counter',trigger).css('visibility','visible');