尝试隐藏内容类型的内容部分 [英] Trying to hide Content Parts on Content Type

查看:95
本文介绍了尝试隐藏内容类型的内容部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建内容类型并添加特定于客户和律师的内容部分.所有这些部分都有字段和/或内容选择器等.

I am building Content Types and adding Content Parts specific to a Client and Attorney. All of these parts have fields and/or content pickers, etc.

我希望将客户角色"限制为仅查看客户内容部分",而我仅允许律师角色"查看任何内容部分",包括针对特定内容类型的其自己的律师内容部分".同样,这些都在相同的内容类型上,因此内容权限"将不起作用(通常在内容类型"上除外).

I want to restrict the Client Role to see only Client Content Parts, while I just allow the Attorney Role to see any Content Parts, including it's own Attorney Content Part for a particular Content Type. Again, these are all on the same Content Type, so Content Permissions will not work (except on the Content Type in general).

我要在客户端登录时隐藏律师内容部分.

I want to hide the Attorney Content Parts when a Client is logged on.

我尝试使用此功能:

public override void Displaying(ShapeDisplayingContext context)
    {
    context.ShapeMetadata.OnDisplaying(displayedContext => {
        var shape = context.Shape;

        if (context.Shape.Part.Name == "Parts_AttorneyMatterPart")
        {
            var workContext = _workContextAccessor.GetContext();
            var user = workContext.CurrentUser;
            var roles = user.As<UserRolesPart>().Roles;

            if (!roles.Contains("Spaces Attorney"))
            {
                shape = null;
            }
        }
        });
    }

我有一个名为"AttorneyMatterPart"的内容部分,而律师角色是"Spaces Attorney".

Where I have a Content Part named "AttorneyMatterPart", and where the Attorney Role is "Spaces Attorney".

这些内容类型和零件都是在Orchard Admin中创建的.我的模块中唯一的东西是此类文件.

These Content Types and Parts were all created in the Orchard Admin. The only thing in my module is this class file.

但是,当客户端登录时,这不会隐藏内容部分.我知道我必须研究哪些角色可以看到事物的逻辑(打算为Admin添加||条件,等等).现在,我只是对此进行测试.

But this won't hide the Content Part when the Client is logged in. I know that I have to work on the logic of what roles can see things (going to add || conditions for Admin, etc.). For now I am just testing this out.

感谢您的帮助.

编辑(增加了赏金) 我真的为是否有可能感到困惑.该内容部分是通过管理界面创建的.在形状跟踪下,我可以在内容"区域的模型">"ContentItem">"AttorneyMatterPart"下看到.我已经尝试过ShapeTableBuilder,并且已经尝试过ShapeDisplayingContext中的OnDisplayingOnDisplayed.

EDIT (Bounty Added) I am really stumped as to whether or not this is even possible. This Content Part is created through the Admin UI. Under shape tracing I can see under the "Content" zone Model > ContentItem > AttorneyMatterPart. I have tried ShapeTableBuilder and I have tried OnDisplaying and OnDisplayed from a ShapeDisplayingContext.

如果有人可以提供工作样品,将不胜感激.

If someone could provide a working sample it would be much appreciated.

推荐答案

通过管理仪表板创建内容部件时,实际上并没有要呈现的形状,只有内部内容字段的各个形状...

When a content part is created through the admin dashboard, there isn't really a shape to render it, only individual shapes for inner content fields...

所以,尝试这个

public override void Displaying(ShapeDisplayingContext context) {
  context.ShapeMetadata.OnDisplaying(displayedContext => {
    var shape = displayedContext.Shape;

    if (shape.ContentPart != null
      && shape.ContentPart.PartDefinition.Name == "PartName") {
      var workContext = _workContextAccessor.GetContext();
      var user = workContext.CurrentUser;

      if (user == null || !user.Has<UserRolesPart>()
        || !user.As<UserRolesPart>().Roles.Contains("RoleName")) {
        displayedContext.ChildContent = new System.Web.HtmlString("");
      }
    }
  });
}

在OrchardPros上查看我的答案

See my answer on OrchardPros

http://orchardpros.net/tickets/6914

最佳

这篇关于尝试隐藏内容类型的内容部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆