Page 1 of 1

GetAbstractPermission in business logic

PostPosted: Mon Apr 01, 2019 11:10 am
by pricerc
In a UI plugin, I can
Code: Select all
accessLevel = salesOrderForm.GetAbstractPermission("sales order - email invoices")


How would I achieve similar, but in business logic?

e.g. I'd like to (but can't):
Code: Select all
accessLevel = salesOrder.GetAbstractPermission("sales order - email invoices")

Re: GetAbstractPermission in business logic

PostPosted: Mon Apr 01, 2019 12:02 pm
by Mike.Sheen
pricerc wrote:e.g. I'd like to (but can't):
Code: Select all
accessLevel = salesOrder.GetAbstractPermission("sales order - email invoices")


Hi Ryan,

The GetAbstractPermission of the form is simply a convenience wrapper around Manager.Staff.GetAbstractPermission - so you want:

Code: Select all
accessLevel = salesOrder.Manager.Staff.GetAbstractPermission("sales order - email invoices")


Mike

Re: GetAbstractPermission in business logic

PostPosted: Mon Apr 01, 2019 12:26 pm
by pricerc
That one has a className parameter as well as an AbstractPermissionName parameter?

(from Object Browser):
Public Function GetAbstractPermission(ClassName As String, AbstractPermissionName As String) As JiwaFinancials.Jiwa.JiwaApplication.Security.UserGroup.AccessLevels
Member of JiwaFinancials.Jiwa.JiwaApplication.JiwaStaff.clsStaff

Re: GetAbstractPermission in business logic  Topic is solved

PostPosted: Mon Apr 01, 2019 12:30 pm
by Mike.Sheen
pricerc wrote:That one has a className parameter as well as an AbstractPermissionName parameter?

(from Object Browser):
Public Function GetAbstractPermission(ClassName As String, AbstractPermissionName As String) As JiwaFinancials.Jiwa.JiwaApplication.Security.UserGroup.AccessLevels
Member of JiwaFinancials.Jiwa.JiwaApplication.JiwaStaff.clsStaff


Ahh - yes I forgot about that.

The ClassName is the class type for the FORM associated with the business logic. You'll find those in the SY_Forms table - but for sales orders it's either "JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm" or "JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.CreditNoteForm" (different permissions for credit notes).

Mike

EDIT: For completeness, the code is:

Code: Select all
accessLevel = salesOrder.Manager.Staff.GetAbstractPermission("JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm", "sales order - email invoices")


EDIT #2:
And you can obtain the ClassName from the business logic itself, without having to inspect the SY_Forms table - use the ClientClassName property of the business logic:

So a more technically correct way:
Code: Select all
accessLevel = salesOrder.Manager.Staff.GetAbstractPermission(salesOrder.ClientClassName, "sales order - email invoices")

Re: GetAbstractPermission in business logic

PostPosted: Mon Apr 01, 2019 3:46 pm
by pricerc
Mike.Sheen wrote:So a more technically correct way:
Code: Select all
accessLevel = salesOrder.Manager.Staff.GetAbstractPermission(salesOrder.ClientClassName, "sales order - email invoices")


I'm glad I spent so much time responding to your anti-VB propaganda... :P (otherwise I would have used your less elegant version already)

I was going to suggest that maybe helper functions on the business objects would be something worth adding. This is pretty good though; makes a nice one-line extension method in my SalesOrder library :):

Code: Select all
       
<Extension()>
        Public Function GetAbstractPermission(salesOrder As SalesOrder, AbstractPermissionName As String) As AccessLevels
            Return salesOrder.Manager.Staff.GetAbstractPermission(salesOrder.ClientClassName, AbstractPermissionName)
        End Function