Ejemplo n.º 1
0
def groups_callback(name, request):
    """Collect and return roles and groups for user.
    
    XXX: request caching via decorator
    """
    roles = request.environ.get('cone.app.user.roles')
    if roles:
        return roles
    roles = list()
    for impl in app_config().auth:
        try:
            user = impl.users.get(name)
        except Exception, e:
            logger.error(str(e))
            continue
        if not user:
            continue
        aggregated = set()
        for role in user.roles:
            aggregated.add('role:%s' % role)
        for group in user.groups:
            aggregated.add('group:%s' % group.name)
            for role in group.roles:
                aggregated.add('role:%s' % role)
        roles = list(aggregated)
        break
Ejemplo n.º 2
0
def node_icon(request, node):
    if node.properties.icon:
        return node.properties.icon
    info = node.nodeinfo
    if not info.icon:
        return app_config().default_node_icon
    return info.icon
Ejemplo n.º 3
0
def node_icon(node):
    if node.properties.icon:
        return node.properties.icon
    info = node.nodeinfo
    if not info.icon:
        return app_config().default_node_icon
    return info.icon
Ejemplo n.º 4
0
def node_icon_url(request, node):
    if node.properties.icon:
        return make_url(request, resource=node.properties.icon)
    info = node.nodeinfo
    if not info.icon:
        return make_url(request, resource=app_config().default_node_icon)
    return make_url(request, resource=info.icon)
Ejemplo n.º 5
0
 def nodeinfo(self):
     info = get_node_info(self.node_info_name)
     if not info:
         info = NodeInfo()
         info.title = str(self.__class__)
         info.node = self.__class__
         info.icon = app_config().default_node_icon
     return info
Ejemplo n.º 6
0
 def nodeinfo(self):
     info = get_node_info(self.node_info_name)
     if not info:
         info = NodeInfo()
         info.title = str(self.__class__)
         info.node = self.__class__
         info.icon = app_config().default_node_icon
     return info
Ejemplo n.º 7
0
def authenticate(request, login, password):
    for impl in app_config().auth:
        try:
            if impl.users.authenticate(login, password):
                return remember(request, login)
        except Exception, e:
            msg = u"Authentication plugin %s raised an Exception while " + \
                  u"trying to authenticate: %s"
            msg = msg % (str(impl.__class__), str(e))
            logger.warning(msg)
Ejemplo n.º 8
0
def search_for_principals(term):
    ret = list()
    criteria = {
        'id': term,
    }
    ugm = app_config().auth
    for user in ugm.users.search(criteria=criteria, or_search=True):
        ret.append(user)
    for group in ugm.groups.search(criteria=criteria, or_search=True):
        ret.append('group:%s' % group)
    return ret
Ejemplo n.º 9
0
def principal_by_id(principal_id):
    ugm = app_config().auth
    try:
        if principal_id.startswith('group:'):
            principal = ugm.groups.get(principal_id[6:])
        else:
            principal = ugm.users.get(principal_id)
        if not principal:
            return None
        return principal
    except Exception:
        return None
Ejemplo n.º 10
0
def authenticate(request, login, password):
    if ADMIN_USER and ADMIN_PASSWORD:
        if login == ADMIN_USER and password == ADMIN_PASSWORD:
            return remember(request, login)
    ugm = app_config().auth
    try:
        if ugm.users.authenticate(login, password):
            id = ugm.users.id_for_login(login)
            return remember(request, id)
    except Exception, e:
        msg = u"Authentication plugin %s raised an Exception while " + \
              u"trying to authenticate: %s"
        msg = msg % (str(ugm.__class__), str(e))
        logger.warning(msg)
Ejemplo n.º 11
0
 def make_item(self, info_name, info):
     model = self.model
     request = self.request
     props = Properties()
     query = make_query(factory=info_name)
     url = make_url(request, node=model, resource='add', query=query)
     props.url = url
     target = make_url(request, node=model, query=query)
     props.target = target
     props.title = info.title
     icon = info.icon
     if not icon:
         icon = app_config().default_node_icon
     props.icon = icon
     return props
Ejemplo n.º 12
0
 def make_item(self, info_name, info):
     model = self.model
     request = self.request
     props = Properties()
     query = make_query(factory=info_name)
     url = make_url(request, node=model, resource='add', query=query)
     props.url = url
     target = make_url(request, node=model, query=query)
     props.target = target
     props.title = info.title
     icon = info.icon
     if not icon:
         icon = app_config().default_node_icon
     props.icon = icon
     return props
Ejemplo n.º 13
0
def groups_callback(name, request):
    """Collect and return roles and groups for user.

    XXX: request caching via decorator
    """
    environ = request.environ
    roles = environ.get(ROLES_CACHE_KEY)
    if roles:
        return roles
    if name == ADMIN_USER:
        roles = environ[ROLES_CACHE_KEY] = [u'role:manager']
        return roles
    ugm = app_config().auth
    user = None
    try:
        user = ugm.users.get(name)
    except Exception, e:
        logger.error(str(e))
Ejemplo n.º 14
0
 def items(self):
     ret = list()
     addables = self.model.nodeinfo.addables
     if not addables:
         return ret
     for addable in addables:
         info = getNodeInfo(addable)
         if not info:
             continue
         query = make_query(factory=addable)
         url = make_url(self.request, node=self.model,
                        resource='add', query=query)
         target = make_url(self.request, node=self.model, query=query)
         props = Properties()
         props.url = url
         props.target = target
         props.title = info.title
         icon = info.icon
         if not icon:
             icon = app_config().default_node_icon
         props.icon = make_url(self.request, resource=icon)
         ret.append(props)
     return ret
Ejemplo n.º 15
0
 def js(self):
     return self.resources(app_config().js)
Ejemplo n.º 16
0
 def css(self):
     return app_config().css
Ejemplo n.º 17
0
 def js(self):
     return app_config().js
Ejemplo n.º 18
0
 def css(self):
     return self.resources(app_config().css)
Ejemplo n.º 19
0
 def js(self):
     return self.resources(app_config().js)
Ejemplo n.º 20
0
 def test_app_config(self):
     # Fetch application configuration
     cfg = app_config()
     self.assertTrue(isinstance(cfg, Properties))
Ejemplo n.º 21
0
 def test_app_config(self):
     # Fetch application configuration
     cfg = app_config()
     self.assertTrue(isinstance(cfg, Properties))
Ejemplo n.º 22
0
 def css(self):
     return self.resources(app_config().css)