Skip to content

Commit 7a7121d

Browse files
committed
Upgraded packages
Added editSelf to SingleTIcket view Fixed issues with counters when using Mongoose 4.0
1 parent ddaa80f commit 7a7121d

File tree

10 files changed

+81
-41
lines changed

10 files changed

+81
-41
lines changed

app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var async = require('async'),
1616
path = require('path'),
1717
fs = require('fs'),
1818
winston = require('winston'),
19+
wConfig = require('winston/lib/winston/config'),
1920
nconf = require('nconf'),
2021
pkg = require('./package.json');
2122

@@ -53,7 +54,7 @@ if (!process.send) {
5354
winston.info(' 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b.');
5455
winston.info(' "888" d888b `V88V"V8P\' `Y8bod88P" `Y8bod8P\' 8""888P\' o888o o888o');
5556
winston.info('==========================================================================');
56-
winston.info('TruDesk v' + pkg.version + ' Copyright (C) 2014-2015 Polonel.com');
57+
winston.info('TruDesk v' + pkg.version + ' Copyright (C) 2014-2015 Chris Brame');
5758
winston.info('');
5859
winston.info('Running in: ' + global.env);
5960
winston.info('Time: ' + new Date());

package.json

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
{
22
"name": "Trudesk",
3-
"version": "0.0.1",
3+
"version": "1.0.0",
44
"private": true,
55
"scripts": {
66
"start": "node ./app"
77
},
88
"dependencies": {
99
"apn": "^1.7.3",
1010
"async": "^0.9.0",
11-
"bcrypt": "^0.8.1",
12-
"body-parser": "^1.12.0",
13-
"chance": "^0.7.3",
11+
"bcrypt": "^0.8.2",
12+
"body-parser": "^1.12.3",
13+
"chance": "^0.7.4",
1414
"connect-flash": "^0.1.1",
15-
"connect-mongo": "^0.7.0",
15+
"connect-mongo": "^0.8.1",
1616
"cookie": "^0.1.2",
1717
"cookie-parser": "^1.3.4",
1818
"daemon": "^1.1.0",
19-
"debug": "^2.1.1",
20-
"email-templates": "^1.1.2",
21-
"express": "^4.11.2",
22-
"express-hbs": "^0.8.0",
23-
"express-session": "^1.10.3",
24-
"handlebars": "^3.0.0",
25-
"lodash": "^3.2.0",
19+
"debug": "^2.1.3",
20+
"email-templates": "^1.2.1",
21+
"express": "^4.12.3",
22+
"express-hbs": "^0.8.4",
23+
"express-session": "^1.11.1",
24+
"handlebars": "^3.0.3",
25+
"lodash": "^3.7.0",
2626
"logrotate-stream": "^0.2.5",
2727
"marked": "^0.3.3",
28-
"moment": "^2.9.0",
29-
"mongoose": "^3.8.23",
30-
"mongoose-deep-populate": "0.0.7",
31-
"morgan": "^1.5.1",
32-
"multer": "^0.1.7",
28+
"moment": "^2.10.2",
29+
"mongoose": "^4.0.2",
30+
"mongoose-deep-populate": "1.1.0",
31+
"morgan": "^1.5.2",
32+
"multer": "^0.1.8",
3333
"nconf": "^0.7.1",
34-
"nodemailer": "^1.3.0",
34+
"nodemailer": "^1.3.4",
3535
"passport": "^0.2.1",
3636
"passport-http": "^0.2.2",
3737
"passport-local": "^1.0.0",
38-
"passport.socketio": "^3.4.1",
38+
"passport.socketio": "^3.5.1",
3939
"prompt": "^0.2.14",
4040
"serve-favicon": "^2.2.0",
41-
"socket.io": "^1.3.4",
42-
"socket.io-client": "^1.3.4",
43-
"uglify-js": "^2.4.16",
44-
"underscore": "^1.7.0",
41+
"socket.io": "^1.3.5",
42+
"socket.io-client": "^1.3.5",
43+
"uglify-js": "^2.4.20",
44+
"underscore": "^1.8.3",
4545
"underscore.string": "^3.0.3",
4646
"winston": "^0.9.0"
4747
},
4848
"devDependencies": {
4949
"grunt": "^0.4.5",
50-
"grunt-contrib-cssmin": "^0.12.1",
50+
"grunt-contrib-cssmin": "^0.12.2",
5151
"grunt-contrib-sass": "^0.9.2",
52-
"grunt-contrib-uglify": "^0.7.0",
52+
"grunt-contrib-uglify": "^0.9.1",
5353
"grunt-contrib-watch": "^0.6.1",
5454
"grunt-cssc": "^0.2.6",
55-
"grunt-express-server": "^0.4.19",
55+
"grunt-express-server": "^0.5.1",
5656
"grunt-htmlhint": "^0.4.1",
57-
"grunt-parallel": "^0.3.1",
57+
"grunt-parallel": "^0.4.1",
5858
"matchdep": "^0.3.0"
5959
}
6060
}

private/.gitkeep

Whitespace-only changes.

src/emitter/events.js

+4
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,8 @@ var templateDir = path.resolve(__dirname, '..', 'mailer', 'templates');
130130
io.sockets.emit('updateComments', ticket);
131131
});
132132

133+
emitter.on('notification:added', function(notification) {
134+
135+
});
136+
133137
})();

src/helpers/hbs/helpers.js

+14
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,19 @@ var helpers = {
490490
}
491491
},
492492

493+
checkEditSelf: function(user, owner, options) {
494+
var P = require('../../permissions');
495+
if (P.canThis(user.role, 'ticket:editSelf')) {
496+
if (user._id.toString() == owner._id.toString()) {
497+
return options.fn(this);
498+
} else {
499+
return options.inverse(this);
500+
}
501+
}
502+
503+
return options.inverse(this);
504+
},
505+
493506
hasGroup: function(arr, value, options) {
494507
var result = _.some(arr, function(i) {
495508
if (_.isUndefined(i) || _.isUndefined(value)) return false;
@@ -516,6 +529,7 @@ helpers.ifLtEq = helpers.if_lteq;
516529
helpers.unlessLtEq = helpers.unless_lteq;
517530
helpers.foreach = helpers.forEach;
518531
helpers.canUser = helpers.checkPerm;
532+
helpers.canEditSelf = helpers.checkEditSelf;
519533
helpers.inArray = helpers.hasGroup;
520534

521535

src/helpers/viewdata/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
**/
1414

1515
var async = require('async'),
16-
_ = require('lodash'),
16+
_ = require('underscore'),
1717
winston = require('winston');
1818

1919
var viewController = {};

src/models/counters.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
**/
1414

1515
var mongoose = require('mongoose');
16-
var _ = require('lodash');
16+
var _ = require('underscore');
1717

1818
var COLLECTION = 'counters';
1919

@@ -22,12 +22,8 @@ var countersSchema = mongoose.Schema({
2222
next: Number
2323
});
2424

25-
countersSchema.statics.findAndModify = function (query, sort, doc, options, callback) {
26-
return this.collection.findAndModify(query, sort, doc, options, callback);
27-
};
28-
2925
countersSchema.statics.increment = function (counter, callback) {
30-
return this.collection.findAndModify({ _id: counter }, [], { $inc: { next: 1 } }, callback);
26+
return this.collection.findOneAndUpdate({ _id: counter }, { $inc: { next: 1 }}, callback);
3127
};
3228

3329
module.exports = mongoose.model(COLLECTION, countersSchema);

src/models/ticket.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var historySchema = require('./history');
2626
var COLLECTION = 'tickets';
2727

2828
var ticketSchema = mongoose.Schema({
29-
uid: { type: Number },
29+
uid: { type: Number, unique: true},
3030
owner: { type: mongoose.Schema.Types.ObjectId, required: true, ref: 'accounts' },
3131
group: { type: mongoose.Schema.Types.ObjectId, required: true, ref: 'groups' },
3232
assignee: { type: mongoose.Schema.Types.ObjectId, ref: 'accounts' },
@@ -47,13 +47,21 @@ var ticketSchema = mongoose.Schema({
4747
ticketSchema.plugin(deepPopulate);
4848

4949
ticketSchema.pre('save', function(next) {
50-
if (!_.isUndefined(this.uid)|| this.uid) return next();
50+
if (!_.isUndefined(this.uid) || this.uid) return next();
5151

5252
var c = require('./counters');
5353
var self = this;
54-
c.increment('tickets', function(err, res) {
55-
self.uid = res.next;
56-
next();
54+
c.increment('tickets', function(err, res, k) {
55+
if (err) return next(err);
56+
57+
self.uid = res.value.next;
58+
59+
if (_.isUndefined(self.uid)) {
60+
var error = new Error('Invalid UID.');
61+
return next(error);
62+
}
63+
64+
return next();
5765
});
5866
});
5967

src/permissions/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ var canThis = function(role, a) {
5959

6060
var actionType = a.split(':')[0];
6161
var action = a.split(':')[1];
62+
6263
if (_.isUndefined(actionType) || _.isUndefined(action)) return false;
6364

6465
var result = _.filter(rolePerm.allowedAction, function(value) {

src/views/subviews/singleticket.hbs

+17-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
{{{data.ticket.issue}}}
178178
</div>
179179
</div>
180-
{{#canUser data.user "tickets:edit"}}
180+
{{#canUser data.user "ticket:edit"}}
181181
<div class="edit-issue-form clearfix hide" style="margin-bottom: 15px;">
182182
<form id="edit-issue-form" ng-submit="updateTicketIssue()" data-abide>
183183
<div class="edit-issue-box">
@@ -191,6 +191,22 @@
191191
</form>
192192
</div>
193193
<div class="edit-issue"><i class="fa fa-pencil fa-lg"></i></div>
194+
{{else}}
195+
{{#canEditSelf data.user data.ticket.owner}}
196+
<div class="edit-issue-form clearfix hide" style="margin-bottom: 15px;">
197+
<form id="edit-issue-form" ng-submit="updateTicketIssue()" data-abide>
198+
<div class="edit-issue-box">
199+
<textarea name="issueText" id="issueText" cols="2" rows="5" data-clearOnSubmit="true" required pattern="is5Long"></textarea>
200+
<small class="error">Please enter a valid issue. Issue must contain at least 5 characters.</small>
201+
</div>
202+
<div class="right">
203+
<button type="reset" ng-click="editIssueCancelClicked($event)">Cancel</button>
204+
<button type="submit" data-preventDefault="false">Save</button>
205+
</div>
206+
</form>
207+
</div>
208+
<div class="edit-issue"><i class="fa fa-pencil fa-lg"></i></div>
209+
{{/canEditSelf}}
194210
{{/canUser}}
195211
</div>
196212
<div class="comments" data-ticketId="{{data.ticket._id}}">

0 commit comments

Comments
 (0)