From 43351863c23cb4dd459307018ff0dc111ae93b2a Mon Sep 17 00:00:00 2001 From: himeshr Date: Thu, 29 Aug 2024 18:22:03 +0530 Subject: [PATCH] #779 | Introduce User "isIgnoreSyncSettingsInDEA" flag to allow DEA access to transactional entities within Catchment but not matching sync settings --- .../src/main/java/org/avni/server/domain/User.java | 11 +++++++++++ .../main/java/org/avni/server/web/UserController.java | 1 + .../org/avni/server/web/request/UserContract.java | 10 ++++++++++ .../V1_339_7__AddIgnoreSyncSettingsInDEAToUser.sql | 1 + 4 files changed, 23 insertions(+) create mode 100644 avni-server-api/src/main/resources/db/migration/V1_339_7__AddIgnoreSyncSettingsInDEAToUser.sql diff --git a/avni-server-api/src/main/java/org/avni/server/domain/User.java b/avni-server-api/src/main/java/org/avni/server/domain/User.java index 0536d3342..1ed8914c8 100644 --- a/avni-server-api/src/main/java/org/avni/server/domain/User.java +++ b/avni-server-api/src/main/java/org/avni/server/domain/User.java @@ -101,6 +101,9 @@ public class User { @Type(type = "jsonObject") private JsonObject syncSettings; + @Column(name = "ignore_sync_settings_in_dea") + private boolean ignoreSyncSettingsInDEA; + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "user") private List userGroups; @@ -291,6 +294,14 @@ public void setSyncSettings(JsonObject syncSettings) { this.syncSettings = syncSettings; } + public boolean isIgnoreSyncSettingsInDEA() { + return ignoreSyncSettingsInDEA; + } + + public void setIgnoreSyncSettingsInDEA(boolean ignoreSyncSettingsInDEA) { + this.ignoreSyncSettingsInDEA = ignoreSyncSettingsInDEA; + } + public String[] getRoles() { ArrayList roles = new ArrayList<>(); if (!isAdmin()) { diff --git a/avni-server-api/src/main/java/org/avni/server/web/UserController.java b/avni-server-api/src/main/java/org/avni/server/web/UserController.java index 0b17619a2..c1c482c81 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/UserController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/UserController.java @@ -193,6 +193,7 @@ private User setUserAttributes(User user, UserContract userContract) { user.setOperatingIndividualScope(OperatingIndividualScope.valueOf(userContract.getOperatingIndividualScope())); user.setSettings(userContract.getSettings()); + user.setIgnoreSyncSettingsInDEA(userContract.isIgnoreSyncSettingsInDEA()); user.setSyncSettings(UserSyncSettings.fromUserSyncWebJSON(userContract.getSyncSettings(), subjectTypeRepository)); User currentUser = userService.getCurrentUser(); Long organisationId = null; diff --git a/avni-server-api/src/main/java/org/avni/server/web/request/UserContract.java b/avni-server-api/src/main/java/org/avni/server/web/request/UserContract.java index 1c76878c0..a5e8ea536 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/request/UserContract.java +++ b/avni-server-api/src/main/java/org/avni/server/web/request/UserContract.java @@ -22,6 +22,7 @@ public class UserContract extends ReferenceDataContract { private Long organisationId; private List accountIds; private boolean disabledInCognito; + private boolean ignoreSyncSettingsInDEA; private String password; private JsonObject syncSettings; private String createdBy; @@ -40,6 +41,7 @@ public static UserContract fromEntity(User user) { userContract.setPhoneNumber(user.getPhoneNumber()); userContract.setOrganisationId(user.getOrganisationId()); userContract.setDisabledInCognito(user.isDisabledInCognito()); + userContract.setIgnoreSyncSettingsInDEA(user.isIgnoreSyncSettingsInDEA()); userContract.setCatchmentId(user.getCatchmentId().orElse(null)); userContract.setSettings(user.getSettings()); userContract.setCreatedBy(user.getCreatedByUserName()); @@ -61,6 +63,14 @@ public void setDisabledInCognito(boolean disabledInCognito) { this.disabledInCognito = disabledInCognito; } + public boolean isIgnoreSyncSettingsInDEA() { + return ignoreSyncSettingsInDEA; + } + + public void setIgnoreSyncSettingsInDEA(boolean ignoreSyncSettingsInDEA) { + this.ignoreSyncSettingsInDEA = ignoreSyncSettingsInDEA; + } + public Long getOrganisationId() { return organisationId; } diff --git a/avni-server-api/src/main/resources/db/migration/V1_339_7__AddIgnoreSyncSettingsInDEAToUser.sql b/avni-server-api/src/main/resources/db/migration/V1_339_7__AddIgnoreSyncSettingsInDEAToUser.sql new file mode 100644 index 000000000..65c93c7d7 --- /dev/null +++ b/avni-server-api/src/main/resources/db/migration/V1_339_7__AddIgnoreSyncSettingsInDEAToUser.sql @@ -0,0 +1 @@ +alter table users add column ignore_sync_settings_in_DEA boolean not null default false; \ No newline at end of file