Privs progress

This commit is contained in:
Mo Bitar
2018-11-21 14:27:04 -06:00
parent c5d50728c0
commit 90793938f7
9 changed files with 67 additions and 43 deletions

View File

@@ -243,36 +243,49 @@ class AccountMenu {
}) })
} }
$scope.importFileSelected = function(files) { $scope.importFileSelected = async function(files) {
$scope.importData = {};
var file = files[0]; let run = () => {
var reader = new FileReader(); $timeout(() => {
reader.onload = function(e) { $scope.importData = {};
try {
var data = JSON.parse(e.target.result);
$timeout(function(){
if(data.auth_params) {
// request password
$scope.importData.requestPassword = true;
$scope.importData.data = data;
$timeout(() => { var file = files[0];
var element = document.getElementById("import-password-request"); var reader = new FileReader();
if(element) { reader.onload = function(e) {
element.scrollIntoView(false); try {
var data = JSON.parse(e.target.result);
$timeout(function(){
if(data.auth_params) {
// request password
$scope.importData.requestPassword = true;
$scope.importData.data = data;
$timeout(() => {
var element = document.getElementById("import-password-request");
if(element) {
element.scrollIntoView(false);
}
})
} else {
$scope.performImport(data, null);
} }
}) })
} else { } catch (e) {
$scope.performImport(data, null); alert("Unable to open file. Ensure it is a proper JSON file and try again.");
} }
}) }
} catch (e) {
alert("Unable to open file. Ensure it is a proper JSON file and try again."); reader.readAsText(file);
} })
} }
reader.readAsText(file); if(await privilegesManager.actionRequiresPrivilege(PrivilegesManager.ActionManageBackups)) {
privilegesManager.presentPrivilegesModal(PrivilegesManager.ActionManageBackups, () => {
run();
});
} else {
run();
}
} }
$scope.importJSONData = function(data, password, callback) { $scope.importJSONData = function(data, password, callback) {
@@ -335,8 +348,8 @@ class AccountMenu {
archiveManager.downloadBackup($scope.archiveFormData.encrypted); archiveManager.downloadBackup($scope.archiveFormData.encrypted);
} }
if(await privilegesManager.actionRequiresPrivilege(PrivilegesManager.ActionDownloadBackup)) { if(await privilegesManager.actionRequiresPrivilege(PrivilegesManager.ActionManageBackups)) {
privilegesManager.presentPrivilegesModal(PrivilegesManager.ActionDownloadBackup, () => { privilegesManager.presentPrivilegesModal(PrivilegesManager.ActionManageBackups, () => {
run(); run();
}); });
} else { } else {

View File

@@ -39,7 +39,7 @@ class PrivilegesAuthModal {
privilegesManager.netCredentialsForAction($scope.action).then((credentials) => { privilegesManager.netCredentialsForAction($scope.action).then((credentials) => {
$timeout(() => { $timeout(() => {
$scope.requiredCredentials = credentials; $scope.requiredCredentials = credentials.sort();
}); });
}); });

View File

@@ -14,13 +14,22 @@ class PrivilegesManagementModal {
} }
} }
controller($scope, privilegesManager, $timeout) { controller($scope, privilegesManager, passcodeManager, $timeout) {
'ngInject'; 'ngInject';
$scope.dummy = {}; $scope.dummy = {};
$scope.hasPasscode = passcodeManager.hasPasscode();
$scope.displayInfoForCredential = function(credential) { $scope.displayInfoForCredential = function(credential) {
return privilegesManager.displayInfoForCredential(credential).label; let info = privilegesManager.displayInfoForCredential(credential);
if(credential == PrivilegesManager.CredentialLocalPasscode) {
info["availability"] = $scope.hasPasscode;
} else {
info["availability"] = true;
}
return info;
} }
$scope.displayInfoForAction = function(action) { $scope.displayInfoForAction = function(action) {
@@ -47,6 +56,11 @@ class PrivilegesManagementModal {
$scope.sessionExpirey = sessionEndDate.toLocaleString(); $scope.sessionExpirey = sessionEndDate.toLocaleString();
$scope.sessionExpired = new Date() >= sessionEndDate; $scope.sessionExpired = new Date() >= sessionEndDate;
$scope.credentialDisplayInfo = {};
for(let cred of $scope.availableCredentials) {
$scope.credentialDisplayInfo[cred] = $scope.displayInfoForCredential(cred);
}
privilegesManager.getPrivileges().then((privs) => { privilegesManager.getPrivileges().then((privs) => {
$timeout(() => { $timeout(() => {
$scope.privileges = privs; $scope.privileges = privs;
@@ -55,6 +69,7 @@ class PrivilegesManagementModal {
} }
$scope.checkboxValueChanged = function(action, credential) { $scope.checkboxValueChanged = function(action, credential) {
console.log("toggleCredentialForAction", action, credential);
$scope.privileges.toggleCredentialForAction(action, credential); $scope.privileges.toggleCredentialForAction(action, credential);
privilegesManager.savePrivileges(); privilegesManager.savePrivileges();
} }

View File

@@ -13,7 +13,6 @@ class PasscodeManager {
const MillisecondsPerSecond = 1000; const MillisecondsPerSecond = 1000;
PasscodeManager.AutoLockIntervalNone = 0; PasscodeManager.AutoLockIntervalNone = 0;
PasscodeManager.AutoLockIntervalFiveSecs = 5 * MillisecondsPerSecond;
PasscodeManager.AutoLockIntervalOneMinute = 60 * MillisecondsPerSecond; PasscodeManager.AutoLockIntervalOneMinute = 60 * MillisecondsPerSecond;
PasscodeManager.AutoLockIntervalFiveMinutes = 300 * MillisecondsPerSecond; PasscodeManager.AutoLockIntervalFiveMinutes = 300 * MillisecondsPerSecond;
PasscodeManager.AutoLockIntervalOneHour = 3600 * MillisecondsPerSecond; PasscodeManager.AutoLockIntervalOneHour = 3600 * MillisecondsPerSecond;
@@ -27,10 +26,6 @@ class PasscodeManager {
value: PasscodeManager.AutoLockIntervalNone, value: PasscodeManager.AutoLockIntervalNone,
label: "None" label: "None"
}, },
{
value: PasscodeManager.AutoLockIntervalFiveSecs,
label: "5 Secs"
},
{ {
value: PasscodeManager.AutoLockIntervalOneMinute, value: PasscodeManager.AutoLockIntervalOneMinute,
label: "1 Min" label: "1 Min"

View File

@@ -15,7 +15,7 @@ class PrivilegesManager {
PrivilegesManager.CredentialLocalPasscode = "CredentialLocalPasscode"; PrivilegesManager.CredentialLocalPasscode = "CredentialLocalPasscode";
PrivilegesManager.ActionManageExtensions = "ActionManageExtensions"; PrivilegesManager.ActionManageExtensions = "ActionManageExtensions";
PrivilegesManager.ActionDownloadBackup = "ActionDownloadBackup"; PrivilegesManager.ActionManageBackups = "ActionManageBackups";
PrivilegesManager.ActionViewLockedNotes = "ActionViewLockedNotes"; PrivilegesManager.ActionViewLockedNotes = "ActionViewLockedNotes";
PrivilegesManager.ActionManagePrivileges = "ActionManagePrivileges"; PrivilegesManager.ActionManagePrivileges = "ActionManagePrivileges";
PrivilegesManager.ActionManagePasscode = "ActionManagePasscode"; PrivilegesManager.ActionManagePasscode = "ActionManagePasscode";
@@ -31,10 +31,10 @@ class PrivilegesManager {
this.availableActions = [ this.availableActions = [
PrivilegesManager.ActionManageExtensions, PrivilegesManager.ActionManageExtensions,
PrivilegesManager.ActionDownloadBackup, PrivilegesManager.ActionManageBackups,
PrivilegesManager.ActionViewLockedNotes,
PrivilegesManager.ActionManagePrivileges, PrivilegesManager.ActionManagePrivileges,
PrivilegesManager.ActionManagePasscode, PrivilegesManager.ActionManagePasscode,
PrivilegesManager.ActionViewLockedNotes,
PrivilegesManager.ActionDeleteNote PrivilegesManager.ActionDeleteNote
] ]
@@ -164,8 +164,8 @@ class PrivilegesManager {
label: "Manage Extensions" label: "Manage Extensions"
}; };
metadata[PrivilegesManager.ActionDownloadBackup] = { metadata[PrivilegesManager.ActionManageBackups] = {
label: "Download Backups" label: "Download/Import Backups"
}; };
metadata[PrivilegesManager.ActionViewLockedNotes] = { metadata[PrivilegesManager.ActionViewLockedNotes] = {
@@ -181,7 +181,7 @@ class PrivilegesManager {
} }
metadata[PrivilegesManager.ActionDeleteNote] = { metadata[PrivilegesManager.ActionDeleteNote] = {
label: "Delete Note" label: "Delete Notes"
} }
return metadata[action]; return metadata[action];

View File

@@ -17,6 +17,7 @@
th { th {
text-align: left; text-align: left;
font-weight: normal;
} }
} }

View File

@@ -133,7 +133,6 @@
.panel-row .panel-row
.horizontal-group .horizontal-group
%h4 Autolock %h4 Autolock
.vertical-rule
%a.info{"ng-repeat" => "option in passcodeAutoLockOptions", "ng-click" => "selectAutoLockInterval(option.value)", %a.info{"ng-repeat" => "option in passcodeAutoLockOptions", "ng-click" => "selectAutoLockInterval(option.value)",
"ng-class" => "{'info boxed' : option.value == selectedAutoLockInterval}"} "ng-class" => "{'info boxed' : option.value == selectedAutoLockInterval}"}
{{option.label}} {{option.label}}

View File

@@ -7,12 +7,12 @@
%h1.title Authentication Required %h1.title Authentication Required
%a.close-button.info{"ng-click" => "cancel()"} Cancel %a.close-button.info{"ng-click" => "cancel()"} Cancel
.content .content
.panel-section %form.panel-section{"ng-submit" => "submit()"}
%div{"ng-repeat" => "credential in requiredCredentials"} %div{"ng-repeat" => "credential in requiredCredentials"}
%p %p
%strong {{promptForCredential(credential)}} %strong {{promptForCredential(credential)}}
%div %div
%input{"type" => "password", "ng-model" => "authenticationParameters[credential]"} %input{"type" => "password", "ng-model" => "authenticationParameters[credential]", "sn-autofocus" => "true", "should-focus" => "$index == 0"}
%div %div
%label.danger{"ng-if" => "isCredentialInFailureState(credential)"} Invalid authentication. Please try again. %label.danger{"ng-if" => "isCredentialInFailureState(credential)"} Invalid authentication. Please try again.
.panel-row .panel-row

View File

@@ -13,7 +13,8 @@
%tr %tr
%th %th
%th{"ng-repeat" => "cred in availableCredentials"} %th{"ng-repeat" => "cred in availableCredentials"}
{{displayInfoForCredential(cred)}} %strong {{credentialDisplayInfo[cred].label}}
%p.font-small{"style" => "margin-top: 2px", "ng-show" => "!credentialDisplayInfo[cred].availability"} Not Configured
%tbody %tbody
%tr{"ng-repeat" => "action in availableActions"} %tr{"ng-repeat" => "action in availableActions"}
%td %td