1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\Dropbox; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | class Module extends \Aurora\System\Module\AbstractModule |
20: | { |
21: | protected $sService = 'dropbox'; |
22: | |
23: | protected $aRequireModules = array( |
24: | 'OAuthIntegratorWebclient' |
25: | ); |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | public function init() |
34: | { |
35: | $this->subscribeEvent('GetServicesSettings', array($this, 'onGetServicesSettings')); |
36: | $this->subscribeEvent('UpdateServicesSettings', array($this, 'onUpdateServicesSettings')); |
37: | } |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | |
45: | public function onGetServicesSettings(&$aServices) |
46: | { |
47: | $aSettings = $this->GetSettings(); |
48: | if (!empty($aSettings)) { |
49: | $aServices[] = $aSettings; |
50: | } |
51: | } |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | |
58: | |
59: | |
60: | |
61: | public function onUpdateServicesSettings($aServices) |
62: | { |
63: | $aSettings = $aServices[$this->sService]; |
64: | |
65: | if (\is_array($aSettings)) { |
66: | $this->UpdateSettings($aSettings['EnableModule'], $aSettings['Id'], $aSettings['Secret']); |
67: | } |
68: | } |
69: | |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | public function GetSettings() |
78: | { |
79: | $aResult = array(); |
80: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
81: | |
82: | $oUser = \Aurora\System\Api::getAuthenticatedUser(); |
83: | if (!empty($oUser) && $oUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin) { |
84: | $aResult = array( |
85: | 'Name' => $this->sService, |
86: | 'DisplayName' => self::GetName(), |
87: | 'EnableModule' => $this->getConfig('EnableModule', false), |
88: | 'Id' => $this->getConfig('Id', ''), |
89: | 'Secret' => $this->getConfig('Secret', '') |
90: | ); |
91: | } |
92: | |
93: | if (!empty($oUser) && $oUser->isNormalOrTenant()) { |
94: | $oAccount = null; |
95: | $oOAuthIntegratorWebclientDecorator = \Aurora\Modules\OAuthIntegratorWebclient\Module::Decorator(); |
96: | if ($oOAuthIntegratorWebclientDecorator) { |
97: | $oAccount = $oOAuthIntegratorWebclientDecorator->GetAccount($this->sService); |
98: | } |
99: | $aResult = array( |
100: | 'EnableModule' => $this->getConfig('EnableModule', false), |
101: | 'Connected' => $oAccount ? true : false |
102: | ); |
103: | $aArgs = array( |
104: | 'OAuthAccount' => $oAccount |
105: | ); |
106: | } |
107: | $this->broadcastEvent('GetSettings', $aArgs, $aResult); |
108: | |
109: | return $aResult; |
110: | } |
111: | |
112: | |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | public function UpdateSettings($EnableModule, $Id, $Secret) |
122: | { |
123: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::TenantAdmin); |
124: | |
125: | try { |
126: | $this->setConfig('EnableModule', $EnableModule); |
127: | $this->setConfig('Id', $Id); |
128: | $this->setConfig('Secret', $Secret); |
129: | $this->saveModuleConfig(); |
130: | } catch (\Exception $ex) { |
131: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::CanNotSaveSettings); |
132: | } |
133: | |
134: | return true; |
135: | } |
136: | |
137: | |
138: | |
139: | |
140: | |
141: | |
142: | public function DeleteAccount() |
143: | { |
144: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
145: | |
146: | $bResult = false; |
147: | $oOAuthIntegratorWebclientDecorator = \Aurora\Modules\OAuthIntegratorWebclient\Module::Decorator(); |
148: | if ($oOAuthIntegratorWebclientDecorator) { |
149: | $bResult = $oOAuthIntegratorWebclientDecorator->DeleteAccount($this->sService); |
150: | } |
151: | |
152: | return $bResult; |
153: | } |
154: | |
155: | } |
156: | |