irlnathan / activityoverlord20

This is an update to activityOverlord.
158 stars 52 forks source link

policyes does not work properly with sails 0.10.5 #1

Closed kazan417 closed 9 years ago

kazan417 commented 9 years ago

I cloned this repo, but policyes does not work. User can not see him profile and also can not edit him profile if not admin.

my UserCanSeeProfile.js module.exports = function(req, res, ok) {

var sessionUserMatchesId = req.session.User.id === req.param('id');
var isAdmin = req.session.User.admin;

// The requested id does not match the user's id,
// and this is not an admin
if (!(sessionUserMatchesId || isAdmin)) {
    var noRightsError = [{name: 'noRights', message: 'You must be an admin.'}]
    req.session.flash = {
        err: noRightsError
    }
res.redirect('/session/new');
return;
}

ok();

}; my policies.js

module.exports.policies = {

// Default policy for all controllers and actions
// (`true` allows public access) 
'*': "flash",

user: {
    'new': "flash",
    subscribe: ["flash", "authenticated"],
    create: "flash",
    show: true,
    edit: "userCanSeeProfile",
    update: "userCanSeeProfile",
    '*': "admin"
}

/*
// Here's an example of adding some policies to a controller
RabbitController: {

    // Apply the `false` policy as the default for all of RabbitController's actions
    // (`false` prevents all access, which ensures that nothing bad happens to our rabbits)
    '*': false,

    // For the action `nurture`, apply the 'isRabbitMother' policy 
    // (this overrides `false` above)
    nurture : 'isRabbitMother',

    // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies
    // before letting any users feed our rabbits
    feed : ['isNiceToAnimals', 'hasRabbitFood']
}
*/

};

kazan417 commented 9 years ago

ssory i make mistake. It about activityoverlord version 1