I'm setting up a BusinessBase object and adding authorization to it. If I use this code in a property:
CanWriteProperty(true);
the authorization works as expected. But, if I use this:
CanWriteProperty("ResearchAnalystId");my authorization always passes, whether or not I'm part of a group that has authorization. For referrence, the line from AddAuthorizationRules() is:
AuthorizationRules.AllowWrite("ResearchAnalystId", "Administrator");My main reason for wanting to call this method with a literal is to check authorization from the UI to control display of fields (label vs. dropdown). What am I doing wrong? Is there another way to do this?
Thanks, Brian. I was definitely missing that in the property code. That works fine, now.
I'm still not getting the correct Boolean return from the CanWriteProperty method, though. It always returns true, which is a problem from the UI. I don't think using a try...catch block is probably the best way to toggle UI elements.
So in the same scenario if you tell CanWriteProperty() to throw exceptions it throws, but if you tell it not to throw exceptions it returns true?
While there's always the possibility for bugs, I am a little skeptical here, because I use the ReadWriteAuthorization control all the time and it uses the boolean return technique to enable/disable the UI elements - it calls the same code you'd be calling.
That, by the way, is what I recommend, and what I show in Chapters 9 and 10 for the Windows and Web UI's - how to have the UI proactively find out what the user can and can't do so it can enable/disable the controls ahead of time.
Copyright (c) Marimer LLC