Skip to content

Commit

Permalink
Add project related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaysan committed Sep 20, 2024
1 parent a7a7377 commit 086a1e2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/features/workflows/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@ def _get_project(self) -> typing.Optional["Project"]:
return self.project or (self.environment and self.environment.project)

def is_approved(self):
if self.environment:
return self.is_approved_via_environment()
if self.project:
return self.is_approved_via_project()
raise RuntimeError(
"Unable to approve change request without environment or project"
)

def is_approved_via_project(self):
return self.project.minimum_change_request_approvals is None or (
self.approvals.filter(approved_at__isnull=False).count()
>= self.project.minimum_change_request_approvals
)

def is_approved_via_environment(self):
return self.environment.minimum_change_request_approvals is None or (
self.approvals.filter(approved_at__isnull=False).count()
>= self.environment.minimum_change_request_approvals
Expand Down Expand Up @@ -407,6 +422,9 @@ def get_audit_log_author(self, history_instance) -> "FFAdminUser":
def _get_environment(self):
return self.change_request.environment

def _get_project(self):
return self.change_request._get_project()


class ChangeRequestGroupAssignment(AbstractBaseExportableModel, LifecycleModel):
change_request = models.ForeignKey(
Expand Down

0 comments on commit 086a1e2

Please sign in to comment.