Skip to content

Commit c2dceaf

Browse files
committed
Step 15.8: Re-add fake users and whitelist them in the publication
1 parent 794c94c commit c2dceaf

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

api/server/main.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,86 @@
11
import { Meteor } from 'meteor/meteor';
2+
import { Picture } from './models';
23
import { Accounts } from 'meteor/accounts-base';
4+
import { Users } from './collections/users';
35

46
Meteor.startup(() => {
57
if (Meteor.settings) {
68
Object.assign(Accounts._options, Meteor.settings['accounts-phone']);
79
SMS.twilio = Meteor.settings['twilio'];
810
}
11+
12+
if (Users.collection.find().count() > 0) {
13+
return;
14+
}
15+
16+
let picture = importPictureFromUrl({
17+
name: 'man1.jpg',
18+
url: 'https://randomuser.me/api/portraits/men/1.jpg'
19+
});
20+
21+
Accounts.createUserWithPhone({
22+
phone: '+972540000001',
23+
profile: {
24+
name: 'Ethan Gonzalez',
25+
pictureId: picture._id
26+
}
27+
});
28+
29+
picture = importPictureFromUrl({
30+
name: 'lego1.jpg',
31+
url: 'https://randomuser.me/api/portraits/lego/1.jpg'
32+
});
33+
34+
Accounts.createUserWithPhone({
35+
phone: '+972540000002',
36+
profile: {
37+
name: 'Bryan Wallace',
38+
pictureId: picture._id
39+
}
40+
});
41+
42+
picture = importPictureFromUrl({
43+
name: 'woman1.jpg',
44+
url: 'https://randomuser.me/api/portraits/women/1.jpg'
45+
});
46+
47+
Accounts.createUserWithPhone({
48+
phone: '+972540000003',
49+
profile: {
50+
name: 'Avery Stewart',
51+
pictureId: picture._id
52+
}
53+
});
54+
55+
picture = importPictureFromUrl({
56+
name: 'woman2.jpg',
57+
url: 'https://randomuser.me/api/portraits/women/2.jpg'
58+
});
59+
60+
Accounts.createUserWithPhone({
61+
phone: '+972540000004',
62+
profile: {
63+
name: 'Katie Peterson',
64+
pictureId: picture._id
65+
}
66+
});
67+
68+
picture = importPictureFromUrl({
69+
name: 'man2.jpg',
70+
url: 'https://randomuser.me/api/portraits/men/2.jpg'
71+
});
72+
73+
Accounts.createUserWithPhone({
74+
phone: '+972540000005',
75+
profile: {
76+
name: 'Ray Edwards',
77+
pictureId: picture._id
78+
}
79+
});
980
});
81+
82+
function importPictureFromUrl(options: { name: string, url: string }): Picture {
83+
const description = { name: options.name };
84+
85+
return Meteor.call('ufsImportURL', options.url, description, 'pictures');
86+
}

api/server/publications.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ Meteor.publishComposite('users', function(
1717
if (pattern) {
1818
selector = {
1919
'profile.name': { $regex: pattern, $options: 'i' },
20-
'phone.number': {$in: contacts}
20+
$or: [
21+
{'phone.number': {$in: contacts}},
22+
{'profile.name': {$in: ['Ethan Gonzalez', 'Bryan Wallace', 'Avery Stewart', 'Katie Peterson', 'Ray Edwards']}}
23+
]
2124
};
2225
} else {
23-
selector = {'phone.number': {$in: contacts}}
26+
selector = {
27+
$or: [
28+
{'phone.number': {$in: contacts}},
29+
{'profile.name': {$in: ['Ethan Gonzalez', 'Bryan Wallace', 'Avery Stewart', 'Katie Peterson', 'Ray Edwards']}}
30+
]
31+
}
2432
}
2533

2634
return {

0 commit comments

Comments
 (0)