Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajout de la route pour les responsables de groupe #30

Merged
merged 4 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Absence/Type/TypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ private function getList(IRequest $request, IResponse $response)
} catch (\Exception $e) {
return $this->getResponseError($response, $e);
}
$entites = [];
foreach ($responseResources as $responseResource) {
$entites[] = $this->buildData($responseResource);
}
$entites = array_map([$this, 'buildData'], $responseResources);

return $this->getResponseSuccess($response, $entites, 200);
}
Expand Down
10 changes: 5 additions & 5 deletions Absence/Type/TypeDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public function getList(array $parametres)
throw new \UnexpectedValueException('No resource match with these parameters');
}

$entites = [];
foreach ($data as $value) {
$entite = new TypeEntite($this->getStorage2Entite($value));
$entites[$entite->getId()] = $entite;
}
$entites = array_map(function ($value) {
return new TypeEntite($this->getStorage2Entite($value));
},
$data
);

return $entites;
}
Expand Down
5 changes: 1 addition & 4 deletions Groupe/GroupeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ private function getList(IRequest $request, IResponse $response)
} catch (\Exception $e) {
return $this->getResponseError($response, $e);
}
$entites = [];
foreach ($groupes as $groupe) {
$entites[] = $this->buildData($groupe);
}
$entites = array_map([$this, 'buildData'], $groupes);

return $this->getResponseSuccess($response, $entites, 200);
}
Expand Down
10 changes: 5 additions & 5 deletions Groupe/GroupeDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public function getList(array $parametres)
throw new \UnexpectedValueException('No resource match with these parameters');
}

$entites = [];
foreach ($data as $value) {
$entite = new GroupeEntite($this->getStorage2Entite($value));
$entites[$entite->getId()] = $entite;
}
$entites = array_map(function ($value) {
return new GroupeEntite($this->getStorage2Entite($value));
},
$data
);

return $entites;
}
Expand Down
2 changes: 1 addition & 1 deletion Groupe/GroupeEntite.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @since 0.7
* @see \LibertAPI\Tests\Units\Groupe\GroupeEntite
*
* Ne devrait être contacté que par le GroupeRepository
* Ne devrait être contacté que par le GroupeDao
* Ne devrait contacter personne
*/
class GroupeEntite extends \LibertAPI\Tools\Libraries\AEntite
Expand Down
87 changes: 87 additions & 0 deletions Groupe/Responsable/ResponsableController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
namespace LibertAPI\Groupe\Responsable;

use LibertAPI\Tools\Exceptions\MissingArgumentException;
use LibertAPI\Tools\Interfaces;
use Psr\Http\Message\ServerRequestInterface as IRequest;
use Psr\Http\Message\ResponseInterface as IResponse;
use LibertAPI\Utilisateur\UtilisateurEntite;

/**
* Contrôleur de responsable de groupes
*
* @author Prytoegrian <prytoegrian@protonmail.com>
* @author Wouldsmina
*
* @since 0.7
* @see \Tests\Units\GroupeController
*
* Ne devrait être contacté que par le routeur
* Ne devrait contacter que le ResponsableRepository
*/
final class ResponsableController extends \LibertAPI\Tools\Libraries\AController
implements Interfaces\IGetable
{
/**
* {@inheritDoc}
*/
protected function ensureAccessUser($order, UtilisateurEntite $utilisateur)
{
unset($order);
if (!$utilisateur->isAdmin()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N'est plus vrai depuis libertempo/web#542

Copy link
Member

@wouldsmina wouldsmina Mar 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

si si! c'est le resp direct qui saute dans 542. Par contre, la suite logique que je prévois (sur Akhaten j'espère) :

  • création d'un compte RH à l'installation
  • le compte admin saute
  • les options permettant de paramétrer les droits des utilisateurs avec le droit admin (conges_users.u_is_admin) sautent
  • les utilisateurs ayant les droits admin auront accès à la configuration globale (conf métier, mail, type de congés...) et à la backup de la bdd

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, cool!

throw new \LibertAPI\Tools\Exceptions\MissingRightException('');
}
}

/**
* {@inheritDoc}
*/
public function get(IRequest $request, IResponse $response, array $arguments)
{
unset($arguments);
try {
$this->ensureAccessUser(__FUNCTION__, $this->currentUser);
$groupes = $this->repository->getList(
$request->getQueryParams()
);
} catch (\UnexpectedValueException $e) {
return $this->getResponseNoContent($response);
} catch (\LibertAPI\Tools\Exceptions\MissingRightException $e) {
return $this->getResponseForbidden($response, $request);
} catch (\Exception $e) {
return $this->getResponseError($response, $e);
}
$entites = array_map([$this, 'buildData'], $groupes);

return $this->getResponseSuccess($response, $entites, 200);
}

/**
* Construit le « data » du json
*
* @param UtilisateurEntite $entite Responsable
*
* @return array
*/
private function buildData(UtilisateurEntite $entite)
{
return [
'id' => $entite->getId(),
'login' => $entite->getLogin(),
'nom' => $entite->getNom(),
'prenom' => $entite->getPrenom(),
'isResp' => $entite->isResponsable(),
'isAdmin' => $entite->isAdmin(),
'isHr' => $entite->isHautReponsable(),
'isActif' => $entite->isActif(),
'password' => $entite->getMotDePasse(),
'quotite' => $entite->getQuotite(),
'email' => $entite->getMail(),
'numeroExercice' => $entite->getNumeroExercice(),
'planningId' => $entite->getPlanningId(),
'heureSolde' => $entite->getHeureSolde(),
'dateInscription' => $entite->getDateInscription(),
'dateLastAccess' => $entite->getDateLastAccess(),
];
}
}
148 changes: 148 additions & 0 deletions Groupe/Responsable/ResponsableDao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php
namespace LibertAPI\Groupe\Responsable;

use LibertAPI\Tools\Libraries\AEntite;
use LibertAPI\Utilisateur\UtilisateurEntite;

/**
* {@inheritDoc}
*
* @author Prytoegrian <prytoegrian@protonmail.com>
* @author Wouldsmina
*
* @since 0.7
*
* Ne devrait être contacté que par ResponsableRepository
* Ne devrait contacter personne
*/
class ResponsableDao extends \LibertAPI\Tools\Libraries\ADao
{
/*************************************************
* GET
*************************************************/

/**
* @inheritDoc
*/
public function getById($id)
{
throw new \RuntimeException('Action is forbidden');
}

/**
* @inheritDoc
*/
public function getList(array $parametres)
{
$this->queryBuilder->select('users.*, users.u_login AS id');
$this->queryBuilder->innerJoin('current', 'conges_users', 'users', 'current.gr_login = u_login');
$this->setWhere($parametres);
$res = $this->queryBuilder->execute();

$data = $res->fetchAll(\PDO::FETCH_ASSOC);
if (empty($data)) {
throw new \UnexpectedValueException('No resource match with these parameters');
}

$entites = array_map(function ($value) {
return new UtilisateurEntite($this->getStorage2Entite($value));
}, $data);

return $entites;
}

/**
* @inheritDoc
*
* Duplication de la fonction dans UtilisateurDao (Cf. decisions.md #2018-02-17)
*/
final protected function getStorage2Entite(array $dataDao)
{
return [
'id' => $dataDao['id'],
'login' => $dataDao['u_login'],
'nom' => $dataDao['u_nom'],
'prenom' => $dataDao['u_prenom'],
'isResp' => $dataDao['u_is_resp'] === 'Y',
'isAdmin' => $dataDao['u_is_admin'] === 'Y',
'isHr' => $dataDao['u_is_hr'] === 'Y',
'isActive' => $dataDao['u_is_active'] === 'Y',
'seeAll' => $dataDao['u_see_all'] === 'Y',
'password' => $dataDao['u_passwd'],
'quotite' => $dataDao['u_quotite'],
'email' => $dataDao['u_email'],
'numeroExercice' => $dataDao['u_num_exercice'],
'planningId' => $dataDao['planning_id'],
'heureSolde' => $dataDao['u_heure_solde'],
'dateInscription' => $dataDao['date_inscription'],
'token' => $dataDao['token'],
'dateLastAccess' => $dataDao['date_last_access'],
];
}

/*************************************************
* POST
*************************************************/

/**
* @inheritDoc
*/
public function post(AEntite $entite)
{
throw new \RuntimeException('Action is forbidden');
}

/*************************************************
* PUT
*************************************************/

/**
* @inheritDoc
*/
public function put(AEntite $entite)
{
throw new \RuntimeException('Action is forbidden');
}

/**
* @inheritDoc
*/
final protected function getEntite2Storage(AEntite $entite)
{
return [];
}

/*************************************************
* DELETE
*************************************************/

/**
* @inheritDoc
*/
public function delete($id)
{
throw new \RuntimeException('Action is forbidden');
}

/**
* Définit les filtres à appliquer à la requête
*
* @param array $parametres
* @example [filter => []]
*/
private function setWhere(array $parametres)
{
if (!empty($parametres['id'])) {
$this->queryBuilder->andWhere('g_gid = :id');
$this->queryBuilder->setParameter(':id', (int) $parametres['id']);
}
}

/**
* @inheritDoc
*/
final protected function getTableName()
{
return 'conges_groupe_resp';
}
}
73 changes: 73 additions & 0 deletions Groupe/Responsable/ResponsableRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
namespace LibertAPI\Groupe\Responsable;

use LibertAPI\Tools\Libraries\AEntite;

/**
* {@inheritDoc}
*
* @author Prytoegrian <prytoegrian@protonmail.com>
* @author Wouldsmina
*
* @since 0.5
* @see \LibertAPI\Tests\Units\Groupe\ResponsableRepository
*/
class ResponsableRepository extends \LibertAPI\Tools\Libraries\ARepository
{
/*************************************************
* GET
*************************************************/

/**
* @inheritDoc
*/
public function getOne($id)
{
throw new \RuntimeException('#' . $id . ' is not a callable resource');
}

/**
* @inheritDoc
*/
final protected function getParamsConsumer2Dao(array $paramsConsumer)
{
unset($paramsConsumer);
return [];
}

/*************************************************
* POST
*************************************************/

/**
* @inheritDoc
*/
public function postOne(array $data, AEntite $entite)
{
throw new \RuntimeException('Action is forbidden');
}

/*************************************************
* PUT
*************************************************/

/**
* @inheritDoc
*/
public function putOne(array $data, AEntite $entite)
{
throw new \RuntimeException('Action is forbidden');
}

/*************************************************
* DELETE
*************************************************/

/**
* @inheritDoc
*/
public function deleteOne(AEntite $entite)
{
throw new \RuntimeException('Action is forbidden');
}
}
Loading