diff --git a/src/models/attachment.js b/src/models/attachment.js index 3cd08b5a8..ef1f376d9 100644 --- a/src/models/attachment.js +++ b/src/models/attachment.js @@ -22,4 +22,10 @@ var attachmentSchema = mongoose.Schema({ type: { type: String, required: true } }); +attachmentSchema.pre('save', function(next) { + this.name = this.name.trim(); + + return next(); +}); + module.exports = attachmentSchema; \ No newline at end of file diff --git a/src/models/notice.js b/src/models/notice.js index 5192a74ec..c24bcdce7 100644 --- a/src/models/notice.js +++ b/src/models/notice.js @@ -40,6 +40,12 @@ var noticeSchema = mongoose.Schema({ alertWindow:{ type: Boolean, default: false } }); +noticeSchema.pre('save', function(next) { + this.name = this.name.trim(); + + return next(); +}); + noticeSchema.statics.getNotices = function(callback) { return this.model(COLLECTION).find({}).exec(callback); }; diff --git a/src/models/tag.js b/src/models/tag.js index ae78a5dcd..b7a648686 100644 --- a/src/models/tag.js +++ b/src/models/tag.js @@ -31,7 +31,8 @@ var tagSchema = mongoose.Schema({ }); tagSchema.pre('save', function(next) { - this.normalized = this.name.toLowerCase(); + this.name = this.name.trim(); + this.normalized = this.name.toLowerCase().trim(); return next(); }); diff --git a/src/models/ticket.js b/src/models/ticket.js index fa99c921b..8a27e90e3 100644 --- a/src/models/ticket.js +++ b/src/models/ticket.js @@ -91,6 +91,8 @@ var ticketSchema = mongoose.Schema({ ticketSchema.index({deleted: -1, group: 1, status: 1}); ticketSchema.pre('save', function(next) { + this.subject = this.subject.trim(); + if (!_.isUndefined(this.uid) || this.uid) return next(); diff --git a/src/models/ticketpriority.js b/src/models/ticketpriority.js index b437dab0a..3b1493087 100644 --- a/src/models/ticketpriority.js +++ b/src/models/ticketpriority.js @@ -32,6 +32,12 @@ var prioritySchema = mongoose.Schema({ } }); +prioritySchema.pre('save', function(next) { + this.name = this.name.trim(); + + return next(); +}); + prioritySchema.virtual('durationFormatted').get(function() { var priority = this; return moment.duration(priority.overdueIn, 'minutes').format('Y [year], M [month], d [day], h [hour], m [min]', {trim: 'both'}); diff --git a/src/models/tickettype.js b/src/models/tickettype.js index 96e6ec07d..22bf1e9a0 100644 --- a/src/models/tickettype.js +++ b/src/models/tickettype.js @@ -42,6 +42,12 @@ var autoPopulatePriorities = function(next) { ticketTypeSchema.pre('find', autoPopulatePriorities); ticketTypeSchema.pre('findOne', autoPopulatePriorities); +ticketTypeSchema.pre('save', function(next) { + this.name = this.name.trim(); + + return next(); +}); + /** * Return all Ticket Types * diff --git a/src/models/user.js b/src/models/user.js index 06c3d9dcb..6ae364827 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -82,6 +82,9 @@ userSchema.pre('save', function(next) { var user = this; user.username = user.username.trim(); + user.title = user.title.trim(); + user.email = user.email.trim(); + user.fullname = user.fullname.trim(); if (!user.isModified('password')) return next(); diff --git a/src/public/js/angularjs/controllers/settings.js b/src/public/js/angularjs/controllers/settings.js index 1c525fa34..0b42ca0cf 100644 --- a/src/public/js/angularjs/controllers/settings.js +++ b/src/public/js/angularjs/controllers/settings.js @@ -214,9 +214,10 @@ define(['angular', 'underscore', 'jquery', 'modules/helpers', 'modules/ui', 'uik if (response.success) { tags = response.tags; // tags = []; - if (tags.length === 0) - $tagWrapper.append('