SDK 版本 LeanCloud-Swift-SDK/17.6.0
按默认设置新建一个Todo表,新增一条记录并把ACL设置为可读可写{"*":{"read":true,"write":true}},尝试修改这条记录的ACL,没有问题:
func editACL(userID: String){
let query = LCQuery(className: "Todo")
query.includeACL = true
query.whereKey("aa", .equalTo("rr"))
_ = query.getFirst() { result in
switch result {
case .success(object: let todo):
print("todo.ACL (todo.ACL?.jsonValue)")
if let acl = todo.ACL{
acl.setAccess([.read], allowed: true, forUserID: userID)
todo.ACL = acl
// 将对象保存到云端
_ = todo.save { result in
switch result {
case .success:
// 成功保存之后,执行其他逻辑
print("success(todo.ACL?.jsonValue)")
break
case .failure(error: let error):
// 异常处理
print("error (error)")
}
}
}
case .failure(error: let error):
print(error)
}
}
}
打印如下:
todo.ACL Optional(["*": ["write": true, "read": true]])
success Optional(["5eea18b81b698900085adb88": ["read": true], "*": ["write": true, "read": true]])
然后进入控制台,在控制台设置 Todo 的add_fields权限为指定用户(指定用户为空),在控制台设置刚才的记录ACL为所有用户可读可写{"*":{"read":true,"write":true}},然后重新执行上面代码,打印如下:
todo.ACL Optional(["*": ["write": true, "read": true]])
error LCError(code: 403, reason: "Forbidden to add new fields by class 'Todo' permissions.")
修改ACL其实并没有增加新的fields,如何在限制add_fields权限的情况下修改ACL?