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

[stable4] fix: Check admin settings when fetching shared forms #2488

Merged
merged 3 commits into from
Jan 11, 2025
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
4 changes: 2 additions & 2 deletions .github/workflows/phpunit-sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ jobs:
working-directory: apps/${{ env.APP_NAME }}
run: composer run test:integration

- name: Upload Unit coverage
- name: Upload integration coverage
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
working-directory: apps/${{ env.APP_NAME }}
file: tests/clover.unit.xml
file: tests/clover.integration.xml
fail_ci_if_error: true
flags: integration

Expand Down
22 changes: 22 additions & 0 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@
throw new OCSForbiddenException();
}

// Do not allow changing showToAllUsers if disabled
if (isset($keyValuePairs['access'])) {
$showAll = $keyValuePairs['access']['showToAllUsers'] ?? false;
$permitAll = $keyValuePairs['access']['permitAllUsers'] ?? false;
if (($showAll && !$this->configService->getAllowShowToAll())
|| ($permitAll && !$this->configService->getAllowPermitAll())) {
$this->logger->info('Not allowed to update showToAllUsers or permitAllUsers');
throw new OCSForbiddenException();

Check warning on line 297 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L291-L297

Added lines #L291 - L297 were not covered by tests
}
}

// Process file linking
if (isset($keyValuePairs['path']) && isset($keyValuePairs['fileFormat'])) {
$file = $this->submissionService->writeFileToCloud($form, $keyValuePairs['path'], $keyValuePairs['fileFormat']);
Expand Down Expand Up @@ -1627,6 +1638,17 @@
throw new OCSForbiddenException();
}

// Do not allow changing showToAllUsers if disabled
if (isset($keyValuePairs['access'])) {
$showAll = $keyValuePairs['access']['showToAllUsers'] ?? false;
$permitAll = $keyValuePairs['access']['permitAllUsers'] ?? false;
if (($showAll && !$this->configService->getAllowShowToAll())
|| ($permitAll && !$this->configService->getAllowPermitAll())) {
$this->logger->info('Not allowed to update showToAllUsers or permitAllUsers');
throw new OCSForbiddenException();

Check warning on line 1648 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L1642-L1648

Added lines #L1642 - L1648 were not covered by tests
}
}

// Create FormEntity with given Params & Id.
foreach ($keyValuePairs as $key => $value) {
$method = 'set' . ucfirst($key);
Expand Down
23 changes: 14 additions & 9 deletions lib/Db/FormMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OCA\Forms\Db;

use OCA\Forms\Constants;
use OCA\Forms\Service\ConfigService;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
Expand All @@ -43,10 +44,11 @@ class FormMapper extends QBMapper {
* @param IDBConnection $db
*/
public function __construct(
IDBConnection $db,
private QuestionMapper $questionMapper,
private ShareMapper $shareMapper,
private SubmissionMapper $submissionMapper,
IDBConnection $db,
private ConfigService $configService,
) {
parent::__construct($db, 'forms_v2_forms', Form::class);
}
Expand Down Expand Up @@ -151,20 +153,23 @@ public function findSharedForms(string $userId, array $groups = [], array $teams
}

// build expression for publicy shared forms (default only directly shown)
if ($filterShown) {
// Only shown
$access = $qbShares->expr()->in('access_enum', $qbShares->createNamedParameter(Constants::FORM_ACCESS_ARRAY_SHOWN, IQueryBuilder::PARAM_INT_ARRAY));
} else {
// All
$access = $qbShares->expr()->neq('access_enum', $qbShares->createNamedParameter(Constants::FORM_ACCESS_NOPUBLICSHARE, IQueryBuilder::PARAM_INT));
if ($this->configService->getAllowPermitAll()) {
if ($filterShown && $this->configService->getAllowShowToAll()) {
// Only shown forms
$access = $qbShares->expr()->in('access_enum', $qbShares->createNamedParameter(Constants::FORM_ACCESS_ARRAY_SHOWN, IQueryBuilder::PARAM_INT_ARRAY, ':access_shown'));
} elseif ($filterShown === false) {
// All
$access = $qbShares->expr()->neq('access_enum', $qbShares->createNamedParameter(Constants::FORM_ACCESS_NOPUBLICSHARE, IQueryBuilder::PARAM_INT, ':access_nopublicshare'));
}
}
// Build the where clause for membership or public access
$memberOrPublic = isset($access) ? $qbShares->expr()->orX($memberships, $access) : $memberships;

// Select all DISTINCT IDs of shared forms
$qbShares->selectDistinct('forms.id')
->from($this->getTableName(), 'forms')
->leftJoin('forms', $this->shareMapper->getTableName(), 'shares', $qbShares->expr()->eq('forms.id', 'shares.form_id'))
->where($memberships)
->orWhere($access)
->where($memberOrPublic)
->andWhere($qbShares->expr()->neq('forms.owner_id', $qbShares->createNamedParameter($userId, IQueryBuilder::PARAM_STR)));

// Select the whole forms for the DISTINCT shared forms IDs
Expand Down
Loading
Loading