Skip to content

Commit 41d0fca

Browse files
updated usersettings
1 parent f9dd22c commit 41d0fca

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

server/helper/seed-helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module.exports = {
7878
}
7979
return 'https://source.unsplash.com/daily?' + unsplashTopicsTmp.pop() + ',' + unsplashTopicsTmp.pop();
8080
},
81-
randomCategories: (seederstore, allowEmpty = true) => {
81+
randomCategories: (seederstore, allowEmpty = false) => {
8282
let count = Math.round(Math.random() * 3);
8383
if (allowEmpty === false && count === 0) {
8484
count = 1;

server/models/usersettings.model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function (app) {
88
const usersettings = new mongooseClient.Schema({
99
userId: {type: String, required: true, unique: true},
1010
uiLanguage: {type: String, required: true, default: 'de'},
11-
contributionLanguages: {type: Array, default: ['de']},
11+
contentLanguages: {type: Array, default: ['de']},
1212
updatedAt: { type: Date, default: Date.now }
1313
});
1414

server/seeder/development/usersettings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = (seederstore) => {
1515
return userKeys.pop();
1616
},
1717
uiLanguage: 'de',
18-
contributionLanguages: ['German']
18+
contentLanguages: ['de']
1919
}
2020
}]
2121
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = (belongs = true) => hook => {
2+
const itemBelongsToAuthenticatedUser = Boolean(hook.params.user && hook.result && hook.params.user._id.toString() === hook.result._id.toString());
3+
return itemBelongsToAuthenticatedUser === belongs;
4+
};

server/services/users/users.hooks.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const createSlug = require('../../hooks/create-slug');
1010
const thumbnails = require('../../hooks/thumbnails');
1111
const inviteCode = require('./hooks/invite-code')();
1212
const search = require('feathers-mongodb-fuzzy-search');
13+
const isOwnEntry = require('./hooks/is-own-entry');
1314

1415
const { hashPassword } = require('feathers-authentication-local').hooks;
1516

@@ -20,6 +21,7 @@ const cleanupPersonalData = when(isProvider('external'),
2021
discard('email', 'verifyToken', 'verifyShortToken', 'doiToken')
2122
);
2223

24+
2325
const restrict = [
2426
authenticate('jwt'),
2527
restrictToOwner({
@@ -48,6 +50,16 @@ const candosSchema = {
4850
}
4951
};
5052

53+
const userSettingsSchema = {
54+
include: {
55+
service: 'usersettings',
56+
nameAs: 'usersettings',
57+
parentField: '_id',
58+
childField: 'userId',
59+
asArray: false
60+
}
61+
};
62+
5163
const saveRemoteImages = require('../../hooks/save-remote-images');
5264

5365
const thumbnailOptions = {
@@ -105,7 +117,7 @@ module.exports = {
105117
],
106118
patch: [
107119
...restrict,
108-
hashPassword(),
120+
// hashPassword(),
109121
disableMultiItemChange(),
110122
// Only set slug once
111123
when(
@@ -137,17 +149,13 @@ module.exports = {
137149

138150
// remove personal data if its not the current authenticated user
139151
iff(isProvider('external'),
140-
when(hook => {
141-
const itemBelongsToAuthenticatedUser = hook.params.user && hook.result && hook.params.user._id.toString() === hook.result._id.toString();
142-
// console.log('hook.params', hook.params);
143-
// console.log('currentId', hook.params.user ? hook.params.user._id : null);
144-
// console.log('foundId', hook.result ? hook.result._id : null);
145-
// console.log('identical', (hook.params.user && hook.result ) ? hook.params.user._id.toString() === hook.result._id.toString() : null);
146-
return itemBelongsToAuthenticatedUser !== true;
147-
// return (!hook.params.user || !hook.result.data || hook.params.user._id !== hook.result.data._id);
148-
}, discard('email', 'verifyToken', 'verifyShortToken', 'doiToken'))
152+
when(isOwnEntry(false), [
153+
cleanupPersonalData
154+
])
155+
),
156+
iff(isOwnEntry(),
157+
populate({ schema: userSettingsSchema })
149158
)
150-
151159
],
152160
create: [
153161
when(isProvider('external'),

0 commit comments

Comments
 (0)