def make_user(cls, login, password, email, full_name, role, initiator_id=None, external_id=None): """Creates new user model, storing it into database.""" model = cls() model.login = login model.password_hash = passwords.hash_password(password) model.email = email model.full_name = full_name model.role = role model.initiator = initiator_id model.external_id = external_id try: model.save() except pymongo.errors.DuplicateKeyError as exc: raise exceptions.UniqueConstraintViolationError() from exc return model
def insert_document(self, db_document): """Inserts DB structure into the MongoDB.""" try: return self.collection().insert(db_document) except pymongo.errors.DuplicateKeyError as exc: raise exceptions.UniqueConstraintViolationError() from exc
def check_constraints(self): super().check_constraints() query = {"is_latest": True, "time_deleted": 0, "name": self.name} if self.model_id: query["model_id"] = {"$ne": self.model_id} if self.collection().find_one(query): raise exceptions.UniqueConstraintViolationError()
def check_constraints(self): super().check_constraints() query = { "time_deleted": 0, "$or": [ {"name": self.name}, {"fqdn": self.fqdn}, {"ip": self.ip}, ] } if self.model_id: query["model_id"] = {"$ne": self.model_id} if self.collection().find_one(query): raise exceptions.UniqueConstraintViolationError()
def check_constraints(self): super().check_constraints() query = { "model_id": { "$ne": self.model_id }, "is_latest": True, "time_deleted": 0, "$or": [{ "email": self.email }, { "login": self.login }] } if self.model_id: query["model_id"] = {"$ne": self.model_id} if self.collection().find_one(query): raise exceptions.UniqueConstraintViolationError()