/** * Estimates if user should be able to access entry. * It's possible, that found key share cannot unlock key * * @param Entry $entry * @return bool */ public function userCanAccessEntry(Entry $entry) { if (!$this->user) { return false; } return $entry->keyShares()->where('user_id', $this->user->id)->count() > 0; }
private function getKey(Request $request, Entry $entry) { $userAndKey = $this->apiKey->extractKeyAndUser($request); $share = $entry->keyShares()->where('user_id', $userAndKey['user']->id)->firstOrFail(); if ($share) { $this->logger->log('entry', 'Accessed entry via API', $entry->id); return $entry->toArray() + ['password' => $this->sealer->unseal($entry->data, $share->public, $userAndKey['key'])]; } return null; }