Beispiel #1
0
    def superordinate(self, argument=None):
        '''Set or query the current objectts "superordinate".

		Set the superordinate to "Argument", if given; otherwise just
		return it.

		If "Argument" is a DN, the superordinate object will be
		fetched from that DN and stored; otherwise, it is assumed to
		be an object and will be queried for the DN to fetch the
		superordinate object from.
		'''
        if argument is None:
            return self.__superordinate
        supmod = umod.superordinate(self.modname)
        if isinstance(argument, basestring):
            dn = argument
            sup = None
        else:
            dn = argument.dn
            sup = getattr(argument, 'superordinate')
        if callable(sup):
            sup = sup()
        kwargs = {'base': dn, 'scope': 'base', 'superordinate': sup}
        res = supmod.lookup(self.__config, self.ldap, '', **kwargs)
        self.__superordinate = res[0]
        return self.__superordinate
Beispiel #2
0
	def superordinate(self, argument = None):
		'''Set or query the current objectts "superordinate".

		Set the superordinate to "Argument", if given; otherwise just
		return it.

		If "Argument" is a DN, the superordinate object will be
		fetched from that DN and stored; otherwise, it is assumed to
		be an object and will be queried for the DN to fetch the
		superordinate object from.
		'''
		if argument is None:
			return self.__superordinate
		supmod = umod.superordinate(self.modname)
		if isinstance(argument, basestring):
			dn = argument
			sup = None
		else:
			dn = argument.dn
			sup = getattr(argument, 'superordinate')
		if callable(sup):
			sup = sup()
		kwargs = { 'base': dn, 'scope': 'base', 'superordinate': sup } 
		res = supmod.lookup(self.__config, self.ldap, '', **kwargs)
		self.__superordinate = res[0]
		return self.__superordinate
Beispiel #3
0
	def types( self, request, ldap_connection = None, ldap_position = None ):
		"""Returns the list of object types matching the given flavor or container.

		requests.options = {}
		  'superordinate' -- if available only types for the given superordinate are returned (not for the navigation)
		  'container' -- if available only types suitable for the given container are returned (only for the navigation)

		return: [ { 'id' : <LDAP DN of container or None>, 'label' : <name> }, ... ]
		"""
		if request.flavor != 'navigation':
			module = UDM_Module( request.flavor )
			superordinate = request.options.get( 'superordinate' )
			if superordinate:
				self.finished( request.id, module.types4superordinate( request.flavor, superordinate ) )
			else:
				self.finished( request.id, module.child_modules )
		else:
			container = request.options.get( 'container' )
			if not container:
				# no container is specified, return all existing object types
				MODULE.info('no container specified, returning all object types')
				self.finished( request.id, map( lambda module: { 'id' : module[ 0 ], 'label' : getattr( module[ 1 ], 'short_description', module[ 0 ] ) }, udm_modules.modules.items() ) )
				return

			if 'None' == container:
				# if 'None' is given, use the LDAP base
				container = ucr.get( 'ldap/base' )
				MODULE.info('no container == \'None\', set LDAP base as container')

			# create a list of modules that can be created
			# ... all container types except container/dc
			allowed_modules = set([m for m in udm_modules.containers if udm_modules.name(m) != 'container/dc'])

			# the container may be a superordinate or have one as its parent
			# (or grandparent, ....)
			superordinate = udm_modules.find_superordinate(container, None, ldap_connection)
			if superordinate:
				# there is a superordinate... add its subtypes to the list of allowed modules
				MODULE.info('container has a superordinate: %s' % superordinate)
				allowed_modules.update(udm_modules.subordinates(superordinate))
			else:
				# add all types that do not have a superordinate
				MODULE.info('container has no superordinate')
				allowed_modules.update(filter(lambda mod: not udm_modules.superordinate(mod), udm_modules.modules.values()))

			# make sure that the object type can be created
			allowed_modules = filter(lambda mod: udm_modules.supports(mod, 'add'), allowed_modules)
			MODULE.info('all modules that are allowed: %s' % [udm_modules.name(mod) for mod in allowed_modules])

			# return the final list of object types
			self.finished( request.id, map( lambda module: { 'id' : udm_modules.name(module), 'label' : getattr( module, 'short_description', udm_modules.name(module) ) }, allowed_modules ) )