-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) { | ||
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(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, cool!