예제 #1
0
 def get_model_ref_model(self, data_json):
     from app.ctrl.ctrl_project import CtrlProject
     from app.ctrl.ctrl_group import CtrlGroup
     proj_id = data_json.get('proj_id')
     accessToken = data_json.get('accessToken')
     username = data_json.get('username')
     try:
         if username in ("Admin", "Test_PMO", "Test_PL", "Test_GL"):
             model_list = CtrlProject().get_leaf_model(proj_id)
         else:
             project_root = CtrlGroup().get_project_root(
                 accessToken, proj_id)
             if not project_root:
                 return None, "您不在该项目体制中!"
             pmo = project_root.get('pmo')
             pl_username = project_root.get('username')
             if username == pmo.get('userName'):
                 model_list = CtrlProject().get_leaf_model(proj_id)
             elif pl_username == username:
                 model_list = CtrlProject().get_leaf_model(proj_id)
             else:
                 group_members = project_root.get('group_members')
                 model_list = self.get_gl_model_list(
                     group_members, username)
         data_list = []
         for model in model_list:
             model_id = model.get('model_id')
             model_ref = self.get_model_ref(proj_id, model_id)
             model['model_ref'] = model_ref
             model['model_list'] = []  # 前端要求加的
             data_list.append(model)
         return data_list, None
     except Exception as e:
         current_app.logger.error('%s' % str(e))
         return None, "服务异常!请联系管理员!"
예제 #2
0
 def get_role_by_cactus(self, data_json):
     """
     从cactus项目体制中获取用户角色
     :param proj_id:
     :param accessToken:
     :param model_id:
     :return:
     """
     try:
         role_list = []
         proj_id = data_json.get('proj_id')
         accessToken = data_json.get('accessToken')
         model_id = data_json.get('model_id')
         username = data_json.get('username')
         user = self.get_user_by_name(username)
         roles = CtrlRole().get_roles_by_user(user.user_id)
         if user.user_type == "TEST" or "Admin" in roles:
             perm_list = self.get_user_permission(user.user_id)
             return perm_list, None
         group_list = []
         if model_id:
             group_list = self.get_group_by_model(proj_id, model_id)
             if not group_list:
                 return role_list, "该模块还没分配组!"
         from app.ctrl.ctrl_group import CtrlGroup
         project_root = CtrlGroup().get_project_root(accessToken, proj_id)
         if not project_root:
             return [], None
         if project_root:
             pmo = project_root.get('pmo')
             if username == pmo.get('userName'):
                 role_list.append('PMO')
             pl_username = project_root.get('username')
             if pl_username == username:
                 role_list.append(project_root.get('user_role'))
             group_members = project_root.get('group_members')
             if group_members:
                 for group in group_members:
                     if username == group.get('username'):
                         if group.get('group_name') in group_list:
                             role_list.append(group.get('user_role'))
         if role_list:
             from app.ctrl.ctrl_permission import CtrlPermission
             perm_list = CtrlPermission().get_perm_by_role(role_list)
         else:
             if model_id:
                 perm_list = self.user_in_model_rel(proj_id, model_id, username, project_root)
             else:
                 perm_list = []
         return perm_list, None
     except Exception as e:
         db.session.rollback()
         current_app.logger.error('%s' % e)
         error = "服务异常!请联系管理员!"
         return None, error