Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3490752
D6092.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D6092.diff
View Options
diff --git a/keyserver/src/endpoints.js b/keyserver/src/endpoints.js
--- a/keyserver/src/endpoints.js
+++ b/keyserver/src/endpoints.js
@@ -1,6 +1,6 @@
// @flow
-import { policyTypes } from 'lib/facts/policies.js';
+import { baseLegalPolicies } from 'lib/facts/policies.js';
import type { Endpoint } from 'lib/types/endpoints';
import {
@@ -60,8 +60,6 @@
import { codeVerificationResponder } from './responders/verification-responders';
import { uploadDeletionResponder } from './uploads/uploads';
-const baseLegalPolicies = [policyTypes.tosAndPrivacyPolicy];
-
const jsonEndpoints: { [id: Endpoint]: JSONResponder } = {
create_account: {
responder: accountCreationResponder,
diff --git a/keyserver/src/fetchers/policy-acknowledgment-fetchers.js b/keyserver/src/fetchers/policy-acknowledgment-fetchers.js
--- a/keyserver/src/fetchers/policy-acknowledgment-fetchers.js
+++ b/keyserver/src/fetchers/policy-acknowledgment-fetchers.js
@@ -4,16 +4,15 @@
import { type UserPolicyConfirmationType } from 'lib/types/policy-types.js';
import { dbQuery, SQL } from '../database/database.js';
-import { Viewer } from '../session/viewer.js';
async function fetchPolicyAcknowledgments(
- viewer: Viewer,
+ userID: string,
policies: $ReadOnlyArray<PolicyType>,
): Promise<$ReadOnlyArray<UserPolicyConfirmationType>> {
const query = SQL`
SELECT policy, confirmed
FROM policy_acknowledgments
- WHERE user=${viewer.id}
+ WHERE user=${userID}
AND policy IN (${policies})
`;
const [data] = await dbQuery(query);
@@ -21,11 +20,11 @@
}
async function fetchNotAcknowledgedPolicies(
- viewer: Viewer,
+ userID: string,
policies: $ReadOnlyArray<PolicyType>,
): Promise<$ReadOnlyArray<PolicyType>> {
const viewerAcknowledgments = await fetchPolicyAcknowledgments(
- viewer,
+ userID,
policies,
);
return policies.filter(policy => {
diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js
--- a/keyserver/src/responders/user-responders.js
+++ b/keyserver/src/responders/user-responders.js
@@ -5,7 +5,7 @@
import t from 'tcomb';
import bcrypt from 'twin-bcrypt';
-import { policies } from 'lib/facts/policies.js';
+import { baseLegalPolicies, policies } from 'lib/facts/policies.js';
import { hasMinCodeVersion } from 'lib/shared/version-utils';
import type {
ResetPasswordRequest,
@@ -62,6 +62,7 @@
import { checkAndInvalidateSIWENonceEntry } from '../deleters/siwe-nonce-deleters.js';
import { fetchEntryInfos } from '../fetchers/entry-fetchers';
import { fetchMessageInfos } from '../fetchers/message-fetchers';
+import { fetchNotAcknowledgedPolicies } from '../fetchers/policy-acknowledgment-fetchers.js';
import { fetchThreadInfos } from '../fetchers/thread-fetchers';
import {
fetchKnownUserInfos,
@@ -215,16 +216,38 @@
const deviceToken = request.deviceTokenUpdateRequest
? request.deviceTokenUpdateRequest.deviceToken
: viewer.deviceToken;
- const [userViewerData] = await Promise.all([
+ const [userViewerData, notAcknowledgedPolicies] = await Promise.all([
createNewUserCookie(userID, {
platformDetails: request.platformDetails,
deviceToken,
primaryIdentityPublicKey,
socialProof,
}),
+ fetchNotAcknowledgedPolicies(userID, baseLegalPolicies),
deleteCookie(viewer.cookieID),
]);
viewer.setNewCookie(userViewerData);
+
+ if (
+ notAcknowledgedPolicies.length &&
+ hasMinCodeVersion(viewer.platformDetails, 1000)
+ ) {
+ const currentUserInfo = await fetchLoggedInUserInfo(viewer);
+ return {
+ notAcknowledgedPolicies,
+ currentUserInfo: currentUserInfo,
+ rawMessageInfos: [],
+ truncationStatuses: {},
+ userInfos: [],
+ rawEntryInfos: [],
+ serverTime: 0,
+ cookieChange: {
+ threadInfos: {},
+ userInfos: [],
+ },
+ };
+ }
+
if (calendarQuery) {
await setNewSession(viewer, calendarQuery, newServerTime);
}
@@ -262,7 +285,10 @@
},
};
if (rawEntryInfos) {
- response.rawEntryInfos = rawEntryInfos;
+ return {
+ ...response,
+ rawEntryInfos,
+ };
}
return response;
}
diff --git a/keyserver/src/utils/validation-utils.js b/keyserver/src/utils/validation-utils.js
--- a/keyserver/src/utils/validation-utils.js
+++ b/keyserver/src/utils/validation-utils.js
@@ -168,7 +168,7 @@
}
const notAcknowledgedPolicies = await fetchNotAcknowledgedPolicies(
- viewer,
+ viewer.id,
policies,
);
diff --git a/lib/actions/siwe-actions.js b/lib/actions/siwe-actions.js
--- a/lib/actions/siwe-actions.js
+++ b/lib/actions/siwe-actions.js
@@ -63,6 +63,7 @@
userInfos,
updatesCurrentAsOf: response.serverTime,
logInActionSource: logInActionSources.logInFromNativeSIWE,
+ notAcknowledgedPolicies: response.notAcknowledgedPolicies,
};
};
diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js
--- a/lib/actions/user-actions.js
+++ b/lib/actions/user-actions.js
@@ -147,6 +147,7 @@
userInfos,
updatesCurrentAsOf: response.serverTime,
logInActionSource: logInInfo.logInActionSource,
+ notAcknowledgedPolicies: response.notAcknowledgedPolicies,
};
};
diff --git a/lib/facts/policies.js b/lib/facts/policies.js
--- a/lib/facts/policies.js
+++ b/lib/facts/policies.js
@@ -9,3 +9,5 @@
export const policies: $ReadOnlyArray<string> = values(policyTypes);
export type PolicyType = $Values<typeof policyTypes>;
+
+export const baseLegalPolicies = [policyTypes.tosAndPrivacyPolicy];
diff --git a/lib/reducers/policies-reducer.js b/lib/reducers/policies-reducer.js
--- a/lib/reducers/policies-reducer.js
+++ b/lib/reducers/policies-reducer.js
@@ -1,6 +1,10 @@
// @flow
-import { policyAcknowledgmentActionTypes } from '../actions/user-actions.js';
+import { siweAuthActionTypes } from '../actions/siwe-actions.js';
+import {
+ logInActionTypes,
+ policyAcknowledgmentActionTypes,
+} from '../actions/user-actions.js';
import type { PolicyType } from '../facts/policies.js';
import {
type UserPolicies,
@@ -12,8 +16,15 @@
state: UserPolicies,
action: BaseAction,
): UserPolicies {
- if (action.type === forcePolicyAcknowledgmentActionType) {
+ if (
+ action.type === forcePolicyAcknowledgmentActionType ||
+ action.type === logInActionTypes.success ||
+ action.type === siweAuthActionTypes.success
+ ) {
const { notAcknowledgedPolicies } = action.payload;
+ if (!notAcknowledgedPolicies) {
+ return state;
+ }
const newState = { ...state };
notAcknowledgedPolicies.forEach((policy: PolicyType) => {
diff --git a/lib/types/account-types.js b/lib/types/account-types.js
--- a/lib/types/account-types.js
+++ b/lib/types/account-types.js
@@ -120,16 +120,17 @@
};
export type LogInResponse = {
- currentUserInfo: LoggedInUserInfo | OldLoggedInUserInfo,
- rawMessageInfos: $ReadOnlyArray<RawMessageInfo>,
- truncationStatuses: MessageTruncationStatuses,
- userInfos: $ReadOnlyArray<UserInfo>,
- rawEntryInfos?: ?$ReadOnlyArray<RawEntryInfo>,
- serverTime: number,
- cookieChange: {
- threadInfos: { +[id: string]: RawThreadInfo },
- userInfos: $ReadOnlyArray<UserInfo>,
+ +currentUserInfo: LoggedInUserInfo | OldLoggedInUserInfo,
+ +rawMessageInfos: $ReadOnlyArray<RawMessageInfo>,
+ +truncationStatuses: MessageTruncationStatuses,
+ +userInfos: $ReadOnlyArray<UserInfo>,
+ +rawEntryInfos?: ?$ReadOnlyArray<RawEntryInfo>,
+ +serverTime: number,
+ +cookieChange: {
+ +threadInfos: { +[id: string]: RawThreadInfo },
+ +userInfos: $ReadOnlyArray<UserInfo>,
},
+ +notAcknowledgedPolicies?: $ReadOnlyArray<PolicyType>,
};
export type LogInResult = {
@@ -140,6 +141,7 @@
+calendarResult: CalendarResult,
+updatesCurrentAsOf: number,
+logInActionSource: LogInActionSource,
+ +notAcknowledgedPolicies?: $ReadOnlyArray<PolicyType>,
};
export type UpdatePasswordRequest = {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 5:28 PM (21 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678135
Default Alt Text
D6092.diff (7 KB)
Attached To
Mode
D6092: [lib] validate policies after user login
Attached
Detach File
Event Timeline
Log In to Comment