Пример #1
0
 def add(self, key, desc):
     sf = SessionFactory.new()
     num = sf.query(func.count(SecurityPoint.id)).filter(SecurityPoint.key_ == key).limit(1).scalar()
     if num > 0:
         return False
     sp = SecurityPoint()
     sp.category = self.category
     sp.group_ = self.group
     sp.key_ = key
     sp.description = desc
     sf.add(sp)
     sf.commit()
     return True
Пример #2
0
def reg_point(key, category="", group_="", description=""):
    """
    :param key: 必须唯一,如果在系统中重复将被忽略掉
    :param category:分类
    :param group_:分类下的分组
    :param description:此安全点的用途
    :return:无返回值
    """
    if not key:
        return
    for sp in ObjectPool.points:
        if sp.key_ == key:
            return
    point = SecurityPoint()
    point.key_ = key
    point.description = description
    point.group_ = group_
    point.category = category
    ObjectPool.points.append(point)
Пример #3
0
 def assign_points_to_superadmin(role_id):
     cnn = SessionFactory.new()
     role_ = cnn.query(Role).get(role_id)
     changes = list()
     for point in ObjectPool.points:
         p = cnn.query(SecurityPoint).filter(SecurityPoint.key_ == point.key_).limit(1).scalar()
         if p:
             p.category = point.category
             p.group_ = point.group_
             p.description = point.description
             changes.append(p)
         else:
             new_point = SecurityPoint()
             new_point.key_ = point.key_
             new_point.category = point.category
             new_point.group_ = point.group_
             new_point.description = point.description
             cnn.add(new_point)
             new_point.roles.append(role_)
     cnn.commit()