refactor: add redundant protection checks (#1822)

This commit is contained in:
Mo
2022-10-18 10:15:14 -05:00
committed by GitHub
parent eec7ae1589
commit 07ffc01ede
7 changed files with 36 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ import {
MobileDeviceInterface,
MobileUnlockTiming,
InternalEventBus,
DecryptedItem,
} from '@standardnotes/snjs'
import { makeObservable, observable } from 'mobx'
import { PanelResizedData } from '@/Types/PanelResizedData'
@@ -308,4 +309,12 @@ export class WebApplication extends SNApplication implements WebApplicationInter
}
return
}
isAuthorizedToRenderItem(item: DecryptedItem): boolean {
if (item.protected && this.hasProtectionSources()) {
return this.hasUnprotectedAccessSession()
}
return true
}
}

View File

@@ -57,6 +57,10 @@ const FilePreview = ({ file, application }: Props) => {
void downloadFileForPreview()
}, [application.files, downloadedBytes, file, isFilePreviewable])
if (!application.isAuthorizedToRenderItem(file)) {
return null
}
return isDownloading ? (
<div className="flex flex-grow flex-col items-center justify-center">
<div className="flex items-center">

View File

@@ -22,6 +22,10 @@ const FilePreviewModal: FunctionComponent<Props> = observer(({ application, view
return null
}
if (!application.isAuthorizedToRenderItem(currentFile)) {
return null
}
const [showFileInfoPanel, setShowFileInfoPanel] = useState(false)
const closeButtonRef = useRef<HTMLButtonElement>(null)

View File

@@ -234,7 +234,9 @@ class NoteView extends PureComponent<NoteViewProps, State> {
this.reloadEditorComponent().catch(console.error)
this.reloadStackComponents().catch(console.error)
const showProtectedWarning = this.note.protected && !this.application.hasProtectionSources()
const showProtectedWarning =
this.note.protected &&
(!this.application.hasProtectionSources() || !this.application.hasUnprotectedAccessSession())
this.setShowProtectedOverlay(showProtectedWarning)
this.reloadPreferences().catch(console.error)
@@ -935,7 +937,7 @@ class NoteView extends PureComponent<NoteViewProps, State> {
}
override render() {
if (this.state.showProtectedWarning) {
if (this.state.showProtectedWarning || !this.application.isAuthorizedToRenderItem(this.note)) {
return (
<ProtectedItemOverlay
viewControllerManager={this.viewControllerManager}

View File

@@ -18,6 +18,7 @@ import { AppPaneId } from '../ResponsivePane/AppPaneMetadata'
import { getNoteBlob, getNoteFileName } from '@/Utils/NoteExportUtils'
import { shareSelectedNotes } from '@/NativeMobileWeb/ShareSelectedNotes'
import { downloadSelectedNotesOnAndroid } from '@/NativeMobileWeb/DownloadSelectedNotesOnAndroid'
import ProtectedUnauthorizedLabel from '../ProtectedItemOverlay/ProtectedUnauthorizedLabel'
type DeletePermanentlyButtonProps = {
onClick: () => void
@@ -267,6 +268,11 @@ const NotesOptions = ({
historyModalController.openModal(notesController.firstSelectedNote)
}, [historyModalController, notesController.firstSelectedNote])
const unauthorized = notes.some((note) => !application.isAuthorizedToRenderItem(note))
if (unauthorized) {
return <ProtectedUnauthorizedLabel />
}
return (
<>
{notes.length === 1 && (

View File

@@ -0,0 +1,5 @@
const ProtectedUnauthorizedLabel = () => {
return <div className="text-center">This item is protected. Please authorize first.</div>
}
export default ProtectedUnauthorizedLabel

View File

@@ -37,6 +37,10 @@ const RevisionHistoryModal: FunctionComponent<RevisionHistoryModalProps> = ({
return null
}
if (!application.isAuthorizedToRenderItem(historyModalController.note)) {
return null
}
return (
<HistoryModalDialog onDismiss={historyModalController.dismissModal}>
<HistoryModalDialogContent