@dhyasama/totem-models 3.2.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Account.js +24 -111
- package/lib/Document.js +4 -2
- package/lib/Interaction.js +1 -1
- package/lib/Message.js +2 -1
- package/lib/Organization.js +10 -2
- package/lib/Person.js +1 -1
- package/package.json +3 -3
- package/test/Account.js +2 -35
- package/test/Document.js +22 -5
- package/test/Message.js +6 -3
- package/test/Person.js +0 -3
- package/.npmignore +0 -14
- package/package-lock.json +0 -1168
package/lib/Account.js
CHANGED
|
@@ -14,33 +14,9 @@ module.exports = function(mongoose, config) {
|
|
|
14
14
|
var Account = new Schema({
|
|
15
15
|
|
|
16
16
|
username: { type: String, required: true, unique: true },
|
|
17
|
-
password: { type: String, default: '' },
|
|
18
17
|
email: { type: String, required: true, unique: true },
|
|
19
|
-
reset: {
|
|
20
|
-
token: { type: String },
|
|
21
|
-
expiresOn: { type: Date }
|
|
22
|
-
},
|
|
23
|
-
setup: {
|
|
24
|
-
token: { type: String },
|
|
25
|
-
expiresOn: { type: Date },
|
|
26
|
-
complete: { type: Boolean},
|
|
27
|
-
terms: {
|
|
28
|
-
raw: { type: String },
|
|
29
|
-
hash: { type: String }
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
twoFactorAuth: {
|
|
33
|
-
enabled: { type: Boolean },
|
|
34
|
-
phone: { type: String },
|
|
35
|
-
country: {
|
|
36
|
-
callingCode: { type: String },
|
|
37
|
-
abbreviation: { type: String }
|
|
38
|
-
},
|
|
39
|
-
verified: { type: Boolean }
|
|
40
|
-
},
|
|
41
18
|
admin: { type: Boolean },
|
|
42
19
|
active: { type: Boolean },
|
|
43
|
-
subscriber: { type: Boolean },
|
|
44
20
|
role: { type: String, enum: ['admin', 'lp-full', 'lp-names', 'welcome', 'none'] },
|
|
45
21
|
|
|
46
22
|
// Enable this and iLevel links will show on portfolio pages
|
|
@@ -85,12 +61,30 @@ module.exports = function(mongoose, config) {
|
|
|
85
61
|
calendar: {
|
|
86
62
|
active: { type: Boolean, default: false }, // only pull if this is active
|
|
87
63
|
forcePullAll: { type: Boolean, default: false } // override newest event date as min and go back all the way
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
inbound: {
|
|
67
|
+
active: { type: Boolean, default: false }
|
|
88
68
|
}
|
|
89
69
|
|
|
90
70
|
});
|
|
91
71
|
|
|
92
|
-
Account.
|
|
93
|
-
|
|
72
|
+
Account.statics.findByEmail = function(email, cb) {
|
|
73
|
+
this
|
|
74
|
+
.findOne({ 'email': email})
|
|
75
|
+
.populate('person')
|
|
76
|
+
.exec(function (err, account) {
|
|
77
|
+
cb(err, account);
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
Account.statics.findByUsername = function(username, cb) {
|
|
82
|
+
this
|
|
83
|
+
.findOne({ 'username': new RegExp(username, 'i') })
|
|
84
|
+
.populate('person')
|
|
85
|
+
.exec(function (err, account) {
|
|
86
|
+
cb(err, account);
|
|
87
|
+
});
|
|
94
88
|
};
|
|
95
89
|
|
|
96
90
|
Account.statics.getById = function (id, cb) {
|
|
@@ -127,91 +121,6 @@ module.exports = function(mongoose, config) {
|
|
|
127
121
|
.exec(cb);
|
|
128
122
|
};
|
|
129
123
|
|
|
130
|
-
Account.statics.upsert = function(account, cb) {
|
|
131
|
-
account.save(cb);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
Account.statics.findByUsername = function(username, cb) {
|
|
135
|
-
this
|
|
136
|
-
.findOne({ 'username': new RegExp(username, 'i') })
|
|
137
|
-
.populate('person')
|
|
138
|
-
.exec(function (err, account) {
|
|
139
|
-
cb(err, account);
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
Account.statics.findByEmail = function(email, cb) {
|
|
144
|
-
this
|
|
145
|
-
.findOne({ 'email': email})
|
|
146
|
-
.populate('person')
|
|
147
|
-
.exec(function (err, account) {
|
|
148
|
-
cb(err, account);
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
Account.statics.findByffEmail = function(email, cb) {
|
|
153
|
-
email = email.toLowerCase();
|
|
154
|
-
|
|
155
|
-
if (email.indexOf('@ffvc.com') > -1) {
|
|
156
|
-
this
|
|
157
|
-
.findOne({ 'email': email})
|
|
158
|
-
.populate('person')
|
|
159
|
-
.exec(function (err, account) {
|
|
160
|
-
cb(err, account);
|
|
161
|
-
});
|
|
162
|
-
} else {
|
|
163
|
-
//passing in null err so passport hits failureRedirect: '/login'
|
|
164
|
-
cb(null, null);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
Account.statics.findByResetToken = function(token, cb) {
|
|
169
|
-
this
|
|
170
|
-
.findOne({ 'reset.token': token})
|
|
171
|
-
.populate('person')
|
|
172
|
-
.exec(function (err, account) {
|
|
173
|
-
cb(err, account);
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
Account.statics.findBySetupToken = function(token, cb) {
|
|
178
|
-
this
|
|
179
|
-
.findOne({ 'setup.token': token})
|
|
180
|
-
.populate('person')
|
|
181
|
-
.exec(function (err, account) {
|
|
182
|
-
cb(err, account);
|
|
183
|
-
});
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
Account.statics.findByCredentials = function (username, cleartextPassword, cb) {
|
|
187
|
-
|
|
188
|
-
this
|
|
189
|
-
.findOne({ 'username': new RegExp(username, 'i') })
|
|
190
|
-
.populate('person')
|
|
191
|
-
.exec(function (err, account) {
|
|
192
|
-
|
|
193
|
-
if (err) {
|
|
194
|
-
return cb(err, null);
|
|
195
|
-
}
|
|
196
|
-
else if (account != null) {
|
|
197
|
-
|
|
198
|
-
// found user, now check password
|
|
199
|
-
|
|
200
|
-
bcrypt.compare(cleartextPassword, account.password, function(err, res) {
|
|
201
|
-
if (err) { return cb(err, null); } // error
|
|
202
|
-
else if (res) { return cb(null, account); } // correct password
|
|
203
|
-
else { return cb(null, null); } // wrong password
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
return cb(null, null); // user not found
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
};
|
|
214
|
-
|
|
215
124
|
Account.statics.listGoogleAccounts = function(cb) {
|
|
216
125
|
|
|
217
126
|
this
|
|
@@ -252,6 +161,10 @@ module.exports = function(mongoose, config) {
|
|
|
252
161
|
|
|
253
162
|
};
|
|
254
163
|
|
|
164
|
+
Account.statics.upsert = function(account, cb) {
|
|
165
|
+
account.save(cb);
|
|
166
|
+
};
|
|
167
|
+
|
|
255
168
|
Account.post('remove', function(doc) {
|
|
256
169
|
// CalendarEvent.account
|
|
257
170
|
// Person.account
|
package/lib/Document.js
CHANGED
|
@@ -25,7 +25,10 @@ module.exports = function(mongoose, config) {
|
|
|
25
25
|
|
|
26
26
|
contentLength: { type: String, required: true },
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
s3: {
|
|
29
|
+
bucket: { type: String, required: true, trim: true },
|
|
30
|
+
key: { type: String, required: true, trim: true }
|
|
31
|
+
}
|
|
29
32
|
|
|
30
33
|
});
|
|
31
34
|
|
|
@@ -61,7 +64,6 @@ module.exports = function(mongoose, config) {
|
|
|
61
64
|
};
|
|
62
65
|
|
|
63
66
|
doc.createdOn = new Date();
|
|
64
|
-
doc.customer = config.CUSTOMER_ID;
|
|
65
67
|
|
|
66
68
|
this.create(doc, addToModel);
|
|
67
69
|
|
package/lib/Interaction.js
CHANGED
package/lib/Message.js
CHANGED
|
@@ -25,7 +25,8 @@ module.exports = function(mongoose, config) {
|
|
|
25
25
|
external: [{ type: Schema.ObjectId, ref: 'Person', index: true }] // everyone else
|
|
26
26
|
},
|
|
27
27
|
notes: [ { type: Schema.ObjectId, ref: 'Note' } ],
|
|
28
|
-
documents: [ { type: Schema.ObjectId, ref: 'Document' } ]
|
|
28
|
+
documents: [ { type: Schema.ObjectId, ref: 'Document' } ],
|
|
29
|
+
raw: { type: Schema.Types.Mixed, required: true }
|
|
29
30
|
|
|
30
31
|
});
|
|
31
32
|
|
package/lib/Organization.js
CHANGED
|
@@ -175,6 +175,14 @@ module.exports = function(mongoose, config) {
|
|
|
175
175
|
|
|
176
176
|
eshares: {
|
|
177
177
|
firmid: { type: String, unique: true, partialFilterExpression : { type :"string" }, trim: true }
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
calendar: {
|
|
181
|
+
active: { type: Boolean, default: false }
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
inbound: {
|
|
185
|
+
active: { type: Boolean, default: false }
|
|
178
186
|
}
|
|
179
187
|
|
|
180
188
|
},
|
|
@@ -722,7 +730,7 @@ module.exports = function(mongoose, config) {
|
|
|
722
730
|
};
|
|
723
731
|
|
|
724
732
|
Organization.statics.findBySlugs = function findBySlugs(slugs, cb) {
|
|
725
|
-
this.find({ 'slug': { $in : slugs }
|
|
733
|
+
this.find({ 'slug': { $in : slugs } }).exec(cb);
|
|
726
734
|
};
|
|
727
735
|
|
|
728
736
|
Organization.statics.findDupes = function findDupes(org, options, cb) {
|
|
@@ -1306,7 +1314,7 @@ module.exports = function(mongoose, config) {
|
|
|
1306
1314
|
self.people = _.reject(self.people, function(p) { return p.person == null; });
|
|
1307
1315
|
|
|
1308
1316
|
// dedupe
|
|
1309
|
-
self.people = _.uniq(self.people, function(p) { return p.person._id ? p.person._id : p.person; });
|
|
1317
|
+
self.people = _.uniq(self.people, function(p) { return p.person._id ? p.person._id.toString() : p.person.toString(); });
|
|
1310
1318
|
|
|
1311
1319
|
};
|
|
1312
1320
|
|
package/lib/Person.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhyasama/totem-models",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"author": "Jason Reynolds",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "Models for Totem platform",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"@dhyasama/ffvc-crypto": "^1.0.0",
|
|
16
16
|
"@dhyasama/ffvc-geoip": "^1.0.0",
|
|
17
17
|
"@dhyasama/ffvc-s3": "^1.0.0",
|
|
18
|
-
"@dhyasama/ffvc-utilities": "^2.
|
|
19
|
-
"async": "^2.6.
|
|
18
|
+
"@dhyasama/ffvc-utilities": "^2.3.1",
|
|
19
|
+
"async": "^2.6.1",
|
|
20
20
|
"awesome-phonenumber": "^1.0.14",
|
|
21
21
|
"bcrypt": "^0.8.0",
|
|
22
22
|
"bluebird": "^3.5.0",
|
package/test/Account.js
CHANGED
|
@@ -45,10 +45,7 @@ describe('Account', function() {
|
|
|
45
45
|
var account = new Account();
|
|
46
46
|
|
|
47
47
|
account.username = 'testy';
|
|
48
|
-
account.email = '
|
|
49
|
-
account.reset.token = '123456789';
|
|
50
|
-
account.setup.token = '987654321';
|
|
51
|
-
account.password = hash;
|
|
48
|
+
account.email = 'test@totemvc.com';
|
|
52
49
|
account.person = newPerson;
|
|
53
50
|
account.active = true;
|
|
54
51
|
|
|
@@ -88,37 +85,7 @@ describe('Account', function() {
|
|
|
88
85
|
|
|
89
86
|
it('finds by email', function(done) {
|
|
90
87
|
|
|
91
|
-
Account.findByEmail('
|
|
92
|
-
should.not.exist(err);
|
|
93
|
-
should.exist(account);
|
|
94
|
-
done();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('finds by reset token', function(done) {
|
|
100
|
-
|
|
101
|
-
Account.findByResetToken('123456789', function(err, account) {
|
|
102
|
-
should.not.exist(err);
|
|
103
|
-
should.exist(account);
|
|
104
|
-
done();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('finds by setup token', function(done) {
|
|
110
|
-
|
|
111
|
-
Account.findBySetupToken('987654321', function(err, account) {
|
|
112
|
-
should.not.exist(err);
|
|
113
|
-
should.exist(account);
|
|
114
|
-
done();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('finds by username and password', function(done) {
|
|
120
|
-
|
|
121
|
-
Account.findByCredentials('testy', 'testy', function(err, account) {
|
|
88
|
+
Account.findByEmail('test@totemvc.com', function(err, account) {
|
|
122
89
|
should.not.exist(err);
|
|
123
90
|
should.exist(account);
|
|
124
91
|
done();
|
package/test/Document.js
CHANGED
|
@@ -51,7 +51,8 @@ describe('Document', function() {
|
|
|
51
51
|
|
|
52
52
|
message = new Message({
|
|
53
53
|
webhook: new mongoose.Types.ObjectId(),
|
|
54
|
-
customer: config.CUSTOMER_ID
|
|
54
|
+
customer: config.CUSTOMER_ID,
|
|
55
|
+
raw: { test: 'test' }
|
|
55
56
|
});
|
|
56
57
|
|
|
57
58
|
Message.upsert(message, function(err, result) {
|
|
@@ -129,11 +130,15 @@ describe('Document', function() {
|
|
|
129
130
|
it('creates a document for an interaction', function(done) {
|
|
130
131
|
|
|
131
132
|
Document.createForModel({
|
|
133
|
+
customer: config.CUSTOMER_ID,
|
|
132
134
|
createdBy: documentCreator,
|
|
133
135
|
name: 'your_mom.doc',
|
|
134
136
|
contentType: 'application/doc',
|
|
135
137
|
contentLength: 1248,
|
|
136
|
-
|
|
138
|
+
s3: {
|
|
139
|
+
bucket: 'totem',
|
|
140
|
+
key: 'docs'
|
|
141
|
+
}
|
|
137
142
|
}, Interaction, interaction._id, function(err, result) {
|
|
138
143
|
|
|
139
144
|
should.not.exist(err);
|
|
@@ -151,11 +156,15 @@ describe('Document', function() {
|
|
|
151
156
|
it('creates a document for a message', function(done) {
|
|
152
157
|
|
|
153
158
|
Document.createForModel({
|
|
159
|
+
customer: config.CUSTOMER_ID,
|
|
154
160
|
createdBy: documentCreator,
|
|
155
161
|
name: 'plain.txt',
|
|
156
162
|
contentType: 'text/plain',
|
|
157
163
|
contentLength: 124,
|
|
158
|
-
|
|
164
|
+
s3: {
|
|
165
|
+
bucket: 'totem',
|
|
166
|
+
key: 'docs'
|
|
167
|
+
}
|
|
159
168
|
}, Message, message._id, function(err, result) {
|
|
160
169
|
|
|
161
170
|
should.not.exist(err);
|
|
@@ -173,11 +182,15 @@ describe('Document', function() {
|
|
|
173
182
|
it('creates a document for an organization', function(done) {
|
|
174
183
|
|
|
175
184
|
Document.createForModel({
|
|
185
|
+
customer: config.CUSTOMER_ID,
|
|
176
186
|
createdBy: documentCreator,
|
|
177
187
|
name: 'test_file.jpg',
|
|
178
188
|
contentType: 'image/jpeg',
|
|
179
189
|
contentLength: 12345,
|
|
180
|
-
|
|
190
|
+
s3: {
|
|
191
|
+
bucket: 'totem',
|
|
192
|
+
key: 'docs'
|
|
193
|
+
}
|
|
181
194
|
}, Organization, org._id, function(err, result) {
|
|
182
195
|
|
|
183
196
|
should.not.exist(err);
|
|
@@ -197,11 +210,15 @@ describe('Document', function() {
|
|
|
197
210
|
it('creates a document for a person', function(done) {
|
|
198
211
|
|
|
199
212
|
Document.createForModel({
|
|
213
|
+
customer: config.CUSTOMER_ID,
|
|
200
214
|
createdBy: documentCreator,
|
|
201
215
|
name: 'test.pdf',
|
|
202
216
|
contentType: 'application/pdf',
|
|
203
217
|
contentLength: 54321,
|
|
204
|
-
|
|
218
|
+
s3: {
|
|
219
|
+
bucket: 'totem',
|
|
220
|
+
key: 'docs'
|
|
221
|
+
}
|
|
205
222
|
}, Person, person._id, function(err, result) {
|
|
206
223
|
|
|
207
224
|
should.not.exist(err);
|
package/test/Message.js
CHANGED
|
@@ -34,7 +34,8 @@ describe('Message', function() {
|
|
|
34
34
|
subject: 'Message one',
|
|
35
35
|
recipients: {
|
|
36
36
|
external: [externalAttendee1]
|
|
37
|
-
}
|
|
37
|
+
},
|
|
38
|
+
raw: { test: 'test' }
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
Message.upsert(message, function(err, result) {
|
|
@@ -53,7 +54,8 @@ describe('Message', function() {
|
|
|
53
54
|
subject: 'Message two',
|
|
54
55
|
recipients: {
|
|
55
56
|
external: [externalAttendee2]
|
|
56
|
-
}
|
|
57
|
+
},
|
|
58
|
+
raw: { test: 'test' }
|
|
57
59
|
});
|
|
58
60
|
|
|
59
61
|
Message.upsert(message, function(err, result) {
|
|
@@ -114,7 +116,8 @@ describe('Message', function() {
|
|
|
114
116
|
subject: 'test 3',
|
|
115
117
|
recipients: {
|
|
116
118
|
external: [new mongoose.Types.ObjectId()]
|
|
117
|
-
}
|
|
119
|
+
},
|
|
120
|
+
raw: { test: 'test' }
|
|
118
121
|
});
|
|
119
122
|
|
|
120
123
|
Message.upsert(message, function(err, result) {
|
package/test/Person.js
CHANGED
|
@@ -537,9 +537,6 @@ describe('Person', function() {
|
|
|
537
537
|
|
|
538
538
|
account.username = 'testy';
|
|
539
539
|
account.email = 'test@ffvc.com';
|
|
540
|
-
account.reset.token = '123456789';
|
|
541
|
-
account.setup.token = '987654321';
|
|
542
|
-
account.password = 'piratebooty';
|
|
543
540
|
account.person = person;
|
|
544
541
|
|
|
545
542
|
Account.upsert(account, function(err, updatedAccount) {
|