当对库中至少有一个没有权限时,不显示Sharepoint模式窗口

时间:2018-01-18 08:13:24

标签: sharepoint permissions modal-dialog sharepoint-2013

我有一个sharepoint 2013服务器场解决方案,项目已添加(同步触发),当用户上传文件时:权限被破坏,删除并再次添加。

共有3组:可见,编辑和隐藏。 当文件被添加为编辑或可见组时,一切正常,权限被破坏,为可见和编辑添加和模态窗口输入必填字段显示。但是当添加为无法查看机密文件的隐藏组时,会添加权限(可见,编辑,隐藏),但会添加文件并且不再显示模态。当我删除任何组的权限时,我可以重新创建这种行为。

我认为它是共享点默认行为,但我已经在标准库上重新创建了这个sittuation,并使用UI设置了相同的权限,并且正常显示模态。

活动代码:

  public override void ItemAdded(SPItemEventProperties properties)
    {
        base.ItemAdded(properties);

        var confidentialField = properties.List.Fields.TryGetFieldByStaticName(Consts.ConfidentialColumnName);
        var confidentialVisibleGroup = getGroup(properties.List, confidentialField, Consts.ConfidentialVisibleGroupName);
        var confidentialHiddenGroup = getGroup(properties.List, confidentialField, Consts.ConfidentialHiddenGroupName);
        var confidentialEditGroup = getGroup(properties.List, confidentialField, Consts.ConfidentialEditGroupName);

        using (var scope = new DisabledItemEventsScope())
        {
            properties.ListItem.File.CheckIn("test"); //need to check in the file because it won't exist when getting it with ID in elevated. it is checked out by default
            SPSecurity.RunWithElevatedPrivileges(delegate ()
            {

                setPermissions(properties, confidentialVisibleGroup, confidentialHiddenGroup, confidentialEditGroup,
                    confidentialField.InternalName);


            });
            properties.ListItem.File.CheckOut(); // no matter if the file is checked out or not modal not shown
        }
    }

    private static void setPermissions(SPItemEventProperties properties, SPGroup confidentialVisibleGroup,
        SPGroup confidentialHiddenGroup, SPGroup confidentialEditGroup, string confidentialFieldInternalName)
    {
        try
        {
            using (var site = new SPSite(properties.SiteId))
            {
                using (var web = site.OpenWeb(properties.RelativeWebUrl))
                {
                    web.AllowUnsafeUpdates = true;

                    var list = web.Lists[properties.List.ID];
                    var listItem = list.GetItemById(properties.ListItemId);
                    listItem.BreakRoleInheritance(false);

                    //add 2 permission groups
                    var roleAssignment = new SPRoleAssignment(confidentialEditGroup);
                    roleAssignment.RoleDefinitionBindings.Add(
                        properties.Web.RoleDefinitions.GetByType(SPRoleType.Contributor));
                    listItem.RoleAssignments.Add(roleAssignment);

                    roleAssignment = new SPRoleAssignment(confidentialVisibleGroup);
                    roleAssignment.RoleDefinitionBindings.Add(
                        properties.Web.RoleDefinitions.GetByType(SPRoleType.Contributor));
                    listItem.RoleAssignments.Add(roleAssignment);

                    //add hidden group with no permissions to all files on library
                    roleAssignment = new SPRoleAssignment(confidentialHiddenGroup);
                        roleAssignment.RoleDefinitionBindings.Add(
                            properties.Web.RoleDefinitions.GetByType(SPRoleType.Contributor));
                        listItem.RoleAssignments.Add(roleAssignment);

                    listItem.SystemUpdate();
                }
            }
        }
        catch (Exception e)
        {
            Logger.GetLogger().WriteLog("Exception while setting permissions to confidential item", e);
        }
    }

0 个答案:

没有答案