def entrypoint(): ''' import dingding data ''' ding_config = DingConfig.get_current() token_manager = AccessTokenManager(ding_config.app_key, ding_config.app_secret, DINGDING_APP_VERSION) department_manager = DepartmentManager(token_manager) user_manager = UserManager(token_manager) role_manager = RoleManager(token_manager) db_executer = cli_factory(EXECUTERS)(User.objects.get(username='******')) root_dep = Dept.objects.get(uid=DEPARTMENT_ROOT_UID) build_department_user_rawdata(db_executer, user_manager, department_manager, DEPARTMENT_ROOT_ID, root_dep) build_group_rawdata(db_executer, role_manager)
def init_group(): ''' 创建必要的组 ''' root = Group.valid_objects.get(uid='root') cli = cli_factory([ 'executer.RDB.RDBExecuter', 'executer.LDAP.LDAPExecuter', ])(User.objects.first()) intra = cli.create_group({'uid': 'intra', 'name': '内部联系人-角色'}) extern = cli.create_group({'uid': 'extern', 'name': '外部联系人-标签'}) managers = cli.create_group({'uid': 'manager', 'name': '管理员'}) cli.add_group_to_group(intra, root) cli.add_group_to_group(extern, root) cli.add_group_to_group(managers, root)
def __init__(self, *args, **kwargs): self.server = Server(settings.LDAP_SERVER) self.base = settings.LDAP_BASE self.conn = Connection(self.server, user=settings.LDAP_USER, password=settings.LDAP_PASSWORD, auto_bind=True, raise_exceptions=False) self.ldap_executer = LDAPExecuter(base='dc=example,dc=org') self.rdb_executer = RDBExecuter() self.cli = cli_factory([ 'executer.RDB.RDBExecuter', 'executer.LDAP.LDAPExecuter', ])(User.objects.first()) settings.LDAP_BASE = 'dc=example,dc=org' super(LDAPBaseTestCase, self).__init__(*args, **kwargs)