<commit_before>// ======== DB-Model: ========
// "_id" -> ID
// "title" -> string
// "description" -> string
// "mentors" -> [userIDs]   optional
// "startdate" -> ISODate
// "host" -> [userIDs]     optional
// "location" -> ...............
// "createdby" -> userId
// "time_created" -> timestamp
// "time_lastedit" -> timestamp
// "course_id" -> ID_course          (maybe list in Future)
// ===========================

Events = new Meteor.Collection("Events");


Events.allow({
	update: function (userId, doc, fieldNames, modifier) {
		return userId && true;	// allow only if UserId is present
	},
	insert: function (userId, doc) {
		return userId && true;	// allow only if UserId is present
	},
	remove: function (userId, doc) {
		return userId && true;	// allow only if UserId is present
	}
});

if (Meteor.isServer) {
	Events.before.insert(function(userId, event) {
		event.time_created = new Date();
		event.time_lastedit = event.time_created;
		event.description = saneHtml(event.description);
	});

	Events.before.update(function(userId, event, _, set) {
		set.$set.time_lastedit = new Date();
		set.$set.description = saneHtml(set.$set.description);
	});
}


Meteor.methods({
	saveEvent: function(eventId, changes) {
		check(eventId, String);
		
		var expectedFields = {
			title:       String,
			description: String,
			location:    String,
			room:        String,
			startdate:   Date,
			enddate:     Date
		}
		
		var isNew = eventId === '';
		if (isNew) {
			expectedFields.region = String;
			expectedFields.course_id = Match.Optional(String);
		}
		
		check(changes, expectedFields);

		var user = Meteor.user()
		if (!user) {
			if (Meteor.is_client) {
				pleaseLogin();
				return;
			} else {
				throw new Meteor.Error(401, "please log in")
			}
		}
		
		var now = new Date();
		
		changes.time_lastedit = now;
		
		if (isNew) {
			changes.time_created = now;
		}
		
		if (changes.startdate < now) {
			throw new Meteor.error(400, "Can't edit events in the past");
		}
		
		if (changes.enddate < changes.startdate) {
			throw new Meteor.error(400, "Enddate before startdate");
		}
		
		if (isNew) {
			var eventId = Events.insert(changes);
		} else {
			Events.update(eventId, { $set: changes });
		}
		
		return eventId;
	}
});


/* Find events for given filters
 *
 * filter: dictionary with filter options
 *   query: string of words to search for
 *   after: only events starting after this date
 *   ongoing: only events that are ongoing during this date
 *   before: only events that ended before this date
 *   location: only events at this location (string match)
 *   room: only events in this room (string match)
 *   standalone: only events that are not attached to a course
 * limit: how many to find
 *
 * The events are sorted by startdate (ascending, before-filter causes descending order)
 *
 */
eventsFind = function(filter, limit) {
	var find = {};
	var options = {
		sort: { startdate: 1 }
	};

	if (limit > 0) {
		options.limit = limit;
	}

	if (filter.after) {
		find.startdate = { $gt: filter.after };
	}

	if (filter.ongoing) {
		find.startdate = { $lte: filter.ongoing };
		find.enddate = { $gte: filter.ongoing };
	}

	if (filter.before) {
		find.enddate = { $lt: filter.before };
		if (!filter.after) options.sort = { startdate: -1 }
	}

	if (filter.location) {
		find.location = filter.location;
	}

	if (filter.room) {
		find.room = filter.room;
	}

	if (filter.standalone) {
		find.course_id = { $exists: false };
	}

	if (filter.query) {
		var searchTerms = filter.query.split(/\s+/);
		var searchQueries = _.map(searchTerms, function(searchTerm) {
			return { $or: [
				{ title: { $regex: escapeRegex(searchTerm), $options: 'i' } },
				{ description: { $regex: escapeRegex(searchTerm), $options: 'i' } }
			] }
		});

		find.$and = searchQueries;
	}

	return Events.find(find, options);
}

<commit_msg>remove obsolete update triggers<commit_after>// ======== DB-Model: ========
// "_id" -> ID
// "title" -> string
// "description" -> string
// "mentors" -> [userIDs]   optional
// "startdate" -> ISODate
// "host" -> [userIDs]     optional
// "location" -> ...............
// "createdby" -> userId
// "time_created" -> timestamp
// "time_lastedit" -> timestamp
// "course_id" -> ID_course          (maybe list in Future)
// ===========================

Events = new Meteor.Collection("Events");


Events.allow({
	update: function (userId, doc, fieldNames, modifier) {
		return userId && true;	// allow only if UserId is present
	},
	insert: function (userId, doc) {
		return userId && true;	// allow only if UserId is present
	},
	remove: function (userId, doc) {
		return userId && true;	// allow only if UserId is present
	}
});


Meteor.methods({
	saveEvent: function(eventId, changes) {
		check(eventId, String);
		
		var expectedFields = {
			title:       String,
			description: String,
			location:    String,
			room:        String,
			startdate:   Date,
			enddate:     Date
		}
		
		var isNew = eventId === '';
		if (isNew) {
			expectedFields.region = String;
			expectedFields.course_id = Match.Optional(String);
		}
		
		check(changes, expectedFields);

		var user = Meteor.user()
		if (!user) {
			if (Meteor.is_client) {
				pleaseLogin();
				return;
			} else {
				throw new Meteor.Error(401, "please log in")
			}
		}
		
		var now = new Date();
		
		changes.time_lastedit = now;
		
		if (isNew) {
			changes.time_created = now;
		}
		
		if (changes.startdate < now) {
			throw new Meteor.error(400, "Can't edit events in the past");
		}
		
		if (changes.enddate < changes.startdate) {
			throw new Meteor.error(400, "Enddate before startdate");
		}
		
		changes.description = saneHtml(changes.description);
		
		if (isNew) {
			var eventId = Events.insert(changes);
		} else {
			Events.update(eventId, { $set: changes });
		}
		
		return eventId;
	}
});


/* Find events for given filters
 *
 * filter: dictionary with filter options
 *   query: string of words to search for
 *   after: only events starting after this date
 *   ongoing: only events that are ongoing during this date
 *   before: only events that ended before this date
 *   location: only events at this location (string match)
 *   room: only events in this room (string match)
 *   standalone: only events that are not attached to a course
 * limit: how many to find
 *
 * The events are sorted by startdate (ascending, before-filter causes descending order)
 *
 */
eventsFind = function(filter, limit) {
	var find = {};
	var options = {
		sort: { startdate: 1 }
	};

	if (limit > 0) {
		options.limit = limit;
	}

	if (filter.after) {
		find.startdate = { $gt: filter.after };
	}

	if (filter.ongoing) {
		find.startdate = { $lte: filter.ongoing };
		find.enddate = { $gte: filter.ongoing };
	}

	if (filter.before) {
		find.enddate = { $lt: filter.before };
		if (!filter.after) options.sort = { startdate: -1 }
	}

	if (filter.location) {
		find.location = filter.location;
	}

	if (filter.room) {
		find.room = filter.room;
	}

	if (filter.standalone) {
		find.course_id = { $exists: false };
	}

	if (filter.query) {
		var searchTerms = filter.query.split(/\s+/);
		var searchQueries = _.map(searchTerms, function(searchTerm) {
			return { $or: [
				{ title: { $regex: escapeRegex(searchTerm), $options: 'i' } },
				{ description: { $regex: escapeRegex(searchTerm), $options: 'i' } }
			] }
		});

		find.$and = searchQueries;
	}

	return Events.find(find, options);
}


{'fraction_non_alphanumeric': 0.15640576586285868, 'fraction_numerical': 0.003233194126364004, 'mean_word_length': 3.0064759848893687, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '2446255', 'n_tokens_mistral': 2737, 'n_tokens_neox': 2423, 'n_words': 670}