Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75124d99 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Home set enumeration: use correct displayName, also honor bind privilege;...

Home set enumeration: use correct displayName, also honor bind privilege; version bump to 2.5.3-beta1
parent a081ef21
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ android {
    defaultConfig {
        applicationId "at.bitfire.davdroid"

        versionCode 293
        versionCode 295
        buildConfigField "long", "buildTime", System.currentTimeMillis() + "L"
        buildConfigField "boolean", "customCerts", "true"

@@ -43,7 +43,7 @@ android {
    flavorDimensions "distribution"
    productFlavors {
        standard {
            versionName "2.5.2-ose"
            versionName "2.5.3-beta1-ose"
        }
    }

+18 −11
Original line number Diff line number Diff line
@@ -196,7 +196,7 @@ class DavService: android.app.Service() {
                                for (href in homeSet.hrefs)
                                    dav.location.resolve(href)?.let {
                                        val foundUrl = UrlUtils.withTrailingSlash(it)
                                        homeSets[foundUrl] = HomeSet(0, service.id, foundUrl, response[DisplayName::class.java]?.displayName)
                                        homeSets[foundUrl] = HomeSet(0, service.id, foundUrl)
                                    }
                            }

@@ -216,7 +216,7 @@ class DavService: android.app.Service() {
                                for (href in homeSet.hrefs)
                                    dav.location.resolve(href)?.let {
                                        val foundUrl = UrlUtils.withTrailingSlash(it)
                                        homeSets[foundUrl] = HomeSet(0, service.id, foundUrl, response[DisplayName::class.java]?.displayName)
                                        homeSets[foundUrl] = HomeSet(0, service.id, foundUrl)
                                    }
                            }

@@ -283,17 +283,23 @@ class DavService: android.app.Service() {
                        selectedCollections += url
                }

                // now refresh collections (taken from home sets)
                // now refresh homesets and their member collections
                val itHomeSets = homeSets.iterator()
                while (itHomeSets.hasNext()) {
                    val homeSet = itHomeSets.next()
                    Logger.log.fine("Listing home set ${homeSet.key}")

                    try {
                        DavResource(httpClient, homeSet.key).propfind(1, *DAV_COLLECTION_PROPERTIES) { response, _ ->
                        DavResource(httpClient, homeSet.key).propfind(1, *DAV_COLLECTION_PROPERTIES) { response, relation ->
                            if (!response.isSuccess())
                                return@propfind

                            if (relation == Response.HrefRelation.SELF) {
                                // this response is about the homeset itself
                                homeSet.value.displayName = response[DisplayName::class.java]?.displayName
                                homeSet.value.privBind = response[CurrentUserPrivilegeSet::class.java]?.mayBind ?: true

                            } else {
                                val info = Collection.fromDavResponse(response) ?: return@propfind
                                info.serviceId = serviceId
                                info.confirmed = true
@@ -303,6 +309,7 @@ class DavService: android.app.Service() {
                                    (service.type == Service.TYPE_CALDAV && arrayOf(Collection.TYPE_CALENDAR, Collection.TYPE_WEBCAL).contains(info.type)))
                                    collections[response.href] = info
                            }
                        }
                    } catch(e: HttpException) {
                        if (e.code in arrayOf(403, 404, 410))
                            // delete home set only if it was not accessible (40x)
+1 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ abstract class AppDatabase: RoomDatabase() {

    object Migration6_7: Migration(6, 7) {
        override fun migrate(db: SupportSQLiteDatabase) {
            db.execSQL("ALTER TABLE homeset ADD COLUMN privBind INTEGER NOT NULL DEFAULT 1")
            db.execSQL("ALTER TABLE homeset ADD COLUMN displayName TEXT DEFAULT NULL")
        }
    }
+2 −0
Original line number Diff line number Diff line
@@ -22,5 +22,7 @@ data class HomeSet(
    var serviceId: Long,
    var url: HttpUrl,

    var privBind: Boolean = true,

    var displayName: String? = null
): IdEntity()
 No newline at end of file
+7 −1
Original line number Diff line number Diff line
package at.bitfire.davdroid.model

import androidx.room.*
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query

@Dao
interface HomeSetDao: SyncableDao<HomeSet> {
@@ -8,6 +11,9 @@ interface HomeSetDao: SyncableDao<HomeSet> {
    @Query("SELECT * FROM homeset WHERE serviceId=:serviceId")
    fun getByService(serviceId: Long): List<HomeSet>

    @Query("SELECT * FROM homeset WHERE serviceId=:serviceId AND privBind")
    fun getBindableByService(serviceId: Long): List<HomeSet>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertOrReplace(homeSet: HomeSet): Long

Loading