Skip to content

Commit

Permalink
replace lazy permission upgrade to forced re-logged in (#4028)
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed May 15, 2022
1 parent 87f8ff5 commit 31ebb42
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 59 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/de/westnordost/streetcomplete/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object Prefs {
const val OSM_USER_ID = "osm.userid"
const val OSM_USER_NAME = "osm.username"
const val OSM_UNREAD_MESSAGES = "osm.unread_messages"
const val OSM_HAS_UPLOAD_TRACES_PERMISSION = "osm.upload_traces_permission"
const val OSM_LOGGED_IN_AFTER_OAUTH_FUCKUP = "osm.logged_in_after_oauth_fuckup"
const val USER_DAYS_ACTIVE = "days_active"
const val USER_GLOBAL_RANK = "user_global_rank"
const val USER_LAST_TIMESTAMP_ACTIVE = "last_timestamp_active"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import de.westnordost.streetcomplete.data.osmnotes.notequests.osmNoteQuestModule
import de.westnordost.streetcomplete.data.osmnotes.notesModule
import de.westnordost.streetcomplete.data.quest.questModule
import de.westnordost.streetcomplete.data.upload.uploadModule
import de.westnordost.streetcomplete.data.user.UserLoginStatusController
import de.westnordost.streetcomplete.data.user.achievements.achievementsModule
import de.westnordost.streetcomplete.data.user.statistics.statisticsModule
import de.westnordost.streetcomplete.data.user.userModule
Expand Down Expand Up @@ -65,6 +66,7 @@ class StreetCompleteApplication : Application() {
private val downloadedTilesDao: DownloadedTilesDao by inject()
private val prefs: SharedPreferences by inject()
private val editHistoryController: EditHistoryController by inject()
private val userLoginStatusController: UserLoginStatusController by inject()

private val applicationScope = CoroutineScope(SupervisorJob() + CoroutineName("Application"))

Expand Down Expand Up @@ -111,6 +113,15 @@ class StreetCompleteApplication : Application() {
)
}

/* Force log out users who use the old OAuth consumer key+secret because it does not exist
anymore. Trying to use that does not result in a "not authorized" API response, but some
response the app cannot handle */
if (!prefs.getBoolean(Prefs.OSM_LOGGED_IN_AFTER_OAUTH_FUCKUP, false)) {
if (userLoginStatusController.isLoggedIn) {
userLoginStatusController.logOut()
}
}

setDefaultLocales()

crashReportExceptionHandler.install()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class UserLoginStatusController(
fun logIn(consumer: OAuthConsumer) {
oAuthStore.oAuthConsumer = consumer
osmConnection.oAuth = consumer
prefs.edit().putBoolean(Prefs.OSM_HAS_UPLOAD_TRACES_PERMISSION, true).apply()
prefs.edit().putBoolean(Prefs.OSM_LOGGED_IN_AFTER_OAUTH_FUCKUP, true).apply()
listeners.forEach { it.onLoggedIn() }
}

fun logOut() {
oAuthStore.oAuthConsumer = null
osmConnection.oAuth = null
prefs.edit().putBoolean(Prefs.OSM_HAS_UPLOAD_TRACES_PERMISSION, false).apply()
prefs.edit().putBoolean(Prefs.OSM_LOGGED_IN_AFTER_OAUTH_FUCKUP, false).apply()
listeners.forEach { it.onLoggedOut() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,10 @@ import de.westnordost.streetcomplete.util.math.area
import de.westnordost.streetcomplete.util.math.enclosingBoundingBox
import de.westnordost.streetcomplete.util.math.initialBearingTo
import de.westnordost.streetcomplete.util.viewBinding
import de.westnordost.streetcomplete.view.dialogs.RequestPermissionUpgradeDialog
import de.westnordost.streetcomplete.view.insets_animation.respectSystemInsets
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.koin.android.ext.android.get
import org.koin.android.ext.android.inject
import kotlin.math.PI
import kotlin.math.abs
Expand Down Expand Up @@ -747,14 +745,6 @@ class MainFragment :
}

private fun onClickCreateTrack() {
// Check that the user has required permission to record a track
val hasUploadPermission = prefs.getBoolean(Prefs.OSM_HAS_UPLOAD_TRACES_PERMISSION, false)
if (!hasUploadPermission) {
RequestPermissionUpgradeDialog(requireContext(), get()).show()
return
}

// Else we are good to start recording!
val mapFragment = mapFragment ?: return
mapFragment.startPositionTrackRecording()
binding.stopTracksButton.isVisible = true
Expand Down

This file was deleted.

14 changes: 0 additions & 14 deletions app/src/main/res/layout/dialog_permission_upgrade.xml

This file was deleted.

3 changes: 2 additions & 1 deletion app/src/main/res/raw/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ v44.0-beta1: |
</ul>
v43.2: |
Sorry, I fucked something up. You need to log in again. 🙇‍
Sorry, I fucked something up. You need to log in again. 🙇‍ Don't worry, your not yet uploaded
edits are safe. (#4028)
v43.1: |
<h3>Enhancements and Fixes</h3>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ If you are overwhelmed by the number of quests, you can always fine-tune which q

<string name="confirmation_authorize_now">"You need to authorize with your OSM user account to publish your answers. Authorize now?"</string>
<string name="confirmation_authorize_now_note2">You can also do this later on the profile screen.</string>
<string name="confirmation_permission_upgrade">"You need to authorize this app to publish track recordings on OpenStreetMap. This requires to log in again. Proceed?"</string>
<string name="later">"Later"</string>
<string name="not_authorized">"Not authorized"</string>

Expand Down

0 comments on commit 31ebb42

Please sign in to comment.