3 var restSerializer
= require('../../../serializers/rest-serializer');
4 var githubGitterUserSearch
= require('../../../services/github-gitter-user-search');
5 var gitterUserSearch
= require('../../../services/user-search-service');
6 var StatusError
= require('statuserror');
7 var mongoUtils
= require('gitter-web-persistence-utils/lib/mongo-utils');
8 var userRemovalService
= require('gitter-web-rooms/lib/user-removal-service');
12 index: function(req
) {
14 throw new StatusError(403);
18 var searchQuery
= req
.query
.q
;
20 var searchType
= req
.query
.type
;
23 limit
: parseInt(req
.query
.limit
, 10) || 10,
24 skip
: parseInt(req
.query
.skip
, 10),
25 excludeTroupeId
: req
.query
.excludeTroupeId
28 return (searchType
=== 'gitter'
29 ? gitterUserSearch
.globalUserSearch(searchQuery
, options
)
30 : githubGitterUserSearch(searchQuery
, user
, options
)
31 ).then(function(searchResults
) {
32 var strategy
= new restSerializer
.SearchResultsStrategy({
33 resultItemStrategy
: new restSerializer
.UserStrategy()
36 return restSerializer
.serializeObject(searchResults
.results
, strategy
);
40 var strategy
= new restSerializer
.UserStrategy({ includeProviders
: true });
41 return restSerializer
.serialize([req
.user
], strategy
);
45 var strategy
= new restSerializer
.UserStrategy({ includeProviders
: true });
46 return restSerializer
.serializeObject(req
.resourceUser
, strategy
);
49 destroy
: async
function(req
) {
50 if (!req
.user
) throw new StatusError(401);
53 if (typeof req
.body
.ghost
=== 'boolean') {
54 ghost
= req
.body
.ghost
;
57 await userRemovalService
.removeByUsername(req
.user
.username
, {
61 return { success
: true };
64 load: function(req
, id
) {
65 if (!req
.user
) throw new StatusError(401);
67 if (id
=== 'me') return req
.user
;
69 // TODO: can the currently logged in user view information about this other user?
70 // For the moment, you'll only be able to see your own information
71 if (!mongoUtils
.objectIDsEqual(req
.user
.id
, id
)) throw new StatusError(403);
77 rooms
: require('./troupes'),
78 orgs
: require('./orgs'),
79 repos
: require('./repos'),
80 groups
: require('./groups'),
81 settings
: require('./user-settings'),
82 suggestedRooms
: require('./suggested-rooms'),
83 unreadItems
: require('./aggregated-unread-items')