diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9.java index 74858af65..0d36c5998 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/SessionController1_9.java @@ -54,6 +54,9 @@ public class SessionController1_9 extends BaseRestController { public static final String USER_CUSTOM_REP = "(uuid,display,username,systemId,userProperties,person:(uuid,display),privileges:(uuid,display,name),roles:(uuid,display,name),links)"; + // The privilege to get providers was changed from "View Providers" to "Get Providers" in OpenMRS 2.0 + private static final String GET_PROVIDERS = "Get Providers"; + @Autowired RestService restService; @@ -139,12 +142,14 @@ protected Provider getCurrentProvider() { Collection providers = new HashSet(); try { Context.addProxyPrivilege(PrivilegeConstants.VIEW_PROVIDERS); + Context.addProxyPrivilege(GET_PROVIDERS); if (currentUser.getPerson() != null) { providers = Context.getProviderService().getProvidersByPerson(currentUser.getPerson(), false); } } finally { Context.removeProxyPrivilege(PrivilegeConstants.VIEW_PROVIDERS); + Context.removeProxyPrivilege(GET_PROVIDERS); } if (providers.size() > 1) { log.warn("Can't handle users with multiple provider accounts"); diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/SessionController2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/SessionController2_0.java deleted file mode 100644 index 4443db8db..000000000 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/SessionController2_0.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs2_0; - -import java.util.Collection; -import java.util.HashSet; - -import org.openmrs.Provider; -import org.openmrs.User; -import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.SessionController1_9; -import org.openmrs.util.PrivilegeConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * @see SessionController1_9 - */ -@Controller -@RequestMapping -public class SessionController2_0 extends SessionController1_9 { - - private static final Logger log = LoggerFactory.getLogger(SessionController2_0.class); - - /** - * @see SessionController1_9#getCurrentProvider() - */ - @Override - protected Provider getCurrentProvider() { - Provider currentProvider = null; - User currentUser = Context.getAuthenticatedUser(); - if (currentUser != null) { - Collection providers = new HashSet(); - try { - Context.addProxyPrivilege(PrivilegeConstants.GET_PROVIDERS); - if (currentUser.getPerson() != null) { - providers = Context.getProviderService().getProvidersByPerson(currentUser.getPerson(), false); - } - } - finally { - Context.removeProxyPrivilege(PrivilegeConstants.GET_PROVIDERS); - } - if (providers.size() > 1) { - log.warn("Can't handle users with multiple provider accounts"); - } else if (providers.size() == 1) { - currentProvider = providers.iterator().next(); - } - } - return currentProvider; - } -} diff --git a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/SessionController2_0Test.java b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/SessionController1_9Test.java similarity index 79% rename from omod-2.0/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/SessionController2_0Test.java rename to omod-2.0/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/SessionController1_9Test.java index c82ebfee3..afe6475f9 100644 --- a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/SessionController2_0Test.java +++ b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_0/SessionController1_9Test.java @@ -13,15 +13,16 @@ import org.junit.Assert; import org.junit.Test; import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9.SessionController1_9; import org.openmrs.web.test.BaseModuleWebContextSensitiveTest; /** - * Tests functionality of {@link SessionController2_0} + * Tests functionality of {@link SessionController1_9} in OpenMRS 2.0 */ -public class SessionController2_0Test extends BaseModuleWebContextSensitiveTest { +public class SessionController1_9Test extends BaseModuleWebContextSensitiveTest { /** - * @see SessionController2_0#get() + * @see SessionController1_9#get() * @verifies return the session with current provider if the user doesn't have Get Providers privilege */ @Test @@ -33,7 +34,7 @@ public void get_shouldReturnCurrentProviderIfTheUserDoesNotHaveGetProvidersPrivi Context.authenticate("test_user", "test"); Assert.assertTrue(Context.isAuthenticated()); - SessionController2_0 controller = Context.getRegisteredComponents(SessionController2_0.class).iterator().next(); + SessionController1_9 controller = Context.getRegisteredComponents(SessionController1_9.class).get(0); Object ret = controller.get(); Object currentProvider = PropertyUtils.getProperty(ret, "currentProvider");