Skip to content

Commit 374c21a

Browse files
Handle organizationId (#403)
* Fixes #401 * Review * Fixes #401: Add organizationId query filter * Fix review * Fix yarn lint * Fix missions routes * Fix review * Fix PHP-CS Co-authored-by: Michel Roca <[email protected]>
1 parent 272011e commit 374c21a

File tree

75 files changed

+677
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+677
-237
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ jobs:
8282
8383
- run: yarn install --frozen-lockfile
8484

85+
- run: bin/console fos:js-routing:dump --format=json --target=assets/js/fos_js_routes.json
86+
8587
- run: yarn encore production
8688

8789
# PHPStan needs the var/cache/test/App_KernelTestContainer.xml file to exist

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
###> symfony/webpack-encore-bundle ###
3737
/node_modules/
3838
/public/build/
39+
/assets/js/fos_js_routes.json
3940
npm-debug.log
4041
yarn-error.log
4142
###< symfony/webpack-encore-bundle ###

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,15 @@ vendors:
6767
bin/node-tools yarn install --pure-lockfile
6868

6969
webpack-build-dev:
70+
bin/tools bin/console fos:js-routing:dump --format=json --target=assets/js/fos_js_routes.json
7071
bin/node-tools yarn encore dev
7172

7273
webpack-watch-dev:
74+
bin/tools bin/console fos:js-routing:dump --format=json --target=assets/js/fos_js_routes.json
7375
bin/node-tools yarn encore dev --watch
7476

7577
webpack-build-prod:
78+
bin/tools bin/console fos:js-routing:dump --format=json --target=assets/js/fos_js_routes.json
7679
bin/node-tools yarn encore production
7780

7881
init-db: start-db

assets/js/_planning-missions.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { addPopovers } from './_planning';
22
import { displayAjaxModal } from './_helpers';
3+
import Routing from './_routing';
34

45
const $ = require('jquery');
56
const moment = require('moment');
@@ -14,7 +15,14 @@ function setSlotMisssion(mission, $slot) {
1415
missionsText += $('<span class="badge badge-secondary">').text(mission.type ? mission.type.name : 'mission')[0].outerHTML;
1516
missionsText += ' ';
1617

17-
const url = window.location.pathname.indexOf('organizations') >= 0 ? `/organizations/missions/${mission.id}/modal` : `/user/availability/missions/${mission.id}/modal`;
18+
// User part
19+
let url = Routing.generate('app_user_availability_mission_modal', { id: mission.id });
20+
21+
if (window.location.pathname.indexOf('organizations') >= 0 && !!mission?.organization?.id) {
22+
// Organization part
23+
url = Routing.generate('app_organization_mission_modal', { organization: mission.organization.id, id: mission.id });
24+
}
25+
1826
missionsText += $(`<button type="button" class="btn btn-link" data-toggle="ajax-modal" data-href="${url}">`).text(mission.name)[0].outerHTML;
1927

2028
$slot.addClass('mission').data('mission-text', missionsText);
@@ -95,8 +103,16 @@ export function fetchMissions() {
95103
let url;
96104

97105
if ($('.planning').length) {
98-
url = '/organizations/missions/find' + window.location.search;
106+
// Organization part
107+
url = Routing.generate('app_organization_mission_find_by_filters', {
108+
organization: window.location.pathname.replace(/^\/organizations\/(\d+).*$/, '$1'),
109+
});
110+
111+
// Add the form search filters to the request
112+
url += window.location.search;
99113
} else {
114+
// User part
115+
// Route: app_user_availability_missions or app_user_availability_missions_week
100116
url = window.location.pathname + '/missions';
101117
}
102118

assets/js/_routing.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Routing from '../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js';
2+
3+
const routes = require('./fos_js_routes.json');
4+
Routing.setRoutingData(routes);
5+
6+
export default Routing;

assets/js/availabilitable-list.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const $ = require('jquery');
22

33
$(document).ready(function () {
44
$('form[name="organization_selector"] select').on('change', function () {
5-
let $selectedOption = $('option:selected', this);
6-
window.location = $selectedOption.data('url');
5+
window.location = window.location.pathname + '?organizationId=' + $(this).val();
76
});
87
});

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"beberlei/assert": "^3.2",
1212
"doctrine/annotations": "^1.8",
1313
"doctrine/doctrine-fixtures-bundle": "^3.3",
14+
"friendsofsymfony/jsrouting-bundle": "^2.5",
1415
"martin-georgiev/postgresql-for-doctrine": "^1.3",
1516
"odolbeau/phone-number-bundle": "^3.0",
1617
"sensio/framework-extra-bundle": "5.*",

composer.lock

+103-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/bundles.php

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true, 'panther' => true],
2222
Hautelook\AliceBundle\HautelookAliceBundle::class => ['dev' => true, 'test' => true, 'panther' => true],
2323
Misd\PhoneNumberBundle\MisdPhoneNumberBundle::class => ['all' => true],
24+
FOS\JsRoutingBundle\FOSJsRoutingBundle::class => ['all' => true],
2425
];

config/routes.yaml

+40-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,58 @@
1+
# {organization} parameter is useless for the moment, but will be useful in ticket https://github.com/crf-devs/resop/issues/338
12
_organizations:
23
resource: ../src/Controller/Organization/
34
type: annotation
45
prefix: /organizations
56

6-
_organizations_planning:
7-
resource: ../src/Controller/Organization/Planning
7+
_organizations_asset_types:
8+
resource: ../src/Controller/Organization/AssetType
89
type: annotation
9-
prefix: /organizations/planning
10+
prefix: /organizations/{organization}/assetTypes
11+
requirements:
12+
organization: '\d+'
1013

11-
_organizations_missions:
12-
resource: ../src/Controller/Organization/Mission
14+
_organizations_children:
15+
resource: ../src/Controller/Organization/Children
1316
type: annotation
14-
# TODO Use organization ID
15-
prefix: /organizations/missions
17+
prefix: /organizations/{organization}/children
18+
requirements:
19+
organization: '\d+'
1620

1721
_organizations_assets:
1822
resource: ../src/Controller/Organization/CommissionableAsset
1923
type: annotation
2024
prefix: /organizations/{organization}/assets
2125
requirements:
2226
organization: '\d+'
23-
27+
28+
_organizations_forecast:
29+
resource: ../src/Controller/Organization/Forecast
30+
type: annotation
31+
prefix: /organizations/{organization}/forecast
32+
requirements:
33+
organization: '\d+'
34+
35+
_organizations_missions:
36+
resource: ../src/Controller/Organization/Mission
37+
type: annotation
38+
prefix: /organizations/{organization}/missions
39+
requirements:
40+
organization: '\d+'
41+
42+
_organizations_mission_types:
43+
resource: ../src/Controller/Organization/MissionType
44+
type: annotation
45+
prefix: /organizations/{organization}/mission_type
46+
requirements:
47+
organization: '\d+'
48+
49+
_organizations_planning:
50+
resource: ../src/Controller/Organization/Planning
51+
type: annotation
52+
prefix: /organizations/{organization}/planning
53+
requirements:
54+
organization: '\d+'
55+
2456
_organizations_users:
2557
resource: ../src/Controller/Organization/User
2658
type: annotation

config/routes/fos_js_routing.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fos_js_routing:
2+
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing-sf4.xml"

config/services.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ services:
125125
arguments:
126126
$cacheStrategy: '@Twig\CacheExtension\CacheStrategyInterface'
127127

128+
App\Twig\Extension\OrganizationExtension:
129+
arguments:
130+
$routingExtension: '@twig.extension.routing'
131+
128132
# declared as public because needed in a migration
129133
App\Domain\SkillSetDomain:
130134
public: true

features/organization/assets.feature

+6-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Feature:
1010

1111
Scenario: As an organization, I can list the assets from my organization
1212
Given I am authenticated as "DT75"
13-
And I am on "/organizations"
13+
And I am on "/organizations/201"
1414
When I follow "Afficher la liste de mes véhicules"
1515
Then I should be on "/organizations/201/assets/"
1616
And the response status code should be 200
@@ -22,12 +22,12 @@ Feature:
2222

2323
Scenario: As a parent organization, I can list the assets from my children organizations
2424
Given I am authenticated as "DT75"
25-
And I am on "/organizations"
25+
And I am on "/organizations/201"
2626
When I follow "Modifier mes structures"
27-
Then I should be on "/organizations/children"
27+
Then I should be on "/organizations/201/children/"
2828
And the response status code should be 200
2929
When I follow "Liste des véhicules"
30-
Then I should be on "/organizations/203/assets/"
30+
Then I should be on "/organizations/201/assets/?organizationId=203"
3131
And the response status code should be 200
3232
And I should see "75012"
3333
And I should see "75016"
@@ -104,16 +104,9 @@ Feature:
104104

105105
Scenario: As a parent organization, I cannot update an invalid asset
106106
Given I am authenticated as "DT75"
107-
When I go to "/organizations/201/assets/75012/edit"
107+
When I go to "/organizations/201/assets/77102/edit"
108108
Then the response status code should be 404
109109

110-
Scenario: As a parent organization, I can delete an asset from my organization or children organizations
111-
Given I am on "/organizations/login"
112-
When I select "DT75" from "identifier"
113-
And I fill in "password" with "covid19"
114-
And I press "Je me connecte"
115-
Then I should be on "/organizations/"
116-
117110
@javascript
118111
Scenario: As a parent organization, I can delete an asset from my organization or children organizations
119112
Given I am authenticated as "DT75"
@@ -122,7 +115,7 @@ Feature:
122115
And I wait for "#delete-item-modal" to be visible
123116
Then I should see "Vous êtes sur le point de supprimer le véhicule suivant et toutes ses disponibilités : VPSP - 75012"
124117
When I press "Supprimer"
125-
Then I should be on "/organizations/203/assets/"
118+
Then I should be on "/organizations/201/assets/?organizationId=203"
126119
And I should see "Le véhicule a été supprimé avec succès."
127120
And I should not see "75012"
128121

0 commit comments

Comments
 (0)