Gnumed.wxpython.gmAccessPermissionWidgets

Package Gnumed :: Package wxpython :: Module gmAccessPermissionWidgets |
[frames] | no frames]

# Source Code for Module Gnumed.wxpython.gmAccessPermissionWidgets

     1  """GNUmed access permissions/violations widgets."""
     2  #=========================================================================
     3  __author__  = "K. Hilbert <Karsten.Hilbert@gmx.net>"
     4  __license__ = "GPL v2 or later (details at http://www.gnu.org)"
     5
     6  import logging
     7  #import functools
     8
     9
    10  import wx
    11
    12
    13  from Gnumed.business import gmStaff
    14
    15  from Gnumed.wxpython import gmGuiHelpers
    16
    17
    18  _log = logging.getLogger('gm.perms')
    19
    20  #=========================================================================
    21  _known_roles = [
    22          'public access',
    23          'non-clinical access',
    24          'limited clinical access',              # currently not in use
    25          'full clinical access',
    26          'admin'                                         # currently not in use
    27  ]
    28
    29  _curr_staff = gmStaff.gmCurrentProvider()
    30
    31  #-------------------------------------------------------------------------
    32 -def verify_minimum_required_role(minimum_role, activity=None, return_value_on_failure=None, fail_silently=False):
    33
    34          if activity is None:
    35                  activity = _('generic activity')
    36
    37          #---------
    38          def _inner_verify_minimum_required_role(original_function):
    39
    40                  #---------
    41                  #@functools.wraps(original_function)
    42                  def _func_decorated_with_required_role_checking(*args, **kwargs):
    43                          if _known_roles.index(minimum_role) > _known_roles.index(_curr_staff['role']):
    44                                  _log.info('access denied: %s', activity)
    45                                  _log.debug('required role: %s', minimum_role)
    46                                  _log.debug('current role: %s (<%s>)', _curr_staff['l10n_role'], _curr_staff['role'])
    47                                  _log.debug('current user: %s (<%s>)', _curr_staff['short_alias'], _curr_staff['db_user'])
    48                                  wx.EndBusyCursor()
    49                                  if fail_silently:
    50                                          return return_value_on_failure
    51                                  gmGuiHelpers.gm_show_error (
    52                                          aTitle = _('Access denied'),
    53                                          aMessage = _(
    54                                                  'Your account is not set up to access this part of GNUmed:\n'
    55                                                  '\n'
    56                                                  '  [%s]'
    57                                          ) % activity
    58                                  )
    59                                  return return_value_on_failure
    60                          return original_function(*args, **kwargs)
    61                  #---------
    62
    63                  return _func_decorated_with_required_role_checking
    64          #---------
    65
    66          return _inner_verify_minimum_required_role
    67
    68  #=========================================================================
    69