/** * @param $query * * @return \Illuminate\Http\JsonResponse */ public function getPeopleSearchListJson($query) { if (auth()->user()->has('people.view', false)) { return ['results' => Person::select('id', 'main_character_name as text')->where('main_character_name', 'like', '%' . $query . '%')->orderBy('main_character_name', 'asc')->get()]; } return ['results' => Person::select('id', 'main_character_name as text')->whereHas('members.characters', function ($query) { $query->whereIn('keyID', ApiKey::where('user_id', auth()->user()->id)->lists('key_id')); })->where('main_character_name', 'like', '%' . $query . '%')->orderBy('main_character_name', 'asc')->get()]; }
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; }
/** * Execute the console command. * * @param \Seat\Eveapi\Helpers\JobPayloadContainer $job * * @return mixed */ public function handle(JobPayloadContainer $job) { // Counter for the number of keys queued $queued_keys = 0; // Query the API Keys from the database // and queue jobs for them 10 at a time. ApiKey::where('enabled', 1)->chunk(10, function ($keys) use($job, &$queued_keys) { foreach ($keys as $key) { $job->scope = 'Key'; $job->api = 'Scheduler'; $job->owner_id = $key->key_id; $job->eve_api_key = $key; $job_id = $this->addUniqueJob(CheckAndQueueKey::class, $job); $this->info('Job ' . $job_id . ' dispatched!'); $queued_keys++; } }); // Analytics dispatch((new Analytics((new AnalyticsContainer())->set('type', 'event')->set('ec', 'queues')->set('ea', 'queue_keys')->set('el', 'console')->set('ev', $queued_keys)))->onQueue('medium')); }
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; }
/** * @return \Illuminate\Http\RedirectResponse */ public function getEnableAll() { $keys = ApiKeyModel::where('enabled', '<>', 1); if (!auth()->user()->has('apikey.list', false)) { $keys = $keys->where('user_id', auth()->user()->id); } // Enable the keys and clear the last error $keys->update(['enabled' => 1, 'last_error' => null]); return redirect()->back()->with('success', 'Keys re-enabled'); }
/** * @param $key_id * * @return \Illuminate\Http\RedirectResponse */ public function getDelete($key_id) { ApiKeyModel::where('key_id', $key_id)->delete(); return redirect()->back()->with('success', 'Key Successfully deleted'); }
/** * @return \Illuminate\Http\RedirectResponse */ public function getDisableAll() { $keys = ApiKeyModel::where('enabled', 1); if (!auth()->user()->has('apikey.list', false)) { $keys = $keys->where('user_id', auth()->user()->id()); } $keys->update(['enabled' => 0, 'last_error' => null]); return redirect()->back()->with('success', 'Keys disabled'); }