Skip to content

Commit

Permalink
fix: Only query active forms for shared entries
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Feb 18, 2024
1 parent a9c75a9 commit 25395ab
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
7 changes: 3 additions & 4 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,14 @@ public function getForms(): DataResponse {
* @return DataResponse
*/
public function getSharedForms(): DataResponse {
$forms = $this->formMapper->findAll();
$forms = $this->formMapper->findActiveForms();

$result = [];
foreach ($forms as $form) {
// Check if the form should be shown on sidebar
if (!$this->formsService->isSharedFormShown($form)) {
continue;
if ($this->formsService->isSharedFormShown($form)) {
$result[] = $this->formsService->getPartialFormArray($form);
}
$result[] = $this->formsService->getPartialFormArray($form);
}

return new DataResponse($result);
Expand Down
24 changes: 24 additions & 0 deletions lib/Db/FormMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@ public function findAllByOwnerId(string $ownerId): array {
return $this->findEntities($qb);
}

/**
* Get only active forms - thus not archived, closed or expired
* @return Form[]
*/
public function findActiveForms(): array {
$qb = $this->db->getQueryBuilder();

$expires = $qb->expr()->orX();
$expires->add($qb->expr()->eq('expires', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
$expires->add($qb->expr()->gt('expires', $qb->createNamedParameter(time(), IQueryBuilder::PARAM_INT)));

$state = $qb->expr()->eq('state', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT));

$qb->select('*')
->from($this->getTableName())
->where($expires)
->andWhere($state)
//Last updated forms first, then newest forms first
->addOrderBy('last_updated', 'DESC')
->addOrderBy('created', 'DESC');

return $this->findEntities($qb);
}

/**
* Delete a Form including connected Questions, Submissions and shares.
* @param Form $form The form instance to delete
Expand Down
3 changes: 1 addition & 2 deletions lib/Service/FormsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,6 @@ public function hasUserAccess(Form $form): bool {
* @return bool
*/
public function isSharedFormShown(Form $form): bool {
$access = $form->getAccess();

// Dont show here to owner, as its in the owned list anyways.
if ($form->getOwnerId() === $this->currentUser->getUID()) {
return false;
Expand All @@ -401,6 +399,7 @@ public function isSharedFormShown(Form $form): bool {
return false;
}

$access = $form->getAccess();
// Shown if permitall and showntoall are both set.
if ($access['permitAllUsers'] &&
$access['showToAllUsers'] &&
Expand Down
2 changes: 1 addition & 1 deletion src/components/AppNavigationForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ import IconDeleteSvg from '@mdi/svg/svg/delete.svg?raw'
import FormsIcon from './Icons/FormsIcon.vue'
import { FormState } from '../models/FormStates'
import { FormState } from '../models/FormStates.ts'
import logger from '../utils/Logger.js'
export default {
Expand Down

0 comments on commit 25395ab

Please sign in to comment.