All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pubnub.api.models.consumer.access_manager.sum.UserPermissions.kt Maven / Gradle / Ivy

Go to download

PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter second!

There is a newer version: 10.2.0
Show newest version
package com.pubnub.api.models.consumer.access_manager.sum

import com.pubnub.api.PubNubError
import com.pubnub.api.PubNubException
import com.pubnub.api.UserId
import com.pubnub.api.models.consumer.access_manager.v3.PNGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNUUIDPatternGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNUUIDResourceGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNUserPatternPermissionsGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNUserPermissionsGrant
import com.pubnub.api.models.consumer.access_manager.v3.UUIDGrant

interface UserPermissions : PNGrant {
    companion object {
        fun id(
            userId: UserId,
            get: Boolean = false,
            update: Boolean = false,
            delete: Boolean = false,
        ): UserPermissions =
            PNUserPermissionsGrant(
                id = userId.value,
                delete = delete,
                get = get,
                update = update,
            )

        fun pattern(
            pattern: String,
            get: Boolean = false,
            update: Boolean = false,
            delete: Boolean = false,
        ): UserPermissions =
            PNUserPatternPermissionsGrant(
                id = pattern,
                delete = delete,
                get = get,
                update = update,
            )
    }
}

fun UserPermissions.toUuidGrant(): UUIDGrant {
    return when (this) {
        is PNUserPermissionsGrant -> PNUUIDResourceGrant(userPermissions = this)
        is PNUserPatternPermissionsGrant -> PNUUIDPatternGrant(userPermissions = this)
        else -> throw PubNubException(pubnubError = PubNubError.INVALID_ARGUMENTS)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy