From ed56845bc1d4e6891cb3372eb5a9fc5323c1b30e Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Sun, 25 Nov 2018 09:17:04 +0100 Subject: [PATCH] Implement remove protection + add success messages --- .../src/common/resources/content.resource.js | 32 ++++++++++++++++- .../content/content.protect.controller.js | 22 ++++++++++-- .../src/views/content/protect.html | 36 ++++++++++++------- src/Umbraco.Web.UI/Umbraco/config/lang/da.xml | 4 +-- src/Umbraco.Web.UI/Umbraco/config/lang/en.xml | 4 +-- src/Umbraco.Web/Editors/ContentController.cs | 27 ++++++++++++-- 6 files changed, 101 insertions(+), 24 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js index c056f70a92..a663d8e52c 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js @@ -996,8 +996,38 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { ), "Failed to update public access for content item with id " + contentId ); - } + }, + /** + * @ngdoc method + * @name umbraco.resources.contentResource#removePublicAccess + * @methodOf umbraco.resources.contentResource + * + * @description + * Removes the public access protection for a content item + * + * ##usage + *
+          * contentResource.removePublicAccess(contentId)
+          *    .then(function() {
+          *        // do your thing
+          *    });
+          * 
+ * + * @param {Int} contentId The content Id + * @returns {Promise} resourcePromise object that's resolved once the public access has been removed + * + */ + removePublicAccess: function (contentId) { + return umbRequestHelper.resourcePromise( + $http.post( + umbRequestHelper.getApiUrl("contentApiBaseUrl", "RemovePublicAccess", { + contentId: contentId + }) + ), + "Failed to remove public access for content item with id " + contentId + ); + } }; } diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.protect.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.protect.controller.js index 84d8619303..3ef930d7af 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.protect.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.protect.controller.js @@ -1,7 +1,7 @@ (function () { "use strict"; - function ContentProtectController($scope, $routeParams, contentResource, memberGroupResource, navigationService, editorService) { + function ContentProtectController($scope, $routeParams, contentResource, memberGroupResource, navigationService, localizationService) { var vm = this; var id = $scope.currentNode.id; @@ -90,7 +90,11 @@ var roles = _.map(selectedGroups, function(group) { return group.name; }); contentResource.updatePublicAccess(id, vm.userName, vm.password, roles, vm.loginPage.id, vm.errorPage.id).then( function () { - vm.saveButtonState = "success"; + localizationService.localize("publicAccess_paIsProtected", [$scope.currentNode.name]).then(function (value) { + vm.success = { + message: value + }; + }); navigationService.syncTree({ tree: "content", path: $scope.currentNode.path, forceReload: true }); }, function (error) { vm.error = error; @@ -147,7 +151,19 @@ function removeConfirm() { vm.saveButtonState = "busy"; - // TODO KJAC: remove protection from the page + contentResource.removePublicAccess(id).then( + function () { + localizationService.localize("publicAccess_paIsRemoved", [$scope.currentNode.name]).then(function(value) { + vm.success = { + message: value + }; + }); + navigationService.syncTree({ tree: "content", path: $scope.currentNode.path, forceReload: true }); + }, function (error) { + vm.error = error; + vm.saveButtonState = "error"; + } + ); } onInit(); diff --git a/src/Umbraco.Web.UI.Client/src/views/content/protect.html b/src/Umbraco.Web.UI.Client/src/views/content/protect.html index 93381303d0..8e1a8259cd 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/protect.html +++ b/src/Umbraco.Web.UI.Client/src/views/content/protect.html @@ -1,12 +1,12 @@
- + -
+
-
{{error.errorMsg}}
-
{{error.data.message}}
+
{{vm.error.errorMsg}}
+
{{vm.error.data.message}}
@@ -97,16 +97,26 @@ + + +
+ + +
- -