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

时间:2009-06-15 17:56:48

标签: sharepoint

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

2 个答案:

答案 0 :(得分:7)

据我所知,标准平台不提供此功能。另一方面,你可以做的是手工制作你自己的fieldcontrol

所以在自定义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"
  />

并在你的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
    }
}

答案 1 :(得分: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);
                            }
                    }
                }
            }
         }
    }
}