工作流中任务权限控制问题

[关键字]: sharepoint Designer 2007, taks,list,Asigned to,permission

[问题描述] 最近有客户问到一个问题,用SharePoint Designer 2007做的一个批准的工作流,发现只要有权限的用户都可以去执行分配(Assign to)给别人的任务,按理说应该是每个人只对分配给自己的任务有修改的权限,对别人的只有读的权限。

[研究过程]

1.对Sharepoint server 2007自带的"approval"模板 和 用sharepoint Designer 2007 做的approve测试,发现创建的任务都没有提供修改权限的接口。

2.想到是否可以针对“Task”这个列表再绑定一个工作流,每当批准的那个工作流产生一个任务到这个"Task"列表中,就自动启动这个工作流来修改任务的权限属性。但是经测试发现不行,原因是由于sharepoint 2007产生的任务虽然放在“Task”这个列表中,但是他不是一个listitem类,细心的话,你会在"site content types"里发现它的Parent是workflow task,而不是item.我们知道workflow 只能绑定在document和list item 上的。

3.再试着使用"create list item"这个操作代替"assign to-do item",这样就可以把上一个方法中提到的工作流用上了,但是发现"create list item" 是一个列表操作,用它创建一个item来表示一个任务的话,不能使工作流保持状态等待这个任务结束后再往下执行。

所以通过种种测试,结论是,不能通过再创工作流的办法来对task这个任务列表进行权限修改。

[解决方案]  最终我们只能回到使用"EventHandler"上来解决这个问题。

代码如下

None.gif using  System;
None.gif
using  System.Collections.Generic;
None.gif
using  System.Text;
None.gif
using  Microsoft.SharePoint;
None.gif
namespace  ItemAddedEventHandler
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public class ItemAddedPermissionControl : SPItemEventReceiver
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public override void ItemAdded (SPItemEventProperties properties)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//run the default event handlers on the item
InBlock.gif
            base.ItemAdded(properties);
InBlock.gif                       
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                    
using (SPSite site = new SPSite(properties.SiteId))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
using (SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif                            
//call the function that changes the permissions on the list item. 
InBlock.gif                            
//Do not use properties.ListItem since that will break impersonation!
InBlock.gif
                            SetOwnerAsOnlyEditor(web.Lists[properties.ListId].GetItemById(properties.ListItemId));
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

InBlock.gif                
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif             
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void SetOwnerAsOnlyEditor(SPListItem item)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            SPWeb myweb1 
= item.Web;
InBlock.gif                        
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**/////get the task owner from the item. 'Assigned To' is a built-in property, so it should be in all lists.
InBlock.gif            string authorValue = item["Assigned To"].ToString();
InBlock.gif
InBlock.gif            SPFieldUserValue authorUserValue 
= new SPFieldUserValue(myweb1, authorValue);
InBlock.gif
InBlock.gif            SPUser authorUser 
= authorUserValue.User;
InBlock.gif
InBlock.gif            
//break the security of the item from the list, but keep the permissions
InBlock.gif

InBlock.gif            item.BreakRoleInheritance(
true);
InBlock.gif
InBlock.gif            SPRoleAssignment roleassignment 
= new SPRoleAssignment(authorUser.LoginName, authorUser.Email, authorUser.Name, authorUser.Name);
InBlock.gif            roleassignment.RoleDefinitionBindings.Add(myweb1.RoleDefinitions[
"Contribute"]);
InBlock.gif
InBlock.gif
InBlock.gif            
foreach (SPRoleAssignment roleAssignment in item.RoleAssignments)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//delete the existing permissions
InBlock.gif
                roleAssignment.RoleDefinitionBindings.RemoveAll();
InBlock.gif                
//add the reader permission
InBlock.gif
InBlock.gif                
//change the permissions of everyone with access to this item so they are readers only
InBlock.gif
                roleAssignment.RoleDefinitionBindings.Add(myweb1.RoleDefinitions["Read"]);
InBlock.gif                roleAssignment.Update();
InBlock.gif                
//  item.Update();
InBlock.gif

ExpandedSubBlockEnd.gif            }

InBlock.gif            item.RoleAssignments.Add(roleassignment);
InBlock.gif            item.Update();
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

 

《如果你想知道如何一步步创建一个Event Handler Feature,请参见http://msdn2.microsoft.com/en-us/library/ms453149.aspx

[后记] 除了使用EventHandler之外,我们也可以尝试使用自定义的custome acticity 来做。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值