from flask import g from auth.auth_view import AuthorizedView from campaigns.services.campaigns_service import CampaignsService from shared.validators import validate_UUID class UndoCampaignDeleteView(AuthorizedView): """Base class for reverting deletion of project or campaign.""" service = CampaignsService() def put(self, campaign_uuid, project_id): """Restore the object. Deletion is reverted by setting objects's is_deleted flag to False and removing the corresponding history record. Args: campaign_uuid project_id Returns: HTTP 204 Raises: HTTP 400: If it is too late to revert. Reversion can be done during 10 seconds after deletion. HTTP 401: If user is not authenticated. HTTP 403: If user is not the one who deleted the object. HTTP 404: If object is not found. """ validate_UUID(campaign_uuid) self.service.undo_delete_campaign(campaign_uuid, user_id=g.user_id) return self.no_content()