Skip to content
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

fix fetch post inside lock functions #4995

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private function updatePostLock($post_id)
// if user can break the lock "has admin role" then release the old lock if it from other user
// If the lock is inactive and the lock is not for current user release old one and create new one

$this->setCurrentPostLock($post_id);
$this->getCurrentPostLock($post_id);

if ($this->current_post_lock) {
if (($this->lockIsBreakable()) || (!$this->currentLockIsActive() && !$this->userOwnsCurrentLock())) {
Expand Down Expand Up @@ -76,7 +76,7 @@ private function userOwnsCurrentLock()
$user = Auth::user();
return intval($user->id) === intval($this->current_post_lock->user_id);
}
private function setCurrentPostLock($post_id): void
private function getCurrentPostLock($post_id): void
{
try {
$this->current_post_lock = $this->post_lock_repository->findByPostId($post_id);
Expand Down
5 changes: 2 additions & 3 deletions src/Ushahidi/Modules/V5/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ public function showPostGeoJson($id, Request $request): PostGeometryResource

public function updateLock(int $post_id, Request $request)
{

$post = $this->queryBus->handle(new FindPostByIdQuery($post_id, ['id', 'user_id', 'form_id']));
$post = $this->getPost($post_id, ['id', 'status','user_id','form_id'], []);
$this->authorize('update', $post);

$this->commandBus->handle(new UpdatePostLockCommand($post_id));
Expand All @@ -491,7 +490,7 @@ public function updateLock(int $post_id, Request $request)

public function deleteLock(int $post_id, Request $request)
{
$post = $this->queryBus->handle(new FindPostByIdQuery($post_id, ['id', 'user_id', 'form_id']));
$post = $this->getPost($post_id, ['id', 'status','user_id','form_id'], []);
$this->authorize('update', $post);

$this->commandBus->handle(new DeletePostLockCommand($post_id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public function deleteById(int $id): void
}
public function deleteByPostId(int $post_id): void
{
$this->findByPostId($post_id)->delete();
$post_locks = PostLock::where('post_id', '=', $post_id)->get();
foreach ($post_locks as $post_lock) {
$post_lock->delete();
}
}
public function deleteByUserId(int $user_id): void
{
Expand Down
Loading