mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-19 02:56:45 -06:00
Fix issues related to not authenticated eduOne students (#2501)
This commit is contained in:
parent
76d038eefa
commit
3881678208
@ -12,6 +12,7 @@ import io.github.wulkanowy.data.db.entities.StudentName
|
|||||||
import io.github.wulkanowy.data.db.entities.StudentNickAndAvatar
|
import io.github.wulkanowy.data.db.entities.StudentNickAndAvatar
|
||||||
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
|
||||||
import io.github.wulkanowy.data.exceptions.NoCurrentStudentException
|
import io.github.wulkanowy.data.exceptions.NoCurrentStudentException
|
||||||
|
import io.github.wulkanowy.data.mappers.mapToEntities
|
||||||
import io.github.wulkanowy.data.mappers.mapToPojo
|
import io.github.wulkanowy.data.mappers.mapToPojo
|
||||||
import io.github.wulkanowy.data.pojos.RegisterUser
|
import io.github.wulkanowy.data.pojos.RegisterUser
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
import io.github.wulkanowy.sdk.Sdk
|
||||||
@ -110,7 +111,22 @@ class StudentRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val initializedSdk = wulkanowySdkFactory.create(student)
|
val initializedSdk = wulkanowySdkFactory.create(student)
|
||||||
val newCurrentStudent = initializedSdk.getCurrentStudent() ?: return
|
val newCurrentStudent = runCatching { initializedSdk.getCurrentStudent() }
|
||||||
|
.onFailure { Timber.e(it, "Check isAuthorized: error occurred") }
|
||||||
|
.getOrNull()
|
||||||
|
|
||||||
|
if (newCurrentStudent == null) {
|
||||||
|
Timber.d("Check isAuthorized: current user is null")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val currentStudentSemesters = semesterDb.loadAll(student.studentId, student.classId)
|
||||||
|
if (currentStudentSemesters.isEmpty()) {
|
||||||
|
Timber.d("Check isAuthorized: apply empty semesters workaround")
|
||||||
|
semesterDb.insertSemesters(
|
||||||
|
items = newCurrentStudent.semesters.mapToEntities(student.studentId),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (!newCurrentStudent.isAuthorized) {
|
if (!newCurrentStudent.isAuthorized) {
|
||||||
Timber.i("Check isAuthorized: authorization required")
|
Timber.i("Check isAuthorized: authorization required")
|
||||||
@ -178,15 +194,21 @@ class StudentRepository @Inject constructor(
|
|||||||
wulkanowySdkFactory.create(student, semester)
|
wulkanowySdkFactory.create(student, semester)
|
||||||
.authorizePermission(pesel)
|
.authorizePermission(pesel)
|
||||||
|
|
||||||
suspend fun refreshStudentName(student: Student, semester: Semester) {
|
suspend fun refreshStudentAfterAuthorize(student: Student, semester: Semester) {
|
||||||
val newCurrentApiStudent = wulkanowySdkFactory.create(student, semester)
|
val newCurrentApiStudent = wulkanowySdkFactory
|
||||||
.getCurrentStudent() ?: return
|
.create(student, semester)
|
||||||
|
.getCurrentStudent()
|
||||||
|
?: return Timber.d("Can't find student with id ${student.studentId}")
|
||||||
|
|
||||||
val studentName = StudentName(
|
val studentName = StudentName(
|
||||||
studentName = "${newCurrentApiStudent.studentName} ${newCurrentApiStudent.studentSurname}"
|
studentName = "${newCurrentApiStudent.studentName} ${newCurrentApiStudent.studentSurname}"
|
||||||
).apply { id = student.id }
|
).apply { id = student.id }
|
||||||
|
|
||||||
studentDb.update(studentName)
|
studentDb.update(studentName)
|
||||||
|
semesterDb.removeOldAndSaveNew(
|
||||||
|
oldItems = semesterDb.loadAll(student.studentId, semester.classId),
|
||||||
|
newItems = newCurrentApiStudent.semesters.mapToEntities(newCurrentApiStudent.studentId)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun deleteStudentsAssociatedWithAccount(student: Student) {
|
suspend fun deleteStudentsAssociatedWithAccount(student: Student) {
|
||||||
@ -202,4 +224,3 @@ class StudentRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class NoAuthorizationException : Exception()
|
class NoAuthorizationException : Exception()
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import io.github.wulkanowy.data.repositories.StudentRepository
|
|||||||
import io.github.wulkanowy.ui.base.BasePresenter
|
import io.github.wulkanowy.ui.base.BasePresenter
|
||||||
import io.github.wulkanowy.ui.base.ErrorHandler
|
import io.github.wulkanowy.ui.base.ErrorHandler
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class AuthPresenter @Inject constructor(
|
class AuthPresenter @Inject constructor(
|
||||||
@ -57,8 +58,9 @@ class AuthPresenter @Inject constructor(
|
|||||||
val semester = semesterRepository.getCurrentSemester(student)
|
val semester = semesterRepository.getCurrentSemester(student)
|
||||||
|
|
||||||
val isSuccess = studentRepository.authorizePermission(student, semester, pesel)
|
val isSuccess = studentRepository.authorizePermission(student, semester, pesel)
|
||||||
|
Timber.d("Auth succeed: $isSuccess")
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
studentRepository.refreshStudentName(student, semester)
|
studentRepository.refreshStudentAfterAuthorize(student, semester)
|
||||||
}
|
}
|
||||||
isSuccess
|
isSuccess
|
||||||
}
|
}
|
||||||
@ -68,6 +70,7 @@ class AuthPresenter @Inject constructor(
|
|||||||
view?.showContent(true)
|
view?.showContent(true)
|
||||||
}
|
}
|
||||||
.onSuccess {
|
.onSuccess {
|
||||||
|
Timber.d("Auth fully succeed: $it")
|
||||||
if (it) {
|
if (it) {
|
||||||
view?.showSuccess(true)
|
view?.showSuccess(true)
|
||||||
view?.showContent(false)
|
view?.showContent(false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user