Securing json endpoint for tags

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-11-02 15:34:01 -07:00
parent a1d749423e
commit cad9138ac4
3 changed files with 11 additions and 8 deletions

View File

@@ -124,6 +124,16 @@ namespace Orchard.Tags.Controllers {
return this.RedirectLocal(returnUrl, () => RedirectToAction("Index"));
}
public JsonResult FetchSimilarTags(string snippet) {
if (!Services.Authorizer.Authorize(Permissions.ManageTags, T("Not authorized to fetch tags")))
return Json(null);
return Json(
_tagService.GetTagsByNameSnippet(snippet).Select(tag => tag.TagName).ToList(),
JsonRequestBehavior.AllowGet
);
}
private static TagEntry CreateTagEntry(TagRecord tagRecord) {
return new TagEntry {
Tag = tagRecord,

View File

@@ -63,12 +63,5 @@ namespace Orchard.Tags.Controllers {
return View(viewModel);
}
public JsonResult FetchSimilarTags(string snippet) {
return Json(
_tagService.GetTagsByNameSnippet(snippet).Select(tag => tag.TagName).ToList(),
JsonRequestBehavior.AllowGet
);
}
}
}

View File

@@ -16,7 +16,7 @@
$(function () {
$.tagsAutocomplete.autocomplete(
'@Html.FieldIdFor(m => m.Tags)',
'@Url.Action("FetchSimilarTags", new { Controller = "Home", Area = "Orchard.Tags" })', 1);
'@Url.Action("FetchSimilarTags", new { Controller = "Admin", Area = "Orchard.Tags" })', 1);
});
//]]>
</script>