refactor: add redundant protection checks (#1822)
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
|||||||
MobileDeviceInterface,
|
MobileDeviceInterface,
|
||||||
MobileUnlockTiming,
|
MobileUnlockTiming,
|
||||||
InternalEventBus,
|
InternalEventBus,
|
||||||
|
DecryptedItem,
|
||||||
} from '@standardnotes/snjs'
|
} from '@standardnotes/snjs'
|
||||||
import { makeObservable, observable } from 'mobx'
|
import { makeObservable, observable } from 'mobx'
|
||||||
import { PanelResizedData } from '@/Types/PanelResizedData'
|
import { PanelResizedData } from '@/Types/PanelResizedData'
|
||||||
@@ -308,4 +309,12 @@ export class WebApplication extends SNApplication implements WebApplicationInter
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAuthorizedToRenderItem(item: DecryptedItem): boolean {
|
||||||
|
if (item.protected && this.hasProtectionSources()) {
|
||||||
|
return this.hasUnprotectedAccessSession()
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ const FilePreview = ({ file, application }: Props) => {
|
|||||||
void downloadFileForPreview()
|
void downloadFileForPreview()
|
||||||
}, [application.files, downloadedBytes, file, isFilePreviewable])
|
}, [application.files, downloadedBytes, file, isFilePreviewable])
|
||||||
|
|
||||||
|
if (!application.isAuthorizedToRenderItem(file)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return isDownloading ? (
|
return isDownloading ? (
|
||||||
<div className="flex flex-grow flex-col items-center justify-center">
|
<div className="flex flex-grow flex-col items-center justify-center">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ const FilePreviewModal: FunctionComponent<Props> = observer(({ application, view
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!application.isAuthorizedToRenderItem(currentFile)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const [showFileInfoPanel, setShowFileInfoPanel] = useState(false)
|
const [showFileInfoPanel, setShowFileInfoPanel] = useState(false)
|
||||||
const closeButtonRef = useRef<HTMLButtonElement>(null)
|
const closeButtonRef = useRef<HTMLButtonElement>(null)
|
||||||
|
|
||||||
|
|||||||
@@ -234,7 +234,9 @@ class NoteView extends PureComponent<NoteViewProps, State> {
|
|||||||
this.reloadEditorComponent().catch(console.error)
|
this.reloadEditorComponent().catch(console.error)
|
||||||
this.reloadStackComponents().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.setShowProtectedOverlay(showProtectedWarning)
|
||||||
|
|
||||||
this.reloadPreferences().catch(console.error)
|
this.reloadPreferences().catch(console.error)
|
||||||
@@ -935,7 +937,7 @@ class NoteView extends PureComponent<NoteViewProps, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override render() {
|
override render() {
|
||||||
if (this.state.showProtectedWarning) {
|
if (this.state.showProtectedWarning || !this.application.isAuthorizedToRenderItem(this.note)) {
|
||||||
return (
|
return (
|
||||||
<ProtectedItemOverlay
|
<ProtectedItemOverlay
|
||||||
viewControllerManager={this.viewControllerManager}
|
viewControllerManager={this.viewControllerManager}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { AppPaneId } from '../ResponsivePane/AppPaneMetadata'
|
|||||||
import { getNoteBlob, getNoteFileName } from '@/Utils/NoteExportUtils'
|
import { getNoteBlob, getNoteFileName } from '@/Utils/NoteExportUtils'
|
||||||
import { shareSelectedNotes } from '@/NativeMobileWeb/ShareSelectedNotes'
|
import { shareSelectedNotes } from '@/NativeMobileWeb/ShareSelectedNotes'
|
||||||
import { downloadSelectedNotesOnAndroid } from '@/NativeMobileWeb/DownloadSelectedNotesOnAndroid'
|
import { downloadSelectedNotesOnAndroid } from '@/NativeMobileWeb/DownloadSelectedNotesOnAndroid'
|
||||||
|
import ProtectedUnauthorizedLabel from '../ProtectedItemOverlay/ProtectedUnauthorizedLabel'
|
||||||
|
|
||||||
type DeletePermanentlyButtonProps = {
|
type DeletePermanentlyButtonProps = {
|
||||||
onClick: () => void
|
onClick: () => void
|
||||||
@@ -267,6 +268,11 @@ const NotesOptions = ({
|
|||||||
historyModalController.openModal(notesController.firstSelectedNote)
|
historyModalController.openModal(notesController.firstSelectedNote)
|
||||||
}, [historyModalController, notesController.firstSelectedNote])
|
}, [historyModalController, notesController.firstSelectedNote])
|
||||||
|
|
||||||
|
const unauthorized = notes.some((note) => !application.isAuthorizedToRenderItem(note))
|
||||||
|
if (unauthorized) {
|
||||||
|
return <ProtectedUnauthorizedLabel />
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{notes.length === 1 && (
|
{notes.length === 1 && (
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
const ProtectedUnauthorizedLabel = () => {
|
||||||
|
return <div className="text-center">This item is protected. Please authorize first.</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProtectedUnauthorizedLabel
|
||||||
@@ -37,6 +37,10 @@ const RevisionHistoryModal: FunctionComponent<RevisionHistoryModalProps> = ({
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!application.isAuthorizedToRenderItem(historyModalController.note)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HistoryModalDialog onDismiss={historyModalController.dismissModal}>
|
<HistoryModalDialog onDismiss={historyModalController.dismissModal}>
|
||||||
<HistoryModalDialogContent
|
<HistoryModalDialogContent
|
||||||
|
|||||||
Reference in New Issue
Block a user