forked from node4good/jest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mongoose_authorization.js
43 lines (37 loc) · 1.13 KB
/
mongoose_authorization.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var Authorization = require('./authorization');
var MongooseAuthorization = module.exports = Authorization.extend({
init:function (user_field) {
this._super();
this.user_field = user_field;
},
get_user_id:function (req) {
return null;
},
limit_object_list:function (req, query, callback) {
var user_id = this.get_user_id(req);
if (!user_id)
callback({message:'cant get user id'});
else {
query.where(this.user_field, user_id);
callback(null, query);
}
},
limit_object:function (req, object, callback) {
var user_id = this.get_user_id(req);
if (!user_id)
callback({message:'cant get user id'});
else {
object.set(this.user_field, user_id);
callback(null, object);
}
},
edit_object:function (req, object, callback) {
var user_id = this.get_user_id(req);
if (!user_id)
callback({message:'cannot get user id'});
else {
object[this.user_field] = user_id;
callback(null, object);
}
}
});