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

5

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

2个回答

7
据我所知,标准平台中没有这个功能。但是您可以手工制作自己的字段控件。因此,在自定义字段类型文件中。
<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"
  />

在您的 fieldcontrol 中。
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
    }
}

我同意自定义字段是正确的选择。非常好的例子! - Kirk Liemohn
我也是,而且示例非常清晰易懂! - Colin

0

您也可以通过注册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);
                            }
                    }
                }
            }
         }
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接