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 06ef8748a0..c056f70a92 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 @@ -940,6 +940,62 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { ), "Failed to roll back content item with id " + contentId ); + }, + + /** + * @ngdoc method + * @name umbraco.resources.contentResource#getPublicAccess + * @methodOf umbraco.resources.contentResource + * + * @description + * Returns the public access protection for a content item + * + * ##usage + *
+ * contentResource.getPublicAccess(contentId)
+ * .then(function(publicAccess) {
+ * // do your thing
+ * });
+ *
+ *
+ * @param {Int} contentId The content Id
+ * @returns {Promise} resourcePromise object containing the public access protection
+ *
+ */
+ getPublicAccess: function (contentId) {
+ return umbRequestHelper.resourcePromise(
+ $http.get(
+ umbRequestHelper.getApiUrl("contentApiBaseUrl", "GetPublicAccess", {
+ contentId: contentId
+ })
+ ),
+ "Failed to get public access for content item with id " + contentId
+ );
+ },
+
+ // TODO KJAC: ngdoc this
+ updatePublicAccess: function (contentId, userName, password, roles, loginPageId, errorPageId) {
+ var publicAccess = {
+ contentId: contentId,
+ loginPageId: loginPageId,
+ errorPageId: errorPageId
+ };
+ if (userName && password) {
+ publicAccess.userName = userName;
+ publicAccess.password = password;
+ }
+ else if (angular.isArray(roles) && roles.length) {
+ publicAccess.roles = roles;
+ }
+ else {
+ throw "must supply either userName/password or roles";
+ }
+ return umbRequestHelper.resourcePromise(
+ $http.post(
+ umbRequestHelper.getApiUrl("contentApiBaseUrl", "PostPublicAccess", publicAccess)
+ ),
+ "Failed to update 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 fc2da0ef75..84d8619303 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) {
+ function ContentProtectController($scope, $routeParams, contentResource, memberGroupResource, navigationService, editorService) {
var vm = this;
var id = $scope.currentNode.id;
@@ -9,35 +9,147 @@
vm.loading = false;
vm.saveButtonState = "init";
+ vm.isValid = isValid;
vm.next = next;
vm.save = save;
vm.close = close;
+ vm.toggle = toggle;
+ vm.pickLoginPage = pickLoginPage;
+ vm.pickErrorPage = pickErrorPage;
+ vm.remove = remove;
+ vm.removeConfirm = removeConfirm;
vm.type = null;
+ vm.step = null;
function onInit() {
vm.loading = true;
- // Get all member groups
- memberGroupResource.getGroups().then(function (groups) {
- vm.groups = groups;
- vm.step = "type";
- vm.loading = false;
+
+ // get the current public access protection
+ contentResource.getPublicAccess(id).then(function (publicAccess) {
+ // init the current settings for public access (if any)
+ vm.loginPage = publicAccess.loginPage;
+ vm.errorPage = publicAccess.errorPage;
+ vm.userName = publicAccess.userName;
+ vm.roles = publicAccess.roles;
+ vm.canRemove = true;
+
+ if (vm.userName) {
+ vm.type = "user";
+ next();
+ }
+ else if (vm.roles) {
+ vm.type = "role";
+ next();
+ }
+ else {
+ vm.canRemove = false;
+ vm.loading = false;
+ }
});
}
function next() {
- vm.step = vm.type;
+ if (vm.type === "role") {
+ vm.loading = true;
+ // Get all member groups
+ memberGroupResource.getGroups().then(function (groups) {
+ vm.step = vm.type;
+ vm.groups = groups;
+ // set groups "selected" according to currently selected roles for public access
+ _.each(groups, function(group) {
+ group.selected = _.contains(vm.roles, group.name);
+ });
+ vm.loading = false;
+ });
+ }
+ else {
+ vm.step = vm.type;
+ }
+ }
+
+ function isValid() {
+ if (!vm.type) {
+ return false;
+ }
+ if (!vm.protectForm.$valid) {
+ return false;
+ }
+ if (!vm.loginPage || !vm.errorPage) {
+ return false;
+ }
+ if (vm.type === "role") {
+ return !!_.find(vm.groups, function(group) { return group.selected; });
+ }
+ return true;
}
function save() {
vm.saveButtonState = "busy";
- console.log("TODO: SAVE!")
+ var selectedGroups = _.filter(vm.groups, function(group) { return group.selected; });
+ 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";
+ navigationService.syncTree({ tree: "content", path: $scope.currentNode.path, forceReload: true });
+ }, function (error) {
+ vm.error = error;
+ vm.saveButtonState = "error";
+ }
+ );
}
function close() {
navigationService.hideDialog();
}
+ function toggle(group) {
+ group.selected = !group.selected;
+ }
+
+ function pickLoginPage() {
+ // TODO KJAC: temporary test values until we fix the content picker
+ if (!vm.loginPage) {
+ vm.loginPage = { id: 1092 };
+ }
+
+ //editorService.contentPicker({
+ // submit: function(model) {
+ // console.log("I picked", model)
+ // editorService.close();
+ // },
+ // close: function () {
+ // editorService.close();
+ // }
+ //});
+ }
+
+ function pickErrorPage() {
+ // TODO KJAC: temporary test values until we fix the content picker
+ if (!vm.errorPage) {
+ vm.errorPage = { id: 1093 };
+ }
+
+ //editorService.contentPicker({
+ // submit: function(model) {
+ // console.log("I picked", model)
+ // editorService.close();
+ // },
+ // close: function () {
+ // editorService.close();
+ // }
+ //});
+ }
+
+ function remove() {
+ vm.removing = true;
+ }
+
+ function removeConfirm() {
+ vm.saveButtonState = "busy";
+ // TODO KJAC: remove protection from the page
+ }
+
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 3823d2bba1..93381303d0 100644
--- a/src/Umbraco.Web.UI.Client/src/views/content/protect.html
+++ b/src/Umbraco.Web.UI.Client/src/views/content/protect.html
@@ -1,82 +1,151 @@