|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Chief\Users\Invites; |
|
4
|
|
|
|
|
5
|
|
|
use Thinktomorrow\Chief\States\State\StatefulContract; |
|
6
|
|
|
use Thinktomorrow\Chief\States\State\StateMachine; |
|
7
|
|
|
|
|
8
|
|
|
class InvitationState extends StateMachine |
|
9
|
|
|
{ |
|
10
|
|
|
const KEY = 'state'; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Possible states of the invitation process: |
|
14
|
|
|
* |
|
15
|
|
|
* NONE - no invitation sent; nothing has happened so far |
|
16
|
|
|
* PENDING - invitation sent or resent and awaiting acceptance |
|
17
|
|
|
* EXPIRED - invitation is no longer valid due to the time restriction |
|
18
|
|
|
* ACCEPTED - new user has accepted the invite |
|
19
|
|
|
* DENIED - new user has denied the invite explicitly |
|
20
|
|
|
* REVOKED - invitation is revoked by an admin |
|
21
|
|
|
*/ |
|
22
|
|
|
const NONE = 'none'; |
|
23
|
|
|
const PENDING = 'pending'; |
|
24
|
|
|
const EXPIRED = 'expired'; |
|
25
|
|
|
const ACCEPTED = 'accepted'; |
|
26
|
|
|
const DENIED = 'denied'; |
|
27
|
|
|
const REVOKED = 'revoked'; |
|
28
|
|
|
|
|
29
|
|
|
protected $states = [ |
|
30
|
|
|
self::NONE, |
|
31
|
|
|
self::PENDING, |
|
32
|
|
|
self::EXPIRED, |
|
33
|
|
|
self::REVOKED, |
|
34
|
|
|
self::ACCEPTED, |
|
35
|
|
|
self::DENIED, |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
protected $transitions = [ |
|
39
|
|
|
'invite' => [ |
|
40
|
|
|
'from' => [self::NONE, self::EXPIRED, self::REVOKED], |
|
41
|
|
|
'to' => self::PENDING, |
|
42
|
|
|
], |
|
43
|
|
|
'expire' => [ |
|
44
|
|
|
'from' => [self::PENDING], |
|
45
|
|
|
'to' => self::EXPIRED, |
|
46
|
|
|
], |
|
47
|
|
|
'revoke' => [ |
|
48
|
|
|
'from' => [self::PENDING, self::EXPIRED], |
|
49
|
|
|
'to' => self::REVOKED, |
|
50
|
|
|
], |
|
51
|
|
|
'accept' => [ |
|
52
|
|
|
'from' => [self::PENDING], |
|
53
|
|
|
'to' => self::ACCEPTED, |
|
54
|
|
|
], |
|
55
|
|
|
'deny' => [ |
|
56
|
|
|
'from' => [self::PENDING], |
|
57
|
|
|
'to' => self::DENIED, |
|
58
|
|
|
], |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
7 |
|
public static function make(StatefulContract $model) |
|
62
|
|
|
{ |
|
63
|
7 |
|
return new static($model, static::KEY); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|