2013-03-18 86 views
4

我正在嘗試向收藏集添加「收視率」屬性,並希望允許任何用戶(而不僅僅是所有者)能夠將收視率添加到收藏集中的收視率集。我的問題是,我設置了允許/拒絕規則,只有所有者可以對他們擁有的集合執行更新。是否有辦法允許任何用戶只有在更新某個特定屬性(「評分」集合)時才更新集合,並且如果他們嘗試更新任何其他屬性,拒絕他們更新訪問權限。允許更新特定集合屬性

我的允許/拒絕在服務器上的規則如下...

Playlists.allow({ 
    insert: function(userId, doc) { 
    return (userId && doc.owner === userId); 
    }, 
    update: function (userId, docs, fields, modifier) { 
    return _.all(docs, function(doc) { 
     return doc.owner === userId; 
    }); 
    }, 
    remove: function (userId, docs) { 
    return _.all(docs, function(doc) { 
     return doc.owner === userId; 
    }); 
    } 
}); 

Playlists.deny({ 
    update: function (userId, docs, fields, modifier) { 
    return _.contains(fields, 'owner'); 
    }, 
    remove: function (userId, docs) { 
    return _.any(docs, function (doc) { 
     return doc.locked; 
    }); 
    }, 
    fetch: ['locked'] 
}); 

回答

3

Playlists.deny.update,你可以改變邏輯,這樣它首先檢查是否有人試圖修改收視率屬性(如:與$addToSet)和return false如果是這樣。所以,你最終會使用如下代碼:

Playlists.deny({ 
    update: function(userId, docs, fields, modifier) { 
     if (fields.ratings && modifier["$addToSet"] && modifier["$addToSet"].ratings) { 
     return false; // don't deny this 
     } 
     else { 
     return _.contains(fields, 'owner'); 
     } 
    } 
    }); 
+0

我試圖做的正是這一點,但它似乎沒有工作。所以,我在allow函數中添加了類似的檢查,並且工作。唯一的問題是,它會導致內部服務錯誤與播放列表集合的其他類型的更新。我不確定這是否是正確的解決方案,或者如果我遇到的問題只是針對我的應用程序。感謝您的建議,但。 – fakepancake 2013-03-18 19:48:55

-2

創建Meteor.methods({updateRatePlaylist:myUpdateRatePlaylistFunction})