middleware/_modelIndex.js
function (cb) {

                // skip this if canEdit is not define for model
                if (!mongooseRecords[0].canEdit) {
                    return cb(null);
                }

                async.each(Object.keys(mongooseRecords), function (index, recordDone) {

                    mongooseRecords[index].canEdit(req, function (err, result, message) {

                        if (err) {
                            return recordDone(err);
                        }

                        records[index].edit = { disabled: !result, message: message };

                        return recordDone(null);

                    });

                }, function (err) {

                    cb(err);

                });

            }
function (cb) {

                // skip this if canEdit is not define for model
                if (!mongooseRecords[0].canEdit) {
                    return cb(null);
                }

                async.each(Object.keys(mongooseRecords), function (index, recordDone) {

                    mongooseRecords[index].canEdit(req, function (err, result, message) {

                        if (err) {
                            return recordDone(err);
                        }

                        records[index].edit = { disabled: !result, message: message };

                        return recordDone(null);

                    });

                }, function (err) {

                    cb(err);

                });

            }
function ( cb ) { // skip this if canEdit is not define for model if ( ! mongooseRecords [ 0 ] . canEdit ) { return cb ( null ) ; } async . each ( Object . keys ( mongooseRecords ) , function ( index , recordDone ) { mongooseRecords [ index ] . canEdit ( req , function ( err , result , message ) { if ( err ) { return recordDone ( err ) ; } records [ index ] . edit = { disabled : ! result , message : message } ; return recordDone ( null ) ; } ) ; } , function ( err ) { cb ( err ) ; } ) ; }
check if each doc can be edited
check if each doc can be edited