def create_api_key(self, user_id: str) -> str: existing = self.get(user_id) if existing is None: raise ValueError("No user found for '{}'".format(user_id)) new_key = secrets.token_hex(16) _ = self.update_one(AbstractMongoStore.id_query(user_id), AbstractMongoStore.set_update("apiKey", new_key)) return new_key
def update_meta(self, data_id, meta_update): if "relations" not in meta_update: meta_update["relations"] = [] update_keys = ["label", "assignments", "relations"] update_values = [ meta_update["label"], meta_update["assignments"], meta_update["relations"] ] if "payload" in meta_update: for payload_key in meta_update["payload"]: update_keys.append("payload.{}".format(payload_key)) update_values.append(meta_update["payload"][payload_key]) update = AbstractMongoStore.set_update(update_keys, update_values) return self.collection.update_one(AbstractMongoStore.id_query(data_id), update)
def change_password(self, user_id, new_password) -> User: self.update_one( AbstractMongoStore.id_query(user_id), AbstractMongoStore.set_update( "password", UserStore._md5_password(new_password))) return self.get(user_id)
def update_profile(self, user_id, new_profile) -> User: self.update_one(AbstractMongoStore.id_query(user_id), AbstractMongoStore.set_update("profile", new_profile)) return self.get(user_id)
def update_permissions(self, user_id, permissions) -> User: self.update_one( AbstractMongoStore.id_query(user_id), AbstractMongoStore.set_update("permissions", permissions)) return self.get(user_id)
def update_target_file(self, doc_id, target_path): return self.update_one( AbstractMongoStore.id_query(doc_id), AbstractMongoStore.set_update("payload.targetFile", target_path))