Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Issue #114 et #115 : gestion du fait que l'on puisse être membre de p…
Browse files Browse the repository at this point in the history
…lusieurs "bacs à sable" (#118)

* feat: affiche le nom du superviseur des espaces de travail

* feat: distingue son espace de test de celui des autres (#115)
  • Loading branch information
slafayIGN authored Jan 20, 2023
1 parent abdb0f1 commit 03a052c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
27 changes: 21 additions & 6 deletions src/Controller/DatastoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function __construct(PlageApiService $plageApi, ParameterBagInterface $pa
}

/**
* Liste des espaces de travail.
* Liste les espaces de travail accessibles de l'utilisateur en distinguant :
* - les datastores "standards"
* - l'espace de test (bac à sable) dont l'utilisateur est superviseur
* - les autres espaces de test (bacs à sable d'autres utilisateurs)
*
* @Route("/", name="index", methods={"GET"})
*/
Expand All @@ -46,10 +49,14 @@ public function index(): Response
/** @var array */
$serviceAccount = $this->params->get('service_account');

$user = $this->plageApi->user->getMe();
$currentUserId = $user['_id'];

$myDatastores = array_values($this->plageApi->user->getMyDatastores());

$datastores = [];
$datastoreBAS = [
$otherSandboxDatastores = [];
$mySandboxDatastore = [
'_id' => -1,
'name' => 'Bac à sable',
'technical_name' => 'bacasable-xxxxxxxxxxxxx',
Expand All @@ -59,17 +66,25 @@ public function index(): Response
foreach ($myDatastores as $datastore) {
preg_match($regexBacasable, $datastore['technical_name'], $matches);

if (0 == count($matches)) { // n'est pas un bacasable
if (0 == count($matches)) { // n'est pas un bac à sable
$datastores[] = $datastore;
} else { // est un bacasable
$datastoreBAS = $datastore;
} else { // est un bac à sable
$community = $this->plageApi->community->get($datastore['community']['_id']);
if ($community['supervisor']['_id'] == $currentUserId) { // est mon bac à sable
$mySandboxDatastore = $datastore;
} else { // est le bac à sable de quelqu'un d'autre
// ajoute les informations du superviseur
$datastore['community']['supervisor'] = $community['supervisor'];
$otherSandboxDatastores[] = $datastore;
}
}
}

return $this->render('pages/datastore/index.html.twig', [
'serviceAccount' => $serviceAccount['username'],
'datastores' => $datastores,
'datastoreBAS' => $datastoreBAS,
'mySandboxDatastore' => $mySandboxDatastore,
'otherSandboxDatastores' => $otherSandboxDatastores,
]);
}

Expand Down
11 changes: 10 additions & 1 deletion src/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ public function __construct(PlageApiService $plageApi)
*/
public function me(): Response
{
$me = $this->plageApi->user->getMe();

$communities = [];
$communitiesMember = $me['communities_member'];
foreach ($communitiesMember as $communityMember) {
$communities[] = $this->plageApi->community->get($communityMember['community']['_id']);
}

return $this->render('pages/user/me.html.twig', [
'user' => $this->plageApi->user->getMe(),
'user' => $me,
'communities' => $communities
]);
}
}
21 changes: 19 additions & 2 deletions templates/pages/datastore/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<div class="container-content">
<div class="o-mea">
<div class="mea-container">

{# Espaces de travail "standards" #}
{% for datastore in datastores %}
<div class="mea-item">
<a href="{{ path('plage_datastore_view', { datastoreId: datastore._id }) }}">
Expand All @@ -26,9 +28,11 @@
</a>
</div>
{% endfor %}

{# Mon espace de test (Bac à sable) #}
{% set target = '' %}
{% if datastoreBAS._id != -1 %}
{% set target = path('plage_datastore_view', { datastoreId: datastoreBAS._id }) %}
{% if mySandboxDatastore._id != -1 %}
{% set target = path('plage_datastore_view', { datastoreId: mySandboxDatastore._id }) %}
{% elseif serviceAccount is not empty %}
{% set target = path('plage_datastore_create_sandbox') %}
{% endif %}
Expand All @@ -43,6 +47,19 @@
</a>
</div>
{% endif %}

{# Les bacs à sable des autres #}
{% for datastore in otherSandboxDatastores %}
<div class="mea-item">
<a href="{{ path('plage_datastore_view', { datastoreId: datastore._id }) }}">
<img class="mea-img" src="{{ asset('build/img/datastore/bac-a-sable.svg') }}"/>
<h3>{{ 'datastore.index.access_other_test' | trans({'%first_name%': datastore.community.supervisor.first_name, '%last_name%': datastore.community.supervisor.last_name}) }}</h3>
<p>
<span class="btn btn--plain btn--accent">{{ 'datastore.index.access_action' | trans }}</span>
</p>
</a>
</div>
{% endfor %}
</div>
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions templates/pages/user/me.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@

<p>{{ "user.me.member"| trans }}</p>
<ul>
{% for member in user.communities_member %}
{% for community in communities %}
<li>
<a href="{{ path('plage_datastore_view', { datastoreId: member.community.datastore }) }}">
{{ member.community.name }}
<a href="{{ path('plage_datastore_view', { datastoreId: community.datastore._id }) }}">
{{ community.name }}
</a>
({{ "user.me.supervisor"| trans }}&nbsp;: {{ community.supervisor.first_name }} {{ community.supervisor.last_name }})
</li>
{% endfor %}
</ul>
Expand Down
2 changes: 2 additions & 0 deletions translations/PlageWebClient.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ user:
creation: "Date d'inscription"
id: "Identifiant technique"
member: "Vous avez accès aux espaces de travail :"
supervisor: "Superviseur"

datastore:
index:
Expand All @@ -101,6 +102,7 @@ datastore:
access_action: "Accéder"
access_test: "Testez le service sur l'espace de test"
access_test_action: "Accéder"
access_other_test: "Accédez à l'espace de test de %first_name% %last_name%"
contact: "Contactez nos services pour ajouter un espace de travail"

dashboard:
Expand Down

0 comments on commit 03a052c

Please sign in to comment.