def put(self, item_id, item): for fieldname in "configuration", "name": if fieldname in self.request_json["data"]: setattr(item, fieldname, self.request_json["data"][fieldname]) item.initiator_id = self.initiator_id try: item.save() except base_exceptions.CannotUpdateDeletedModel as exc: LOG.warning( "Cannot update playbook configuration %s (deleted at %s, " "version %s)", item_id, item.time_deleted, item.version) raise http_exceptions.CannotUpdateDeletedModel() from exc except base_exceptions.UniqueConstraintViolationError as exc: LOG.warning( "Cannot update playbook configuration %s " "(unique constraint violation)", self.request_json["data"]["name"]) raise http_exceptions.CannotUpdateModelWithSuchParameters() \ from exc LOG.info("Playbook configuration %s was updated by %s", item_id, self.initiator_id) return item
def put(self, item_id, item): item.name = self.request_json["data"]["name"] item.initiator_id = self.initiator_id try: item.save() except base_exceptions.CannotUpdateDeletedModel as exc: LOG.warning( "Cannot update deleted model %s (deleted at %s, " "version %s)", item.model_id, item.time_deleted, item.version) raise http_exceptions.CannotUpdateDeletedModel() from exc except base_exceptions.UniqueConstraintViolationError as exc: LOG.warning( "Cannot update server %s (unique constraint " "violation)", self.request_json["data"]["name"]) raise http_exceptions.CannotUpdateModelWithSuchParameters() \ from exc else: if item.cluster_id: item.cluster.update_servers([item]) item.cluster.save() LOG.info("Server model %s was update to version %s by %s", item.model_id, item.version, self.initiator_id) return item
def put(self, item_id, item): try: for key, value in self.request_json["data"].items(): setattr(item, key, value) item.initiator_id = self.initiator_id item.save() except base_exceptions.CannotUpdateDeletedModel as exc: LOG.warning( "Cannot update deleted role %s (deleted at %s, " "version %s)", item_id, item.time_deleted, item.version ) raise http_exceptions.CannotUpdateDeletedModel() from exc except base_exceptions.UniqueConstraintViolationError as exc: LOG.warning("Cannot update role %s (unique constraint " "violation)", self.request_json["data"]["name"]) raise http_exceptions.CannotUpdateModelWithSuchParameters() \ from exc except ValueError as exc: LOG.warning("Incorrect permissions for role %s: %s", item_id, exc) raise http_exceptions.BadRequest from exc LOG.info("Role %s was updated by %s", item_id, self.initiator_id) return item
def delete(self, item_id, item): try: item.delete() except base_exceptions.CannotUpdateDeletedModel as exc: LOG.warning("Cannot delete deleted server %s", item_id) raise http_exceptions.CannotUpdateDeletedModel() from exc LOG.info("Server %s was deleted by %s", item_id, self.initiator_id) return item
def delete(self, item_id, item): try: item.delete() except base_exceptions.CannotUpdateDeletedModel as exc: LOG.warning("Cannot delete deleted role %s", item_id) raise http_exceptions.CannotUpdateDeletedModel() from exc except base_exceptions.CannotDeleteRoleWithActiveUsers as exc: LOG.warning("Cannot delete role %s with active users", item_id) raise http_exceptions.CannotDeleteRoleWithActiveUsers() from exc LOG.info("Role %s was deleted by %s", item_id, self.initiator_id) return item
def delete(self, item_id, item): try: item.delete() except base_exceptions.CannotUpdateDeletedModel as exc: LOG.warning("Cannot delete deleted role %s", item_id) raise http_exceptions.CannotUpdateDeletedModel() from exc except base_exceptions.CannotDeleteLockedPlaybookConfiguration as exc: LOG.warning("Cannot delete locked configuration %s", item.model_id) raise http_exceptions.CannotDeleteLockedPlaybookConfiguration( item.model_id) from exc LOG.info("Playbook configuration %s was deleted by %s", item_id, self.initiator_id) return item
def post_new_password_reset(self): login = self.request_json["login"] user_model = user.UserModel.find_by_login(login) if not user_model: raise http_exceptions.UnknownUserError(login) if user_model.time_deleted: raise http_exceptions.CannotUpdateDeletedModel() reset_model = password_reset.PasswordReset.create(user_model.model_id) LOG.info("Requested password reset for %s", login) notify_user(reset_model._id, user_model.email) return {"message": "Password reset was requested."}
def put(self, item_id, item): for key, value in self.request_json["data"].items(): setattr(item, key, value) item.initiator_id = self.initiator_id try: item.save() except base_exceptions.CannotUpdateDeletedModel as exc: LOG.warning( "Cannot update deleted model %s (deleted at %s, " "version %s)", item.model_id, item.time_deleted, item.version) raise http_exceptions.CannotUpdateDeletedModel() from exc except base_exceptions.UniqueConstraintViolationError as exc: LOG.warning( "Cannot update user %s (unique constraint " "violation)", self.request_json["data"]["login"]) raise http_exceptions.CannotUpdateModelWithSuchParameters() \ from exc LOG.info("User model %s was updated to version %s by %s", item.model_id, item.version, self.initiator_id) return item