def update_user(self, userid=None, name=None, department=[], position=None, mobile=None, tel=None, extid=None, gender=None, slaves=[], password=None, cpwd_login=0): """Update a new user. :param str userid: User's email :param str name: User's name :param list department: User's department lists :param str position Position name :param str mobile: Mobile phone number :param str tel: Telephone number :param str extid: :param int gender: 1 is man, 2 is woman :param list slaves: Alias :param str password: Login password :param int cpwd_login: Change password after login """ if len(department) > 20: raise exceptions.ParamsError('Departments must be within 20') if department and not isinstance(department, tuple): raise exceptions.ParamsError('department should be tuple type') if len(slaves) > 5: raise exceptions.ParamsError('Slaves must be within 5') if slaves and not isinstance(slaves, tuple): raise exceptions.ParamsError('slaves should be tuple type') body = { 'userid': userid, 'name': name, 'department': department, 'position': position, 'mobile': mobile, 'tel': tel, 'extid': extid, 'gender': gender, 'slaves': slaves, 'password': password, 'cpwd_login': cpwd_login } self.transport.perform_request(api='/user/update?access_token=%s' % self.access_token, body=body, method='POST')
def create_group(self, groupid=None, groupname=None, userlist=None, grouplist=None, departments=None, allow_type=0, allow_userlist=None): """Create a mail group. :param str groupid: Group email address :param str groupname: Group email name :param tuple userlist: Users in group :param tuple grouplist: Groups :param tuple departments: Departments :param int allow_type: The permission of send group mail :param tuple allow_userlist: The user who have permission to send group mail """ if not groupid and \ not groupname: raise exceptions.ParamsError('groupid and groupname should be set') if not userlist and \ not grouplist and \ not departments: raise exceptions.ParamsError( 'userlist, grouplist and departments must be set at one least') body = { 'groupid': groupid, 'groupname': groupname, 'allow_type': allow_type, } if userlist and isinstance(userlist, tuple): body['userlist'] = userlist if grouplist and isinstance(grouplist, tuple): body['grouplist'] = grouplist if departments and isinstance(departments, tuple): body['department'] = departments if allow_userlist and isinstance(allow_userlist, tuple): body['allow_userlist'] = allow_userlist self.transport.perform_request(api='/group/create?access_token=%s' % self.access_token, body=body, method='POST')
def update_department(self, department_id=None, name=None, parentid=None, order=None): """Update department. :param int department_id: Department's id :param str name: Department name :param int parentid: Department parent id :param int oder: Order """ if not department_id: raise exceptions.ParamsError('department id is required') if not name and not parentid and not order: return body = {'id': department_id} if name: body['name'] = name if parentid: body['parentid'] = parentid if order: body['order'] = order self.transport.perform_request( api='/department/update?access_token=%s' % self.access_token, body=body, method='POST')
def delete_department(self, department_id=None): """Delete department. :param int department_id: Department's id """ if not department_id: raise exceptions.ParamsError('department id is required') body = {'access_token': self.access_token, 'id': department_id} self.transport.perform_request(api='/department/delete', body=body)
def delete_group(self, groupid=None): """Delete a mail group. :param str groupid: Group email address """ if not groupid: raise exceptions.ParamsError('groupid should be set') body = {'groupid': groupid, 'access_token': self.access_token} self.transport.perform_request(api='/group/delete', body=body)
def get_group(self, groupid=None): """Get a mail group info. :param str groupid: Group email address :return: A dict """ if not groupid: raise exceptions.ParamsError('groupid should be set') body = {'groupid': groupid, 'access_token': self.access_token} return self.transport.perform_request(api='/group/get', body=body)
def delete_user(self, userid=None): """Delete a user. :param str userid: User's email """ if not userid: raise exceptions.ParamsError('userid should be set') self.transport.perform_request(api='/user/delete', body={ 'userid': userid, 'access_token': self.access_token })
def list_departments(self, department_id=None): """List departments. :param int department_id: Department's id :return: A list of deparments. """ if not department_id: raise exceptions.ParamsError('department id is required') body = {'access_token': self.access_token, 'id': department_id} data = self.transport.perform_request(api='/department/list', body=body) return data['department']
def get_user(self, userid=None): """Get a user. :param str userid: User's email """ if not userid: raise exceptions.ParamsError('userid should be set') data = self.transport.perform_request(api='/user/get', body={ 'userid': userid, 'access_token': self.access_token }) return data
def update_group(self, groupid=None, groupname=None, userlist=None, grouplist=None, departments=None, allow_type=0, allow_userlist=None): """Update a mail group. :param str groupid: Group email address :param str groupname: Group email name :param tuple userlist: Users in group :param tuple grouplist: Groups :param tuple departments: Departments :param int allow_type: The permission of send group mail :param tuple allow_userlist: The user who have permission to send group mail """ if not groupid: raise exceptions.ParamsError('groupid should be set') body = {'groupid': groupid} if groupname: body['groupname'] = groupname if userlist and isinstance(userlist, tuple): body['userlist'] = userlist if grouplist and isinstance(grouplist, tuple): body['grouplist'] = grouplist if departments and isinstance(departments, tuple): body['department'] = departments if allow_userlist and isinstance(allow_userlist, tuple): body['allow_userlist'] = allow_userlist if len(body.keys()) == 1: return self.transport.perform_request(api='/group/update?access_token=%s' % self.access_token, body=body, method='POST')
def get_login_url(self, userid=None): """Get login url. :param str userid: User's email :return: A login url. """ if not userid: raise exceptions.ParamsError('userid must be set') body = { 'access_token': self.access_token, 'userid': userid } data = self.transport.perform_request( api='/login', body=body ) return data['login_url']
def create_department(self, name=None, parentid=None, order=None): """Create department. :param str name: Department name :param int parentid: Department parent id :param int oder: Order :return: Created department's id """ if not name and not parentid: raise exceptions.ParamsError("name and parentid can'\t be None") body = {'name': name, 'parentid': parentid} if order: body['order'] = order data = self.transport.perform_request( api='/department/create?access_token=%s' % self.access_token, body=body, method='POST') return data['id']