Preferences and Refactor

This commit is contained in:
Yuri Kuznetsov
2014-01-24 12:14:47 +02:00
parent 2bf146f944
commit fea3ac311b
15 changed files with 728 additions and 515 deletions

View File

@@ -17,16 +17,41 @@ class Preferences extends \Espo\Core\Controllers\Base
{
return $this->getContainer()->get('entityManager');
}
public function actionRead($params)
protected function handleUserAccess($userId)
{
$userId = $params['id'];
if (!$this->getUser()->isAdmin()) {
if ($this->getUser()->id != $userId) {
throw new Forbidden();
}
}
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
}
public function actionPatch($params, $data)
{
return $this->actionUpdate($params, $data);
}
public function actionUpdate($params, $data)
{
$userId = $params['id'];
$this->handleUserAccess($userId);
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
if ($entity) {
$entity->set($data);
$this->getEntityManager()->saveEntity($entity);
return $entity->toArray();
}
throw new Error();
}
public function actionRead($params)
{
$userId = $params['id'];
$this->handleUserAccess($userId);
$entity = $this->getEntityManager()->getEntity('Preferences', $userId);
if ($entity) {
return $entity->toArray();
}