Skip to content

Commit

Permalink
sync: safer call operator in datamanager (fixes #3298) (#3300)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Mar 22, 2024
1 parent 6fa93bb commit 304d6b3
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 185 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1443
versionName "0.14.43"
versionCode 1444
versionName "0.14.44"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ManagerSync private constructor(context: Context) {
override fun onResponse(call: Call<JsonObject?>, response: Response<JsonObject?>) {
if (response.isSuccessful && response.body() != null) {
val jsonDoc = response.body()
if (jsonDoc!!.has("derived_key") && jsonDoc.has("salt")) {
if (jsonDoc?.has("derived_key") == true && jsonDoc.has("salt")) {
// val decrypt = AndroidDecrypter()
val derivedKey = jsonDoc["derived_key"].asString
val salt = jsonDoc["salt"].asString
Expand Down Expand Up @@ -86,17 +86,17 @@ class ManagerSync private constructor(context: Context) {
private fun checkManagerAndInsert(jsonDoc: JsonObject?, realm: Realm, listener: SyncListener) {
Utilities.log("Check manager and insert")
if (isManager(jsonDoc)) {
populateUsersTable(jsonDoc!!, realm, settings)
populateUsersTable(jsonDoc, realm, settings)
listener.onSyncComplete()
} else {
listener.onSyncFailed("The user is not a manager.")
}
}

private fun isManager(jsonDoc: JsonObject?): Boolean {
val roles = jsonDoc!!["roles"].asJsonArray
val roles = jsonDoc?.get("roles")?.asJsonArray
val isManager = roles.toString().lowercase(Locale.getDefault()).contains("manager")
return jsonDoc["isUserAdmin"].asBoolean || isManager
return jsonDoc?.get("isUserAdmin")?.asBoolean == true || isManager
}

companion object {
Expand Down
Loading

0 comments on commit 304d6b3

Please sign in to comment.