Skip to content

Commit

Permalink
COH-58 No authorization required for services
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Aug 16, 2024
1 parent f4259f1 commit 022fcdf
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
*/
package org.openmrs.module.cohort.api;

import static org.openmrs.module.cohort.api.CohortService.EDIT_COHORTS_PRIVILEGE;
import static org.openmrs.module.cohort.api.CohortService.MANAGE_COHORTS_PRIVILEGE;
import static org.openmrs.module.cohort.api.CohortService.VIEW_COHORTS_PRIVILEGE;

import javax.validation.constraints.NotNull;

import java.util.Collection;

import org.openmrs.annotation.Authorized;
import org.openmrs.api.OpenmrsService;
import org.openmrs.module.cohort.CohortMember;
import org.openmrs.module.cohort.CohortMemberAttribute;
Expand All @@ -22,65 +27,85 @@
public interface CohortMemberService extends OpenmrsService {

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortMember getCohortMemberByUuid(@NotNull String uuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortMember getCohortMemberByName(@NotNull String name);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortMember> findAllCohortMembers();

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
CohortMember saveCohortMember(@NotNull CohortMember cohortMember);

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
void voidCohortMember(@NotNull CohortMember cohortMember, String voidReason);

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
void purgeCohortMember(@NotNull CohortMember cohortMember);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortMemberAttributeType getCohortMemberAttributeTypeByUuid(@NotNull String uuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortMemberAttributeType> findAllCohortMemberAttributeTypes();

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
CohortMemberAttribute saveCohortMemberAttribute(CohortMemberAttribute cohortMemberAttributeType);

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
void voidCohortMemberAttribute(CohortMemberAttribute cohortMemberAttribute, String voidReason);

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
void purgeCohortMemberAttribute(CohortMemberAttribute cohortMemberAttribute);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortMemberAttribute getCohortMemberAttributeByUuid(@NotNull String uuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortMemberAttribute> getCohortMemberAttributesByTypeUuid(@NotNull String attributeTypeUuid);

@Transactional
@Authorized(MANAGE_COHORTS_PRIVILEGE)
CohortMemberAttributeType saveCohortMemberAttributeType(CohortMemberAttributeType cohortMemberAttributeType);

@Transactional
@Authorized(MANAGE_COHORTS_PRIVILEGE)
void voidCohortMemberAttributeType(CohortMemberAttributeType cohortMemberAttributeType, String voidReason);

@Transactional
@Authorized(MANAGE_COHORTS_PRIVILEGE)
void purgeCohortMemberAttributeType(CohortMemberAttributeType cohortMemberAttributeType);

//Search methods

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortMember> findCohortMembersByCohortUuid(@NotNull String cohortUuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortMember> findCohortMembersByPatientUuid(@NotNull String patientUuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortMember> findCohortMembersByPatientName(@NotNull String patientName);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortMember> findCohortMembersByCohortAndPatientName(@NotNull String cohortUuid,
@NotNull String patientName);
}
30 changes: 30 additions & 0 deletions api/src/main/java/org/openmrs/module/cohort/api/CohortService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Map;

import org.openmrs.annotation.Authorized;
import org.openmrs.api.OpenmrsService;
import org.openmrs.module.cohort.CohortAttribute;
import org.openmrs.module.cohort.CohortAttributeType;
Expand All @@ -24,74 +25,103 @@

public interface CohortService extends OpenmrsService {

String MANAGE_COHORTS_PRIVILEGE = "Manage Cohorts In Cohort Module";

String VIEW_COHORTS_PRIVILEGE = "View Cohorts In Cohort Module";

String EDIT_COHORTS_PRIVILEGE = "Edit Cohorts in Cohort Module";

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortM getCohortM(@NotNull String name);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortM getCohortM(@NotNull int id);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortM getCohortMByUuid(@NotNull String uuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortM> findCohortMByLocationUuid(@NotNull String locationUuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortM> findCohortMByPatientUuid(@NotNull String patientUuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortM> findAll();

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
CohortM saveCohortM(@NotNull CohortM cohortType);

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
void voidCohortM(@NotNull CohortM cohort, String reason);

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
void purgeCohortM(@NotNull CohortM cohortType);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortAttribute getCohortAttributeByUuid(@NotNull String uuid);

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
CohortAttribute saveCohortAttribute(@NotNull CohortAttribute attribute);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortAttribute> findCohortAttributesByCohortUuid(@NotNull String cohortUuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortAttribute> findCohortAttributesByTypeUuid(@NotNull String attributeTypeUuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortAttribute> findCohortAttributesByTypeName(@NotNull String attributeTypeName);

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
void voidCohortAttribute(@NotNull CohortAttribute attribute, String retiredReason);

@Transactional
@Authorized(EDIT_COHORTS_PRIVILEGE)
void purgeCohortAttribute(@NotNull CohortAttribute attribute);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortAttributeType getCohortAttributeTypeByUuid(@NotNull String uuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortAttributeType getCohortAttributeTypeByName(@NotNull String name);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortAttributeType> findAllCohortAttributeTypes();

@Transactional
@Authorized(MANAGE_COHORTS_PRIVILEGE)
CohortAttributeType saveCohortAttributeType(@NotNull CohortAttributeType attributeType);

@Transactional
@Authorized(MANAGE_COHORTS_PRIVILEGE)
void voidCohortAttributeType(@NotNull CohortAttributeType attributeType, String retiredReason);

@Transactional
@Authorized(MANAGE_COHORTS_PRIVILEGE)
void purgeCohortAttributeType(@NotNull CohortAttributeType attributeType);

//Search
@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
List<CohortM> findMatchingCohortMs(String nameMatching, Map<String, String> attributes, CohortType cohortType,
boolean includeVoided);
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
package org.openmrs.module.cohort.api;

import static org.openmrs.module.cohort.api.CohortService.MANAGE_COHORTS_PRIVILEGE;
import static org.openmrs.module.cohort.api.CohortService.VIEW_COHORTS_PRIVILEGE;

import javax.validation.constraints.NotNull;

import java.util.Collection;

import org.openmrs.annotation.Authorized;
import org.openmrs.api.OpenmrsService;
import org.openmrs.module.cohort.CohortType;
import org.springframework.transaction.annotation.Transactional;

public interface CohortTypeService extends OpenmrsService {

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortType getCohortTypeByUuid(@NotNull String uuid);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortType getCohortTypeByUuid(@NotNull String uuid, boolean includeVoided);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortType getCohortTypeByName(@NotNull String name);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
CohortType getCohortTypeByName(@NotNull String name, boolean includeVoided);

@Transactional(readOnly = true)
@Authorized(VIEW_COHORTS_PRIVILEGE)
Collection<CohortType> findAllCohortTypes();

@Transactional
@Authorized(MANAGE_COHORTS_PRIVILEGE)
CohortType saveCohortType(@NotNull CohortType cohortType);

@Transactional
@Authorized(MANAGE_COHORTS_PRIVILEGE)
void voidCohortType(@NotNull CohortType cohortType, String voidedReason);

@Transactional
@Authorized(MANAGE_COHORTS_PRIVILEGE)
void purgeCohortType(@NotNull CohortType cohortType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;


public class CohortTypeGenericDaoTest extends BaseModuleContextSensitiveTest {

private static final String COHORT_TYPE_INITIAL_TEST_DATA_XML = "org/openmrs/module/cohort/api/hibernate/db/CohortTypeDaoTest_initialTestData.xml";
Expand Down
15 changes: 15 additions & 0 deletions omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@
CohortAttributeType.hbm.xml
</mappingFiles>

<privilege>
<name>View Cohorts In Cohort Module</name>
<description>Allows to view Cohorts</description>
</privilege>

<privilege>
<name>Edit Cohorts In Cohort Module</name>
<description>Allows to edit Cohorts</description>
</privilege>

<privilege>
<name>Manage Cohorts In Cohort Module</name>
<description>Allows to manage Cohorts' metadata</description>
</privilege>

<!-- Internationalization -->
<!-- All message codes should start with ${project.parent.artifactId}. -->
<messages>
Expand Down

0 comments on commit 022fcdf

Please sign in to comment.