<commit_before><commit_msg>middleware permissions, object attrs visibility<commit_after>var models = require('../../models'),
	statusCodes = require('../statusCodes'),
	log = require('czagenda-log').from(__filename);
	
exports.getUserPermsAndGroups = function (req, res, next) {
	
	if (typeof(req.user) === 'undefined') {
		res.statusCode = statusCodes.FORBIDDEN;
		res.end('User unknow, access forbidden.');
		log.warning('req.user is undefined, sending 403')
		return;
	}
		
	models.User.get({id:req.user}, function (err, user) {
		
		if (user.isActive === false) {
			res.statusCode = statusCodes.FORBIDDEN;
			res.end('Account disabled');
			log.notice('Account is disabled, sending 403');
			return;
		}
		
		req.user = user.serialize(['id', 'isStaff', 'isSuperuser', 'isActive']);
		
		next();
	})
	
}


exports.staffOnly = function (req, res, next) {
	
	
	
	if (req.user.isStaff === true || req.user.isSuperuser) {
		log.debug('check staffOnly, granted');
		next();
	} else {
		log.debug('check staffOnly, forbidden');
		res.statusCode = statusCodes.FORBIDDEN;
		res.end('Insufficient privileges');
	}
		
}
{'fraction_non_alphanumeric': 0.1707097933513028, 'fraction_numerical': 0.005390835579514825, 'mean_word_length': 4.1336405529953915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7117585', 'n_tokens_mistral': 416, 'n_tokens_neox': 365, 'n_words': 75}