Page MenuHomePhabricator

D5875.diff
No OneTemporary

D5875.diff

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
@@ -4,7 +4,7 @@
import t from 'tcomb';
import bcrypt from 'twin-bcrypt';
-import { policies } from 'lib/facts/policies.js';
+import { policies, policyTypes } from 'lib/facts/policies.js';
import { hasMinCodeVersion } from 'lib/shared/version-utils';
import type {
ResetPasswordRequest,
@@ -66,7 +66,7 @@
} from '../updaters/account-updaters';
import { userSubscriptionUpdater } from '../updaters/user-subscription-updaters';
import { viewerAcknowledgmentUpdater } from '../updaters/viewer-acknowledgment-updater.js';
-import { validateInput } from '../utils/validation-utils';
+import { policiesValidator, validateInput } from '../utils/validation-utils';
import {
entryQueryInputValidator,
newEntryQueryInputValidator,
@@ -290,6 +290,15 @@
if (rawEntryInfos) {
response.rawEntryInfos = rawEntryInfos;
}
+
+ try {
+ await policiesValidator(viewer, [policyTypes.tosAndPrivacyPolicy]);
+ } catch (error) {
+ if (error.message === 'policies_not_accepted') {
+ response.notAcknowledgedPolicies = error.payload.notAcknowledgedPolicies;
+ }
+ }
+
return response;
}
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/hooks/log-in-call.js b/lib/hooks/log-in-call.js
new file mode 100644
--- /dev/null
+++ b/lib/hooks/log-in-call.js
@@ -0,0 +1,35 @@
+// @flow
+
+import * as React from 'react';
+import { useDispatch } from 'react-redux';
+
+import { logIn } from '../actions/user-actions.js';
+import type { LogInInfo, LogInResult } from '../types/account-types.js';
+import { forcePolicyAcknowledgmentActionType } from '../types/policy-types.js';
+import { useServerCall } from '../utils/action-utils.js';
+
+function useLogInServerCall(): (logInInfo: LogInInfo) => Promise<LogInResult> {
+ const dispatch = useDispatch();
+ const callLogIn = useServerCall(logIn);
+
+ return React.useCallback(
+ async (logInInfo: LogInInfo) => {
+ const result = await callLogIn(logInInfo);
+ if (
+ result.notAcknowledgedPolicies &&
+ result.notAcknowledgedPolicies.length
+ ) {
+ dispatch({
+ type: forcePolicyAcknowledgmentActionType,
+ payload: {
+ notAcknowledgedPolicies: result.notAcknowledgedPolicies,
+ },
+ });
+ }
+ return result;
+ },
+ [callLogIn, dispatch],
+ );
+}
+
+export { useLogInServerCall };
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
@@ -129,6 +129,7 @@
threadInfos: { +[id: string]: RawThreadInfo },
userInfos: $ReadOnlyArray<UserInfo>,
},
+ notAcknowledgedPolicies?: $ReadOnlyArray<PolicyType>,
};
export type LogInResult = {
@@ -139,6 +140,7 @@
+calendarResult: CalendarResult,
+updatesCurrentAsOf: number,
+logInActionSource: LogInActionSource,
+ +notAcknowledgedPolicies?: $ReadOnlyArray<PolicyType>,
};
export type UpdatePasswordRequest = {
diff --git a/native/account/log-in-panel.react.js b/native/account/log-in-panel.react.js
--- a/native/account/log-in-panel.react.js
+++ b/native/account/log-in-panel.react.js
@@ -5,7 +5,8 @@
import { View, StyleSheet, Alert, Keyboard, Platform } from 'react-native';
import Animated from 'react-native-reanimated';
-import { logInActionTypes, logIn } from 'lib/actions/user-actions';
+import { logInActionTypes } from 'lib/actions/user-actions';
+import { useLogInServerCall } from 'lib/hooks/log-in-call';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors';
import {
validEmailRegex,
@@ -20,7 +21,6 @@
} from 'lib/types/account-types';
import type { LoadingStatus } from 'lib/types/loading-types';
import {
- useServerCall,
useDispatchActionPromise,
type DispatchActionPromise,
} from 'lib/utils/action-utils';
@@ -366,7 +366,7 @@
);
const dispatchActionPromise = useDispatchActionPromise();
- const callLogIn = useServerCall(logIn);
+ const callLogIn = useLogInServerCall();
return (
<LogInPanel
diff --git a/web/account/log-in-form.react.js b/web/account/log-in-form.react.js
--- a/web/account/log-in-form.react.js
+++ b/web/account/log-in-form.react.js
@@ -3,8 +3,9 @@
import invariant from 'invariant';
import * as React from 'react';
-import { logInActionTypes, logIn } from 'lib/actions/user-actions';
+import { logInActionTypes } from 'lib/actions/user-actions';
import { useModalContext } from 'lib/components/modal-provider.react';
+import { useLogInServerCall } from 'lib/hooks/log-in-call.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors';
import {
oldValidUsernameRegex,
@@ -15,10 +16,7 @@
type LogInStartingPayload,
logInActionSources,
} from 'lib/types/account-types';
-import {
- useDispatchActionPromise,
- useServerCall,
-} from 'lib/utils/action-utils';
+import { useDispatchActionPromise } from 'lib/utils/action-utils';
import Button from '../components/button.react';
import LoadingIndicator from '../loading-indicator.react';
@@ -32,7 +30,7 @@
function LoginForm(): React.Node {
const inputDisabled = useSelector(loadingStatusSelector) === 'loading';
const loginExtraInfo = useSelector(webLogInExtraInfoSelector);
- const callLogIn = useServerCall(logIn);
+ const callLogIn = useLogInServerCall();
const dispatchActionPromise = useDispatchActionPromise();
const modalContext = useModalContext();

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 15, 10:52 PM (20 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2495719
Default Alt Text
D5875.diff (5 KB)

Event Timeline