Skip to content

Commit d187aa3

Browse files
committed
realm state: Store emailAddressVisibility
1 parent 6494c50 commit d187aa3

File tree

8 files changed

+56
-6
lines changed

8 files changed

+56
-6
lines changed

src/__tests__/lib/exampleData.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { randString, randInt } from '../../utils/misc';
2121
import { makeUserId } from '../../api/idTypes';
2222
import type { InitialData } from '../../api/apiTypes';
2323
import { EventTypes, type UpdateMessageEvent } from '../../api/eventTypes';
24-
import { CreateWebPublicStreamPolicy } from '../../api/permissionsTypes';
24+
import { CreateWebPublicStreamPolicy, EmailAddressVisibility } from '../../api/permissionsTypes';
2525
import type {
2626
AccountSwitchAction,
2727
LoginSuccessAction,
@@ -785,7 +785,7 @@ export const action = Object.freeze({
785785
realm_digest_weekday: 2,
786786
realm_disallow_disposable_email_addresses: true,
787787
realm_edit_topic_policy: 3,
788-
realm_email_address_visibility: 3,
788+
realm_email_address_visibility: EmailAddressVisibility.Admins,
789789
realm_email_auth_enabled: true,
790790
realm_email_changes_disabled: true,
791791
realm_emails_restricted_to_domains: false,

src/api/initialDataTypes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
import type {
2020
CreatePublicOrPrivateStreamPolicyT,
2121
CreateWebPublicStreamPolicy,
22+
EmailAddressVisibility,
2223
} from './permissionsTypes';
2324

2425
/*
@@ -207,7 +208,7 @@ export type InitialDataRealm = $ReadOnly<{|
207208
// TODO(server-5.0): Added in feat. 75, replacing realm_allow_community_topic_editing
208209
realm_edit_topic_policy?: number,
209210

210-
realm_email_address_visibility: number,
211+
realm_email_address_visibility: EmailAddressVisibility,
211212
realm_email_auth_enabled: boolean,
212213
realm_email_changes_disabled: boolean,
213214
realm_emails_restricted_to_domains: boolean,

src/api/permissionsTypes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,14 @@ export enum CreateWebPublicStreamPolicy {
9595
Nobody = 6,
9696
OwnerOnly = 7,
9797
}
98+
99+
/**
100+
* The policy for who in the organization has access to users' actual email
101+
*/
102+
export enum EmailAddressVisibility {
103+
Everyone = 1,
104+
Members = 2,
105+
Admins = 3,
106+
Nobody = 4,
107+
Moderators = 5,
108+
}

src/realm/__tests__/realmReducer-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { RealmDataForUpdate } from '../../api/realmDataTypes';
1515
import {
1616
CreatePublicOrPrivateStreamPolicy,
1717
CreateWebPublicStreamPolicy,
18+
EmailAddressVisibility,
1819
} from '../../api/permissionsTypes';
1920
import { CustomProfileFieldType } from '../../api/modelTypes';
2021
import { EventTypes } from '../../api/eventTypes';
@@ -68,6 +69,7 @@ describe('realmReducer', () => {
6869
waitingPeriodThreshold: action.data.realm_waiting_period_threshold,
6970
allowEditHistory: action.data.realm_allow_edit_history,
7071
enableReadReceipts: action.data.realm_enable_read_receipts,
72+
emailAddressVisibility: action.data.realm_email_address_visibility,
7173

7274
//
7375
// InitialDataRealmUser
@@ -500,6 +502,31 @@ describe('realmReducer', () => {
500502
check(false, true);
501503
check(false, false);
502504
});
505+
506+
describe('emailAddressVisibility / email_address_visibility', () => {
507+
const { Everyone, Members, Admins, Nobody, Moderators } = EmailAddressVisibility;
508+
const check = mkCheck('emailAddressVisibility', 'email_address_visibility');
509+
check(Everyone, Members);
510+
check(Everyone, Admins);
511+
check(Everyone, Nobody);
512+
check(Everyone, Moderators);
513+
check(Members, Everyone);
514+
check(Members, Admins);
515+
check(Members, Nobody);
516+
check(Members, Moderators);
517+
check(Admins, Everyone);
518+
check(Admins, Members);
519+
check(Admins, Nobody);
520+
check(Admins, Moderators);
521+
check(Nobody, Everyone);
522+
check(Nobody, Admins);
523+
check(Nobody, Members);
524+
check(Nobody, Moderators);
525+
check(Moderators, Everyone);
526+
check(Moderators, Admins);
527+
check(Moderators, Members);
528+
check(Moderators, Nobody);
529+
});
503530
});
504531
});
505532
});

src/realm/realmReducer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
import {
99
CreatePublicOrPrivateStreamPolicy,
1010
CreateWebPublicStreamPolicy,
11+
EmailAddressVisibility,
1112
} from '../api/permissionsTypes';
1213
import { EventTypes } from '../api/eventTypes';
1314
import {
@@ -54,6 +55,7 @@ const initialState = {
5455
waitingPeriodThreshold: 90,
5556
allowEditHistory: false,
5657
enableReadReceipts: false,
58+
emailAddressVisibility: EmailAddressVisibility.Admins,
5759

5860
//
5961
// InitialDataRealmUser
@@ -162,6 +164,7 @@ export default (
162164
waitingPeriodThreshold: action.data.realm_waiting_period_threshold,
163165
allowEditHistory: action.data.realm_allow_edit_history,
164166
enableReadReceipts: action.data.realm_enable_read_receipts ?? false,
167+
emailAddressVisibility: action.data.realm_email_address_visibility,
165168

166169
//
167170
// InitialDataRealmUser
@@ -265,6 +268,9 @@ export default (
265268
if (data.enable_read_receipts !== undefined) {
266269
result.enableReadReceipts = data.enable_read_receipts;
267270
}
271+
if (data.email_address_visibility !== undefined) {
272+
result.emailAddressVisibility = data.email_address_visibility;
273+
}
268274

269275
return result;
270276
}

src/reduxTypes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import type { PmConversationsState } from './pm-conversations/pmConversationsMod
3838
import type { UnreadState } from './unread/unreadModelTypes';
3939
import type { UserStatusesState } from './user-statuses/userStatusesCore';
4040
import type { ServerEmojiData } from './api/modelTypes';
41+
import type { EmailAddressVisibility } from './api/permissionsTypes';
4142

4243
export type { MuteState } from './mute/muteModelTypes';
4344
export type { UserStatusesState } from './user-statuses/userStatusesCore';
@@ -307,6 +308,7 @@ export type RealmState = {|
307308
+waitingPeriodThreshold: number,
308309
+allowEditHistory: boolean,
309310
+enableReadReceipts: boolean,
311+
+emailAddressVisibility: EmailAddressVisibility,
310312

311313
//
312314
// InitialDataRealmUser

src/storage/__tests__/migrations-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('migrations', () => {
104104
// What `base` becomes after all migrations.
105105
const endBase = {
106106
...base52,
107-
migrations: { version: 53 },
107+
migrations: { version: 54 },
108108
};
109109

110110
for (const [desc, before, after] of [
@@ -127,8 +127,8 @@ describe('migrations', () => {
127127
// redundant with this one, because none of the migration steps notice
128128
// whether any properties outside `storeKeys` are present or not.
129129
[
130-
'check dropCache at 53',
131-
{ ...endBase, migrations: { version: 52 }, mute: [], nonsense: [1, 2, 3] },
130+
'check dropCache at 54',
131+
{ ...endBase, migrations: { version: 53 }, mute: [], nonsense: [1, 2, 3] },
132132
endBase,
133133
],
134134

src/storage/migrations.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ const migrationsInner: {| [string]: (LessPartialState) => LessPartialState |} =
463463
// Add enableReadReceipts to state.realm.
464464
'53': dropCache,
465465

466+
// Add emailAddressVisibility to state.realm
467+
'54': dropCache,
468+
466469
// TIP: When adding a migration, consider just using `dropCache`.
467470
// (See its jsdoc for guidance on when that's the right answer.)
468471
};

0 commit comments

Comments
 (0)