import torrus 1.0.9
[freeside.git] / rt / docs / design_docs / ruleset-workflow.txt
1 # For an online version, see http://wiki.bestpractical.com/?RulesetWorkflow
2
3 _*This is a design document for a work in progress.
4 It describes features that do not exist today and may never exist*_
5
6 == Text Description
7
8 * The user of PurchaseOrder queue fill in a numeric "CF", called "Price".
9 * On creation, it needs to create following approvals:
10 ** "ManagerApproval" if CF.Price is > 1000
11 ** "PresidentApproval" if CF.Price is > 2000
12 * When all of "M", "P" are resolved (or if there were none to begin with), Create "FinanceApproval".
13 * If any approvals above is rejected, reject the original ticket.
14 * If "FinanceApproval" is resolved, resolve original ticket.
15 * If "FinanceApproval" is rejected, create an approval for "CEOApproval".
16 * If "CEOApproval" is resolved, resolve the original ticket.
17 * If "CEOApproval" is rejected, reject the original ticket.
18
19 == ASCII Diagram
20
21        ,----------.      ,---------------------->[DONE]
22        |           \    /                           ^
23  [TOP]-+-?---->[M]---->[F]                          |
24        |        |  /    \                           |
25        `-?->[P]-+-'      `-(!)->[C]-----------------'
26              |  |                |
27              |  |                `-(!)---------->[FAIL]
28              |  |                                   ^
29              `-(!)----------------------------------'
30
31 == Objects
32
33 Note that "Scrips" are now called "Rules".
34
35 === RuleAction "AquireMyLocks"
36
37   FOREACH $Scrip IN $TicketObj->Scrips
38     WHERE $Scrip.Action.Type == "TryCreateTicketWithRuleset"
39        DO LockRuleset $Scrip.Action.Argument
40
41 === RuleAction "TryCreateTicketWithRuleset"
42
43   DO ReleaseMyLockOnRuleset $Argument
44   UNLESS RulesetLocked $Argument
45       DO CreateTicketWithRuleset $Argument
46
47 === RuleAction "CreateTicketWithRuleset"
48
49   GIVEN $Ticket AS CreateTicket(@OtherArguments)
50      DO SetTicketRuleSet $Argument
51      DO RunTicketRuleSet $Argument
52   
53 === GlobalRule "AquireLocks"
54
55 * AppliesTo: All Objects
56 * Condition: OnCreate
57 * Action: AquireMyLocks
58
59 === Queue "PurchaseOrder"
60
61 * Rule:
62 ** Condition: OnCreate
63 ** Action: SetTicketRuleSet "PurchaseFlow"
64 ** Action: RunTicketRuleSet "PurchaseFlow"
65
66 === RuleSet "PurchaseFlow"
67
68 * Rule (implicitly run by AcquireMyLocks):
69 ** Condition: OnCreate
70 ** Action: LockRuleSet "ManagerApproval"
71 ** Action: LockRuleSet "PresidentApproval"
72 ** Action: LockRuleSet "FinanceApproval"
73
74 * Rule:
75 ** Condition: OnCreate 
76 ** Condition: CF.Price > 1000
77 ** Action: TryCreateTicketWithRuleset "ManagerApproval"
78
79 * Rule:
80 ** Condition: OnCreate 
81 ** Condition: CF.Price > 2000
82 ** Action: TryCreateTicketWithRuleset "PresidentApproval"
83
84 * Rule:
85 ** Condition: OnCreate 
86 ** Condition: "Finance" is not blocked
87 ** Action: TryCreateTicketWithRuleset "FinanceApproval"
88
89 * Rule:
90 ** Condition: OnReject
91 ** Action: DeleteTree
92
93 === RuleSet: "ManagerApproval"
94
95 * Rule (implicitly run by AcquireMyLocks):
96 ** Condition: OnCreate
97 ** Action: LockRuleSet "FinanceApproval"
98
99 * Rule:
100 ** Condition: OnResolve
101 ** Action: TryCreateTicketWithRuleset "FinanceApproval"
102
103 * Rule:
104 ** Condition: OnReject
105 ** Action: RejectTicket "PurchaseFlow"
106
107 === RuleSet: "PresidentApproval"
108
109 * Rule (implicitly run by AcquireMyLocks):
110 ** Condition: OnCreate
111 ** Action: LockRuleSet "FinanceApproval"
112
113 * Rule:
114 ** Condition: OnResolve
115 ** Action: TryCreateTicketWithRuleset "FinanceApproval"
116
117 * Rule:
118 ** Condition: OnReject
119 ** Action: RejectTicket "PurchaseFlow"
120
121 === RuleSet: "FinanceApproval"
122
123 * Rule:
124 ** Condition: OnResolve
125 ** Action: ResolveTicket "PurchaseFlow"
126
127 * Rule:
128 ** Condition: OnReject
129 ** Action: ForceCreateTicketWithRuleset "CEOApproval"
130
131 === RuleSet: "CEOApproval"
132
133 * Rule:
134 ** Condition: OnResolve
135 ** Action: ResolveTicket "PurchaseFlow"
136
137 * Rule:
138 ** Condition: OnReject
139 ** Action: RejectTicket "PurchaseFlow"
140
141 ### FNORD FNORD FNORD FNORD FNORD FNORD FNORD FNORD FNORD ###
142
143 == Another Text Description
144
145 * I have a MonitoredQueue that sets tickets to "Monitored" if its subject matches /monitored/.
146 * I want to have a kind of Ticket that are 'Monitored'.
147 * I want all monitored tickets, when they are overdue for 14 days, to:
148 ** Send notification to manager
149 ** Mark as stalled
150 * I want all monitored tickets, when they are overdue for 28 days, to:
151 ** Mark as rejected
152 * I want to query all tickets that are monitored as such
153 * I want to modify 14 => 15 and have it affect all existing tickets that are monitored
154 * I want to add a new "overdue for 27 days, add a 'ultimatum' correspondence to it" rule
155 ** For all monitored tickets.
156 * I want to add a new "overdue for 27 days, add a 'ultimatum' correspondence to it" rule
157 ** For all _new_ monitored tickets.
158 ** Without affecting existing ones.