<commit_before>var Base = require('./base.js').Base;
var util = require("util");
var utils = require('../libs/utils.js');
var errors = require('./errors.js');
var settings = require('../settings.js');

function Agenda () {
	this._attributs = {title : null, description : null, writeGroups : null, writeUsers : null, computedWriteUsers : [], computedWriteGroups : []};
	Base.call(this, 'agenda');	
}

util.inherits(Agenda, Base);

Agenda.publicAttributes = Base.publicAttributes.concat(['title', 'description', 'writeGroups', 'writeUsers']);
Agenda.staffAttributes = Agenda.publicAttributes.concat(Base.staffAttributes);

Agenda.publicWriteAttributes = ['title', 'description'];
Agenda.staffWriteAttributes = Agenda.publicWriteAttributes;


Agenda.prototype.hasPerm = function (perm, user, callback) {
	
	switch (perm) {
		case 'read':
		case 'create':
			callback(null, true);
			break;
					
		case 'write':
		case 'del':
			callback(null, this.hasWritePerm(user));
			break;
			
		default:
			return false;
		
	}
}

Agenda.prototype._validate = function (callback) {
	this.validateString('title', false, 5, 128);
	this.validateString('description', true, null, 1024);
	
	callback(null);
}

Agenda.prototype._generateHash = function () {
	c = require('crypto')
    h = c.createHash('md5')
    h.update(this._type);
	h.update(JSON.stringify(this.title));
	h.update(JSON.stringify(this.description));
	this._data['hash'] = h.digest('hex')
}

Agenda.prototype._generateId = function () {
	return '/agenda/' + utils.slugify(this.title);
}

/*
Agenda.prototype.save = function (callback) {
	
	if (typeof(this.title) !== 'string') {
		this.addValidationError('title', 'a string is required')
		callback(new errors.ValidationError(), this);
		return;
	}
	
	Base.prototype.save.call(this, callback);
	
}
*/
Agenda.prototype._preSave = function (callback) {
	if (this.id === null) {
		this._data.writeGroups = this._data.id + '/perms/wg';
		this._data.writeUsers = this._data.id + '/perms/wu';
	}<commit_msg>clean<commit_after>var Base = require('./base.js').Base;
var util = require("util");
var utils = require('../libs/utils.js');
var errors = require('./errors.js');
var settings = require('../settings.js');

function Agenda () {
	this._attributs = {title : null, description : null, writeGroups : null, writeUsers : null, computedWriteUsers : [], computedWriteGroups : []};
	Base.call(this, 'agenda');	
}

util.inherits(Agenda, Base);

Agenda.publicAttributes = Base.publicAttributes.concat(['title', 'description', 'writeGroups', 'writeUsers']);
Agenda.staffAttributes = Agenda.publicAttributes.concat(Base.staffAttributes);

Agenda.publicWriteAttributes = ['title', 'description'];
Agenda.staffWriteAttributes = Agenda.publicWriteAttributes;


Agenda.prototype.hasPerm = function (perm, user, callback) {
	
	switch (perm) {
		case 'read':
		case 'create':
			callback(null, true);
			break;
					
		case 'write':
		case 'del':
			callback(null, this.hasWritePerm(user));
			break;
			
		default:
			return false;
		
	}
}

Agenda.prototype._validate = function (callback) {
	this.validateString('title', false, 5, 128);
	this.validateString('description', true, null, 1024);
	
	callback(null);
}

Agenda.prototype._generateHash = function () {
	c = require('crypto')
    h = c.createHash('md5')
    h.update(this._type);
	h.update(JSON.stringify(this.title));
	h.update(JSON.stringify(this.description));
	this._data['hash'] = h.digest('hex')
}

Agenda.prototype._generateId = function () {
	return '/agenda/' + utils.slugify(this.title);
}

Agenda.prototype._preSave = function (callback) {
	if (this.id === null) {
		this._data.writeGroups = this._data.id + '/perms/wg';
		this._data.writeUsers = this._data.id + '/perms/wu';
	}
{'fraction_non_alphanumeric': 0.17216411906677392, 'fraction_numerical': 0.004827031375703942, 'mean_word_length': 4.625942684766215, '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': '60967', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1191, 'n_words': 233}