diff --git a/src/Orchard.Web/Packages/Orchard.Tags/Controllers/AdminController.cs b/src/Orchard.Web/Packages/Orchard.Tags/Controllers/AdminController.cs index 6042ee96c..5ff36e28b 100644 --- a/src/Orchard.Web/Packages/Orchard.Tags/Controllers/AdminController.cs +++ b/src/Orchard.Web/Packages/Orchard.Tags/Controllers/AdminController.cs @@ -4,35 +4,27 @@ using System.Linq; using System.Web.Mvc; using JetBrains.Annotations; using Orchard.Localization; -using Orchard.Logging; using Orchard.ContentManagement; using Orchard.Settings; using Orchard.Tags.Models; using Orchard.Tags.ViewModels; -using Orchard.UI.Notify; -using Orchard.Security; using Orchard.Tags.Services; +using Orchard.UI.Notify; namespace Orchard.Tags.Controllers { [ValidateInput(false)] public class AdminController : Controller { 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; - _authorizer = authorizer; - _notifier = notifier; - Logger = NullLogger.Instance; T = NullLocalizer.Instance; } + public IOrchardServices Services { get; set; } protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; } - - public ILogger Logger { get; set; } public Localizer T { get; set; } public ActionResult Index() { @@ -43,7 +35,7 @@ namespace Orchard.Tags.Controllers { return View(model); } catch (Exception exception) { - _notifier.Error(T("Listing tags failed: " + exception.Message)); + Services.Notifier.Error(T("Listing tags failed: " + exception.Message)); return Index(); } } @@ -60,7 +52,7 @@ namespace Orchard.Tags.Controllers { case TagAdminIndexBulkAction.None: break; 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(); foreach (TagEntry entry in checkedEntries) { @@ -73,7 +65,7 @@ namespace Orchard.Tags.Controllers { } } catch (Exception exception) { - _notifier.Error(T("Editing tags failed: " + exception.Message)); + Services.Notifier.Error(T("Editing tags failed: " + exception.Message)); return Index(); } @@ -89,13 +81,13 @@ namespace Orchard.Tags.Controllers { var viewModel = new TagsAdminCreateViewModel(); try { 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(); _tagService.CreateTag(viewModel.TagName); return RedirectToAction("Index"); } catch (Exception exception) { - _notifier.Error(T("Creating tag failed: " + exception.Message)); + Services.Notifier.Error(T("Creating tag failed: " + exception.Message)); return View(viewModel); } } @@ -111,7 +103,7 @@ namespace Orchard.Tags.Controllers { } catch (Exception exception) { - _notifier.Error(T("Retrieving tag information failed: " + exception.Message)); + Services.Notifier.Error(T("Retrieving tag information failed: " + exception.Message)); return Index(); } } @@ -121,14 +113,14 @@ namespace Orchard.Tags.Controllers { var viewModel = new TagsAdminEditViewModel(); try { 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(); _tagService.UpdateTag(viewModel.Id, viewModel.TagName); return RedirectToAction("Index"); } catch (Exception exception) { - _notifier.Error(T("Editing tag failed: " + exception.Message)); + Services.Notifier.Error(T("Editing tag failed: " + exception.Message)); return View(viewModel); } } @@ -145,7 +137,7 @@ namespace Orchard.Tags.Controllers { } catch (Exception exception) { - _notifier.Error(T("Retrieving tagged items failed: " + exception.Message)); + Services.Notifier.Error(T("Retrieving tagged items failed: " + exception.Message)); return Index(); } } diff --git a/src/Orchard.Web/Packages/Orchard.Tags/Controllers/HomeController.cs b/src/Orchard.Web/Packages/Orchard.Tags/Controllers/HomeController.cs index 468b9f896..514161317 100644 --- a/src/Orchard.Web/Packages/Orchard.Tags/Controllers/HomeController.cs +++ b/src/Orchard.Web/Packages/Orchard.Tags/Controllers/HomeController.cs @@ -5,34 +5,23 @@ using System.Web.Mvc; using JetBrains.Annotations; using Orchard.Localization; using Orchard.Logging; -using Orchard.ContentManagement; using Orchard.Settings; using Orchard.Tags.Helpers; -using Orchard.Tags.Models; using Orchard.Tags.Services; using Orchard.Tags.ViewModels; using Orchard.UI.Notify; -using Orchard.Security; namespace Orchard.Tags.Controllers { [ValidateInput(false)] public class HomeController : Controller { private readonly ITagService _tagService; - private readonly IAuthorizer _authorizer; - private readonly IContentManager _contentManager; - private readonly INotifier _notifier; - public HomeController(ITagService tagService, INotifier notifier, IAuthorizer authorizer, - IContentManager contentManager) { + public HomeController(ITagService tagService) { _tagService = tagService; - _authorizer = authorizer; - _contentManager = contentManager; - _notifier = notifier; - Logger = NullLogger.Instance; T = NullLocalizer.Instance; } - + public IOrchardServices Services { get; set; } protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; } @@ -46,7 +35,7 @@ namespace Orchard.Tags.Controllers { return View(model); } catch (Exception exception) { - _notifier.Error(T("Listing tags failed: " + exception.Message)); + Services.Notifier.Error(T("Listing tags failed: " + exception.Message)); return Index(); } } @@ -54,7 +43,7 @@ namespace Orchard.Tags.Controllers { [HttpPost] public ActionResult Edit(FormCollection input, int taggedContentId, string returnUrl, string newTagName) { 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(); if (!String.IsNullOrEmpty(newTagName)) { foreach (var tagName in TagHelpers.ParseCommaSeparatedTagNames(newTagName)) { @@ -70,7 +59,7 @@ namespace Orchard.Tags.Controllers { return RedirectToAction("Index"); } catch (Exception exception) { - _notifier.Error(T("Editing tags failed: " + exception.Message)); + Services.Notifier.Error(T("Editing tags failed: " + exception.Message)); if (!String.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); } @@ -81,7 +70,7 @@ namespace Orchard.Tags.Controllers { [HttpPost] public ActionResult Update(string tags, int taggedContentId, string returnUrl) { 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(); List tagNames = TagHelpers.ParseCommaSeparatedTagNames(tags); _tagService.UpdateTagsForContentItem(taggedContentId, tagNames); @@ -91,7 +80,7 @@ namespace Orchard.Tags.Controllers { return RedirectToAction("Index"); } catch (Exception exception) { - _notifier.Error(T("Updating tags failed: " + exception.Message)); + Services.Notifier.Error(T("Updating tags failed: " + exception.Message)); if (!String.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); } @@ -104,7 +93,7 @@ namespace Orchard.Tags.Controllers { var tag = _tagService.GetTagByName(tagName); var items = _tagService.GetTaggedContentItems(tag.Id).Select( - ic => _contentManager.BuildDisplayModel(ic, "SummaryForSearch")); + ic => Services.ContentManager.BuildDisplayModel(ic, "SummaryForSearch")); var viewModel = new TagsSearchViewModel { TagName = tag.TagName, @@ -114,7 +103,7 @@ namespace Orchard.Tags.Controllers { } 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"); } } diff --git a/src/Orchard.Web/Packages/Orchard.Users/Controllers/AdminController.cs b/src/Orchard.Web/Packages/Orchard.Users/Controllers/AdminController.cs index be54b4db4..a63a78c93 100644 --- a/src/Orchard.Web/Packages/Orchard.Users/Controllers/AdminController.cs +++ b/src/Orchard.Web/Packages/Orchard.Users/Controllers/AdminController.cs @@ -112,6 +112,16 @@ namespace Orchard.Users.Controllers { 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 model, string prefix, string[] includeProperties, string[] excludeProperties) { return TryUpdateModel(model, prefix, includeProperties, excludeProperties); } diff --git a/src/Orchard.Web/Packages/Orchard.Users/Permissions.cs b/src/Orchard.Web/Packages/Orchard.Users/Permissions.cs index 095cf06d9..8fe371f20 100644 --- a/src/Orchard.Web/Packages/Orchard.Users/Permissions.cs +++ b/src/Orchard.Web/Packages/Orchard.Users/Permissions.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using JetBrains.Annotations; using Orchard.Security.Permissions; diff --git a/src/Orchard.Web/Packages/Orchard.Users/Views/Admin/Index.aspx b/src/Orchard.Web/Packages/Orchard.Users/Views/Admin/Index.aspx index 4b85a37d8..5daa5d801 100644 --- a/src/Orchard.Web/Packages/Orchard.Users/Views/Admin/Index.aspx +++ b/src/Orchard.Web/Packages/Orchard.Users/Views/Admin/Index.aspx @@ -28,7 +28,8 @@ <%=Html.Encode(row.User.Email)%> - <%=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 })%> <%}%>