@@ -43,250 +43,250 @@ |
||
| 43 | 43 | |
| 44 | 44 | class Hooks { |
| 45 | 45 | |
| 46 | - /** @var IActivityManager */ |
|
| 47 | - protected $activityManager; |
|
| 48 | - /** @var IGroupManager|\OC\Group\Manager */ |
|
| 49 | - protected $groupManager; |
|
| 50 | - /** @var IUserManager */ |
|
| 51 | - protected $userManager; |
|
| 52 | - /** @var IUserSession */ |
|
| 53 | - protected $userSession; |
|
| 54 | - /** @var IURLGenerator */ |
|
| 55 | - protected $urlGenerator; |
|
| 56 | - /** @var IMailer */ |
|
| 57 | - protected $mailer; |
|
| 58 | - /** @var IConfig */ |
|
| 59 | - protected $config; |
|
| 60 | - /** @var IFactory */ |
|
| 61 | - protected $languageFactory; |
|
| 62 | - |
|
| 63 | - public function __construct(IActivityManager $activityManager, |
|
| 64 | - IGroupManager $groupManager, |
|
| 65 | - IUserManager $userManager, |
|
| 66 | - IUserSession $userSession, |
|
| 67 | - IURLGenerator $urlGenerator, |
|
| 68 | - IMailer $mailer, |
|
| 69 | - IConfig $config, |
|
| 70 | - IFactory $languageFactory) { |
|
| 71 | - $this->activityManager = $activityManager; |
|
| 72 | - $this->groupManager = $groupManager; |
|
| 73 | - $this->userManager = $userManager; |
|
| 74 | - $this->userSession = $userSession; |
|
| 75 | - $this->urlGenerator = $urlGenerator; |
|
| 76 | - $this->mailer = $mailer; |
|
| 77 | - $this->config = $config; |
|
| 78 | - $this->languageFactory = $languageFactory; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param string $uid |
|
| 83 | - * @throws \InvalidArgumentException |
|
| 84 | - * @throws \BadMethodCallException |
|
| 85 | - * @throws \Exception |
|
| 86 | - */ |
|
| 87 | - public function onChangePassword($uid) { |
|
| 88 | - $user = $this->userManager->get($uid); |
|
| 89 | - |
|
| 90 | - if (!$user instanceof IUser || $user->getLastLogin() === 0) { |
|
| 91 | - // User didn't login, so don't create activities and emails. |
|
| 92 | - return; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $event = $this->activityManager->generateEvent(); |
|
| 96 | - $event->setApp('settings') |
|
| 97 | - ->setType('personal_settings') |
|
| 98 | - ->setAffectedUser($user->getUID()); |
|
| 99 | - |
|
| 100 | - $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 101 | - $language = $this->languageFactory->getUserLanguage($user); |
|
| 102 | - $l = $this->languageFactory->get('settings', $language); |
|
| 103 | - |
|
| 104 | - $actor = $this->userSession->getUser(); |
|
| 105 | - if ($actor instanceof IUser) { |
|
| 106 | - if ($actor->getUID() !== $user->getUID()) { |
|
| 107 | - // Admin changed the password through the user panel |
|
| 108 | - $text = $l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
| 109 | - $event->setAuthor($actor->getUID()) |
|
| 110 | - ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]); |
|
| 111 | - } else { |
|
| 112 | - // User changed their password themselves through settings |
|
| 113 | - $text = $l->t('Your password on %s was changed.', [$instanceUrl]); |
|
| 114 | - $event->setAuthor($actor->getUID()) |
|
| 115 | - ->setSubject(Provider::PASSWORD_CHANGED_SELF); |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - if (\OC::$CLI) { |
|
| 119 | - // Admin used occ to reset the password |
|
| 120 | - $text = $l->t('Your password on %s was reset by an administrator.', [$instanceUrl]); |
|
| 121 | - $event->setSubject(Provider::PASSWORD_RESET); |
|
| 122 | - } else { |
|
| 123 | - // User reset their password from Lost page |
|
| 124 | - $text = $l->t('Your password on %s was reset.', [$instanceUrl]); |
|
| 125 | - $event->setSubject(Provider::PASSWORD_RESET_SELF); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $this->activityManager->publish($event); |
|
| 130 | - |
|
| 131 | - if ($user->getEMailAddress() !== null) { |
|
| 132 | - $template = $this->mailer->createEMailTemplate('settings.PasswordChanged', [ |
|
| 133 | - 'displayname' => $user->getDisplayName(), |
|
| 134 | - 'emailAddress' => $user->getEMailAddress(), |
|
| 135 | - 'instanceUrl' => $instanceUrl, |
|
| 136 | - ]); |
|
| 137 | - |
|
| 138 | - $template->setSubject($l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
| 139 | - $template->addHeader(); |
|
| 140 | - $template->addHeading($l->t('Password changed for %s', [$user->getDisplayName()]), false); |
|
| 141 | - $template->addBodyText($text . ' ' . $l->t('If you did not request this, please contact an administrator.')); |
|
| 142 | - $template->addFooter(); |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - $message = $this->mailer->createMessage(); |
|
| 146 | - $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
| 147 | - $message->useTemplate($template); |
|
| 148 | - $this->mailer->send($message); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param IUser $user |
|
| 154 | - * @param string|null $oldMailAddress |
|
| 155 | - * @throws \InvalidArgumentException |
|
| 156 | - * @throws \BadMethodCallException |
|
| 157 | - */ |
|
| 158 | - public function onChangeEmail(IUser $user, $oldMailAddress) { |
|
| 159 | - if ($oldMailAddress === $user->getEMailAddress() || |
|
| 160 | - $user->getLastLogin() === 0) { |
|
| 161 | - // Email didn't really change or user didn't login, |
|
| 162 | - // so don't create activities and emails. |
|
| 163 | - return; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $event = $this->activityManager->generateEvent(); |
|
| 167 | - $event->setApp('settings') |
|
| 168 | - ->setType('personal_settings') |
|
| 169 | - ->setAffectedUser($user->getUID()); |
|
| 170 | - |
|
| 171 | - $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 172 | - $language = $this->languageFactory->getUserLanguage($user); |
|
| 173 | - $l = $this->languageFactory->get('settings', $language); |
|
| 174 | - |
|
| 175 | - $actor = $this->userSession->getUser(); |
|
| 176 | - if ($actor instanceof IUser) { |
|
| 177 | - $subject = Provider::EMAIL_CHANGED_SELF; |
|
| 178 | - if ($actor->getUID() !== $user->getUID()) { |
|
| 179 | - $subject = Provider::EMAIL_CHANGED; |
|
| 180 | - } |
|
| 181 | - $text = $l->t('Your email address on %s was changed.', [$instanceUrl]); |
|
| 182 | - $event->setAuthor($actor->getUID()) |
|
| 183 | - ->setSubject($subject); |
|
| 184 | - } else { |
|
| 185 | - if ($this->config->getAppValue('settings', 'disable_email.email_address_changed_by_admin', 'no') === 'yes') { |
|
| 186 | - return; |
|
| 187 | - } |
|
| 188 | - $text = $l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]); |
|
| 189 | - $event->setSubject(Provider::EMAIL_CHANGED); |
|
| 190 | - } |
|
| 191 | - $this->activityManager->publish($event); |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - if ($oldMailAddress !== null) { |
|
| 195 | - $template = $this->mailer->createEMailTemplate('settings.EmailChanged', [ |
|
| 196 | - 'displayname' => $user->getDisplayName(), |
|
| 197 | - 'newEMailAddress' => $user->getEMailAddress(), |
|
| 198 | - 'oldEMailAddress' => $oldMailAddress, |
|
| 199 | - 'instanceUrl' => $instanceUrl, |
|
| 200 | - ]); |
|
| 201 | - |
|
| 202 | - $template->setSubject($l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
| 203 | - $template->addHeader(); |
|
| 204 | - $template->addHeading($l->t('Email address changed for %s', [$user->getDisplayName()]), false); |
|
| 205 | - $template->addBodyText($text . ' ' . $l->t('If you did not request this, please contact an administrator.')); |
|
| 206 | - if ($user->getEMailAddress()) { |
|
| 207 | - $template->addBodyText($l->t('The new email address is %s', [$user->getEMailAddress()])); |
|
| 208 | - } |
|
| 209 | - $template->addFooter(); |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - $message = $this->mailer->createMessage(); |
|
| 213 | - $message->setTo([$oldMailAddress => $user->getDisplayName()]); |
|
| 214 | - $message->useTemplate($template); |
|
| 215 | - $this->mailer->send($message); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param IGroup $group |
|
| 221 | - * @param IUser $user |
|
| 222 | - * @throws \InvalidArgumentException |
|
| 223 | - * @throws \BadMethodCallException |
|
| 224 | - */ |
|
| 225 | - public function addUserToGroup(IGroup $group, IUser $user): void { |
|
| 226 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 227 | - $usersToNotify = $subAdminManager->getGroupsSubAdmins($group); |
|
| 228 | - $usersToNotify[] = $user; |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - $event = $this->activityManager->generateEvent(); |
|
| 232 | - $event->setApp('settings') |
|
| 233 | - ->setType('group_settings'); |
|
| 234 | - |
|
| 235 | - $actor = $this->userSession->getUser(); |
|
| 236 | - if ($actor instanceof IUser) { |
|
| 237 | - $event->setAuthor($actor->getUID()) |
|
| 238 | - ->setSubject(GroupProvider::ADDED_TO_GROUP, [ |
|
| 239 | - 'user' => $user->getUID(), |
|
| 240 | - 'group' => $group->getGID(), |
|
| 241 | - 'actor' => $actor->getUID(), |
|
| 242 | - ]); |
|
| 243 | - } else { |
|
| 244 | - $event->setSubject(GroupProvider::ADDED_TO_GROUP, [ |
|
| 245 | - 'user' => $user->getUID(), |
|
| 246 | - 'group' => $group->getGID(), |
|
| 247 | - ]); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - foreach ($usersToNotify as $userToNotify) { |
|
| 251 | - $event->setAffectedUser($userToNotify->getUID()); |
|
| 252 | - $this->activityManager->publish($event); |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @param IGroup $group |
|
| 258 | - * @param IUser $user |
|
| 259 | - * @throws \InvalidArgumentException |
|
| 260 | - * @throws \BadMethodCallException |
|
| 261 | - */ |
|
| 262 | - public function removeUserFromGroup(IGroup $group, IUser $user): void { |
|
| 263 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 264 | - $usersToNotify = $subAdminManager->getGroupsSubAdmins($group); |
|
| 265 | - $usersToNotify[] = $user; |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - $event = $this->activityManager->generateEvent(); |
|
| 269 | - $event->setApp('settings') |
|
| 270 | - ->setType('group_settings'); |
|
| 271 | - |
|
| 272 | - $actor = $this->userSession->getUser(); |
|
| 273 | - if ($actor instanceof IUser) { |
|
| 274 | - $event->setAuthor($actor->getUID()) |
|
| 275 | - ->setSubject(GroupProvider::REMOVED_FROM_GROUP, [ |
|
| 276 | - 'user' => $user->getUID(), |
|
| 277 | - 'group' => $group->getGID(), |
|
| 278 | - 'actor' => $actor->getUID(), |
|
| 279 | - ]); |
|
| 280 | - } else { |
|
| 281 | - $event->setSubject(GroupProvider::REMOVED_FROM_GROUP, [ |
|
| 282 | - 'user' => $user->getUID(), |
|
| 283 | - 'group' => $group->getGID(), |
|
| 284 | - ]); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - foreach ($usersToNotify as $userToNotify) { |
|
| 288 | - $event->setAffectedUser($userToNotify->getUID()); |
|
| 289 | - $this->activityManager->publish($event); |
|
| 290 | - } |
|
| 291 | - } |
|
| 46 | + /** @var IActivityManager */ |
|
| 47 | + protected $activityManager; |
|
| 48 | + /** @var IGroupManager|\OC\Group\Manager */ |
|
| 49 | + protected $groupManager; |
|
| 50 | + /** @var IUserManager */ |
|
| 51 | + protected $userManager; |
|
| 52 | + /** @var IUserSession */ |
|
| 53 | + protected $userSession; |
|
| 54 | + /** @var IURLGenerator */ |
|
| 55 | + protected $urlGenerator; |
|
| 56 | + /** @var IMailer */ |
|
| 57 | + protected $mailer; |
|
| 58 | + /** @var IConfig */ |
|
| 59 | + protected $config; |
|
| 60 | + /** @var IFactory */ |
|
| 61 | + protected $languageFactory; |
|
| 62 | + |
|
| 63 | + public function __construct(IActivityManager $activityManager, |
|
| 64 | + IGroupManager $groupManager, |
|
| 65 | + IUserManager $userManager, |
|
| 66 | + IUserSession $userSession, |
|
| 67 | + IURLGenerator $urlGenerator, |
|
| 68 | + IMailer $mailer, |
|
| 69 | + IConfig $config, |
|
| 70 | + IFactory $languageFactory) { |
|
| 71 | + $this->activityManager = $activityManager; |
|
| 72 | + $this->groupManager = $groupManager; |
|
| 73 | + $this->userManager = $userManager; |
|
| 74 | + $this->userSession = $userSession; |
|
| 75 | + $this->urlGenerator = $urlGenerator; |
|
| 76 | + $this->mailer = $mailer; |
|
| 77 | + $this->config = $config; |
|
| 78 | + $this->languageFactory = $languageFactory; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param string $uid |
|
| 83 | + * @throws \InvalidArgumentException |
|
| 84 | + * @throws \BadMethodCallException |
|
| 85 | + * @throws \Exception |
|
| 86 | + */ |
|
| 87 | + public function onChangePassword($uid) { |
|
| 88 | + $user = $this->userManager->get($uid); |
|
| 89 | + |
|
| 90 | + if (!$user instanceof IUser || $user->getLastLogin() === 0) { |
|
| 91 | + // User didn't login, so don't create activities and emails. |
|
| 92 | + return; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $event = $this->activityManager->generateEvent(); |
|
| 96 | + $event->setApp('settings') |
|
| 97 | + ->setType('personal_settings') |
|
| 98 | + ->setAffectedUser($user->getUID()); |
|
| 99 | + |
|
| 100 | + $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 101 | + $language = $this->languageFactory->getUserLanguage($user); |
|
| 102 | + $l = $this->languageFactory->get('settings', $language); |
|
| 103 | + |
|
| 104 | + $actor = $this->userSession->getUser(); |
|
| 105 | + if ($actor instanceof IUser) { |
|
| 106 | + if ($actor->getUID() !== $user->getUID()) { |
|
| 107 | + // Admin changed the password through the user panel |
|
| 108 | + $text = $l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
| 109 | + $event->setAuthor($actor->getUID()) |
|
| 110 | + ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]); |
|
| 111 | + } else { |
|
| 112 | + // User changed their password themselves through settings |
|
| 113 | + $text = $l->t('Your password on %s was changed.', [$instanceUrl]); |
|
| 114 | + $event->setAuthor($actor->getUID()) |
|
| 115 | + ->setSubject(Provider::PASSWORD_CHANGED_SELF); |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + if (\OC::$CLI) { |
|
| 119 | + // Admin used occ to reset the password |
|
| 120 | + $text = $l->t('Your password on %s was reset by an administrator.', [$instanceUrl]); |
|
| 121 | + $event->setSubject(Provider::PASSWORD_RESET); |
|
| 122 | + } else { |
|
| 123 | + // User reset their password from Lost page |
|
| 124 | + $text = $l->t('Your password on %s was reset.', [$instanceUrl]); |
|
| 125 | + $event->setSubject(Provider::PASSWORD_RESET_SELF); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $this->activityManager->publish($event); |
|
| 130 | + |
|
| 131 | + if ($user->getEMailAddress() !== null) { |
|
| 132 | + $template = $this->mailer->createEMailTemplate('settings.PasswordChanged', [ |
|
| 133 | + 'displayname' => $user->getDisplayName(), |
|
| 134 | + 'emailAddress' => $user->getEMailAddress(), |
|
| 135 | + 'instanceUrl' => $instanceUrl, |
|
| 136 | + ]); |
|
| 137 | + |
|
| 138 | + $template->setSubject($l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
| 139 | + $template->addHeader(); |
|
| 140 | + $template->addHeading($l->t('Password changed for %s', [$user->getDisplayName()]), false); |
|
| 141 | + $template->addBodyText($text . ' ' . $l->t('If you did not request this, please contact an administrator.')); |
|
| 142 | + $template->addFooter(); |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + $message = $this->mailer->createMessage(); |
|
| 146 | + $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
| 147 | + $message->useTemplate($template); |
|
| 148 | + $this->mailer->send($message); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param IUser $user |
|
| 154 | + * @param string|null $oldMailAddress |
|
| 155 | + * @throws \InvalidArgumentException |
|
| 156 | + * @throws \BadMethodCallException |
|
| 157 | + */ |
|
| 158 | + public function onChangeEmail(IUser $user, $oldMailAddress) { |
|
| 159 | + if ($oldMailAddress === $user->getEMailAddress() || |
|
| 160 | + $user->getLastLogin() === 0) { |
|
| 161 | + // Email didn't really change or user didn't login, |
|
| 162 | + // so don't create activities and emails. |
|
| 163 | + return; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $event = $this->activityManager->generateEvent(); |
|
| 167 | + $event->setApp('settings') |
|
| 168 | + ->setType('personal_settings') |
|
| 169 | + ->setAffectedUser($user->getUID()); |
|
| 170 | + |
|
| 171 | + $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 172 | + $language = $this->languageFactory->getUserLanguage($user); |
|
| 173 | + $l = $this->languageFactory->get('settings', $language); |
|
| 174 | + |
|
| 175 | + $actor = $this->userSession->getUser(); |
|
| 176 | + if ($actor instanceof IUser) { |
|
| 177 | + $subject = Provider::EMAIL_CHANGED_SELF; |
|
| 178 | + if ($actor->getUID() !== $user->getUID()) { |
|
| 179 | + $subject = Provider::EMAIL_CHANGED; |
|
| 180 | + } |
|
| 181 | + $text = $l->t('Your email address on %s was changed.', [$instanceUrl]); |
|
| 182 | + $event->setAuthor($actor->getUID()) |
|
| 183 | + ->setSubject($subject); |
|
| 184 | + } else { |
|
| 185 | + if ($this->config->getAppValue('settings', 'disable_email.email_address_changed_by_admin', 'no') === 'yes') { |
|
| 186 | + return; |
|
| 187 | + } |
|
| 188 | + $text = $l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]); |
|
| 189 | + $event->setSubject(Provider::EMAIL_CHANGED); |
|
| 190 | + } |
|
| 191 | + $this->activityManager->publish($event); |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + if ($oldMailAddress !== null) { |
|
| 195 | + $template = $this->mailer->createEMailTemplate('settings.EmailChanged', [ |
|
| 196 | + 'displayname' => $user->getDisplayName(), |
|
| 197 | + 'newEMailAddress' => $user->getEMailAddress(), |
|
| 198 | + 'oldEMailAddress' => $oldMailAddress, |
|
| 199 | + 'instanceUrl' => $instanceUrl, |
|
| 200 | + ]); |
|
| 201 | + |
|
| 202 | + $template->setSubject($l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
| 203 | + $template->addHeader(); |
|
| 204 | + $template->addHeading($l->t('Email address changed for %s', [$user->getDisplayName()]), false); |
|
| 205 | + $template->addBodyText($text . ' ' . $l->t('If you did not request this, please contact an administrator.')); |
|
| 206 | + if ($user->getEMailAddress()) { |
|
| 207 | + $template->addBodyText($l->t('The new email address is %s', [$user->getEMailAddress()])); |
|
| 208 | + } |
|
| 209 | + $template->addFooter(); |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + $message = $this->mailer->createMessage(); |
|
| 213 | + $message->setTo([$oldMailAddress => $user->getDisplayName()]); |
|
| 214 | + $message->useTemplate($template); |
|
| 215 | + $this->mailer->send($message); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param IGroup $group |
|
| 221 | + * @param IUser $user |
|
| 222 | + * @throws \InvalidArgumentException |
|
| 223 | + * @throws \BadMethodCallException |
|
| 224 | + */ |
|
| 225 | + public function addUserToGroup(IGroup $group, IUser $user): void { |
|
| 226 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 227 | + $usersToNotify = $subAdminManager->getGroupsSubAdmins($group); |
|
| 228 | + $usersToNotify[] = $user; |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + $event = $this->activityManager->generateEvent(); |
|
| 232 | + $event->setApp('settings') |
|
| 233 | + ->setType('group_settings'); |
|
| 234 | + |
|
| 235 | + $actor = $this->userSession->getUser(); |
|
| 236 | + if ($actor instanceof IUser) { |
|
| 237 | + $event->setAuthor($actor->getUID()) |
|
| 238 | + ->setSubject(GroupProvider::ADDED_TO_GROUP, [ |
|
| 239 | + 'user' => $user->getUID(), |
|
| 240 | + 'group' => $group->getGID(), |
|
| 241 | + 'actor' => $actor->getUID(), |
|
| 242 | + ]); |
|
| 243 | + } else { |
|
| 244 | + $event->setSubject(GroupProvider::ADDED_TO_GROUP, [ |
|
| 245 | + 'user' => $user->getUID(), |
|
| 246 | + 'group' => $group->getGID(), |
|
| 247 | + ]); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + foreach ($usersToNotify as $userToNotify) { |
|
| 251 | + $event->setAffectedUser($userToNotify->getUID()); |
|
| 252 | + $this->activityManager->publish($event); |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @param IGroup $group |
|
| 258 | + * @param IUser $user |
|
| 259 | + * @throws \InvalidArgumentException |
|
| 260 | + * @throws \BadMethodCallException |
|
| 261 | + */ |
|
| 262 | + public function removeUserFromGroup(IGroup $group, IUser $user): void { |
|
| 263 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 264 | + $usersToNotify = $subAdminManager->getGroupsSubAdmins($group); |
|
| 265 | + $usersToNotify[] = $user; |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + $event = $this->activityManager->generateEvent(); |
|
| 269 | + $event->setApp('settings') |
|
| 270 | + ->setType('group_settings'); |
|
| 271 | + |
|
| 272 | + $actor = $this->userSession->getUser(); |
|
| 273 | + if ($actor instanceof IUser) { |
|
| 274 | + $event->setAuthor($actor->getUID()) |
|
| 275 | + ->setSubject(GroupProvider::REMOVED_FROM_GROUP, [ |
|
| 276 | + 'user' => $user->getUID(), |
|
| 277 | + 'group' => $group->getGID(), |
|
| 278 | + 'actor' => $actor->getUID(), |
|
| 279 | + ]); |
|
| 280 | + } else { |
|
| 281 | + $event->setSubject(GroupProvider::REMOVED_FROM_GROUP, [ |
|
| 282 | + 'user' => $user->getUID(), |
|
| 283 | + 'group' => $group->getGID(), |
|
| 284 | + ]); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + foreach ($usersToNotify as $userToNotify) { |
|
| 288 | + $event->setAffectedUser($userToNotify->getUID()); |
|
| 289 | + $this->activityManager->publish($event); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | 292 | } |