diff --git a/common/models/user.js b/common/models/user.js index 25f1779062..0ddb4cd027 100644 --- a/common/models/user.js +++ b/common/models/user.js @@ -93,7 +93,7 @@ module.exports = function(User) { debug('where', where); User.count( where, - function (err, count) { + function(err, count) { if (err) { debug('err checking existance: ', err); return cb(err); @@ -132,4 +132,52 @@ module.exports = function(User) { } } ); + + User.about = function about(username, cb) { + if (!username) { + // Zalgo!! + return process.nextTick(() => { + cb( + new TypeError('FCC: username should be a string but got %s', username) + ); + }); + } + User.findOne({ where: { username } }, (err, user) => { + if (err) { + cb(err); + } + if (!user || user.username !== username) { + cb(new Error('FCC: no user found for %s', username)); + } + const aboutUser = { + username: user.username, + bio: user.bio, + github: user.githubProfile + }; + cb(null, aboutUser); + }); + }; + + User.remoteMethod( + 'about', + { + description: 'get public info about user', + accepts: [ + { + arg: 'username', + type: 'string' + } + ], + returns: [ + { + arg: 'about', + type: 'object' + } + ], + http: { + path: '/about', + verb: 'get' + } + } + ); }; diff --git a/common/models/user.json b/common/models/user.json index b49b9cd085..c52ebaa3d4 100644 --- a/common/models/user.json +++ b/common/models/user.json @@ -126,10 +126,6 @@ "resetPasswordToken": { "type": "string" }, - "sentSlackInvite": { - "type": "boolean", - "default": false - }, "resetPasswordExpires": { "type": "string" }, @@ -249,6 +245,13 @@ "principalId": "$everyone", "permission": "ALLOW", "property": "doesExist" + }, + { + "accessType": "EXECUTE", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW", + "property": "about" } ], "methods": []