|
84 | 84 | )
|
85 | 85 | from fides.api.schemas.dataset import CollectionAddressResponse, DryRunDatasetResponse
|
86 | 86 | from fides.api.schemas.external_https import PrivacyRequestResumeFormat
|
87 |
| -from fides.api.schemas.policy import ActionType, CurrentStep |
| 87 | +from fides.api.schemas.policy import ActionType |
88 | 88 | from fides.api.schemas.privacy_request import (
|
89 | 89 | BulkPostPrivacyRequests,
|
90 | 90 | BulkReviewResponse,
|
|
170 | 170 | )
|
171 | 171 | from fides.service.messaging.messaging_service import MessagingService
|
172 | 172 | from fides.service.privacy_request.privacy_request_service import (
|
| 173 | + PrivacyRequestError, |
173 | 174 | PrivacyRequestService,
|
| 175 | + _process_privacy_request_restart, |
| 176 | + _requeue_privacy_request, |
174 | 177 | _trigger_pre_approval_webhooks,
|
175 | 178 | queue_privacy_request,
|
176 | 179 | )
|
@@ -1867,35 +1870,6 @@ def resume_privacy_request_from_requires_input(
|
1867 | 1870 | return privacy_request # type: ignore[return-value]
|
1868 | 1871 |
|
1869 | 1872 |
|
1870 |
| -def _process_privacy_request_restart( |
1871 |
| - privacy_request: PrivacyRequest, |
1872 |
| - failed_step: Optional[CurrentStep], |
1873 |
| - db: Session, |
1874 |
| -) -> PrivacyRequestResponse: |
1875 |
| - """If failed_step is provided, restart the DSR within that step. Otherwise, |
1876 |
| - restart the privacy request from the beginning.""" |
1877 |
| - if failed_step: |
1878 |
| - logger.info( |
1879 |
| - "Restarting failed privacy request '{}' from '{}'", |
1880 |
| - privacy_request.id, |
1881 |
| - failed_step, |
1882 |
| - ) |
1883 |
| - else: |
1884 |
| - logger.info( |
1885 |
| - "Restarting failed privacy request '{}' from the beginning", |
1886 |
| - privacy_request.id, |
1887 |
| - ) |
1888 |
| - |
1889 |
| - privacy_request.status = PrivacyRequestStatus.in_processing |
1890 |
| - privacy_request.save(db=db) |
1891 |
| - queue_privacy_request( |
1892 |
| - privacy_request_id=privacy_request.id, |
1893 |
| - from_step=failed_step.value if failed_step else None, |
1894 |
| - ) |
1895 |
| - |
1896 |
| - return privacy_request # type: ignore[return-value] |
1897 |
| - |
1898 |
| - |
1899 | 1873 | @router.get(
|
1900 | 1874 | REQUEST_TASKS,
|
1901 | 1875 | dependencies=[Security(verify_oauth_client, scopes=[PRIVACY_REQUEST_READ])],
|
@@ -1936,52 +1910,18 @@ def requeue_privacy_request(
|
1936 | 1910 |
|
1937 | 1911 | Don't use this unless the Privacy Request is stuck.
|
1938 | 1912 | """
|
1939 |
| - pr: PrivacyRequest = get_privacy_request_or_error(db, privacy_request_id) |
| 1913 | + privacy_request: PrivacyRequest = get_privacy_request_or_error( |
| 1914 | + db, privacy_request_id |
| 1915 | + ) |
1940 | 1916 |
|
1941 |
| - if pr.status not in [ |
1942 |
| - PrivacyRequestStatus.approved, |
1943 |
| - PrivacyRequestStatus.in_processing, |
1944 |
| - ]: |
| 1917 | + try: |
| 1918 | + return _requeue_privacy_request(db, privacy_request) |
| 1919 | + except PrivacyRequestError as exc: |
1945 | 1920 | raise HTTPException(
|
1946 | 1921 | status_code=HTTP_400_BAD_REQUEST,
|
1947 |
| - detail=f"Request failed. Cannot re-queue privacy request {pr.id} with status {pr.status.value}", |
| 1922 | + detail=exc.message, |
1948 | 1923 | )
|
1949 | 1924 |
|
1950 |
| - # Both DSR 2.0 and 3.0 cache checkpoint details |
1951 |
| - checkpoint_details: Optional[CheckpointActionRequired] = ( |
1952 |
| - pr.get_failed_checkpoint_details() |
1953 |
| - ) |
1954 |
| - resume_step = checkpoint_details.step if checkpoint_details else None |
1955 |
| - |
1956 |
| - # DSR 3.0 additionally stores Request Tasks in the application db that can be used to infer |
1957 |
| - # a resume checkpoint in the event the cache has expired. |
1958 |
| - if not resume_step and pr.request_tasks.count(): |
1959 |
| - if pr.consent_tasks.count(): |
1960 |
| - resume_step = CurrentStep.consent |
1961 |
| - elif pr.erasure_tasks.count(): |
1962 |
| - # Checking if access terminator task was completed, because erasure tasks are created |
1963 |
| - # at the same time as the access tasks |
1964 |
| - terminator_access_task = pr.get_terminate_task_by_action(ActionType.access) |
1965 |
| - resume_step = ( |
1966 |
| - CurrentStep.erasure |
1967 |
| - if terminator_access_task.status == ExecutionLogStatus.complete |
1968 |
| - else CurrentStep.access |
1969 |
| - ) |
1970 |
| - elif pr.access_tasks.count(): |
1971 |
| - resume_step = CurrentStep.access |
1972 |
| - |
1973 |
| - logger.info( |
1974 |
| - "Manually re-queuing Privacy Request {} from step {}", |
1975 |
| - pr, |
1976 |
| - resume_step.value if resume_step else None, |
1977 |
| - ) |
1978 |
| - |
1979 |
| - return _process_privacy_request_restart( |
1980 |
| - pr, |
1981 |
| - resume_step, |
1982 |
| - db, |
1983 |
| - ) |
1984 |
| - |
1985 | 1925 |
|
1986 | 1926 | @router.post(
|
1987 | 1927 | REQUEST_TASK_CALLBACK,
|
|
0 commit comments