def add(self, did, domain, flags=None, force=False): dflags = self.default_flags() fmask = parse_flags(flags) flags = new_flags(dflags, fmask) canonical = is_canonical(flags) if self.exist(did, domain): if force: return raise Error (EDUPL, errstr(did=did, domain=domain)) # set digest realm attr da = self.Domain_attrs(self.dburi, self.db) da.set_default(did, 'digest_realm', domain) # update canonical flag cnd, err = cond(CND_NO_DELETED, did=did) rows = self.db.select(self.TABLE, self.COLUMNS, cnd) canon_exist = False for row in rows: if not is_canonical(row[self.FLAGIDX]): continue if not canonical: canon_exist = True break f = clear_canonical(row[self.FLAGIDX]) cnd = full_cond(self.COLUMNS, row) self.db.update(self.TABLE, {'flags':f}, cnd) if not canonical and not canon_exist: flags = set_canonical(flags) # add new domain ins = { 'did' : did, 'domain' : domain, 'flags' : flags } self.db.insert(self.TABLE, ins)
def change(self, uid, uri, flags=None, force=False): fmask = parse_flags(flags) nflags = new_flags(0, fmask) canonical = is_canonical(nflags) try: username, did = self.uri2id(uri) except: if force: return raise cndt, err = cond(CND_NO_DELETED, uid=uid, username=username, did=did) if not self.exist(uid, username, did): if force: return raise Error (ENOREC, err) # clear canon if canonical: cnd, err = cond(CND_NO_DELETED, uid=uid) cnd.append(CND_CANONICAL) rows = self.db.select(self.TABLE, self.COLUMNS, cnd) for row in rows: nf = clear_canonical(row[self.FLAGIDX]) cnd = full_cond(self.COLUMNS, row) self.db.update(self.TABLE, {'flags':nf}, cnd) # update flags rows = self.db.select(self.TABLE, self.COLUMNS, cndt) if not rows and not force: raise Error (ENOREC, err) for row in rows: nf = new_flags(row[self.FLAGIDX], fmask) cnd = full_cond(self.COLUMNS, row) self.db.update(self.TABLE, {'flags':nf}, cnd)
def change_domain(self, domain, flags=None, force=False): upd = {} fmask = parse_flags(flags) nflags = new_flags(0, fmask) canonical = is_canonical(nflags) # get did try: did = self.get_did(domain) except: if force: return raise # clear canon if canonical: cnd, err = cond(CND_NO_DELETED, did=did) cnd.append(CND_CANONICAL) rows = self.db.select(self.TABLE, self.COLUMNS, cnd) for row in rows: nf = clear_canonical(row[self.FLAGIDX]) cnd = full_cond(self.COLUMNS, row) upd = {'flags':nf} self.db.update(self.TABLE, upd, cnd) # update flags cnd, err = cond(CND_NO_DELETED, domain=domain) rows = self.db.select(self.TABLE, self.COLUMNS, cnd) if not rows and not force: raise Error (ENOREC, err) for row in rows: nf = new_flags(row[self.FLAGIDX], fmask) cnd = full_cond(self.COLUMNS, row) self.db.update(self.TABLE, {'flags':nf}, cnd)
def add(self, uid, uri, flags=None, force=False): dflags = self.default_flags() fmask = parse_flags(flags) flags = new_flags(dflags, fmask) canonical = is_canonical(flags) try: username, did = self.uri2id(uri) except: if force: return raise us = self.User(self.dburi, self.db) if not us.exist(uid) and not force: raise Error (ENOUSER, uid) if self.exist(uid, username, did): if force: return raise Error (EDUPL, username) # update canonical flag cnd, err = cond(CND_NO_DELETED, uid=uid) rows = self.db.select(self.TABLE, self.COLUMNS, cnd) canon_exist = False for row in rows: if not is_canonical(row[self.FLAGIDX]): continue if not canonical: canon_exist = True break f = clear_canonical(row[self.FLAGIDX]) cnd = full_cond(self.COLUMNS, row) self.db.update(self.TABLE, {'flags':f}, cnd) if not canonical and not canon_exist: flags = set_canonical(flags) # add new URI ins = { 'uid' : uid, 'did' : did, 'username' : username, \ 'flags' : flags } self.db.insert(self.TABLE, ins)