【分享】二开插件代码怎么控制功能权限,数据范围权限
金蝶云社区-宇
11人赞赏了该文章 5,822次浏览 未经作者许可,禁止转载编辑于2016年08月26日 16:17:49
summary-icon摘要由AI智能服务提供

文本讨论了在一个基于Windows CE操作系统的PDA条码项目中,如何通过调用K3Cloud的WEBApi接口获取用户权限的问题。文本提供了五个具体问题的代码实现方法:1)检查用户是否有采购订单的审核权限;2)获取当前用户有权访问的仓库列表;3)获取报表中客户基础资料的查看权限范围;4)列出当前用户的组织;5)检查用户是否有查看采购订单单价字段的权限。每个问题都通过调用Kingdee.BOS相关的DLL文件中的类和方法实现权限验证和数据过滤。

业务背景:有个条码项目,客户端是PDA,操作系统是WindowsCE,程序由第三方开发,调用K3Cloud的WEBApi接口,WEBApi接口需要识别用户有哪些组织权限?有哪些基础资料权限(比如可以方位哪些仓库)?有哪些业务单据操作权限?请教老师如何在插件里面获得这些权限,谢谢
引用工程
Kingdee.BOS.dll
Kingdee.BOS.Core.dll
Kingdee.BOS.DataEntity.dll
Kingdee.BOS.ServiceHelper.dll

问题1:判断当前用户是否拥有采购订单的审核权限?[code] //检测当前用户是否有采购订单的审核权限
Kingdee.BOS.Core.Permission.BusinessObject permissionForm = new Kingdee.BOS.Core.Permission.BusinessObject()
{
Id = "PUR_PurchaseOrder", //采购订单单据d
PermissionControl = businessInfo.GetForm().SupportPermissionControl //是否权限控制
};

//如果要检查其它的操作权限,需要更改strPerItemId参数
var authResult = PermissionServiceHelper.FuncPermissionAuth(this.View.Context, permissionForm, Kingdee.BOS.Core.Permission.PermissionConst.Audit);
if (authResult.Passed == false)
{
//没有采购订单的审核权限
this.View.ShowErrMessage("你没有审核的权限,请联系系统管理员!");
return;
}
else
{
//有采购订单的审核权限
}[/code]

问题2:当前用户能看到哪些仓库?(只能查到当前用户有权限的仓库)

[code] string formId = "BD_STOCK";//仓库单据ID
Kingdee.BOS.Core.Metadata.FormMetadata stockFormMetaData = MetaDataServiceHelper.GetFormMetaData(this.View.Context, formId);
DataRuleFilterParamenter filterParameter = new DataRuleFilterParamenter(formId)
{
PermissionItemId = Kingdee.BOS.Core.Permission.PermissionConst.View,
SubSystemId = stockFormMetaData.BusinessInfo.GetForm().SubsysId,
BusinessInfo = stockFormMetaData.BusinessInfo
};

DataRuleFilterObject filterObject = PermissionServiceHelper.LoadDataRuleFilter(this.View.Context, filterParameter);//获取当前用户可以访问哪些仓库(过滤条件)
Kingdee.BOS.Core.SqlBuilder.QueryBuilderParemeter queryParameter = new Kingdee.BOS.Core.SqlBuilder.QueryBuilderParemeter
{
FormId = formId,
BusinessInfo = stockFormMetaData.BusinessInfo,
PermissionItemId = Kingdee.BOS.Core.Permission.PermissionConst.View,
FilterClauseWihtKey = filterObject.FilterString,//过滤条件
};

Kingdee.BOS.Orm.DataEntity.DynamicObject[] stockObjects = BusinessDataServiceHelper.Load(this.View.Context, stockFormMetaData.BusinessInfo.GetDynamicObjectType(), queryParameter);[/code]

问题3:怎么获取报表的基础资料权限
[code] //获取到期债务表报表中客户的基础资料范围权限
string formId = "BD_Customer";//客户单据ID
Kingdee.BOS.Core.Metadata.FormMetadata formMetaData = MetaDataServiceHelper.GetFormMetaData(this.View.Context, formId);
DataRuleFilterParamenter filterParameter = new DataRuleFilterParamenter(formId)
{
PermissionItemId = Kingdee.BOS.Core.Permission.PermissionConst.View,//查看权限项
SubSystemId = formMetaData.BusinessInfo.GetForm().SubsysId,
BusinessInfo = formMetaData.BusinessInfo,
IsLookUp=true,//是否基础资料权限
ParentFormId = "AP_MaturedDebt"//到期债务表报表ID
};

DataRuleFilterObject filterObject = PermissionServiceHelper.LoadDataRuleFilter(this.View.Context, filterParameter);//获取权限过滤条件
string filter = filterObject.FilterString;[/code]

问题4:当前用户有哪些组织?

[code] //获取当前登陆用户的用户组织关系
List orgs = PermissionServiceHelper.GetUserOrg(this.View.Context);[/code]
问题5:当前用户有采购订单的单价字段查看权限?

在字段授权里把采购订单的单价字段查看权限设置为拒绝,则结果为false
[code] //验证用户是否能查看采购订单的价格字段
string formId = "PUR_PurchaseOrder";//采购订单的单据ID
string fieldId = "FPrice";//价格字段Id
var businessInfo = MetaDataServiceHelper.GetFormMetaData(this.View.Context, formId).BusinessInfo;
BusinessObject permissonObject = new BusinessObject()
{
PermissionControl = businessInfo.GetForm().SupportPermissionControl,
Id = formId
};

List authResult = PermissionServiceHelper.GetAllowFieldList(this.View.Context, permissonObject, FieldInv.View);
bool isAllow = authResult.Any(f => f.FieldAllow(fieldId));
if (isAllow)
{
//有权限查看
}
else
{
//没有权限查看
}[/code]