Revert "feat: handle unprotected session expiration (#747)"

This reverts commit 8db549f6f6.
This commit is contained in:
Karol Sójko
2021-12-15 15:26:31 +01:00
parent 0e4757d426
commit 2e168df929
26 changed files with 755 additions and 418 deletions

View File

@@ -8,7 +8,7 @@ import { Button } from '@/components/Button';
import { SyncQueueStrategy, dateToLocalizedString } from '@standardnotes/snjs';
import { STRING_GENERIC_SYNC_ERROR } from '@/strings';
import { useState } from '@node_modules/preact/hooks';
import { observer } from 'mobx-react-lite';
import { observer } from '@node_modules/mobx-react-lite';
import { WebApplication } from '@/ui_models/application';
import { FunctionComponent } from 'preact';

View File

@@ -4,12 +4,7 @@ import { useCallback, useState } from 'preact/hooks';
import { useEffect } from 'preact/hooks';
import { ApplicationEvent } from '@standardnotes/snjs';
import { isSameDay } from '@/utils';
import {
PreferencesGroup,
PreferencesSegment,
Title,
Text,
} from '@/preferences/components';
import { PreferencesGroup, PreferencesSegment, Title, Text } from '@/preferences/components';
import { Button } from '@/components/Button';
type Props = {
@@ -21,9 +16,7 @@ export const Protections: FunctionalComponent<Props> = ({ application }) => {
application.clearProtectionSession();
};
const [hasProtections, setHasProtections] = useState(() =>
application.hasProtectionSources()
);
const [hasProtections, setHasProtections] = useState(() => application.hasProtectionSources());
const getProtectionsDisabledUntil = useCallback((): string | null => {
const protectionExpiry = application.getProtectionSessionExpiryDate();
@@ -33,7 +26,7 @@ export const Protections: FunctionalComponent<Props> = ({ application }) => {
if (isSameDay(protectionExpiry, now)) {
f = new Intl.DateTimeFormat(undefined, {
hour: 'numeric',
minute: 'numeric',
minute: 'numeric'
});
} else {
f = new Intl.DateTimeFormat(undefined, {
@@ -41,7 +34,7 @@ export const Protections: FunctionalComponent<Props> = ({ application }) => {
day: 'numeric',
month: 'short',
hour: 'numeric',
minute: 'numeric',
minute: 'numeric'
});
}
@@ -50,23 +43,14 @@ export const Protections: FunctionalComponent<Props> = ({ application }) => {
return null;
}, [application]);
const [protectionsDisabledUntil, setProtectionsDisabledUntil] = useState(
getProtectionsDisabledUntil()
);
const [protectionsDisabledUntil, setProtectionsDisabledUntil] = useState(getProtectionsDisabledUntil());
useEffect(() => {
const removeUnprotectedSessionBeginObserver = application.addEventObserver(
const removeProtectionSessionExpiryDateChangedObserver = application.addEventObserver(
async () => {
setProtectionsDisabledUntil(getProtectionsDisabledUntil());
},
ApplicationEvent.UnprotectedSessionBegan
);
const removeUnprotectedSessionEndObserver = application.addEventObserver(
async () => {
setProtectionsDisabledUntil(getProtectionsDisabledUntil());
},
ApplicationEvent.UnprotectedSessionExpired
ApplicationEvent.ProtectionSessionExpiryDateChanged
);
const removeKeyStatusChangedObserver = application.addEventObserver(
@@ -77,8 +61,7 @@ export const Protections: FunctionalComponent<Props> = ({ application }) => {
);
return () => {
removeUnprotectedSessionBeginObserver();
removeUnprotectedSessionEndObserver();
removeProtectionSessionExpiryDateChangedObserver();
removeKeyStatusChangedObserver();
};
}, [application, getProtectionsDisabledUntil]);
@@ -91,28 +74,19 @@ export const Protections: FunctionalComponent<Props> = ({ application }) => {
<PreferencesGroup>
<PreferencesSegment>
<Title>Protections</Title>
{protectionsDisabledUntil ? (
<Text className="info">
Unprotected access expires at {protectionsDisabledUntil}.
</Text>
) : (
<Text className="info">Protections are enabled.</Text>
)}
{protectionsDisabledUntil
? <Text className="info">Protections are disabled until {protectionsDisabledUntil}.</Text>
: <Text className="info">Protections are enabled.</Text>
}
<Text className="mt-2">
Actions like viewing or searching protected notes, exporting decrypted
backups, or revoking an active session require additional
authentication such as entering your account password or application
passcode.
Actions like viewing protected notes, exporting decrypted backups,
or revoking an active session, require additional authentication
like entering your account password or application passcode.
</Text>
{protectionsDisabledUntil && (
<Button
className="mt-3"
type="primary"
label="End Unprotected Access"
onClick={enableProtections}
/>
)}
{protectionsDisabledUntil &&
<Button className="mt-3" type="primary" label="Enable Protections" onClick={enableProtections} />
}
</PreferencesSegment>
</PreferencesGroup>
</PreferencesGroup >
);
};

View File

@@ -5,8 +5,7 @@ import {
DisclosurePanel,
} from '@reach/disclosure';
import { FunctionComponent } from 'preact';
import { MouseEventHandler } from 'react';
import { useState, useRef, useEffect } from 'preact/hooks';
import { useState, useRef, useEffect, MouseEventHandler } from 'react';
const DisclosureIconButton: FunctionComponent<{
className?: string;