Orchard CMS前端按用户权限过滤所有可能的内容



美好的一天!

在我的果园中,我有几种内容类型,所有内容类型都附加了我的自定义部件。此部分定义此内容可供哪些用户使用。对于每个登录的用户,都有外部服务,该服务定义了用户可以或不能访问的内容。现在,我需要访问限制以应用于果园显示内容列表的任何位置,这包括标记云中特定标记的结果,或分类术语中列出的结果。除了修改分类服务代码以及 TagCloud 服务之外,我似乎找不到任何好的方法,也加入我的部分并按它过滤。这确实是唯一的方法还是有其他解决方案?如果可能的话,我想避免对内置模块进行更改,但找不到其他方法。

提前谢谢。

我目前正在为同样的问题而笨拙。我目前正在考虑的一种方法是挂钩到内容管理器。

[OrchardSuppressDependency("Orchard.ContentManagement.DefaultContentManager")]
    public class ModContentManager : DefaultContentManager, IContentManager
    {
        //private readonly Lazy<IShapeFactory> _shapeFactory;
        private readonly IModAuthContext _modAuthContext;
        public ModContentManager(IComponentContext context,
            IRepository<ContentTypeRecord> contentTypeRepository,
            IRepository<ContentItemRecord> contentItemRepository,
            IRepository<ContentItemVersionRecord> contentItemVersionRepository,
            IContentDefinitionManager contentDefinitionManager,
            ICacheManager cacheManager,
            Func<IContentManagerSession> contentManagerSession,
            Lazy<IContentDisplay> contentDisplay,
            Lazy<ISessionLocator> sessionLocator,
            Lazy<IEnumerable<IContentHandler>> handlers,
            Lazy<IEnumerable<IIdentityResolverSelector>> identityResolverSelectors,
            Lazy<IEnumerable<ISqlStatementProvider>> sqlStatementProviders,
            ShellSettings shellSettings,
            ISignals signals,
            //Lazy<IShapeFactory> shapeFactory, 
            IModAuthContext modAuthContext)
            : base(context,
                contentTypeRepository,
                contentItemRepository,
                contentItemVersionRepository,
                contentDefinitionManager,
                cacheManager,
                contentManagerSession,
                contentDisplay,
                sessionLocator,
                handlers,
                identityResolverSelectors,
                sqlStatementProviders,
                shellSettings,
                signals) {
            //_shapeFactory = shapeFactory;
            _modAuthContext = modAuthContext;
        }
        public new dynamic BuildDisplay(IContent content, string displayType = "", string groupId = "") {
            // So you could do something like... 
            // var myPart = content.As<MyAuthoPart>();
            // if(!myPart.IsUserAuthorized)...
            // then display something else or display nothing (I think returning null works for this but 
            //don't quote me on that. Can always return a random empty shape)
            // else return base.BuildDisplay(content, displayType, groupId);
            // ever want to display a shape based on the name...
            //dynamic shapes = _shapeFactory.Value;
        }
    }
}

还可以挂接到IAuthorizationServiceEventHandler,该处理程序之前在主ItemController中激活,并执行检查以查看您是否正在渲染投影或分类列表设置一个值以告诉您的内容管理器执行检查,否则只需让他们通过。可能对:)有所帮助

最新更新