refactor: add redundant protection checks (#1822)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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 && (
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
if (!application.isAuthorizedToRenderItem(historyModalController.note)) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<HistoryModalDialog onDismiss={historyModalController.dismissModal}>
|
||||
<HistoryModalDialogContent
|
||||
|
||||
Reference in New Issue
Block a user