Beispiel #1
0
 def saveInterface(self, name, path, method, desc, id=""):
     try:
         if id:
             interface = self.getById(id)
             if interface:
                 interface.name = name
                 interface.method = method
                 interface.desc = desc
                 interface.path = path
                 self.session.commit()
                 return True, ""
         else:
             check_path_method = self.db_obj.filter(
                 self.table.path == path,
                 self.table.method == method).first()
             if check_path_method:
                 return False, u"方法和路径必须唯一"
             add_interface = self.table(name=name,
                                        path=path,
                                        method=method,
                                        desc=desc,
                                        id=create_id())
             self.session.add(add_interface)
             self.session.commit()
             return True, add_interface
     except Exception as e:
         LOG.error("save_interface: {}".format(e))
         self.session.rollback()
         return False, ""
     return True, ""
Beispiel #2
0
    def saveRoleFunction(self, roleId, permission):
        try:
            role_data = self.db_obj.filter(self.table.roleId == roleId).all()
            if len(permission) == 0:
                for data in role_data:
                    self.session.delete(data)
                    self.session.commit()
                return True, ""
            else:
                for item in role_data:
                    if item.menuId in permission:
                        permission.remove(item.menuId)
                        continue
                    else:
                        self.session.delete(item)
                        self.session.commit()
                for i in permission:
                    add_data = self.table(roleId=roleId,
                                          menuId=i,
                                          id=create_id())
                    self.session.add(add_data)
                    self.session.commit()
                return True, ""

        except Exception as e:
            LOG.error(e)
            return False, ""
Beispiel #3
0
 def saveRole(self, name, code, desc, isLock=False, id=None):
     check_name = self.db_obj.filter(self.table.name == name).first()
     if check_name and check_name.id != id:
         return False, ""
     check_code = self.db_obj.filter(self.table.code == code).first()
     if check_code and check_code.id != id:
         return False, ""
     try:
         if id:
             role = self.db_obj.filter(self.table.id == id).first()
             if role:
                 role.name = name
                 role.code = code
                 role.desc = desc
                 role.isLock = isLock
                 self.session.commit()
         else:
             add_role = self.table(name=name,
                                   code=code,
                                   desc=desc,
                                   isLock=isLock,
                                   id=create_id())
             self.session.add(add_role)
             self.session.commit()
     except Exception as e:
         LOG.error("save_user: {}".format(e))
         self.session.rollback()
         return False, ""
     return True, ""
Beispiel #4
0
def make_auth_file(key):
    tmp_key_file = "%s/%s/.%s" % (PATH_APP_ROOT, "keys", create_id())
    status, msg = check_ssh_key(key)
    if status:
        with open(tmp_key_file, "wb+") as tkf:
            tkf.write(msg)
            os.system("chmod 600 %s" % tmp_key_file)
            return True, tmp_key_file
    else:
        return False, ""
Beispiel #5
0
 def saveMenu(self,
              parentId,
              title,
              icon,
              sort,
              _type,
              isLock=False,
              desc="",
              permission="",
              path="",
              id=""):
     try:
         if id and id != "0":
             menu = self.getMenuById(id)
             if menu:
                 menu.title = title
                 menu.type = int(_type)
                 menu.isLock = isLock
                 menu.icon = icon
                 menu.permission = permission
                 menu.sort = sort
                 self.session.commit()
                 return True, ""
         check_permission = self.db_obj.filter(
             self.table.permission == permission,
             self.table.type == int(_type)).first()
         if check_permission:
             return False, "权限标识已经存在"
         if int(_type) == 1:
             check_path = self.db_obj.filter(
                 self.table.path == path).first()
             if check_path:
                 return False, "前端路径已经存在"
         add_menu = self.table(parentId=parentId,
                               path=path,
                               title=title,
                               icon=icon,
                               permission=permission,
                               type=int(_type),
                               sort=sort,
                               isLock=isLock,
                               desc=desc,
                               id=create_id())
         self.session.add(add_menu)
         self.session.flush()
         self.session.commit()
         return True, add_menu
     except Exception as e:
         LOG.error("save_user: {}".format(e))
         self.session.rollback()
         return False, ""
Beispiel #6
0
    def saveUser(self,
                 user="",
                 realName="",
                 password="",
                 email="",
                 phone="",
                 id=None,
                 isLock=False):
        check_user = self.db_obj.filter(self.table.name == user).first()
        if check_user and check_user.id != id:
            return False, u"用户已经存在"

        check_email = self.db_obj.filter(self.table.email == email).first()
        if check_email and check_email.id != id:
            return False, u"邮箱已经存在"

        try:
            if id:
                userobj = self.db_obj.filter(self.table.id == id).first()
                if userobj:
                    if user:
                        userobj.name = user
                    if email:
                        userobj.email = email
                    if realName:
                        userobj.realName = realName
                    if password:
                        userobj.password = password
                    if phone:
                        userobj.phone = phone
                    userobj.isLock = False
                    self.session.commit()
                    return True, userobj
            else:
                add_user = self.table(name=user,
                                      realName=realName,
                                      password=password,
                                      email=email,
                                      phone=phone,
                                      isLock=isLock,
                                      id=create_id(),
                                      create_at=datetime.datetime.now())
                self.session.add(add_user)
                self.session.commit()
                return True, add_user
        except Exception as e:
            LOG.error("save_user: {}".format(e))
            self.session.rollback()
            return False, ""
        return True, ""
Beispiel #7
0
 def saveRoute(self,
               parentId="",
               name="",
               path="",
               title="",
               component="",
               sort="",
               componentPath="",
               isLock=False,
               cache=True,
               permission="",
               id=""):
     try:
         if id and id != "0":
             route = self.getRouteById(id)
             if route:
                 route.title = title,
                 route.path = path
                 route.isLocak = isLock,
                 route.name = name
                 route.permission = permission
                 route.sort = sort
                 route.component = component,
                 route.componentPath = componentPath,
                 route.cache = cache
                 self.session.commit()
                 return True, ""
         else:
             add_route = self.table(parentId=parentId,
                                    path=path,
                                    name=name,
                                    title=title,
                                    permission=permission,
                                    component=component,
                                    componentPath=componentPath,
                                    sort=sort,
                                    isLock=isLock,
                                    cache=cache,
                                    id=create_id())
             self.session.add(add_route)
             self.session.flush()
             self.session.commit()
             return True, add_route
     except Exception as e:
         import traceback
         traceback.print_exc()
         LOG.error("save_route: {}".format(e))
         self.session.rollback()
         return False, ""
Beispiel #8
0
    def saveFunctionInterface(self, action, funcrionId, interfaceId):
        functioninterface = self.db_obj.filter(
            self.table.menuId == funcrionId,
            self.table.interfaceId == interfaceId).first()

        if action == 0 and functioninterface:
            self.session.delete(functioninterface)
            self.session.commit()
            return True
        elif action == 1 and not functioninterface:
            add_data = self.table(menuId=funcrionId,
                                  interfaceId=interfaceId,
                                  id=create_id())
            self.session.add(add_data)
            self.session.commit()
            return True
        else:
            return False
Beispiel #9
0
 def saveRoleUser(self, action, roleId, userId):
     try:
         roleuser = self.db_obj.filter(self.table.userId == userId,
                                       self.table.roleId == roleId).first()
         if action == 1 or action == "1":
             if not roleuser:
                 add_roleuser = self.table(userId=userId,
                                           roleId=roleId,
                                           id=create_id())
                 self.session.add(add_roleuser)
             else:
                 return False, "已经存在"
         if action == "0" or action == 0:
             self.session.delete(roleuser)
         self.session.commit()
         return True, ""
     except Exception as e:
         LOG.error("save_interface: {}".format(e))
         self.session.rollback()
         return False, ""
     return True, ""