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

@@ -255,13 +255,18 @@ class UsrLists implements ControllerProviderInterface
$em->remove($list);
$em->flush();
$datas = array(
'success' => true
, 'message' => sprintf(_('List has been deleted'))
);
}
catch (\Exception $e)
{
$datas = array(
'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
*/
$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();
$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();
$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)
{
$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
*/
$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();
$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,6 +18,8 @@ use Alchemy\Phrasea\Core\Configuration;
require_once __DIR__ . '/../../vendor/Silex/vendor/pimple/lib/Pimple.php';
/**
*
* Phraseanet Core Container
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
@@ -25,7 +27,6 @@ require_once __DIR__ . '/../../vendor/Silex/vendor/pimple/lib/Pimple.php';
class Core extends \Pimple
{
protected static $availableLanguages = array(
'ar_SA' => 'العربية'
, 'de_DE' => 'Deutsch'
@@ -358,7 +359,6 @@ class Core extends \Pimple
public static function initAutoloads()
{
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-extensions/lib/Twig/Extensions/Autoloader.php';

View File

@@ -156,6 +156,22 @@ class UsrList
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
*

View File

@@ -138,5 +138,9 @@ class UsrListEntry
{
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
{
const ROLE_USER = 'user';
const ROLE_EDITOR = 'editor';
const ROLE_ADMIN = 'admin';
const ROLE_USER = 1;
const ROLE_EDITOR = 2;
const ROLE_ADMIN = 3;
/**
* @var integer $id

View File

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

View File

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

View File

@@ -90,6 +90,18 @@ class EntitiesUsrListProxy extends \Entities\UsrList implements \Doctrine\ORM\Pr
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)
{
$this->__load();

View File

@@ -34,4 +34,22 @@ class UsrListEntryRepository extends EntityRepository
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
{
/**
*
*
* @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);
foreach ($rights_to_give as $sbas_id => $rights)
foreach ($rights_to_give as $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()
);
if (self::mail($to, $from, $params['ssel_id']))
if (self::mail($to, $from, $params['ssel_id'], $params['url']))
$mailed = true;
}
@@ -192,7 +192,7 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
* @param int $ssel_id
* @return boolean
*/
function mail($to, $from, $ssel_id)
function mail($to, $from, $ssel_id, $url)
{
try
{
@@ -217,7 +217,7 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
$from['name']
) . "</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());
}

View File

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

View File

@@ -381,8 +381,14 @@ class record_preview extends record_adapter
$tab[$hour][$site][$action] = array();
if (!isset($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']))
$tab[$hour][$site][$action][$row['usr_id']]['final'][] =

View File

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

View File

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

View File

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