Exemple #1
0
 def get_env(self):
     logger.info("------[get_env]------")
     env_id = self.params.get("env_id")
     env = self.db.query(Env_Info).filter(Env_Info.id == env_id).first()
     if not env:
         raise NotFoundError()
     return self.success(data=env)
Exemple #2
0
 def get_info(self):
     logger.info("------[get_info]------")
     perm_id = self.params.get("perm_id")
     pt_perm = svc.db.query(PT_Perm).filter(PT_Perm.id == perm_id).first()
     if pt_perm:
         return self.success(data=projects)
     else:
         return NotFoundError()
Exemple #3
0
    def set_profile(self):
        logger.info("------[set_profile]------")
        user_id = int(self.params.get("user_id"))
        username = self.params.get("username")
        email = self.params.get("email")
        mobile = self.params.get("mobile")
        current_user = self.handler.current_user
        if current_user:
            if current_user.id != user_id:
                raise NotFoundError()
            if not username:
                return self.failure(ERROR.username_empty_err)
            if not email:
                return self.failure(ERROR.email_empty_err)
            if not mobile:
                return self.failure(ERROR.mobile_empty_err)
            user = self.db.query(PT_User).filter(PT_User.id == user_id).first()
            username_duplicate = self.db.query(PT_User).filter(
                PT_User.id != user_id, PT_User.username == username).first()
            logger.info(username_duplicate)
            if username_duplicate:
                return self.failure(ERROR.username_duplicate_err)
            email_duplicate = self.db.query(PT_User).filter(
                PT_User.id != user_id, PT_User.email == email).first()
            if email_duplicate:
                return self.failure(ERROR.email_duplicate_err)
            mobile_duplicate = self.db.query(PT_User).filter(
                PT_User.id != user_id, PT_User.mobile == mobile).first()
            if mobile_duplicate:
                return self.failure(ERROR.mobile_duplicate_err)
            user.username = username
            user.email = email
            user.mobile = mobile.replace(' ', '')
            self.db.add(user)
            self.db.flush()
            logger.info("*" * 60)
            logger.info(user.username)
            logger.info("*" * 60)
            login = LoginService(self.handler)
            login.set_user_attrs(user)

            # res = project.as_dict()
            # logger.info("project: %s" % res)
            return self.success(data=user)
        else:
            return NotFoundError()
Exemple #4
0
 def get_profile(self):
     logger.info("------[get_profile]------")
     current_user_id = self.handler.current_user.id
     if current_user_id:
         pt_user = self.db.query(PT_User).filter(
             PT_User.id == current_user_id).first()
         return self.success(data=pt_user)
     else:
         return NotFoundError()
Exemple #5
0
 def get_info(self):
     logger.info("------[get_info]------")
     logger.info(self.params)
     logger.info(self.handler.args)
     role_id = self.params.get("role_id")
     logger.info(role_id)
     pt_role = self.db.query(PT_Role).filter(PT_Role.id == role_id).first()
     if pt_role:
         data = {"pt_role": pt_role, "sys_groups": sys_groups}
         return self.success(data=data)
     else:
         return NotFoundError()
Exemple #6
0
 def confirm_start_date(self):
     task_id = self.params.get("task_id")
     act = self.db.query(
         Act_Pro_History
     ).filter(
         Act_Pro_History.id == task_id
     ).first()
     if act:
         act.checker_id = self.handler.current_user.id
         self.db.add(act)
         self.db.flush()
         return self.success()
     else:
         return NotFoundError()
Exemple #7
0
 def get_info(self):
     logger.info("------[get_info]------")
     logger.info(self.params)
     logger.info(self.handler.args)
     user_id = self.params.get("user_id")
     logger.info(user_id)
     pt_user = self.db.query(
         PT_User
     ).filter(
         PT_User.id == user_id
     ).first()
     if pt_user:
         return self.success(data=pt_user)
     else:
         return NotFoundError()
Exemple #8
0
 def update_info(self):
     logger.info("------ [update_info] ------")
     role_id = self.params.get("role_id")
     name = self.params.get("name", "")
     desc = self.params.get("desc")
     remark = self.params.get("remark")
     role = self.db.query(PT_Role).filter(PT_Role.id == role_id, ).first()
     if role:
         role.name = name
         role.desc = desc
         role.remark = remark
         self.db.add(role)
         self.db.flush()
         return self.success(data={"is_success": True})
     else:
         return NotFoundError()
Exemple #9
0
 def edit_env(self):
     logger.info("------[edit_env]------")
     env_id = self.params.get("env_id")
     name = self.params.get("name")
     desc = self.params.get("desc")
     if not name:
         return self.failure(ERROR.env_name_empty_err)
     if not desc:
         return self.failure(ERROR.env_desc_empty_err)
     env = self.db.query(Env_Info).filter(Env_Info.id == env_id).first()
     if not env:
         raise NotFoundError()
     env.name = name
     env.desc = desc
     self.db.add(env)
     self.db.flush()
     return self.success(data=env)
Exemple #10
0
    def get_last_apply(self):
        logger.info("------[get_profile]------")
        current_user = self.handler.current_user
        if current_user:
            last_apply = self.db.query(
                Act_Pro_History
            ).filter(
                Act_Pro_History.user_id == current_user.id
            ).order_by(
                Act_Pro_History.create_time.desc()
            ).first()

            # res = project.as_dict()
            # logger.info("project: %s" % res)
            return self.success(data=last_apply)
        else:
            return NotFoundError()
Exemple #11
0
    def get_list(self):
        logger.info("------[get_profile]------")
        current_user = self.handler.current_user
        if current_user:
            history_list = self.db.query(
                Act_History
            ).filter(
                Act_History.user_id == current_user.id
            ).order_by(
                Act_History.id.desc()
            ).limit(10)

            # res = project.as_dict()
            # logger.info("project: %s" % res)
            return self.success(data=history_list)
        else:
            return NotFoundError()
 def do_pay(self):
     logger.info("\t [ DO PAY ]")
     res_id = self.params.get("res_id", 0)
     user_id = self.params.get("user_id", 0)
     user_id = self.handler.current_user.id
     resource_query = self.db.query(Pro_Resource_Apply).filter(
         Pro_Resource_Apply.id == res_id)
     logger.info("\t [QUERY] : %s" % resource_query)
     resource = resource_query.first()
     if not resource:
         # return self.failure(ERROR.not_found_err)
         return NotFoundError()
     # 状态不为0(即:不是提交状态),不允许撤销
     logger.info("\t [resource.status]: %s" % resource.status)
     logger.info("\t [STATUS_RESOURCE.CHECKED]: %s" %
                 STATUS_RESOURCE.CHECKED)
     logger.info("\t change to [STATUS_RESOURCE.PAYED]: %s" %
                 STATUS_RESOURCE.PAYED)
     if resource.status != STATUS_RESOURCE.CHECKED:
         return self.failure(ERROR.res_pay_err)
     resource.status = STATUS_RESOURCE.PAYED
     self.db.add(resource)
     self.db.flush()
     mail_html = self.render_to_string(
         "admin/mail/pro_resource_apply_to_admin.html",
         resource_apply=resource,
         STATUS_RESOURCE=STATUS_RESOURCE)
     mail_title = mail_title_format % {
         "user_name": resource.user.email or resource.user.mobile,
         "pro_name": resource.project.name,
         "res_desc": resource.desc,
         "action": u"申请的",
         "todo_action": u"资源,已完成支付,请确认收款",
     }
     sendMail.delay("*****@*****.**", admin_emails, mail_title,
                    mail_html)
     task_post_pro_res_apply_history.delay(status=resource.status,
                                           content=mail_title,
                                           pro_id=resource.project.id,
                                           res_apply_id=resource.id,
                                           user_id=user_id)
     # from scloud.views.admin.ws.pubsub import r
     # r.publish("test_realtime", "notice_checker")
     return self.success(data=resource)
Exemple #13
0
 def update_info(self):
     logger.info("------ [update_info] ------")
     user_id = self.params.get("user_id")
     username = self.params.get("username", "")
     email = self.params.get("email", "")
     mobile = self.params.get("mobile", "")
     password = self.params.get("password")
     user_filter = self.db.query(
         PT_User
     ).filter(
         PT_User.id == user_id,
     )
     user = user_filter.first()
     if user:
         user.username = username
         user.email = email
         user.mobile = mobile
         if password:
             user.password = password
         self.db.add(user)
         return self.success(data={"pt_user": user})
     else:
         return NotFoundError()
Exemple #14
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()