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.importData = {};
$scope.importFileSelected = async function(files) {
var file = files[0];
var reader = new FileReader();
reader.onload = function(e) {
try {
var data = JSON.parse(e.target.result);
$timeout(function(){
if(data.auth_params) {
// request password
$scope.importData.requestPassword = true;
$scope.importData.data = data;
let run = () => {
$timeout(() => {
$scope.importData = {};
$timeout(() => {
var element = document.getElementById("import-password-request");
if(element) {
element.scrollIntoView(false);
var file = files[0];
var reader = new FileReader();
reader.onload = function(e) {
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 {
$scope.performImport(data, null);
} catch (e) {
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) {
@@ -335,8 +348,8 @@ class AccountMenu {
archiveManager.downloadBackup($scope.archiveFormData.encrypted);
}
if(await privilegesManager.actionRequiresPrivilege(PrivilegesManager.ActionDownloadBackup)) {
privilegesManager.presentPrivilegesModal(PrivilegesManager.ActionDownloadBackup, () => {
if(await privilegesManager.actionRequiresPrivilege(PrivilegesManager.ActionManageBackups)) {
privilegesManager.presentPrivilegesModal(PrivilegesManager.ActionManageBackups, () => {
run();
});
} else {

View File

@@ -39,7 +39,7 @@ class PrivilegesAuthModal {
privilegesManager.netCredentialsForAction($scope.action).then((credentials) => {
$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';
$scope.dummy = {};
$scope.hasPasscode = passcodeManager.hasPasscode();
$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) {
@@ -47,6 +56,11 @@ class PrivilegesManagementModal {
$scope.sessionExpirey = sessionEndDate.toLocaleString();
$scope.sessionExpired = new Date() >= sessionEndDate;
$scope.credentialDisplayInfo = {};
for(let cred of $scope.availableCredentials) {
$scope.credentialDisplayInfo[cred] = $scope.displayInfoForCredential(cred);
}
privilegesManager.getPrivileges().then((privs) => {
$timeout(() => {
$scope.privileges = privs;
@@ -55,6 +69,7 @@ class PrivilegesManagementModal {
}
$scope.checkboxValueChanged = function(action, credential) {
console.log("toggleCredentialForAction", action, credential);
$scope.privileges.toggleCredentialForAction(action, credential);
privilegesManager.savePrivileges();
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -13,7 +13,8 @@
%tr
%th
%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
%tr{"ng-repeat" => "action in availableActions"}
%td