-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from leepeuker/add-privacy-levels
Add privacy levels for users
- Loading branch information
Showing
15 changed files
with
306 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
final class AddPrivacyLevelToUser extends AbstractMigration | ||
{ | ||
public function down() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
ALTER TABLE user DROP COLUMN privacy_level; | ||
SQL | ||
); | ||
} | ||
|
||
public function up() : void | ||
{ | ||
$this->execute( | ||
<<<SQL | ||
ALTER TABLE user ADD COLUMN privacy_level TINYINT UNSIGNED DEFAULT 1 AFTER password; | ||
SQL | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/Application/User/Service/UserPageAuthorizationChecker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\Application\User\Service; | ||
|
||
use Movary\Application\User\Api; | ||
|
||
class UserPageAuthorizationChecker | ||
{ | ||
public function __construct( | ||
private readonly Api $userApi, | ||
private readonly Authentication $authenticationService | ||
) { | ||
} | ||
|
||
public function fetchAllHavingWatchedMovieVisibleUsernamesForCurrentVisitor(int $movieId) : array | ||
{ | ||
if ($this->authenticationService->isUserAuthenticated() === false) { | ||
return $this->userApi->fetchAllHavingWatchedMoviePublicVisibleUsernames($movieId); | ||
} | ||
|
||
return $this->userApi->fetchAllHavingWatchedMovieInternVisibleUsernames($movieId); | ||
} | ||
|
||
public function fetchAllHavingWatchedMovieWithPersonVisibleUsernamesForCurrentVisitor(int $personId) : array | ||
{ | ||
if ($this->authenticationService->isUserAuthenticated() === false) { | ||
return $this->userApi->fetchAllHavingWatchedMovieWithPersonPublicVisibleUsernames($personId); | ||
} | ||
|
||
return $this->userApi->fetchAllHavingWatchedMovieWithPersonInternVisibleUsernames($personId); | ||
} | ||
|
||
public function fetchAllVisibleUsernamesForCurrentVisitor() : array | ||
{ | ||
if ($this->authenticationService->isUserAuthenticated() === false) { | ||
return $this->userApi->fetchAllPublicVisibleUsernames(); | ||
} | ||
|
||
return $this->userApi->fetchAllInternVisibleUsernames(); | ||
} | ||
|
||
public function findUserIdIfCurrentVisitorIsAllowedToSeeUser(string $username) : ?int | ||
{ | ||
$user = $this->userApi->findUserByName($username); | ||
if ($user === null) { | ||
return null; | ||
} | ||
|
||
$userId = $user->getId(); | ||
|
||
if ($this->authenticationService->isUserPageVisible($user->getPrivacyLevel(), $userId) === false) { | ||
return null; | ||
} | ||
|
||
return $user->getId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.