Exemplo n.º 1
0
    def create_syndicate(self):
        name = self.get_argument("name","")
        desc = self.get_argument("desc","")
        uuid = self.get_argument("uuid","")
        user_name = self.get_argument("user_name","")
        telephone = self.get_argument("telephone","")
        self.logger.info("name:"+name+"  desc:"+desc+"  user_name:"+user_name+"  telephone:"+telephone)

        if name == "" or user_name == "" or telephone == "" or uuid == "":
            self.set_status(400)
            return {"result":False,'msg':err_msgs['PARAMS_MISSING']}

        usr_db = UserDao(session= self.session)
        # 一个超级运营员只允许管理一个集团
        if usr_db.exist_role_group_by_tel(telephone, Users.ROLE_SUP_MGR):
            result = {
                    'result': False,
                    'msg': err_msgs['ROLE_SUP_MGR_EXIST']
                }
            self.set_status(400)
            return result

        match, usr_id, user_name = usr_db.insert_user(user_name,telephone, Users.ROLE_SUP_MGR)
        if not match:
            result = {
                    'result': False,
                    'msg': err_msgs['TEL_NAME_NOT_MATCH'],
                    'name': user_name
                }
            self.set_status(400)
            return result

        token = self.request.headers.get("user_token",None)
        redis = RedisBase()
        token_info = redis.get_token_info(token)
        user_id = token_info['uuid']

        com_db = CompanyDao(session=self.session)
        # 当uuid已存在时插入失败,返回推荐uuid
        if not com_db.insert_company(name,desc,None,user_id,Company.NO_PARENT,uuid,None):
            result = {
                'result': False,
                'msg': err_msgs['COM_UUID_EXIST'],
                'recommendation': self.build_company_uuid(uuid)
            }
            self.set_status(400)
            return result

        usr_rle_db = UserConfDao(session=self.session)
        usr_rle_db.insert_role(usr_id,uuid,UserConf.SUB_ROLE_SUP_MGR,UserConf.TYPE_ROLE_SUPMGR)
        # 日志
        self.log_user_action(token_info.get("uuid"),"create_syndicate",uuid)

        result = {
            'result': True
        }
        return result
Exemplo n.º 2
0
    def edit_admins(self):

        user_id = self.get_argument("user_id", "")
        user_name = self.get_argument("user_name", "")
        telephone = self.get_argument("telephone", "")
        roles = self.get_arguments("role[]")
        self.logger.info("user_id:" + user_id + " username:"******"  telephone:" + telephone)

        if user_id == "" or user_name == "" or telephone == "":
            self.set_status(400)
            return {"result": False, 'msg': err_msgs['PARAMS_MISSING']}

        # 更新User表中的信息
        usr_db = UserDao(session=self.session)
        user_info = usr_db.user(user_id)
        old_tel = user_info['telephone']
        # 当手机号发生改变时判断该手机号是否存在
        if old_tel != telephone and usr_db.get_user_id_by_tel(telephone):
            result = {'result': False, 'msg': err_msgs['TEL_EXIST']}
            self.set_status(400)
            return result

        usr_db.update_user(user_id, user_name, telephone)

        usr_rle_db = UserConfDao(session=self.session)

        # 通知该用户,其已经发生变化。
        redis = RedisBase()
        redis.user_change(user_id, CODE_USER_MODIFIED, Users.ROLE_ADMIN)

        # 删除admin的相关信息
        usr_rle_db.delete_company_user(user_id, UserConf.ACC_COM_ID,
                                       UserConf.TYPE_ROLE_ADMIN)

        # 重新插入admin
        for role in roles:
            usr_rle_db.insert_role(user_id, UserConf.ACC_COM_ID, role,
                                   UserConf.TYPE_ROLE_ADMIN)
        # 日志
        self.log_user_action(self.get_token().get("uuid"), "edit_admin",
                             user_id)

        result = {'result': True}
        return result
Exemplo n.º 3
0
    def add_supmanager(self):
        user_name = self.get_argument("user_name", "")
        telephone = self.get_argument("telephone", "")
        syndicate = self.get_argument("syndicate", "")

        self.logger.info("username:"******"  telephone:" + telephone +
                         "  syndicate:" + syndicate)

        if user_name == '' or telephone == '' or syndicate == '':
            self.set_status(400)
            return {"result": False, 'msg': err_msgs['PARAMS_MISSING']}

        usr_db = UserDao(session=self.session)

        # 一个超级运营员只允许管理一个集团
        if usr_db.exist_role_group_by_tel(telephone, Users.ROLE_SUP_MGR):
            result = {'result': False, 'msg': err_msgs['ROLE_SUP_MGR_EXIST']}
            self.set_status(400)
            return result

        match, usr_id, user_name = usr_db.insert_user(user_name, telephone,
                                                      Users.ROLE_SUP_MGR)
        if not match:
            result = {
                'result': False,
                'msg': err_msgs['TEL_NAME_NOT_MATCH'],
                'name': user_name
            }
            self.set_status(400)
            return result

        usr_rle_db = UserConfDao(session=self.session)
        usr_rle_db.insert_role(usr_id, syndicate, UserConf.SUB_ROLE_SUP_MGR,
                               UserConf.TYPE_ROLE_SUPMGR)
        # 日志
        self.log_user_action(self.get_token().get("uuid"), "add_supmgr",
                             usr_id)

        result = {'result': True, 'user_id': usr_id}
        return result
Exemplo n.º 4
0
    def add_admin(self):
        user_name = self.get_argument("user_name", "")
        telephone = self.get_argument("telephone", "")
        roles = self.get_arguments("role[]")

        if user_name == '' or telephone == '':
            self.set_status(400)
            return {"result": False, 'msg': err_msgs['PARAMS_MISSING']}

        usr_db = UserDao(session=self.session)
        # 一个手机号只能存在一个管理员角色
        if usr_db.exist_role_group_by_tel(telephone, Users.ROLE_ADMIN):
            result = {'result': False, 'msg': err_msgs['ROLE_ADMIN_EXIST']}
            self.set_status(400)
            return result

        match, usr_id, user_name = usr_db.insert_user(user_name, telephone,
                                                      Users.ROLE_ADMIN)
        if not match:
            result = {
                'result': False,
                'msg': err_msgs['TEL_NAME_NOT_MATCH'],
                'name': user_name
            }
            self.set_status(400)
            return result

        usr_rle_db = UserConfDao(session=self.session)
        for role in roles:
            usr_rle_db.insert_role(usr_id, UserConf.ACC_COM_ID, role,
                                   UserConf.TYPE_ROLE_ADMIN)
        # 日志
        self.log_user_action(self.get_token().get("uuid"), "add_admin", usr_id)

        result = {'result': True, 'user_id': usr_id}
        return result
Exemplo n.º 5
0
    def edit_manager(self):

        user_id = self.get_argument("user_id", "")
        user_name = self.get_argument("user_name", "")
        telephone = self.get_argument("telephone", "")
        roles = self.get_arguments("role[]")

        # data = json.loads(self.request.body)
        # user_id = data.get("user_id","")
        # user_name = data.get("user_name","")
        # telephone = data.get("telephone","")
        # roles = data.get("role",[])

        self.logger.info("user_id:" + user_id + " username:"******"  telephone:" + telephone + "  roles:" +
                         ','.join(roles))

        if user_id == "" or user_name == "" or telephone == "" or roles == []:
            self.set_status(400)
            return {"result": False, 'msg': err_msgs['PARAMS_MISSING']}

        token = self.request.headers.get("user_token", None)
        redis = RedisBase()

        token_info = redis.get_token_info(token)
        company_uuid = token_info['company_uuid']

        # 更新User表中的信息
        usr_db = UserDao(session=self.session)
        user_info = usr_db.user(user_id)
        old_tel = user_info['telephone']
        # 当手机号发生改变时判断该手机号是否存在
        if old_tel != telephone and usr_db.get_user_id_by_tel(telephone):
            result = {'result': False, 'msg': err_msgs['TEL_EXIST']}
            self.set_status(400)
            return result

        usr_db.update_user(user_id, user_name, telephone)

        usr_rle_db = UserConfDao(session=self.session)

        # 通知该用户,其已经发生变化。
        redis = RedisBase()
        redis.user_change(user_id, CODE_USER_MODIFIED, Users.ROLE_MANAGER)

        # 下面的是东辉的版本 貌似不能用
        # 获取用户当前角色判断角色是否发生改变
        # roles_old = usr_rle_db.get_spec_roles(user_id,company_uuid,UserConf.TYPE_ROLE_MGR)
        # if sorted(roles_old) != sorted(roles):
        #     usr_status_db = UserLastStatusDao(session=self.session)
        #     statuses = usr_status_db.get_status_by_userid_and_role_group(user_id,Users.ROLE_MANAGER)
        #     for status in statuses:
        #         if company_uuid==status.company_uuid and redis.exists_token(status.token):
        #             mgr_token_info = redis.get_token_info(status.token)
        #             mgr_token_info['status'] = {
        #                 'code': CODE_USER_MODIFIED,
        #                 'msg': token_status[CODE_USER_MODIFIED]['msg']
        #             }
        #             redis.set_token(status.token,json.dumps(mgr_token_info),False)

        # 删除manager的相关信息
        usr_rle_db.delete_company_user(user_id, company_uuid,
                                       UserConf.TYPE_ROLE_MGR)

        # 重新插入manager
        for role in roles:
            usr_rle_db.insert_role(user_id, company_uuid, role,
                                   UserConf.TYPE_ROLE_MGR)
        # 日志
        self.log_user_action(token_info.get("uuid"), "edit_manager", user_id)

        result = {'result': True}
        return result
Exemplo n.º 6
0
    def add_viewer(self):
        user_name = self.get_argument("user_name", "")
        telephone = self.get_argument("telephone", "")
        role = self.get_argument("role", "")
        qq = self.get_argument("qq", "")
        weixin = self.get_argument("weixin", "")
        weibo = self.get_argument("weibo", "")

        self.logger.info("username:"******"  telephone:" + telephone +
                         "  roles:" + role + " qq:" + qq + " weixin:" +
                         weixin + " weibo:" + weibo)
        if user_name == "" or telephone == "" or role == "":
            self.set_status(400)
            return {"result": False, 'msg': err_msgs['PARAMS_MISSING']}

        token = self.request.headers.get("user_token", None)
        redis = RedisBase()
        token_info = redis.get_token_info(token)
        company_uuid = token_info['company_uuid']

        usr_db = UserDao(session=self.session)
        match, usr_id, user_name = usr_db.insert_user(
            user_name, telephone, Users.ROLE_VIEWER)  #增加用户。

        usr_rle_db = UserConfDao(session=self.session)
        if usr_rle_db.viewer_is_exist(usr_id,
                                      company_uuid):  # 判断当前用户在该公司是否存在观察者角色
            result = {'result': False, 'msg': err_msgs['VIEW_EXIST']}
            self.set_status(400)
            return result

        if not match:
            result = {
                'result': False,
                'msg': err_msgs['TEL_NAME_NOT_MATCH'],
                'name': user_name
            }
            self.set_status(400)
            return result

        usr_rle_db.insert_role(user_id=usr_id,
                               company_uuid=company_uuid,
                               role=role,
                               role_type=UserConf.TYPE_ROLE_VIEWER)

        if qq != '':
            usr_rle_db.insert_account(user_id=usr_id,
                                      type=UserConf.TYPE_QQ,
                                      account=qq)
        if weixin != '':
            usr_rle_db.insert_account(user_id=usr_id,
                                      type=UserConf.TYPE_WX,
                                      account=weixin)
        if weibo != '':
            usr_rle_db.insert_account(user_id=usr_id,
                                      type=UserConf.TYPE_WB,
                                      account=weibo)

        # 通知该用户,其已经发生变化。
        redis = RedisBase()
        redis.user_change(usr_id, CODE_USER_MODIFIED, Users.ROLE_VIEWER)
        # 日志
        self.log_user_action(token_info.get("uuid"), "add_viewer", usr_id)

        result = {'result': True, 'user_id': usr_id}

        return result
Exemplo n.º 7
0
    def edit_viewer(self):
        user_id = self.get_argument("user_id", "")
        user_name = self.get_argument("user_name", "")
        telephone = self.get_argument("telephone", "")
        role = self.get_argument("role", "")
        qq = self.get_argument("qq", "")
        weixin = self.get_argument("weixin", "")
        weibo = self.get_argument("weibo", "")

        self.logger.info("user_id:" + user_id + " username:"******"  telephone:" + telephone + "  roles:" + role +
                         " qq:" + qq + " weixin:" + weixin + " weibo" + weibo)
        if user_id == "" or user_name == "" or telephone == "" or role == "":
            self.set_status(400)
            return {"result": False, 'msg': err_msgs['PARAMS_MISSING']}

        token = self.request.headers.get("user_token", None)
        redis = RedisBase()

        token_info = redis.get_token_info(token)
        company_uuid = token_info['company_uuid']

        # 更新User表中的信息
        usr_db = UserDao(session=self.session)
        user_info = usr_db.user(user_id)
        old_tel = user_info['telephone']
        # 当手机号发生改变时判断该手机号是否存在
        if old_tel != telephone and usr_db.get_user_id_by_tel(telephone):
            result = {'result': False, 'msg': err_msgs['TEL_EXIST']}
            self.set_status(400)
            return result
        usr_db.update_user(user_id, user_name, telephone)

        # 删除user_conf表中对应的角色
        usr_rle_db = UserConfDao(session=self.session)
        usr_rle_db.delete_company_user(user_id, company_uuid,
                                       UserConf.TYPE_ROLE_VIEWER)

        # 插入新的角色
        usr_rle_db.insert_role(user_id, company_uuid, role,
                               UserConf.TYPE_ROLE_VIEWER)

        # 删除账户信息
        usr_rle_db.delete_account(user_id)

        # 插入账户信息
        if qq != '':
            usr_rle_db.insert_account(user_id=user_id,
                                      type=UserConf.TYPE_QQ,
                                      account=qq)
        if weixin != '':
            usr_rle_db.insert_account(user_id=user_id,
                                      type=UserConf.TYPE_WX,
                                      account=weixin)
        if weibo != '':
            usr_rle_db.insert_account(user_id=user_id,
                                      type=UserConf.TYPE_WB,
                                      account=weibo)

        # 通知该用户,其已经发生变化。
        redis = RedisBase()
        redis.user_change(user_id, CODE_USER_MODIFIED, Users.ROLE_VIEWER)
        # 日志
        self.log_user_action(token_info.get("uuid"), "edit_viewer", user_id)

        result = {'result': True}

        return result
Exemplo n.º 8
0
            return result

        if not match:
            result = {
                'result': False,
                'msg': err_msgs['TEL_NAME_NOT_MATCH'],
                'name': user_name
            }
            self.set_status(400)
            return result

        company_roles = []
        try:
            for role in roles:
                usr_rle_db.insert_role(user_id=usr_id,
                                       company_uuid=company_uuid,
                                       role=role,
                                       role_type=UserConf.TYPE_ROLE_MGR)

            company_roles = usr_rle_db.get_manager_companies(usr_id)
        except Exception, e:
            self.logger.error(traceback.format_exc())

        # 通知该用户,其已经发生变化。
        redis = RedisBase()
        redis.user_change(usr_id, CODE_USER_MODIFIED, Users.ROLE_MANAGER)
        # 日志
        self.log_user_action(self.get_token().get("uuid"), "add_manager",
                             usr_id)

        result = {
            'result': True,