public function call() { // call the parent call method in order to load the Slack Api Token parent::call(); // get all Api Key owned by the user $keys = ApiKey::where('user_id', $this->user->id)->get(); // get the Slack Api User $slackUser = SlackUser::where('user_id', $this->user->id)->where('invited', true)->whereNotNull('slack_id')->first(); if ($slackUser != null) { // get channels into which current user is already member $channels = $this->getSlackApi()->member($slackUser->slack_id, false); $groups = $this->getSlackApi()->member($slackUser->slack_id, true); // if key are not valid OR account no longer paid // kick the user from all channels to which he's member if ($this->isEnabledKey($keys) == false || $this->isActive($keys) == false) { if (!empty($channels)) { $this->processChannelsKick($slackUser, $channels); $this->logEvent('kick', $channels); } if (!empty($groups)) { $this->processGroupsKick($slackUser, $groups); $this->logEvent('kick', $groups); } return; } // in other way, compute the gap and kick only the user // to channel from which he's no longer granted to be in $allowedChannels = $this->allowedChannels($slackUser, false); $extraChannels = array_diff($channels, $allowedChannels); // remove channels in which user is already in from all granted channels and invite him if (!empty($extraChannels)) { $this->processChannelsKick($slackUser, $extraChannels); $this->logEvent('kick', $extraChannels); } // remove granted channels from channels in which user is already in and kick him $allowedGroups = $this->allowedChannels($slackUser, true); $extraGroups = array_diff($groups, $allowedGroups); if (!empty($extraGroups)) { $this->processGroupsKick($slackUser, array_diff($groups, $extraGroups)); $this->logEvent('kick', $extraGroups); } } return; }
public function call() { // call the parent call method in order to load the Slack Api Token parent::call(); // get all Api Key owned by the user $keys = ApiKey::where('user_id', $this->user->id)->get(); // invite user only if both account are subscribed and keys active if ($this->isEnabledKey($keys) && $this->isActive($keys)) { // if the user is not yet invited, invite him to team if ($this->isInvited($this->user) == false) { $this->processMemberInvitation($this->user); return; } // in other case, invite him to channels and groups // get the attached slack user $slackUser = SlackUser::where('user_id', $this->user->id)->first(); // control that we already know it's slack ID (mean that he creates his account) if ($slackUser->slack_id != null) { $allowedChannels = $this->allowedChannels($slackUser, false); $memberOfChannels = $this->getSlackApi()->member($slackUser->slack_id, false); $missingChannels = array_diff($allowedChannels, $memberOfChannels); if (!empty($missingChannels)) { $this->processChannelsInvitation($slackUser, $missingChannels); $this->logEvent('invite', $missingChannels); } $allowedGroups = $this->allowedChannels($slackUser, true); $memberOfGroups = $this->getSlackApi()->member($slackUser->slack_id, true); $missingGroups = array_diff($allowedGroups, $memberOfGroups); if (!empty($missingGroups)) { $this->processGroupsInvitation($slackUser, $missingGroups); $this->logEvent('invite', $missingGroups); } } } return; }