Skip to content

Commit

Permalink
refactor: remove privileges in favor of SNJS protections
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Jan 18, 2021
1 parent 75f02b4 commit 42a7cb4
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 434 deletions.
7 changes: 0 additions & 7 deletions app/assets/javascripts/app.ts
Expand Up @@ -44,8 +44,6 @@ import {
PanelResizer,
PasswordWizard,
PermissionsModal,
PrivilegesAuthModal,
PrivilegesManagementModal,
RevisionPreviewModal,
HistoryMenu,
SyncResolutionMenu,
Expand Down Expand Up @@ -140,11 +138,6 @@ const startApplication: StartApplication = async function startApplication(
.directive('panelResizer', () => new PanelResizer())
.directive('passwordWizard', () => new PasswordWizard())
.directive('permissionsModal', () => new PermissionsModal())
.directive('privilegesAuthModal', () => new PrivilegesAuthModal())
.directive(
'privilegesManagementModal',
() => new PrivilegesManagementModal()
)
.directive('revisionPreviewModal', () => new RevisionPreviewModal())
.directive('historyMenu', () => new HistoryMenu())
.directive('syncResolutionMenu', () => new SyncResolutionMenu())
Expand Down
2 changes: 0 additions & 2 deletions app/assets/javascripts/directives/views/index.ts
Expand Up @@ -8,8 +8,6 @@ export { MenuRow } from './menuRow';
export { PanelResizer } from './panelResizer';
export { PasswordWizard } from './passwordWizard';
export { PermissionsModal } from './permissionsModal';
export { PrivilegesAuthModal } from './privilegesAuthModal';
export { PrivilegesManagementModal } from './privilegesManagementModal';
export { RevisionPreviewModal } from './revisionPreviewModal';
export { HistoryMenu } from './historyMenu';
export { SyncResolutionMenu } from './syncResolutionMenu';
128 changes: 0 additions & 128 deletions app/assets/javascripts/directives/views/privilegesAuthModal.ts

This file was deleted.

118 changes: 0 additions & 118 deletions app/assets/javascripts/directives/views/privilegesManagementModal.ts

This file was deleted.

5 changes: 4 additions & 1 deletion app/assets/javascripts/directives/views/sessionsModal.tsx
Expand Up @@ -5,6 +5,7 @@ import {
RemoteSession,
SessionStrings,
UuidString,
isNullOrUndefined,
} from '@standardnotes/snjs';
import { autorun, IAutorunOptions, IReactionPublic } from 'mobx';
import { render, FunctionComponent } from 'preact';
Expand Down Expand Up @@ -78,7 +79,9 @@ function useSessions(
setSessions(sessionsDuringRevoke);

const response = await responsePromise;
if ('error' in response) {
if (isNullOrUndefined(response)) {
setSessions(sessionsBeforeRevoke);
} else if ('error' in response) {
if (response.error?.message) {
setErrorMessage(response.error?.message);
} else {
Expand Down
56 changes: 23 additions & 33 deletions app/assets/javascripts/services/archiveManager.ts
@@ -1,5 +1,10 @@
import { WebApplication } from '@/ui_models/application';
import { EncryptionIntent, ProtectedAction, SNItem, ContentType, SNNote, BackupFile } from '@standardnotes/snjs';
import {
EncryptionIntent,
ContentType,
SNNote,
BackupFile
} from '@standardnotes/snjs';

function zippableTxtName(name: string, suffix = ""): string {
const sanitizedName = name
Expand All @@ -22,41 +27,26 @@ export class ArchiveManager {
}

public async downloadBackup(encrypted: boolean) {
const run = async () => {
const intent = encrypted
? EncryptionIntent.FileEncrypted
: EncryptionIntent.FileDecrypted;
const intent = encrypted
? EncryptionIntent.FileEncrypted
: EncryptionIntent.FileDecrypted;

const data = await this.application.createBackupFile(intent);
if (!data) {
return;
}
const blobData = new Blob(
[JSON.stringify(data, null, 2)],
{ type: 'text/json' }
const data = await this.application.createBackupFile(intent);
if (!data) {
return;
}
const blobData = new Blob(
[JSON.stringify(data, null, 2)],
{ type: 'text/json' }
);
if (encrypted) {
this.downloadData(
blobData,
`Standard Notes Encrypted Backup and Import File - ${this.formattedDate()}.txt`
);
if (encrypted) {
this.downloadData(
blobData,
`Standard Notes Encrypted Backup and Import File - ${this.formattedDate()}.txt`
);
} else {
/** download as zipped plain text files */
this.downloadZippedDecryptedItems(data);
}
};

if (
await this.application.privilegesService!
.actionRequiresPrivilege(ProtectedAction.ManageBackups)
) {
this.application.presentPrivilegesModal(
ProtectedAction.ManageBackups,
() => {
run();
});
} else {
run();
/** download as zipped plain text files */
this.downloadZippedDecryptedItems(data);
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/ui_models/app_state.ts
Expand Up @@ -217,7 +217,7 @@ export class AppState {
}
}

async openEditor(noteUuid: string) {
async openEditor(noteUuid: string): Promise<void> {
if (this.getActiveEditor()?.note?.uuid === noteUuid) {
return;
}
Expand All @@ -226,7 +226,7 @@ export class AppState {
if (!note) {
console.warn('Tried accessing a non-existant note of UUID ' + noteUuid);
return;
};
}

if (await this.application.authorizeNoteAccess(note)) {
const activeEditor = this.getActiveEditor();
Expand Down
3 changes: 1 addition & 2 deletions app/assets/javascripts/views/editor/editor-view.pug
Expand Up @@ -80,8 +80,7 @@
)
menu-row(
action='self.selectedMenuItem(true); self.toggleProtectNote()'
desc=`'Protecting a note will require credentials to view
it (Manage Privileges via Account menu)'`,
desc=`'Protecting a note will require credentials to view it'`,
label="self.note.protected ? 'Unprotect' : 'Protect'"
)
menu-row(
Expand Down

0 comments on commit 42a7cb4

Please sign in to comment.