Page 1 of 1

IsCashSale

Posted: Tue May 05, 2020 2:06 pm
by tmeisinger
I want to make Order.IsCashSale Read Only but can't get this Module to fire? Help me please.

Code: Select all

from System import *
from SoftPro.ClientModel import *
from SoftPro.OrderTracking.Client import *
from SoftPro.OrderTracking.Client.Orders import *
from SoftPro.Select.Client.Security import *
from System.Collections.Generic import IEnumerable, List
from System.Linq import Enumerable
import clr
clr.ImportExtensions(Linq)

def Order_IsCashSale_ReadOnly(args):
	secMgr = args.GetService(ISecurityManager)
	userSecId = ISecurityManager.CurrentSecurityIdentityID.GetValue(secMgr)
	secUser = ISecurityManager.GetUser(secMgr, userSecId)
	groups = List[ISecurityIdentity](secUser.Groups)
	foundUser = Enumerable.Any(groups, lambda t: t.IsGroup and t.Name == 'Administrators')

	if not foundUser:
		args.Value = True

Re: IsCashSale

Posted: Tue May 05, 2020 2:16 pm
by tmeisinger
Not sure why, but the code is firing, it just wont break in Debug mode. I don't need to understand why...

Re: IsCashSale

Posted: Tue May 05, 2020 3:19 pm
by BobRichards
Glad it's working for you. Be aware that this method will make a call to the server then to the SQL database and can be costly in terms of the user experience resulting in slower order load times.

Code: Select all

secUser = ISecurityManager.GetUser(secMgr, userSecId)
Best practice is that you don't call server code in CORs. However if you can't avoid it, make sure order load time is still acceptable in your production environment.

Re: IsCashSale

Posted: Tue May 05, 2020 3:27 pm
by tmeisinger
Thanks for the advice, is there a better way to allow "someone" the ability to access a field that I'm going to make Read Only for the masses?