-
Notifications
You must be signed in to change notification settings - Fork 30
Introducing thread/microblog locking #1773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DoctrineMigrations; | ||
|
|
||
| use Doctrine\DBAL\Schema\Schema; | ||
| use Doctrine\Migrations\AbstractMigration; | ||
|
|
||
| final class Version20251031174052 extends AbstractMigration | ||
| { | ||
| public function getDescription(): string | ||
| { | ||
| return 'Add is_locked column to post and entry'; | ||
| } | ||
|
|
||
| public function up(Schema $schema): void | ||
| { | ||
| $this->addSql('ALTER TABLE entry ADD is_locked BOOLEAN DEFAULT false NOT NULL'); | ||
| $this->addSql('ALTER TABLE post ADD is_locked BOOLEAN DEFAULT false NOT NULL'); | ||
| } | ||
|
|
||
| public function down(Schema $schema): void | ||
| { | ||
| $this->addSql('ALTER TABLE post DROP is_locked'); | ||
| $this->addSql('ALTER TABLE entry DROP is_locked'); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,87 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Controller\Api\Entry\Moderate; | ||
|
|
||
| use App\Controller\Api\Entry\EntriesBaseApi; | ||
| use App\DTO\EntryResponseDto; | ||
| use App\Entity\Entry; | ||
| use App\Factory\EntryFactory; | ||
| use App\Schema\Errors\ForbiddenErrorSchema; | ||
| use App\Schema\Errors\NotFoundErrorSchema; | ||
| use App\Schema\Errors\TooManyRequestsErrorSchema; | ||
| use App\Schema\Errors\UnauthorizedErrorSchema; | ||
| use App\Service\EntryManager; | ||
| use Nelmio\ApiDocBundle\Attribute\Model; | ||
| use Nelmio\ApiDocBundle\Attribute\Security; | ||
| use OpenApi\Attributes as OA; | ||
| use Symfony\Bridge\Doctrine\Attribute\MapEntity; | ||
| use Symfony\Component\HttpFoundation\JsonResponse; | ||
| use Symfony\Component\RateLimiter\RateLimiterFactory; | ||
| use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
|
|
||
| class EntriesLockApi extends EntriesBaseApi | ||
| { | ||
| #[OA\Response( | ||
| response: 200, | ||
| description: 'Entry lock status toggled', | ||
| headers: [ | ||
| new OA\Header(header: 'X-RateLimit-Remaining', description: 'Number of requests left until you will be rate limited', schema: new OA\Schema(type: 'integer')), | ||
| new OA\Header(header: 'X-RateLimit-Retry-After', description: 'Unix timestamp to retry the request after', schema: new OA\Schema(type: 'integer')), | ||
| new OA\Header(header: 'X-RateLimit-Limit', description: 'Number of requests available', schema: new OA\Schema(type: 'integer')), | ||
| ], | ||
| content: new Model(type: EntryResponseDto::class) | ||
| )] | ||
| #[OA\Response( | ||
| response: 401, | ||
| description: 'Permission denied due to missing or expired token', | ||
| content: new OA\JsonContent(ref: new Model(type: UnauthorizedErrorSchema::class)) | ||
| )] | ||
| #[OA\Response( | ||
| response: 403, | ||
| description: 'You are not authorized to lock this entry', | ||
| content: new OA\JsonContent(ref: new Model(type: ForbiddenErrorSchema::class)) | ||
| )] | ||
| #[OA\Response( | ||
| response: 404, | ||
| description: 'Entry not found', | ||
| content: new OA\JsonContent(ref: new Model(type: NotFoundErrorSchema::class)) | ||
| )] | ||
| #[OA\Response( | ||
| response: 429, | ||
| description: 'You are being rate limited', | ||
| headers: [ | ||
| new OA\Header(header: 'X-RateLimit-Remaining', description: 'Number of requests left until you will be rate limited', schema: new OA\Schema(type: 'integer')), | ||
| new OA\Header(header: 'X-RateLimit-Retry-After', description: 'Unix timestamp to retry the request after', schema: new OA\Schema(type: 'integer')), | ||
| new OA\Header(header: 'X-RateLimit-Limit', description: 'Number of requests available', schema: new OA\Schema(type: 'integer')), | ||
| ], | ||
| content: new OA\JsonContent(ref: new Model(type: TooManyRequestsErrorSchema::class)) | ||
| )] | ||
| #[OA\Parameter( | ||
| name: 'entry_id', | ||
| description: 'The entry to lock or unlock', | ||
| in: 'path', | ||
| schema: new OA\Schema(type: 'integer'), | ||
| )] | ||
| #[OA\Tag(name: 'moderation/entry')] | ||
| #[Security(name: 'oauth2', scopes: ['moderate:entry:lock'])] | ||
| #[IsGranted('ROLE_OAUTH2_MODERATE:ENTRY:LOCK')] | ||
| #[IsGranted('lock', subject: 'entry')] | ||
| public function __invoke( | ||
| #[MapEntity(id: 'entry_id')] | ||
| Entry $entry, | ||
| EntryManager $manager, | ||
| EntryFactory $factory, | ||
| RateLimiterFactory $apiModerateLimiter, | ||
| ): JsonResponse { | ||
| $headers = $this->rateLimit($apiModerateLimiter); | ||
|
|
||
| $manager->toggleLock($entry, $this->getUserOrThrow()); | ||
|
|
||
| return new JsonResponse( | ||
| $this->serializeEntry($factory->createDto($entry), $this->tagLinkRepository->getTagsOfContent($entry), $this->entryRepository->findCross($entry)), | ||
| headers: $headers | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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,87 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Controller\Api\Post\Moderate; | ||
|
|
||
| use App\Controller\Api\Post\PostsBaseApi; | ||
| use App\DTO\PostResponseDto; | ||
| use App\Entity\Post; | ||
| use App\Factory\PostFactory; | ||
| use App\Schema\Errors\ForbiddenErrorSchema; | ||
| use App\Schema\Errors\NotFoundErrorSchema; | ||
| use App\Schema\Errors\TooManyRequestsErrorSchema; | ||
| use App\Schema\Errors\UnauthorizedErrorSchema; | ||
| use App\Service\PostManager; | ||
| use Nelmio\ApiDocBundle\Attribute\Model; | ||
| use Nelmio\ApiDocBundle\Attribute\Security; | ||
| use OpenApi\Attributes as OA; | ||
| use Symfony\Bridge\Doctrine\Attribute\MapEntity; | ||
| use Symfony\Component\HttpFoundation\JsonResponse; | ||
| use Symfony\Component\RateLimiter\RateLimiterFactory; | ||
| use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
|
|
||
| class PostsLockApi extends PostsBaseApi | ||
| { | ||
| #[OA\Response( | ||
| response: 200, | ||
| description: 'Post lock status toggled', | ||
| headers: [ | ||
| new OA\Header(header: 'X-RateLimit-Remaining', description: 'Number of requests left until you will be rate limited', schema: new OA\Schema(type: 'integer')), | ||
| new OA\Header(header: 'X-RateLimit-Retry-After', description: 'Unix timestamp to retry the request after', schema: new OA\Schema(type: 'integer')), | ||
| new OA\Header(header: 'X-RateLimit-Limit', description: 'Number of requests available', schema: new OA\Schema(type: 'integer')), | ||
| ], | ||
| content: new Model(type: PostResponseDto::class) | ||
| )] | ||
| #[OA\Response( | ||
| response: 401, | ||
| description: 'Permission denied due to missing or expired token', | ||
| content: new OA\JsonContent(ref: new Model(type: UnauthorizedErrorSchema::class)) | ||
| )] | ||
| #[OA\Response( | ||
| response: 403, | ||
| description: 'You are not authorized to lock this post', | ||
| content: new OA\JsonContent(ref: new Model(type: ForbiddenErrorSchema::class)) | ||
| )] | ||
| #[OA\Response( | ||
| response: 404, | ||
| description: 'Post not found', | ||
| content: new OA\JsonContent(ref: new Model(type: NotFoundErrorSchema::class)) | ||
| )] | ||
| #[OA\Response( | ||
| response: 429, | ||
| description: 'You are being rate limited', | ||
| headers: [ | ||
| new OA\Header(header: 'X-RateLimit-Remaining', description: 'Number of requests left until you will be rate limited', schema: new OA\Schema(type: 'integer')), | ||
| new OA\Header(header: 'X-RateLimit-Retry-After', description: 'Unix timestamp to retry the request after', schema: new OA\Schema(type: 'integer')), | ||
| new OA\Header(header: 'X-RateLimit-Limit', description: 'Number of requests available', schema: new OA\Schema(type: 'integer')), | ||
| ], | ||
| content: new OA\JsonContent(ref: new Model(type: TooManyRequestsErrorSchema::class)) | ||
| )] | ||
| #[OA\Parameter( | ||
| name: 'post_id', | ||
| description: 'The post to lock or unlock', | ||
| in: 'path', | ||
| schema: new OA\Schema(type: 'integer'), | ||
| )] | ||
| #[OA\Tag(name: 'moderation/post')] | ||
| #[Security(name: 'oauth2', scopes: ['moderate:post:lock'])] | ||
| #[IsGranted('ROLE_OAUTH2_MODERATE:POST:LOCK')] | ||
| #[IsGranted('lock', subject: 'post')] | ||
| public function __invoke( | ||
| #[MapEntity(id: 'post_id')] | ||
| Post $post, | ||
| PostManager $manager, | ||
| PostFactory $factory, | ||
| RateLimiterFactory $apiModerateLimiter, | ||
| ): JsonResponse { | ||
| $headers = $this->rateLimit($apiModerateLimiter); | ||
|
|
||
| $manager->toggleLock($post, $this->getUserOrThrow()); | ||
|
|
||
| return new JsonResponse( | ||
| $this->serializePost($factory->createDto($post), $this->tagLinkRepository->getTagsOfContent($post)), | ||
| headers: $headers | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
due to the fact we might introduced other migrations.. it might be wise to upgrade the file name and class name to reflect the current date again..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory yes, but I have already been running this migration locally and on gehirneimer, so it would complicate things there... If you do not insist on it, I'd prefer to leave it as is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK let's hope then it won't case any issues and symfony migration is smart enough