From ddcdaccbe05c33cc66ce531a2af21d403eb67701 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Tue, 5 May 2020 16:31:54 +0200 Subject: [PATCH] Check Scene.guestAccessEnabled flag on guest application of scene --- .../sa4/sanmarinoes/smarthut/controller/SceneController.java | 2 +- .../inf/sa4/sanmarinoes/smarthut/models/SceneRepository.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java index 2eeaaef..f2d0795 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SceneController.java @@ -70,7 +70,7 @@ public class SceneController { Utils.returnIfGuest(userRepository, null, hostId, principal); return sceneService.applyAsGuest( sceneRepository - .findByIdAndUserId(id, hostId) + .findByIdAndUserIdAndGuestAccessEnabled(id, hostId, true) .orElseThrow(NotFoundException::new), principal.getName(), hostId); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SceneRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SceneRepository.java index 028f292..8b6e4f1 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SceneRepository.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/SceneRepository.java @@ -23,5 +23,6 @@ public interface SceneRepository extends CrudRepository { @Query("SELECT s FROM Scene s JOIN s.user u WHERE u.id = ?1 AND s.guestAccessEnabled = true") List findByHostId(Long hostId); - Optional findByIdAndUserId(Long id, Long userId); + Optional findByIdAndUserIdAndGuestAccessEnabled( + Long id, Long userId, boolean guestAccessEnabled); }