Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/add_user_details_to_shared_prefs…
Browse files Browse the repository at this point in the history
…' into anc-issue-fix-906

# Conflicts:
#	gradle.properties
  • Loading branch information
junaidwarsivd committed Oct 12, 2022
2 parents 1067621 + 2b450bc commit 9dc6eb6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class AllConstants {
public static final String DEFAULT_TEAM_PREFIX = "dfltTeam-";
public static final String DEFAULT_TEAM_ID_PREFIX = "dfltTeamId-";
public static final String USER_LOCALITY_ID_PREFIX = "userLoc-";
public static final String USER_ID_PREFIX = "userId-";
public static final String PIONEER_USER = "pioneerUser";
public static final String LANGUAGE_PREFERENCE_KEY = "locale";
public static final String CURRENT_LOCALITY = "current_locality";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,5 +398,13 @@ public void updateLastAuthenticationHttpStatus(int httpStatus) {
public int getLastAuthenticationHttpStatus() {
return preferences.getInt(LAST_AUTHENTICATION_HTTP_STATUS, 0);
}

public void saveUserId(String username, String userId) {
preferences.edit().putString(AllConstants.USER_ID_PREFIX + username, userId).apply();
}

public String getUserId(String userName) {
return StringUtils.isNotBlank(userName) ? preferences.getString(AllConstants.USER_ID_PREFIX + userName, null) : "";
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package org.smartregister.service;

import static org.smartregister.AllConstants.ENGLISH_LANGUAGE;
import static org.smartregister.AllConstants.ENGLISH_LOCALE;
import static org.smartregister.AllConstants.JURISDICTION_IDS;
import static org.smartregister.AllConstants.KANNADA_LANGUAGE;
import static org.smartregister.AllConstants.KANNADA_LOCALE;
import static org.smartregister.AllConstants.OPENSRP_AUTH_USER_URL_PATH;
import static org.smartregister.AllConstants.OPENSRP_LOCATION_URL_PATH;
import static org.smartregister.AllConstants.OPERATIONAL_AREAS;
import static org.smartregister.AllConstants.ORGANIZATION_IDS;
import static org.smartregister.event.Event.ON_LOGOUT;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -63,17 +74,6 @@

import timber.log.Timber;

import static org.smartregister.AllConstants.ENGLISH_LANGUAGE;
import static org.smartregister.AllConstants.ENGLISH_LOCALE;
import static org.smartregister.AllConstants.JURISDICTION_IDS;
import static org.smartregister.AllConstants.KANNADA_LANGUAGE;
import static org.smartregister.AllConstants.KANNADA_LOCALE;
import static org.smartregister.AllConstants.OPENSRP_AUTH_USER_URL_PATH;
import static org.smartregister.AllConstants.OPENSRP_LOCATION_URL_PATH;
import static org.smartregister.AllConstants.OPERATIONAL_AREAS;
import static org.smartregister.AllConstants.ORGANIZATION_IDS;
import static org.smartregister.event.Event.ON_LOGOUT;

public class UserService {
private static final String KEYSTORE = "AndroidKeyStore";
private static final String CIPHER = "RSA/ECB/PKCS1Padding";
Expand Down Expand Up @@ -404,6 +404,7 @@ public void processLoginResponseDataForUser(String userName, LoginResponseData u
saveJurisdictions(userInfo.jurisdictions);
saveJurisdictionIds(userInfo.jurisdictionIds);
saveOrganizations(getUserTeam(userInfo));
saveUserId(userName, userInfo.user.getBaseEntityId());
if (loginSuccessful &&
(StringUtils.isBlank(getUserDefaultLocationId(userInfo)) ||
StringUtils.isNotBlank(allSharedPreferences.fetchDefaultLocalityId(username))) &&
Expand Down Expand Up @@ -848,4 +849,10 @@ public byte[] getGroupId(String userName, KeyStore.PrivateKeyEntry privateKeyEnt
}
return null;
}

public void saveUserId(String userName, String baseEntityId) {
if (userName != null) {
allSharedPreferences.saveUserId(userName, baseEntityId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.reflect.Whitebox;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.BaseUnitTest;
Expand Down Expand Up @@ -188,7 +187,7 @@ public void shouldRegisterANewUser() {
@Test
public void shouldDeleteDataAndSettingsWhenLogoutHappens() throws Exception {
SyncConfiguration syncConfiguration = mock(SyncConfiguration.class);
Mockito.doReturn(false).when(syncConfiguration).clearDataOnNewTeamLogin();
doReturn(false).when(syncConfiguration).clearDataOnNewTeamLogin();
ReflectionHelpers.setField(CoreLibrary.getInstance(), "syncConfiguration", syncConfiguration);
Whitebox.setInternalState(drishtiApplication, "password", password);

Expand Down

0 comments on commit 9dc6eb6

Please sign in to comment.