代码之家  ›  专栏  ›  技术社区  ›  kyrisu

如何在SharePoint列表中管理基于列的访问控制?

  •  5
  • kyrisu  · 技术社区  · 16 年前

    我正在创建基于SharePoint的问题跟踪门户。用户应该能够添加条目,但在条目本身中,我希望只有一列对特定的用户组(管理员)可见。有没有方法设置基于列的访问控制?

    2 回复  |  直到 12 年前
        1
  •  7
  •   Johan Leino    16 年前

    据我所知,这在标准平台中不可用。另一方面,你能做的就是手工制作你自己的现场控制系统。

    所以在custom fieldtypes.xml中

    <FieldTypes>
    
      <FieldType>
        <Field Name="TypeName">MyInteger</Field>
        <Field Name="ParentType">Integer</Field>
        ...
        <Field Name="FieldTypeClass">xxx</Field>
      </FieldType>
    

    以及在sitecolumns.xml中

      <Field ID="xxx"
          Name="xxx"
          DisplayName="xxx
          Description="xxx"
          Group="xxx
          Type="MyInteger"    
          DisplaceOnUpgrade="TRUE"
      />
    

    在你的现场控制中

    public class MyInteger: SPFieldNumber
    {
        public MyInteger(SPFieldCollection fields, string fieldName)
            : base(fields, fieldName)
        {
        }
    
        public MyInteger(SPFieldCollection fields, string typeName, string displayName)
            : base(fields, typeName, displayName)
        {
        }
    
    
        public override BaseFieldControl FieldRenderingControl
        {
            [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
            get
            {
                Microsoft.SharePoint.WebControls.BaseFieldControl ctl = 
                   new MyIntegerControl();
                ctl.FieldName = InternalName;
                return ctl;
    
            }
        }
    
        }
    

    在MyIntegerControl中,您可以做任何您想做的事情(很多覆盖),但是一个例子是:

    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        if (this.ControlMode == SPControlMode.New || 
            this.ControlMode == SPControlMode.Display)
        {
          // check that use is admin and display value
        }
    }
    
        2
  •  0
  •   Raymond    12 年前

    您还可以通过注册一个customAction,并更改列表视图架构动态来实现这一点。

         <CustomAction Id="CustomAction"
              GroupId="SiteActions"
              Location="Microsoft.SharePoint.StandardMenu"
              Sequence="1003"
              ControlAssembly="$SharePoint.Project.AssemblyFullName$"
           ControlClass="CustomAction.ColumnPermissionAction"/>
    

    在你的控制课上:

    class ColumnPermissionAction : Control
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            HideColumn();
        }
    
        private HideColumn(){
             WebPart part=//find your web part
             string colName="SecretColumn";
             if(part is ListViewWebPart){
                (part as ListViewWebPart).ListViewXml = (part as ListViewWebPart).ListViewXml.Replace(string.Format("<FieldRef Name=\"{0}\"/>", colName), string.Empty);
             }else if(part is XsltListViewWebPart){
                PropertyInfo property = typeof(DataFormWebPart).GetProperty("ListViewXmlDom", BindingFlags.NonPublic | BindingFlags.Instance);
                if (property != null)
                {
                    XmlNode xmlView = property.GetValue(part as XsltListViewWebPart, null) as XmlNode;
                    if (xmlView != null)
                    {
                        XmlNode node = xmlView.SelectSingleNode("//ViewFields");
                        if (node != null)
                        {
                                var field = node.SelectSingleNode(string.Format("FieldRef[@Name='{0}']", colName));
                                if (field != null)
                                {
                                    node.RemoveChild(field);
                                }
                        }
                    }
                }
             }
        }
    }