1
+ """
2
+ This module holds Use Cases (UCs) implementations. These are indirections to trigger business rules
3
+ and avoid the sponsors core logic and state management to be spread across views codes.
4
+ """
1
5
from abc import ABC ,abstractmethod
2
6
3
7
from sponsors import notifications
6
10
7
11
8
12
class BaseUseCaseWithNotifications (ABC ):
13
+ """
14
+ Abstract base class to be used to implement use cases.
15
+ It holds a list of notifications to be dispatched by the UC if needed
16
+ """
9
17
notifications = []
10
18
11
19
@classmethod
12
20
def build (cls ):
21
+ """
22
+ Factory method to explicity handle complex logic and/or dependency injection
23
+ """
13
24
return cls (cls .notifications )
14
25
15
26
@abstractmethod
16
27
def execute (self ,* args ,** kwargs ):
28
+ """
29
+ Abstract method to implement specific UC business rules
30
+ """
17
31
pass
18
32
19
33
def __init__ (self ,notifications ):
@@ -25,6 +39,10 @@ def notify(self, **kwargs):
25
39
26
40
27
41
class CreateSponsorshipApplicationUseCase (BaseUseCaseWithNotifications ):
42
+ """
43
+ Use case called to create a new sponsorships application for submitted by a user
44
+ """
45
+
28
46
notifications = [
29
47
notifications .AppliedSponsorshipNotificationToPSF (),
30
48
notifications .AppliedSponsorshipNotificationToSponsors (),
@@ -37,6 +55,9 @@ def execute(self, user, sponsor, benefits, package=None, request=None):
37
55
38
56
39
57
class RejectSponsorshipApplicationUseCase (BaseUseCaseWithNotifications ):
58
+ """
59
+ Use case to enable PSF staff to reject an application
60
+ """
40
61
notifications = [
41
62
notifications .RejectedSponsorshipNotificationToPSF (),
42
63
notifications .RejectedSponsorshipNotificationToSponsors (),
@@ -50,6 +71,9 @@ def execute(self, sponsorship, request=None):
50
71
51
72
52
73
class ApproveSponsorshipApplicationUseCase (BaseUseCaseWithNotifications ):
74
+ """
75
+ Use case to enable PSF staff to approve an application
76
+ """
53
77
notifications = [
54
78
notifications .SponsorshipApprovalLogger (),
55
79
]
@@ -77,6 +101,10 @@ def execute(self, sponsorship, start_date, end_date, **kwargs):
77
101
78
102
79
103
class SendContractUseCase (BaseUseCaseWithNotifications ):
104
+ """
105
+ Use case to enable PSF staff to generate the contract .docx
106
+ file and sent it over email
107
+ """
80
108
notifications = [
81
109
notifications .ContractNotificationToPSF (),
82
110
# TODO: sponsor's notification will be enabled again once
@@ -98,6 +126,14 @@ def execute(self, contract, **kwargs):
98
126
99
127
100
128
class ExecuteExistingContractUseCase (BaseUseCaseWithNotifications ):
129
+ """
130
+ Use case to PSF Staff to finalize a sponsorship by "executing" a contract.
131
+ This UC was created to enable to enable to upload existing contracts documents
132
+ that weren't generated by the sponsors app.
133
+
134
+ It's probable that this UC will become a legacy one once all the new
135
+ contracts and sponsorships were created via the Django application
136
+ """
101
137
notifications = [
102
138
notifications .ExecutedExistingContractLogger (),
103
139
]
@@ -113,13 +149,22 @@ def execute(self, contract, contract_file, **kwargs):
113
149
114
150
115
151
class ExecuteContractUseCase (ExecuteExistingContractUseCase ):
152
+ """
153
+ Use case to PSF Staff to execute a contract created by the sponsors app.
154
+ Execute a contract requires the admin user to upload the signed contract
155
+ and this will flag the contract as Executed and the corresponding Sponsorship
156
+ as Finalized.
157
+ """
116
158
notifications = [
117
159
notifications .ExecutedContractLogger (),
118
160
]
119
161
force_execute = False
120
162
121
163
122
164
class NullifyContractUseCase (BaseUseCaseWithNotifications ):
165
+ """
166
+ Use case to enable PSF staff to nullify non-executed contracts
167
+ """
123
168
notifications = [
124
169
notifications .NullifiedContractLogger (),
125
170
]
@@ -133,6 +178,10 @@ def execute(self, contract, **kwargs):
133
178
134
179
135
180
class SendSponsorshipNotificationUseCase (BaseUseCaseWithNotifications ):
181
+ """
182
+ Use case to enable PSF staff to send DB stored email notifications
183
+ to a list of selected sponsorships.
184
+ """
136
185
notifications = [
137
186
notifications .SendSponsorNotificationLogger (),
138
187
]