如何防止用户编辑特定列,同时仍然对 Parse 上的对象具有写入权限?

How to prevent user editing a specific column while still having write access to the object on Parse?

我的 _User class 上有一些特定的列,我只想在服务器端使用主密钥进行编辑。我的用户确实对自己有写访问权限。有没有办法阻止我的用户编辑特定的列,例如,假设我有一个用户对象,我希望用户阻止编辑自己的点:

before save trigger:
 if(points field have been changed by the user){
  response.error();
 )

它不必在保存触发器之前,但我非常怀疑是否有任何其他点可以检查这样的 "dirty" 列(如果有的话)。有没有办法实现我所需要的(除了显而易见的解决方案,例如创建新的 class、将其 ACL 设置为 none、持有用户指针和分数列并仅使用主键进行编辑)?

这是Parse JavaScript Documentation related to "dirty" objects and properties.

{Boolean} dirty(attr)

Returns true if this object has been modified since its last save/refresh. If an attribute is specified, it returns true only if that particular attribute has been modified since the last save/refresh.

Parameters: {String} attr

An attribute name (optional).

Returns: {Boolean}

如果你结合那个位(用 beforeSave() Cloud Code function 调用 dirty("score")),你应该得到你想要的。

Modifying Objects On Save

In some cases, you don't want to throw out invalid data. You just want to tweak it a bit before saving it. beforeSave can handle this case, too. You just call response.success on the altered object.

In our movie review example, we might want to ensure that comments aren't too long. A single long comment might be tricky to display. We can use beforeSave to truncate the comment field to 140 characters:

Parse.Cloud.beforeSave("Review", function(request, response) {
    var comment = request.object.get("comment");
    if (comment.length > 140) {
        // Truncate and add a ...
       request.object.set("comment", comment.substring(0, 137) + "...");
    }
    response.success();
});