Skip to content

Instantly share code, notes, and snippets.

@skttl
Created May 12, 2022 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skttl/1607ef85d79618d6e956b36fd7438be3 to your computer and use it in GitHub Desktop.
Save skttl/1607ef85d79618d6e956b36fd7438be3 to your computer and use it in GitHub Desktop.
Custom Content Type Permissions in Umbraco 7
<div class="umb-dialog-body with-footer" ng-controller="Project.ContentCreateController">
<div class="umb-pane">
<h5><localize key="create_createUnder">Create a page under</localize> {{currentNode.name}}</h5>
<p class="abstract" ng-hide="allowedTypes">
<localize key="create_noDocumentTypes" />
</p>
<ul class="umb-actions umb-actions-child">
<li ng-repeat="docType in allowedTypes | filterDisallowedDocTypes: disallowedTypes | orderBy:'name':false">
<a href="#content/content/edit/{{currentNode.id}}?doctype={{docType.alias}}&create=true" ng-click="nav.hideNavigation()">
<i class="large {{docType.icon}}"></i>
<span class="menu-label">
{{docType.name}}
<small>
{{docType.description}}
</small>
</span>
</a>
</li>
</ul>
</div>
</div>
<div class="umb-dialog-footer btn-toolbar umb-btn-toolbar">
<button class="btn" ng-click="nav.hideDialog(true)">
<localize key="buttons_somethingElse">Do something else</localize>
</button>
</div>
angular.module('umbraco.services').config([
'$httpProvider',
function ($httpProvider) {
$httpProvider.interceptors.push(function ($q) {
return {
'request': function (request) {
if (request.url.indexOf("views/content/create.html") > -1) {
request.url = '/App_Plugins/DocTypePermissions/create.html';
}
return request || $q.when(request);
}
};
});
}]);
angular.module('umbraco').filter('filterDisallowedDocTypes', function () {
return function (input, disallowed) {
var inputArray = [];
for (var item in input) {
inputArray.push(input[item]);
}
return inputArray.filter(function (v) { return disallowed.indexOf(v.alias) < 0; });
};
});
angular.module('umbraco').controller('Project.ContentCreateController',
['$scope', '$controller', '$http',
function ($scope, $controller, $http) {
angular.extend(this, $controller('Umbraco.Editors.Content.CreateController', { $scope: $scope }));
$http.get("/umbraco/backoffice/api/Permissions/GetDisallowedDocTypes?parentId=" + $scope.currentNode.id).then(function (r) {
$scope.disallowedTypes = r.data;
});
}]);
{
javascript: [
"~/App_Plugins/DocTypePermissions/doctypepermissions.js"
]
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.WebApi;
namespace Project.Controllers
{
public class PermissionsController : UmbracoAuthorizedApiController
{
[HttpGet]
public List<string> GetDisallowedDocTypes(int parentId)
{
var listOfAliases = new List<string>();
// do the logic here, to find the content type aliases, that is NOT allowed
// eg
listOfAliases.Add("imNotAllowed");
return listOfAliases;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment