diff --git a/src/karma.conf.js b/src/karma.conf.js index 97e91a70..6e192d1e 100644 --- a/src/karma.conf.js +++ b/src/karma.conf.js @@ -75,6 +75,7 @@ module.exports = function (config) { __dirname + '/wwwroot/filters/numberFormat.js', __dirname + '/wwwroot/services/auth.js', __dirname + '/wwwroot/services/clerk.js', + __dirname + '/wwwroot/services/featureGating.js', __dirname + '/wwwroot/services/linkUtilities.js', __dirname + '/wwwroot/services/reports.js', __dirname + '/wwwroot/services/templates.js', diff --git a/src/wwwroot/controllers/MyProfileCtrl.js b/src/wwwroot/controllers/MyProfileCtrl.js index 274101f0..b9e96efe 100644 --- a/src/wwwroot/controllers/MyProfileCtrl.js +++ b/src/wwwroot/controllers/MyProfileCtrl.js @@ -14,10 +14,11 @@ '$timeout', 'settings', 'clerk', - 'RELAY_CONFIG' + 'RELAY_CONFIG', + 'featureGating' ]; - function MyProfileCtrl($scope, $location, $rootScope, auth, $translate, $timeout, settings, clerk, RELAY_CONFIG, $http) { + function MyProfileCtrl($scope, $location, $rootScope, auth, $translate, $timeout, settings, clerk, RELAY_CONFIG, featureGating, $http) { var vm = this; $rootScope.setSubmenues([ { text: 'submenu_my_profile', url: 'settings/my-profile', active: true }, @@ -44,6 +45,15 @@ vm.emailResendSuccess = false; vm.pendingNewEmail = null; vm.twoFactorRequiredMessage = null; + vm.emailChange2faStatus = 'allowed'; + + refreshEmailChange2faStatus(); + + function refreshEmailChange2faStatus() { + featureGating.evaluate('update_email').then(function (status) { + vm.emailChange2faStatus = status; + }); + } function updateValidation(form) { if (!form.pass.$modelValue || !form.confPass.$modelValue) { @@ -149,14 +159,14 @@ return; } - clerk.hasTwoFactorEnabled() - .then(function(enabled) { - if (enabled) { - vm.showUserNameContainer = true; - } else { - vm.twoFactorRequiredMessage = $translate.instant('two_factor_required_for_action'); - } - }); + featureGating.evaluate('update_email').then(function(status) { + vm.emailChange2faStatus = status; + if (status === featureGating.STATUS_BLOCKED_NEEDS_2FA) { + vm.twoFactorRequiredMessage = $translate.instant('two_factor_required_for_action'); + return; + } + vm.showUserNameContainer = true; + }); } function changeUsername(form) { @@ -171,30 +181,23 @@ var useClerkAuth = RELAY_CONFIG.useClerkAuthentication || false; if (useClerkAuth) { - clerk.hasTwoFactorEnabled() - .then(function(enabled) { - if (!enabled) { - vm.emailChangeError = $translate.instant('two_factor_required_for_action'); + clerk.createEmailAddress(form.username.$modelValue) + .then(function(result) { + if (!result.success) { + if (result.emailAlreadyExists) { + vm.existingEmail = true; + return; + } + if (result.invalidFormat) { + vm.emailChangeError = $translate.instant('change_email_invalid_format'); + return; + } + vm.emailChangeError = result.error || $translate.instant('change_email_error'); return; } - return clerk.createEmailAddress(form.username.$modelValue) - .then(function(result) { - if (!result.success) { - if (result.emailAlreadyExists) { - vm.existingEmail = true; - return; - } - if (result.invalidFormat) { - vm.emailChangeError = $translate.instant('change_email_invalid_format'); - return; - } - vm.emailChangeError = result.error || $translate.instant('change_email_error'); - return; - } - vm.emailChangeStep = 'otp'; - vm.pendingNewEmail = form.username.$modelValue; - }); + vm.emailChangeStep = 'otp'; + vm.pendingNewEmail = form.username.$modelValue; }) .catch(function(error) { vm.emailChangeError = $translate.instant('change_email_error'); diff --git a/src/wwwroot/controllers/SettingsCtrl.js b/src/wwwroot/controllers/SettingsCtrl.js index bef106c6..19a9135e 100644 --- a/src/wwwroot/controllers/SettingsCtrl.js +++ b/src/wwwroot/controllers/SettingsCtrl.js @@ -12,13 +12,14 @@ 'settings', '$translate', 'ModalService', - 'auth' + 'auth', + 'featureGating' ]; - function SettingsCtrl($scope, $rootScope, RELAY_CONFIG, settings, $translate, ModalService, auth) { + function SettingsCtrl($scope, $rootScope, RELAY_CONFIG, settings, $translate, ModalService, auth, featureGating) { $rootScope.setSubmenues([ { text: 'domains_text', url: 'settings/domain-manager', active: false }, - { text: 'submenu_smtp', url: 'settings/connection-settings', active: true } + { text: 'submenu_smtp', url: 'settings/connection-settings', active: true } ]); var vm = this; vm.loadInProgress = true; @@ -30,12 +31,31 @@ vm.toggleShowPassword = function () { vm.inputType = vm.inputType != 'password' ? 'password' : 'text'; } - + vm.apiKeySentSuccefully = false; vm.apiKeySentFailed = false; vm.canManageApiKey = auth.canManageApiKey(); + vm.apiKey2faStatus = 'allowed'; + + refreshApiKey2faStatus(); + + function refreshApiKey2faStatus() { + featureGating.evaluate('manage_apikeys').then(function (status) { + vm.apiKey2faStatus = status; + }); + } vm.requestApiKey = function () { + featureGating.evaluate('manage_apikeys').then(function (status) { + vm.apiKey2faStatus = status; + if (status === featureGating.STATUS_BLOCKED_NEEDS_2FA) { + return; + } + doRequestApiKey(); + }); + } + + function doRequestApiKey() { vm.loadInProgress = true; vm.apiKeySentSuccefully = false; vm.apiKeySentFailed = false; @@ -54,6 +74,16 @@ } vm.resetApiKey = function() { + featureGating.evaluate('manage_apikeys').then(function (status) { + vm.apiKey2faStatus = status; + if (status === featureGating.STATUS_BLOCKED_NEEDS_2FA) { + return; + } + showResetApiKeyConfirmation(); + }); + } + + function showResetApiKeyConfirmation() { ModalService.showModal({ templateUrl: 'partials/modals/confirm.html', controller: 'Confirm', diff --git a/src/wwwroot/index.html b/src/wwwroot/index.html index 8d8e0348..65d7a022 100644 --- a/src/wwwroot/index.html +++ b/src/wwwroot/index.html @@ -144,6 +144,7 @@ + diff --git a/src/wwwroot/partials/settings/connection-settings.html b/src/wwwroot/partials/settings/connection-settings.html index 773e6045..c6949978 100644 --- a/src/wwwroot/partials/settings/connection-settings.html +++ b/src/wwwroot/partials/settings/connection-settings.html @@ -36,8 +36,18 @@
- - + +