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

exclude posts of survey with private locations #4922

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -24,9 +24,10 @@ public function getSearchFields()
return $this->search_fields;
}

public static function fromRequest(Request $request): self
public static function fromRequest(Request $request, array $surveys_with_private_location = []): self
{

$post_search_fields = new PostStatsSearchFields($request);
$post_search_fields->excludeFormIds($surveys_with_private_location);
return new self(new PostStatsSearchFields($request));
}
}
21 changes: 16 additions & 5 deletions src/Ushahidi/Modules/V5/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
class PostController extends V5Controller
{

// It uses methods from several traits to check access:
// It uses methods from several traits to check access:
// - `AdminAccess` to check if the user has admin access
use AdminAccess;


/**
* Not all fields are things we want to allow on the body of requests
* an author won't change after the fact, so we limit that change
Expand Down Expand Up @@ -354,15 +354,26 @@ public function delete(int $id, Request $request)

public function stats(Request $request)
{
$stats = $this->queryBus->handle(PostsStatsQuery::FromRequest($request));
$surveys_with_private_location = $this->queryBus->handle(new GetSurveyIdsWithPrivateLocationQuery());
Mh-Asmi marked this conversation as resolved.
Show resolved Hide resolved
if ($this->canUserseePostsWithPrivateLocation()) {
$stats = $this->queryBus->handle(PostsStatsQuery::FromRequest($request));
} else {
$stats = $this->queryBus->handle(
PostsStatsQuery::FromRequest(
$request,
$surveys_with_private_location->pluck('id')->toArray()
)
);
}

return new PostStatsResource($stats);
}

public function indexGeoJson(Request $request): PostGeometryCollection
{

$surveys_with_private_location = $this->queryBus->handle(new GetSurveyIdsWithPrivateLocationQuery());

if ($this->canUserseePostsWithPrivateLocation()) {
$posts = $this->queryBus->handle(ListPostsGeometryQuery::FromRequest($request));
} else {
Expand All @@ -373,7 +384,7 @@ public function indexGeoJson(Request $request): PostGeometryCollection
)
);
}

return new PostGeometryCollection($posts);
}

Expand Down
Loading