Esempio n. 1
0
    def getTemplateI18N(self, language, theme="default"):
        templates = []
        factory = ObjectFactory.getInstance()

        for otype in factory.getObjectTypes():
            templates += factory.getObjectTemplateNames(otype)

        return factory.getNamedI18N(list(set(templates)), language=language, theme=theme)
Esempio n. 2
0
    def __init__(self):
        self.env = Environment.getInstance()

        # Load container mapping from object Factory
        factory = ObjectFactory.getInstance()
        self.containers = []
        for ot, info in factory.getObjectTypes().items():
            if 'container' in info:
                self.containers.append(ot)
Esempio n. 3
0
    def searchForObjectDetails(self, user, extension, attribute, fltr, attributes, skip_values):
        """
        Search selectable items valid for the attribute "extension.attribute".

        This is used to add new groups to the users groupMembership attribute.
        """

        # Extract the the required information about the object
        # relation out of the BackendParameters for the given extension.
        of = ObjectFactory.getInstance()
        be_data = of.getObjectBackendParameters(extension, attribute)
        if not be_data:
            raise GOsaException(C.make_error("BACKEND_PARAMETER_MISSING", extension=extension, attribute=attribute))

        # Collection basic information
        otype, oattr, foreignMatchAttr, matchAttr = be_data[attribute] #@UnusedVariable

        # Create a list of attributes that will be requested
        if oattr not in attributes:
            attributes.append(oattr)
        attrs = dict([(x, 1) for x in attributes])
        if not "dn" in attrs:
            attrs.update({'dn': 1})

        # Start the query and brind the result in a usable form
        index = PluginRegistry.getInstance("ObjectIndex")
        res = index.search({
            '$or': [{'_type': otype}, {'_extensions': otype}],
            oattr: re.compile("^.*" + re.escape(fltr) + ".*$")
            }, attrs)
        result = []

        # Do we have read permissions for the requested attribute
        env = Environment.getInstance()
        topic = "%s.objects.%s" % (env.domain, otype)
        aclresolver = PluginRegistry.getInstance("ACLResolver")

        for entry in res:

            if not aclresolver.check(user, topic, "s", base=entry['dn']):
                continue

            item = {}
            for attr in attributes:
                if attr in entry and len(entry[attr]):
                    item[attr] = entry[attr] if attr == "dn" else entry[attr][0]
                else:
                    item[attr] = ""
            item['__identifier__'] = item[oattr]

            # Skip values that are in the skip list
            if skip_values and item['__identifier__'] in skip_values:
                continue

            result.append(item)

        return result
Esempio n. 4
0
    def getObjectDetails(self, extension, attribute, names, attributes):
        """
        This method is used to complete object information shown in the gui.
        e.g. The groupMembership table just knows the groups cn attribute.
             To be able to show the description too, it uses this method.

        #TODO: @fabian - this function is about 95% the same than the one
        #                above.
        """

        # Extract the the required information about the object
        # relation out of the BackendParameters for the given extension.
        of = ObjectFactory.getInstance()
        be_data = of.getObjectBackendParameters(extension, attribute)

        if not be_data:
            raise GOsaException(C.make_error("BACKEND_PARAMETER_MISSING", extension=extension, attribute=attribute))

        # Collection basic information
        otype, oattr, foreignMatchAttr, matchAttr = be_data[attribute] #@UnusedVariable

        # Create a list of attributes that will be requested
        if oattr not in attributes:
            attributes.append(oattr)
        attrs = dict([(x, 1) for x in attributes])

        # Start the query and brind the result in a usable form
        index = PluginRegistry.getInstance("ObjectIndex")

        res = index.search({
            '$or': [{'_type': otype}, {'_extensions': otype}],
            oattr: {'$in': names}
            }, attrs)

        result = {}
        mapping = {}

        for entry in names:
            _id = len(result)
            mapping[entry] = _id
            result[_id] = None

        for entry in res:
            item = {}
            for attr in attributes:
                if attr in entry and len(entry[attr]):
                    item[attr] = entry[attr] if attr == 'dn' else entry[attr][0]
                else:
                    item[attr] = ""

            _id = mapping[item[oattr]]
            result[_id] = item

        return {"result": result, "map": mapping}
Esempio n. 5
0
    def getGuiDialogs(self, objectType, theme="default"):
        factory = ObjectFactory.getInstance()
        if objectType not in factory.getObjectTypes():
            raise GOsaException(C.make_error("OBJECT_UNKNOWN_TYPE", type=objectType))

        return factory.getObjectDialogs(objectType, theme)
Esempio n. 6
0
 def getAvailableObjectNames(self):
     factory = ObjectFactory.getInstance()
     return factory.getAvailableObjectNames()