extools.ui.field_security

Field Security UIs

UIs for implementing additional security at the field level.

Use the extools.ui.field_security.permissions_callback_for_table() together with the extools.ui.field_security.FieldSecurityCallbackUI to quickly apply permissions to pretty much any field on a Sage screen.

# AP1200
# Add permissions to AP Vendor Tax Number field

MY_PERMISSIONS_TABLE = "MYMODULE.MYPERMS"
'''Table format
| USER | CANREAD | CANWRITE |'''

# The tax number field control name from accpacUIInfo
TAX_NUM_CONTROL = "afecAPVENtaxnbr"
# The tab control name
TAB_CONTROL = "SSTab1"
# The id of the "Invoicing" tab, which has the field.
TAB_ID = 1

def main(*args, **kwargs):
    callback = permissions_callback_for_table(
            MY_PERMISSIONS_TABLE, "USER", "CANREAD", "CANWRITE")
    ui = FieldSecurityCallbackUI(
            TAX_NUM_CONTROL, callback, TAB_CONTROL, TAB_ID)
class extools.ui.field_security.FieldSecurityCallbackUI(control, callback, tab_control='', tab_id=None, ds_name='')[source]

Bases: object

Apply custom permissions to a specific on-screen field.

Parameters:
  • control (str) – name of the on-screen control.
  • callback (func) – callback function to check perms. receives (user, control, ds). callback must return (bool(can_read), bool(can_write)).
  • tab_control (str) – name of the tab control (if applicable).
  • tab_id (str) – tab id on which the field appears (if applicable).
  • ds_name (str) – name of a ds (i.e. adsOEORDH) to open and pass to callback.
onControlInfo(info)[source]
onTabClick(tab)[source]

On tab change hide or show field based on callback.

extools.ui.field_security.permissions_callback_for_table(view, user_field, read_field, write_field)[source]

Generate a callback that checks a user’s permissions in a view.

Best used with the FieldSecurityCallbackUI, it will check a table containing permissions and return a simple (read, write) pair suitable for use as a callback.

Parameters:
  • view (str) – the view to read from, built-in (OE0520) or custom (MOD.TABLE)
  • user_field (str) – the username field in the view. must be a key or browseable field.
  • read_field (str) – the read permission field name - must be bool.
  • write_field (str) – the write permission field name - must be bool.
Returns:

func