Skip to content

Commit 816b9b8

Browse files
author
David Renshaw
committed
include organization members in powerbox contact picker
1 parent acc6b01 commit 816b9b8

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

shell/server/identity.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,31 +132,46 @@ globalFrontendRefRegistry.register({
132132
},
133133

134134
query(db, userId, value) {
135-
const result = [];
135+
const resultSet = {};
136136
let requestedPermissions = [];
137137
if (value) {
138138
requestedPermissions = Capnp.parse(Identity.PowerboxTag, value).permissions || [];
139139
}
140140

141+
const resultForIdentity = function (identity) {
142+
return {
143+
_id: "frontendref-identity-" + identity._id,
144+
frontendRef: { identity: identity._id },
145+
cardTemplate: "identityPowerboxCard",
146+
configureTemplate: "identityPowerboxConfiguration",
147+
profile: identity.profile,
148+
requestedPermissions,
149+
searchTerms: [
150+
identity.profile.name,
151+
identity.profile.handle,
152+
identity.profile.intrinsicName,
153+
],
154+
};
155+
};
156+
141157
db.collections.contacts.find({ ownerId: userId }).forEach(contact => {
142158
const identity = db.getIdentity(contact.identityId);
143159
if (identity) {
144-
result.push({
145-
_id: "frontendref-identity-" + contact.identityId,
146-
frontendRef: { identity: contact.identityId },
147-
cardTemplate: "identityPowerboxCard",
148-
configureTemplate: "identityPowerboxConfiguration",
149-
profile: identity.profile,
150-
requestedPermissions,
151-
searchTerms: [
152-
identity.profile.name,
153-
identity.profile.handle,
154-
identity.profile.intrinsicName,
155-
],
156-
});
160+
resultSet[contact.identityId] = resultForIdentity(identity);
157161
}
158162
});
159163

160-
return result;
164+
if (db.getOrganizationShareContacts() &&
165+
db.isUserInOrganization(db.collections.users.findOne({ _id: userId }))) {
166+
167+
// TODO(perf): Add some way to efficiently fetch all members in an organization.
168+
db.collections.users.find({ profile: { $exists: 1 } }).forEach((user) => {
169+
if (db.isIdentityInOrganization(user)) {
170+
resultSet[user._id] = resultForIdentity(db.getIdentity(user._id));
171+
}
172+
});
173+
}
174+
175+
return _.values(resultSet);
161176
},
162177
});

0 commit comments

Comments
 (0)