use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class PrivilegeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see PrivilegeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
Privilege priv = new Privilege();
priv.setPrivilege("Wallhacking");
priv.setDescription("description");
Errors errors = new BindException(priv, "priv");
new PrivilegeValidator().validate(priv, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class UserServiceImpl method checkPrivileges.
/**
* Convenience method to check if the authenticated user has all privileges they are giving out
*
* @param new user that has privileges
*/
private void checkPrivileges(User user) {
Collection<Role> roles = user.getAllRoles();
List<String> requiredPrivs = new ArrayList<>();
for (Role r : roles) {
if (r.getRole().equals(RoleConstants.SUPERUSER) && !Context.hasPrivilege(PrivilegeConstants.ASSIGN_SYSTEM_DEVELOPER_ROLE)) {
throw new APIException("User.you.must.have.role", new Object[] { RoleConstants.SUPERUSER });
}
if (r.getPrivileges() != null) {
for (Privilege p : r.getPrivileges()) {
if (!Context.hasPrivilege(p.getPrivilege())) {
requiredPrivs.add(p.getPrivilege());
}
}
}
}
if (requiredPrivs.size() == 1) {
throw new APIException("User.you.must.have.privilege", new Object[] { requiredPrivs.get(0) });
} else if (requiredPrivs.size() > 1) {
StringBuilder txt = new StringBuilder("You must have the following privileges in order to assign them: ");
for (String s : requiredPrivs) {
txt.append(s).append(", ");
}
throw new APIException(txt.substring(0, txt.length() - 2));
}
}
use of org.openmrs.Privilege in project openmrs-module-mirebalais by PIH.
the class RequireUtilTest method setup.
@Before
public void setup() throws Exception {
appFrameworkService = new AppFrameworkServiceImpl(null, null, null, null, null, null, null, null);
doctor = new Role("Doctor");
admin = new Role("Admin");
Privilege enterConsultNote = new Privilege(Privileges.TASK_EMR_ENTER_CONSULT_NOTE.privilege());
enterConsultNote.setUuid(Privileges.TASK_EMR_ENTER_CONSULT_NOTE.uuid());
enterConsultNote.setDescription(Privileges.TASK_EMR_ENTER_CONSULT_NOTE.description());
Privilege retroClinicalNote = new Privilege(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE.privilege());
retroClinicalNote.setUuid(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE.uuid());
retroClinicalNote.setDescription(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE.description());
Privilege retroClinicalNoteThisProviderOnly = new Privilege(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE_THIS_PROVIDER_ONLY.privilege());
retroClinicalNoteThisProviderOnly.setUuid(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE_THIS_PROVIDER_ONLY.uuid());
retroClinicalNoteThisProviderOnly.setDescription(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE_THIS_PROVIDER_ONLY.description());
doctor.addPrivilege(enterConsultNote);
doctor.addPrivilege(retroClinicalNoteThisProviderOnly);
admin.addPrivilege(enterConsultNote);
admin.addPrivilege(retroClinicalNote);
user = new User();
user.setUsername("bobMeIn");
user.setUuid("123-456");
user.setSystemId("abc");
user.setRetired(true);
userContext = mock(UserContext.class);
when(userContext.getAuthenticatedUser()).thenReturn(user);
uiSessionContext = new UiSessionContext();
uiSessionContext.setUserContext(userContext);
}
use of org.openmrs.Privilege in project openmrs-module-mirebalais by PIH.
the class MirebalaisHospitalActivator method removeOldPrivileges.
/* private void migratePaperRecordLocation(PaperRecordProperties paperRecordProperties) {
Context.getAdministrationService().executeSQL("update patient_identifier set location_id = (select location_id from location where uuid='"+
Locations.MIREBALAIS_HOSPITAL.uuid() + "')" +
"where identifier_type = (select patient_identifier_type_id from patient_identifier_type where uuid = '" +
paperRecordProperties.getPaperRecordIdentifierType().getUuid() + "')" +
"and location_id = (select location_id from location where uuid='" +
Locations.MIREBALAIS_CDI_PARENT.uuid() + "')", false);
Context.getAdministrationService().executeSQL("update paperrecord_paper_record set record_location = (select location_id from location where uuid='" +
Locations.MIREBALAIS_HOSPITAL.uuid() + "')" +
"where record_location = (select location_id from location where uuid='" +
Locations.MIREBALAIS_CDI_PARENT.uuid() + "')", false);
}*/
private void removeOldPrivileges() {
UserService userService = Context.getUserService();
Privilege privilege = userService.getPrivilege("App: appointmentschedulingui.scheduleAdmin");
if (privilege != null) {
userService.purgePrivilege(privilege);
}
}
use of org.openmrs.Privilege in project openmrs-module-coreapps by openmrs.
the class VisitDetailsFragmentControllerTest method createPrivilegeToEditEncounters.
private Privilege createPrivilegeToEditEncounters() {
Privilege privilege = new Privilege();
privilege.setPrivilege(EmrApiConstants.PRIVILEGE_EDIT_ENCOUNTER);
return privilege;
}
Aggregations