Exemplo n.º 1
0
    def do_notice_checker(self, json_message):
        logger.info(
            "-----------------------------NOTICE CHECKER-----------------------------"
        )
        svc = PtUserService(self)
        pt_users_res = svc.get_list()
        user_ids = [
            u.id for u in pt_users_res.data
            if "pro_resource_apply.check" in u.get_current_perms()
        ]

        for user_id in user_ids:
            svc = ActHistoryService(self, {"user_id": user_id})
            tasks_res = svc.get_res_tasks()
            data = {
                "tasks_res": tasks_res,
                "imchecker": True,
                "STATUS_RESOURCE": STATUS_RESOURCE
            }
            chat = {
                "user_id": user_id,
                "html": self.render_to_string("admin/notice/tasks.html",
                                              **data)
            }
            chat.update(json_message)
            logger.error(chat)
            EchoWebSocket.send_message(chat)
Exemplo n.º 2
0
 def do_online(self, json_message):
     user_id = json_message["user_id"]
     svc = PtUserService(self, {"user_id": user_id})
     pt_user_res = svc.get_info()
     pt_user = pt_user_res.data
     if not isinstance(pt_user_res, Exception):
         logger.info("pt_user: %s" % pt_user)
         data = {
             "level":
             "info",
             "content":
             u"%s已经上线!" %
             (pt_user.username or pt_user.email or pt_user.mobile),
         }
         try:
             html = self.render_to_string("admin/notice/online.html",
                                          **data)
         except Exception as e:
             logThrown()
             html = ""
         chat = {"user_id": pt_user.id, "html": html}
         chat.update(json_message)
         EchoWebSocket.users.update({user_id: self})
         EchoWebSocket.send_all(chat)
         logger.info("**users: %s" % EchoWebSocket.users)
Exemplo n.º 3
0
 def get_index_page(self):
     svc = PtUserService(self)
     response = svc.get_list()
     # search = self.args.get("search", "")
     # response = yield gen.Task(svc_pt_user.get_list.apply_async, args=[search])
     data = {"result": response}
     pprint(data)
     return self.render_to_string("admin/pt_user/index.html", **data)
Exemplo n.º 4
0
 def get(self):
     svc = PtUserService(self)
     response = svc.get_info()
     # user_id = self.args.get("user_id", 0)
     # response = yield gen.Task(svc_pt_user.get_info.apply_async, args=[user_id])
     if isinstance(response, Exception):
         data = {"result": response, "action_name": "pt_user"}
     else:
         data = {"result": response, "action_name": "pt_user.info"}
     return self.render_to_string("admin/pt_user/_index_form.html", **data)
Exemplo n.º 5
0
 def get(self):
     svc = PtUserService(self)
     response = svc.get_user_roles()
     user_id = self.args.get("user_id", 0)
     logger.info(response)
     data = {"user_id": user_id, "action_name": "pt_user.role_info"}
     if response.return_code == 0:
         data.update({"result": response})
     response = svc_pt_user.get_user_roles(user_id)
     return self.render_to_string(
         "admin/pt_user/_index_user_roles_form.html", **data)
Exemplo n.º 6
0
def publish_notice_user(user_id=0):
    logger.info("#"*30+" [user %s notice_user tasks] "%user_id+"#"*30)
    action = "on_notice_user"
    with DataBaseService({}) as DBSvc:
        svc = PtUserService(DBSvc)
        pt_users_res = svc.get_list()
        user_ids = [u.id for u in pt_users_res.data if "pro_resource_apply.check" in u.get_current_perms()]
        pub_svc = TaskPublish(DBSvc)
        pub_svc.publish_tasks(user_id, action=action)
        for this_id in user_ids:
            # 通知所有审核员
            pub_svc.publish_tasks(this_id)
        logger.info("#"*30+" [user %s notice_user tasks finish] "%user_id+"#"*30)
    return True
Exemplo n.º 7
0
 def post(self):
     svc = PtUserService(self)
     response1 = svc.update_info()
     if response1.return_code == 0:
         self.add_message(u"%s成功!" % act_actions.get(2).value %
                          PT_User.__doc__,
                          level="success")
     else:
         self.add_message(u"failure code (%s): %s" %
                          (response1.return_code, response1.return_message),
                          level="warning")
     response = svc.get_list()
     data = {"result": response, "action_name": "pt_user.info"}
     raise gen.Return(self.render("admin/pt_user/index.html", **data))
Exemplo n.º 8
0
 def delete_user(self):
     svc = PtUserService(self)
     response1 = svc.delete_info()
     # user_id = self.args.get("user_id", 0)
     # response1 = yield gen.Task(svc_pt_user.delete_info.apply_async, args=[user_id])
     if response1.return_code == 0:
         self.add_message(u"%s成功!" % act_actions.get(3).value %
                          PT_User.__doc__,
                          level="success")
     else:
         self.add_message(u"failure code (%s): %s" %
                          (response1.return_code, response1.return_message),
                          level="warning")
     return self.get_index_page()
Exemplo n.º 9
0
 def on_message(self, message):
     logger.error("====[status onmessage]====")
     self.svc = DataBaseService()
     self.svc.__enter__()
     logger.error("\t WebSocket message: %s" % message)
     json_message = simplejson.loads(message)
     if json_message["action"] == "init_status":
         # svc = ProResourceApplyService(self, {"res_id": json_message["res_id"]})
         # resource_res = svc.get_resource()
         # user_id = resource_res.data.user_id
         user_id = json_message["user_id"]
         svc = PtUserService(self, {"user_id": user_id})
         pt_user_res = svc.get_info()
         if pt_user_res.return_code == 0:
             current_perms = pt_user_res.data.get_current_perms()
             if "pro_resource_apply.view" in current_perms:
                 imchecker = False
             else:
                 imchecker = True
             svc = ActHistoryService(self, {"user_id": user_id})
             tasks_res = svc.get_res_tasks()
             data = {
                 "tasks_res": tasks_res,
                 "imchecker": imchecker,
                 "STATUS_RESOURCE": STATUS_RESOURCE
             }
             chat = {
                 "user_id":
                 user_id,
                 "task_html":
                 self.render_to_string("admin/notice/tasks.html", **data)
             }
             chat.update(json_message)
             logger.error(chat)
             self.write_message(chat)
         # self.on_finish()
         # chat.update(json_message)
         # EchoWebSocket.send_message(chat)
         # self.write_message(u"You said: " + message)
     elif json_message["action"] == "offline":
         EchoWebSocket.users.pop(str(json_message["user_id"]))
     else:
         self.write_message(u"You said: " + message)
     self.svc.db.commit()
     self.svc.db.close()
     logger.error("====[status finish]====")
Exemplo n.º 10
0
 def post_user(self):
     svc = PtUserService(self)
     response1 = svc.get_or_create()
     # username = self.args.get("username", "")
     # password = self.args.get("password", "")
     # response1 = yield gen.Task(
     #     svc_pt_user.get_or_create.apply_async,
     #     args=[username, password]
     # )
     # logger.info(response1.result)
     if response1.return_code == 0:
         self.add_message(u"%s成功!" % act_actions.get(1).value %
                          PT_User.__doc__,
                          level="success")
     else:
         self.add_message(u"failure code (%s): %s" %
                          (response1.return_code, response1.return_message),
                          level="warning")
     return self.get_index_page()
Exemplo n.º 11
0
    def do_notice_checker(self, json_message):
        logger.info("-----------------------------NOTICE CHECKER-----------------------------")
        svc = PtUserService(self)
        pt_users_res = svc.get_list()
        user_ids = [u.id for u in pt_users_res.data if "pro_resource_apply.check" in u.get_current_perms()]

        for user_id in user_ids:
            svc = ActHistoryService(self, {"user_id": user_id})
            tasks_res = svc.get_res_tasks()
            data = {
                "tasks_res": tasks_res,
                "imchecker": True,
                "STATUS_RESOURCE": STATUS_RESOURCE
            }
            chat = {
                "user_id": user_id,
                "html": self.render_to_string("admin/notice/tasks.html", **data)
            }
            chat.update(json_message)
            logger.error(chat)
            EchoWebSocket.send_message(chat)
Exemplo n.º 12
0
 def do_online(self, json_message):
     user_id = json_message["user_id"]
     svc = PtUserService(self, {"user_id": user_id})
     pt_user_res = svc.get_info()
     pt_user = pt_user_res.data
     logger.info("pt_user: %s"% pt_user)
     data = {
         "level": "info",
         "content": u"%s已经上线!" % (pt_user.username or pt_user.email or pt_user.mobile),
     }
     try:
         html = self.render_to_string("admin/notice/online.html", **data)
     except Exception as e:
         logThrown()
         html = ""
     chat = {
         "user_id": pt_user.id,
         "html": html
     }
     chat.update(json_message)
     EchoWebSocket.users.update({user_id: self})
     EchoWebSocket.send_all(chat)
     logger.info("**users: %s" % EchoWebSocket.users)
Exemplo n.º 13
0
 def post(self):
     role_ids = self.get_arguments("role_id")
     svc = PtUserService(self, {"role_ids": role_ids})
     response1 = svc.post_user_roles()
     response = svc.get_list()
     # user_id = self.args.get("user_id", 0)
     # group_op_list = [(g, op) for g, op in [_str.split(".") for _str in group_ops]]
     # logger.info(role_ids)
     # response1 = yield gen.Task(svc_pt_user.post_user_roles.apply_async, args=[user_id, role_ids])
     # response = yield gen.Task(
     #     svc_pt_user.get_list.apply_async,
     #     args=[]
     # )
     data = {"result": response}
     if response1.return_code == 0:
         data.update(response1.data)
     logger.info("data")
     logger.info(data)
     self.add_message(u"%s成功!" % act_actions.get(2).value %
                      PT_User_Role.__doc__,
                      level="success")
     # data = {}
     return self.render_to_string("admin/pt_user/index.html", **data)
Exemplo n.º 14
0
    def publish_tasks(self, user_id, pro_id=None, action="on_task", do_publish=True):
        logger.info("------[publish_tasks]------")

        user_svc = PtUserService(self, {"user_id": user_id, "pro_id": pro_id})
        pt_user_res = user_svc.get_info()
        logger.info(pt_user_res)
        current_perms = pt_user_res.data.get_current_perms()
        imchecker = pt_user_res.data.imchecker
        # if "pro_resource_apply.check" in pt_user_res.data.get_current_perms():
        #     imchecker = True
        # else:
        #     imchecker = False
        # 获取任务列表
        svc = ActHistoryService(self, {"user_id": user_id, "pro_id": pro_id})
        tasks_res = svc.get_res_tasks()
        data = {
            "tasks_res": tasks_res,
            "task_list": tasks_res.data,
            "imchecker": imchecker,
            "current_perms": current_perms,
            "STATUS_RESOURCE": STATUS_RESOURCE
        }

        # 获取用户申请列表
        svc = ProUserService(self, {"user_id": user_id, "pro_id": pro_id})
        pro_user_list_res = svc.get_list()
        if imchecker:
            pro_user_list = [i for i in pro_user_list_res.data if i.status == STATUS_PRO_TABLES.APPLIED]
        else:
            pro_user_list = [i for i in pro_user_list_res.data if i.status in [STATUS_PRO_TABLES.REFUSED, STATUS_PRO_TABLES.CHECKED]]
        data.update({
            "pro_user_list": pro_user_list,
            "imchecker": imchecker,
            "STATUS_PRO_TABLES": STATUS_PRO_TABLES
        })
        # logger.info(pro_user_list)

        # 获取互联网发布申请列表
        svc = ApplyPublish(self, {"user_id": user_id, "pro_id": pro_id})
        pro_publish_list_res = svc.get_list()
        # logger.info(pro_publish_list_res.data)
        if imchecker:
            pro_publish_list = [i for i in pro_publish_list_res.data if i.status == STATUS_PRO_TABLES.APPLIED]
        else:
            pro_publish_list = [i for i in pro_publish_list_res.data if i.status in [STATUS_PRO_TABLES.REFUSED, STATUS_PRO_TABLES.CHECKED]]
        data.update({
            "pro_publish_list": pro_publish_list,
            "imchecker": imchecker,
            "STATUS_PRO_TABLES": STATUS_PRO_TABLES
        })

        # 获取负载均衡申请列表
        svc = ApplyLoadBalance(self, {"user_id": user_id, "pro_id": pro_id})
        pro_balance_list_res = svc.get_list()
        # logger.info(pro_balance_list_res.data)
        if imchecker:
            pro_balance_list = [i for i in pro_balance_list_res.data if i.status == STATUS_PRO_TABLES.APPLIED]
        else:
            pro_balance_list = [i for i in pro_balance_list_res.data if i.status in [STATUS_PRO_TABLES.REFUSED, STATUS_PRO_TABLES.CHECKED]]
        data.update({
            "pro_balance_list": pro_balance_list,
            "imchecker": imchecker,
            "STATUS_PRO_TABLES": STATUS_PRO_TABLES
        })

        # 获取定期备份申请列表
        svc = ApplyBackups(self, {"user_id": user_id, "pro_id": pro_id})
        pro_backup_list_res = svc.get_list()
        # logger.info(pro_backup_list_res.data)
        if imchecker:
            pro_backup_list = [i for i in pro_backup_list_res.data if i.status == STATUS_PRO_TABLES.APPLIED]
        else:
            pro_backup_list = [i for i in pro_backup_list_res.data if i.status in [STATUS_PRO_TABLES.REFUSED, STATUS_PRO_TABLES.CHECKED]]
        data.update({
            "pro_backup_list": pro_backup_list,
            "imchecker": imchecker,
            "STATUS_PRO_TABLES": STATUS_PRO_TABLES
        })

        # 获取定期备份申请列表
        svc = EventService(self, {"user_id": user_id, "pro_id": pro_id})
        pro_event_list_res = svc.get_list()
        # logger.info(pro_event_list_res.data)
        if imchecker:
            pro_event_list = [i for i in pro_event_list_res.data if i.status == STATUS_PRO_TABLES.APPLIED]
        else:
            pro_event_list = [i for i in pro_event_list_res.data if i.status in [STATUS_PRO_TABLES.REFUSED, STATUS_PRO_TABLES.CHECKED]]
        data.update({
            "pro_event_list": pro_event_list,
            "imchecker": imchecker,
            "STATUS_PRO_TABLES": STATUS_PRO_TABLES
        })

        # 获取任务列表总和
        pro_tables_total = len(pro_user_list) + len(pro_publish_list) + len(pro_balance_list) + len(pro_backup_list) + len(pro_event_list)
        logger.info("len(pro_user_list): %s" % len(pro_user_list))
        logger.info("len(pro_publish_list): %s" % len(pro_publish_list))
        logger.info("len(pro_balance_list): %s" % len(pro_balance_list))
        logger.info("len(pro_backup_list): %s" % len(pro_backup_list))
        logger.info("len(pro_event_list): %s" % len(pro_event_list))
        data["pro_tables_total"] = pro_tables_total
        data["tasks_total"] = len(tasks_res.data)
        logger.info("total: %s" % pro_tables_total)
        logger.info("tasks_total: %s" % len(tasks_res.data))
        if do_publish:
            self.do_publish(user_id, action, **data)
        return self.success(data=data)
Exemplo n.º 15
0
    def get_res_tasks(self):
        logger.info("------[get_res_tasks]------")
        pro_id = self.params.get("pro_id", None)
        user_id = self.params.get("user_id", None)
        if not user_id:
            user_id = self.handler.current_user.id
        logger.info("user_id: %s" % user_id )
        svc = PtUserService(self.handler, {"user_id": user_id})
        user_res = svc.get_info()
        user = user_res.data if not isinstance(user_res, Exception) else None
        logger.info("user_info: %s" % user)
        # current_user = self.handler.current_user
        # if current_user:
        if user:
            # user_id = current_user.id
            # role_ids = [role.id for role in current_user.user_roles]
            # current_perms = current_user.current_perms
            current_perms = user.get_current_perms()
            logger.info("current_perms: %s" % current_perms)
            conditions = and_()
            if pro_id:
                conditions.append(Pro_Resource_Apply.pro_id == pro_id)
            or_conditions = or_()
            # 如果是管理员用户,查看所有项目申请提交的任务状态
            # 如果是普通用户,查看自己资源审批的任务状态
            if "pro_resource_apply.view" in current_perms.keys():
                conditions.append(Pro_Resource_Apply.user_id == user_id)
                logger.info("view user")
            conditions.append(or_conditions)

            resource_list = self.db.query(
                Pro_Resource_Apply
            ).filter(
                conditions
            ).order_by(
                Pro_Resource_Apply.update_time.desc()
            )
            task_list = []
            for resource in resource_list:
                histories = resource.act_pro_histories
                if len(histories) > 0:
                    last_history = histories[-1]
                    if "pro_resource_apply.check" in current_perms:
                        if last_history.status in [STATUS_RESOURCE.APPLIED,
                                                    STATUS_RESOURCE.PAYED, 
                                                    STATUS_RESOURCE.CONFIRMPAYED]:
                            if last_history.status == STATUS_RESOURCE.CONFIRMPAYED:
                                if last_history.checker_id == 0: 

                                    task_list.append(last_history)
                            else:
                                task_list.append(last_history)
                    if "pro_resource_apply.view" in current_perms.keys():
                        if last_history.status in [STATUS_RESOURCE.REFUSED,
                                                    STATUS_RESOURCE.UNKNOWN,
                                                    STATUS_RESOURCE.REVOKED,
                                                    STATUS_RESOURCE.CHECKED,
                                                    STATUS_RESOURCE.CONFIRMPAYED]:
                            if last_history.status == STATUS_RESOURCE.CONFIRMPAYED:
                                if not last_history.res_apply.start_date:
                                    task_list.append(last_history)
                            else:
                                task_list.append(last_history)

            logger.info(task_list)
            for last_history in task_list:
                logger.info("#"*60)
                logger.info(u"STATUS:%s(%s) - USER_ID:%s - CHECKER_ID:%s" % (last_history.status, STATUS_RESOURCE.get(last_history.status).value, last_history.user_id, last_history.checker_id))
                logger.info("#"*60)
            return self.success(data=task_list)
        else:
            return NotFoundError()
Exemplo n.º 16
0
    def publish_tasks(self,
                      user_id,
                      pro_id=None,
                      action="on_task",
                      do_publish=True):
        logger.info("------[publish_tasks]------")

        user_svc = PtUserService(self, {"user_id": user_id, "pro_id": pro_id})
        pt_user_res = user_svc.get_info()
        logger.info(pt_user_res)
        current_perms = pt_user_res.data.get_current_perms()
        imchecker = pt_user_res.data.imchecker
        # if "pro_resource_apply.check" in pt_user_res.data.get_current_perms():
        #     imchecker = True
        # else:
        #     imchecker = False
        # 获取任务列表
        svc = ActHistoryService(self, {"user_id": user_id, "pro_id": pro_id})
        tasks_res = svc.get_res_tasks()
        data = {
            "tasks_res": tasks_res,
            "task_list": tasks_res.data,
            "imchecker": imchecker,
            "current_perms": current_perms,
            "STATUS_RESOURCE": STATUS_RESOURCE
        }

        # 获取用户申请列表
        svc = ProUserService(self, {"user_id": user_id, "pro_id": pro_id})
        pro_user_list_res = svc.get_list()
        if imchecker:
            pro_user_list = [
                i for i in pro_user_list_res.data
                if i.status == STATUS_PRO_TABLES.APPLIED
            ]
        else:
            pro_user_list = [
                i for i in pro_user_list_res.data if i.status in
                [STATUS_PRO_TABLES.REFUSED, STATUS_PRO_TABLES.CHECKED]
            ]
        data.update({
            "pro_user_list": pro_user_list,
            "imchecker": imchecker,
            "STATUS_PRO_TABLES": STATUS_PRO_TABLES
        })
        # logger.info(pro_user_list)

        # 获取互联网发布申请列表
        svc = ApplyPublish(self, {"user_id": user_id, "pro_id": pro_id})
        pro_publish_list_res = svc.get_list()
        # logger.info(pro_publish_list_res.data)
        if imchecker:
            pro_publish_list = [
                i for i in pro_publish_list_res.data
                if i.status == STATUS_PRO_TABLES.APPLIED
            ]
        else:
            pro_publish_list = [
                i for i in pro_publish_list_res.data if i.status in
                [STATUS_PRO_TABLES.REFUSED, STATUS_PRO_TABLES.CHECKED]
            ]
        data.update({
            "pro_publish_list": pro_publish_list,
            "imchecker": imchecker,
            "STATUS_PRO_TABLES": STATUS_PRO_TABLES
        })

        # 获取负载均衡申请列表
        svc = ApplyLoadBalance(self, {"user_id": user_id, "pro_id": pro_id})
        pro_balance_list_res = svc.get_list()
        # logger.info(pro_balance_list_res.data)
        if imchecker:
            pro_balance_list = [
                i for i in pro_balance_list_res.data
                if i.status == STATUS_PRO_TABLES.APPLIED
            ]
        else:
            pro_balance_list = [
                i for i in pro_balance_list_res.data if i.status in
                [STATUS_PRO_TABLES.REFUSED, STATUS_PRO_TABLES.CHECKED]
            ]
        data.update({
            "pro_balance_list": pro_balance_list,
            "imchecker": imchecker,
            "STATUS_PRO_TABLES": STATUS_PRO_TABLES
        })

        # 获取定期备份申请列表
        svc = ApplyBackups(self, {"user_id": user_id, "pro_id": pro_id})
        pro_backup_list_res = svc.get_list()
        # logger.info(pro_backup_list_res.data)
        if imchecker:
            pro_backup_list = [
                i for i in pro_backup_list_res.data
                if i.status == STATUS_PRO_TABLES.APPLIED
            ]
        else:
            pro_backup_list = [
                i for i in pro_backup_list_res.data if i.status in
                [STATUS_PRO_TABLES.REFUSED, STATUS_PRO_TABLES.CHECKED]
            ]
        data.update({
            "pro_backup_list": pro_backup_list,
            "imchecker": imchecker,
            "STATUS_PRO_TABLES": STATUS_PRO_TABLES
        })

        # 获取定期备份申请列表
        svc = EventService(self, {"user_id": user_id, "pro_id": pro_id})
        pro_event_list_res = svc.get_list()
        # logger.info(pro_event_list_res.data)
        if imchecker:
            pro_event_list = [
                i for i in pro_event_list_res.data
                if i.status == STATUS_PRO_TABLES.APPLIED
            ]
        else:
            pro_event_list = [
                i for i in pro_event_list_res.data if i.status in
                [STATUS_PRO_TABLES.REFUSED, STATUS_PRO_TABLES.CHECKED]
            ]
        data.update({
            "pro_event_list": pro_event_list,
            "imchecker": imchecker,
            "STATUS_PRO_TABLES": STATUS_PRO_TABLES
        })

        # 获取任务列表总和
        pro_tables_total = len(pro_user_list) + len(pro_publish_list) + len(
            pro_balance_list) + len(pro_backup_list) + len(pro_event_list)
        logger.info("len(pro_user_list): %s" % len(pro_user_list))
        logger.info("len(pro_publish_list): %s" % len(pro_publish_list))
        logger.info("len(pro_balance_list): %s" % len(pro_balance_list))
        logger.info("len(pro_backup_list): %s" % len(pro_backup_list))
        logger.info("len(pro_event_list): %s" % len(pro_event_list))
        data["pro_tables_total"] = pro_tables_total
        data["tasks_total"] = len(tasks_res.data)
        logger.info("total: %s" % pro_tables_total)
        logger.info("tasks_total: %s" % len(tasks_res.data))
        if do_publish:
            self.do_publish(user_id, action, **data)
        return self.success(data=data)