diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Controllers/TagsController.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Controllers/TagsController.cs index 3b99517d3..bc1d929f3 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Controllers/TagsController.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Controllers/TagsController.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Globalization; using System.Web.Http; using Orchard.ContentManagement; @@ -9,25 +10,33 @@ using Orchard.Taxonomies.Helpers; using Orchard.Taxonomies.Models; using Orchard.Taxonomies.Services; using System.Linq; +using Orchard.Security; +using Orchard.Taxonomies.ViewModels; namespace Orchard.Taxonomies.Controllers { public class TagsController : ApiController { private readonly ITaxonomyService _taxonomyService; private readonly IContentManager _contentManager; + private readonly IAuthorizer _authorizer; public Localizer T { get; set; } protected ILogger Logger { get; set; } public TagsController( ITaxonomyService taxonomyService, - IContentManager contentManager) { + IContentManager contentManager, + IAuthorizer authorizer) { _taxonomyService = taxonomyService; T = NullLocalizer.Instance; _contentManager = contentManager; + _authorizer = authorizer; Logger = NullLogger.Instance; } - public IEnumerable Get(int taxonomyId, bool leavesOnly, string query) { - if (string.IsNullOrEmpty(query)) return new List(); + public IEnumerable Get(int taxonomyId, bool leavesOnly, string query) { + if (!_authorizer.Authorize(StandardPermissions.AccessAdminPanel)) { + throw new UnauthorizedAccessException("Can't access the admin"); + } + if (string.IsNullOrEmpty(query)) return new List(); var allTerms = leavesOnly ? _taxonomyService.GetTerms(taxonomyId).ToList() : new List(); @@ -36,25 +45,19 @@ namespace Orchard.Taxonomies.Controllers { .Join() .Where(r => r.Title.Contains(query)) .List() - .Select(t => CreateTagDto(t, leavesOnly, allTerms)) - .OrderBy(t => t.label) + .Select(t => BuildTag(t, leavesOnly, allTerms)) + .OrderBy(t => t.Label) .ToList(); return matchingTerms; } - private static TagDto CreateTagDto(TermPart term, bool leavesOnly, IEnumerable terms) { - return new TagDto { - value = term.Id, - label = term.Name, - disabled = !term.Selectable || (leavesOnly && terms.Any(t => t.Path.Contains(term.Path + term.Id))), - levels = term.GetLevels() + private static Tag BuildTag(TermPart term, bool leavesOnly, IEnumerable terms) { + return new Tag { + Value = term.Id, + Label = term.Name, + Disabled = !term.Selectable || (leavesOnly && terms.Any(t => t.Path.Contains(term.Path + term.Id))), + Levels = term.GetLevels() }; } } - public class TagDto { - public string label { get; set; } - public int value { get; set; } - public int levels { get; set; } - public bool disabled { get; set; } - } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Orchard.Taxonomies.csproj b/src/Orchard.Web/Modules/Orchard.Taxonomies/Orchard.Taxonomies.csproj index d7249ff13..b3725af1a 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Orchard.Taxonomies.csproj +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Orchard.Taxonomies.csproj @@ -50,6 +50,9 @@ + + ..\..\..\..\lib\newtonsoft.json\Newtonsoft.Json.dll + 3.5 @@ -76,6 +79,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/ViewModels/Tag.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/ViewModels/Tag.cs new file mode 100644 index 000000000..e379d0653 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/ViewModels/Tag.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace Orchard.Taxonomies.ViewModels { + public class Tag { + [JsonProperty("label")] + public string Label { get; set; } + + [JsonProperty("value")] + public int Value { get; set; } + + [JsonProperty("levels")] + public int Levels { get; set; } + + [JsonProperty("disabled")] + public bool Disabled { get; set; } + } +} \ No newline at end of file