Skip to content

Commit

Permalink
Merge pull request #12668 from SORMAS-Foundation/change-10796-sync_di…
Browse files Browse the repository at this point in the history
…alog_entities_shown

Change 10796 sync dialog entities shown
  • Loading branch information
sergiupacurariu authored Oct 23, 2023
2 parents a776b1a + ae8d007 commit e8706e4
Show file tree
Hide file tree
Showing 5 changed files with 568 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@

package de.symeda.sormas.api.user;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import de.symeda.sormas.api.campaign.CampaignDto;
import de.symeda.sormas.api.campaign.data.CampaignFormDataDto;
Expand All @@ -43,84 +47,84 @@

public class DtoViewAndEditRights {

private static Map<String, UserRight> viewRights = new HashMap<>();
private static Map<String, UserRight> editRights = new HashMap<>();
private static final Map<String, Set<UserRight>> viewRights = new HashMap<>();
private static final Map<String, Set<UserRight>> editRights = new HashMap<>();

static {
viewRights.put(AdditionalTestDto.class.getSimpleName(), UserRight.ADDITIONAL_TEST_VIEW);
editRights.put(AdditionalTestDto.class.getSimpleName(), UserRight.ADDITIONAL_TEST_EDIT);
viewRights.put(AdditionalTestDto.class.getSimpleName(), Collections.singleton(UserRight.ADDITIONAL_TEST_VIEW));
editRights.put(AdditionalTestDto.class.getSimpleName(), Collections.singleton(UserRight.ADDITIONAL_TEST_EDIT));

viewRights.put(AggregateReportDto.class.getSimpleName(), UserRight.AGGREGATE_REPORT_VIEW);
editRights.put(AggregateReportDto.class.getSimpleName(), UserRight.AGGREGATE_REPORT_EDIT);
viewRights.put(AggregateReportDto.class.getSimpleName(), Collections.singleton(UserRight.AGGREGATE_REPORT_VIEW));
editRights.put(AggregateReportDto.class.getSimpleName(), Collections.singleton(UserRight.AGGREGATE_REPORT_EDIT));

viewRights.put(CaseDataDto.class.getSimpleName(), UserRight.CASE_VIEW);
editRights.put(CaseDataDto.class.getSimpleName(), UserRight.CASE_EDIT);
viewRights.put(CaseDataDto.class.getSimpleName(), Collections.singleton(UserRight.CASE_VIEW));
editRights.put(CaseDataDto.class.getSimpleName(), Collections.singleton(UserRight.CASE_EDIT));

viewRights.put(ClinicalVisitDto.class.getSimpleName(), UserRight.CLINICAL_COURSE_VIEW);
editRights.put(ClinicalVisitDto.class.getSimpleName(), UserRight.CLINICAL_VISIT_EDIT);
viewRights.put(ClinicalVisitDto.class.getSimpleName(), Collections.singleton(UserRight.CLINICAL_COURSE_VIEW));
editRights.put(ClinicalVisitDto.class.getSimpleName(), Collections.singleton(UserRight.CLINICAL_VISIT_EDIT));

viewRights.put(ContactDto.class.getSimpleName(), UserRight.CONTACT_VIEW);
editRights.put(ContactDto.class.getSimpleName(), UserRight.CONTACT_EDIT);
viewRights.put(ContactDto.class.getSimpleName(), Collections.singleton(UserRight.CONTACT_VIEW));
editRights.put(ContactDto.class.getSimpleName(), Collections.singleton(UserRight.CONTACT_EDIT));

viewRights.put(EnvironmentDto.class.getSimpleName(), UserRight.ENVIRONMENT_VIEW);
editRights.put(EnvironmentDto.class.getSimpleName(), UserRight.ENVIRONMENT_EDIT);
viewRights.put(EnvironmentDto.class.getSimpleName(), Collections.singleton(UserRight.ENVIRONMENT_VIEW));
editRights.put(EnvironmentDto.class.getSimpleName(), Collections.singleton(UserRight.ENVIRONMENT_EDIT));

viewRights.put(EnvironmentSampleDto.class.getSimpleName(), UserRight.ENVIRONMENT_SAMPLE_VIEW);
editRights.put(EnvironmentSampleDto.class.getSimpleName(), UserRight.ENVIRONMENT_SAMPLE_EDIT);
viewRights.put(EnvironmentSampleDto.class.getSimpleName(), Collections.singleton(UserRight.ENVIRONMENT_SAMPLE_VIEW));
editRights.put(EnvironmentSampleDto.class.getSimpleName(), Collections.singleton(UserRight.ENVIRONMENT_SAMPLE_EDIT));

viewRights.put(EventDto.class.getSimpleName(), UserRight.EVENT_VIEW);
editRights.put(EventDto.class.getSimpleName(), UserRight.EVENT_EDIT);
viewRights.put(EventDto.class.getSimpleName(), Collections.singleton(UserRight.EVENT_VIEW));
editRights.put(EventDto.class.getSimpleName(), Collections.singleton(UserRight.EVENT_EDIT));

viewRights.put(EventParticipantDto.class.getSimpleName(), UserRight.EVENTPARTICIPANT_VIEW);
editRights.put(EventParticipantDto.class.getSimpleName(), UserRight.EVENTPARTICIPANT_EDIT);
viewRights.put(EventParticipantDto.class.getSimpleName(), Collections.singleton(UserRight.EVENTPARTICIPANT_VIEW));
editRights.put(EventParticipantDto.class.getSimpleName(), Collections.singleton(UserRight.EVENTPARTICIPANT_EDIT));

viewRights.put(ImmunizationDto.class.getSimpleName(), UserRight.IMMUNIZATION_VIEW);
editRights.put(ImmunizationDto.class.getSimpleName(), UserRight.IMMUNIZATION_EDIT);
viewRights.put(ImmunizationDto.class.getSimpleName(), Collections.singleton(UserRight.IMMUNIZATION_VIEW));
editRights.put(ImmunizationDto.class.getSimpleName(), Collections.singleton(UserRight.IMMUNIZATION_EDIT));

viewRights.put(OutbreakDto.class.getSimpleName(), UserRight.OUTBREAK_VIEW);
editRights.put(OutbreakDto.class.getSimpleName(), UserRight.OUTBREAK_EDIT);
viewRights.put(OutbreakDto.class.getSimpleName(), Collections.singleton(UserRight.OUTBREAK_VIEW));
editRights.put(OutbreakDto.class.getSimpleName(), Collections.singleton(UserRight.OUTBREAK_EDIT));

// no explicit UserRight to view PathogenTestDto
editRights.put(PathogenTestDto.class.getSimpleName(), UserRight.PATHOGEN_TEST_EDIT);
viewRights.put(
PathogenTestDto.class.getSimpleName(),
Stream.of(UserRight.SAMPLE_VIEW, UserRight.ENVIRONMENT_SAMPLE_VIEW).collect(Collectors.toSet()));
editRights.put(PathogenTestDto.class.getSimpleName(), Collections.singleton(UserRight.PATHOGEN_TEST_EDIT));

viewRights.put(PersonDto.class.getSimpleName(), UserRight.PERSON_VIEW);
editRights.put(PersonDto.class.getSimpleName(), UserRight.PERSON_EDIT);
viewRights.put(PersonDto.class.getSimpleName(), Collections.singleton(UserRight.PERSON_VIEW));
editRights.put(PersonDto.class.getSimpleName(), Collections.singleton(UserRight.PERSON_EDIT));

viewRights.put(PrescriptionDto.class.getSimpleName(), UserRight.CASE_VIEW);
editRights.put(PrescriptionDto.class.getSimpleName(), UserRight.PRESCRIPTION_EDIT);
viewRights.put(PrescriptionDto.class.getSimpleName(), Collections.singleton(UserRight.THERAPY_VIEW));
editRights.put(PrescriptionDto.class.getSimpleName(), Collections.singleton(UserRight.PRESCRIPTION_EDIT));

viewRights.put(SampleDto.class.getSimpleName(), UserRight.SAMPLE_VIEW);
editRights.put(SampleDto.class.getSimpleName(), UserRight.SAMPLE_EDIT);
viewRights.put(TreatmentDto.class.getSimpleName(), Collections.singleton(UserRight.THERAPY_VIEW));
editRights.put(TreatmentDto.class.getSimpleName(), Collections.singleton(UserRight.TREATMENT_EDIT));

viewRights.put(TaskDto.class.getSimpleName(), UserRight.TASK_VIEW);
editRights.put(TaskDto.class.getSimpleName(), UserRight.TASK_EDIT);
viewRights.put(SampleDto.class.getSimpleName(), Collections.singleton(UserRight.SAMPLE_VIEW));
editRights.put(SampleDto.class.getSimpleName(), Collections.singleton(UserRight.SAMPLE_EDIT));

viewRights.put(TreatmentDto.class.getSimpleName(), UserRight.CASE_VIEW);
editRights.put(TreatmentDto.class.getSimpleName(), UserRight.TREATMENT_EDIT);
viewRights.put(TaskDto.class.getSimpleName(), Collections.singleton(UserRight.TASK_VIEW));
editRights.put(TaskDto.class.getSimpleName(), Collections.singleton(UserRight.TASK_EDIT));

// can be with CONTACT_VIEW, too. Currently all user roles that can view
// cases can also view contacts.
viewRights.put(VisitDto.class.getSimpleName(), UserRight.CASE_VIEW);
editRights.put(VisitDto.class.getSimpleName(), UserRight.VISIT_EDIT);
viewRights.put(VisitDto.class.getSimpleName(), Stream.of(UserRight.CASE_VIEW, UserRight.CONTACT_VIEW).collect(Collectors.toSet()));
editRights.put(VisitDto.class.getSimpleName(), Collections.singleton(UserRight.VISIT_EDIT));

viewRights.put(WeeklyReportDto.class.getSimpleName(), UserRight.WEEKLYREPORT_VIEW);
// no explicit UserRight to edit WeeklyReportDto
viewRights.put(WeeklyReportDto.class.getSimpleName(), Collections.singleton(UserRight.WEEKLYREPORT_VIEW));
editRights.put(WeeklyReportDto.class.getSimpleName(), Collections.singleton(UserRight.WEEKLYREPORT_CREATE));

viewRights.put(CampaignFormMetaDto.class.getSimpleName(), UserRight.CAMPAIGN_VIEW);
editRights.put(CampaignFormMetaDto.class.getSimpleName(), UserRight.CAMPAIGN_EDIT);
viewRights.put(CampaignFormMetaDto.class.getSimpleName(), Collections.singleton(UserRight.CAMPAIGN_VIEW));
editRights.put(CampaignFormMetaDto.class.getSimpleName(), Collections.singleton(UserRight.CAMPAIGN_EDIT));

viewRights.put(CampaignDto.class.getSimpleName(), UserRight.CAMPAIGN_VIEW);
editRights.put(CampaignDto.class.getSimpleName(), UserRight.CAMPAIGN_EDIT);
viewRights.put(CampaignDto.class.getSimpleName(), Collections.singleton(UserRight.CAMPAIGN_VIEW));
editRights.put(CampaignDto.class.getSimpleName(), Collections.singleton(UserRight.CAMPAIGN_EDIT));

viewRights.put(CampaignFormDataDto.class.getSimpleName(), UserRight.CAMPAIGN_FORM_DATA_VIEW);
editRights.put(CampaignFormDataDto.class.getSimpleName(), UserRight.CAMPAIGN_FORM_DATA_EDIT);
viewRights.put(CampaignFormDataDto.class.getSimpleName(), Collections.singleton(UserRight.CAMPAIGN_FORM_DATA_VIEW));
editRights.put(CampaignFormDataDto.class.getSimpleName(), Collections.singleton(UserRight.CAMPAIGN_FORM_DATA_EDIT));
}

public static UserRight getUserRightView(Class clazz) {
public static Set<UserRight> getUserRightsView(Class<?> clazz) {
return viewRights.get(clazz.getSimpleName());
}

public static UserRight getUserRightEdit(Class clazz) {
public static Set<UserRight> getUserRightsEdit(Class<?> clazz) {
return editRights.get(clazz.getSimpleName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public static boolean isFeatureConfigForSampleEnabled() {
return DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(FeatureType.SAMPLES_LAB);
}

public static boolean isFeatureConfigForSampleTestsEnabled() {
return DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(FeatureType.SAMPLES_LAB);
public static boolean isFeatureConfigForPathogenTestsEnabled() {
return DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(FeatureType.SAMPLES_LAB)
|| DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(FeatureType.ENVIRONMENT_MANAGEMENT);
}

public static boolean isFeatureConfigForAdditionalTestsEnabled() {
Expand Down Expand Up @@ -69,11 +70,11 @@ public static boolean isFeatureConfigForAggregateReportsEnabled() {
}

public static boolean isFeatureConfigForPrescriptionsEnabled() {
return DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(FeatureType.CASE_SURVEILANCE);
return DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(FeatureType.CLINICAL_MANAGEMENT);
}

public static boolean isFeatureConfigForTreatmentsEnabled() {
return DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(FeatureType.CASE_SURVEILANCE);
return DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(FeatureType.CLINICAL_MANAGEMENT);
}

public static boolean isFeatureConfigForClinicalVisitsEnabled() {
Expand All @@ -83,4 +84,12 @@ public static boolean isFeatureConfigForClinicalVisitsEnabled() {
public static boolean isFeatureConfigForEnvironmentEnabled() {
return DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(FeatureType.ENVIRONMENT_MANAGEMENT);
}

public static boolean isFeatureConfigForEnvironmentSamplesEnabled() {
return DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(FeatureType.ENVIRONMENT_MANAGEMENT);
}

public static boolean isFeatureConfigForCampaignsEnabled() {
return DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(FeatureType.CAMPAIGNS);
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,57 @@
/*
* SORMAS® - Surveillance Outbreak Response Management & Analysis System
* Copyright © 2016-2022 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

package de.symeda.sormas.app.backend.common;

import java.util.Map;
import java.util.Set;

import de.symeda.sormas.api.feature.FeatureType;
import de.symeda.sormas.api.user.DtoViewAndEditRights;
import de.symeda.sormas.api.user.UserRight;
import de.symeda.sormas.app.backend.config.ConfigProvider;

public class DtoUserRightsHelper {

public static boolean isViewAllowed(Class clazz) {
UserRight userRightView = DtoViewAndEditRights.getUserRightView(clazz);
return userRightView == null || ConfigProvider.hasUserRight(userRightView);
public static boolean isViewAllowed(Class<?> clazz) {
Set<UserRight> userRightsView = DtoViewAndEditRights.getUserRightsView(clazz);
return userRightsView == null || userRightsView.stream().anyMatch(ConfigProvider::hasUserRight);
}

public static boolean isViewAllowedWithFeatureDependencies(Class<?> clazz, Map<UserRight, FeatureType> featureDependencies) {
Set<UserRight> userRightsView = DtoViewAndEditRights.getUserRightsView(clazz);
return userRightsView == null
|| userRightsView.stream()
.anyMatch(
r -> ConfigProvider.hasUserRight(r)
&& (!featureDependencies.containsKey(r)
|| DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(featureDependencies.get(r))));
}

public static boolean isEditAllowed(Class<?> clazz) {
Set<UserRight> userRightsEdit = DtoViewAndEditRights.getUserRightsEdit(clazz);
return userRightsEdit == null || userRightsEdit.stream().anyMatch(ConfigProvider::hasUserRight);
}

public static boolean isEditAllowed(Class clazz) {
UserRight userRightEdit = DtoViewAndEditRights.getUserRightEdit(clazz);
return userRightEdit == null || ConfigProvider.hasUserRight(userRightEdit);
public static boolean isEditAllowedWithFeatureDependencies(Class<?> clazz, Map<UserRight, FeatureType> featureDependencies) {
Set<UserRight> userRightsEdit = DtoViewAndEditRights.getUserRightsEdit(clazz);
return userRightsEdit == null
|| userRightsEdit.stream()
.anyMatch(
r -> ConfigProvider.hasUserRight(r)
&& (!featureDependencies.containsKey(r)
|| DatabaseHelper.getFeatureConfigurationDao().isFeatureEnabled(featureDependencies.get(r))));
}
}
Loading

0 comments on commit e8706e4

Please sign in to comment.