Last active
August 29, 2015 14:11
-
-
Save swist/56429283fe3eec8a9dd1 to your computer and use it in GitHub Desktop.
sails resource policy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Graph.js | |
* | |
* @description :: TODO: You might write a short summary of how this model works and what it represents here. | |
* @docs :: http://sailsjs.org/#!documentation/models | |
*/ | |
module.exports = { | |
attributes: { | |
uuid: { | |
type: 'string', | |
primaryKey: true, | |
required: true | |
}, | |
user: { | |
model: 'User', | |
via: 'graphs', | |
required: true | |
} | |
} | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets the current user from session, or returns 403 | |
*/ | |
module.exports = function(req, res, next) { | |
// User is allowed, proceed to controller | |
if (req.session.user) { | |
if (!req.query) { | |
req.query = {}; | |
} | |
sails.log.debug('setting req query'); | |
req.query.user = req.session.user.id; | |
return next(); | |
} | |
// User is not allowed | |
else { | |
return res.send('You are not permitted to perform this action.', 403); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* User.js | |
* | |
* @description :: TODO: You might write a short summary of how this model works and what it represents here. | |
* @docs :: http://sailsjs.org/#!documentation/models | |
*/ | |
var User = { | |
// Enforce model schema in the case of schemaless databases | |
schema: true, | |
attributes: { | |
username : { type: 'string', unique: true }, | |
email : { type: 'email', unique: true }, | |
passports : { collection: 'Passport', via: 'user' }, | |
graphs : { collection: 'Graph', via: 'user'} | |
} | |
}; | |
module.exports = User; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment