SecurityMetadata extends AbstractMetadataBundle { @Override public void install() { String[] appIds = { EmrConstants.APP_REGISTRATION, EmrConstants.APP_INTAKE, EmrConstants.APP_CLINICIAN, EmrConstants.APP_CHART, EmrConstants.APP_REPORTS, EmrConstants.APP_DIRECTORY, EmrConstants.APP_FACILITIES, EmrConstants.APP_ADMIN, DqConstants.APP_DATAQUALITY, DqConstants.APP_DATAMANAGER }; for (String appId : appIds) { install(privilege(app(appId), "Access to the " + appId + " app")); } install(privilege(_Privilege.VIEW_LEGACY_INTERFACE, "Can view legacy web interface")); install(privilege(PrivilegeConstants.PURGE_PATIENT_IDENTIFIERS, "Able to purge patient identifiers")); install(role(_Role.API_PRIVILEGES, "All API privileges", null, getApiPrivileges(true)) ); install(role(_Role.API_PRIVILEGES_VIEW_AND_EDIT, "All viewing and editing API privileges", null, getApiPrivileges(false)) ); install(role(_Role.REGISTRATION, "Can access the registration app", idSet(_Role.API_PRIVILEGES_VIEW_AND_EDIT), idSet( app(EmrConstants.APP_REGISTRATION), app(EmrConstants.APP_DIRECTORY), app(EmrConstants.APP_FACILITIES) ) )); install(role(_Role.INTAKE, "Can access the registration and triage apps", idSet(_Role.API_PRIVILEGES_VIEW_AND_EDIT), idSet( app(EmrConstants.APP_REGISTRATION), app(EmrConstants.APP_INTAKE), app(EmrConstants.APP_DIRECTORY), app(EmrConstants.APP_FACILITIES) ) )); install(role(_Role.MANAGER, "Can access all apps except admin", idSet(_Role.API_PRIVILEGES), idSet( app(EmrConstants.APP_REGISTRATION), app(EmrConstants.APP_INTAKE), app(EmrConstants.APP_CLINICIAN), app(EmrConstants.APP_CHART), app(EmrConstants.APP_REPORTS), app(EmrConstants.APP_DIRECTORY), app(EmrConstants.APP_FACILITIES), app(DqConstants.APP_DATAQUALITY), app(DqConstants.APP_DATAMANAGER) ) )); install(role(_Role.CLINICIAN, "Can access the registration, triage, clinician, chart and reports apps", idSet(_Role.API_PRIVILEGES_VIEW_AND_EDIT), idSet( app(EmrConstants.APP_REGISTRATION), app(EmrConstants.APP_INTAKE), app(EmrConstants.APP_CLINICIAN), app(EmrConstants.APP_CHART), app(EmrConstants.APP_REPORTS), app(EmrConstants.APP_DIRECTORY), app(EmrConstants.APP_FACILITIES) ) )); install(role(_Role.DATA_CLERK, "Can access the chart, reporting and data quality apps", idSet(_Role.API_PRIVILEGES_VIEW_AND_EDIT), idSet( app(EmrConstants.APP_CHART), app(EmrConstants.APP_REPORTS), app(EmrConstants.APP_DIRECTORY), app(EmrConstants.APP_FACILITIES), app(DqConstants.APP_DATAQUALITY) ) )); install(role(_Role.SYSTEM_ADMIN, "Can access the admin app", idSet(_Role.API_PRIVILEGES_VIEW_AND_EDIT), idSet( app(EmrConstants.APP_ADMIN), app(EmrConstants.APP_DIRECTORY), app(EmrConstants.APP_FACILITIES) ) )); }  @Override void install();  }
@Test public void install_shouldInstallAllMetadata() { securityMetadata.install(); Context.flushSession(); Context.clearSession(); Role apiPrivilegesViewAndEdit = MetadataUtils.existing(Role.class, "API Privileges (View and Edit)"); Role registration = MetadataUtils.existing(Role.class, "Registration"); Assert.assertThat(registration.getInheritedRoles(), contains(apiPrivilegesViewAndEdit)); Assert.assertThat(registration.hasPrivilege("App: kenyaemr.registration"), is(true)); Assert.assertThat(registration.hasPrivilege("App: kenyaemr.directory"), is(true)); Assert.assertThat(registration.hasPrivilege("App: kenyaemr.facilities"), is(true)); Assert.assertThat(registration.hasPrivilege("App: kenyaemr.admin"), is(false)); }