@@ -159,7 +159,7 @@ |
||
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - return array_filter($providers, function ($provider) use ($user) { |
|
| 162 | + return array_filter($providers, function($provider) use ($user) { |
|
| 163 | 163 | /* @var $provider IProvider */ |
| 164 | 164 | return $provider->isTwoFactorAuthEnabledForUser($user); |
| 165 | 165 | }); |
@@ -41,296 +41,296 @@ |
||
| 41 | 41 | |
| 42 | 42 | class Manager { |
| 43 | 43 | |
| 44 | - const SESSION_UID_KEY = 'two_factor_auth_uid'; |
|
| 45 | - const SESSION_UID_DONE = 'two_factor_auth_passed'; |
|
| 46 | - const BACKUP_CODES_APP_ID = 'twofactor_backupcodes'; |
|
| 47 | - const BACKUP_CODES_PROVIDER_ID = 'backup_codes'; |
|
| 48 | - const REMEMBER_LOGIN = 'two_factor_remember_login'; |
|
| 49 | - |
|
| 50 | - /** @var AppManager */ |
|
| 51 | - private $appManager; |
|
| 52 | - |
|
| 53 | - /** @var ISession */ |
|
| 54 | - private $session; |
|
| 55 | - |
|
| 56 | - /** @var IConfig */ |
|
| 57 | - private $config; |
|
| 58 | - |
|
| 59 | - /** @var IManager */ |
|
| 60 | - private $activityManager; |
|
| 61 | - |
|
| 62 | - /** @var ILogger */ |
|
| 63 | - private $logger; |
|
| 64 | - |
|
| 65 | - /** @var TokenProvider */ |
|
| 66 | - private $tokenProvider; |
|
| 67 | - |
|
| 68 | - /** @var ITimeFactory */ |
|
| 69 | - private $timeFactory; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param AppManager $appManager |
|
| 73 | - * @param ISession $session |
|
| 74 | - * @param IConfig $config |
|
| 75 | - * @param IManager $activityManager |
|
| 76 | - * @param ILogger $logger |
|
| 77 | - * @param TokenProvider $tokenProvider |
|
| 78 | - * @param ITimeFactory $timeFactory |
|
| 79 | - */ |
|
| 80 | - public function __construct(AppManager $appManager, |
|
| 81 | - ISession $session, |
|
| 82 | - IConfig $config, |
|
| 83 | - IManager $activityManager, |
|
| 84 | - ILogger $logger, |
|
| 85 | - TokenProvider $tokenProvider, |
|
| 86 | - ITimeFactory $timeFactory) { |
|
| 87 | - $this->appManager = $appManager; |
|
| 88 | - $this->session = $session; |
|
| 89 | - $this->config = $config; |
|
| 90 | - $this->activityManager = $activityManager; |
|
| 91 | - $this->logger = $logger; |
|
| 92 | - $this->tokenProvider = $tokenProvider; |
|
| 93 | - $this->timeFactory = $timeFactory; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Determine whether the user must provide a second factor challenge |
|
| 98 | - * |
|
| 99 | - * @param IUser $user |
|
| 100 | - * @return boolean |
|
| 101 | - */ |
|
| 102 | - public function isTwoFactorAuthenticated(IUser $user) { |
|
| 103 | - $twoFactorEnabled = ((int) $this->config->getUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 0)) === 0; |
|
| 104 | - return $twoFactorEnabled && count($this->getProviders($user)) > 0; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Disable 2FA checks for the given user |
|
| 109 | - * |
|
| 110 | - * @param IUser $user |
|
| 111 | - */ |
|
| 112 | - public function disableTwoFactorAuthentication(IUser $user) { |
|
| 113 | - $this->config->setUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 1); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Enable all 2FA checks for the given user |
|
| 118 | - * |
|
| 119 | - * @param IUser $user |
|
| 120 | - */ |
|
| 121 | - public function enableTwoFactorAuthentication(IUser $user) { |
|
| 122 | - $this->config->deleteUserValue($user->getUID(), 'core', 'two_factor_auth_disabled'); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Get a 2FA provider by its ID |
|
| 127 | - * |
|
| 128 | - * @param IUser $user |
|
| 129 | - * @param string $challengeProviderId |
|
| 130 | - * @return IProvider|null |
|
| 131 | - */ |
|
| 132 | - public function getProvider(IUser $user, $challengeProviderId) { |
|
| 133 | - $providers = $this->getProviders($user, true); |
|
| 134 | - return isset($providers[$challengeProviderId]) ? $providers[$challengeProviderId] : null; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param IUser $user |
|
| 139 | - * @return IProvider|null the backup provider, if enabled for the given user |
|
| 140 | - */ |
|
| 141 | - public function getBackupProvider(IUser $user) { |
|
| 142 | - $providers = $this->getProviders($user, true); |
|
| 143 | - if (!isset($providers[self::BACKUP_CODES_PROVIDER_ID])) { |
|
| 144 | - return null; |
|
| 145 | - } |
|
| 146 | - return $providers[self::BACKUP_CODES_PROVIDER_ID]; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Get the list of 2FA providers for the given user |
|
| 151 | - * |
|
| 152 | - * @param IUser $user |
|
| 153 | - * @param bool $includeBackupApp |
|
| 154 | - * @return IProvider[] |
|
| 155 | - * @throws Exception |
|
| 156 | - */ |
|
| 157 | - public function getProviders(IUser $user, $includeBackupApp = false) { |
|
| 158 | - $allApps = $this->appManager->getEnabledAppsForUser($user); |
|
| 159 | - $providers = []; |
|
| 160 | - |
|
| 161 | - foreach ($allApps as $appId) { |
|
| 162 | - if (!$includeBackupApp && $appId === self::BACKUP_CODES_APP_ID) { |
|
| 163 | - continue; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $info = $this->appManager->getAppInfo($appId); |
|
| 167 | - if (isset($info['two-factor-providers'])) { |
|
| 168 | - $providerClasses = $info['two-factor-providers']; |
|
| 169 | - foreach ($providerClasses as $class) { |
|
| 170 | - try { |
|
| 171 | - $this->loadTwoFactorApp($appId); |
|
| 172 | - $provider = OC::$server->query($class); |
|
| 173 | - $providers[$provider->getId()] = $provider; |
|
| 174 | - } catch (QueryException $exc) { |
|
| 175 | - // Provider class can not be resolved |
|
| 176 | - throw new Exception("Could not load two-factor auth provider $class"); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return array_filter($providers, function ($provider) use ($user) { |
|
| 183 | - /* @var $provider IProvider */ |
|
| 184 | - return $provider->isTwoFactorAuthEnabledForUser($user); |
|
| 185 | - }); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Load an app by ID if it has not been loaded yet |
|
| 190 | - * |
|
| 191 | - * @param string $appId |
|
| 192 | - */ |
|
| 193 | - protected function loadTwoFactorApp($appId) { |
|
| 194 | - if (!OC_App::isAppLoaded($appId)) { |
|
| 195 | - OC_App::loadApp($appId); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Verify the given challenge |
|
| 201 | - * |
|
| 202 | - * @param string $providerId |
|
| 203 | - * @param IUser $user |
|
| 204 | - * @param string $challenge |
|
| 205 | - * @return boolean |
|
| 206 | - */ |
|
| 207 | - public function verifyChallenge($providerId, IUser $user, $challenge) { |
|
| 208 | - $provider = $this->getProvider($user, $providerId); |
|
| 209 | - if (is_null($provider)) { |
|
| 210 | - return false; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $passed = $provider->verifyChallenge($user, $challenge); |
|
| 214 | - if ($passed) { |
|
| 215 | - if ($this->session->get(self::REMEMBER_LOGIN) === true) { |
|
| 216 | - // TODO: resolve cyclic dependency and use DI |
|
| 217 | - \OC::$server->getUserSession()->createRememberMeToken($user); |
|
| 218 | - } |
|
| 219 | - $this->session->remove(self::SESSION_UID_KEY); |
|
| 220 | - $this->session->remove(self::REMEMBER_LOGIN); |
|
| 221 | - $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
| 222 | - |
|
| 223 | - // Clear token from db |
|
| 224 | - $sessionId = $this->session->getId(); |
|
| 225 | - $token = $this->tokenProvider->getToken($sessionId); |
|
| 226 | - $tokenId = $token->getId(); |
|
| 227 | - $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $tokenId); |
|
| 228 | - |
|
| 229 | - $this->publishEvent($user, 'twofactor_success', [ |
|
| 230 | - 'provider' => $provider->getDisplayName(), |
|
| 231 | - ]); |
|
| 232 | - } else { |
|
| 233 | - $this->publishEvent($user, 'twofactor_failed', [ |
|
| 234 | - 'provider' => $provider->getDisplayName(), |
|
| 235 | - ]); |
|
| 236 | - } |
|
| 237 | - return $passed; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Push a 2fa event the user's activity stream |
|
| 242 | - * |
|
| 243 | - * @param IUser $user |
|
| 244 | - * @param string $event |
|
| 245 | - */ |
|
| 246 | - private function publishEvent(IUser $user, $event, array $params) { |
|
| 247 | - $activity = $this->activityManager->generateEvent(); |
|
| 248 | - $activity->setApp('core') |
|
| 249 | - ->setType('security') |
|
| 250 | - ->setAuthor($user->getUID()) |
|
| 251 | - ->setAffectedUser($user->getUID()) |
|
| 252 | - ->setSubject($event, $params); |
|
| 253 | - try { |
|
| 254 | - $this->activityManager->publish($activity); |
|
| 255 | - } catch (BadMethodCallException $e) { |
|
| 256 | - $this->logger->warning('could not publish backup code creation activity', ['app' => 'core']); |
|
| 257 | - $this->logger->logException($e, ['app' => 'core']); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Check if the currently logged in user needs to pass 2FA |
|
| 263 | - * |
|
| 264 | - * @param IUser $user the currently logged in user |
|
| 265 | - * @return boolean |
|
| 266 | - */ |
|
| 267 | - public function needsSecondFactor(IUser $user = null) { |
|
| 268 | - if ($user === null) { |
|
| 269 | - return false; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - // If we are authenticated using an app password skip all this |
|
| 273 | - if ($this->session->exists('app_password')) { |
|
| 274 | - return false; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // First check if the session tells us we should do 2FA (99% case) |
|
| 278 | - if (!$this->session->exists(self::SESSION_UID_KEY)) { |
|
| 279 | - |
|
| 280 | - // Check if the session tells us it is 2FA authenticated already |
|
| 281 | - if ($this->session->exists(self::SESSION_UID_DONE) && |
|
| 282 | - $this->session->get(self::SESSION_UID_DONE) === $user->getUID()) { |
|
| 283 | - return false; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /* |
|
| 44 | + const SESSION_UID_KEY = 'two_factor_auth_uid'; |
|
| 45 | + const SESSION_UID_DONE = 'two_factor_auth_passed'; |
|
| 46 | + const BACKUP_CODES_APP_ID = 'twofactor_backupcodes'; |
|
| 47 | + const BACKUP_CODES_PROVIDER_ID = 'backup_codes'; |
|
| 48 | + const REMEMBER_LOGIN = 'two_factor_remember_login'; |
|
| 49 | + |
|
| 50 | + /** @var AppManager */ |
|
| 51 | + private $appManager; |
|
| 52 | + |
|
| 53 | + /** @var ISession */ |
|
| 54 | + private $session; |
|
| 55 | + |
|
| 56 | + /** @var IConfig */ |
|
| 57 | + private $config; |
|
| 58 | + |
|
| 59 | + /** @var IManager */ |
|
| 60 | + private $activityManager; |
|
| 61 | + |
|
| 62 | + /** @var ILogger */ |
|
| 63 | + private $logger; |
|
| 64 | + |
|
| 65 | + /** @var TokenProvider */ |
|
| 66 | + private $tokenProvider; |
|
| 67 | + |
|
| 68 | + /** @var ITimeFactory */ |
|
| 69 | + private $timeFactory; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param AppManager $appManager |
|
| 73 | + * @param ISession $session |
|
| 74 | + * @param IConfig $config |
|
| 75 | + * @param IManager $activityManager |
|
| 76 | + * @param ILogger $logger |
|
| 77 | + * @param TokenProvider $tokenProvider |
|
| 78 | + * @param ITimeFactory $timeFactory |
|
| 79 | + */ |
|
| 80 | + public function __construct(AppManager $appManager, |
|
| 81 | + ISession $session, |
|
| 82 | + IConfig $config, |
|
| 83 | + IManager $activityManager, |
|
| 84 | + ILogger $logger, |
|
| 85 | + TokenProvider $tokenProvider, |
|
| 86 | + ITimeFactory $timeFactory) { |
|
| 87 | + $this->appManager = $appManager; |
|
| 88 | + $this->session = $session; |
|
| 89 | + $this->config = $config; |
|
| 90 | + $this->activityManager = $activityManager; |
|
| 91 | + $this->logger = $logger; |
|
| 92 | + $this->tokenProvider = $tokenProvider; |
|
| 93 | + $this->timeFactory = $timeFactory; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Determine whether the user must provide a second factor challenge |
|
| 98 | + * |
|
| 99 | + * @param IUser $user |
|
| 100 | + * @return boolean |
|
| 101 | + */ |
|
| 102 | + public function isTwoFactorAuthenticated(IUser $user) { |
|
| 103 | + $twoFactorEnabled = ((int) $this->config->getUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 0)) === 0; |
|
| 104 | + return $twoFactorEnabled && count($this->getProviders($user)) > 0; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Disable 2FA checks for the given user |
|
| 109 | + * |
|
| 110 | + * @param IUser $user |
|
| 111 | + */ |
|
| 112 | + public function disableTwoFactorAuthentication(IUser $user) { |
|
| 113 | + $this->config->setUserValue($user->getUID(), 'core', 'two_factor_auth_disabled', 1); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Enable all 2FA checks for the given user |
|
| 118 | + * |
|
| 119 | + * @param IUser $user |
|
| 120 | + */ |
|
| 121 | + public function enableTwoFactorAuthentication(IUser $user) { |
|
| 122 | + $this->config->deleteUserValue($user->getUID(), 'core', 'two_factor_auth_disabled'); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Get a 2FA provider by its ID |
|
| 127 | + * |
|
| 128 | + * @param IUser $user |
|
| 129 | + * @param string $challengeProviderId |
|
| 130 | + * @return IProvider|null |
|
| 131 | + */ |
|
| 132 | + public function getProvider(IUser $user, $challengeProviderId) { |
|
| 133 | + $providers = $this->getProviders($user, true); |
|
| 134 | + return isset($providers[$challengeProviderId]) ? $providers[$challengeProviderId] : null; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param IUser $user |
|
| 139 | + * @return IProvider|null the backup provider, if enabled for the given user |
|
| 140 | + */ |
|
| 141 | + public function getBackupProvider(IUser $user) { |
|
| 142 | + $providers = $this->getProviders($user, true); |
|
| 143 | + if (!isset($providers[self::BACKUP_CODES_PROVIDER_ID])) { |
|
| 144 | + return null; |
|
| 145 | + } |
|
| 146 | + return $providers[self::BACKUP_CODES_PROVIDER_ID]; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Get the list of 2FA providers for the given user |
|
| 151 | + * |
|
| 152 | + * @param IUser $user |
|
| 153 | + * @param bool $includeBackupApp |
|
| 154 | + * @return IProvider[] |
|
| 155 | + * @throws Exception |
|
| 156 | + */ |
|
| 157 | + public function getProviders(IUser $user, $includeBackupApp = false) { |
|
| 158 | + $allApps = $this->appManager->getEnabledAppsForUser($user); |
|
| 159 | + $providers = []; |
|
| 160 | + |
|
| 161 | + foreach ($allApps as $appId) { |
|
| 162 | + if (!$includeBackupApp && $appId === self::BACKUP_CODES_APP_ID) { |
|
| 163 | + continue; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $info = $this->appManager->getAppInfo($appId); |
|
| 167 | + if (isset($info['two-factor-providers'])) { |
|
| 168 | + $providerClasses = $info['two-factor-providers']; |
|
| 169 | + foreach ($providerClasses as $class) { |
|
| 170 | + try { |
|
| 171 | + $this->loadTwoFactorApp($appId); |
|
| 172 | + $provider = OC::$server->query($class); |
|
| 173 | + $providers[$provider->getId()] = $provider; |
|
| 174 | + } catch (QueryException $exc) { |
|
| 175 | + // Provider class can not be resolved |
|
| 176 | + throw new Exception("Could not load two-factor auth provider $class"); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return array_filter($providers, function ($provider) use ($user) { |
|
| 183 | + /* @var $provider IProvider */ |
|
| 184 | + return $provider->isTwoFactorAuthEnabledForUser($user); |
|
| 185 | + }); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Load an app by ID if it has not been loaded yet |
|
| 190 | + * |
|
| 191 | + * @param string $appId |
|
| 192 | + */ |
|
| 193 | + protected function loadTwoFactorApp($appId) { |
|
| 194 | + if (!OC_App::isAppLoaded($appId)) { |
|
| 195 | + OC_App::loadApp($appId); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Verify the given challenge |
|
| 201 | + * |
|
| 202 | + * @param string $providerId |
|
| 203 | + * @param IUser $user |
|
| 204 | + * @param string $challenge |
|
| 205 | + * @return boolean |
|
| 206 | + */ |
|
| 207 | + public function verifyChallenge($providerId, IUser $user, $challenge) { |
|
| 208 | + $provider = $this->getProvider($user, $providerId); |
|
| 209 | + if (is_null($provider)) { |
|
| 210 | + return false; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $passed = $provider->verifyChallenge($user, $challenge); |
|
| 214 | + if ($passed) { |
|
| 215 | + if ($this->session->get(self::REMEMBER_LOGIN) === true) { |
|
| 216 | + // TODO: resolve cyclic dependency and use DI |
|
| 217 | + \OC::$server->getUserSession()->createRememberMeToken($user); |
|
| 218 | + } |
|
| 219 | + $this->session->remove(self::SESSION_UID_KEY); |
|
| 220 | + $this->session->remove(self::REMEMBER_LOGIN); |
|
| 221 | + $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
| 222 | + |
|
| 223 | + // Clear token from db |
|
| 224 | + $sessionId = $this->session->getId(); |
|
| 225 | + $token = $this->tokenProvider->getToken($sessionId); |
|
| 226 | + $tokenId = $token->getId(); |
|
| 227 | + $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $tokenId); |
|
| 228 | + |
|
| 229 | + $this->publishEvent($user, 'twofactor_success', [ |
|
| 230 | + 'provider' => $provider->getDisplayName(), |
|
| 231 | + ]); |
|
| 232 | + } else { |
|
| 233 | + $this->publishEvent($user, 'twofactor_failed', [ |
|
| 234 | + 'provider' => $provider->getDisplayName(), |
|
| 235 | + ]); |
|
| 236 | + } |
|
| 237 | + return $passed; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Push a 2fa event the user's activity stream |
|
| 242 | + * |
|
| 243 | + * @param IUser $user |
|
| 244 | + * @param string $event |
|
| 245 | + */ |
|
| 246 | + private function publishEvent(IUser $user, $event, array $params) { |
|
| 247 | + $activity = $this->activityManager->generateEvent(); |
|
| 248 | + $activity->setApp('core') |
|
| 249 | + ->setType('security') |
|
| 250 | + ->setAuthor($user->getUID()) |
|
| 251 | + ->setAffectedUser($user->getUID()) |
|
| 252 | + ->setSubject($event, $params); |
|
| 253 | + try { |
|
| 254 | + $this->activityManager->publish($activity); |
|
| 255 | + } catch (BadMethodCallException $e) { |
|
| 256 | + $this->logger->warning('could not publish backup code creation activity', ['app' => 'core']); |
|
| 257 | + $this->logger->logException($e, ['app' => 'core']); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Check if the currently logged in user needs to pass 2FA |
|
| 263 | + * |
|
| 264 | + * @param IUser $user the currently logged in user |
|
| 265 | + * @return boolean |
|
| 266 | + */ |
|
| 267 | + public function needsSecondFactor(IUser $user = null) { |
|
| 268 | + if ($user === null) { |
|
| 269 | + return false; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + // If we are authenticated using an app password skip all this |
|
| 273 | + if ($this->session->exists('app_password')) { |
|
| 274 | + return false; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // First check if the session tells us we should do 2FA (99% case) |
|
| 278 | + if (!$this->session->exists(self::SESSION_UID_KEY)) { |
|
| 279 | + |
|
| 280 | + // Check if the session tells us it is 2FA authenticated already |
|
| 281 | + if ($this->session->exists(self::SESSION_UID_DONE) && |
|
| 282 | + $this->session->get(self::SESSION_UID_DONE) === $user->getUID()) { |
|
| 283 | + return false; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /* |
|
| 287 | 287 | * If the session is expired check if we are not logged in by a token |
| 288 | 288 | * that still needs 2FA auth |
| 289 | 289 | */ |
| 290 | - try { |
|
| 291 | - $sessionId = $this->session->getId(); |
|
| 292 | - $token = $this->tokenProvider->getToken($sessionId); |
|
| 293 | - $tokenId = $token->getId(); |
|
| 294 | - $tokensNeeding2FA = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
| 295 | - |
|
| 296 | - if (!in_array($tokenId, $tokensNeeding2FA, true)) { |
|
| 297 | - $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
| 298 | - return false; |
|
| 299 | - } |
|
| 300 | - } catch (InvalidTokenException $e) { |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if (!$this->isTwoFactorAuthenticated($user)) { |
|
| 305 | - // There is no second factor any more -> let the user pass |
|
| 306 | - // This prevents infinite redirect loops when a user is about |
|
| 307 | - // to solve the 2FA challenge, and the provider app is |
|
| 308 | - // disabled the same time |
|
| 309 | - $this->session->remove(self::SESSION_UID_KEY); |
|
| 310 | - |
|
| 311 | - $keys = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
| 312 | - foreach ($keys as $key) { |
|
| 313 | - $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $key); |
|
| 314 | - } |
|
| 315 | - return false; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - return true; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Prepare the 2FA login |
|
| 323 | - * |
|
| 324 | - * @param IUser $user |
|
| 325 | - * @param boolean $rememberMe |
|
| 326 | - */ |
|
| 327 | - public function prepareTwoFactorLogin(IUser $user, $rememberMe) { |
|
| 328 | - $this->session->set(self::SESSION_UID_KEY, $user->getUID()); |
|
| 329 | - $this->session->set(self::REMEMBER_LOGIN, $rememberMe); |
|
| 330 | - |
|
| 331 | - $id = $this->session->getId(); |
|
| 332 | - $token = $this->tokenProvider->getToken($id); |
|
| 333 | - $this->config->setUserValue($user->getUID(), 'login_token_2fa', $token->getId(), $this->timeFactory->getTime()); |
|
| 334 | - } |
|
| 290 | + try { |
|
| 291 | + $sessionId = $this->session->getId(); |
|
| 292 | + $token = $this->tokenProvider->getToken($sessionId); |
|
| 293 | + $tokenId = $token->getId(); |
|
| 294 | + $tokensNeeding2FA = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
| 295 | + |
|
| 296 | + if (!in_array($tokenId, $tokensNeeding2FA, true)) { |
|
| 297 | + $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
| 298 | + return false; |
|
| 299 | + } |
|
| 300 | + } catch (InvalidTokenException $e) { |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if (!$this->isTwoFactorAuthenticated($user)) { |
|
| 305 | + // There is no second factor any more -> let the user pass |
|
| 306 | + // This prevents infinite redirect loops when a user is about |
|
| 307 | + // to solve the 2FA challenge, and the provider app is |
|
| 308 | + // disabled the same time |
|
| 309 | + $this->session->remove(self::SESSION_UID_KEY); |
|
| 310 | + |
|
| 311 | + $keys = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
| 312 | + foreach ($keys as $key) { |
|
| 313 | + $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $key); |
|
| 314 | + } |
|
| 315 | + return false; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + return true; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Prepare the 2FA login |
|
| 323 | + * |
|
| 324 | + * @param IUser $user |
|
| 325 | + * @param boolean $rememberMe |
|
| 326 | + */ |
|
| 327 | + public function prepareTwoFactorLogin(IUser $user, $rememberMe) { |
|
| 328 | + $this->session->set(self::SESSION_UID_KEY, $user->getUID()); |
|
| 329 | + $this->session->set(self::REMEMBER_LOGIN, $rememberMe); |
|
| 330 | + |
|
| 331 | + $id = $this->session->getId(); |
|
| 332 | + $token = $this->tokenProvider->getToken($id); |
|
| 333 | + $this->config->setUserValue($user->getUID(), 'login_token_2fa', $token->getId(), $this->timeFactory->getTime()); |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | 336 | } |
@@ -129,7 +129,7 @@ |
||
| 129 | 129 | $data = $result->fetchAll(); |
| 130 | 130 | $result->closeCursor(); |
| 131 | 131 | |
| 132 | - $entities = array_map(function ($row) { |
|
| 132 | + $entities = array_map(function($row) { |
|
| 133 | 133 | return DefaultToken::fromRow($row); |
| 134 | 134 | }, $data); |
| 135 | 135 | |
@@ -36,134 +36,134 @@ |
||
| 36 | 36 | |
| 37 | 37 | class DefaultTokenMapper extends Mapper { |
| 38 | 38 | |
| 39 | - public function __construct(IDBConnection $db) { |
|
| 40 | - parent::__construct($db, 'authtoken'); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Invalidate (delete) a given token |
|
| 45 | - * |
|
| 46 | - * @param string $token |
|
| 47 | - */ |
|
| 48 | - public function invalidate($token) { |
|
| 49 | - /* @var $qb IQueryBuilder */ |
|
| 50 | - $qb = $this->db->getQueryBuilder(); |
|
| 51 | - $qb->delete('authtoken') |
|
| 52 | - ->where($qb->expr()->eq('token', $qb->createParameter('token'))) |
|
| 53 | - ->setParameter('token', $token) |
|
| 54 | - ->execute(); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param int $olderThan |
|
| 59 | - * @param int $remember |
|
| 60 | - */ |
|
| 61 | - public function invalidateOld($olderThan, $remember = IToken::DO_NOT_REMEMBER) { |
|
| 62 | - /* @var $qb IQueryBuilder */ |
|
| 63 | - $qb = $this->db->getQueryBuilder(); |
|
| 64 | - $qb->delete('authtoken') |
|
| 65 | - ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
| 66 | - ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT))) |
|
| 67 | - ->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))) |
|
| 68 | - ->execute(); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Get the user UID for the given token |
|
| 73 | - * |
|
| 74 | - * @param string $token |
|
| 75 | - * @throws DoesNotExistException |
|
| 76 | - * @return DefaultToken |
|
| 77 | - */ |
|
| 78 | - public function getToken($token) { |
|
| 79 | - /* @var $qb IQueryBuilder */ |
|
| 80 | - $qb = $this->db->getQueryBuilder(); |
|
| 81 | - $result = $qb->select('*') |
|
| 82 | - ->from('authtoken') |
|
| 83 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 84 | - ->execute(); |
|
| 85 | - |
|
| 86 | - $data = $result->fetch(); |
|
| 87 | - $result->closeCursor(); |
|
| 88 | - if ($data === false) { |
|
| 89 | - throw new DoesNotExistException('token does not exist'); |
|
| 90 | - } |
|
| 91 | - return DefaultToken::fromRow($data); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Get the token for $id |
|
| 96 | - * |
|
| 97 | - * @param string $id |
|
| 98 | - * @throws DoesNotExistException |
|
| 99 | - * @return DefaultToken |
|
| 100 | - */ |
|
| 101 | - public function getTokenById($id) { |
|
| 102 | - /* @var $qb IQueryBuilder */ |
|
| 103 | - $qb = $this->db->getQueryBuilder(); |
|
| 104 | - $result = $qb->select('*') |
|
| 105 | - ->from('authtoken') |
|
| 106 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 107 | - ->execute(); |
|
| 108 | - |
|
| 109 | - $data = $result->fetch(); |
|
| 110 | - $result->closeCursor(); |
|
| 111 | - if ($data === false) { |
|
| 112 | - throw new DoesNotExistException('token does not exist'); |
|
| 113 | - } |
|
| 114 | - return DefaultToken::fromRow($data); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Get all tokens of a user |
|
| 119 | - * |
|
| 120 | - * The provider may limit the number of result rows in case of an abuse |
|
| 121 | - * where a high number of (session) tokens is generated |
|
| 122 | - * |
|
| 123 | - * @param IUser $user |
|
| 124 | - * @return DefaultToken[] |
|
| 125 | - */ |
|
| 126 | - public function getTokenByUser(IUser $user) { |
|
| 127 | - /* @var $qb IQueryBuilder */ |
|
| 128 | - $qb = $this->db->getQueryBuilder(); |
|
| 129 | - $qb->select('*') |
|
| 130 | - ->from('authtoken') |
|
| 131 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 132 | - ->setMaxResults(1000); |
|
| 133 | - $result = $qb->execute(); |
|
| 134 | - $data = $result->fetchAll(); |
|
| 135 | - $result->closeCursor(); |
|
| 136 | - |
|
| 137 | - $entities = array_map(function ($row) { |
|
| 138 | - return DefaultToken::fromRow($row); |
|
| 139 | - }, $data); |
|
| 140 | - |
|
| 141 | - return $entities; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param IUser $user |
|
| 146 | - * @param int $id |
|
| 147 | - */ |
|
| 148 | - public function deleteById(IUser $user, $id) { |
|
| 149 | - /* @var $qb IQueryBuilder */ |
|
| 150 | - $qb = $this->db->getQueryBuilder(); |
|
| 151 | - $qb->delete('authtoken') |
|
| 152 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 153 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))); |
|
| 154 | - $qb->execute(); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * delete all auth token which belong to a specific client if the client was deleted |
|
| 159 | - * |
|
| 160 | - * @param string $name |
|
| 161 | - */ |
|
| 162 | - public function deleteByName($name) { |
|
| 163 | - $qb = $this->db->getQueryBuilder(); |
|
| 164 | - $qb->delete('authtoken') |
|
| 165 | - ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)); |
|
| 166 | - $qb->execute(); |
|
| 167 | - } |
|
| 39 | + public function __construct(IDBConnection $db) { |
|
| 40 | + parent::__construct($db, 'authtoken'); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Invalidate (delete) a given token |
|
| 45 | + * |
|
| 46 | + * @param string $token |
|
| 47 | + */ |
|
| 48 | + public function invalidate($token) { |
|
| 49 | + /* @var $qb IQueryBuilder */ |
|
| 50 | + $qb = $this->db->getQueryBuilder(); |
|
| 51 | + $qb->delete('authtoken') |
|
| 52 | + ->where($qb->expr()->eq('token', $qb->createParameter('token'))) |
|
| 53 | + ->setParameter('token', $token) |
|
| 54 | + ->execute(); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param int $olderThan |
|
| 59 | + * @param int $remember |
|
| 60 | + */ |
|
| 61 | + public function invalidateOld($olderThan, $remember = IToken::DO_NOT_REMEMBER) { |
|
| 62 | + /* @var $qb IQueryBuilder */ |
|
| 63 | + $qb = $this->db->getQueryBuilder(); |
|
| 64 | + $qb->delete('authtoken') |
|
| 65 | + ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
| 66 | + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT))) |
|
| 67 | + ->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))) |
|
| 68 | + ->execute(); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Get the user UID for the given token |
|
| 73 | + * |
|
| 74 | + * @param string $token |
|
| 75 | + * @throws DoesNotExistException |
|
| 76 | + * @return DefaultToken |
|
| 77 | + */ |
|
| 78 | + public function getToken($token) { |
|
| 79 | + /* @var $qb IQueryBuilder */ |
|
| 80 | + $qb = $this->db->getQueryBuilder(); |
|
| 81 | + $result = $qb->select('*') |
|
| 82 | + ->from('authtoken') |
|
| 83 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 84 | + ->execute(); |
|
| 85 | + |
|
| 86 | + $data = $result->fetch(); |
|
| 87 | + $result->closeCursor(); |
|
| 88 | + if ($data === false) { |
|
| 89 | + throw new DoesNotExistException('token does not exist'); |
|
| 90 | + } |
|
| 91 | + return DefaultToken::fromRow($data); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Get the token for $id |
|
| 96 | + * |
|
| 97 | + * @param string $id |
|
| 98 | + * @throws DoesNotExistException |
|
| 99 | + * @return DefaultToken |
|
| 100 | + */ |
|
| 101 | + public function getTokenById($id) { |
|
| 102 | + /* @var $qb IQueryBuilder */ |
|
| 103 | + $qb = $this->db->getQueryBuilder(); |
|
| 104 | + $result = $qb->select('*') |
|
| 105 | + ->from('authtoken') |
|
| 106 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 107 | + ->execute(); |
|
| 108 | + |
|
| 109 | + $data = $result->fetch(); |
|
| 110 | + $result->closeCursor(); |
|
| 111 | + if ($data === false) { |
|
| 112 | + throw new DoesNotExistException('token does not exist'); |
|
| 113 | + } |
|
| 114 | + return DefaultToken::fromRow($data); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Get all tokens of a user |
|
| 119 | + * |
|
| 120 | + * The provider may limit the number of result rows in case of an abuse |
|
| 121 | + * where a high number of (session) tokens is generated |
|
| 122 | + * |
|
| 123 | + * @param IUser $user |
|
| 124 | + * @return DefaultToken[] |
|
| 125 | + */ |
|
| 126 | + public function getTokenByUser(IUser $user) { |
|
| 127 | + /* @var $qb IQueryBuilder */ |
|
| 128 | + $qb = $this->db->getQueryBuilder(); |
|
| 129 | + $qb->select('*') |
|
| 130 | + ->from('authtoken') |
|
| 131 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 132 | + ->setMaxResults(1000); |
|
| 133 | + $result = $qb->execute(); |
|
| 134 | + $data = $result->fetchAll(); |
|
| 135 | + $result->closeCursor(); |
|
| 136 | + |
|
| 137 | + $entities = array_map(function ($row) { |
|
| 138 | + return DefaultToken::fromRow($row); |
|
| 139 | + }, $data); |
|
| 140 | + |
|
| 141 | + return $entities; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param IUser $user |
|
| 146 | + * @param int $id |
|
| 147 | + */ |
|
| 148 | + public function deleteById(IUser $user, $id) { |
|
| 149 | + /* @var $qb IQueryBuilder */ |
|
| 150 | + $qb = $this->db->getQueryBuilder(); |
|
| 151 | + $qb->delete('authtoken') |
|
| 152 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 153 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))); |
|
| 154 | + $qb->execute(); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * delete all auth token which belong to a specific client if the client was deleted |
|
| 159 | + * |
|
| 160 | + * @param string $name |
|
| 161 | + */ |
|
| 162 | + public function deleteByName($name) { |
|
| 163 | + $qb = $this->db->getQueryBuilder(); |
|
| 164 | + $qb->delete('authtoken') |
|
| 165 | + ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)); |
|
| 166 | + $qb->execute(); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | 169 | } |
@@ -27,10 +27,10 @@ |
||
| 27 | 27 | |
| 28 | 28 | class DefaultTokenCleanupJob extends Job { |
| 29 | 29 | |
| 30 | - protected function run($argument) { |
|
| 31 | - /* @var $provider IProvider */ |
|
| 32 | - $provider = OC::$server->query('OC\Authentication\Token\IProvider'); |
|
| 33 | - $provider->invalidateOldTokens(); |
|
| 34 | - } |
|
| 30 | + protected function run($argument) { |
|
| 31 | + /* @var $provider IProvider */ |
|
| 32 | + $provider = OC::$server->query('OC\Authentication\Token\IProvider'); |
|
| 33 | + $provider->invalidateOldTokens(); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | } |
@@ -103,6 +103,6 @@ |
||
| 103 | 103 | $time = new \DateTime('now', $timeZone); |
| 104 | 104 | $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); |
| 105 | 105 | |
| 106 | - return $timestampInfo . ' ' . $this->formatter->format($message); |
|
| 106 | + return $timestampInfo.' '.$this->formatter->format($message); |
|
| 107 | 107 | } |
| 108 | 108 | } |
@@ -28,85 +28,85 @@ |
||
| 28 | 28 | use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface; |
| 29 | 29 | |
| 30 | 30 | class TimestampFormatter implements OutputFormatterInterface { |
| 31 | - /** @var IConfig */ |
|
| 32 | - protected $config; |
|
| 31 | + /** @var IConfig */ |
|
| 32 | + protected $config; |
|
| 33 | 33 | |
| 34 | - /** @var OutputFormatterInterface */ |
|
| 35 | - protected $formatter; |
|
| 34 | + /** @var OutputFormatterInterface */ |
|
| 35 | + protected $formatter; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param IConfig $config |
|
| 39 | - * @param OutputFormatterInterface $formatter |
|
| 40 | - */ |
|
| 41 | - public function __construct(IConfig $config, OutputFormatterInterface $formatter) { |
|
| 42 | - $this->config = $config; |
|
| 43 | - $this->formatter = $formatter; |
|
| 44 | - } |
|
| 37 | + /** |
|
| 38 | + * @param IConfig $config |
|
| 39 | + * @param OutputFormatterInterface $formatter |
|
| 40 | + */ |
|
| 41 | + public function __construct(IConfig $config, OutputFormatterInterface $formatter) { |
|
| 42 | + $this->config = $config; |
|
| 43 | + $this->formatter = $formatter; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Sets the decorated flag. |
|
| 48 | - * |
|
| 49 | - * @param bool $decorated Whether to decorate the messages or not |
|
| 50 | - */ |
|
| 51 | - public function setDecorated($decorated) { |
|
| 52 | - $this->formatter->setDecorated($decorated); |
|
| 53 | - } |
|
| 46 | + /** |
|
| 47 | + * Sets the decorated flag. |
|
| 48 | + * |
|
| 49 | + * @param bool $decorated Whether to decorate the messages or not |
|
| 50 | + */ |
|
| 51 | + public function setDecorated($decorated) { |
|
| 52 | + $this->formatter->setDecorated($decorated); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Gets the decorated flag. |
|
| 57 | - * |
|
| 58 | - * @return bool true if the output will decorate messages, false otherwise |
|
| 59 | - */ |
|
| 60 | - public function isDecorated() { |
|
| 61 | - return $this->formatter->isDecorated(); |
|
| 62 | - } |
|
| 55 | + /** |
|
| 56 | + * Gets the decorated flag. |
|
| 57 | + * |
|
| 58 | + * @return bool true if the output will decorate messages, false otherwise |
|
| 59 | + */ |
|
| 60 | + public function isDecorated() { |
|
| 61 | + return $this->formatter->isDecorated(); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Sets a new style. |
|
| 66 | - * |
|
| 67 | - * @param string $name The style name |
|
| 68 | - * @param OutputFormatterStyleInterface $style The style instance |
|
| 69 | - */ |
|
| 70 | - public function setStyle($name, OutputFormatterStyleInterface $style) { |
|
| 71 | - $this->formatter->setStyle($name, $style); |
|
| 72 | - } |
|
| 64 | + /** |
|
| 65 | + * Sets a new style. |
|
| 66 | + * |
|
| 67 | + * @param string $name The style name |
|
| 68 | + * @param OutputFormatterStyleInterface $style The style instance |
|
| 69 | + */ |
|
| 70 | + public function setStyle($name, OutputFormatterStyleInterface $style) { |
|
| 71 | + $this->formatter->setStyle($name, $style); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Checks if output formatter has style with specified name. |
|
| 76 | - * |
|
| 77 | - * @param string $name |
|
| 78 | - * @return bool |
|
| 79 | - */ |
|
| 80 | - public function hasStyle($name) { |
|
| 81 | - return $this->formatter->hasStyle($name); |
|
| 82 | - } |
|
| 74 | + /** |
|
| 75 | + * Checks if output formatter has style with specified name. |
|
| 76 | + * |
|
| 77 | + * @param string $name |
|
| 78 | + * @return bool |
|
| 79 | + */ |
|
| 80 | + public function hasStyle($name) { |
|
| 81 | + return $this->formatter->hasStyle($name); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Gets style options from style with specified name. |
|
| 86 | - * |
|
| 87 | - * @param string $name |
|
| 88 | - * @return OutputFormatterStyleInterface |
|
| 89 | - * @throws \InvalidArgumentException When style isn't defined |
|
| 90 | - */ |
|
| 91 | - public function getStyle($name) { |
|
| 92 | - return $this->formatter->getStyle($name); |
|
| 93 | - } |
|
| 84 | + /** |
|
| 85 | + * Gets style options from style with specified name. |
|
| 86 | + * |
|
| 87 | + * @param string $name |
|
| 88 | + * @return OutputFormatterStyleInterface |
|
| 89 | + * @throws \InvalidArgumentException When style isn't defined |
|
| 90 | + */ |
|
| 91 | + public function getStyle($name) { |
|
| 92 | + return $this->formatter->getStyle($name); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Formats a message according to the given styles. |
|
| 97 | - * |
|
| 98 | - * @param string $message The message to style |
|
| 99 | - * @return string The styled message, prepended with a timestamp using the |
|
| 100 | - * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00" |
|
| 101 | - */ |
|
| 102 | - public function format($message) { |
|
| 95 | + /** |
|
| 96 | + * Formats a message according to the given styles. |
|
| 97 | + * |
|
| 98 | + * @param string $message The message to style |
|
| 99 | + * @return string The styled message, prepended with a timestamp using the |
|
| 100 | + * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00" |
|
| 101 | + */ |
|
| 102 | + public function format($message) { |
|
| 103 | 103 | |
| 104 | - $timeZone = $this->config->getSystemValue('logtimezone', 'UTC'); |
|
| 105 | - $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null; |
|
| 104 | + $timeZone = $this->config->getSystemValue('logtimezone', 'UTC'); |
|
| 105 | + $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null; |
|
| 106 | 106 | |
| 107 | - $time = new \DateTime('now', $timeZone); |
|
| 108 | - $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); |
|
| 107 | + $time = new \DateTime('now', $timeZone); |
|
| 108 | + $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); |
|
| 109 | 109 | |
| 110 | - return $timestampInfo . ' ' . $this->formatter->format($message); |
|
| 111 | - } |
|
| 110 | + return $timestampInfo . ' ' . $this->formatter->format($message); |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -36,253 +36,253 @@ |
||
| 36 | 36 | |
| 37 | 37 | class SubAdmin extends PublicEmitter { |
| 38 | 38 | |
| 39 | - /** @var IUserManager */ |
|
| 40 | - private $userManager; |
|
| 41 | - |
|
| 42 | - /** @var IGroupManager */ |
|
| 43 | - private $groupManager; |
|
| 44 | - |
|
| 45 | - /** @var IDBConnection */ |
|
| 46 | - private $dbConn; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param IUserManager $userManager |
|
| 50 | - * @param IGroupManager $groupManager |
|
| 51 | - * @param IDBConnection $dbConn |
|
| 52 | - */ |
|
| 53 | - public function __construct(IUserManager $userManager, |
|
| 54 | - IGroupManager $groupManager, |
|
| 55 | - IDBConnection $dbConn) { |
|
| 56 | - $this->userManager = $userManager; |
|
| 57 | - $this->groupManager = $groupManager; |
|
| 58 | - $this->dbConn = $dbConn; |
|
| 59 | - |
|
| 60 | - $this->userManager->listen('\OC\User', 'postDelete', function($user) { |
|
| 61 | - $this->post_deleteUser($user); |
|
| 62 | - }); |
|
| 63 | - $this->groupManager->listen('\OC\Group', 'postDelete', function($group) { |
|
| 64 | - $this->post_deleteGroup($group); |
|
| 65 | - }); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * add a SubAdmin |
|
| 70 | - * @param IUser $user user to be SubAdmin |
|
| 71 | - * @param IGroup $group group $user becomes subadmin of |
|
| 72 | - * @return bool |
|
| 73 | - */ |
|
| 74 | - public function createSubAdmin(IUser $user, IGroup $group) { |
|
| 75 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 76 | - |
|
| 77 | - $qb->insert('group_admin') |
|
| 78 | - ->values([ |
|
| 79 | - 'gid' => $qb->createNamedParameter($group->getGID()), |
|
| 80 | - 'uid' => $qb->createNamedParameter($user->getUID()) |
|
| 81 | - ]) |
|
| 82 | - ->execute(); |
|
| 83 | - |
|
| 84 | - $this->emit('\OC\SubAdmin', 'postCreateSubAdmin', [$user, $group]); |
|
| 85 | - \OC_Hook::emit("OC_SubAdmin", "post_createSubAdmin", ["gid" => $group->getGID()]); |
|
| 86 | - return true; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * delete a SubAdmin |
|
| 91 | - * @param IUser $user the user that is the SubAdmin |
|
| 92 | - * @param IGroup $group the group |
|
| 93 | - * @return bool |
|
| 94 | - */ |
|
| 95 | - public function deleteSubAdmin(IUser $user, IGroup $group) { |
|
| 96 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 97 | - |
|
| 98 | - $qb->delete('group_admin') |
|
| 99 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID()))) |
|
| 100 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 101 | - ->execute(); |
|
| 102 | - |
|
| 103 | - $this->emit('\OC\SubAdmin', 'postDeleteSubAdmin', [$user, $group]); |
|
| 104 | - \OC_Hook::emit("OC_SubAdmin", "post_deleteSubAdmin", ["gid" => $group->getGID()]); |
|
| 105 | - return true; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * get groups of a SubAdmin |
|
| 110 | - * @param IUser $user the SubAdmin |
|
| 111 | - * @return IGroup[] |
|
| 112 | - */ |
|
| 113 | - public function getSubAdminsGroups(IUser $user) { |
|
| 114 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 115 | - |
|
| 116 | - $result = $qb->select('gid') |
|
| 117 | - ->from('group_admin') |
|
| 118 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 119 | - ->execute(); |
|
| 120 | - |
|
| 121 | - $groups = []; |
|
| 122 | - while($row = $result->fetch()) { |
|
| 123 | - $group = $this->groupManager->get($row['gid']); |
|
| 124 | - if(!is_null($group)) { |
|
| 125 | - $groups[] = $group; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - $result->closeCursor(); |
|
| 129 | - |
|
| 130 | - return $groups; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * get SubAdmins of a group |
|
| 135 | - * @param IGroup $group the group |
|
| 136 | - * @return IUser[] |
|
| 137 | - */ |
|
| 138 | - public function getGroupsSubAdmins(IGroup $group) { |
|
| 139 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 140 | - |
|
| 141 | - $result = $qb->select('uid') |
|
| 142 | - ->from('group_admin') |
|
| 143 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID()))) |
|
| 144 | - ->execute(); |
|
| 145 | - |
|
| 146 | - $users = []; |
|
| 147 | - while($row = $result->fetch()) { |
|
| 148 | - $user = $this->userManager->get($row['uid']); |
|
| 149 | - if(!is_null($user)) { |
|
| 150 | - $users[] = $user; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - $result->closeCursor(); |
|
| 154 | - |
|
| 155 | - return $users; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * get all SubAdmins |
|
| 160 | - * @return array |
|
| 161 | - */ |
|
| 162 | - public function getAllSubAdmins() { |
|
| 163 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 164 | - |
|
| 165 | - $result = $qb->select('*') |
|
| 166 | - ->from('group_admin') |
|
| 167 | - ->execute(); |
|
| 168 | - |
|
| 169 | - $subadmins = []; |
|
| 170 | - while($row = $result->fetch()) { |
|
| 171 | - $user = $this->userManager->get($row['uid']); |
|
| 172 | - $group = $this->groupManager->get($row['gid']); |
|
| 173 | - if(!is_null($user) && !is_null($group)) { |
|
| 174 | - $subadmins[] = [ |
|
| 175 | - 'user' => $user, |
|
| 176 | - 'group' => $group |
|
| 177 | - ]; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - $result->closeCursor(); |
|
| 181 | - |
|
| 182 | - return $subadmins; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * checks if a user is a SubAdmin of a group |
|
| 187 | - * @param IUser $user |
|
| 188 | - * @param IGroup $group |
|
| 189 | - * @return bool |
|
| 190 | - */ |
|
| 191 | - public function isSubAdminOfGroup(IUser $user, IGroup $group) { |
|
| 192 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 193 | - |
|
| 194 | - /* |
|
| 39 | + /** @var IUserManager */ |
|
| 40 | + private $userManager; |
|
| 41 | + |
|
| 42 | + /** @var IGroupManager */ |
|
| 43 | + private $groupManager; |
|
| 44 | + |
|
| 45 | + /** @var IDBConnection */ |
|
| 46 | + private $dbConn; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param IUserManager $userManager |
|
| 50 | + * @param IGroupManager $groupManager |
|
| 51 | + * @param IDBConnection $dbConn |
|
| 52 | + */ |
|
| 53 | + public function __construct(IUserManager $userManager, |
|
| 54 | + IGroupManager $groupManager, |
|
| 55 | + IDBConnection $dbConn) { |
|
| 56 | + $this->userManager = $userManager; |
|
| 57 | + $this->groupManager = $groupManager; |
|
| 58 | + $this->dbConn = $dbConn; |
|
| 59 | + |
|
| 60 | + $this->userManager->listen('\OC\User', 'postDelete', function($user) { |
|
| 61 | + $this->post_deleteUser($user); |
|
| 62 | + }); |
|
| 63 | + $this->groupManager->listen('\OC\Group', 'postDelete', function($group) { |
|
| 64 | + $this->post_deleteGroup($group); |
|
| 65 | + }); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * add a SubAdmin |
|
| 70 | + * @param IUser $user user to be SubAdmin |
|
| 71 | + * @param IGroup $group group $user becomes subadmin of |
|
| 72 | + * @return bool |
|
| 73 | + */ |
|
| 74 | + public function createSubAdmin(IUser $user, IGroup $group) { |
|
| 75 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 76 | + |
|
| 77 | + $qb->insert('group_admin') |
|
| 78 | + ->values([ |
|
| 79 | + 'gid' => $qb->createNamedParameter($group->getGID()), |
|
| 80 | + 'uid' => $qb->createNamedParameter($user->getUID()) |
|
| 81 | + ]) |
|
| 82 | + ->execute(); |
|
| 83 | + |
|
| 84 | + $this->emit('\OC\SubAdmin', 'postCreateSubAdmin', [$user, $group]); |
|
| 85 | + \OC_Hook::emit("OC_SubAdmin", "post_createSubAdmin", ["gid" => $group->getGID()]); |
|
| 86 | + return true; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * delete a SubAdmin |
|
| 91 | + * @param IUser $user the user that is the SubAdmin |
|
| 92 | + * @param IGroup $group the group |
|
| 93 | + * @return bool |
|
| 94 | + */ |
|
| 95 | + public function deleteSubAdmin(IUser $user, IGroup $group) { |
|
| 96 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 97 | + |
|
| 98 | + $qb->delete('group_admin') |
|
| 99 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID()))) |
|
| 100 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 101 | + ->execute(); |
|
| 102 | + |
|
| 103 | + $this->emit('\OC\SubAdmin', 'postDeleteSubAdmin', [$user, $group]); |
|
| 104 | + \OC_Hook::emit("OC_SubAdmin", "post_deleteSubAdmin", ["gid" => $group->getGID()]); |
|
| 105 | + return true; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * get groups of a SubAdmin |
|
| 110 | + * @param IUser $user the SubAdmin |
|
| 111 | + * @return IGroup[] |
|
| 112 | + */ |
|
| 113 | + public function getSubAdminsGroups(IUser $user) { |
|
| 114 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 115 | + |
|
| 116 | + $result = $qb->select('gid') |
|
| 117 | + ->from('group_admin') |
|
| 118 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 119 | + ->execute(); |
|
| 120 | + |
|
| 121 | + $groups = []; |
|
| 122 | + while($row = $result->fetch()) { |
|
| 123 | + $group = $this->groupManager->get($row['gid']); |
|
| 124 | + if(!is_null($group)) { |
|
| 125 | + $groups[] = $group; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + $result->closeCursor(); |
|
| 129 | + |
|
| 130 | + return $groups; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * get SubAdmins of a group |
|
| 135 | + * @param IGroup $group the group |
|
| 136 | + * @return IUser[] |
|
| 137 | + */ |
|
| 138 | + public function getGroupsSubAdmins(IGroup $group) { |
|
| 139 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 140 | + |
|
| 141 | + $result = $qb->select('uid') |
|
| 142 | + ->from('group_admin') |
|
| 143 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID()))) |
|
| 144 | + ->execute(); |
|
| 145 | + |
|
| 146 | + $users = []; |
|
| 147 | + while($row = $result->fetch()) { |
|
| 148 | + $user = $this->userManager->get($row['uid']); |
|
| 149 | + if(!is_null($user)) { |
|
| 150 | + $users[] = $user; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + $result->closeCursor(); |
|
| 154 | + |
|
| 155 | + return $users; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * get all SubAdmins |
|
| 160 | + * @return array |
|
| 161 | + */ |
|
| 162 | + public function getAllSubAdmins() { |
|
| 163 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 164 | + |
|
| 165 | + $result = $qb->select('*') |
|
| 166 | + ->from('group_admin') |
|
| 167 | + ->execute(); |
|
| 168 | + |
|
| 169 | + $subadmins = []; |
|
| 170 | + while($row = $result->fetch()) { |
|
| 171 | + $user = $this->userManager->get($row['uid']); |
|
| 172 | + $group = $this->groupManager->get($row['gid']); |
|
| 173 | + if(!is_null($user) && !is_null($group)) { |
|
| 174 | + $subadmins[] = [ |
|
| 175 | + 'user' => $user, |
|
| 176 | + 'group' => $group |
|
| 177 | + ]; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + $result->closeCursor(); |
|
| 181 | + |
|
| 182 | + return $subadmins; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * checks if a user is a SubAdmin of a group |
|
| 187 | + * @param IUser $user |
|
| 188 | + * @param IGroup $group |
|
| 189 | + * @return bool |
|
| 190 | + */ |
|
| 191 | + public function isSubAdminOfGroup(IUser $user, IGroup $group) { |
|
| 192 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 193 | + |
|
| 194 | + /* |
|
| 195 | 195 | * Primary key is ('gid', 'uid') so max 1 result possible here |
| 196 | 196 | */ |
| 197 | - $result = $qb->select('*') |
|
| 198 | - ->from('group_admin') |
|
| 199 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID()))) |
|
| 200 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 201 | - ->execute(); |
|
| 202 | - |
|
| 203 | - $fetch = $result->fetch(); |
|
| 204 | - $result->closeCursor(); |
|
| 205 | - $result = !empty($fetch) ? true : false; |
|
| 206 | - |
|
| 207 | - return $result; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * checks if a user is a SubAdmin |
|
| 212 | - * @param IUser $user |
|
| 213 | - * @return bool |
|
| 214 | - */ |
|
| 215 | - public function isSubAdmin(IUser $user) { |
|
| 216 | - // Check if the user is already an admin |
|
| 217 | - if ($this->groupManager->isAdmin($user->getUID())) { |
|
| 218 | - return true; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 222 | - |
|
| 223 | - $result = $qb->select('gid') |
|
| 224 | - ->from('group_admin') |
|
| 225 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 226 | - ->setMaxResults(1) |
|
| 227 | - ->execute(); |
|
| 228 | - |
|
| 229 | - $isSubAdmin = $result->fetch(); |
|
| 230 | - $result->closeCursor(); |
|
| 231 | - |
|
| 232 | - $result = $isSubAdmin === false ? false : true; |
|
| 233 | - |
|
| 234 | - return $result; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * checks if a user is a accessible by a subadmin |
|
| 239 | - * @param IUser $subadmin |
|
| 240 | - * @param IUser $user |
|
| 241 | - * @return bool |
|
| 242 | - */ |
|
| 243 | - public function isUserAccessible($subadmin, $user) { |
|
| 244 | - if(!$this->isSubAdmin($subadmin)) { |
|
| 245 | - return false; |
|
| 246 | - } |
|
| 247 | - if($this->groupManager->isAdmin($user->getUID())) { |
|
| 248 | - return false; |
|
| 249 | - } |
|
| 250 | - $accessibleGroups = $this->getSubAdminsGroups($subadmin); |
|
| 251 | - foreach($accessibleGroups as $accessibleGroup) { |
|
| 252 | - if($accessibleGroup->inGroup($user)) { |
|
| 253 | - return true; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - return false; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * delete all SubAdmins by $user |
|
| 261 | - * @param IUser $user |
|
| 262 | - * @return boolean |
|
| 263 | - */ |
|
| 264 | - private function post_deleteUser($user) { |
|
| 265 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 266 | - |
|
| 267 | - $qb->delete('group_admin') |
|
| 268 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 269 | - ->execute(); |
|
| 270 | - |
|
| 271 | - return true; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * delete all SubAdmins by $group |
|
| 276 | - * @param IGroup $group |
|
| 277 | - * @return boolean |
|
| 278 | - */ |
|
| 279 | - private function post_deleteGroup($group) { |
|
| 280 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 281 | - |
|
| 282 | - $qb->delete('group_admin') |
|
| 283 | - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID()))) |
|
| 284 | - ->execute(); |
|
| 285 | - |
|
| 286 | - return true; |
|
| 287 | - } |
|
| 197 | + $result = $qb->select('*') |
|
| 198 | + ->from('group_admin') |
|
| 199 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID()))) |
|
| 200 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 201 | + ->execute(); |
|
| 202 | + |
|
| 203 | + $fetch = $result->fetch(); |
|
| 204 | + $result->closeCursor(); |
|
| 205 | + $result = !empty($fetch) ? true : false; |
|
| 206 | + |
|
| 207 | + return $result; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * checks if a user is a SubAdmin |
|
| 212 | + * @param IUser $user |
|
| 213 | + * @return bool |
|
| 214 | + */ |
|
| 215 | + public function isSubAdmin(IUser $user) { |
|
| 216 | + // Check if the user is already an admin |
|
| 217 | + if ($this->groupManager->isAdmin($user->getUID())) { |
|
| 218 | + return true; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 222 | + |
|
| 223 | + $result = $qb->select('gid') |
|
| 224 | + ->from('group_admin') |
|
| 225 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 226 | + ->setMaxResults(1) |
|
| 227 | + ->execute(); |
|
| 228 | + |
|
| 229 | + $isSubAdmin = $result->fetch(); |
|
| 230 | + $result->closeCursor(); |
|
| 231 | + |
|
| 232 | + $result = $isSubAdmin === false ? false : true; |
|
| 233 | + |
|
| 234 | + return $result; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * checks if a user is a accessible by a subadmin |
|
| 239 | + * @param IUser $subadmin |
|
| 240 | + * @param IUser $user |
|
| 241 | + * @return bool |
|
| 242 | + */ |
|
| 243 | + public function isUserAccessible($subadmin, $user) { |
|
| 244 | + if(!$this->isSubAdmin($subadmin)) { |
|
| 245 | + return false; |
|
| 246 | + } |
|
| 247 | + if($this->groupManager->isAdmin($user->getUID())) { |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | + $accessibleGroups = $this->getSubAdminsGroups($subadmin); |
|
| 251 | + foreach($accessibleGroups as $accessibleGroup) { |
|
| 252 | + if($accessibleGroup->inGroup($user)) { |
|
| 253 | + return true; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + return false; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * delete all SubAdmins by $user |
|
| 261 | + * @param IUser $user |
|
| 262 | + * @return boolean |
|
| 263 | + */ |
|
| 264 | + private function post_deleteUser($user) { |
|
| 265 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 266 | + |
|
| 267 | + $qb->delete('group_admin') |
|
| 268 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
|
| 269 | + ->execute(); |
|
| 270 | + |
|
| 271 | + return true; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * delete all SubAdmins by $group |
|
| 276 | + * @param IGroup $group |
|
| 277 | + * @return boolean |
|
| 278 | + */ |
|
| 279 | + private function post_deleteGroup($group) { |
|
| 280 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 281 | + |
|
| 282 | + $qb->delete('group_admin') |
|
| 283 | + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID()))) |
|
| 284 | + ->execute(); |
|
| 285 | + |
|
| 286 | + return true; |
|
| 287 | + } |
|
| 288 | 288 | } |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | ->execute(); |
| 120 | 120 | |
| 121 | 121 | $groups = []; |
| 122 | - while($row = $result->fetch()) { |
|
| 122 | + while ($row = $result->fetch()) { |
|
| 123 | 123 | $group = $this->groupManager->get($row['gid']); |
| 124 | - if(!is_null($group)) { |
|
| 124 | + if (!is_null($group)) { |
|
| 125 | 125 | $groups[] = $group; |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | ->execute(); |
| 145 | 145 | |
| 146 | 146 | $users = []; |
| 147 | - while($row = $result->fetch()) { |
|
| 147 | + while ($row = $result->fetch()) { |
|
| 148 | 148 | $user = $this->userManager->get($row['uid']); |
| 149 | - if(!is_null($user)) { |
|
| 149 | + if (!is_null($user)) { |
|
| 150 | 150 | $users[] = $user; |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | ->execute(); |
| 168 | 168 | |
| 169 | 169 | $subadmins = []; |
| 170 | - while($row = $result->fetch()) { |
|
| 170 | + while ($row = $result->fetch()) { |
|
| 171 | 171 | $user = $this->userManager->get($row['uid']); |
| 172 | 172 | $group = $this->groupManager->get($row['gid']); |
| 173 | - if(!is_null($user) && !is_null($group)) { |
|
| 173 | + if (!is_null($user) && !is_null($group)) { |
|
| 174 | 174 | $subadmins[] = [ |
| 175 | 175 | 'user' => $user, |
| 176 | 176 | 'group' => $group |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) |
| 201 | 201 | ->execute(); |
| 202 | 202 | |
| 203 | - $fetch = $result->fetch(); |
|
| 203 | + $fetch = $result->fetch(); |
|
| 204 | 204 | $result->closeCursor(); |
| 205 | 205 | $result = !empty($fetch) ? true : false; |
| 206 | 206 | |
@@ -241,15 +241,15 @@ discard block |
||
| 241 | 241 | * @return bool |
| 242 | 242 | */ |
| 243 | 243 | public function isUserAccessible($subadmin, $user) { |
| 244 | - if(!$this->isSubAdmin($subadmin)) { |
|
| 244 | + if (!$this->isSubAdmin($subadmin)) { |
|
| 245 | 245 | return false; |
| 246 | 246 | } |
| 247 | - if($this->groupManager->isAdmin($user->getUID())) { |
|
| 247 | + if ($this->groupManager->isAdmin($user->getUID())) { |
|
| 248 | 248 | return false; |
| 249 | 249 | } |
| 250 | 250 | $accessibleGroups = $this->getSubAdminsGroups($subadmin); |
| 251 | - foreach($accessibleGroups as $accessibleGroup) { |
|
| 252 | - if($accessibleGroup->inGroup($user)) { |
|
| 251 | + foreach ($accessibleGroups as $accessibleGroup) { |
|
| 252 | + if ($accessibleGroup->inGroup($user)) { |
|
| 253 | 253 | return true; |
| 254 | 254 | } |
| 255 | 255 | } |
@@ -30,523 +30,523 @@ |
||
| 30 | 30 | |
| 31 | 31 | class Event implements IEvent { |
| 32 | 32 | |
| 33 | - /** @var string */ |
|
| 34 | - protected $app = ''; |
|
| 35 | - /** @var string */ |
|
| 36 | - protected $type = ''; |
|
| 37 | - /** @var string */ |
|
| 38 | - protected $affectedUser = ''; |
|
| 39 | - /** @var string */ |
|
| 40 | - protected $author = ''; |
|
| 41 | - /** @var int */ |
|
| 42 | - protected $timestamp = 0; |
|
| 43 | - /** @var string */ |
|
| 44 | - protected $subject = ''; |
|
| 45 | - /** @var array */ |
|
| 46 | - protected $subjectParameters = []; |
|
| 47 | - /** @var string */ |
|
| 48 | - protected $subjectParsed; |
|
| 49 | - /** @var string */ |
|
| 50 | - protected $subjectRich; |
|
| 51 | - /** @var array */ |
|
| 52 | - protected $subjectRichParameters; |
|
| 53 | - /** @var string */ |
|
| 54 | - protected $message = ''; |
|
| 55 | - /** @var array */ |
|
| 56 | - protected $messageParameters = []; |
|
| 57 | - /** @var string */ |
|
| 58 | - protected $messageParsed; |
|
| 59 | - /** @var string */ |
|
| 60 | - protected $messageRich; |
|
| 61 | - /** @var array */ |
|
| 62 | - protected $messageRichParameters; |
|
| 63 | - /** @var string */ |
|
| 64 | - protected $objectType = ''; |
|
| 65 | - /** @var int */ |
|
| 66 | - protected $objectId = 0; |
|
| 67 | - /** @var string */ |
|
| 68 | - protected $objectName = ''; |
|
| 69 | - /** @var string */ |
|
| 70 | - protected $link = ''; |
|
| 71 | - /** @var string */ |
|
| 72 | - protected $icon = ''; |
|
| 73 | - |
|
| 74 | - /** @var IEvent */ |
|
| 75 | - protected $child = null; |
|
| 76 | - /** @var IValidator */ |
|
| 77 | - protected $richValidator; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param IValidator $richValidator |
|
| 81 | - */ |
|
| 82 | - public function __construct(IValidator $richValidator) { |
|
| 83 | - $this->richValidator = $richValidator; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Set the app of the activity |
|
| 88 | - * |
|
| 89 | - * @param string $app |
|
| 90 | - * @return IEvent |
|
| 91 | - * @throws \InvalidArgumentException if the app id is invalid |
|
| 92 | - * @since 8.2.0 |
|
| 93 | - */ |
|
| 94 | - public function setApp($app) { |
|
| 95 | - if (!is_string($app) || $app === '' || isset($app[32])) { |
|
| 96 | - throw new \InvalidArgumentException('The given app is invalid'); |
|
| 97 | - } |
|
| 98 | - $this->app = (string) $app; |
|
| 99 | - return $this; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - public function getApp() { |
|
| 106 | - return $this->app; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Set the type of the activity |
|
| 111 | - * |
|
| 112 | - * @param string $type |
|
| 113 | - * @return IEvent |
|
| 114 | - * @throws \InvalidArgumentException if the type is invalid |
|
| 115 | - * @since 8.2.0 |
|
| 116 | - */ |
|
| 117 | - public function setType($type) { |
|
| 118 | - if (!is_string($type) || $type === '' || isset($type[255])) { |
|
| 119 | - throw new \InvalidArgumentException('The given type is invalid'); |
|
| 120 | - } |
|
| 121 | - $this->type = (string) $type; |
|
| 122 | - return $this; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - public function getType() { |
|
| 129 | - return $this->type; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Set the affected user of the activity |
|
| 134 | - * |
|
| 135 | - * @param string $affectedUser |
|
| 136 | - * @return IEvent |
|
| 137 | - * @throws \InvalidArgumentException if the affected user is invalid |
|
| 138 | - * @since 8.2.0 |
|
| 139 | - */ |
|
| 140 | - public function setAffectedUser($affectedUser) { |
|
| 141 | - if (!is_string($affectedUser) || $affectedUser === '' || isset($affectedUser[64])) { |
|
| 142 | - throw new \InvalidArgumentException('The given affected user is invalid'); |
|
| 143 | - } |
|
| 144 | - $this->affectedUser = (string) $affectedUser; |
|
| 145 | - return $this; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @return string |
|
| 150 | - */ |
|
| 151 | - public function getAffectedUser() { |
|
| 152 | - return $this->affectedUser; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Set the author of the activity |
|
| 157 | - * |
|
| 158 | - * @param string $author |
|
| 159 | - * @return IEvent |
|
| 160 | - * @throws \InvalidArgumentException if the author is invalid |
|
| 161 | - * @since 8.2.0 |
|
| 162 | - */ |
|
| 163 | - public function setAuthor($author) { |
|
| 164 | - if (!is_string($author) || isset($author[64])) { |
|
| 165 | - throw new \InvalidArgumentException('The given author user is invalid'. serialize($author)); |
|
| 166 | - } |
|
| 167 | - $this->author = (string) $author; |
|
| 168 | - return $this; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @return string |
|
| 173 | - */ |
|
| 174 | - public function getAuthor() { |
|
| 175 | - return $this->author; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Set the timestamp of the activity |
|
| 180 | - * |
|
| 181 | - * @param int $timestamp |
|
| 182 | - * @return IEvent |
|
| 183 | - * @throws \InvalidArgumentException if the timestamp is invalid |
|
| 184 | - * @since 8.2.0 |
|
| 185 | - */ |
|
| 186 | - public function setTimestamp($timestamp) { |
|
| 187 | - if (!is_int($timestamp)) { |
|
| 188 | - throw new \InvalidArgumentException('The given timestamp is invalid'); |
|
| 189 | - } |
|
| 190 | - $this->timestamp = (int) $timestamp; |
|
| 191 | - return $this; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @return int |
|
| 196 | - */ |
|
| 197 | - public function getTimestamp() { |
|
| 198 | - return $this->timestamp; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Set the subject of the activity |
|
| 203 | - * |
|
| 204 | - * @param string $subject |
|
| 205 | - * @param array $parameters |
|
| 206 | - * @return IEvent |
|
| 207 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
| 208 | - * @since 8.2.0 |
|
| 209 | - */ |
|
| 210 | - public function setSubject($subject, array $parameters = []) { |
|
| 211 | - if (!is_string($subject) || isset($subject[255])) { |
|
| 212 | - throw new \InvalidArgumentException('The given subject is invalid'); |
|
| 213 | - } |
|
| 214 | - $this->subject = (string) $subject; |
|
| 215 | - $this->subjectParameters = $parameters; |
|
| 216 | - return $this; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @return string |
|
| 221 | - */ |
|
| 222 | - public function getSubject() { |
|
| 223 | - return $this->subject; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @return array |
|
| 228 | - */ |
|
| 229 | - public function getSubjectParameters() { |
|
| 230 | - return $this->subjectParameters; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @param string $subject |
|
| 235 | - * @return $this |
|
| 236 | - * @throws \InvalidArgumentException if the subject is invalid |
|
| 237 | - * @since 11.0.0 |
|
| 238 | - */ |
|
| 239 | - public function setParsedSubject($subject) { |
|
| 240 | - if (!is_string($subject) || $subject === '') { |
|
| 241 | - throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
| 242 | - } |
|
| 243 | - $this->subjectParsed = $subject; |
|
| 244 | - return $this; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * @return string |
|
| 249 | - * @since 11.0.0 |
|
| 250 | - */ |
|
| 251 | - public function getParsedSubject() { |
|
| 252 | - return $this->subjectParsed; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @param string $subject |
|
| 257 | - * @param array $parameters |
|
| 258 | - * @return $this |
|
| 259 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
| 260 | - * @since 11.0.0 |
|
| 261 | - */ |
|
| 262 | - public function setRichSubject($subject, array $parameters = []) { |
|
| 263 | - if (!is_string($subject) || $subject === '') { |
|
| 264 | - throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
| 265 | - } |
|
| 266 | - $this->subjectRich = $subject; |
|
| 267 | - |
|
| 268 | - if (!is_array($parameters)) { |
|
| 269 | - throw new \InvalidArgumentException('The given subject parameters are invalid'); |
|
| 270 | - } |
|
| 271 | - $this->subjectRichParameters = $parameters; |
|
| 272 | - |
|
| 273 | - return $this; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @return string |
|
| 278 | - * @since 11.0.0 |
|
| 279 | - */ |
|
| 280 | - public function getRichSubject() { |
|
| 281 | - return $this->subjectRich; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * @return array[] |
|
| 286 | - * @since 11.0.0 |
|
| 287 | - */ |
|
| 288 | - public function getRichSubjectParameters() { |
|
| 289 | - return $this->subjectRichParameters; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Set the message of the activity |
|
| 294 | - * |
|
| 295 | - * @param string $message |
|
| 296 | - * @param array $parameters |
|
| 297 | - * @return IEvent |
|
| 298 | - * @throws \InvalidArgumentException if the message or parameters are invalid |
|
| 299 | - * @since 8.2.0 |
|
| 300 | - */ |
|
| 301 | - public function setMessage($message, array $parameters = []) { |
|
| 302 | - if (!is_string($message) || isset($message[255])) { |
|
| 303 | - throw new \InvalidArgumentException('The given message is invalid'); |
|
| 304 | - } |
|
| 305 | - $this->message = (string) $message; |
|
| 306 | - $this->messageParameters = $parameters; |
|
| 307 | - return $this; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @return string |
|
| 312 | - */ |
|
| 313 | - public function getMessage() { |
|
| 314 | - return $this->message; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @return array |
|
| 319 | - */ |
|
| 320 | - public function getMessageParameters() { |
|
| 321 | - return $this->messageParameters; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * @param string $message |
|
| 326 | - * @return $this |
|
| 327 | - * @throws \InvalidArgumentException if the message is invalid |
|
| 328 | - * @since 11.0.0 |
|
| 329 | - */ |
|
| 330 | - public function setParsedMessage($message) { |
|
| 331 | - if (!is_string($message)) { |
|
| 332 | - throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
| 333 | - } |
|
| 334 | - $this->messageParsed = $message; |
|
| 335 | - return $this; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * @return string |
|
| 340 | - * @since 11.0.0 |
|
| 341 | - */ |
|
| 342 | - public function getParsedMessage() { |
|
| 343 | - return $this->messageParsed; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @param string $message |
|
| 348 | - * @param array $parameters |
|
| 349 | - * @return $this |
|
| 350 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
| 351 | - * @since 11.0.0 |
|
| 352 | - */ |
|
| 353 | - public function setRichMessage($message, array $parameters = []) { |
|
| 354 | - if (!is_string($message)) { |
|
| 355 | - throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
| 356 | - } |
|
| 357 | - $this->messageRich = $message; |
|
| 358 | - |
|
| 359 | - if (!is_array($parameters)) { |
|
| 360 | - throw new \InvalidArgumentException('The given message parameters are invalid'); |
|
| 361 | - } |
|
| 362 | - $this->messageRichParameters = $parameters; |
|
| 363 | - |
|
| 364 | - return $this; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * @return string |
|
| 369 | - * @since 11.0.0 |
|
| 370 | - */ |
|
| 371 | - public function getRichMessage() { |
|
| 372 | - return $this->messageRich; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * @return array[] |
|
| 377 | - * @since 11.0.0 |
|
| 378 | - */ |
|
| 379 | - public function getRichMessageParameters() { |
|
| 380 | - return $this->messageRichParameters; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Set the object of the activity |
|
| 385 | - * |
|
| 386 | - * @param string $objectType |
|
| 387 | - * @param int $objectId |
|
| 388 | - * @param string $objectName |
|
| 389 | - * @return IEvent |
|
| 390 | - * @throws \InvalidArgumentException if the object is invalid |
|
| 391 | - * @since 8.2.0 |
|
| 392 | - */ |
|
| 393 | - public function setObject($objectType, $objectId, $objectName = '') { |
|
| 394 | - if (!is_string($objectType) || isset($objectType[255])) { |
|
| 395 | - throw new \InvalidArgumentException('The given object type is invalid'); |
|
| 396 | - } |
|
| 397 | - if (!is_int($objectId)) { |
|
| 398 | - throw new \InvalidArgumentException('The given object id is invalid'); |
|
| 399 | - } |
|
| 400 | - if (!is_string($objectName) || isset($objectName[4000])) { |
|
| 401 | - throw new \InvalidArgumentException('The given object name is invalid'); |
|
| 402 | - } |
|
| 403 | - $this->objectType = (string) $objectType; |
|
| 404 | - $this->objectId = (int) $objectId; |
|
| 405 | - $this->objectName = (string) $objectName; |
|
| 406 | - return $this; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * @return string |
|
| 411 | - */ |
|
| 412 | - public function getObjectType() { |
|
| 413 | - return $this->objectType; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * @return string |
|
| 418 | - */ |
|
| 419 | - public function getObjectId() { |
|
| 420 | - return $this->objectId; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * @return string |
|
| 425 | - */ |
|
| 426 | - public function getObjectName() { |
|
| 427 | - return $this->objectName; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Set the link of the activity |
|
| 432 | - * |
|
| 433 | - * @param string $link |
|
| 434 | - * @return IEvent |
|
| 435 | - * @throws \InvalidArgumentException if the link is invalid |
|
| 436 | - * @since 8.2.0 |
|
| 437 | - */ |
|
| 438 | - public function setLink($link) { |
|
| 439 | - if (!is_string($link) || isset($link[4000])) { |
|
| 440 | - throw new \InvalidArgumentException('The given link is invalid'); |
|
| 441 | - } |
|
| 442 | - $this->link = (string) $link; |
|
| 443 | - return $this; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * @return string |
|
| 448 | - */ |
|
| 449 | - public function getLink() { |
|
| 450 | - return $this->link; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * @param string $icon |
|
| 455 | - * @return $this |
|
| 456 | - * @throws \InvalidArgumentException if the icon is invalid |
|
| 457 | - * @since 11.0.0 |
|
| 458 | - */ |
|
| 459 | - public function setIcon($icon) { |
|
| 460 | - if (!is_string($icon) || isset($icon[4000])) { |
|
| 461 | - throw new \InvalidArgumentException('The given icon is invalid'); |
|
| 462 | - } |
|
| 463 | - $this->icon = $icon; |
|
| 464 | - return $this; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * @return string |
|
| 469 | - * @since 11.0.0 |
|
| 470 | - */ |
|
| 471 | - public function getIcon() { |
|
| 472 | - return $this->icon; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * @param IEvent $child |
|
| 477 | - * @since 11.0.0 |
|
| 478 | - */ |
|
| 479 | - public function setChildEvent(IEvent $child) { |
|
| 480 | - $this->child = $child; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * @return IEvent|null |
|
| 485 | - * @since 11.0.0 |
|
| 486 | - */ |
|
| 487 | - public function getChildEvent() { |
|
| 488 | - return $this->child; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * @return bool |
|
| 493 | - * @since 8.2.0 |
|
| 494 | - */ |
|
| 495 | - public function isValid() { |
|
| 496 | - return |
|
| 497 | - $this->isValidCommon() |
|
| 498 | - && |
|
| 499 | - $this->getSubject() !== '' |
|
| 500 | - ; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * @return bool |
|
| 505 | - * @since 8.2.0 |
|
| 506 | - */ |
|
| 507 | - public function isValidParsed() { |
|
| 508 | - if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) { |
|
| 509 | - try { |
|
| 510 | - $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters()); |
|
| 511 | - } catch (InvalidObjectExeption $e) { |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) { |
|
| 517 | - try { |
|
| 518 | - $this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters()); |
|
| 519 | - } catch (InvalidObjectExeption $e) { |
|
| 520 | - return false; |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - return |
|
| 525 | - $this->isValidCommon() |
|
| 526 | - && |
|
| 527 | - $this->getParsedSubject() !== '' |
|
| 528 | - ; |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * @return bool |
|
| 533 | - */ |
|
| 534 | - protected function isValidCommon() { |
|
| 535 | - return |
|
| 536 | - $this->getApp() !== '' |
|
| 537 | - && |
|
| 538 | - $this->getType() !== '' |
|
| 539 | - && |
|
| 540 | - $this->getAffectedUser() !== '' |
|
| 541 | - && |
|
| 542 | - $this->getTimestamp() !== 0 |
|
| 543 | - /** |
|
| 544 | - * Disabled for BC with old activities |
|
| 33 | + /** @var string */ |
|
| 34 | + protected $app = ''; |
|
| 35 | + /** @var string */ |
|
| 36 | + protected $type = ''; |
|
| 37 | + /** @var string */ |
|
| 38 | + protected $affectedUser = ''; |
|
| 39 | + /** @var string */ |
|
| 40 | + protected $author = ''; |
|
| 41 | + /** @var int */ |
|
| 42 | + protected $timestamp = 0; |
|
| 43 | + /** @var string */ |
|
| 44 | + protected $subject = ''; |
|
| 45 | + /** @var array */ |
|
| 46 | + protected $subjectParameters = []; |
|
| 47 | + /** @var string */ |
|
| 48 | + protected $subjectParsed; |
|
| 49 | + /** @var string */ |
|
| 50 | + protected $subjectRich; |
|
| 51 | + /** @var array */ |
|
| 52 | + protected $subjectRichParameters; |
|
| 53 | + /** @var string */ |
|
| 54 | + protected $message = ''; |
|
| 55 | + /** @var array */ |
|
| 56 | + protected $messageParameters = []; |
|
| 57 | + /** @var string */ |
|
| 58 | + protected $messageParsed; |
|
| 59 | + /** @var string */ |
|
| 60 | + protected $messageRich; |
|
| 61 | + /** @var array */ |
|
| 62 | + protected $messageRichParameters; |
|
| 63 | + /** @var string */ |
|
| 64 | + protected $objectType = ''; |
|
| 65 | + /** @var int */ |
|
| 66 | + protected $objectId = 0; |
|
| 67 | + /** @var string */ |
|
| 68 | + protected $objectName = ''; |
|
| 69 | + /** @var string */ |
|
| 70 | + protected $link = ''; |
|
| 71 | + /** @var string */ |
|
| 72 | + protected $icon = ''; |
|
| 73 | + |
|
| 74 | + /** @var IEvent */ |
|
| 75 | + protected $child = null; |
|
| 76 | + /** @var IValidator */ |
|
| 77 | + protected $richValidator; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param IValidator $richValidator |
|
| 81 | + */ |
|
| 82 | + public function __construct(IValidator $richValidator) { |
|
| 83 | + $this->richValidator = $richValidator; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Set the app of the activity |
|
| 88 | + * |
|
| 89 | + * @param string $app |
|
| 90 | + * @return IEvent |
|
| 91 | + * @throws \InvalidArgumentException if the app id is invalid |
|
| 92 | + * @since 8.2.0 |
|
| 93 | + */ |
|
| 94 | + public function setApp($app) { |
|
| 95 | + if (!is_string($app) || $app === '' || isset($app[32])) { |
|
| 96 | + throw new \InvalidArgumentException('The given app is invalid'); |
|
| 97 | + } |
|
| 98 | + $this->app = (string) $app; |
|
| 99 | + return $this; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + public function getApp() { |
|
| 106 | + return $this->app; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Set the type of the activity |
|
| 111 | + * |
|
| 112 | + * @param string $type |
|
| 113 | + * @return IEvent |
|
| 114 | + * @throws \InvalidArgumentException if the type is invalid |
|
| 115 | + * @since 8.2.0 |
|
| 116 | + */ |
|
| 117 | + public function setType($type) { |
|
| 118 | + if (!is_string($type) || $type === '' || isset($type[255])) { |
|
| 119 | + throw new \InvalidArgumentException('The given type is invalid'); |
|
| 120 | + } |
|
| 121 | + $this->type = (string) $type; |
|
| 122 | + return $this; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + public function getType() { |
|
| 129 | + return $this->type; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Set the affected user of the activity |
|
| 134 | + * |
|
| 135 | + * @param string $affectedUser |
|
| 136 | + * @return IEvent |
|
| 137 | + * @throws \InvalidArgumentException if the affected user is invalid |
|
| 138 | + * @since 8.2.0 |
|
| 139 | + */ |
|
| 140 | + public function setAffectedUser($affectedUser) { |
|
| 141 | + if (!is_string($affectedUser) || $affectedUser === '' || isset($affectedUser[64])) { |
|
| 142 | + throw new \InvalidArgumentException('The given affected user is invalid'); |
|
| 143 | + } |
|
| 144 | + $this->affectedUser = (string) $affectedUser; |
|
| 145 | + return $this; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @return string |
|
| 150 | + */ |
|
| 151 | + public function getAffectedUser() { |
|
| 152 | + return $this->affectedUser; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Set the author of the activity |
|
| 157 | + * |
|
| 158 | + * @param string $author |
|
| 159 | + * @return IEvent |
|
| 160 | + * @throws \InvalidArgumentException if the author is invalid |
|
| 161 | + * @since 8.2.0 |
|
| 162 | + */ |
|
| 163 | + public function setAuthor($author) { |
|
| 164 | + if (!is_string($author) || isset($author[64])) { |
|
| 165 | + throw new \InvalidArgumentException('The given author user is invalid'. serialize($author)); |
|
| 166 | + } |
|
| 167 | + $this->author = (string) $author; |
|
| 168 | + return $this; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @return string |
|
| 173 | + */ |
|
| 174 | + public function getAuthor() { |
|
| 175 | + return $this->author; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Set the timestamp of the activity |
|
| 180 | + * |
|
| 181 | + * @param int $timestamp |
|
| 182 | + * @return IEvent |
|
| 183 | + * @throws \InvalidArgumentException if the timestamp is invalid |
|
| 184 | + * @since 8.2.0 |
|
| 185 | + */ |
|
| 186 | + public function setTimestamp($timestamp) { |
|
| 187 | + if (!is_int($timestamp)) { |
|
| 188 | + throw new \InvalidArgumentException('The given timestamp is invalid'); |
|
| 189 | + } |
|
| 190 | + $this->timestamp = (int) $timestamp; |
|
| 191 | + return $this; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @return int |
|
| 196 | + */ |
|
| 197 | + public function getTimestamp() { |
|
| 198 | + return $this->timestamp; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Set the subject of the activity |
|
| 203 | + * |
|
| 204 | + * @param string $subject |
|
| 205 | + * @param array $parameters |
|
| 206 | + * @return IEvent |
|
| 207 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
| 208 | + * @since 8.2.0 |
|
| 209 | + */ |
|
| 210 | + public function setSubject($subject, array $parameters = []) { |
|
| 211 | + if (!is_string($subject) || isset($subject[255])) { |
|
| 212 | + throw new \InvalidArgumentException('The given subject is invalid'); |
|
| 213 | + } |
|
| 214 | + $this->subject = (string) $subject; |
|
| 215 | + $this->subjectParameters = $parameters; |
|
| 216 | + return $this; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @return string |
|
| 221 | + */ |
|
| 222 | + public function getSubject() { |
|
| 223 | + return $this->subject; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @return array |
|
| 228 | + */ |
|
| 229 | + public function getSubjectParameters() { |
|
| 230 | + return $this->subjectParameters; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @param string $subject |
|
| 235 | + * @return $this |
|
| 236 | + * @throws \InvalidArgumentException if the subject is invalid |
|
| 237 | + * @since 11.0.0 |
|
| 238 | + */ |
|
| 239 | + public function setParsedSubject($subject) { |
|
| 240 | + if (!is_string($subject) || $subject === '') { |
|
| 241 | + throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
| 242 | + } |
|
| 243 | + $this->subjectParsed = $subject; |
|
| 244 | + return $this; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * @return string |
|
| 249 | + * @since 11.0.0 |
|
| 250 | + */ |
|
| 251 | + public function getParsedSubject() { |
|
| 252 | + return $this->subjectParsed; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @param string $subject |
|
| 257 | + * @param array $parameters |
|
| 258 | + * @return $this |
|
| 259 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
| 260 | + * @since 11.0.0 |
|
| 261 | + */ |
|
| 262 | + public function setRichSubject($subject, array $parameters = []) { |
|
| 263 | + if (!is_string($subject) || $subject === '') { |
|
| 264 | + throw new \InvalidArgumentException('The given parsed subject is invalid'); |
|
| 265 | + } |
|
| 266 | + $this->subjectRich = $subject; |
|
| 267 | + |
|
| 268 | + if (!is_array($parameters)) { |
|
| 269 | + throw new \InvalidArgumentException('The given subject parameters are invalid'); |
|
| 270 | + } |
|
| 271 | + $this->subjectRichParameters = $parameters; |
|
| 272 | + |
|
| 273 | + return $this; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @return string |
|
| 278 | + * @since 11.0.0 |
|
| 279 | + */ |
|
| 280 | + public function getRichSubject() { |
|
| 281 | + return $this->subjectRich; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * @return array[] |
|
| 286 | + * @since 11.0.0 |
|
| 287 | + */ |
|
| 288 | + public function getRichSubjectParameters() { |
|
| 289 | + return $this->subjectRichParameters; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Set the message of the activity |
|
| 294 | + * |
|
| 295 | + * @param string $message |
|
| 296 | + * @param array $parameters |
|
| 297 | + * @return IEvent |
|
| 298 | + * @throws \InvalidArgumentException if the message or parameters are invalid |
|
| 299 | + * @since 8.2.0 |
|
| 300 | + */ |
|
| 301 | + public function setMessage($message, array $parameters = []) { |
|
| 302 | + if (!is_string($message) || isset($message[255])) { |
|
| 303 | + throw new \InvalidArgumentException('The given message is invalid'); |
|
| 304 | + } |
|
| 305 | + $this->message = (string) $message; |
|
| 306 | + $this->messageParameters = $parameters; |
|
| 307 | + return $this; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @return string |
|
| 312 | + */ |
|
| 313 | + public function getMessage() { |
|
| 314 | + return $this->message; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @return array |
|
| 319 | + */ |
|
| 320 | + public function getMessageParameters() { |
|
| 321 | + return $this->messageParameters; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * @param string $message |
|
| 326 | + * @return $this |
|
| 327 | + * @throws \InvalidArgumentException if the message is invalid |
|
| 328 | + * @since 11.0.0 |
|
| 329 | + */ |
|
| 330 | + public function setParsedMessage($message) { |
|
| 331 | + if (!is_string($message)) { |
|
| 332 | + throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
| 333 | + } |
|
| 334 | + $this->messageParsed = $message; |
|
| 335 | + return $this; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * @return string |
|
| 340 | + * @since 11.0.0 |
|
| 341 | + */ |
|
| 342 | + public function getParsedMessage() { |
|
| 343 | + return $this->messageParsed; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @param string $message |
|
| 348 | + * @param array $parameters |
|
| 349 | + * @return $this |
|
| 350 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
| 351 | + * @since 11.0.0 |
|
| 352 | + */ |
|
| 353 | + public function setRichMessage($message, array $parameters = []) { |
|
| 354 | + if (!is_string($message)) { |
|
| 355 | + throw new \InvalidArgumentException('The given parsed message is invalid'); |
|
| 356 | + } |
|
| 357 | + $this->messageRich = $message; |
|
| 358 | + |
|
| 359 | + if (!is_array($parameters)) { |
|
| 360 | + throw new \InvalidArgumentException('The given message parameters are invalid'); |
|
| 361 | + } |
|
| 362 | + $this->messageRichParameters = $parameters; |
|
| 363 | + |
|
| 364 | + return $this; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * @return string |
|
| 369 | + * @since 11.0.0 |
|
| 370 | + */ |
|
| 371 | + public function getRichMessage() { |
|
| 372 | + return $this->messageRich; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * @return array[] |
|
| 377 | + * @since 11.0.0 |
|
| 378 | + */ |
|
| 379 | + public function getRichMessageParameters() { |
|
| 380 | + return $this->messageRichParameters; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Set the object of the activity |
|
| 385 | + * |
|
| 386 | + * @param string $objectType |
|
| 387 | + * @param int $objectId |
|
| 388 | + * @param string $objectName |
|
| 389 | + * @return IEvent |
|
| 390 | + * @throws \InvalidArgumentException if the object is invalid |
|
| 391 | + * @since 8.2.0 |
|
| 392 | + */ |
|
| 393 | + public function setObject($objectType, $objectId, $objectName = '') { |
|
| 394 | + if (!is_string($objectType) || isset($objectType[255])) { |
|
| 395 | + throw new \InvalidArgumentException('The given object type is invalid'); |
|
| 396 | + } |
|
| 397 | + if (!is_int($objectId)) { |
|
| 398 | + throw new \InvalidArgumentException('The given object id is invalid'); |
|
| 399 | + } |
|
| 400 | + if (!is_string($objectName) || isset($objectName[4000])) { |
|
| 401 | + throw new \InvalidArgumentException('The given object name is invalid'); |
|
| 402 | + } |
|
| 403 | + $this->objectType = (string) $objectType; |
|
| 404 | + $this->objectId = (int) $objectId; |
|
| 405 | + $this->objectName = (string) $objectName; |
|
| 406 | + return $this; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * @return string |
|
| 411 | + */ |
|
| 412 | + public function getObjectType() { |
|
| 413 | + return $this->objectType; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * @return string |
|
| 418 | + */ |
|
| 419 | + public function getObjectId() { |
|
| 420 | + return $this->objectId; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * @return string |
|
| 425 | + */ |
|
| 426 | + public function getObjectName() { |
|
| 427 | + return $this->objectName; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Set the link of the activity |
|
| 432 | + * |
|
| 433 | + * @param string $link |
|
| 434 | + * @return IEvent |
|
| 435 | + * @throws \InvalidArgumentException if the link is invalid |
|
| 436 | + * @since 8.2.0 |
|
| 437 | + */ |
|
| 438 | + public function setLink($link) { |
|
| 439 | + if (!is_string($link) || isset($link[4000])) { |
|
| 440 | + throw new \InvalidArgumentException('The given link is invalid'); |
|
| 441 | + } |
|
| 442 | + $this->link = (string) $link; |
|
| 443 | + return $this; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * @return string |
|
| 448 | + */ |
|
| 449 | + public function getLink() { |
|
| 450 | + return $this->link; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * @param string $icon |
|
| 455 | + * @return $this |
|
| 456 | + * @throws \InvalidArgumentException if the icon is invalid |
|
| 457 | + * @since 11.0.0 |
|
| 458 | + */ |
|
| 459 | + public function setIcon($icon) { |
|
| 460 | + if (!is_string($icon) || isset($icon[4000])) { |
|
| 461 | + throw new \InvalidArgumentException('The given icon is invalid'); |
|
| 462 | + } |
|
| 463 | + $this->icon = $icon; |
|
| 464 | + return $this; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * @return string |
|
| 469 | + * @since 11.0.0 |
|
| 470 | + */ |
|
| 471 | + public function getIcon() { |
|
| 472 | + return $this->icon; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * @param IEvent $child |
|
| 477 | + * @since 11.0.0 |
|
| 478 | + */ |
|
| 479 | + public function setChildEvent(IEvent $child) { |
|
| 480 | + $this->child = $child; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * @return IEvent|null |
|
| 485 | + * @since 11.0.0 |
|
| 486 | + */ |
|
| 487 | + public function getChildEvent() { |
|
| 488 | + return $this->child; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * @return bool |
|
| 493 | + * @since 8.2.0 |
|
| 494 | + */ |
|
| 495 | + public function isValid() { |
|
| 496 | + return |
|
| 497 | + $this->isValidCommon() |
|
| 498 | + && |
|
| 499 | + $this->getSubject() !== '' |
|
| 500 | + ; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * @return bool |
|
| 505 | + * @since 8.2.0 |
|
| 506 | + */ |
|
| 507 | + public function isValidParsed() { |
|
| 508 | + if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) { |
|
| 509 | + try { |
|
| 510 | + $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters()); |
|
| 511 | + } catch (InvalidObjectExeption $e) { |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) { |
|
| 517 | + try { |
|
| 518 | + $this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters()); |
|
| 519 | + } catch (InvalidObjectExeption $e) { |
|
| 520 | + return false; |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + return |
|
| 525 | + $this->isValidCommon() |
|
| 526 | + && |
|
| 527 | + $this->getParsedSubject() !== '' |
|
| 528 | + ; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * @return bool |
|
| 533 | + */ |
|
| 534 | + protected function isValidCommon() { |
|
| 535 | + return |
|
| 536 | + $this->getApp() !== '' |
|
| 537 | + && |
|
| 538 | + $this->getType() !== '' |
|
| 539 | + && |
|
| 540 | + $this->getAffectedUser() !== '' |
|
| 541 | + && |
|
| 542 | + $this->getTimestamp() !== 0 |
|
| 543 | + /** |
|
| 544 | + * Disabled for BC with old activities |
|
| 545 | 545 | && |
| 546 | 546 | $this->getObjectType() !== '' |
| 547 | 547 | && |
| 548 | 548 | $this->getObjectId() !== 0 |
| 549 | - */ |
|
| 550 | - ; |
|
| 551 | - } |
|
| 549 | + */ |
|
| 550 | + ; |
|
| 551 | + } |
|
| 552 | 552 | } |
@@ -162,7 +162,7 @@ |
||
| 162 | 162 | */ |
| 163 | 163 | public function setAuthor($author) { |
| 164 | 164 | if (!is_string($author) || isset($author[64])) { |
| 165 | - throw new \InvalidArgumentException('The given author user is invalid'. serialize($author)); |
|
| 165 | + throw new \InvalidArgumentException('The given author user is invalid'.serialize($author)); |
|
| 166 | 166 | } |
| 167 | 167 | $this->author = (string) $author; |
| 168 | 168 | return $this; |
@@ -26,83 +26,83 @@ |
||
| 26 | 26 | |
| 27 | 27 | class LegacyFilter implements IFilter { |
| 28 | 28 | |
| 29 | - /** @var IManager */ |
|
| 30 | - protected $manager; |
|
| 31 | - /** @var string */ |
|
| 32 | - protected $identifier; |
|
| 33 | - /** @var string */ |
|
| 34 | - protected $name; |
|
| 35 | - /** @var bool */ |
|
| 36 | - protected $isTopFilter; |
|
| 29 | + /** @var IManager */ |
|
| 30 | + protected $manager; |
|
| 31 | + /** @var string */ |
|
| 32 | + protected $identifier; |
|
| 33 | + /** @var string */ |
|
| 34 | + protected $name; |
|
| 35 | + /** @var bool */ |
|
| 36 | + protected $isTopFilter; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * LegacySetting constructor. |
|
| 40 | - * |
|
| 41 | - * @param IManager $manager |
|
| 42 | - * @param string $identifier |
|
| 43 | - * @param string $name |
|
| 44 | - * @param bool $isTopFilter |
|
| 45 | - */ |
|
| 46 | - public function __construct(IManager $manager, |
|
| 47 | - $identifier, |
|
| 48 | - $name, |
|
| 49 | - $isTopFilter) { |
|
| 50 | - $this->manager = $manager; |
|
| 51 | - $this->identifier = $identifier; |
|
| 52 | - $this->name = $name; |
|
| 53 | - $this->isTopFilter = $isTopFilter; |
|
| 54 | - } |
|
| 38 | + /** |
|
| 39 | + * LegacySetting constructor. |
|
| 40 | + * |
|
| 41 | + * @param IManager $manager |
|
| 42 | + * @param string $identifier |
|
| 43 | + * @param string $name |
|
| 44 | + * @param bool $isTopFilter |
|
| 45 | + */ |
|
| 46 | + public function __construct(IManager $manager, |
|
| 47 | + $identifier, |
|
| 48 | + $name, |
|
| 49 | + $isTopFilter) { |
|
| 50 | + $this->manager = $manager; |
|
| 51 | + $this->identifier = $identifier; |
|
| 52 | + $this->name = $name; |
|
| 53 | + $this->isTopFilter = $isTopFilter; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @return string Lowercase a-z and underscore only identifier |
|
| 58 | - * @since 11.0.0 |
|
| 59 | - */ |
|
| 60 | - public function getIdentifier() { |
|
| 61 | - return $this->identifier; |
|
| 62 | - } |
|
| 56 | + /** |
|
| 57 | + * @return string Lowercase a-z and underscore only identifier |
|
| 58 | + * @since 11.0.0 |
|
| 59 | + */ |
|
| 60 | + public function getIdentifier() { |
|
| 61 | + return $this->identifier; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return string A translated string |
|
| 66 | - * @since 11.0.0 |
|
| 67 | - */ |
|
| 68 | - public function getName() { |
|
| 69 | - return $this->name; |
|
| 70 | - } |
|
| 64 | + /** |
|
| 65 | + * @return string A translated string |
|
| 66 | + * @since 11.0.0 |
|
| 67 | + */ |
|
| 68 | + public function getName() { |
|
| 69 | + return $this->name; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @return int whether the filter should be rather on the top or bottom of |
|
| 74 | - * the admin section. The filters are arranged in ascending order of the |
|
| 75 | - * priority values. It is required to return a value between 0 and 100. |
|
| 76 | - * @since 11.0.0 |
|
| 77 | - */ |
|
| 78 | - public function getPriority() { |
|
| 79 | - return $this->isTopFilter ? 40 : 50; |
|
| 80 | - } |
|
| 72 | + /** |
|
| 73 | + * @return int whether the filter should be rather on the top or bottom of |
|
| 74 | + * the admin section. The filters are arranged in ascending order of the |
|
| 75 | + * priority values. It is required to return a value between 0 and 100. |
|
| 76 | + * @since 11.0.0 |
|
| 77 | + */ |
|
| 78 | + public function getPriority() { |
|
| 79 | + return $this->isTopFilter ? 40 : 50; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @return string Full URL to an icon, empty string when none is given |
|
| 84 | - * @since 11.0.0 |
|
| 85 | - */ |
|
| 86 | - public function getIcon() { |
|
| 87 | - // Old API was CSS class, so we can not use this... |
|
| 88 | - return ''; |
|
| 89 | - } |
|
| 82 | + /** |
|
| 83 | + * @return string Full URL to an icon, empty string when none is given |
|
| 84 | + * @since 11.0.0 |
|
| 85 | + */ |
|
| 86 | + public function getIcon() { |
|
| 87 | + // Old API was CSS class, so we can not use this... |
|
| 88 | + return ''; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @param string[] $types |
|
| 93 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
| 94 | - * @since 11.0.0 |
|
| 95 | - */ |
|
| 96 | - public function filterTypes(array $types) { |
|
| 97 | - return $this->manager->filterNotificationTypes($types, $this->getIdentifier()); |
|
| 98 | - } |
|
| 91 | + /** |
|
| 92 | + * @param string[] $types |
|
| 93 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
| 94 | + * @since 11.0.0 |
|
| 95 | + */ |
|
| 96 | + public function filterTypes(array $types) { |
|
| 97 | + return $this->manager->filterNotificationTypes($types, $this->getIdentifier()); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
| 102 | - * @since 11.0.0 |
|
| 103 | - */ |
|
| 104 | - public function allowedApps() { |
|
| 105 | - return []; |
|
| 106 | - } |
|
| 100 | + /** |
|
| 101 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
| 102 | + * @since 11.0.0 |
|
| 103 | + */ |
|
| 104 | + public function allowedApps() { |
|
| 105 | + return []; |
|
| 106 | + } |
|
| 107 | 107 | } |
| 108 | 108 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $this->consumers = []; |
| 115 | - foreach($this->consumersClosures as $consumer) { |
|
| 115 | + foreach ($this->consumersClosures as $consumer) { |
|
| 116 | 116 | $c = $consumer(); |
| 117 | 117 | if ($c instanceof IConsumer) { |
| 118 | 118 | $this->consumers[] = $c; |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | $this->extensions = []; |
| 136 | - foreach($this->extensionsClosures as $extension) { |
|
| 136 | + foreach ($this->extensionsClosures as $extension) { |
|
| 137 | 137 | $e = $extension(); |
| 138 | 138 | if ($e instanceof IExtension) { |
| 139 | 139 | $this->extensions[] = $e; |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | return array(null, null); |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
| 672 | + return array(' and (('.implode(') or (', $conditions).'))', $parameters); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -39,688 +39,688 @@ |
||
| 39 | 39 | use OCP\RichObjectStrings\IValidator; |
| 40 | 40 | |
| 41 | 41 | class Manager implements IManager { |
| 42 | - /** @var IRequest */ |
|
| 43 | - protected $request; |
|
| 44 | - |
|
| 45 | - /** @var IUserSession */ |
|
| 46 | - protected $session; |
|
| 47 | - |
|
| 48 | - /** @var IConfig */ |
|
| 49 | - protected $config; |
|
| 50 | - |
|
| 51 | - /** @var IValidator */ |
|
| 52 | - protected $validator; |
|
| 53 | - |
|
| 54 | - /** @var string */ |
|
| 55 | - protected $formattingObjectType; |
|
| 56 | - |
|
| 57 | - /** @var int */ |
|
| 58 | - protected $formattingObjectId; |
|
| 59 | - |
|
| 60 | - /** @var bool */ |
|
| 61 | - protected $requirePNG; |
|
| 62 | - |
|
| 63 | - /** @var string */ |
|
| 64 | - protected $currentUserId; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * constructor of the controller |
|
| 68 | - * |
|
| 69 | - * @param IRequest $request |
|
| 70 | - * @param IUserSession $session |
|
| 71 | - * @param IConfig $config |
|
| 72 | - * @param IValidator $validator |
|
| 73 | - */ |
|
| 74 | - public function __construct(IRequest $request, |
|
| 75 | - IUserSession $session, |
|
| 76 | - IConfig $config, |
|
| 77 | - IValidator $validator) { |
|
| 78 | - $this->request = $request; |
|
| 79 | - $this->session = $session; |
|
| 80 | - $this->config = $config; |
|
| 81 | - $this->validator = $validator; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** @var \Closure[] */ |
|
| 85 | - private $consumersClosures = array(); |
|
| 86 | - |
|
| 87 | - /** @var IConsumer[] */ |
|
| 88 | - private $consumers = array(); |
|
| 89 | - |
|
| 90 | - /** @var \Closure[] */ |
|
| 91 | - private $extensionsClosures = array(); |
|
| 92 | - |
|
| 93 | - /** @var IExtension[] */ |
|
| 94 | - private $extensions = array(); |
|
| 95 | - |
|
| 96 | - /** @var array list of filters "name" => "is valid" */ |
|
| 97 | - protected $validFilters = array( |
|
| 98 | - 'all' => true, |
|
| 99 | - 'by' => true, |
|
| 100 | - 'self' => true, |
|
| 101 | - ); |
|
| 102 | - |
|
| 103 | - /** @var array list of type icons "type" => "css class" */ |
|
| 104 | - protected $typeIcons = array(); |
|
| 105 | - |
|
| 106 | - /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ |
|
| 107 | - protected $specialParameters = array(); |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return \OCP\Activity\IConsumer[] |
|
| 111 | - */ |
|
| 112 | - protected function getConsumers() { |
|
| 113 | - if (!empty($this->consumers)) { |
|
| 114 | - return $this->consumers; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $this->consumers = []; |
|
| 118 | - foreach($this->consumersClosures as $consumer) { |
|
| 119 | - $c = $consumer(); |
|
| 120 | - if ($c instanceof IConsumer) { |
|
| 121 | - $this->consumers[] = $c; |
|
| 122 | - } else { |
|
| 123 | - throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return $this->consumers; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return \OCP\Activity\IExtension[] |
|
| 132 | - */ |
|
| 133 | - protected function getExtensions() { |
|
| 134 | - if (!empty($this->extensions)) { |
|
| 135 | - return $this->extensions; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $this->extensions = []; |
|
| 139 | - foreach($this->extensionsClosures as $extension) { |
|
| 140 | - $e = $extension(); |
|
| 141 | - if ($e instanceof IExtension) { |
|
| 142 | - $this->extensions[] = $e; |
|
| 143 | - } else { |
|
| 144 | - throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return $this->extensions; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Generates a new IEvent object |
|
| 153 | - * |
|
| 154 | - * Make sure to call at least the following methods before sending it to the |
|
| 155 | - * app with via the publish() method: |
|
| 156 | - * - setApp() |
|
| 157 | - * - setType() |
|
| 158 | - * - setAffectedUser() |
|
| 159 | - * - setSubject() |
|
| 160 | - * |
|
| 161 | - * @return IEvent |
|
| 162 | - */ |
|
| 163 | - public function generateEvent() { |
|
| 164 | - return new Event($this->validator); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Publish an event to the activity consumers |
|
| 169 | - * |
|
| 170 | - * Make sure to call at least the following methods before sending an Event: |
|
| 171 | - * - setApp() |
|
| 172 | - * - setType() |
|
| 173 | - * - setAffectedUser() |
|
| 174 | - * - setSubject() |
|
| 175 | - * |
|
| 176 | - * @param IEvent $event |
|
| 177 | - * @throws \BadMethodCallException if required values have not been set |
|
| 178 | - */ |
|
| 179 | - public function publish(IEvent $event) { |
|
| 180 | - if ($event->getAuthor() === '') { |
|
| 181 | - if ($this->session->getUser() instanceof IUser) { |
|
| 182 | - $event->setAuthor($this->session->getUser()->getUID()); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - if (!$event->getTimestamp()) { |
|
| 187 | - $event->setTimestamp(time()); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if (!$event->isValid()) { |
|
| 191 | - throw new \BadMethodCallException('The given event is invalid'); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - foreach ($this->getConsumers() as $c) { |
|
| 195 | - $c->receive($event); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param string $app The app where this event is associated with |
|
| 201 | - * @param string $subject A short description of the event |
|
| 202 | - * @param array $subjectParams Array with parameters that are filled in the subject |
|
| 203 | - * @param string $message A longer description of the event |
|
| 204 | - * @param array $messageParams Array with parameters that are filled in the message |
|
| 205 | - * @param string $file The file including path where this event is associated with |
|
| 206 | - * @param string $link A link where this event is associated with |
|
| 207 | - * @param string $affectedUser Recipient of the activity |
|
| 208 | - * @param string $type Type of the notification |
|
| 209 | - * @param int $priority Priority of the notification |
|
| 210 | - */ |
|
| 211 | - public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) { |
|
| 212 | - $event = $this->generateEvent(); |
|
| 213 | - $event->setApp($app) |
|
| 214 | - ->setType($type) |
|
| 215 | - ->setAffectedUser($affectedUser) |
|
| 216 | - ->setSubject($subject, $subjectParams) |
|
| 217 | - ->setMessage($message, $messageParams) |
|
| 218 | - ->setObject('', 0, $file) |
|
| 219 | - ->setLink($link); |
|
| 220 | - |
|
| 221 | - $this->publish($event); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 226 | - * activity consumers are actually requested |
|
| 227 | - * |
|
| 228 | - * $callable has to return an instance of OCA\Activity\IConsumer |
|
| 229 | - * |
|
| 230 | - * @param \Closure $callable |
|
| 231 | - */ |
|
| 232 | - public function registerConsumer(\Closure $callable) { |
|
| 233 | - array_push($this->consumersClosures, $callable); |
|
| 234 | - $this->consumers = []; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 239 | - * activity consumers are actually requested |
|
| 240 | - * |
|
| 241 | - * $callable has to return an instance of OCA\Activity\IExtension |
|
| 242 | - * |
|
| 243 | - * @param \Closure $callable |
|
| 244 | - */ |
|
| 245 | - public function registerExtension(\Closure $callable) { |
|
| 246 | - array_push($this->extensionsClosures, $callable); |
|
| 247 | - $this->extensions = []; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** @var string[] */ |
|
| 251 | - protected $filterClasses = []; |
|
| 252 | - |
|
| 253 | - /** @var IFilter[] */ |
|
| 254 | - protected $filters = []; |
|
| 255 | - |
|
| 256 | - /** @var bool */ |
|
| 257 | - protected $loadedLegacyFilters = false; |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
| 261 | - * @return void |
|
| 262 | - */ |
|
| 263 | - public function registerFilter($filter) { |
|
| 264 | - $this->filterClasses[$filter] = false; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @return IFilter[] |
|
| 269 | - * @throws \InvalidArgumentException |
|
| 270 | - */ |
|
| 271 | - public function getFilters() { |
|
| 272 | - if (!$this->loadedLegacyFilters) { |
|
| 273 | - $legacyFilters = $this->getNavigation(); |
|
| 274 | - |
|
| 275 | - foreach ($legacyFilters['top'] as $filter => $data) { |
|
| 276 | - $this->filters[$filter] = new LegacyFilter( |
|
| 277 | - $this, $filter, $data['name'], true |
|
| 278 | - ); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - foreach ($legacyFilters['apps'] as $filter => $data) { |
|
| 282 | - $this->filters[$filter] = new LegacyFilter( |
|
| 283 | - $this, $filter, $data['name'], false |
|
| 284 | - ); |
|
| 285 | - } |
|
| 286 | - $this->loadedLegacyFilters = true; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - foreach ($this->filterClasses as $class => $false) { |
|
| 290 | - /** @var IFilter $filter */ |
|
| 291 | - $filter = \OC::$server->query($class); |
|
| 292 | - |
|
| 293 | - if (!$filter instanceof IFilter) { |
|
| 294 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - $this->filters[$filter->getIdentifier()] = $filter; |
|
| 298 | - |
|
| 299 | - unset($this->filterClasses[$class]); |
|
| 300 | - } |
|
| 301 | - return $this->filters; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @param string $id |
|
| 306 | - * @return IFilter |
|
| 307 | - * @throws \InvalidArgumentException when the filter was not found |
|
| 308 | - * @since 11.0.0 |
|
| 309 | - */ |
|
| 310 | - public function getFilterById($id) { |
|
| 311 | - $filters = $this->getFilters(); |
|
| 312 | - |
|
| 313 | - if (isset($filters[$id])) { |
|
| 314 | - return $filters[$id]; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - throw new \InvalidArgumentException('Requested filter does not exist'); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** @var string[] */ |
|
| 321 | - protected $providerClasses = []; |
|
| 322 | - |
|
| 323 | - /** @var IProvider[] */ |
|
| 324 | - protected $providers = []; |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
| 328 | - * @return void |
|
| 329 | - */ |
|
| 330 | - public function registerProvider($provider) { |
|
| 331 | - $this->providerClasses[$provider] = false; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * @return IProvider[] |
|
| 336 | - * @throws \InvalidArgumentException |
|
| 337 | - */ |
|
| 338 | - public function getProviders() { |
|
| 339 | - foreach ($this->providerClasses as $class => $false) { |
|
| 340 | - /** @var IProvider $provider */ |
|
| 341 | - $provider = \OC::$server->query($class); |
|
| 342 | - |
|
| 343 | - if (!$provider instanceof IProvider) { |
|
| 344 | - throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - $this->providers[] = $provider; |
|
| 348 | - |
|
| 349 | - unset($this->providerClasses[$class]); |
|
| 350 | - } |
|
| 351 | - return $this->providers; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** @var string[] */ |
|
| 355 | - protected $settingsClasses = []; |
|
| 356 | - |
|
| 357 | - /** @var ISetting[] */ |
|
| 358 | - protected $settings = []; |
|
| 359 | - |
|
| 360 | - /** @var bool */ |
|
| 361 | - protected $loadedLegacyTypes = false; |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
| 365 | - * @return void |
|
| 366 | - */ |
|
| 367 | - public function registerSetting($setting) { |
|
| 368 | - $this->settingsClasses[$setting] = false; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * @return ISetting[] |
|
| 373 | - * @throws \InvalidArgumentException |
|
| 374 | - */ |
|
| 375 | - public function getSettings() { |
|
| 376 | - if (!$this->loadedLegacyTypes) { |
|
| 377 | - $l = \OC::$server->getL10N('core'); |
|
| 378 | - $legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); |
|
| 379 | - $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); |
|
| 380 | - $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); |
|
| 381 | - foreach ($legacyTypes as $type => $data) { |
|
| 382 | - if (is_string($data)) { |
|
| 383 | - $desc = $data; |
|
| 384 | - $canChangeStream = true; |
|
| 385 | - $canChangeMail = true; |
|
| 386 | - } else { |
|
| 387 | - $desc = $data['desc']; |
|
| 388 | - $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); |
|
| 389 | - $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - $this->settings[$type] = new LegacySetting( |
|
| 393 | - $type, $desc, |
|
| 394 | - $canChangeStream, in_array($type, $streamTypes), |
|
| 395 | - $canChangeMail, in_array($type, $mailTypes) |
|
| 396 | - ); |
|
| 397 | - } |
|
| 398 | - $this->loadedLegacyTypes = true; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - foreach ($this->settingsClasses as $class => $false) { |
|
| 402 | - /** @var ISetting $setting */ |
|
| 403 | - $setting = \OC::$server->query($class); |
|
| 404 | - |
|
| 405 | - if (!$setting instanceof ISetting) { |
|
| 406 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - $this->settings[$setting->getIdentifier()] = $setting; |
|
| 410 | - |
|
| 411 | - unset($this->settingsClasses[$class]); |
|
| 412 | - } |
|
| 413 | - return $this->settings; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * @param string $id |
|
| 418 | - * @return ISetting |
|
| 419 | - * @throws \InvalidArgumentException when the setting was not found |
|
| 420 | - * @since 11.0.0 |
|
| 421 | - */ |
|
| 422 | - public function getSettingById($id) { |
|
| 423 | - $settings = $this->getSettings(); |
|
| 424 | - |
|
| 425 | - if (isset($settings[$id])) { |
|
| 426 | - return $settings[$id]; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - throw new \InvalidArgumentException('Requested setting does not exist'); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * @param string $type |
|
| 434 | - * @return string |
|
| 435 | - */ |
|
| 436 | - public function getTypeIcon($type) { |
|
| 437 | - if (isset($this->typeIcons[$type])) { |
|
| 438 | - return $this->typeIcons[$type]; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - foreach ($this->getExtensions() as $c) { |
|
| 442 | - $icon = $c->getTypeIcon($type); |
|
| 443 | - if (is_string($icon)) { |
|
| 444 | - $this->typeIcons[$type] = $icon; |
|
| 445 | - return $icon; |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - $this->typeIcons[$type] = ''; |
|
| 450 | - return ''; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * @param string $type |
|
| 455 | - * @param string $id |
|
| 456 | - */ |
|
| 457 | - public function setFormattingObject($type, $id) { |
|
| 458 | - $this->formattingObjectType = $type; |
|
| 459 | - $this->formattingObjectId = (string) $id; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * @return bool |
|
| 464 | - */ |
|
| 465 | - public function isFormattingFilteredObject() { |
|
| 466 | - return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
| 467 | - && $this->formattingObjectType === $this->request->getParam('object_type') |
|
| 468 | - && $this->formattingObjectId === $this->request->getParam('object_id'); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
| 473 | - */ |
|
| 474 | - public function setRequirePNG($status) { |
|
| 475 | - $this->requirePNG = $status; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * @return bool |
|
| 480 | - */ |
|
| 481 | - public function getRequirePNG() { |
|
| 482 | - return $this->requirePNG; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * @param string $app |
|
| 487 | - * @param string $text |
|
| 488 | - * @param array $params |
|
| 489 | - * @param boolean $stripPath |
|
| 490 | - * @param boolean $highlightParams |
|
| 491 | - * @param string $languageCode |
|
| 492 | - * @return string|false |
|
| 493 | - */ |
|
| 494 | - public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
| 495 | - foreach ($this->getExtensions() as $c) { |
|
| 496 | - $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
| 497 | - if (is_string($translation)) { |
|
| 498 | - return $translation; |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - return false; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * @param string $app |
|
| 507 | - * @param string $text |
|
| 508 | - * @return array|false |
|
| 509 | - */ |
|
| 510 | - public function getSpecialParameterList($app, $text) { |
|
| 511 | - if (isset($this->specialParameters[$app][$text])) { |
|
| 512 | - return $this->specialParameters[$app][$text]; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - if (!isset($this->specialParameters[$app])) { |
|
| 516 | - $this->specialParameters[$app] = array(); |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - foreach ($this->getExtensions() as $c) { |
|
| 520 | - $specialParameter = $c->getSpecialParameterList($app, $text); |
|
| 521 | - if (is_array($specialParameter)) { |
|
| 522 | - $this->specialParameters[$app][$text] = $specialParameter; |
|
| 523 | - return $specialParameter; |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - $this->specialParameters[$app][$text] = false; |
|
| 528 | - return false; |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * @param array $activity |
|
| 533 | - * @return integer|false |
|
| 534 | - */ |
|
| 535 | - public function getGroupParameter($activity) { |
|
| 536 | - foreach ($this->getExtensions() as $c) { |
|
| 537 | - $parameter = $c->getGroupParameter($activity); |
|
| 538 | - if ($parameter !== false) { |
|
| 539 | - return $parameter; |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - return false; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Set the user we need to use |
|
| 548 | - * |
|
| 549 | - * @param string|null $currentUserId |
|
| 550 | - * @throws \UnexpectedValueException If the user is invalid |
|
| 551 | - */ |
|
| 552 | - public function setCurrentUserId($currentUserId) { |
|
| 553 | - if (!is_string($currentUserId) && $currentUserId !== null) { |
|
| 554 | - throw new \UnexpectedValueException('The given current user is invalid'); |
|
| 555 | - } |
|
| 556 | - $this->currentUserId = $currentUserId; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Get the user we need to use |
|
| 561 | - * |
|
| 562 | - * Either the user is logged in, or we try to get it from the token |
|
| 563 | - * |
|
| 564 | - * @return string |
|
| 565 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
| 566 | - */ |
|
| 567 | - public function getCurrentUserId() { |
|
| 568 | - if ($this->currentUserId !== null) { |
|
| 569 | - return $this->currentUserId; |
|
| 570 | - } else if (!$this->session->isLoggedIn()) { |
|
| 571 | - return $this->getUserFromToken(); |
|
| 572 | - } else { |
|
| 573 | - return $this->session->getUser()->getUID(); |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Get the user for the token |
|
| 579 | - * |
|
| 580 | - * @return string |
|
| 581 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
| 582 | - */ |
|
| 583 | - protected function getUserFromToken() { |
|
| 584 | - $token = (string) $this->request->getParam('token', ''); |
|
| 585 | - if (strlen($token) !== 30) { |
|
| 586 | - throw new \UnexpectedValueException('The token is invalid'); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
| 590 | - |
|
| 591 | - if (count($users) !== 1) { |
|
| 592 | - // No unique user found |
|
| 593 | - throw new \UnexpectedValueException('The token is invalid'); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - // Token found login as that user |
|
| 597 | - return array_shift($users); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * @return array |
|
| 602 | - * @deprecated 11.0.0 - Use getFilters() instead |
|
| 603 | - */ |
|
| 604 | - public function getNavigation() { |
|
| 605 | - $entries = array( |
|
| 606 | - 'apps' => array(), |
|
| 607 | - 'top' => array(), |
|
| 608 | - ); |
|
| 609 | - foreach ($this->getExtensions() as $c) { |
|
| 610 | - $additionalEntries = $c->getNavigation(); |
|
| 611 | - if (is_array($additionalEntries)) { |
|
| 612 | - $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); |
|
| 613 | - $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return $entries; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * @param string $filterValue |
|
| 622 | - * @return boolean |
|
| 623 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
| 624 | - */ |
|
| 625 | - public function isFilterValid($filterValue) { |
|
| 626 | - if (isset($this->validFilters[$filterValue])) { |
|
| 627 | - return $this->validFilters[$filterValue]; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - foreach ($this->getExtensions() as $c) { |
|
| 631 | - if ($c->isFilterValid($filterValue) === true) { |
|
| 632 | - $this->validFilters[$filterValue] = true; |
|
| 633 | - return true; |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - $this->validFilters[$filterValue] = false; |
|
| 638 | - return false; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * @param array $types |
|
| 643 | - * @param string $filter |
|
| 644 | - * @return array |
|
| 645 | - * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
| 646 | - */ |
|
| 647 | - public function filterNotificationTypes($types, $filter) { |
|
| 648 | - if (!$this->isFilterValid($filter)) { |
|
| 649 | - return $types; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - foreach ($this->getExtensions() as $c) { |
|
| 653 | - $result = $c->filterNotificationTypes($types, $filter); |
|
| 654 | - if (is_array($result)) { |
|
| 655 | - $types = $result; |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - return $types; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * @param string $filter |
|
| 663 | - * @return array |
|
| 664 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
| 665 | - */ |
|
| 666 | - public function getQueryForFilter($filter) { |
|
| 667 | - if (!$this->isFilterValid($filter)) { |
|
| 668 | - return [null, null]; |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - $conditions = array(); |
|
| 672 | - $parameters = array(); |
|
| 673 | - |
|
| 674 | - foreach ($this->getExtensions() as $c) { |
|
| 675 | - $result = $c->getQueryForFilter($filter); |
|
| 676 | - if (is_array($result)) { |
|
| 677 | - list($condition, $parameter) = $result; |
|
| 678 | - if ($condition && is_array($parameter)) { |
|
| 679 | - $conditions[] = $condition; |
|
| 680 | - $parameters = array_merge($parameters, $parameter); |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - if (empty($conditions)) { |
|
| 686 | - return array(null, null); |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - /** |
|
| 693 | - * Will return additional notification types as specified by other apps |
|
| 694 | - * |
|
| 695 | - * @param string $languageCode |
|
| 696 | - * @return array |
|
| 697 | - * @deprecated 11.0.0 - Use getSettings() instead |
|
| 698 | - */ |
|
| 699 | - public function getNotificationTypes($languageCode) { |
|
| 700 | - $notificationTypes = $sharingNotificationTypes = []; |
|
| 701 | - foreach ($this->getExtensions() as $c) { |
|
| 702 | - $result = $c->getNotificationTypes($languageCode); |
|
| 703 | - if (is_array($result)) { |
|
| 704 | - $notificationTypes = array_merge($notificationTypes, $result); |
|
| 705 | - } |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - return array_merge($sharingNotificationTypes, $notificationTypes); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * @param string $method |
|
| 713 | - * @return array |
|
| 714 | - * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
| 715 | - */ |
|
| 716 | - public function getDefaultTypes($method) { |
|
| 717 | - $defaultTypes = array(); |
|
| 718 | - foreach ($this->getExtensions() as $c) { |
|
| 719 | - $types = $c->getDefaultTypes($method); |
|
| 720 | - if (is_array($types)) { |
|
| 721 | - $defaultTypes = array_merge($types, $defaultTypes); |
|
| 722 | - } |
|
| 723 | - } |
|
| 724 | - return $defaultTypes; |
|
| 725 | - } |
|
| 42 | + /** @var IRequest */ |
|
| 43 | + protected $request; |
|
| 44 | + |
|
| 45 | + /** @var IUserSession */ |
|
| 46 | + protected $session; |
|
| 47 | + |
|
| 48 | + /** @var IConfig */ |
|
| 49 | + protected $config; |
|
| 50 | + |
|
| 51 | + /** @var IValidator */ |
|
| 52 | + protected $validator; |
|
| 53 | + |
|
| 54 | + /** @var string */ |
|
| 55 | + protected $formattingObjectType; |
|
| 56 | + |
|
| 57 | + /** @var int */ |
|
| 58 | + protected $formattingObjectId; |
|
| 59 | + |
|
| 60 | + /** @var bool */ |
|
| 61 | + protected $requirePNG; |
|
| 62 | + |
|
| 63 | + /** @var string */ |
|
| 64 | + protected $currentUserId; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * constructor of the controller |
|
| 68 | + * |
|
| 69 | + * @param IRequest $request |
|
| 70 | + * @param IUserSession $session |
|
| 71 | + * @param IConfig $config |
|
| 72 | + * @param IValidator $validator |
|
| 73 | + */ |
|
| 74 | + public function __construct(IRequest $request, |
|
| 75 | + IUserSession $session, |
|
| 76 | + IConfig $config, |
|
| 77 | + IValidator $validator) { |
|
| 78 | + $this->request = $request; |
|
| 79 | + $this->session = $session; |
|
| 80 | + $this->config = $config; |
|
| 81 | + $this->validator = $validator; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** @var \Closure[] */ |
|
| 85 | + private $consumersClosures = array(); |
|
| 86 | + |
|
| 87 | + /** @var IConsumer[] */ |
|
| 88 | + private $consumers = array(); |
|
| 89 | + |
|
| 90 | + /** @var \Closure[] */ |
|
| 91 | + private $extensionsClosures = array(); |
|
| 92 | + |
|
| 93 | + /** @var IExtension[] */ |
|
| 94 | + private $extensions = array(); |
|
| 95 | + |
|
| 96 | + /** @var array list of filters "name" => "is valid" */ |
|
| 97 | + protected $validFilters = array( |
|
| 98 | + 'all' => true, |
|
| 99 | + 'by' => true, |
|
| 100 | + 'self' => true, |
|
| 101 | + ); |
|
| 102 | + |
|
| 103 | + /** @var array list of type icons "type" => "css class" */ |
|
| 104 | + protected $typeIcons = array(); |
|
| 105 | + |
|
| 106 | + /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ |
|
| 107 | + protected $specialParameters = array(); |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return \OCP\Activity\IConsumer[] |
|
| 111 | + */ |
|
| 112 | + protected function getConsumers() { |
|
| 113 | + if (!empty($this->consumers)) { |
|
| 114 | + return $this->consumers; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $this->consumers = []; |
|
| 118 | + foreach($this->consumersClosures as $consumer) { |
|
| 119 | + $c = $consumer(); |
|
| 120 | + if ($c instanceof IConsumer) { |
|
| 121 | + $this->consumers[] = $c; |
|
| 122 | + } else { |
|
| 123 | + throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return $this->consumers; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return \OCP\Activity\IExtension[] |
|
| 132 | + */ |
|
| 133 | + protected function getExtensions() { |
|
| 134 | + if (!empty($this->extensions)) { |
|
| 135 | + return $this->extensions; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $this->extensions = []; |
|
| 139 | + foreach($this->extensionsClosures as $extension) { |
|
| 140 | + $e = $extension(); |
|
| 141 | + if ($e instanceof IExtension) { |
|
| 142 | + $this->extensions[] = $e; |
|
| 143 | + } else { |
|
| 144 | + throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return $this->extensions; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Generates a new IEvent object |
|
| 153 | + * |
|
| 154 | + * Make sure to call at least the following methods before sending it to the |
|
| 155 | + * app with via the publish() method: |
|
| 156 | + * - setApp() |
|
| 157 | + * - setType() |
|
| 158 | + * - setAffectedUser() |
|
| 159 | + * - setSubject() |
|
| 160 | + * |
|
| 161 | + * @return IEvent |
|
| 162 | + */ |
|
| 163 | + public function generateEvent() { |
|
| 164 | + return new Event($this->validator); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Publish an event to the activity consumers |
|
| 169 | + * |
|
| 170 | + * Make sure to call at least the following methods before sending an Event: |
|
| 171 | + * - setApp() |
|
| 172 | + * - setType() |
|
| 173 | + * - setAffectedUser() |
|
| 174 | + * - setSubject() |
|
| 175 | + * |
|
| 176 | + * @param IEvent $event |
|
| 177 | + * @throws \BadMethodCallException if required values have not been set |
|
| 178 | + */ |
|
| 179 | + public function publish(IEvent $event) { |
|
| 180 | + if ($event->getAuthor() === '') { |
|
| 181 | + if ($this->session->getUser() instanceof IUser) { |
|
| 182 | + $event->setAuthor($this->session->getUser()->getUID()); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + if (!$event->getTimestamp()) { |
|
| 187 | + $event->setTimestamp(time()); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if (!$event->isValid()) { |
|
| 191 | + throw new \BadMethodCallException('The given event is invalid'); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + foreach ($this->getConsumers() as $c) { |
|
| 195 | + $c->receive($event); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param string $app The app where this event is associated with |
|
| 201 | + * @param string $subject A short description of the event |
|
| 202 | + * @param array $subjectParams Array with parameters that are filled in the subject |
|
| 203 | + * @param string $message A longer description of the event |
|
| 204 | + * @param array $messageParams Array with parameters that are filled in the message |
|
| 205 | + * @param string $file The file including path where this event is associated with |
|
| 206 | + * @param string $link A link where this event is associated with |
|
| 207 | + * @param string $affectedUser Recipient of the activity |
|
| 208 | + * @param string $type Type of the notification |
|
| 209 | + * @param int $priority Priority of the notification |
|
| 210 | + */ |
|
| 211 | + public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) { |
|
| 212 | + $event = $this->generateEvent(); |
|
| 213 | + $event->setApp($app) |
|
| 214 | + ->setType($type) |
|
| 215 | + ->setAffectedUser($affectedUser) |
|
| 216 | + ->setSubject($subject, $subjectParams) |
|
| 217 | + ->setMessage($message, $messageParams) |
|
| 218 | + ->setObject('', 0, $file) |
|
| 219 | + ->setLink($link); |
|
| 220 | + |
|
| 221 | + $this->publish($event); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 226 | + * activity consumers are actually requested |
|
| 227 | + * |
|
| 228 | + * $callable has to return an instance of OCA\Activity\IConsumer |
|
| 229 | + * |
|
| 230 | + * @param \Closure $callable |
|
| 231 | + */ |
|
| 232 | + public function registerConsumer(\Closure $callable) { |
|
| 233 | + array_push($this->consumersClosures, $callable); |
|
| 234 | + $this->consumers = []; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 239 | + * activity consumers are actually requested |
|
| 240 | + * |
|
| 241 | + * $callable has to return an instance of OCA\Activity\IExtension |
|
| 242 | + * |
|
| 243 | + * @param \Closure $callable |
|
| 244 | + */ |
|
| 245 | + public function registerExtension(\Closure $callable) { |
|
| 246 | + array_push($this->extensionsClosures, $callable); |
|
| 247 | + $this->extensions = []; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** @var string[] */ |
|
| 251 | + protected $filterClasses = []; |
|
| 252 | + |
|
| 253 | + /** @var IFilter[] */ |
|
| 254 | + protected $filters = []; |
|
| 255 | + |
|
| 256 | + /** @var bool */ |
|
| 257 | + protected $loadedLegacyFilters = false; |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
| 261 | + * @return void |
|
| 262 | + */ |
|
| 263 | + public function registerFilter($filter) { |
|
| 264 | + $this->filterClasses[$filter] = false; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @return IFilter[] |
|
| 269 | + * @throws \InvalidArgumentException |
|
| 270 | + */ |
|
| 271 | + public function getFilters() { |
|
| 272 | + if (!$this->loadedLegacyFilters) { |
|
| 273 | + $legacyFilters = $this->getNavigation(); |
|
| 274 | + |
|
| 275 | + foreach ($legacyFilters['top'] as $filter => $data) { |
|
| 276 | + $this->filters[$filter] = new LegacyFilter( |
|
| 277 | + $this, $filter, $data['name'], true |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + foreach ($legacyFilters['apps'] as $filter => $data) { |
|
| 282 | + $this->filters[$filter] = new LegacyFilter( |
|
| 283 | + $this, $filter, $data['name'], false |
|
| 284 | + ); |
|
| 285 | + } |
|
| 286 | + $this->loadedLegacyFilters = true; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + foreach ($this->filterClasses as $class => $false) { |
|
| 290 | + /** @var IFilter $filter */ |
|
| 291 | + $filter = \OC::$server->query($class); |
|
| 292 | + |
|
| 293 | + if (!$filter instanceof IFilter) { |
|
| 294 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + $this->filters[$filter->getIdentifier()] = $filter; |
|
| 298 | + |
|
| 299 | + unset($this->filterClasses[$class]); |
|
| 300 | + } |
|
| 301 | + return $this->filters; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @param string $id |
|
| 306 | + * @return IFilter |
|
| 307 | + * @throws \InvalidArgumentException when the filter was not found |
|
| 308 | + * @since 11.0.0 |
|
| 309 | + */ |
|
| 310 | + public function getFilterById($id) { |
|
| 311 | + $filters = $this->getFilters(); |
|
| 312 | + |
|
| 313 | + if (isset($filters[$id])) { |
|
| 314 | + return $filters[$id]; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + throw new \InvalidArgumentException('Requested filter does not exist'); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** @var string[] */ |
|
| 321 | + protected $providerClasses = []; |
|
| 322 | + |
|
| 323 | + /** @var IProvider[] */ |
|
| 324 | + protected $providers = []; |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
| 328 | + * @return void |
|
| 329 | + */ |
|
| 330 | + public function registerProvider($provider) { |
|
| 331 | + $this->providerClasses[$provider] = false; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * @return IProvider[] |
|
| 336 | + * @throws \InvalidArgumentException |
|
| 337 | + */ |
|
| 338 | + public function getProviders() { |
|
| 339 | + foreach ($this->providerClasses as $class => $false) { |
|
| 340 | + /** @var IProvider $provider */ |
|
| 341 | + $provider = \OC::$server->query($class); |
|
| 342 | + |
|
| 343 | + if (!$provider instanceof IProvider) { |
|
| 344 | + throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + $this->providers[] = $provider; |
|
| 348 | + |
|
| 349 | + unset($this->providerClasses[$class]); |
|
| 350 | + } |
|
| 351 | + return $this->providers; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** @var string[] */ |
|
| 355 | + protected $settingsClasses = []; |
|
| 356 | + |
|
| 357 | + /** @var ISetting[] */ |
|
| 358 | + protected $settings = []; |
|
| 359 | + |
|
| 360 | + /** @var bool */ |
|
| 361 | + protected $loadedLegacyTypes = false; |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
| 365 | + * @return void |
|
| 366 | + */ |
|
| 367 | + public function registerSetting($setting) { |
|
| 368 | + $this->settingsClasses[$setting] = false; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * @return ISetting[] |
|
| 373 | + * @throws \InvalidArgumentException |
|
| 374 | + */ |
|
| 375 | + public function getSettings() { |
|
| 376 | + if (!$this->loadedLegacyTypes) { |
|
| 377 | + $l = \OC::$server->getL10N('core'); |
|
| 378 | + $legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); |
|
| 379 | + $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); |
|
| 380 | + $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); |
|
| 381 | + foreach ($legacyTypes as $type => $data) { |
|
| 382 | + if (is_string($data)) { |
|
| 383 | + $desc = $data; |
|
| 384 | + $canChangeStream = true; |
|
| 385 | + $canChangeMail = true; |
|
| 386 | + } else { |
|
| 387 | + $desc = $data['desc']; |
|
| 388 | + $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); |
|
| 389 | + $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + $this->settings[$type] = new LegacySetting( |
|
| 393 | + $type, $desc, |
|
| 394 | + $canChangeStream, in_array($type, $streamTypes), |
|
| 395 | + $canChangeMail, in_array($type, $mailTypes) |
|
| 396 | + ); |
|
| 397 | + } |
|
| 398 | + $this->loadedLegacyTypes = true; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + foreach ($this->settingsClasses as $class => $false) { |
|
| 402 | + /** @var ISetting $setting */ |
|
| 403 | + $setting = \OC::$server->query($class); |
|
| 404 | + |
|
| 405 | + if (!$setting instanceof ISetting) { |
|
| 406 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + $this->settings[$setting->getIdentifier()] = $setting; |
|
| 410 | + |
|
| 411 | + unset($this->settingsClasses[$class]); |
|
| 412 | + } |
|
| 413 | + return $this->settings; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * @param string $id |
|
| 418 | + * @return ISetting |
|
| 419 | + * @throws \InvalidArgumentException when the setting was not found |
|
| 420 | + * @since 11.0.0 |
|
| 421 | + */ |
|
| 422 | + public function getSettingById($id) { |
|
| 423 | + $settings = $this->getSettings(); |
|
| 424 | + |
|
| 425 | + if (isset($settings[$id])) { |
|
| 426 | + return $settings[$id]; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + throw new \InvalidArgumentException('Requested setting does not exist'); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * @param string $type |
|
| 434 | + * @return string |
|
| 435 | + */ |
|
| 436 | + public function getTypeIcon($type) { |
|
| 437 | + if (isset($this->typeIcons[$type])) { |
|
| 438 | + return $this->typeIcons[$type]; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + foreach ($this->getExtensions() as $c) { |
|
| 442 | + $icon = $c->getTypeIcon($type); |
|
| 443 | + if (is_string($icon)) { |
|
| 444 | + $this->typeIcons[$type] = $icon; |
|
| 445 | + return $icon; |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + $this->typeIcons[$type] = ''; |
|
| 450 | + return ''; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * @param string $type |
|
| 455 | + * @param string $id |
|
| 456 | + */ |
|
| 457 | + public function setFormattingObject($type, $id) { |
|
| 458 | + $this->formattingObjectType = $type; |
|
| 459 | + $this->formattingObjectId = (string) $id; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * @return bool |
|
| 464 | + */ |
|
| 465 | + public function isFormattingFilteredObject() { |
|
| 466 | + return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
| 467 | + && $this->formattingObjectType === $this->request->getParam('object_type') |
|
| 468 | + && $this->formattingObjectId === $this->request->getParam('object_id'); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
| 473 | + */ |
|
| 474 | + public function setRequirePNG($status) { |
|
| 475 | + $this->requirePNG = $status; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * @return bool |
|
| 480 | + */ |
|
| 481 | + public function getRequirePNG() { |
|
| 482 | + return $this->requirePNG; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * @param string $app |
|
| 487 | + * @param string $text |
|
| 488 | + * @param array $params |
|
| 489 | + * @param boolean $stripPath |
|
| 490 | + * @param boolean $highlightParams |
|
| 491 | + * @param string $languageCode |
|
| 492 | + * @return string|false |
|
| 493 | + */ |
|
| 494 | + public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
| 495 | + foreach ($this->getExtensions() as $c) { |
|
| 496 | + $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
| 497 | + if (is_string($translation)) { |
|
| 498 | + return $translation; |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + return false; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * @param string $app |
|
| 507 | + * @param string $text |
|
| 508 | + * @return array|false |
|
| 509 | + */ |
|
| 510 | + public function getSpecialParameterList($app, $text) { |
|
| 511 | + if (isset($this->specialParameters[$app][$text])) { |
|
| 512 | + return $this->specialParameters[$app][$text]; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + if (!isset($this->specialParameters[$app])) { |
|
| 516 | + $this->specialParameters[$app] = array(); |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + foreach ($this->getExtensions() as $c) { |
|
| 520 | + $specialParameter = $c->getSpecialParameterList($app, $text); |
|
| 521 | + if (is_array($specialParameter)) { |
|
| 522 | + $this->specialParameters[$app][$text] = $specialParameter; |
|
| 523 | + return $specialParameter; |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + $this->specialParameters[$app][$text] = false; |
|
| 528 | + return false; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * @param array $activity |
|
| 533 | + * @return integer|false |
|
| 534 | + */ |
|
| 535 | + public function getGroupParameter($activity) { |
|
| 536 | + foreach ($this->getExtensions() as $c) { |
|
| 537 | + $parameter = $c->getGroupParameter($activity); |
|
| 538 | + if ($parameter !== false) { |
|
| 539 | + return $parameter; |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + return false; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Set the user we need to use |
|
| 548 | + * |
|
| 549 | + * @param string|null $currentUserId |
|
| 550 | + * @throws \UnexpectedValueException If the user is invalid |
|
| 551 | + */ |
|
| 552 | + public function setCurrentUserId($currentUserId) { |
|
| 553 | + if (!is_string($currentUserId) && $currentUserId !== null) { |
|
| 554 | + throw new \UnexpectedValueException('The given current user is invalid'); |
|
| 555 | + } |
|
| 556 | + $this->currentUserId = $currentUserId; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Get the user we need to use |
|
| 561 | + * |
|
| 562 | + * Either the user is logged in, or we try to get it from the token |
|
| 563 | + * |
|
| 564 | + * @return string |
|
| 565 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
| 566 | + */ |
|
| 567 | + public function getCurrentUserId() { |
|
| 568 | + if ($this->currentUserId !== null) { |
|
| 569 | + return $this->currentUserId; |
|
| 570 | + } else if (!$this->session->isLoggedIn()) { |
|
| 571 | + return $this->getUserFromToken(); |
|
| 572 | + } else { |
|
| 573 | + return $this->session->getUser()->getUID(); |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Get the user for the token |
|
| 579 | + * |
|
| 580 | + * @return string |
|
| 581 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
| 582 | + */ |
|
| 583 | + protected function getUserFromToken() { |
|
| 584 | + $token = (string) $this->request->getParam('token', ''); |
|
| 585 | + if (strlen($token) !== 30) { |
|
| 586 | + throw new \UnexpectedValueException('The token is invalid'); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
| 590 | + |
|
| 591 | + if (count($users) !== 1) { |
|
| 592 | + // No unique user found |
|
| 593 | + throw new \UnexpectedValueException('The token is invalid'); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + // Token found login as that user |
|
| 597 | + return array_shift($users); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * @return array |
|
| 602 | + * @deprecated 11.0.0 - Use getFilters() instead |
|
| 603 | + */ |
|
| 604 | + public function getNavigation() { |
|
| 605 | + $entries = array( |
|
| 606 | + 'apps' => array(), |
|
| 607 | + 'top' => array(), |
|
| 608 | + ); |
|
| 609 | + foreach ($this->getExtensions() as $c) { |
|
| 610 | + $additionalEntries = $c->getNavigation(); |
|
| 611 | + if (is_array($additionalEntries)) { |
|
| 612 | + $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); |
|
| 613 | + $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return $entries; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * @param string $filterValue |
|
| 622 | + * @return boolean |
|
| 623 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
| 624 | + */ |
|
| 625 | + public function isFilterValid($filterValue) { |
|
| 626 | + if (isset($this->validFilters[$filterValue])) { |
|
| 627 | + return $this->validFilters[$filterValue]; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + foreach ($this->getExtensions() as $c) { |
|
| 631 | + if ($c->isFilterValid($filterValue) === true) { |
|
| 632 | + $this->validFilters[$filterValue] = true; |
|
| 633 | + return true; |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + $this->validFilters[$filterValue] = false; |
|
| 638 | + return false; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * @param array $types |
|
| 643 | + * @param string $filter |
|
| 644 | + * @return array |
|
| 645 | + * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
| 646 | + */ |
|
| 647 | + public function filterNotificationTypes($types, $filter) { |
|
| 648 | + if (!$this->isFilterValid($filter)) { |
|
| 649 | + return $types; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + foreach ($this->getExtensions() as $c) { |
|
| 653 | + $result = $c->filterNotificationTypes($types, $filter); |
|
| 654 | + if (is_array($result)) { |
|
| 655 | + $types = $result; |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + return $types; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * @param string $filter |
|
| 663 | + * @return array |
|
| 664 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
| 665 | + */ |
|
| 666 | + public function getQueryForFilter($filter) { |
|
| 667 | + if (!$this->isFilterValid($filter)) { |
|
| 668 | + return [null, null]; |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + $conditions = array(); |
|
| 672 | + $parameters = array(); |
|
| 673 | + |
|
| 674 | + foreach ($this->getExtensions() as $c) { |
|
| 675 | + $result = $c->getQueryForFilter($filter); |
|
| 676 | + if (is_array($result)) { |
|
| 677 | + list($condition, $parameter) = $result; |
|
| 678 | + if ($condition && is_array($parameter)) { |
|
| 679 | + $conditions[] = $condition; |
|
| 680 | + $parameters = array_merge($parameters, $parameter); |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + if (empty($conditions)) { |
|
| 686 | + return array(null, null); |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + /** |
|
| 693 | + * Will return additional notification types as specified by other apps |
|
| 694 | + * |
|
| 695 | + * @param string $languageCode |
|
| 696 | + * @return array |
|
| 697 | + * @deprecated 11.0.0 - Use getSettings() instead |
|
| 698 | + */ |
|
| 699 | + public function getNotificationTypes($languageCode) { |
|
| 700 | + $notificationTypes = $sharingNotificationTypes = []; |
|
| 701 | + foreach ($this->getExtensions() as $c) { |
|
| 702 | + $result = $c->getNotificationTypes($languageCode); |
|
| 703 | + if (is_array($result)) { |
|
| 704 | + $notificationTypes = array_merge($notificationTypes, $result); |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + return array_merge($sharingNotificationTypes, $notificationTypes); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * @param string $method |
|
| 713 | + * @return array |
|
| 714 | + * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
| 715 | + */ |
|
| 716 | + public function getDefaultTypes($method) { |
|
| 717 | + $defaultTypes = array(); |
|
| 718 | + foreach ($this->getExtensions() as $c) { |
|
| 719 | + $types = $c->getDefaultTypes($method); |
|
| 720 | + if (is_array($types)) { |
|
| 721 | + $defaultTypes = array_merge($types, $defaultTypes); |
|
| 722 | + } |
|
| 723 | + } |
|
| 724 | + return $defaultTypes; |
|
| 725 | + } |
|
| 726 | 726 | } |
@@ -25,99 +25,99 @@ |
||
| 25 | 25 | |
| 26 | 26 | class LegacySetting implements ISetting { |
| 27 | 27 | |
| 28 | - /** @var string */ |
|
| 29 | - protected $identifier; |
|
| 30 | - /** @var string */ |
|
| 31 | - protected $name; |
|
| 32 | - /** @var bool */ |
|
| 33 | - protected $canChangeStream; |
|
| 34 | - /** @var bool */ |
|
| 35 | - protected $isDefaultEnabledStream; |
|
| 36 | - /** @var bool */ |
|
| 37 | - protected $canChangeMail; |
|
| 38 | - /** @var bool */ |
|
| 39 | - protected $isDefaultEnabledMail; |
|
| 28 | + /** @var string */ |
|
| 29 | + protected $identifier; |
|
| 30 | + /** @var string */ |
|
| 31 | + protected $name; |
|
| 32 | + /** @var bool */ |
|
| 33 | + protected $canChangeStream; |
|
| 34 | + /** @var bool */ |
|
| 35 | + protected $isDefaultEnabledStream; |
|
| 36 | + /** @var bool */ |
|
| 37 | + protected $canChangeMail; |
|
| 38 | + /** @var bool */ |
|
| 39 | + protected $isDefaultEnabledMail; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * LegacySetting constructor. |
|
| 43 | - * |
|
| 44 | - * @param string $identifier |
|
| 45 | - * @param string $name |
|
| 46 | - * @param bool $canChangeStream |
|
| 47 | - * @param bool $isDefaultEnabledStream |
|
| 48 | - * @param bool $canChangeMail |
|
| 49 | - * @param bool $isDefaultEnabledMail |
|
| 50 | - */ |
|
| 51 | - public function __construct($identifier, |
|
| 52 | - $name, |
|
| 53 | - $canChangeStream, |
|
| 54 | - $isDefaultEnabledStream, |
|
| 55 | - $canChangeMail, |
|
| 56 | - $isDefaultEnabledMail) { |
|
| 57 | - $this->identifier = $identifier; |
|
| 58 | - $this->name = $name; |
|
| 59 | - $this->canChangeStream = $canChangeStream; |
|
| 60 | - $this->isDefaultEnabledStream = $isDefaultEnabledStream; |
|
| 61 | - $this->canChangeMail = $canChangeMail; |
|
| 62 | - $this->isDefaultEnabledMail = $isDefaultEnabledMail; |
|
| 63 | - } |
|
| 41 | + /** |
|
| 42 | + * LegacySetting constructor. |
|
| 43 | + * |
|
| 44 | + * @param string $identifier |
|
| 45 | + * @param string $name |
|
| 46 | + * @param bool $canChangeStream |
|
| 47 | + * @param bool $isDefaultEnabledStream |
|
| 48 | + * @param bool $canChangeMail |
|
| 49 | + * @param bool $isDefaultEnabledMail |
|
| 50 | + */ |
|
| 51 | + public function __construct($identifier, |
|
| 52 | + $name, |
|
| 53 | + $canChangeStream, |
|
| 54 | + $isDefaultEnabledStream, |
|
| 55 | + $canChangeMail, |
|
| 56 | + $isDefaultEnabledMail) { |
|
| 57 | + $this->identifier = $identifier; |
|
| 58 | + $this->name = $name; |
|
| 59 | + $this->canChangeStream = $canChangeStream; |
|
| 60 | + $this->isDefaultEnabledStream = $isDefaultEnabledStream; |
|
| 61 | + $this->canChangeMail = $canChangeMail; |
|
| 62 | + $this->isDefaultEnabledMail = $isDefaultEnabledMail; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return string Lowercase a-z and underscore only identifier |
|
| 67 | - * @since 11.0.0 |
|
| 68 | - */ |
|
| 69 | - public function getIdentifier() { |
|
| 70 | - return $this->identifier; |
|
| 71 | - } |
|
| 65 | + /** |
|
| 66 | + * @return string Lowercase a-z and underscore only identifier |
|
| 67 | + * @since 11.0.0 |
|
| 68 | + */ |
|
| 69 | + public function getIdentifier() { |
|
| 70 | + return $this->identifier; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @return string A translated string |
|
| 75 | - * @since 11.0.0 |
|
| 76 | - */ |
|
| 77 | - public function getName() { |
|
| 78 | - return $this->name; |
|
| 79 | - } |
|
| 73 | + /** |
|
| 74 | + * @return string A translated string |
|
| 75 | + * @since 11.0.0 |
|
| 76 | + */ |
|
| 77 | + public function getName() { |
|
| 78 | + return $this->name; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @return int whether the filter should be rather on the top or bottom of |
|
| 83 | - * the admin section. The filters are arranged in ascending order of the |
|
| 84 | - * priority values. It is required to return a value between 0 and 100. |
|
| 85 | - * @since 11.0.0 |
|
| 86 | - */ |
|
| 87 | - public function getPriority() { |
|
| 88 | - return 70; |
|
| 89 | - } |
|
| 81 | + /** |
|
| 82 | + * @return int whether the filter should be rather on the top or bottom of |
|
| 83 | + * the admin section. The filters are arranged in ascending order of the |
|
| 84 | + * priority values. It is required to return a value between 0 and 100. |
|
| 85 | + * @since 11.0.0 |
|
| 86 | + */ |
|
| 87 | + public function getPriority() { |
|
| 88 | + return 70; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @return bool True when the option can be changed for the stream |
|
| 93 | - * @since 11.0.0 |
|
| 94 | - */ |
|
| 95 | - public function canChangeStream() { |
|
| 96 | - return $this->canChangeStream; |
|
| 97 | - } |
|
| 91 | + /** |
|
| 92 | + * @return bool True when the option can be changed for the stream |
|
| 93 | + * @since 11.0.0 |
|
| 94 | + */ |
|
| 95 | + public function canChangeStream() { |
|
| 96 | + return $this->canChangeStream; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @return bool True when the option can be changed for the stream |
|
| 101 | - * @since 11.0.0 |
|
| 102 | - */ |
|
| 103 | - public function isDefaultEnabledStream() { |
|
| 104 | - return $this->isDefaultEnabledStream; |
|
| 105 | - } |
|
| 99 | + /** |
|
| 100 | + * @return bool True when the option can be changed for the stream |
|
| 101 | + * @since 11.0.0 |
|
| 102 | + */ |
|
| 103 | + public function isDefaultEnabledStream() { |
|
| 104 | + return $this->isDefaultEnabledStream; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @return bool True when the option can be changed for the mail |
|
| 109 | - * @since 11.0.0 |
|
| 110 | - */ |
|
| 111 | - public function canChangeMail() { |
|
| 112 | - return $this->canChangeMail; |
|
| 113 | - } |
|
| 107 | + /** |
|
| 108 | + * @return bool True when the option can be changed for the mail |
|
| 109 | + * @since 11.0.0 |
|
| 110 | + */ |
|
| 111 | + public function canChangeMail() { |
|
| 112 | + return $this->canChangeMail; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * @return bool True when the option can be changed for the stream |
|
| 117 | - * @since 11.0.0 |
|
| 118 | - */ |
|
| 119 | - public function isDefaultEnabledMail() { |
|
| 120 | - return $this->isDefaultEnabledMail; |
|
| 121 | - } |
|
| 115 | + /** |
|
| 116 | + * @return bool True when the option can be changed for the stream |
|
| 117 | + * @since 11.0.0 |
|
| 118 | + */ |
|
| 119 | + public function isDefaultEnabledMail() { |
|
| 120 | + return $this->isDefaultEnabledMail; |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | |