如何为只能访问一个分支的用户返回其他分支的数据? [英] How do I return data for other branches for a user with access to only one branch?
问题描述
我发现 Acumatica 的基本安装不包含记录库存项目的批准制造商/零件编号的能力非常奇怪,因此我将此功能添加到我的自定义项目中.该设计允许每个分支机构定义自己的批准制造商和零件编号,但我需要允许只能访问一个分支机构的用户查看其他分支机构批准的制造商.
I found it very odd that the base installation of Acumatica did not contain the ability to document approved Manufacturer/part number for Stock Items, so I added this functionality to my customization project. The design allows each branch to define their own approved manufacturers and part number, but I need to allow a user with access to only one branch to see the approved manufacturers from other branches.
我的 DAC 是 SSINManufacturer(制造商主)和 SSINItemManufacturer(库存项目的各个分支特定制造商零件编号记录).
My DAC's are SSINManufacturer (the manufacturer master) and SSINItemManufacturer (the individual branch specific manufacturer part number record for the Stock Item).
自定义已作为网格视图在库存项目下添加为新选项卡.分公司(跨系统)的访问控制通过分公司的用户角色进行处理,但我需要允许任何有权访问库存物品的用户查看任何分公司的所有制造商零件编号.
The customization was added as a new tab under Stocked Items as a grid view. Access control by branch (across the system) is handled via a user role for the branch, but I need allow any user with access to Stocked Items to see all manufacturer part numbers from any branch.
我在 AsiaBlog (https://asiablog.acumatica.com/2015/11/using-scopes-in-acumatica.html) 中提到使用 PXReadBranchRestrictedScope 来移除由系统核心自动应用的分支的限制,如果你有 BranchID所选 DAC 中的属性".有人建议我不要在我的自定义 DAC 中使用 BranchID,而是使用 UsrBranchID,但我怀疑这是我在此视图中仍然仅限于当前分支数据的根本原因.
I found a post in AsiaBlog (https://asiablog.acumatica.com/2015/11/using-scopes-in-acumatica.html) that mentions the use of PXReadBranchRestrictedScope to "remove restriction by branches that will be automatically applied by the system core, if you have BranchID attribute in the selected DAC". I was advised not to use BranchID, but rather UsrBranchID in my custom DAC's, but I suspect this is the underlying reason that I'm still restricted to just the current branch data in this view.
我刚刚开始学习使用构造函数来覆盖视图将生成的默认结果,我不确定这个定义是否正确.
I am just starting to learn to use a constructor to override the default results that a view would generate, and I'm not sure that this definition is correct.
public PXSelectJoin<SSINItemManufacturer,
InnerJoin<SSINManufacturer, On<SSINManufacturer.manufacturerID, Equal<SSINItemManufacturer.manufacturerID>>>,
Where<SSINItemManufacturer.inventoryID, Equal<Current<InventoryItem.inventoryID>>
>> ItemManufacturerXrefs;
public virtual IEnumerable itemmanufacturerxrefs()
{
using (new PXReadBranchRestrictedScope())
{
PXResult<SSINItemManufacturer> Results = PXSelectJoin<SSINItemManufacturer,
InnerJoin<SSINManufacturer, On<SSINManufacturer.manufacturerID, Equal<SSINItemManufacturer.manufacturerID>>>,
Where<SSINItemManufacturer.inventoryID, Equal<Current<InventoryItem.inventoryID>>
>>.Select(Base);
yield return Results;
}
}
构造函数是否正确定义以利用 PXReadBranchRestrictedScope?我是否需要将 BranchID 添加到我的 DAC 中才能返回租户中库存项目的所有记录?
Is the constructor defined correctly to leverage PXReadBranchRestrictedScope? And do I need to add BranchID to my DAC to make this return all records for the Stocked Item in the tenant?
推荐答案
发现两个问题解决了问题.首先,PXResultset 被定义为只返回 1 个值的 PXResult,后续返回结果的方法需要进行扩展,以更明确地构建要返回的结果.
Two issues found which resolved the problem. First, the PXResultset was defined as PXResult which returned only 1 value, and the subsequent method of returning the result needed to be expanded to more explicitly build the results to be returned.
public virtual IEnumerable itemmanufacturerxrefs()
{
using (new PXReadBranchRestrictedScope())
{
PXResultset<SSINItemManufacturer> Results = PXSelectJoin<SSINItemManufacturer,
InnerJoin<SSINManufacturer, On<SSINManufacturer.manufacturerID, Equal<SSINItemManufacturer.manufacturerID>>>,
Where<SSINItemManufacturer.inventoryID, Equal<Current<InventoryItem.inventoryID>>
>>.Select(Base);
foreach (PXResult<SSINItemManufacturer, SSINManufacturer> result in Results)
{
SSINItemManufacturer mfgitem = result;
SSINManufacturer mfg = result;
yield return new PXResult<SSINItemManufacturer, SSINManufacturer>(mfgitem, mfg);
}
}
}
其次,仔细查看 AsiaBlog 上的帖子后,需要将 BranchID(实际上是 Branch)的 ATTRIBUTE 添加到 DAC 字段中.UsrBranchID 适用于字段名称,前提是添加了 [Branch] 属性.
Secondly, upon closer review of the post on AsiaBlog, the BranchID (actually Branch) ATTRIBUTE needed to be added to the field of the DAC. UsrBranchID is fine for a field name, provided the [Branch] attribute was added.
#region UsrBranchID
[Branch(IsKey = true)]
[PXDefault(typeof(AccessInfo.branchID))]
[PXUIField(DisplayName = Messages.FldUsrBranchID)]
public virtual int? UsrBranchID { get; set; }
public abstract class usrBranchID : PX.Data.BQL.BqlInt.Field<usrBranchID> { }
#endregion
范围覆盖效果很好.在视图上使用构造函数使我能够按照广告"授予对所有分支数据的可见性.
The scope override works well. The use of the constructor on the view allows me to grant visibility to the data from all branches "as advertised".
这篇关于如何为只能访问一个分支的用户返回其他分支的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!