def to(self, r, submit): approvals = r.approvals to, cc = [], [] to_group = [DEFAULT_GROUP.QA] to_group.extend([DEFAULT_GROUP.OP]) for g in to_group: to.extend([u.mail for u in Group.get_users(g)]) user = User.get(r.apply_uid) sub = u"发布申请:%s" % r.project if submit and submit["status"] == RELEASE.FAIL: sub = u"发布退回:%s %s" % (r.project, submit["type"]) to = [user["mail"]] elif approvals: sub = u"发布确认:%s %s" % (r.project, submit["type"]) to.append(user["mail"]) try: copy_to = User.get(r.copy_to_uid) if copy_to["mail"] not in to: cc.append(copy_to["mail"]) except: pass self.send(to, sub, "/templates/release/release.html", "mail.tpl.html", cc=cc, release=r, approvals=approvals)
def to(self, access): try: ldap = Ldap() copy_to_uid = [User.get(uid)["mail"] for uid in access.copy_to_uid.split(",")] \ if access.copy_to_uid \ else [User.get(ldap.get_1st_manager(access.apply_uid))["mail"]] copy_to_uid.extend( [u.mail for u in Group.get_users(DEFAULT_GROUP.OP)]) sub = u" %s权限申请 申请人:%s 申请时间:%s" % ( access.type, access.apply_uid, access.apply_time.strftime("%Y-%m-%d %H:%M")) self.send(copy_to_uid, sub, access=access, url="/templates/jurisdiction/curr_apply.html?id=%d" % access.id, tpl="mail.access.tpl.html") return True except Exception, e: traceback.print_exc() return False
def to(self, access): try: ldap = Ldap() copy_to_uid = [User.get(uid)["mail"] for uid in access.copy_to_uid.split(",")] \ if access.copy_to_uid \ else [User.get(ldap.get_1st_manager(access.apply_uid))["mail"]] copy_to_uid.extend([u.mail for u in Group.get_users(DEFAULT_GROUP.OP)]) sub = u" %s权限申请 申请人:%s 申请时间:%s" % ( access.type, access.apply_uid, access.apply_time.strftime("%Y-%m-%d %H:%M") ) self.send( copy_to_uid, sub, access=access, url="/templates/jurisdiction/curr_apply.html?id=%d"%access.id, tpl="mail.access.tpl.html" ) return True except Exception, e: traceback.print_exc() return False
def to(self, l): try: uids = [l.uid, l.approval_uid] + l.copy_to_uid.split(",") if l.status == LEAVE.PASS: uids += [u.uid for u in Group.get_users(DEFAULT_GROUP.LEAVE.MAIL)] to = [User.get(uid)["mail"] for uid in uids] to.append("*****@*****.**") else: to = [User.get(uid)["mail"] for uid in uids] status = l.status if status != LEAVE.PASS: status = u"已退回" sub = u"%s的请假申请%s 审批时间:%s 编号:%d" % ( l.uid,status,l.approval_time.strftime("%Y-%m-%d"),l.id) self.send( to, sub, "/templates/leave/approval.html", "mail.leave.tpl.html", leave=l, leave_type=Ref.map(LEAVE.TYPE)[int(l.type_id)]) except Exception,e: log.exception(e) raise ExceptionEx("邮件发送失败,请重试!")
def to(self, p): approvals = p.approvals to = [] if not p.is_finished: if p.cur_approval_type == PURCHASE.FLOW_ONE: ldap = Ldap() suser = User.get(ldap.get_2nd_manager(p.apply_uid)) to.append(suser["mail"]) else: to.extend( [u.mail for u in Group.get_users(p.cur_approval_type)]) else: user = User.get(p.apply_uid) to.extend( [u.mail for u in Group.get_users(DEFAULT_GROUP.PURCHASE.FIN)]) to.append(user["mail"]) sub = u"采购编号:%s 采购申请:%s" % (p.id, ",".join( [g.category.name for g in p.goods])) self.send(to, sub, "/templates/purchase/approval.html", "mail.purchase.tpl.html", purchase=p, goods=p.goods, approvals=approvals, group_names=Group.get_descs())
def to(self, p): approvals = p.approvals to = [] if not p.is_finished: if p.cur_approval_type == PURCHASE.FLOW_ONE: ldap=Ldap() suser = User.get(ldap.get_2nd_manager(p.apply_uid)) to.append(suser["mail"]) else: to.extend([u.mail for u in Group.get_users(p.cur_approval_type)]) else: user = User.get(p.apply_uid) to.extend([u.mail for u in Group.get_users(DEFAULT_GROUP.PURCHASE.FIN)]) to.append(user["mail"]) sub = u"采购编号:%s 采购申请:%s" % (p.id, ",".join([g.category.name for g in p.goods])) self.send( to, sub, "/templates/purchase/approval.html", "mail.purchase.tpl.html", purchase=p, goods=p.goods, approvals=approvals, group_names=Group.get_descs())
def put(self): submit = self.request() if submit.__contains__("mobile"): ldap = Ldap() ldap.modify(session[USER_SESSION]["uid"], {"mobile": submit["mobile"]}, submit["password"]) User.edit(submit) return self.succ()
def to(self, r,submit): approvals = r.approvals to, cc = [], [] to_group = [DEFAULT_GROUP.QA] to_group.extend([DEFAULT_GROUP.OP]) for g in to_group: to.extend([u.mail for u in Group.get_users(g)]) user = User.get(r.apply_uid) sub = u"发布申请:%s" % r.project if submit and submit["status"] == RELEASE.FAIL: sub = u"发布退回:%s %s" % (r.project, submit["type"]) to = [user["mail"]] elif approvals: sub = u"发布确认:%s %s" % (r.project, submit["type"]) to.append(user["mail"]) try: copy_to = User.get(r.copy_to_uid) if copy_to["mail"] not in to: cc.append(copy_to["mail"]) except: pass self.send( to, sub, "/templates/release/release.html", "mail.tpl.html", cc=cc, release=r, approvals=approvals)
def delete(self, uid): ldap = Ldap() if uid in ["*", u"*"]: raise ExceptionEx("无效的uid") else: ldap.delete(uid) User.update() return self.succ()
def to(self, p): self.send([ User.get(u)["mail"] for u in [p.demand_uid, p.develop_uid, p.test_uid, p.release_uid] ], u"项目创建提醒: %s" % (p.name), "/templates/project/edit.html?id=%d" % p.id, "mail.project.tpl.html")
def check_uid(self, submit): uids = User.uids() if submit.__contains__("mainten_uid") and submit["mainten_uid"]: if submit["mainten_uid"] not in uids: raise ExceptionEx("不存在维护人 %s" % submit["mainten_uid"]) if submit.__contains__("opt_uid") and submit["opt_uid"]: if submit["opt_uid"] not in uids: raise ExceptionEx("不存在业务人 %s" % submit["opt_uid"])
def post(self, uid): user = User.get(uid) user["pwd"] = crypt.randpass() ldap = Ldap() ldap.reset_pwd(uid, user["pwd"]) Mail().to(user) return self.succ()
def post(self, uid): submit = self.request() submit["uid"] = uid submit["c"] = submit["x-csf-emp-nationality"] submit["x-csf-emp-pwdReset"] = "TRUE" submit["userPassword"] = "******" _submit = self.to_str_dict(submit) _submit["objectClass"] = [ "country", "x-csf-EmployeeObject", "inetOrgPerson", "organizationalPerson", "person", "top" ] ldap = Ldap() ldap.add(uid, _submit) User.update() return self.succ()
def get(self, uid, pwd): if session.__contains__(USER_SESSION): User.add(session[USER_SESSION]) return self.fail("已登录") if not session.__contains__(KEY_SESSION): raise ExceptionEx("未申请密钥") uid = crypt.desc(uid) pwd = crypt.desc(pwd) ldap = Ldap() if not ldap.auth(uid, pwd): return self.fail("用户名或密码错误") dn, _user = ldap.search(uid).first() User.add(_user) session[USER_SESSION] = _user return self.succ(session[USER_SESSION])
def to(self, uid, newpass): try: user = User.get(uid) sub = u"密码重置提醒 %s" % (datetime.now().strftime("%Y-%m-%d %M:%S")) self.send( [user["mail"]], sub, "", "mail.passwd.tpl.html", newpass=newpass, ) except Exception, e: log.exception(e) raise ExceptionEx("邮件发送失败,请重试!")
def add(_dict): from bmp.models.user import User if Project.query.filter(Project.name == _dict["name"]).count(): raise ExceptionEx("项目名 %s 已存在" % _dict["name"]) uids = User.uids() for uid in [_dict[u] for u in _dict if "_uid" in u]: if uid not in uids: raise ExceptionEx("用户 %s 不存在" % uid) proj = Project(_dict) db.session.add(proj) db.session.commit() return proj
def finished(page=1, pre_page=20): from bmp.models.user import User uid = session[USER_SESSION]["uid"] group = set(User.get(uid)["group"]).intersection(PURCHASE.FLOW) page = Purchase.query \ .join(PurchaseApproval) \ .filter(or_(Purchase.apply_uid == uid, PurchaseApproval.uid == uid, PurchaseApproval.type.in_(group))) \ .filter(Purchase.is_draft == False) \ .filter(Purchase.is_finished == True) \ .order_by(Purchase.apply_time.desc()).paginate(page, pre_page) return page.to_page(Purchase._to_dict)
def to(self, l): try: uids = [l.approval_uid] + l.copy_to_uid.split(",") to = [User.get(uid)["mail"] for uid in uids] sub = u"请假申请 申请人:%s 申请时间:%s 编号:%d" % (l.uid,l.apply_time.strftime("%Y-%m-%d"),l.id) self.send( to, sub, "/templates/leave/approval.html", "mail.leave.tpl.html", leave=l, leave_type=Ref.map(LEAVE.TYPE)[int(l.type_id)]) except Exception,e: log.exception(e) raise ExceptionEx("邮件发送失败,请重试!")
def to(self, l): try: uids = [l.approval_uid] + l.copy_to_uid.split(",") to = [User.get(uid)["mail"] for uid in uids] sub = u"请假申请 申请人:%s 申请时间:%s 编号:%d" % ( l.uid, l.apply_time.strftime("%Y-%m-%d"), l.id) self.send(to, sub, "/templates/leave/approval.html", "mail.leave.tpl.html", leave=l, leave_type=Ref.map(LEAVE.TYPE)[int(l.type_id)]) except Exception, e: log.exception(e) raise ExceptionEx("邮件发送失败,请重试!")
def unfinished(user_groups): from bmp.models.user import Group, User purchases = [] uid = session[USER_SESSION]["uid"] group = set(User.get(uid)["group"]).intersection(PURCHASE.FLOW) group_map = {} for g in Group.select(to_dict=False): group_map[g.name.upper()] = g.desc for purchase in Purchase.query \ .filter(Purchase.is_draft == False) \ .filter(Purchase.is_finished == False).order_by(Purchase.apply_time.desc()).all(): approvals = purchase.approvals apply_uid = purchase.apply_uid cur_approval_type = purchase.cur_approval_type purchase.cur_approval_type_desc = "" purchase.approval_enable = False is_append = False if group_map.__contains__(cur_approval_type.upper()): purchase.cur_approval_type_desc = group_map[ cur_approval_type.upper()] if uid in [purchase.apply_uid] + [a.uid for a in approvals] \ or group.intersection([a.type for a in approvals]): purchases.append(purchase) is_append = True if cur_approval_type == PURCHASE.FLOW_ONE: if Purchase.__is_superior(uid, apply_uid): purchase.approval_enable = True if not is_append: purchases.append(purchase) elif uid in user_groups[cur_approval_type]: purchase.approval_enable = True if not is_append: purchases.append(purchase) else: continue return [ Purchase._to_dict(p, ["approval_enable", "cur_approval_type_desc"]) for p in purchases ]
def unfinished(user_groups): from bmp.models.user import Group, User purchases = [] uid = session[USER_SESSION]["uid"] group = set(User.get(uid)["group"]).intersection(PURCHASE.FLOW) group_map = {} for g in Group.select(to_dict=False): group_map[g.name.upper()] = g.desc for purchase in Purchase.query \ .filter(Purchase.is_draft == False) \ .filter(Purchase.is_finished == False).order_by(Purchase.apply_time.desc()).all(): approvals = purchase.approvals apply_uid = purchase.apply_uid cur_approval_type = purchase.cur_approval_type purchase.cur_approval_type_desc = "" purchase.approval_enable = False is_append = False if group_map.__contains__(cur_approval_type.upper()): purchase.cur_approval_type_desc = group_map[cur_approval_type.upper()] if uid in [purchase.apply_uid] + [a.uid for a in approvals] \ or group.intersection([a.type for a in approvals]): purchases.append(purchase) is_append = True if cur_approval_type == PURCHASE.FLOW_ONE: if Purchase.__is_superior(uid, apply_uid): purchase.approval_enable = True if not is_append: purchases.append(purchase) elif uid in user_groups[cur_approval_type]: purchase.approval_enable = True if not is_append: purchases.append(purchase) else: continue return [Purchase._to_dict(p, ["approval_enable", "cur_approval_type_desc"]) for p in purchases]
def put(self, uid, oldpass=None, newpass=None): if not oldpass: if not session.__contains__(USER_SESSION): raise ExceptionEx("未登录") if not User.get(session[USER_SESSION]["uid"])["is_admin"]: raise ExceptionEx("权限不足") if not uid or uid in ["*", u"*"]: return self.fail("无效的用户名") newpass = newpass if newpass else crypt.randpass() ldap = Ldap() if not ldap.reset_pwd(uid, newpass, oldpass): return self.fail() mail = Mail() mail.to(uid, newpass) return self.succ() if oldpass else self.succ(newpass)
def to(self, p): self.send( [User.get(u)["mail"] for u in [p.demand_uid, p.develop_uid, p.test_uid, p.release_uid]], u"项目创建提醒: %s" % (p.name), "/templates/project/edit.html?id=%d"%p.id, "mail.project.tpl.html")
def put(self, uid): submit = self.request() ldap = Ldap() ldap.modify(uid, self.to_str_dict(submit)) User.update() return self.succ()
def _to_dict(self): _dict = self.to_dict() _dict["apply_user"] = User.get(_dict["apply_uid"]) _dict["content"] = json.loads(_dict["content"]) return _dict
def put(self): submit = self.request() User.edit(submit) return self.succ()
def delete(self, uid): User.delete(uid) return self.succ()
def groups(self, uid): submit = self.request() User.set_groups(uid, submit["groups"]) return self.succ()
def update(self): if not User.update(): return self.fail() return self.succ()
def get(self): return self.succ(User.get(session[USER_SESSION]["uid"]))
def get(self, uid="%"): return self.succ(User.select(uid))
def to(self, p): self.send( [u.mail for u in User.get_business_category("it")], u"【%s】 %s:%s %s" % (p.type, p.txt, p.uid, p.time.strftime("%Y-%m-%d %H:%M:%S")), "/templates/project/index.html", "mail.project_notice.tpl.html")
def to(self, p): self.send([u.mail for u in User.get_business_category("it")], u"【%s】 %s:%s %s" % (p.type, p.txt, p.uid, p.time.strftime("%Y-%m-%d %H:%M:%S")), "/templates/project/index.html", "mail.project_notice.tpl.html")