web.navigator.navigator

Package web :: Package navigator :: Module navigator |
[hide private]
[frames] | no frames]

# Source Code for Module web.navigator.navigator

     1  import web
     2  from main.model import Computer, OrganizativeUnit
     3  from user.model import User
     4  from user import login
     5  from decorators import i18n
     6
     7 -class Navigator:
     8      @i18n
     9
    10      @login.authenticated
    11 -    def GET(self, name = None):
    12          orm = web.ctx.orm
    13          user = User.current()
    14
    15          # Checking if a argument is passed
    16          if name:
    17              ou = orm.query(OrganizativeUnit).filter(
    18                      OrganizativeUnit.name==name).first()
    19              computer = orm.query(Computer).filter(
    20                      Computer.name==name).first()
    21              # Checking if it's a ou
    22              if ou:
    23                  self.__check_permissions(ou, user)
    24                  return web.ctx.render.navigator.organizativeunit(
    25                          ou, ou.childs, ou.computers,
    26                          user, web.ctx.plugin_manager.get_enabled_plugins())
    27              # Checking if it's a computer
    28              elif computer:
    29                  self.__check_permissions(computer, user)
    30                  return web.ctx.render.navigator.computer(computer,
    31                          user, web.ctx.plugin_manager.get_enabled_plugins())
    32              # If not found in db it's a error
    33              else:
    34                  raise web.notfound()
    35          # If not we show the root ous of the user
    36          else:
    37              ous = None
    38              print user.super_user
    39              # If it's super user it can see everything
    40              if user.super_user:
    41                  ous = orm.query(OrganizativeUnit).filter(
    42                          OrganizativeUnit.parent_id==None).all()
    43                  return web.ctx.render.navigator.organizativeunit(
    44                          None, ous, [], user, web.ctx.plugin_manager.get_enabled_plugins())
    45
    46              # If not will see its root ous
    47              else:
    48                  ous = user.organizative_units
    49
    50              return web.ctx.render.navigator.organizativeunit(
    51                      None, ous, [], user, web.ctx.plugin_manager.get_enabled_plugins())
    52
    53 -    def __check_permissions(self, item, user):
    54          # Super users always have permisions
    55          if user.super_user:
    56              return
    57          if item.__class__.__name__ == "OrganizativeUnit":
    58              if item.parent_id == None and not item in user.organizative_units:
    59                  # TODO: show the user it has no permissions
    60                  raise web.seeother('/navigator')
    61              elif item in user.organizative_units:
    62                  # Has permissions, so nothing to do
    63                  return
    64              else:
    65                  self.__check_permissions(item.parent, user)
    66          else:
    67              self.__check_permissions(item.ou, user)
    68
    69 -    def __init__(self):
    70          pass
    71