Exemple #1
0
    def from_appstruct(self, appstruct):
        if 'id' in appstruct:
            if appstruct['id'] != self.id:
                print "ID in appstruct does not match: {} - {}".format(type(appstruct['id']), type(self.id))
                raise ValueError

        if 'dc' in appstruct:
            self.dc = appstruct['dc']

        self.name = appstruct['name']
        self.oneliner = appstruct['oneliner']
        self.description = appstruct['description']
        self.website = appstruct['website']

        if 'logo_path' in appstruct:
            self.logo = appstruct['logo_path']

        new_poc_ids = set([p['id'] for p in appstruct['pocs'] if p['id'] != -1])
        cur_poc_ids = set([p.id for p in self.pocs])
        del_poc_ids = cur_poc_ids - new_poc_ids

        if len(del_poc_ids):
            for poc in self.pocs:
                if poc.id in del_poc_ids:
                    DBSession.delete(poc)

        for poc in appstruct['pocs']:
            if poc['id'] in cur_poc_ids:
                cur_poc = [p for p in self.pocs if p.id == poc['id']][0]
                cur_poc.from_appstruct(poc)
            else:
                npoc = POC()
                npoc.from_appstruct(poc)
                self.pocs.append(npoc)
Exemple #2
0
    def find_defcon_villages(cls, num):
        l = DBSession.query(cls).filter(cls.id == num).join(cls.cve).filter(CVEBase.type == 'village').options(contains_eager('cve')).all()

        if len(l) == 0:
            return None

        return l[0]
Exemple #3
0
    def validate_user_password(cls, username, password):
        user = DBSession.query(cls).options(noload(cls.groups)).filter(cls.username == username.lower()).first()

        if user is None:
            return None

        manager = BCRYPTPasswordManager()
        if manager.check(user.credentials, password):
            return user

        return None
Exemple #4
0
 def find_tickets(cls, cve_id):
     return DBSession.query(cls).filter(cls.cve_id == cve_id).order_by(cls.created.asc()).all()
Exemple #5
0
 def count_tickets(cls, cve_id):
     return DBSession.query(func.count(cls.id)).filter(cls.cve_id == cve_id).all()
Exemple #6
0
 def find(cls, type, value):
     return DBSession.query(cls).filter(cls.type == type, cls.name == value.lower()).first()
Exemple #7
0
 def find_group_by_id(cls, id):
     return DBSession.query(cls).get(id)
Exemple #8
0
 def find_group(cls, name):
     return DBSession.query(cls).filter(cls.name == name).first()
Exemple #9
0
    def from_appstruct(self, appstruct):
        super(Village, self).from_appstruct(appstruct)

        self.hrsofoperation = appstruct['hrsofoperation']
        self.spacereq = appstruct['spacereq']
        self.tables = appstruct['tables']
        self.chairs = appstruct['chairs']
        self.signage = appstruct['signage']
        self.projectors = appstruct['projectors']
        self.screens = appstruct['screens']
        self.numparticipants = appstruct['numparticipants']
        self.years = appstruct['years']
        self.quiet_time = appstruct['quiet_time']
        self.sharing = appstruct['sharing']

        new_power_ids = set([p['id'] for p in appstruct['power'] if p['id'] != -1])
        cur_power_ids = set([p.id for p in self.power])
        del_power_ids = cur_power_ids - new_power_ids

        if len(del_power_ids):
            for power in self.power:
                if power.id in del_power_ids:
                    DBSession.delete(power)

        for power in appstruct['power']:
            if power['id'] in cur_power_ids:
                cur_power = [p for p in event.power if p.id == power['id']][0]
                cur_power.from_appstruct(power)
            else:
                npower = Power()
                npower.from_appstruct(power)
                self.power.append(npower)

        new_drop_ids = set([d['id'] for d in appstruct['drops'] if d['id'] != -1])
        cur_drop_ids = set([d.id for d in self.drops])
        del_drop_ids = cur_drop_ids - new_drop_ids

        if len(del_drop_ids):
            for drop in self.drops:
                if drop.id in del_drop_ids:
                    DBSession.delete(drop)

        for drop in appstruct['drops']:
            if drop['id'] in cur_drop_ids:
                cur_drop = [d for d in self.drops if d.id == drop['id']][0]
                cur_drop.from_appstruct(drop)
            else:
                ndrop = WiredInternet()
                ndrop.from_appstruct(drop)
                self.drops.append(ndrop)

        new_ap_ids = set([a['id'] for a in appstruct['aps'] if a['id'] != -1])
        cur_ap_ids = set([a.id for a in self.aps])
        del_ap_ids = cur_ap_ids - new_ap_ids

        if len(del_ap_ids):
            for ap in self.aps:
                if ap.id in del_ap_ids:
                    DBSession.delete(ap)

        for ap in appstruct['aps']:
            if ap['id'] in cur_ap_ids:
                cur_ap = [a for a in self.aps if a.id == ap['id']][0]
                cur_ap.from_appstruct(appstruct)
            else:
                nap = AccessPoint()
                nap.from_appstruct(ap)
                self.aps.append(nap)
Exemple #10
0
 def find_user_by_email(cls, email):
     return DBSession.query(cls).filter(cls.email == email.lower()).first()
Exemple #11
0
 def find_user_no_groups(cls, username):
     return DBSession.query(cls).options(noload(cls.groups)).filter(cls.username == username.lower()).first()
Exemple #12
0
 def find_user(cls, username):
     return DBSession.query(cls).filter(cls.username == username.lower()).first()
Exemple #13
0
 def find_ticket_username(cls, ticket, username):
     return DBSession.query(cls).join(User, and_(User.username == username.lower(), User.id == cls.user_id)).filter(cls.ticket == ticket).options(contains_eager('user')).first()
Exemple #14
0
 def find_defcon(cls, num):
     return DBSession.query(cls).filter(cls.id == num).first()