Implement remove protection + add success messages
This commit is contained in:
@@ -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
|
||||
* <pre>
|
||||
* contentResource.removePublicAccess(contentId)
|
||||
* .then(function() {
|
||||
* // do your thing
|
||||
* });
|
||||
* </pre>
|
||||
*
|
||||
* @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
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<div ng-controller="Umbraco.Editors.Content.ProtectController as vm">
|
||||
<form name="vm.protectForm" novalidate>
|
||||
<div class="umb-dialog-body form-horizontal" ng-cloak>
|
||||
<umb-pane>
|
||||
<umb-pane ng-hide="vm.success">
|
||||
|
||||
<div ng-show="error">
|
||||
<div ng-show="vm.error">
|
||||
<div class="alert alert-error">
|
||||
<div><strong>{{error.errorMsg}}</strong></div>
|
||||
<div>{{error.data.message}}</div>
|
||||
<div><strong>{{vm.error.errorMsg}}</strong></div>
|
||||
<div>{{vm.error.data.message}}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -97,16 +97,26 @@
|
||||
<!--<pre>{{vm | json}}</pre>-->
|
||||
|
||||
</umb-pane>
|
||||
|
||||
<umb-pane ng-show="vm.success">
|
||||
<div class="alert alert-success" ng-bind-html="vm.success.message"></div>
|
||||
<umb-button type="button"
|
||||
action="vm.close()"
|
||||
button-style="success"
|
||||
label-key="general_ok">
|
||||
</umb-button>
|
||||
</umb-pane>
|
||||
</div>
|
||||
|
||||
<div class="umb-dialog-footer umb-btn-toolbar" ng-hide="vm.loading || vm.removing">
|
||||
<umb-button type="button"
|
||||
<div class="umb-dialog-footer umb-btn-toolbar" ng-hide="vm.loading || vm.success">
|
||||
<umb-button ng-hide="vm.removing"
|
||||
type="button"
|
||||
button-style="link"
|
||||
action="vm.close()"
|
||||
label-key="general_close">
|
||||
</umb-button>
|
||||
|
||||
<umb-button ng-hide="vm.step"
|
||||
<umb-button ng-hide="vm.step || vm.removing"
|
||||
type="button"
|
||||
action="vm.next()"
|
||||
button-style="success"
|
||||
@@ -114,7 +124,7 @@
|
||||
disabled="vm.loading || !vm.type">
|
||||
</umb-button>
|
||||
|
||||
<umb-button ng-show="vm.canRemove"
|
||||
<umb-button ng-show="vm.canRemove && !vm.removing"
|
||||
type="button"
|
||||
action="vm.remove()"
|
||||
button-style="warning"
|
||||
@@ -122,7 +132,7 @@
|
||||
disabled="vm.loading">
|
||||
</umb-button>
|
||||
|
||||
<umb-button ng-show="vm.step"
|
||||
<umb-button ng-show="vm.step && !vm.removing"
|
||||
type="button"
|
||||
action="vm.save()"
|
||||
state="vm.saveButtonState"
|
||||
@@ -130,16 +140,16 @@
|
||||
label-key="buttons_save"
|
||||
disabled="vm.buttonState === 'busy' || !vm.isValid()">
|
||||
</umb-button>
|
||||
</div>
|
||||
|
||||
<div class="umb-dialog-footer umb-btn-toolbar" ng-show="vm.removing">
|
||||
<umb-button type="button"
|
||||
<umb-button ng-show="vm.removing"
|
||||
type="button"
|
||||
button-style="link"
|
||||
action="vm.close()"
|
||||
label-key="buttons_confirmActionCancel">
|
||||
</umb-button>
|
||||
|
||||
<umb-button type="button"
|
||||
<umb-button ng-show="vm.removing"
|
||||
type="button"
|
||||
action="vm.removeConfirm()"
|
||||
state="vm.saveButtonState"
|
||||
button-style="success"
|
||||
|
||||
@@ -879,8 +879,8 @@ Mange hilsner fra Umbraco robotten
|
||||
<key alias="paErrorPage">Fejlside</key>
|
||||
<key alias="paErrorPageHelp">Brugt når folk er logget ind, men ingen adgang</key>
|
||||
<key alias="paHowWould"><![CDATA[Vælg hvordan siden <strong>%0%</strong> skal beskyttes]]></key>
|
||||
<!--<key alias="paIsProtected">%0% er nu beskyttet</key>
|
||||
<key alias="paIsRemoved">Beskyttelse fjernet fra %0%</key>-->
|
||||
<key alias="paIsProtected"><![CDATA[<strong>%0%</strong> er nu beskyttet]]></key>
|
||||
<key alias="paIsRemoved"><![CDATA[Beskyttelse fjernet fra <strong>%0%</strong>]]></key>
|
||||
<key alias="paLoginPage">Log ind-side</key>
|
||||
<key alias="paLoginPageHelp">Vælg siden der indeholder log ind-formularen</key>
|
||||
<key alias="paRemoveProtection">Fjern beskyttelse...</key>
|
||||
|
||||
@@ -1131,8 +1131,8 @@ To manage your website, simply open the Umbraco back office and start adding con
|
||||
<key alias="paErrorPage">Error Page</key>
|
||||
<key alias="paErrorPageHelp">Used when people are logged on, but do not have access</key>
|
||||
<key alias="paHowWould"><![CDATA[Choose how to restrict access to the page <strong>%0%</strong>]]></key>
|
||||
<!--<key alias="paIsProtected">%0% is now protected</key>
|
||||
<key alias="paIsRemoved">Protection removed from %0%</key>-->
|
||||
<key alias="paIsProtected"><![CDATA[<strong>%0%</strong> is now protected]]></key>
|
||||
<key alias="paIsRemoved"><![CDATA[Protection removed from <strong>%0%</strong>]]></key>
|
||||
<key alias="paLoginPage">Login Page</key>
|
||||
<key alias="paLoginPageHelp">Choose the page that contains the login form</key>
|
||||
<key alias="paRemoveProtection">Remove protection...</key>
|
||||
|
||||
@@ -2246,9 +2246,9 @@ namespace Umbraco.Web.Editors
|
||||
}
|
||||
}
|
||||
|
||||
Services.PublicAccessService.Save(entry);
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK);
|
||||
return Services.PublicAccessService.Save(entry).Success
|
||||
? Request.CreateResponse(HttpStatusCode.OK)
|
||||
: Request.CreateResponse(HttpStatusCode.InternalServerError);
|
||||
}
|
||||
|
||||
// set up public access using username and password
|
||||
@@ -2274,5 +2274,26 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
return Request.CreateResponse(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
[EnsureUserPermissionForContent("contentId", ActionProtect.ActionLetter)]
|
||||
[HttpPost]
|
||||
public HttpResponseMessage RemovePublicAccess(int contentId)
|
||||
{
|
||||
var content = Services.ContentService.GetById(contentId);
|
||||
if (content == null)
|
||||
{
|
||||
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
|
||||
}
|
||||
|
||||
var entry = Services.PublicAccessService.GetEntryForContent(content);
|
||||
if (entry == null)
|
||||
{
|
||||
return Request.CreateResponse(HttpStatusCode.OK);
|
||||
}
|
||||
|
||||
return Services.PublicAccessService.Delete(entry).Success
|
||||
? Request.CreateResponse(HttpStatusCode.OK)
|
||||
: Request.CreateResponse(HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user