Skip to content

Commit aeb50ad

Browse files
authored
Disable drawer get resource according feature flag (RedHatInsights#3153)
1 parent fee97da commit aeb50ad

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Diff for: backend/src/main/java/com/redhat/cloud/notifications/routers/DrawerResource.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.redhat.cloud.notifications.routers;
22

3+
import com.redhat.cloud.notifications.config.BackendConfig;
34
import com.redhat.cloud.notifications.db.Query;
45
import com.redhat.cloud.notifications.db.repositories.DrawerNotificationRepository;
56
import com.redhat.cloud.notifications.models.DrawerEntryPayload;
@@ -39,6 +40,9 @@ public class DrawerResource {
3940
@Inject
4041
DrawerNotificationRepository drawerRepository;
4142

43+
@Inject
44+
BackendConfig backendConfig;
45+
4246
@Path(API_NOTIFICATIONS_V_1_0 + "/notifications/drawer")
4347
public static class V1 extends DrawerResource {
4448

@@ -58,10 +62,13 @@ public Page<DrawerEntryPayload> getDrawerEntries(@Context SecurityContext securi
5862
String orgId = getOrgId(securityContext);
5963
String username = getUsername(securityContext);
6064
LocalDateTime start = LocalDateTime.now();
61-
Long count = drawerRepository.count(orgId, username, bundleIds, appIds, eventTypeIds, startDate, endDate, readStatus);
6265
List<DrawerEntryPayload> drawerEntries = new ArrayList<>();
63-
if (count > 0) {
64-
drawerEntries = drawerRepository.getNotifications(orgId, username, bundleIds, appIds, eventTypeIds, startDate, endDate, readStatus, query);
66+
Long count = 0L;
67+
if (backendConfig.isDrawerEnabled()) {
68+
count = drawerRepository.count(orgId, username, bundleIds, appIds, eventTypeIds, startDate, endDate, readStatus);
69+
if (count > 0) {
70+
drawerEntries = drawerRepository.getNotifications(orgId, username, bundleIds, appIds, eventTypeIds, startDate, endDate, readStatus, query);
71+
}
6572
}
6673
LocalDateTime now = LocalDateTime.now();
6774
Log.infof("Drawer request duration %s for orgId: %s, userId: %s",

Diff for: backend/src/test/java/com/redhat/cloud/notifications/routers/DrawerResourceTest.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.redhat.cloud.notifications.MockServerConfig;
55
import com.redhat.cloud.notifications.TestHelpers;
66
import com.redhat.cloud.notifications.TestLifecycleManager;
7+
import com.redhat.cloud.notifications.config.BackendConfig;
78
import com.redhat.cloud.notifications.db.DbIsolatedTest;
89
import com.redhat.cloud.notifications.db.ResourceHelpers;
910
import com.redhat.cloud.notifications.models.Application;
@@ -14,6 +15,7 @@
1415
import com.redhat.cloud.notifications.models.EventType;
1516
import com.redhat.cloud.notifications.routers.models.Page;
1617
import com.redhat.cloud.notifications.routers.models.UpdateNotificationDrawerStatus;
18+
import io.quarkus.test.InjectMock;
1719
import io.quarkus.test.common.QuarkusTestResource;
1820
import io.quarkus.test.junit.QuarkusTest;
1921
import io.restassured.common.mapper.TypeRef;
@@ -39,6 +41,7 @@
3941
import static java.time.ZoneOffset.UTC;
4042
import static org.junit.jupiter.api.Assertions.assertEquals;
4143
import static org.junit.jupiter.api.Assertions.assertTrue;
44+
import static org.mockito.Mockito.when;
4245

4346
@QuarkusTest
4447
@QuarkusTestResource(TestLifecycleManager.class)
@@ -53,9 +56,12 @@ public class DrawerResourceTest extends DbIsolatedTest {
5356
@Inject
5457
ResourceHelpers resourceHelpers;
5558

59+
@InjectMock
60+
BackendConfig backendConfig;
61+
5662
@Test
5763
void testMultiplePages() {
58-
64+
when(backendConfig.isDrawerEnabled()).thenReturn(true);
5965
final String USERNAME = "user-1";
6066
Header defaultIdentityHeader = mockRbac(DEFAULT_ACCOUNT_ID, DEFAULT_ORG_ID, USERNAME, FULL_ACCESS);
6167

@@ -95,7 +101,7 @@ void testMultiplePages() {
95101

96102
@Test
97103
void testFilters() {
98-
104+
when(backendConfig.isDrawerEnabled()).thenReturn(true);
99105
Bundle createdBundle = resourceHelpers.createBundle("test-drawer-event-resource-bundle");
100106
Bundle createdBundle2 = resourceHelpers.createBundle("test-drawer-event-resource-bundle2");
101107
Application createdApplication = resourceHelpers.createApplication(createdBundle.getId(), "test-drawer-event-resource-application");

0 commit comments

Comments
 (0)