mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
16963: Tags: only keep manage tags permission
--HG-- branch : dev
This commit is contained in:
@@ -71,9 +71,6 @@ namespace Orchard.Tags.Controllers {
|
|||||||
return Index();
|
return Index();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Services.Authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag")))
|
|
||||||
return new HttpUnauthorizedResult();
|
|
||||||
|
|
||||||
_tagService.CreateTag(viewModel.TagName);
|
_tagService.CreateTag(viewModel.TagName);
|
||||||
|
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
|
@@ -34,17 +34,11 @@ namespace Orchard.Tags.Drivers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Editor(TagsPart part, dynamic shapeHelper) {
|
protected override DriverResult Editor(TagsPart part, dynamic shapeHelper) {
|
||||||
if (!_authorizationService.TryCheckAccess(Permissions.ApplyTag, _orchardServices.WorkContext.CurrentUser, part))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return ContentShape("Parts_Tags_Edit",
|
return ContentShape("Parts_Tags_Edit",
|
||||||
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: BuildEditorViewModel(part), Prefix: Prefix));
|
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: BuildEditorViewModel(part), Prefix: Prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Editor(TagsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
protected override DriverResult Editor(TagsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
if (!_authorizationService.TryCheckAccess(Permissions.ApplyTag, _orchardServices.WorkContext.CurrentUser, part))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var model = new EditTagsViewModel();
|
var model = new EditTagsViewModel();
|
||||||
updater.TryUpdateModel(model, Prefix, null, null);
|
updater.TryUpdateModel(model, Prefix, null, null);
|
||||||
|
|
||||||
|
@@ -5,16 +5,12 @@ using Orchard.Security.Permissions;
|
|||||||
namespace Orchard.Tags {
|
namespace Orchard.Tags {
|
||||||
public class Permissions : IPermissionProvider {
|
public class Permissions : IPermissionProvider {
|
||||||
public static readonly Permission ManageTags = new Permission { Description = "Manage tags", Name = "ManageTags" };
|
public static readonly Permission ManageTags = new Permission { Description = "Manage tags", Name = "ManageTags" };
|
||||||
public static readonly Permission CreateTag = new Permission { Description = "Create tag", Name = "CreateTag", ImpliedBy = new[] { ManageTags } };
|
|
||||||
public static readonly Permission ApplyTag = new Permission { Description = "Applying a Tag", Name = "ApplyTag", ImpliedBy = new[] { ManageTags, CreateTag } };
|
|
||||||
|
|
||||||
public virtual Feature Feature { get; set; }
|
public virtual Feature Feature { get; set; }
|
||||||
|
|
||||||
public IEnumerable<Permission> GetPermissions() {
|
public IEnumerable<Permission> GetPermissions() {
|
||||||
return new[] {
|
return new[] {
|
||||||
ManageTags,
|
ManageTags,
|
||||||
CreateTag,
|
|
||||||
ApplyTag,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,11 +30,9 @@ namespace Orchard.Tags {
|
|||||||
},
|
},
|
||||||
new PermissionStereotype {
|
new PermissionStereotype {
|
||||||
Name = "Author",
|
Name = "Author",
|
||||||
Permissions = new[] {CreateTag, ApplyTag}
|
|
||||||
},
|
},
|
||||||
new PermissionStereotype {
|
new PermissionStereotype {
|
||||||
Name = "Contributor",
|
Name = "Contributor",
|
||||||
Permissions = new[] {ApplyTag}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,6 @@ namespace Orchard.Tags.Services {
|
|||||||
public TagRecord CreateTag(string tagName) {
|
public TagRecord CreateTag(string tagName) {
|
||||||
var result = _tagRepository.Get(x => x.TagName == tagName);
|
var result = _tagRepository.Get(x => x.TagName == tagName);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
_authorizationService.CheckAccess(Permissions.CreateTag, _orchardServices.WorkContext.CurrentUser, null);
|
|
||||||
result = new TagRecord { TagName = tagName };
|
result = new TagRecord { TagName = tagName };
|
||||||
_tagRepository.Create(result);
|
_tagRepository.Create(result);
|
||||||
}
|
}
|
||||||
@@ -151,14 +150,12 @@ namespace Orchard.Tags.Services {
|
|||||||
if (contentItem.Id == 0)
|
if (contentItem.Id == 0)
|
||||||
throw new OrchardException(T("Error adding tag to content item: the content item has not been created yet."));
|
throw new OrchardException(T("Error adding tag to content item: the content item has not been created yet."));
|
||||||
|
|
||||||
var tags = tagNamesForContentItem.Select(name => CreateTag(name));
|
var tags = tagNamesForContentItem.Select(CreateTag);
|
||||||
var newTagsForContentItem = new List<TagRecord>(tags);
|
var newTagsForContentItem = new List<TagRecord>(tags);
|
||||||
var currentTagsForContentItem = _contentTagRepository.Fetch(x => x.TagsPartRecord.Id == contentItem.Id);
|
var currentTagsForContentItem = _contentTagRepository.Fetch(x => x.TagsPartRecord.Id == contentItem.Id);
|
||||||
|
|
||||||
foreach (var tagContentItem in currentTagsForContentItem) {
|
foreach (var tagContentItem in currentTagsForContentItem) {
|
||||||
if (!newTagsForContentItem.Contains(tagContentItem.TagRecord)) {
|
if (!newTagsForContentItem.Contains(tagContentItem.TagRecord)) {
|
||||||
_authorizationService.CheckAccess(Permissions.ApplyTag, _orchardServices.WorkContext.CurrentUser, null);
|
|
||||||
|
|
||||||
_contentTagRepository.Delete(tagContentItem);
|
_contentTagRepository.Delete(tagContentItem);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -167,8 +164,6 @@ namespace Orchard.Tags.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (var newTagForContentItem in newTagsForContentItem) {
|
foreach (var newTagForContentItem in newTagsForContentItem) {
|
||||||
_authorizationService.CheckAccess(Permissions.ApplyTag, _orchardServices.WorkContext.CurrentUser, null);
|
|
||||||
|
|
||||||
_contentTagRepository.Create(new ContentTagRecord { TagsPartRecord = contentItem.As<TagsPart>().Record, TagRecord = newTagForContentItem });
|
_contentTagRepository.Create(new ContentTagRecord { TagsPartRecord = contentItem.As<TagsPart>().Record, TagRecord = newTagForContentItem });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -141,7 +141,6 @@ namespace Orchard.Tags.Services {
|
|||||||
|
|
||||||
private void MetaWeblogUpdateTags(int contentItemId, string appKey, string userName, string password, XRpcStruct content, bool publish, ICollection<IXmlRpcDriver> drivers) {
|
private void MetaWeblogUpdateTags(int contentItemId, string appKey, string userName, string password, XRpcStruct content, bool publish, ICollection<IXmlRpcDriver> drivers) {
|
||||||
var user = _membershipService.ValidateUser(userName, password);
|
var user = _membershipService.ValidateUser(userName, password);
|
||||||
_authorizationService.CheckAccess(Permissions.ApplyTag, user, null);
|
|
||||||
|
|
||||||
var rawTags = content.Optional<string>("mt_keywords");
|
var rawTags = content.Optional<string>("mt_keywords");
|
||||||
if (string.IsNullOrWhiteSpace(rawTags))
|
if (string.IsNullOrWhiteSpace(rawTags))
|
||||||
|
Reference in New Issue
Block a user