Skip to content

Commit

Permalink
Merge pull request #12903 from SORMAS-Foundation/feature-12697_additi…
Browse files Browse the repository at this point in the history
…onal_restrictions_added

Feature 12697 additional restrictions added
  • Loading branch information
sergiupacurariu authored Jan 23, 2024
2 parents adc9322 + abe0dbd commit 7c4fdab
Show file tree
Hide file tree
Showing 83 changed files with 1,858 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@
public abstract class JurisdictionValidator<T> {

protected List<? extends JurisdictionValidator<T>> associatedJurisdictionValidators;
private boolean userHasRestrictedAccess;

public JurisdictionValidator(List<? extends JurisdictionValidator<T>> associatedJurisdictionValidators) {
public JurisdictionValidator(List<? extends JurisdictionValidator<T>> associatedJurisdictionValidators, boolean userHasRestrictedAccess) {
this.associatedJurisdictionValidators = associatedJurisdictionValidators;
this.userHasRestrictedAccess = userHasRestrictedAccess;
}

// disease restriction overrules entity ownership
public T inJurisdictionOrOwned() {
T rootInJurisdictionOrOwned = isRootInJurisdictionOrOwned();
T rootInJurisdictionOrOwned = isRootAccessible();
T rootHasLimitedDisease = hasUserLimitedDisease();
if (associatedJurisdictionValidators != null && !associatedJurisdictionValidators.isEmpty()) {
final List<T> jurisdictionTypes = new ArrayList<>();
jurisdictionTypes.add(and(rootInJurisdictionOrOwned, rootHasLimitedDisease));
for (JurisdictionValidator<T> jurisdictionValidator : associatedJurisdictionValidators) {
if (jurisdictionValidator != null) {
T associatedInJurisdictionOrOwned = jurisdictionValidator.isRootInJurisdictionOrOwned();
T associatedInJurisdictionOrOwned = jurisdictionValidator.isRootAccessible();
T associatedHasLimitedDisease = jurisdictionValidator.hasUserLimitedDisease();
jurisdictionTypes.add(and(associatedInJurisdictionOrOwned, associatedHasLimitedDisease));
}
Expand Down Expand Up @@ -68,12 +70,21 @@ public T inJurisdiction() {
}
}

public T isRootAccessible() {
if (userHasRestrictedAccess) {
return isRootInJurisdictionForRestrictedAccess();
}
return isRootInJurisdictionOrOwned();
}

public abstract T isRootInJurisdiction();

public abstract T isRootInJurisdictionOrOwned();

public abstract T hasUserLimitedDisease();

public abstract T isRootInJurisdictionForRestrictedAccess();

protected T isInJurisdictionByJurisdictionLevel(JurisdictionLevel jurisdictionLevel) {

switch (jurisdictionLevel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,17 @@ public void deleteCaseAndAllDependingEntities(String caseUuid) throws SQLExcepti
deleteCascade(caze);
}

public List<Case> getByPerson(Person person) {
try {
QueryBuilder qb = queryBuilder();
qb.where().eq(Case.PERSON, person);
return qb.query();
} catch (SQLException e) {
Log.e(getTableName(), "Could not perform queryByCriteria on Contact");
throw new RuntimeException(e);
}
}

public List<Case> getSimilarCases(CaseSimilarityCriteria criteria) {
try {
QueryBuilder<Case, Long> queryBuilder = queryBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@ public Boolean isRootInJurisdiction() {
return isInJurisdictionByJurisdictionLevel(userJurisdiction.getJurisdictionLevel());
}

@Override
public Boolean isRootInJurisdictionOrOwned() {
return userJurisdiction.getUuid().equals(caseJurisdiction.getReportingUserUuid()) || inJurisdiction();
}
@Override
public Boolean isRootInJurisdictionOrOwned() {
return getReportedByCurrentUser() || inJurisdiction();
}

private boolean getReportedByCurrentUser() {
return userJurisdiction.getUuid().equals(caseJurisdiction.getReportingUserUuid());
}

@Override
public Boolean isRootInJurisdictionForRestrictedAccess() {
return getReportedByCurrentUser() || userJurisdiction.getUuid().equals(caseJurisdiction.getSurveillanceOfficerUuid());
}

@Override
protected Disease getDisease() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CaseJurisdictionDto implements Serializable {
private String healthFacilityUuid;
private String pointOfEntryUuid;
private List<String> sampleLabUuids;
private String surveillanceOfficerUuid;

public CaseJurisdictionDto() {
}
Expand Down Expand Up @@ -118,4 +119,13 @@ public List<String> getSampleLabUuids() {
public void setSampleLabUuids(List<String> sampleLabUuids) {
this.sampleLabUuids = sampleLabUuids;
}

public String getSurveillanceOfficerUuid() {
return surveillanceOfficerUuid;
}

public CaseJurisdictionDto setSurveillanceOfficerUuid(String surveillanceOfficerUuid) {
this.surveillanceOfficerUuid = surveillanceOfficerUuid;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public static final String DATABASE_NAME = "sormas.db";
// any time you make changes to your database objects, you may have to increase the database version

public static final int DATABASE_VERSION = 358;
public static final int DATABASE_VERSION = 359;

private static DatabaseHelper instance = null;

Expand Down Expand Up @@ -3174,6 +3174,11 @@ public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int
currentVersion = 357;
getDao(CustomizableEnumValue.class).executeRaw("ALTER TABLE customizableEnumValue ADD COLUMN active boolean default true;");

case 358:
currentVersion = 358;
getDao(UserRole.class)
.executeRaw("ALTER TABLE userroles ADD COLUMN restrictAccessToAssignedEntities boolean NOT NULL DEFAULT false;");

// ATTENTION: break should only be done after last version
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ public List<Contact> queryByCriteria(ContactCriteria criteria, long offset, long
}
}

public List<Contact> getByPerson(Person person) {
try {
QueryBuilder qb = queryBuilder();
qb.where().eq(Contact.PERSON, person);
return qb.query();
} catch (SQLException e) {
Log.e(getTableName(), "Could not perform queryByCriteria on Contact");
throw new RuntimeException(e);
}
}

private QueryBuilder<Contact, Long> buildQueryBuilder(ContactCriteria contactCriteria) throws SQLException {
QueryBuilder<Contact, Long> queryBuilder = queryBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,20 @@ public Boolean isRootInJurisdiction() {
return isInJurisdictionByJurisdictionLevel(userJurisdiction.getJurisdictionLevel());
}

@Override
public Boolean isRootInJurisdictionOrOwned() {
return userJurisdiction.getUuid().equals(contactJurisdictionDto.getReportingUserUuid()) || inJurisdiction();
@Override
public Boolean isRootInJurisdictionOrOwned() {
return isReportedByCurrentUser() || inJurisdiction();
}

private boolean isReportedByCurrentUser(){
return userJurisdiction.getUuid().equals(contactJurisdictionDto.getReportingUserUuid());
}

@Override
public Boolean isRootInJurisdictionForRestrictedAccess() {
return isReportedByCurrentUser() || userJurisdiction.getUuid().equals(contactJurisdictionDto.getContactOfficerUuid());
}

@Override
protected Disease getDisease() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class ContactJurisdictionDto implements Serializable {

private CaseJurisdictionDto caseJurisdiction;

private String contactOfficerUuid;

public ContactJurisdictionDto() {

}
Expand Down Expand Up @@ -110,4 +112,13 @@ public List<String> getSampleLabUuids() {
public void setSampleLabUuids(List<String> sampleLabUuids) {
this.sampleLabUuids = sampleLabUuids;
}

public String getContactOfficerUuid() {
return contactOfficerUuid;
}

public ContactJurisdictionDto setContactOfficerUuid(String contactOfficerUuid) {
this.contactOfficerUuid = contactOfficerUuid;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,20 @@ public Boolean isRootInJurisdiction() {

@Override
public Boolean isRootInJurisdictionOrOwned() {
return userJurisdiction.getUuid().equals(environmentJurisdiction.getReportingUserUuid())
|| userJurisdiction.getUuid().equals(environmentJurisdiction.getResponsibleUserUuid())
|| inJurisdiction();
return isReportedByCurrentUser() || isResponsibleByCurrentUser() || inJurisdiction();
}

private boolean isReportedByCurrentUser() {
return userJurisdiction.getUuid().equals(environmentJurisdiction.getReportingUserUuid());
}

private boolean isResponsibleByCurrentUser() {
return userJurisdiction.getUuid().equals(environmentJurisdiction.getResponsibleUserUuid());
}

@Override
public Boolean isRootInJurisdictionForRestrictedAccess() {
return isReportedByCurrentUser() || isResponsibleByCurrentUser();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ public Boolean isRootInJurisdiction() {

@Override
public Boolean isRootInJurisdictionOrOwned() {
return userJurisdiction.getUuid().equals(environmentSampleJurisdiction.getReportingUserUuid()) || inJurisdiction();
return isReportedByCurrentUser() || inJurisdiction();
}

private boolean isReportedByCurrentUser() {
return userJurisdiction.getUuid().equals(environmentSampleJurisdiction.getReportingUserUuid());
}

@Override
public Boolean isRootInJurisdictionForRestrictedAccess() {
return isReportedByCurrentUser() || userJurisdiction.getUuid().equals(environmentSampleJurisdiction.getEnvironmentResponsibleUser());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class EnvironmentSampleJurisdictionDto implements Serializable {
private String regionUuid;
private String districtUuid;
private String communityUuid;
private String environmentResponsibleUser;

public EnvironmentSampleJurisdictionDto() {
}
Expand Down Expand Up @@ -67,4 +68,11 @@ public void setCommunityUuid(String communityUuid) {
this.communityUuid = communityUuid;
}

public String getEnvironmentResponsibleUser() {
return environmentResponsibleUser;
}

public void setEnvironmentResponsibleUser(String environmentResponsibleUser) {
this.environmentResponsibleUser = environmentResponsibleUser;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
import de.symeda.sormas.app.backend.common.DaoException;
import de.symeda.sormas.app.backend.common.DatabaseHelper;
import de.symeda.sormas.app.backend.config.ConfigProvider;
import de.symeda.sormas.app.backend.contact.Contact;
import de.symeda.sormas.app.backend.location.Location;
import de.symeda.sormas.app.backend.person.Person;
import de.symeda.sormas.app.backend.task.Task;
import de.symeda.sormas.app.util.DiseaseConfigurationCache;
import de.symeda.sormas.app.util.LocationService;
Expand Down Expand Up @@ -260,4 +262,19 @@ private QueryBuilder<Event, Long> buildQueryBuilder(EventCriteria criteria) thro

return queryBuilder;
}
public List<Event> getByEventParticipantPerson(Person person){
try {
QueryBuilder<Event, Long> queryBuilder = queryBuilder();
QueryBuilder<EventParticipant, Long> eventParticipantBuilder = DatabaseHelper.getEventParticipantDao().queryBuilder();
queryBuilder.leftJoin(eventParticipantBuilder);
Where<EventParticipant, Long> where = eventParticipantBuilder.where();

where.eq(EventParticipant.PERSON + "_id", person.getId());

return queryBuilder.query();
} catch (SQLException e) {
Log.e(getTableName(), "Could not perform queryByCriteria on Event");
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,23 @@ public Boolean isRootInJurisdiction() {
return isInJurisdictionByJurisdictionLevel(userJurisdiction.getJurisdictionLevel());
}

@Override
public Boolean isRootInJurisdictionOrOwned() {
return userJurisdiction.getUuid().equals(eventJurisdictionDto.getReportingUserUuid()) || userJurisdiction.getUuid().equals(eventJurisdictionDto.getResponsibleUserUuid()) || inJurisdiction();
}
@Override
public Boolean isRootInJurisdictionOrOwned() {
return getReportedByCurrentUser() || isCurrentUserResponsible() || inJurisdiction();
}

private boolean getReportedByCurrentUser() {
return userJurisdiction.getUuid().equals(eventJurisdictionDto.getReportingUserUuid());
}

public boolean isCurrentUserResponsible() {
return userJurisdiction.getUuid().equals(eventJurisdictionDto.getResponsibleUserUuid());
}

@Override
public Boolean isRootInJurisdictionForRestrictedAccess() {
return getReportedByCurrentUser() || isCurrentUserResponsible();
}

@Override
protected Disease getDisease() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public String getResponsibleUserUuid() {
return responsibleUserUuid;
}

public void setResponsibleUserUuid(String responsibleUserUuid) {
public EventJurisdictionDto setResponsibleUserUuid(String responsibleUserUuid) {
this.responsibleUserUuid = responsibleUserUuid;
return this;
}

public String getRegionUuid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ public Boolean isRootInJurisdiction() {

@Override
public Boolean isRootInJurisdictionOrOwned() {
return userJurisdiction.getUuid().equals(eventParticipantJurisdictionDto.getReportingUserUuid()) || inJurisdiction();
return getReportedByCurrentUser() || inJurisdiction();
}

private boolean getReportedByCurrentUser() {
return userJurisdiction.getUuid().equals(eventParticipantJurisdictionDto.getReportingUserUuid());
}

@Override
public Boolean isRootInJurisdictionForRestrictedAccess() {
return getReportedByCurrentUser() || userJurisdiction.getUuid().equals(eventParticipantJurisdictionDto.getEventResponsibleUserUuid());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class EventParticipantJurisdictionDto implements Serializable {
private String districtUuid;
private String eventUuid;
private EventJurisdictionDto eventJurisdictionDto;
private String eventResponsibleUserUuid;

public EventParticipantJurisdictionDto() {
}
Expand Down Expand Up @@ -96,4 +97,12 @@ public EventJurisdictionDto getEventJurisdictionDto() {
public void setEventJurisdictionDto(EventJurisdictionDto eventJurisdictionDto) {
this.eventJurisdictionDto = eventJurisdictionDto;
}

public String getEventResponsibleUserUuid() {
return eventResponsibleUserUuid;
}

public void setEventResponsibleUserUuid(String eventResponsibleUserUuid) {
this.eventResponsibleUserUuid = eventResponsibleUserUuid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@

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

import java.util.ArrayList;
import java.util.List;

import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.utils.DataHelper;
import de.symeda.sormas.app.backend.caze.CaseJurisdictionDto;
import de.symeda.sormas.app.backend.caze.ResponsibleJurisdictionDto;
import de.symeda.sormas.app.backend.person.PersonJurisdictionBooleanValidator;
import de.symeda.sormas.app.util.BooleanJurisdictionValidator;
import de.symeda.sormas.app.util.UserJurisdiction;

Expand Down Expand Up @@ -48,6 +53,13 @@ public Boolean isRootInJurisdictionOrOwned() {
return userJurisdiction.getUuid().equals(immunizationJurisdiction.getReportingUserUuid()) || inJurisdiction();
}

@Override
public Boolean isRootInJurisdictionForRestrictedAccess() {
PersonJurisdictionBooleanValidator personJurisdictionBooleanValidator = new PersonJurisdictionBooleanValidator(userJurisdiction, immunizationJurisdiction.getPersonJurisdiction());

return isRootInJurisdictionOrOwned() && personJurisdictionBooleanValidator.isRootInJurisdictionForRestrictedAccess();
}

@Override
protected Disease getDisease() {
return null;
Expand Down
Loading

0 comments on commit 7c4fdab

Please sign in to comment.