Exemplo n.º 1
0
    def deltagusers(self, tagid, userlist=None, partylist=None):
        """
        :param tagid: 标题id
        :param userlist:企业成员id列表,userlist,partylist不能同时为空
        :param partylist:企业部门id列表 TODO:不能同时存在
        """
        # 读取config中的成员列表数据
        # 验证是否存在
        useridlist = _config.useridlist
        tagidlist = [i['tagid'] for i in self.taglist()['taglist']]
        userlist = [userlist]
        partyidlist = _config.partyidlist

        for i in userlist:
            if i in useridlist:
                if tagid in tagidlist:
                    WeChatWorkError.overlength(userlist, 1000)
                    WeChatWorkError.overlength(partylist, 100)
                    return self.post_api(api='deltagusers',
                                         data={
                                             'tagid': tagid,
                                             'userlist': userlist,
                                             'partylist': partylist
                                         })
                    # 逐层排查,返回空
                else:
                    return
            else:
                return
Exemplo n.º 2
0
    def update(self, id_, name, name_en=None, parentid=None, order=None):
        """"
        :param id_: 部门id
        :param name:部门名称,长度为1~32字符,不能包括\:?"<>/
        :param name_en:需要开启多语言支持,其余同上,# 
        :param parentid:父部门id
        :param order:在父部门中的次序,#
        """
        # 验证是否存在,若不存在则打印出,同时返回空
        all_Dep_ids = [i['id'] for i in self.Departmenlist()['department']]
        if id_ in all_Dep_ids:
            # 对长度进行处理
            WeChatWorkError.lesslength(name, 1)
            WeChatWorkError.overlength(name, 32)
            WeChatWorkError.lesslength(name_en, 1)
            WeChatWorkError.overlength(name_en, 32)

            data_params = {
                'id': id_,
                'name': name,
                'name_en': name_en,
                'parentid': parentid,
                'order': order
            }
            return self.post_api(api='update', data=data_params)
        else:
            return
Exemplo n.º 3
0
    def batchdelete(self, useridlist):
        # 最多支持同时删除200个,且如果存在无效则抛出错误
        WeChatWorkError.overlength(useridlist, 200)

        # 检查是否存在,若存在则存入另一个list
        simplelist = [
            i['userid'].lower() for i in self.simplelist(1, 1)['userlist']
        ]
        userid_list = []
        for userid in useridlist:
            if userid in simplelist:
                userid_list.append(userid)

                return self.post_api(api='batchdelete',
                                     data={"useridlist": userid_list})
Exemplo n.º 4
0
    def invite(self, user=None, party=None, tag=None):
        """
        :param user:成员ID列表, 最多支持1000个
        :param party:部门ID列表,最多支持100个
        :param tag:标签ID列表,最多支持100个
        """
        WeChatWorkError.overlength(user, 1000)
        WeChatWorkError.overlength(party, 100)
        # WeChatWorkError.overlength(tag,100)

        return self.post_api(api='invite',
                             data={
                                 'user': user,
                                 'party': party,
                                 'tag': tag
                             })
Exemplo n.º 5
0
 def create(self, tagname, tagid=None):
     """
     :param tagname:标签名称,长度小于32字,不可以与其他的标签重复 TODO:解决标签重复问题
     """
     # 验证是否存在,若不存在则打印出,同时返回空
     tagidlist = [i['tagid'] for i in self.taglist()['taglist']]
     tagnamelist = [i['tagname'] for i in self.taglist()['taglist']]
     if tagname not in tagnamelist:
         if tagid not in tagidlist:
             WeChatWorkError.overlength(tagname, 32)
             return self.post_api(api='create',
                                  data={
                                      'tagname': tagname,
                                      'tagid': tagid
                                  })
         else:
             return {'error': '该id已经存在'}
     else:
         return {'error': '该标签已经存在'}
Exemplo n.º 6
0
 def update(self, tagid, tagname):
     """
     :param tagid:标签ID
     :param tagname:标签名称,长度小于32字,不可以与其他的标签重复
     """
     # 验证是否存在,若不存在则打印出,同时返回空
     tagidlist = [i['tagid'] for i in self.taglist()['taglist']]
     tagnamelist = [i['tagname'] for i in self.taglist()['taglist']]
     if tagname in tagnamelist:
         if tagid in tagidlist:
             WeChatWorkError.overlength(tagname, 32)
             return self.post_api(api='update',
                                  data={
                                      'tagid': tagid,
                                      'tagname': tagname
                                  })
         else:
             print('tagid not found')
             return
     else:
         print('tagname not found')
         return