Skip to content

Draft #2060 Upgraded Django-fsm to Viewflow [backup] #3670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ django-widget-tweaks = "*"
cachetools = "*"
requests = "*"
django-fsm = "2.8.1"
django-viewflow = "*"
django-phonenumber-field = {extras = ["phonenumberslite"], version = "*"}
boto3 = "*"
typing-extensions ='*'
Expand Down
695 changes: 363 additions & 332 deletions src/Pipfile.lock

Large diffs are not rendered by default.

29 changes: 17 additions & 12 deletions src/registrar/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
Value,
When,
)

from registrar.models.flows import PortfolioInvitationFlow, DomainInvitationFlow, DomainRequestFlow
from django.db.models.functions import Concat, Coalesce
from django.http import HttpResponseRedirect

from registrar.models.federal_agency import FederalAgency
from registrar.models.portfolio_invitation import PortfolioInvitation
from registrar.utility.admin_helpers import (
AutocompleteSelectWithPlaceholder,
get_action_needed_reason_default_email,
Expand All @@ -28,6 +28,7 @@
from django.shortcuts import redirect, get_object_or_404
from django_fsm import get_available_FIELD_transitions, FSMField
from registrar.models import DomainInformation, Portfolio, UserPortfolioPermission, DomainInvitation

from registrar.models.utility.portfolio_helper import UserPortfolioPermissionChoices, UserPortfolioRoleChoices
from registrar.utility.email_invitations import (
send_domain_invitation_email,
Expand Down Expand Up @@ -1754,7 +1755,8 @@ def save_model(self, request, obj, form, change):
)
# if user exists for email, immediately retrieve portfolio invitation upon creation
if requested_user is not None:
portfolio_invitation.retrieve()
portfolio_flow = PortfolioInvitationFlow(portfolio_invitation)
portfolio_flow.retrieve()
portfolio_invitation.save()
messages.success(request, f"{requested_email} has been invited to the organization: {domain_org}")

Expand All @@ -1768,7 +1770,8 @@ def save_model(self, request, obj, form, change):
messages.warning(request, "Could not send email confirmation to existing domain managers.")
if requested_user is not None:
# Domain Invitation creation for an existing User
obj.retrieve()
flow = DomainInvitationFlow(obj)
flow.retrieve()
# Call the parent save method to save the object
super().save_model(request, obj, form, change)
messages.success(request, f"{requested_email} has been invited to the domain: {domain}")
Expand Down Expand Up @@ -1861,7 +1864,8 @@ def save_model(self, request, obj, form, change):
)
# if user exists for email, immediately retrieve portfolio invitation upon creation
if requested_user is not None:
obj.retrieve()
flow = PortfolioInvitationFlow(obj)
flow.retrieve()
messages.success(request, f"{requested_email} has been invited.")
else:
messages.warning(request, "User is already a member of this portfolio.")
Expand Down Expand Up @@ -2958,15 +2962,16 @@ def _handle_status_change(self, request, obj, original_obj):
def get_status_method_mapping(self, domain_request):
"""Returns what method should be ran given an domain request object"""
# Define a per-object mapping
flow = DomainRequestFlow(domain_request)
status_method_mapping = {
models.DomainRequest.DomainRequestStatus.STARTED: None,
models.DomainRequest.DomainRequestStatus.SUBMITTED: domain_request.submit,
models.DomainRequest.DomainRequestStatus.IN_REVIEW: domain_request.in_review,
models.DomainRequest.DomainRequestStatus.ACTION_NEEDED: domain_request.action_needed,
models.DomainRequest.DomainRequestStatus.APPROVED: domain_request.approve,
models.DomainRequest.DomainRequestStatus.WITHDRAWN: domain_request.withdraw,
models.DomainRequest.DomainRequestStatus.REJECTED: domain_request.reject,
models.DomainRequest.DomainRequestStatus.INELIGIBLE: (domain_request.reject_with_prejudice),
models.DomainRequest.DomainRequestStatus.SUBMITTED: flow.submit,
models.DomainRequest.DomainRequestStatus.IN_REVIEW: flow.in_review,
models.DomainRequest.DomainRequestStatus.ACTION_NEEDED: flow.action_needed,
models.DomainRequest.DomainRequestStatus.APPROVED: flow.approve,
models.DomainRequest.DomainRequestStatus.WITHDRAWN: flow.withdraw,
models.DomainRequest.DomainRequestStatus.REJECTED: flow.reject,
models.DomainRequest.DomainRequestStatus.INELIGIBLE: (flow.reject_with_prejudice),
}

# Grab the method
Expand Down
4 changes: 3 additions & 1 deletion src/registrar/fixtures/fixtures_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from registrar.fixtures.fixtures_users import UserFixture
from registrar.models import User, DomainRequest
from registrar.models.domain import Domain
from registrar.models.flows import DomainRequestFlow

fake = Faker()
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,7 +65,8 @@ def _approve_request(cls, domain_request, users):
domain_request.investigator = random.choice(users) # nosec

# Approve the domain request
domain_request.approve(send_email=False)
flow = DomainRequestFlow(domain_request)
flow.approve(send_email=False)

return domain_request

Expand Down
19 changes: 13 additions & 6 deletions src/registrar/management/commands/create_federal_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
import logging
from django.core.management import BaseCommand, CommandError
from registrar.management.commands.utility.terminal_helper import TerminalColors, TerminalHelper
from registrar.models import DomainInformation, DomainRequest, FederalAgency, Suborganization, Portfolio, User
from registrar.models.domain import Domain
from registrar.models.domain_invitation import DomainInvitation
from registrar.models.portfolio_invitation import PortfolioInvitation
from registrar.models.user_domain_role import UserDomainRole
from registrar.models.user_portfolio_permission import UserPortfolioPermission
from registrar.models import (
Domain,
DomainInformation,
DomainInvitation,
DomainRequest,
FederalAgency,
Suborganization,
Portfolio,
PortfolioInvitation,
User,
UserDomainRole,
UserPortfolioPermission,
)
from registrar.models.utility.generic_helper import normalize_string
from django.db.models import F, Q

Expand Down
Loading
Loading