def create_extended_option(option, app, lo, pos): attrs = {} option_position = '%s,%s' % (option.position, ucr_get('ldap/base')) create_recursive_container(option_position, lo, pos) pos.setDn(option_position) attrs['name'] = option.name attrs['shortDescription'] = option.description if option.long_description: attrs['longDescription'] = option.long_description if option.description_de: attrs['translationShortDescription'] = [('de_DE', option.description_de)] if option.long_description_de: attrs['translationLongDescription'] = [('de_DE', option.long_description_de)] attrs['default'] = option.default attrs['editable'] = option.editable attrs['module'] = option.module attrs['objectClass'] = option.object_class attrs['isApp'] = '1' attribute_logger.debug('Creating DN: %s' % option.dn) if not create_object_if_not_exists('settings/extended_options', lo, pos, ** attrs): attribute_logger.debug('... already exists. Overwriting!') modify_object('settings/extended_options', lo, pos, option.dn, **attrs)
def create_extended_attribute(attribute, app, layout_position, lo, pos): attrs = {} attribute_position = '%s,%s' % (attribute.position, ucr_get('ldap/base')) create_recursive_container(attribute_position, lo, pos) pos.setDn(attribute_position) attrs['name'] = attribute.name attrs['shortDescription'] = attribute.description if attribute.long_description: attrs['longDescription'] = attribute.long_description if attribute.description_de: attrs['translationShortDescription'] = [('de_DE', attribute.description_de)] if attribute.long_description_de: attrs['translationLongDescription'] = [('de_DE', attribute.long_description_de)] attrs['syntax'] = attribute._udm_syntax or attribute.syntax attrs['multivalue'] = not attribute.single_value if attribute.default: attrs['default'] = attribute.default attrs['tabPosition'] = str(layout_position) attrs['tabName'] = 'Apps' attrs['groupName'] = app.name attrs['ldapMapping'] = attribute.name attrs['objectClass'] = attribute.belongs_to attrs['module'] = attribute.module attrs['deleteObjectClass'] = True attrs['mayChange'] = True attrs['fullWidth'] = attribute._full_width attribute_logger.debug('Creating DN: %s' % attribute.dn) if not create_object_if_not_exists('settings/extended_attribute', lo, pos, **attrs): attribute_logger.debug('... already exists. Overwriting!') modify_object('settings/extended_attribute', lo, pos, attribute.dn, **attrs)
def create_extended_attribute(attribute, app, layout_position, lo, pos): attrs = {} attribute_position = '%s,%s' % (attribute.position, ucr_get('ldap/base')) create_recursive_container(attribute_position, lo, pos) pos.setDn(attribute_position) attrs['name'] = attribute.name attrs['shortDescription'] = attribute.description if attribute.long_description: attrs['longDescription'] = attribute.long_description if attribute.description_de: attrs['translationShortDescription'] = [('de_DE', attribute.description_de)] if attribute.long_description_de: attrs['translationLongDescription'] = [('de_DE', attribute.long_description_de)] attrs['syntax'] = attribute.udm_syntax attrs['multivalue'] = str(int(not attribute.single_value)) if attribute.default: attrs['default'] = attribute.default attrs['tabPosition'] = attribute.tab_position or str(layout_position) attrs['tabName'] = attribute.tab_name if attribute.tab_name_de: attrs['translationTabName'] = [('de_DE', attribute.tab_name_de)] attrs['groupName'] = attribute.group_name or app.name if attribute.group_name_de: attrs['translationGroupName'] = [('de_DE', attribute.group_name_de)] attrs['ldapMapping'] = attribute.ldap_mapping attrs['objectClass'] = attribute.belongs_to attrs['module'] = attribute.module attrs['deleteObjectClass'] = attribute.delete_object_class attrs['mayChange'] = attribute.may_change attrs['fullWidth'] = attribute.full_width attrs['hook'] = attribute.hook attrs['disableUDMWeb'] = attribute.disable_web attrs['groupPosition'] = attribute.group_position attrs['tabAdvanced'] = attribute.advanced attrs['overwriteTab'] = attribute.overwrite_tab attrs['overwritePosition'] = attribute.overwrite_position attrs['valueRequired'] = attribute.required attrs['notEditable'] = attribute.not_editable attrs['doNotSearch'] = attribute.dont_search attrs['copyable'] = attribute.copyable attrs['options'] = attribute.options attrs['CLIName'] = attribute.cli_name attrs = dict( (key, value) for key, value in attrs.items() if value is not None) attribute_logger.debug('Creating DN: %s' % attribute.dn) if not create_object_if_not_exists('settings/extended_attribute', lo, pos, **attrs): attribute_logger.debug('... already exists. Overwriting!') modify_object('settings/extended_attribute', lo, pos, attribute.dn, **attrs)
def _register_attributes(self, app, args): # FIXME: there is no better lib function than this snippet schema_file = app.get_share_file('schema') if os.path.exists(schema_file): self.log('Registering schema %s' % schema_file) lo, pos = self._get_ldap_connection(args) with self._get_password_file(args) as password_file: create_recursive_container( 'cn=ldapschema,cn=univention,%s' % ucr_get('ldap/base'), lo, pos) if app.automatic_schema_creation: schema_obj = UniventionLDAPSchema(ucr_instance()) userdn = self._get_userdn(args) udm_passthrough_options = [ '--binddn', userdn, '--bindpwdfile', password_file ] opts = Values() opts.packagename = 'appcenter-app-%s' % app.id opts.packageversion = app.version opts.ucsversionstart = None opts.ucsversionend = None os.environ['UNIVENTION_APP_IDENTIFIER'] = app.id try: schema_obj.register(schema_file, opts, udm_passthrough_options) except SystemExit as exc: if exc.code == 4: self.warn( 'A newer version of %s has already been registered. Skipping...' % schema_file) else: raise RegisterSchemaFailed(exc.code) else: if not schema_obj.wait_for_activation(): raise RegisterSchemaFileFailed(schema_file) finally: if 'UNIVENTION_APP_IDENTIFIER' in os.environ: del os.environ['UNIVENTION_APP_IDENTIFIER'] # and this is what should be there after one line of lib.register_schema(schema_file) app = app.get_app_cache_obj().copy( locale='en').find_by_component_id(app.component_id) attributes, __, options = get_extended_attributes(app) for option in options: self.log('Registering option %s' % option.name) create_extended_option(option, app, lo, pos) if attributes: for i, attribute in enumerate(attributes): self.log('Registering attribute %s' % attribute.name) create_extended_attribute(attribute, app, i + 1, lo, pos)