Skip to content

Commit 2711917

Browse files
author
Dushyant Bhalgami
authored
chenges to add universal member to groups (#53)
* chenges to add universal member to groups * chenges to add universal member to groups * updated to add/remove universal member to groups
1 parent 0d0ecdd commit 2711917

File tree

6 files changed

+257
-63
lines changed

6 files changed

+257
-63
lines changed

config/default.js

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ module.exports = {
3737
KAFKA_GROUP_DELETE_TOPIC: process.env.KAFKA_GROUP_DELETE_TOPIC || 'groups.notification.delete',
3838
KAFKA_GROUP_MEMBER_ADD_TOPIC: process.env.KAFKA_GROUP_MEMBER_ADD_TOPIC || 'groups.notification.member.add',
3939
KAFKA_GROUP_MEMBER_DELETE_TOPIC: process.env.KAFKA_GROUP_MEMBER_DELETE_TOPIC || 'groups.notification.member.delete',
40+
KAFKA_GROUP_UNIVERSAL_MEMBER_ADD_TOPIC: process.env.KAFKA_GROUP_UNIVERSAL_MEMBER_ADD_TOPIC || 'groups.notification.universalmember.add',
41+
KAFKA_GROUP_UNIVERSAL_MEMBER_DELETE_TOPIC: process.env.KAFKA_GROUP_UNIVERSAL_MEMBER_DELETE_TOPIC || 'groups.notification.universalmember.delete',
4042

4143
USER_ROLES: {
4244
Admin: 'Administrator',

src/common/helper.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -74,36 +74,36 @@ async function ensureExists(tx, model, id, isAdmin = false) {
7474
if (model === 'Group') {
7575
if (validate(id, 4)) {
7676
if (!isAdmin) {
77-
res = await tx.run(`MATCH (e:${model} {id: {id}, status: '${constants.GroupStatus.Active}'}) RETURN e`, {
78-
id
79-
})
77+
res = await tx.run(`MATCH (e:${model} {id: {id}, status: '${constants.GroupStatus.Active}'}) RETURN e`, {id})
8078
} else {
81-
res = await tx.run(`MATCH (e:${model} {id: {id}}) RETURN e`, {
82-
id
83-
})
79+
res = await tx.run(`MATCH (e:${model} {id: {id}}) RETURN e`, {id})
8480
}
8581
} else {
8682
if (!isAdmin) {
8783
res = await tx.run(`MATCH (e:${model} {oldId: {id}, status: '${constants.GroupStatus.Active}'}) RETURN e`, {
8884
id
8985
})
9086
} else {
91-
res = await tx.run(`MATCH (e:${model} {oldId: {id}}) RETURN e`, {
92-
id
93-
})
87+
res = await tx.run(`MATCH (e:${model} {oldId: {id}}) RETURN e`, {id})
9488
}
9589
}
9690

9791
if (res && res.records.length === 0) {
9892
throw new errors.NotFoundError(`Not found ${model} of id ${id}`)
9993
}
10094
} else if (model === 'User') {
101-
res = await tx.run(`MATCH (e:${model} {id: {id}}) RETURN e`, {
102-
id
103-
})
95+
if (validate(id, 4)) {
96+
res = await tx.run(`MATCH (e:${model} {universalUID: {id}}) RETURN e`, {id})
10497

105-
if (res && res.records.length === 0) {
106-
res = await tx.run(`CREATE (user:User {id: {id}}) RETURN user`, { id })
98+
if (res && res.records.length === 0) {
99+
res = await tx.run(`CREATE (user:User {id: '00000000', universalUID: {id}}) RETURN user`, {id})
100+
}
101+
} else {
102+
res = await tx.run(`MATCH (e:${model} {id: {id}}) RETURN e`, {id})
103+
104+
if (res && res.records.length === 0) {
105+
res = await tx.run(`CREATE (user:User {id: {id}, universalUID: '00000000'}) RETURN user`, {id})
106+
}
107107
}
108108
}
109109

@@ -123,7 +123,7 @@ async function ensureGroupMember(session, groupId, userId) {
123123
try {
124124
const memberCheckRes = await session.run(
125125
'MATCH (g:Group {id: {groupId}})-[r:GroupContains {type: {membershipType}}]->(u:User {id: {userId}}) RETURN r',
126-
{ groupId, membershipType: config.MEMBERSHIP_TYPES.User, userId }
126+
{groupId, membershipType: config.MEMBERSHIP_TYPES.User, userId}
127127
)
128128
if (memberCheckRes.records.length === 0) {
129129
throw new errors.ForbiddenError(`User is not member of the group`)
@@ -143,7 +143,7 @@ async function getChildGroups(session, groupId) {
143143
try {
144144
const res = await session.run(
145145
'MATCH (g:Group {id: {groupId}})-[r:GroupContains]->(c:Group) RETURN c ORDER BY c.oldId',
146-
{ groupId }
146+
{groupId}
147147
)
148148
return _.map(res.records, (record) => record.get(0).properties)
149149
} catch (error) {
@@ -161,7 +161,7 @@ async function getParentGroups(session, groupId) {
161161
try {
162162
const res = await session.run(
163163
'MATCH (g:Group)-[r:GroupContains]->(c:Group {id: {groupId}}) RETURN g ORDER BY g.oldId',
164-
{ groupId }
164+
{groupId}
165165
)
166166
return _.map(res.records, (record) => record.get(0).properties)
167167
} catch (error) {
@@ -176,7 +176,7 @@ async function getParentGroups(session, groupId) {
176176
* @returns {String} link for the page
177177
*/
178178
function getPageLink(req, page) {
179-
const q = _.assignIn({}, req.query, { page })
179+
const q = _.assignIn({}, req.query, {page})
180180
return `${req.protocol}://${req.get('Host')}${req.baseUrl}${req.path}?${querystring.stringify(q)}`
181181
}
182182

src/controllers/GroupMembershipController.js

+29-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ async function deleteGroupMember(req, res) {
5656
const result = await service.deleteGroupMember(
5757
req.authUser.isMachine ? 'M2M' : req.authUser,
5858
req.params.groupId,
59-
req.params.memberId
59+
req.params.memberId ? req.params.memberId : null,
60+
Object.keys(req.query).length !== 0 ? req.query : null
6061
)
6162
res.send(result)
6263
}
@@ -71,13 +72,36 @@ async function getGroupMembersCount(req, res) {
7172
res.send(result)
7273
}
7374

75+
/**
76+
* Get list of mapping of groups and members count
77+
* @param req the request
78+
* @param res the response
79+
*/
80+
async function listGroupsMemberCount(req, res) {
81+
const result = await service.listGroupsMemberCount(req.query)
82+
res.send(result)
83+
}
84+
7485
/**
7586
* Get group members
7687
* @param req the request
7788
* @param res the response
7889
*/
7990
async function getMemberGroups(req, res) {
80-
const result = await service.getMemberGroups(req.authUser.isMachine ? 'M2M' : req.authUser, req.params.memberId)
91+
const result = await service.getMemberGroups(req.authUser.isMachine ? 'M2M' : req.authUser, req.params.memberId, {})
92+
helper.setResHeaders(req, res, result)
93+
res.send(result)
94+
}
95+
96+
/**
97+
* Get group members
98+
* @param req the request
99+
* @param res the response
100+
*/
101+
async function searchMemberGroups(req, res) {
102+
console.log('sssss')
103+
console.log(JSON.stringify(req.query))
104+
const result = await service.getMemberGroups(req.authUser.isMachine ? 'M2M' : req.authUser, {}, req.query)
81105
helper.setResHeaders(req, res, result)
82106
res.send(result)
83107
}
@@ -88,5 +112,7 @@ module.exports = {
88112
getGroupMember,
89113
deleteGroupMember,
90114
getGroupMembersCount,
91-
getMemberGroups
115+
listGroupsMemberCount,
116+
getMemberGroups,
117+
searchMemberGroups
92118
}

src/routes.js

+22
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ module.exports = {
7373
auth: 'jwt',
7474
access: [constants.UserRoles.Admin, constants.UserRoles.User],
7575
scopes: ['write:groups', 'all:groups']
76+
},
77+
delete: {
78+
controller: 'GroupMembershipController',
79+
method: 'deleteGroupMember',
80+
auth: 'jwt',
81+
access: [constants.UserRoles.Admin],
82+
scopes: ['write:groups', 'all:groups']
7683
}
7784
},
7885
'/groups/:groupId/members/:memberId': {
@@ -97,6 +104,12 @@ module.exports = {
97104
method: 'getGroupMembersCount'
98105
}
99106
},
107+
'/groupsMemberCount': {
108+
get: {
109+
controller: 'GroupMembershipController',
110+
method: 'listGroupsMemberCount'
111+
}
112+
},
100113
'/groups/memberGroups/:memberId': {
101114
get: {
102115
controller: 'GroupMembershipController',
@@ -106,6 +119,15 @@ module.exports = {
106119
scopes: ['read:groups']
107120
}
108121
},
122+
'/groups/memberGroups/': {
123+
get: {
124+
controller: 'GroupMembershipController',
125+
method: 'searchMemberGroups',
126+
auth: 'jwt',
127+
access: [constants.UserRoles.Admin, constants.UserRoles.User],
128+
scopes: ['read:groups']
129+
}
130+
},
109131
'/health': {
110132
get: {
111133
controller: 'HealthController',

0 commit comments

Comments
 (0)