Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit fcf5353

Browse files
Merge pull request #88 from Human-Connection/invite-dialogue
Invite dialogue
2 parents 2b763c9 + 2259e13 commit fcf5353

17 files changed

+374
-22
lines changed

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
22
"name": "human-connection-api",
33
"description": "Human-Connection API",
4-
"version": "0.1.0",
4+
"version": "0.5.0",
55
"homepage": "https://human-connection.org",
66
"license": "MIT",
77
"repository": {
88
"type": "git",
99
"url": "https://github.com/Human-Connection/API.git"
1010
},
11-
"main": "server",
12-
"keywords": [
13-
"human-connection",
14-
"social network",
15-
"api",
16-
"feathersjs"
17-
],
1811
"author": {
1912
"name": "Human Connection gGmbH",
2013
"email": "[email protected]"
2114
},
22-
"contributors": [],
2315
"bugs": {
2416
"url": "https://github.com/Human-Connection/API/issues",
2517
"email": "[email protected]"
2618
},
19+
"main": "server",
20+
"keywords": [
21+
"human-connection",
22+
"social network",
23+
"api",
24+
"feathersjs"
25+
],
26+
"contributors": [],
2727
"directories": {
2828
"lib": "server",
2929
"test": "test/"
@@ -100,6 +100,7 @@
100100
"shortid": "~2.2.8",
101101
"slug": "~0.9.1",
102102
"trunc-html": "^1.1.2",
103+
"uuid": "^3.3.2",
103104
"valid-url": "^1.0.9",
104105
"winston": "~3.0.0-rc5"
105106
},

server/app.hooks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ module.exports = {
88
find: [],
99
get: [],
1010
create: [
11-
discard('_id')
11+
discard('_id', '__v')
1212
],
1313
update: [
14-
discard('_id')
14+
discard('_id', '__v')
1515
],
1616
patch: [
17-
discard('_id')
17+
discard('_id', '__v')
1818
],
1919
remove: []
2020
},

server/channels.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module.exports = function (app) {
4747
// });
4848

4949
app.service('contributions').publish('patched', () => app.channel('authenticated'));
50+
app.service('settings').publish('patched', () => app.channel('anonymous', 'authenticated'));
5051

5152
app.service('categories').publish(() => app.channel('anonymous', 'authenticated'));
5253
app.service('comments').publish(() => app.channel('authenticated'));

server/hooks/save-remote-images.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const { isEmpty } = require('lodash');
88
const fs = require('fs');
99
const path = require('path');
1010
const request = require('request');
11-
const faker = require('faker');
1211
const mime = require('mime/lite');
1312
const validUrl = require('valid-url');
13+
const uuid = require('uuid/v1');
1414

1515
function createUploadDirIfNeeded () {
1616
const uploadDir = path.resolve('public/uploads');
@@ -60,8 +60,7 @@ module.exports = function (options = []) { // eslint-disable-line no-unused-vars
6060
loading++;
6161
imgCount++;
6262
// TODO: fix that to use the data _id or somethink similar
63-
let uuid = faker.fake('{{random.uuid}}');
64-
const imgName = `${field}_${uuid}`;
63+
const imgName = `${field}_${uuid()}`;
6564
let imgPath = path.resolve('public', 'uploads/' + imgName);
6665

6766
if (typeof hook.data[field] === 'object') {

server/models/invites.model.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// invites-model.js - A mongoose model
2-
//
2+
//
33
// See http://mongoosejs.com/docs/models.html
44
// for more of what you can do here.
55
module.exports = function (app) {
@@ -12,6 +12,7 @@ module.exports = function (app) {
1212
enum: ['admin', 'moderator', 'manager', 'editor', 'user'],
1313
default: 'user'
1414
},
15+
invitedByUserId: { type: String },
1516
language: { type: String },
1617
badgeIds: [],
1718
wasUsed: { type: Boolean },

server/models/settings.model.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// settings-model.js - A mongoose model
2+
//
3+
// See http://mongoosejs.com/docs/models.html
4+
// for more of what you can do here.
5+
module.exports = function (app) {
6+
const mongooseClient = app.get('mongooseClient');
7+
const { Schema } = mongooseClient;
8+
9+
const settings = new Schema({
10+
key: {type: String, default: 'system', index: true, unique: true},
11+
invites: {
12+
userCanInvite: { type: Boolean, required: true, default: false },
13+
maxInvitesByUser: { type: Number, required: true, default: 1 },
14+
onlyUserWithBadgesCanInvite: { type: Array, default: [] }
15+
},
16+
maintenance: false
17+
}, {
18+
timestamps: true
19+
});
20+
21+
return mongooseClient.model('settings', settings);
22+
};

server/services/admin/admin.class.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-unused-vars */
22

33
const { asyncForEach, genInviteCode } = require('../../helper/seed-helpers');
4-
const { keyBy, isEmpty, isString } = require('lodash');
4+
const { keyBy, isEmpty, isString, difference, merge } = require('lodash');
55

66
class Service {
77
constructor (options) {
@@ -147,9 +147,31 @@ class Service {
147147
}
148148
});
149149
if (!userWithEmail.total) {
150+
// create new user
150151
const res = await this.app.service('invites').create(query);
151152
output.push(res);
153+
} else if (userWithEmail.total === 1 && difference(query.badgeIds, userWithEmail.data[0].badgeIds).length) {
154+
// update badges of existing user
155+
156+
let user = await this.app.service('users').find({
157+
query: {
158+
email: invite.email,
159+
$select: '_id'
160+
}
161+
});
162+
if (!user.total === 1) {
163+
return;
164+
}
165+
user = user.data.pop();
166+
let res = await this.app.service('users').patch(user._id, {
167+
$set: {
168+
badgeIds: merge(query.badgeIds, userWithEmail.data[0].badgeIds)
169+
}
170+
});
171+
res.wasUpdated = true;
172+
output.push(res);
152173
}
174+
153175
} catch (err) {
154176
this.app.error(err);
155177
}

server/services/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const search = require('./search/search.service.js');
2121
const usersettings = require('./usersettings/usersettings.service.js');
2222
const pages = require('./pages/pages.service.js');
2323
const systemNotifications = require('./system-notifications/system-notifications.service.js');
24+
const settings = require('./settings/settings.service.js');
25+
const userInvites = require('./user-invites/user-invites.service.js');
2426

2527
module.exports = function () {
2628
const app = this; // eslint-disable-line no-unused-vars
@@ -47,4 +49,6 @@ module.exports = function () {
4749
app.configure(usersettings);
4850
app.configure(pages);
4951
app.configure(systemNotifications);
52+
app.configure(settings);
53+
app.configure(userInvites);
5054
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const isAdmin = require('../../hooks/is-admin');
2+
const mapCreateToUpsert = require('../../hooks/map-create-to-upsert');
3+
4+
module.exports = {
5+
before: {
6+
all: [],
7+
find: [],
8+
get: [],
9+
create: [
10+
isAdmin(),
11+
mapCreateToUpsert(context => {
12+
const { data } = context;
13+
return { key: data.key || 'system' };
14+
})
15+
],
16+
update: [
17+
isAdmin()
18+
],
19+
patch: [
20+
isAdmin()
21+
],
22+
remove: [
23+
isAdmin()
24+
]
25+
},
26+
27+
after: {
28+
all: [],
29+
find: [],
30+
get: [],
31+
create: [],
32+
update: [],
33+
patch: [],
34+
remove: []
35+
},
36+
37+
error: {
38+
all: [],
39+
find: [],
40+
get: [],
41+
create: [],
42+
update: [],
43+
patch: [],
44+
remove: []
45+
}
46+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Initializes the `settings` service on path `/settings`
2+
const createService = require('feathers-mongoose');
3+
const createModel = require('../../models/settings.model');
4+
const hooks = require('./settings.hooks');
5+
6+
module.exports = function (app) {
7+
const Model = createModel(app);
8+
9+
const options = {
10+
Model
11+
};
12+
13+
// Initialize our service with any options it requires
14+
app.use('/settings', createService(options));
15+
16+
// Get our initialized service so that we can register hooks
17+
const service = app.service('settings');
18+
19+
service.hooks(hooks);
20+
};

0 commit comments

Comments
 (0)