Skip to content

Commit 532ee6e

Browse files
committed
Send a notification warning affected users that identities are changing.
See explanation here: sandstorm-io/sandstorm-website#289 We send a bell notification to all users who have multiple identities where the display names of those identities are not all the same. We also show a warning on the accounts page for these users. We specifically look for users with varying names on the assumption that if all the names are the same, then the user really only has one identity anyway, and the coming changes will be a strict improvement for them. I didn't feel it was necessary to compare profile pictures, handles, or preferred pronouns because if the display name is the same, it seems unlikely that the profiles vary significantly in these other factors.
1 parent ae2ae54 commit 532ee6e

File tree

8 files changed

+111
-0
lines changed

8 files changed

+111
-0
lines changed

shell/client/accounts/account-settings.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ <h1>Account</h1>
2828

2929
<h3 class="title-bar">Linked identities</h3>
3030

31+
{{#if affectedByIdentityRefactor}}
32+
<p class="alert-identity-refactor">We're changing the way identities work. Your account may be affected.
33+
<a href="https://sandstorm.io/news/2017-05-08-refactoring-identities">Learn more &raquo;</a></p>
34+
{{/if}}
35+
3136
{{#with actionCompleted}}
3237
{{#if success}}
3338
{{#focusingSuccessBox}}

shell/client/accounts/account-settings.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@ Template.sandstormAccountSettings.helpers({
184184
showDeleteButton: function () {
185185
return !Template.instance().data._db.isUserInOrganization(Meteor.user());
186186
},
187+
188+
affectedByIdentityRefactor: function () {
189+
let previousName = null;
190+
let needsNotification = false;
191+
192+
SandstormDb.getUserIdentityIds(Meteor.user())
193+
.map((id) => Meteor.users.findOne({ _id: id }))
194+
.filter((identity) => !!identity)
195+
.forEach((identity) => {
196+
const name = identity.profile && identity.profile.name;
197+
if (!name || (previousName && previousName !== name)) {
198+
needsNotification = true;
199+
}
200+
previousName = name;
201+
});
202+
203+
return needsNotification;
204+
},
187205
});
188206

189207
GENDERS = { male: "male", female: "female", neutral: "neutral", robot: "robot" };

shell/client/notifications-client.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ Template.notificationItem.helpers({
162162
const data = Template.currentData();
163163
return !!data.ongoing;
164164
},
165+
166+
isIdentityChanges() {
167+
const data = Template.currentData();
168+
return !!data.identityChanges;
169+
},
165170
});
166171

167172
Template.appUpdateNotificationItem.helpers({
@@ -249,6 +254,12 @@ Template.referralNotificationItem.events({
249254
},
250255
});
251256

257+
Template.identityChangesNotificationItem.events({
258+
"click .notification-item"(evt) {
259+
Meteor.call("dismissNotification", this._id);
260+
},
261+
});
262+
252263
Template.adminNotificationItem.helpers({
253264
isType(type) {
254265
return this.admin.type === type;

shell/client/notifications.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@
116116
{{/linkTo}}
117117
</template>
118118

119+
<template name="identityChangesNotificationItem">
120+
<a href="https://sandstorm.io/news/2017-05-08-refactoring-identities" class="notification-item"
121+
target="_blank">
122+
<div class="notification-icon">
123+
<img src="/sandstorm-gradient-logo.svg">
124+
</div>
125+
126+
We're changing the way identities work in Sandstorm. Your account may be affected. Click here
127+
to learn more.
128+
129+
<div class="notification-footer">
130+
<span title="{{timestamp}}" class="notification-timestamp">{{dateString timestamp}}</span>
131+
</div>
132+
</a>
133+
</template>
134+
119135
<template name="grainActivityNotificationItem">
120136
<a class="notification-item" href="{{notificationUrl}}">
121137
<div class="notification-icon">
@@ -157,11 +173,15 @@
157173
{{else}}
158174
{{#if isOngoing }}
159175
{{> backgroundedGrainNotificationItem . }}
176+
{{else}}
177+
{{#if isIdentityChanges }}
178+
{{> identityChangesNotificationItem . }}
160179
{{else}}
161180
{{> grainActivityNotificationItem . }}
162181
{{/if}}
163182
{{/if}}
164183
{{/if}}
165184
{{/if}}
166185
{{/if}}
186+
{{/if}}
167187
</template>

shell/client/styles/_account.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,11 @@ body>.main-content>.account {
492492
padding: 5px;
493493
}
494494

495+
p.alert-identity-refactor {
496+
color: red;
497+
padding-left: 5px;
498+
}
499+
495500
.identities-and-editor {
496501
@media #{$not-mobile-only} {
497502
width: 660px;

shell/imports/server/migrations.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,48 @@ function setIpBlacklist(db, backend) {
787787
}
788788
}
789789

790+
function notifyIdentityChanges(db, backend) {
791+
// Notify users who might be affected by the identity model changes.
792+
//
793+
// Two types of users are affected:
794+
// - Users who have multiple identities with differing names.
795+
// - Users who have identities that are shared with other users.
796+
//
797+
// However, the second group seems like it must be a subset of the first group. So we only check
798+
// for the first.
799+
800+
const names = {};
801+
Meteor.users.find({ "profile.name": { $exists: true } }, { fields: { "profile.name": 1 } })
802+
.forEach(user => {
803+
names[user._id] = user.profile.name;
804+
});
805+
806+
Meteor.users.find({ loginIdentities: { $exists: true } },
807+
{ fields: { loginIdentities: 1, nonloginIdentities: 1 } }).forEach(user => {
808+
let previousName = null;
809+
let needsNotification = false;
810+
SandstormDb.getUserIdentityIds( user).forEach(identityId => {
811+
const name = names[identityId];
812+
if (!name || (previousName && previousName !== name)) {
813+
needsNotification = true;
814+
}
815+
previousName = name;
816+
});
817+
818+
if (needsNotification) {
819+
db.collections.notifications.upsert({
820+
userId: user._id,
821+
identityChanges: true,
822+
}, {
823+
userId: user._id,
824+
identityChanges: true,
825+
timestamp: new Date(),
826+
isUnread: true,
827+
});
828+
}
829+
});
830+
}
831+
790832
// This must come after all the functions named within are defined.
791833
// Only append to this list! Do not modify or remove list entries;
792834
// doing so is likely change the meaning and semantics of user databases.
@@ -824,6 +866,7 @@ const MIGRATIONS = [
824866
addMembraneRequirementsToIdentities,
825867
addEncryptionToFrontendRefIpNetwork,
826868
setIpBlacklist,
869+
notifyIdentityChanges,
827870
];
828871

829872
const NEW_SERVER_STARTUP = [

shell/packages/sandstorm-db/db.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ Notifications = new Mongo.Collection("notifications", collectionOptions);
637637
// mailingListBonus: Like `referral`, but notify the user about the mailing list bonus. This is
638638
// a one-time notification only to Oasis users who existed when the bonus program
639639
// was implemented.
640+
// identityChanges: If this boolean field is true, this notification should show a warning about
641+
// upcoming changes to the identity model.
640642

641643
ActivitySubscriptions = new Mongo.Collection("activitySubscriptions", collectionOptions);
642644
// Activity events to which a user is subscribed.

shell/server/notifications-server.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ Meteor.methods({
240240
isUnread: true,
241241
});
242242

243+
Notifications.insert({
244+
userId: this.userId,
245+
identityChanges: true,
246+
timestamp: new Date(),
247+
isUnread: true,
248+
});
249+
243250
if (global.BlackrockPayments) {
244251
Notifications.insert({
245252
userId: this.userId,

0 commit comments

Comments
 (0)