77from audit .constants import (
88 RELEASE_PIPELINE_CREATED_MESSAGE ,
99 RELEASE_PIPELINE_DELETED_MESSAGE ,
10- RELEASE_PIPELINE_PUBLISHED_MESSAGE ,
1110)
12- from audit .models import AuditLog
1311from audit .related_object_type import RelatedObjectType
1412from core .models import (
1513 SoftDeleteExportableModel ,
1614 abstract_base_auditable_model_factory ,
1715)
1816from features .release_pipelines .core .constants import MAX_PIPELINE_STAGES
1917from features .release_pipelines .core .exceptions import InvalidPipelineStateError
18+ from features .versioning .models import EnvironmentFeatureVersion
2019from projects .models import Project
2120from users .models import FFAdminUser
2221
@@ -72,7 +71,13 @@ def publish(self, published_by: FFAdminUser) -> None:
7271 self .published_at = timezone .now ()
7372 self .published_by = published_by
7473 self .save ()
75- self ._create_pipeline_published_audit_log ()
74+
75+ def unpublish (self , unpublished_by : FFAdminUser ) -> None :
76+ if self .published_at is None :
77+ raise InvalidPipelineStateError ("Pipeline is not published." )
78+ self .published_at = None
79+ self .published_by = None
80+ self .save ()
7681
7782 def get_first_stage (self ) -> "PipelineStage | None" :
7883 return self .stages .order_by ("order" ).first ()
@@ -90,18 +95,15 @@ def get_delete_log_message(
9095 ) -> typing .Optional [str ]:
9196 return RELEASE_PIPELINE_DELETED_MESSAGE % self .name
9297
98+ def has_feature_in_flight (self ) -> bool :
99+ has_feature_in_flight : bool = EnvironmentFeatureVersion .objects .filter (
100+ published_at__isnull = True , pipeline_stage__in = self .stages .all ()
101+ ).exists ()
102+ return has_feature_in_flight
103+
93104 def _get_project (self ) -> Project :
94105 return self .project
95106
96- def _create_pipeline_published_audit_log (self ) -> None :
97- AuditLog .objects .create (
98- related_object_id = self .id ,
99- related_object_type = RelatedObjectType .RELEASE_PIPELINE .name ,
100- project = self ._get_project (),
101- log = RELEASE_PIPELINE_PUBLISHED_MESSAGE % self .name ,
102- author = self .published_by ,
103- )
104-
105107
106108class PipelineStage (models .Model ):
107109 name = models .CharField (max_length = 255 )
0 commit comments