Permissions 使用领域对象服务器设置共享领域的权限

Permissions 使用领域对象服务器设置共享领域的权限,permissions,realm-mobile-platform,realm-object-server,Permissions,Realm Mobile Platform,Realm Object Server,我正在尝试建立一个共享领域,所有用户都可以访问该领域。我还打算让用户根据需要创建表示项目的领域。我想给用户读写他们创建的任何项目领域的权限,但是对所有其他用户的领域都有读访问权。我还希望能够根据需要将写权限分配给其他用户,而不给他们领域对象服务器中的管理员状态 我认为我的应用程序将允许用户以最低权限登录,并让第二个管理员用户在后台工作,以管理权限。管理员用户不会向该用户公开 我一直在遵循中提供的示例,但是在设置权限方面没有任何成功。我的测试用例如下: import UIKit import Re

我正在尝试建立一个共享领域,所有用户都可以访问该领域。我还打算让用户根据需要创建表示项目的领域。我想给用户读写他们创建的任何项目领域的权限,但是对所有其他用户的领域都有读访问权。我还希望能够根据需要将写权限分配给其他用户,而不给他们领域对象服务器中的管理员状态

我认为我的应用程序将允许用户以最低权限登录,并让第二个管理员用户在后台工作,以管理权限。管理员用户不会向该用户公开

我一直在遵循中提供的示例,但是在设置权限方面没有任何成功。我的测试用例如下:

import UIKit
import RealmSwift
import Realm

let ApplicationName = "SyncTest"
let syncHost = "127.0.0.1" //  The realm-oject-server is hosted on AWS, however changed for this example to keep user data private. HTTPS has also been implemented.
let syncAuthURL = URL(string: "https://\(syncHost):9443")!
let commonRealmURL:URL = URL(string: "realms://\(syncHost):9443/\(ApplicationName)-CommonRealm")!

class Dog: Object {
    dynamic var name = ""
    dynamic var age = 0
}

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        updateUserPermissions()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    private func updateUserPermissions() {

        // Create the callback block that will perform the request
        let logInBlock: ((SyncCredentials) -> Void) = { credentials in
            SyncUser.logIn(with: credentials, server: syncAuthURL, timeout: 30, onCompletion: { (user, error) in
                DispatchQueue.main.async {
                    // Display an error message if the login failed
                    if let error = error {
                        self.showError(title: "Unable to Sign In", message: error.localizedDescription)
                        return
                    }
                    guard let user = user else { return }

                    print("ID: \(String(describing: user.identity)), Total Users Logged In: \(SyncUser.all.count)")

                    let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: commonRealmURL), objectTypes: [Dog.self])

                    let adminRealm:Realm = try! Realm(configuration: config)

                    let permission = SyncPermissionValue(realmPath: adminRealm.configuration.syncConfiguration!.realmURL.path,
                                                         username: "user@host.com",
                                                         accessLevel: .write)
                    user.applyPermission(permission) { error in
                        if let error = error {
                            self.showError(title: "Unable to Apply Permissions", message: error.localizedDescription)
                            return
                        }
                    }

                    let myDog = Dog()
                    myDog.name = "admin" + Date().description
                    myDog.age = 1

                    try! adminRealm.write {
                        adminRealm.add(myDog)
                    }

                    let results = adminRealm.objects(Dog.self)

                    print("Number of results after admin login: \(results.count)")

                    self.logInUser()
                }
            })
        }

        let credentials = SyncCredentials.usernamePassword(username: "admin@host.com", password: "admin", register: false)

        logInBlock(credentials)

    }


    private func showError(title: String, message: String) {
        let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
        alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
        self.present(alertController, animated: true, completion: nil)
    }

    private func logInUser() {

        // Create the callback block that will perform the request
        let logInBlock: ((SyncCredentials) -> Void) = { credentials in
            SyncUser.logIn(with: credentials, server: syncAuthURL, timeout: 30, onCompletion: { (user, error) in
                DispatchQueue.main.async {
                    // Display an error message if the login failed
                    if let error = error {
                        self.showError(title: "Unable to Sign In", message: error.localizedDescription)
                        return
                    }
                    guard let user = user else { return }

                    let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: commonRealmURL), objectTypes: [Dog.self])
                    let userRealm = try! Realm(configuration: config)

                    let myDog = Dog()
                    myDog.name = "user" + Date().description
                    myDog.age = 2

                    try! userRealm.write {
                        userRealm.add(myDog)
                    }

                    let results = userRealm.objects(Dog.self)

                    print("Number of results after user login: \(results.count)")

                }
            })
        }

        let credentials = SyncCredentials.usernamePassword(username: "user@host.com", password: "user", register: false)

        logInBlock(credentials)



    }

}

你知道如何成功地为后台管理员用户分配权限吗?还是我最好使用不同的数据库结构?谢谢

你解决这个问题了吗?