ethyca-fides 2.63.1b0__py2.py3-none-any.whl → 2.63.1b3__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. {ethyca_fides-2.63.1b0.dist-info → ethyca_fides-2.63.1b3.dist-info}/METADATA +1 -1
  2. {ethyca_fides-2.63.1b0.dist-info → ethyca_fides-2.63.1b3.dist-info}/RECORD +124 -112
  3. fides/_version.py +3 -3
  4. fides/api/alembic/migrations/versions/5efcdf18438e_add_manual_task_tables.py +160 -0
  5. fides/api/alembic/migrations/versions/bf713b5a021d_staged_resource_ancestor_link_data_.py +20 -11
  6. fides/api/db/base.py +2 -0
  7. fides/api/migrations/post_upgrade_index_creation.py +3 -3
  8. fides/api/models/attachment.py +36 -23
  9. fides/api/models/manual_tasks/__init__.py +8 -0
  10. fides/api/models/manual_tasks/manual_task.py +110 -0
  11. fides/api/models/manual_tasks/manual_task_log.py +100 -0
  12. fides/api/schemas/manual_tasks/__init__.py +0 -0
  13. fides/api/schemas/manual_tasks/manual_task_schemas.py +79 -0
  14. fides/api/schemas/manual_tasks/manual_task_status.py +151 -0
  15. fides/api/service/privacy_request/attachment_handling.py +132 -0
  16. fides/api/service/privacy_request/dsr_package/dsr_report_builder.py +264 -46
  17. fides/api/service/privacy_request/dsr_package/templates/attachments_index.html +33 -0
  18. fides/api/service/privacy_request/dsr_package/templates/collection_index.html +34 -9
  19. fides/api/service/privacy_request/dsr_package/templates/main.css +45 -2
  20. fides/api/service/privacy_request/dsr_package/templates/welcome.html +12 -8
  21. fides/api/service/privacy_request/request_runner_service.py +258 -139
  22. fides/api/service/storage/gcs.py +15 -3
  23. fides/api/service/storage/s3.py +28 -14
  24. fides/api/service/storage/util.py +45 -7
  25. fides/api/tasks/csv_utils.py +170 -0
  26. fides/api/tasks/encryption_utils.py +42 -0
  27. fides/api/tasks/storage.py +85 -91
  28. fides/api/util/cache.py +77 -1
  29. fides/config/redis_settings.py +99 -8
  30. fides/service/manual_tasks/__init__.py +0 -0
  31. fides/service/manual_tasks/manual_task_service.py +150 -0
  32. fides/service/messaging/aws_ses_service.py +5 -1
  33. fides/ui-build/static/admin/404.html +1 -1
  34. fides/ui-build/static/admin/add-systems/manual.html +1 -1
  35. fides/ui-build/static/admin/add-systems/multiple.html +1 -1
  36. fides/ui-build/static/admin/add-systems.html +1 -1
  37. fides/ui-build/static/admin/consent/configure/add-vendors.html +1 -1
  38. fides/ui-build/static/admin/consent/configure.html +1 -1
  39. fides/ui-build/static/admin/consent/privacy-experience/[id].html +1 -1
  40. fides/ui-build/static/admin/consent/privacy-experience/new.html +1 -1
  41. fides/ui-build/static/admin/consent/privacy-experience.html +1 -1
  42. fides/ui-build/static/admin/consent/privacy-notices/[id].html +1 -1
  43. fides/ui-build/static/admin/consent/privacy-notices/new.html +1 -1
  44. fides/ui-build/static/admin/consent/privacy-notices.html +1 -1
  45. fides/ui-build/static/admin/consent/properties.html +1 -1
  46. fides/ui-build/static/admin/consent/reporting.html +1 -1
  47. fides/ui-build/static/admin/consent.html +1 -1
  48. fides/ui-build/static/admin/data-catalog/[systemId]/projects/[projectUrn]/[resourceUrn].html +1 -1
  49. fides/ui-build/static/admin/data-catalog/[systemId]/projects/[projectUrn].html +1 -1
  50. fides/ui-build/static/admin/data-catalog/[systemId]/projects.html +1 -1
  51. fides/ui-build/static/admin/data-catalog/[systemId]/resources/[resourceUrn].html +1 -1
  52. fides/ui-build/static/admin/data-catalog/[systemId]/resources.html +1 -1
  53. fides/ui-build/static/admin/data-catalog.html +1 -1
  54. fides/ui-build/static/admin/data-discovery/action-center/[monitorId]/[systemId].html +1 -1
  55. fides/ui-build/static/admin/data-discovery/action-center/[monitorId].html +1 -1
  56. fides/ui-build/static/admin/data-discovery/action-center.html +1 -1
  57. fides/ui-build/static/admin/data-discovery/activity.html +1 -1
  58. fides/ui-build/static/admin/data-discovery/detection/[resourceUrn].html +1 -1
  59. fides/ui-build/static/admin/data-discovery/detection.html +1 -1
  60. fides/ui-build/static/admin/data-discovery/discovery/[resourceUrn].html +1 -1
  61. fides/ui-build/static/admin/data-discovery/discovery.html +1 -1
  62. fides/ui-build/static/admin/datamap.html +1 -1
  63. fides/ui-build/static/admin/dataset/[datasetId]/[collectionName]/[...subfieldNames].html +1 -1
  64. fides/ui-build/static/admin/dataset/[datasetId]/[collectionName].html +1 -1
  65. fides/ui-build/static/admin/dataset/[datasetId].html +1 -1
  66. fides/ui-build/static/admin/dataset/new.html +1 -1
  67. fides/ui-build/static/admin/dataset.html +1 -1
  68. fides/ui-build/static/admin/datastore-connection/[id].html +1 -1
  69. fides/ui-build/static/admin/datastore-connection/new.html +1 -1
  70. fides/ui-build/static/admin/datastore-connection.html +1 -1
  71. fides/ui-build/static/admin/index.html +1 -1
  72. fides/ui-build/static/admin/integrations/[id].html +1 -1
  73. fides/ui-build/static/admin/integrations.html +1 -1
  74. fides/ui-build/static/admin/lib/fides-ext-gpp.js +1 -1
  75. fides/ui-build/static/admin/lib/fides-headless.js +1 -1
  76. fides/ui-build/static/admin/lib/fides-preview.js +1 -1
  77. fides/ui-build/static/admin/lib/fides-tcf.js +2 -2
  78. fides/ui-build/static/admin/lib/fides.js +2 -2
  79. fides/ui-build/static/admin/login/[provider].html +1 -1
  80. fides/ui-build/static/admin/login.html +1 -1
  81. fides/ui-build/static/admin/messaging/[id].html +1 -1
  82. fides/ui-build/static/admin/messaging/add-template.html +1 -1
  83. fides/ui-build/static/admin/messaging.html +1 -1
  84. fides/ui-build/static/admin/poc/ant-components.html +1 -1
  85. fides/ui-build/static/admin/poc/form-experiments/AntForm.html +1 -1
  86. fides/ui-build/static/admin/poc/form-experiments/FormikAntFormItem.html +1 -1
  87. fides/ui-build/static/admin/poc/form-experiments/FormikControlled.html +1 -1
  88. fides/ui-build/static/admin/poc/form-experiments/FormikField.html +1 -1
  89. fides/ui-build/static/admin/poc/form-experiments/FormikSpreadField.html +1 -1
  90. fides/ui-build/static/admin/poc/forms.html +1 -1
  91. fides/ui-build/static/admin/poc/table-migration.html +1 -1
  92. fides/ui-build/static/admin/privacy-requests/[id].html +1 -1
  93. fides/ui-build/static/admin/privacy-requests/configure/messaging.html +1 -1
  94. fides/ui-build/static/admin/privacy-requests/configure/storage.html +1 -1
  95. fides/ui-build/static/admin/privacy-requests/configure.html +1 -1
  96. fides/ui-build/static/admin/privacy-requests.html +1 -1
  97. fides/ui-build/static/admin/properties/[id].html +1 -1
  98. fides/ui-build/static/admin/properties/add-property.html +1 -1
  99. fides/ui-build/static/admin/properties.html +1 -1
  100. fides/ui-build/static/admin/reporting/datamap.html +1 -1
  101. fides/ui-build/static/admin/settings/about/alpha.html +1 -1
  102. fides/ui-build/static/admin/settings/about.html +1 -1
  103. fides/ui-build/static/admin/settings/consent/[configuration_id]/[purpose_id].html +1 -1
  104. fides/ui-build/static/admin/settings/consent.html +1 -1
  105. fides/ui-build/static/admin/settings/custom-fields.html +1 -1
  106. fides/ui-build/static/admin/settings/domain-records.html +1 -1
  107. fides/ui-build/static/admin/settings/domains.html +1 -1
  108. fides/ui-build/static/admin/settings/email-templates.html +1 -1
  109. fides/ui-build/static/admin/settings/locations.html +1 -1
  110. fides/ui-build/static/admin/settings/organization.html +1 -1
  111. fides/ui-build/static/admin/settings/regulations.html +1 -1
  112. fides/ui-build/static/admin/systems/configure/[id]/test-datasets.html +1 -1
  113. fides/ui-build/static/admin/systems/configure/[id].html +1 -1
  114. fides/ui-build/static/admin/systems.html +1 -1
  115. fides/ui-build/static/admin/taxonomy.html +1 -1
  116. fides/ui-build/static/admin/user-management/new.html +1 -1
  117. fides/ui-build/static/admin/user-management/profile/[id].html +1 -1
  118. fides/ui-build/static/admin/user-management.html +1 -1
  119. fides/api/service/privacy_request/dsr_package/templates/item.html +0 -37
  120. {ethyca_fides-2.63.1b0.dist-info → ethyca_fides-2.63.1b3.dist-info}/WHEEL +0 -0
  121. {ethyca_fides-2.63.1b0.dist-info → ethyca_fides-2.63.1b3.dist-info}/entry_points.txt +0 -0
  122. {ethyca_fides-2.63.1b0.dist-info → ethyca_fides-2.63.1b3.dist-info}/licenses/LICENSE +0 -0
  123. {ethyca_fides-2.63.1b0.dist-info → ethyca_fides-2.63.1b3.dist-info}/top_level.txt +0 -0
  124. /fides/ui-build/static/admin/_next/static/{j0v5qPG9TaezfK2WMkHhI → ycPcko8qnif6BlkQ6MN4D}/_buildManifest.js +0 -0
  125. /fides/ui-build/static/admin/_next/static/{j0v5qPG9TaezfK2WMkHhI → ycPcko8qnif6BlkQ6MN4D}/_ssgManifest.js +0 -0
@@ -0,0 +1,151 @@
1
+ from datetime import datetime, timezone
2
+ from enum import Enum as EnumType
3
+ from typing import Optional
4
+
5
+ from sqlalchemy.orm import Session
6
+
7
+
8
+ class StatusTransitionNotAllowed(Exception):
9
+ """Exception raised when a status transition is not allowed."""
10
+
11
+ def __init__(self, message: str):
12
+ self.message = message
13
+ super().__init__(self.message)
14
+
15
+
16
+ class StatusType(str, EnumType):
17
+ """Enum for manual task status."""
18
+
19
+ pending = "pending"
20
+ in_progress = "in_progress"
21
+ completed = "completed"
22
+ failed = "failed"
23
+
24
+ @classmethod
25
+ def get_valid_transitions(cls, current_status: "StatusType") -> list["StatusType"]:
26
+ """Get valid transitions from the current status.
27
+
28
+ Args:
29
+ current_status: The current status
30
+
31
+ Returns:
32
+ list[StatusType]: List of valid transitions
33
+ """
34
+ if current_status == cls.pending:
35
+ return [cls.in_progress, cls.failed]
36
+ if current_status == cls.in_progress:
37
+ return [cls.completed, cls.failed]
38
+ if current_status == cls.completed:
39
+ return []
40
+ if current_status == cls.failed:
41
+ return [cls.pending, cls.in_progress]
42
+ return []
43
+
44
+
45
+ class StatusTransitionMixin:
46
+ """Mixin for handling status transitions.
47
+
48
+ This mixin provides methods for managing status transitions and completion tracking.
49
+ It can be used by any model that needs status management.
50
+ """
51
+
52
+ # These should be overridden by the implementing class
53
+ status: StatusType
54
+ completed_at: Optional[datetime]
55
+ completed_by_id: Optional[str]
56
+
57
+ def _get_valid_transitions(self) -> list[StatusType]:
58
+ """Get valid transitions from the current status.
59
+
60
+ Returns:
61
+ list[StatusType]: List of valid transitions
62
+ """
63
+ return StatusType.get_valid_transitions(self.status)
64
+
65
+ def _validate_status_transition(self, new_status: StatusType) -> None:
66
+ """Validate that a status transition is allowed.
67
+
68
+ Args:
69
+ new_status: The new status to transition to
70
+
71
+ Raises:
72
+ StatusTransitionNotAllowed: If the transition is not allowed
73
+ """
74
+ # Don't allow transitions to the same status
75
+ if new_status == self.status:
76
+ raise StatusTransitionNotAllowed(
77
+ f"Invalid status transition: already in status {new_status}"
78
+ )
79
+
80
+ # Get valid transitions for current status
81
+ valid_transitions = self._get_valid_transitions()
82
+ if new_status not in valid_transitions:
83
+ raise StatusTransitionNotAllowed(
84
+ f"Invalid status transition from {self.status} to {new_status}. "
85
+ f"Valid transitions are: {valid_transitions}"
86
+ )
87
+
88
+ def update_status(
89
+ self, db: Session, new_status: StatusType, user_id: Optional[str] = None
90
+ ) -> None:
91
+ """Update the status with validation and completion handling.
92
+
93
+ Args:
94
+ db: Database session
95
+ new_status: New status to set
96
+ user_id: Optional user ID who is making the change
97
+ """
98
+ self._validate_status_transition(new_status)
99
+
100
+ if new_status == StatusType.completed:
101
+ self.completed_at = datetime.now(timezone.utc)
102
+ self.completed_by_id = user_id
103
+ elif new_status == StatusType.pending:
104
+ # Reset completion fields if going back to pending
105
+ self.completed_at = None
106
+ self.completed_by_id = None
107
+
108
+ self.status = new_status
109
+ db.add(self)
110
+ db.commit()
111
+
112
+ def mark_completed(self, db: Session, user_id: str) -> None:
113
+ """Mark as completed.
114
+
115
+ Args:
116
+ db: Database session
117
+ user_id: user ID who completed the task
118
+ """
119
+ self.update_status(db, StatusType.completed, user_id)
120
+
121
+ def mark_failed(self, db: Session) -> None:
122
+ """Mark as failed."""
123
+ self.update_status(db, StatusType.failed)
124
+
125
+ def start_progress(self, db: Session) -> None:
126
+ """Mark as in progress."""
127
+ self.update_status(db, StatusType.in_progress)
128
+
129
+ def reset_to_pending(self, db: Session) -> None:
130
+ """Reset to pending status."""
131
+ self.update_status(db, StatusType.pending)
132
+
133
+ @property
134
+ def is_completed(self) -> bool:
135
+ """Check if completed."""
136
+ return self.status == StatusType.completed
137
+
138
+ @property
139
+ def is_failed(self) -> bool:
140
+ """Check if failed."""
141
+ return self.status == StatusType.failed
142
+
143
+ @property
144
+ def is_in_progress(self) -> bool:
145
+ """Check if in progress."""
146
+ return self.status == StatusType.in_progress
147
+
148
+ @property
149
+ def is_pending(self) -> bool:
150
+ """Check if pending."""
151
+ return self.status == StatusType.pending
@@ -0,0 +1,132 @@
1
+ import time as time_module
2
+ from dataclasses import dataclass
3
+ from typing import Any, Dict, Iterator, List, Optional, Tuple
4
+
5
+ from loguru import logger
6
+
7
+ from fides.api.models.attachment import Attachment, AttachmentType
8
+ from fides.api.schemas.storage.storage import StorageDetails
9
+
10
+
11
+ @dataclass
12
+ class AttachmentData:
13
+ """Data structure for attachment metadata and content.
14
+ Using a dataclass rather than a Pydantic model here for the following reasons:
15
+ - The data structure is simple and doesn't need complex validation.
16
+ - The fields being used have already been validated and are properly typed.
17
+ - The class is used internally for data transfer, not for API serialization.
18
+ - Performance is important since this is used in a data processing pipeline.
19
+ """
20
+
21
+ file_name: str
22
+ file_size: Optional[int]
23
+ download_url: Optional[str]
24
+ content_type: str
25
+ bucket_name: str
26
+ file_key: str
27
+ storage_key: str
28
+
29
+ def to_upload_dict(self) -> Dict[str, Any]:
30
+ """Convert to dictionary for upload, including presigned URL."""
31
+ return {
32
+ "file_name": self.file_name,
33
+ "file_size": self.file_size,
34
+ "download_url": self.download_url,
35
+ "content_type": self.content_type,
36
+ }
37
+
38
+ def to_storage_dict(self) -> Dict[str, Any]:
39
+ """Convert to dictionary for storage, including the elements needed to recreated the presigned URL."""
40
+ return {
41
+ "file_name": self.file_name,
42
+ "file_size": self.file_size,
43
+ "content_type": self.content_type,
44
+ "bucket_name": self.bucket_name,
45
+ "file_key": self.file_key,
46
+ "storage_key": self.storage_key,
47
+ }
48
+
49
+
50
+ def get_attachments_content(
51
+ loaded_attachments: List[Attachment],
52
+ ) -> Iterator[AttachmentData]:
53
+ """
54
+ Retrieves all attachments associated with a privacy request that are marked to be included with the access package.
55
+ Yields AttachmentData objects containing attachment metadata and download urls.
56
+ Uses generators to minimize memory usage.
57
+
58
+ Args:
59
+ loaded_attachments: List of Attachment objects to process
60
+
61
+ Yields:
62
+ AttachmentData object containing attachment metadata and url
63
+ """
64
+ start_time = time_module.time()
65
+ processed_count = 0
66
+ skipped_count = 0
67
+ error_count = 0
68
+ total_size = 0
69
+
70
+ for attachment in loaded_attachments:
71
+ if attachment.attachment_type != AttachmentType.include_with_access_package:
72
+ skipped_count += 1
73
+ continue
74
+
75
+ try:
76
+ # Get size and download URL using retrieve_attachment
77
+ size, url = attachment.retrieve_attachment()
78
+ total_size += size if size else 0
79
+ if url is None:
80
+ logger.warning(
81
+ "No download URL retrieved for attachment {}", attachment.file_name
82
+ )
83
+ skipped_count += 1
84
+ continue
85
+
86
+ processed_count += 1
87
+ yield AttachmentData(
88
+ file_name=attachment.file_name,
89
+ file_size=size,
90
+ download_url=str(url) if url else None,
91
+ content_type=attachment.content_type,
92
+ bucket_name=attachment.config.details[StorageDetails.BUCKET.value],
93
+ file_key=attachment.file_key,
94
+ storage_key=attachment.storage_key,
95
+ )
96
+
97
+ except Exception as e:
98
+ error_count += 1
99
+ logger.error(
100
+ "Error processing attachment {}: {}", attachment.file_name, str(e)
101
+ )
102
+ continue
103
+
104
+ # Log final metrics
105
+ time_taken = time_module.time() - start_time
106
+ logger.bind(
107
+ time_to_process=time_taken,
108
+ total_attachments=len(loaded_attachments),
109
+ processed_attachments=processed_count,
110
+ skipped_attachments=skipped_count,
111
+ error_attachments=error_count,
112
+ total_size_bytes=total_size,
113
+ ).info("Attachment processing complete")
114
+
115
+
116
+ def process_attachments_for_upload(
117
+ attachments: Iterator[AttachmentData],
118
+ ) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]]]:
119
+ """
120
+ Process attachments into separate upload and storage formats.
121
+ Returns both formats:
122
+ - upload_attachments: Used for uploading to access packages
123
+ - storage_attachments: Used for saving filtered access results
124
+ """
125
+ upload_attachments = []
126
+ storage_attachments = []
127
+
128
+ for attachment in attachments:
129
+ storage_attachments.append(attachment.to_storage_dict())
130
+ upload_attachments.append(attachment.to_upload_dict())
131
+
132
+ return upload_attachments, storage_attachments