mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-22 12:54:10 +08:00
- 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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string> 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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
|
||||
return TryUpdateModel(model, prefix, includeProperties, excludeProperties);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
<%=Html.Encode(row.User.Email)%>
|
||||
</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>
|
||||
</tr>
|
||||
<%}%>
|
||||
|
||||
Reference in New Issue
Block a user