Skip to content

Commit 8f6a1ff

Browse files
authored
Merge pull request #3633 from betagouv/claim-update-redirect
Après avoir révendiquer une cantine sur la page SIRET, rediriger l'utilisateur vers la page modification de la cantine
2 parents ebff156 + a051599 commit 8f6a1ff

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

api/serializers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
CanteenTeledeclarationSerializer,
1212
SatelliteTeledeclarationSerializer,
1313
ElectedCanteenSerializer,
14+
MinimalCanteenSerializer,
1415
)
1516
from .diagnostic import ( # noqa: F401
1617
ManagerDiagnosticSerializer,

api/tests/test_published_canteens.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,14 @@ def test_canteen_claim_value(self):
579579

580580
@authenticate
581581
def test_canteen_claim_request(self):
582-
canteen = CanteenFactory.create(publication_status=Canteen.PublicationStatus.PUBLISHED.value)
582+
canteen = CanteenFactory.create(publication_status=Canteen.PublicationStatus.DRAFT)
583583
canteen.managers.clear()
584584

585585
response = self.client.post(reverse("claim_canteen", kwargs={"canteen_pk": canteen.id}), None)
586586
self.assertEqual(response.status_code, status.HTTP_200_OK)
587+
body = response.json()
588+
self.assertEqual(body["id"], canteen.id)
589+
self.assertEqual(body["name"], canteen.name)
587590
user = authenticate.user
588591
self.assertEqual(canteen.managers.first().id, user.id)
589592
self.assertEqual(canteen.managers.count(), 1)

api/views/canteen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
CanteenActionsSerializer,
3636
CanteenStatusSerializer,
3737
ElectedCanteenSerializer,
38+
MinimalCanteenSerializer,
3839
)
3940
from data.models import Canteen, ManagerInvitation, Sector, Diagnostic, Teledeclaration, Purchase
4041
from data.region_choices import Region
@@ -1047,7 +1048,7 @@ def post(self, request, canteen_pk):
10471048
canteen.claimed_by = self.request.user
10481049
canteen.has_been_claimed = True
10491050
canteen.save()
1050-
return JsonResponse({}, status=status.HTTP_200_OK)
1051+
return JsonResponse(camelize(MinimalCanteenSerializer(canteen).data), status=status.HTTP_200_OK)
10511052

10521053

10531054
class UndoClaimCanteenView(APIView):

frontend/src/views/CanteenEditor/SiretCheck.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export default {
180180
this.requestSent = true
181181
this.$store.dispatch("notify", {
182182
status: "success",
183-
message: `Votre message a bien été envoyé.`,
183+
message: "Votre message a bien été envoyé.",
184184
})
185185
window.scrollTo(0, 0)
186186
})
@@ -190,8 +190,18 @@ export default {
190190
const canteenId = this.duplicateSiretCanteen.id
191191
return this.$store
192192
.dispatch("claimCanteen", { canteenId })
193-
.then(() => (this.requestSent = true))
194193
.catch((e) => this.$store.dispatch("notifyServerError", e))
194+
.then((response) => {
195+
this.$store.dispatch("notify", {
196+
status: "success",
197+
message: "Vous gérez maintenant cet établissement.",
198+
})
199+
this.$router.push({
200+
name: "CanteenForm",
201+
params: { canteenUrlComponent: this.$store.getters.getCanteenUrlComponent(response) },
202+
})
203+
})
204+
.catch(() => this.$router.push({ name: "ManagementPage" }))
195205
},
196206
saveSiretIfNeeded() {
197207
if (!this.canteen?.id) return Promise.resolve()

0 commit comments

Comments
 (0)