- Adding ability to delete users from the manage users screen.

- Fixing a couple bugs/refactoring related to tags.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4046022
This commit is contained in:
suhacan
2010-01-27 20:39:35 +00:00
parent 1157fac6b1
commit dac26b2b6d
5 changed files with 33 additions and 42 deletions

View File

@@ -4,35 +4,27 @@ using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Settings; using Orchard.Settings;
using Orchard.Tags.Models; using Orchard.Tags.Models;
using Orchard.Tags.ViewModels; using Orchard.Tags.ViewModels;
using Orchard.UI.Notify;
using Orchard.Security;
using Orchard.Tags.Services; using Orchard.Tags.Services;
using Orchard.UI.Notify;
namespace Orchard.Tags.Controllers { namespace Orchard.Tags.Controllers {
[ValidateInput(false)] [ValidateInput(false)]
public class AdminController : Controller { public class AdminController : Controller {
private readonly ITagService _tagService; private readonly ITagService _tagService;
private readonly IAuthorizer _authorizer;
private readonly INotifier _notifier;
public AdminController(ITagService tagService, INotifier notifier, IAuthorizer authorizer) { public AdminController(ITagService tagService) {
_tagService = tagService; _tagService = tagService;
_authorizer = authorizer;
_notifier = notifier;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
public IOrchardServices Services { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; } protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
public ILogger Logger { get; set; }
public Localizer T { get; set; } public Localizer T { get; set; }
public ActionResult Index() { public ActionResult Index() {
@@ -43,7 +35,7 @@ namespace Orchard.Tags.Controllers {
return View(model); return View(model);
} }
catch (Exception exception) { catch (Exception exception) {
_notifier.Error(T("Listing tags failed: " + exception.Message)); Services.Notifier.Error(T("Listing tags failed: " + exception.Message));
return Index(); return Index();
} }
} }
@@ -60,7 +52,7 @@ namespace Orchard.Tags.Controllers {
case TagAdminIndexBulkAction.None: case TagAdminIndexBulkAction.None:
break; break;
case TagAdminIndexBulkAction.Delete: case TagAdminIndexBulkAction.Delete:
if (!_authorizer.Authorize(Permissions.ManageTags, T("Couldn't delete tag"))) if (!Services.Authorizer.Authorize(Permissions.ManageTags, T("Couldn't delete tag")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
foreach (TagEntry entry in checkedEntries) { foreach (TagEntry entry in checkedEntries) {
@@ -73,7 +65,7 @@ namespace Orchard.Tags.Controllers {
} }
} }
catch (Exception exception) { catch (Exception exception) {
_notifier.Error(T("Editing tags failed: " + exception.Message)); Services.Notifier.Error(T("Editing tags failed: " + exception.Message));
return Index(); return Index();
} }
@@ -89,13 +81,13 @@ namespace Orchard.Tags.Controllers {
var viewModel = new TagsAdminCreateViewModel(); var viewModel = new TagsAdminCreateViewModel();
try { try {
UpdateModel(viewModel); UpdateModel(viewModel);
if (!_authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag"))) if (!Services.Authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
_tagService.CreateTag(viewModel.TagName); _tagService.CreateTag(viewModel.TagName);
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
catch (Exception exception) { catch (Exception exception) {
_notifier.Error(T("Creating tag failed: " + exception.Message)); Services.Notifier.Error(T("Creating tag failed: " + exception.Message));
return View(viewModel); return View(viewModel);
} }
} }
@@ -111,7 +103,7 @@ namespace Orchard.Tags.Controllers {
} }
catch (Exception exception) { catch (Exception exception) {
_notifier.Error(T("Retrieving tag information failed: " + exception.Message)); Services.Notifier.Error(T("Retrieving tag information failed: " + exception.Message));
return Index(); return Index();
} }
} }
@@ -121,14 +113,14 @@ namespace Orchard.Tags.Controllers {
var viewModel = new TagsAdminEditViewModel(); var viewModel = new TagsAdminEditViewModel();
try { try {
UpdateModel(viewModel); UpdateModel(viewModel);
if (!_authorizer.Authorize(Permissions.ManageTags, T("Couldn't edit tag"))) if (!Services.Authorizer.Authorize(Permissions.ManageTags, T("Couldn't edit tag")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
_tagService.UpdateTag(viewModel.Id, viewModel.TagName); _tagService.UpdateTag(viewModel.Id, viewModel.TagName);
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
catch (Exception exception) { catch (Exception exception) {
_notifier.Error(T("Editing tag failed: " + exception.Message)); Services.Notifier.Error(T("Editing tag failed: " + exception.Message));
return View(viewModel); return View(viewModel);
} }
} }
@@ -145,7 +137,7 @@ namespace Orchard.Tags.Controllers {
} }
catch (Exception exception) { catch (Exception exception) {
_notifier.Error(T("Retrieving tagged items failed: " + exception.Message)); Services.Notifier.Error(T("Retrieving tagged items failed: " + exception.Message));
return Index(); return Index();
} }
} }

View File

@@ -5,34 +5,23 @@ using System.Web.Mvc;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.ContentManagement;
using Orchard.Settings; using Orchard.Settings;
using Orchard.Tags.Helpers; using Orchard.Tags.Helpers;
using Orchard.Tags.Models;
using Orchard.Tags.Services; using Orchard.Tags.Services;
using Orchard.Tags.ViewModels; using Orchard.Tags.ViewModels;
using Orchard.UI.Notify; using Orchard.UI.Notify;
using Orchard.Security;
namespace Orchard.Tags.Controllers { namespace Orchard.Tags.Controllers {
[ValidateInput(false)] [ValidateInput(false)]
public class HomeController : Controller { public class HomeController : Controller {
private readonly ITagService _tagService; private readonly ITagService _tagService;
private readonly IAuthorizer _authorizer;
private readonly IContentManager _contentManager;
private readonly INotifier _notifier;
public HomeController(ITagService tagService, INotifier notifier, IAuthorizer authorizer, public HomeController(ITagService tagService) {
IContentManager contentManager) {
_tagService = tagService; _tagService = tagService;
_authorizer = authorizer;
_contentManager = contentManager;
_notifier = notifier;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
} }
public IOrchardServices Services { get; set; }
protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; } protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; }
@@ -46,7 +35,7 @@ namespace Orchard.Tags.Controllers {
return View(model); return View(model);
} }
catch (Exception exception) { catch (Exception exception) {
_notifier.Error(T("Listing tags failed: " + exception.Message)); Services.Notifier.Error(T("Listing tags failed: " + exception.Message));
return Index(); return Index();
} }
} }
@@ -54,7 +43,7 @@ namespace Orchard.Tags.Controllers {
[HttpPost] [HttpPost]
public ActionResult Edit(FormCollection input, int taggedContentId, string returnUrl, string newTagName) { public ActionResult Edit(FormCollection input, int taggedContentId, string returnUrl, string newTagName) {
try { try {
if (!_authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag"))) if (!Services.Authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
if (!String.IsNullOrEmpty(newTagName)) { if (!String.IsNullOrEmpty(newTagName)) {
foreach (var tagName in TagHelpers.ParseCommaSeparatedTagNames(newTagName)) { foreach (var tagName in TagHelpers.ParseCommaSeparatedTagNames(newTagName)) {
@@ -70,7 +59,7 @@ namespace Orchard.Tags.Controllers {
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
catch (Exception exception) { catch (Exception exception) {
_notifier.Error(T("Editing tags failed: " + exception.Message)); Services.Notifier.Error(T("Editing tags failed: " + exception.Message));
if (!String.IsNullOrEmpty(returnUrl)) { if (!String.IsNullOrEmpty(returnUrl)) {
return Redirect(returnUrl); return Redirect(returnUrl);
} }
@@ -81,7 +70,7 @@ namespace Orchard.Tags.Controllers {
[HttpPost] [HttpPost]
public ActionResult Update(string tags, int taggedContentId, string returnUrl) { public ActionResult Update(string tags, int taggedContentId, string returnUrl) {
try { try {
if (!_authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag"))) if (!Services.Authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
List<string> tagNames = TagHelpers.ParseCommaSeparatedTagNames(tags); List<string> tagNames = TagHelpers.ParseCommaSeparatedTagNames(tags);
_tagService.UpdateTagsForContentItem(taggedContentId, tagNames); _tagService.UpdateTagsForContentItem(taggedContentId, tagNames);
@@ -91,7 +80,7 @@ namespace Orchard.Tags.Controllers {
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
catch (Exception exception) { catch (Exception exception) {
_notifier.Error(T("Updating tags failed: " + exception.Message)); Services.Notifier.Error(T("Updating tags failed: " + exception.Message));
if (!String.IsNullOrEmpty(returnUrl)) { if (!String.IsNullOrEmpty(returnUrl)) {
return Redirect(returnUrl); return Redirect(returnUrl);
} }
@@ -104,7 +93,7 @@ namespace Orchard.Tags.Controllers {
var tag = _tagService.GetTagByName(tagName); var tag = _tagService.GetTagByName(tagName);
var items = var items =
_tagService.GetTaggedContentItems(tag.Id).Select( _tagService.GetTaggedContentItems(tag.Id).Select(
ic => _contentManager.BuildDisplayModel(ic, "SummaryForSearch")); ic => Services.ContentManager.BuildDisplayModel(ic, "SummaryForSearch"));
var viewModel = new TagsSearchViewModel { var viewModel = new TagsSearchViewModel {
TagName = tag.TagName, TagName = tag.TagName,
@@ -114,7 +103,7 @@ namespace Orchard.Tags.Controllers {
} }
catch (Exception exception) { catch (Exception exception) {
_notifier.Error(T("Retrieving tagged items failed: " + exception.Message)); Services.Notifier.Error(T("Retrieving tagged items failed: " + exception.Message));
return RedirectToAction("Index"); return RedirectToAction("Index");
} }
} }

View File

@@ -112,6 +112,16 @@ namespace Orchard.Users.Controllers {
return RedirectToAction("Edit", new { id }); return RedirectToAction("Edit", new { id });
} }
public ActionResult Delete(int id) {
if (!Services.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users")))
return new HttpUnauthorizedResult();
Services.ContentManager.Remove(Services.ContentManager.Get(id));
Services.Notifier.Information(T("User deleted"));
return RedirectToAction("Index");
}
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) { bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
return TryUpdateModel(model, prefix, includeProperties, excludeProperties); return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
} }

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Security.Permissions; using Orchard.Security.Permissions;

View File

@@ -28,7 +28,8 @@
<%=Html.Encode(row.User.Email)%> <%=Html.Encode(row.User.Email)%>
</td> </td>
<td> <td>
<%=Html.ActionLink(T("Edit").ToString(), "Edit", new { row.User.Id })%> <%=Html.ActionLink(T("Edit").ToString(), "Edit", new { row.User.Id })%> |
<%=Html.ActionLink(T("Delete").ToString(), "Delete", new { row.User.Id })%>
</td> </td>
</tr> </tr>
<%}%> <%}%>