Skip to content

Commit

Permalink
chore: remove legacy link support
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <[email protected]>
  • Loading branch information
Chartman123 committed Oct 11, 2024
1 parent d5de048 commit c732219
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 123 deletions.
5 changes: 1 addition & 4 deletions lib/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,13 @@ class Constants {
public const FORM_ACCESS_NOPUBLICSHARE = 0;
public const FORM_ACCESS_PERMITALLUSERS = 1;
public const FORM_ACCESS_SHOWTOALLUSERS = 2;
/** @deprecated 5.0.0 still needed for Migrations */
public const FORM_ACCESS_LEGACYLINK = 3;
public const FORM_ACCESS_LEGACYLINK_PERMITALLUSERS = 4;
public const FORM_ACCESS_LEGACYLINK_SHOWTOALLUSERS = 5;
public const FORM_ACCESS_ARRAY_PERMIT = [
self::FORM_ACCESS_PERMITALLUSERS,
self::FORM_ACCESS_LEGACYLINK_PERMITALLUSERS
];
public const FORM_ACCESS_ARRAY_SHOWN = [
self::FORM_ACCESS_SHOWTOALLUSERS,
self::FORM_ACCESS_LEGACYLINK_SHOWTOALLUSERS
];

/**
Expand Down
5 changes: 0 additions & 5 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2765,11 +2765,6 @@ private function loadFormForSubmission(int $formId, string $shareHash): Form {

// If hash given, find the corresponding share & check if hash corresponds to given formId.
if ($shareHash !== '') {
// public by legacy Link
if (isset($form->getAccess()['legacyLink']) && $shareHash === $form->getHash()) {
$isPublicShare = true;
}

// Public link share
$share = $this->shareMapper->findPublicShareByHash($shareHash);
if ($share->getFormId() === $formId) {
Expand Down
25 changes: 0 additions & 25 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,6 @@ public function internalLinkView(string $hash): Response {
return new RedirectResponse($internalView);
}

// For legacy-support, show public template
try {
$form = $this->formMapper->findByHash($hash);
} catch (DoesNotExistException $e) {
return $this->provideEmptyContent(Constants::EMPTY_NOTFOUND);
}
if (isset($form->getAccess()['legacyLink'])) {
// Inject style on all templates
Util::addStyle($this->appName, 'forms');

// Has form expired
if ($this->formsService->hasFormExpired($form)) {
return $this->provideEmptyContent(Constants::EMPTY_EXPIRED, $form);
}

// Public Template to fill the form
Util::addScript($this->appName, 'forms-submit');
$this->insertHeaderOnIos();
$this->initialState->provideInitialState('form', $this->formsService->getPublicForm($form));
$this->initialState->provideInitialState('isLoggedIn', $this->userSession->isLoggedIn());
$this->initialState->provideInitialState('shareHash', $hash);
$this->initialState->provideInitialState('maxStringLengths', Constants::MAX_STRING_LENGTHS);
return $this->provideTemplate(self::TEMPLATE_MAIN, $form);
}

// Otherwise Redirect to login (& then internal view)
return new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', ['redirect_url' => $internalView]));
}
Expand Down
10 changes: 1 addition & 9 deletions lib/Db/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ public function getAccess(): array {
$accessEnum = $this->getAccessEnum();
$access = [];

if ($accessEnum >= Constants::FORM_ACCESS_LEGACYLINK) {
$access['legacyLink'] = true;
}
switch ($accessEnum % Constants::FORM_ACCESS_LEGACYLINK) {
switch ($accessEnum) {
case Constants::FORM_ACCESS_NOPUBLICSHARE:
$access['permitAllUsers'] = false;
$access['showToAllUsers'] = false;
Expand Down Expand Up @@ -135,11 +132,6 @@ public function setAccess(array $access) {
$value = Constants::FORM_ACCESS_PERMITALLUSERS;
}

// If legacyLink add 3
if (isset($access['legacyLink']) && $access['legacyLink']) {
$value += Constants::FORM_ACCESS_LEGACYLINK;
}

$this->setAccessEnum($value);
}

Expand Down
38 changes: 38 additions & 0 deletions lib/Migration/Version050000Date20241005173955.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Forms\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version050000Date20241005173955 extends SimpleMigrationStep {

public function __construct(

Check warning on line 20 in lib/Migration/Version050000Date20241005173955.php

View check run for this annotation

Codecov / codecov/patch

lib/Migration/Version050000Date20241005173955.php#L20

Added line #L20 was not covered by tests
protected IDBConnection $db,
) {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$qbUpdate = $this->db->getQueryBuilder();

Check warning on line 31 in lib/Migration/Version050000Date20241005173955.php

View check run for this annotation

Codecov / codecov/patch

lib/Migration/Version050000Date20241005173955.php#L30-L31

Added lines #L30 - L31 were not covered by tests

$qbUpdate->update('forms_v2_forms')
->set('access_enum', 'access_enum - 3')
->where($qbUpdate->expr()->gte('access_enum', '3'))
->executeStatement();

Check warning on line 36 in lib/Migration/Version050000Date20241005173955.php

View check run for this annotation

Codecov / codecov/patch

lib/Migration/Version050000Date20241005173955.php#L33-L36

Added lines #L33 - L36 were not covered by tests
}
}
6 changes: 1 addition & 5 deletions lib/Service/FormsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public function canDeleteResults(Form $form): bool {
* @return boolean
*/
public function canSubmit(Form $form): bool {
// We cannot control how many time users can submit if public link / legacyLink available
// We cannot control how many time users can submit if public link available
if ($this->hasPublicLink($form)) {
return true;
}
Expand Down Expand Up @@ -387,10 +387,6 @@ public function canSubmit(Form $form): bool {
private function hasPublicLink(Form $form): bool {
$access = $form->getAccess();

if (isset($access['legacyLink'])) {
return true;
}

$shareEntities = $this->shareMapper->findByForm($form->getId());
foreach ($shareEntities as $shareEntity) {
if ($shareEntity->getShareType() === IShare::TYPE_LINK) {
Expand Down
6 changes: 1 addition & 5 deletions src/components/SidebarTabs/SettingsSidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,7 @@ export default {
* Submit Multiple is disabled, if it cannot be controlled.
*/
disableSubmitMultiple() {
return (
this.hasPublicLink ||
this.form.access.legacyLink ||
this.form.isAnonymous
)
return this.hasPublicLink || this.form.isAnonymous
},
disableSubmitMultipleExplanation() {
if (this.disableSubmitMultiple) {
Expand Down
44 changes: 0 additions & 44 deletions src/components/SidebarTabs/SharingSidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,37 +115,6 @@
:text="qrDialogText"
@closed="qrDialogText = ''" />

<!-- Legacy Info, if present -->
<div v-if="form.access.legacyLink" class="share-div">
<div class="share-div__avatar">
<IconLinkVariant :size="20" />
</div>
<div class="share-div__desc share-div__desc--twoline">
<span>{{ t('forms', 'Legacy Link') }}</span>
<span>{{
t('forms', 'Form still supports old sharing-link.')
}}</span>
</div>
<div
v-tooltip="
t(
'forms',
'For compatibility with the old Sharing, the internal link is still usable as Share link. Please replace the link with a new Share link. The internal sharing link will not work anymore starting with Forms 5.0',
)
"
class="share-div__legacy-warning">
<IconAlertCircleOutline :size="20" />
</div>
<NcActions>
<NcActionButton @click="removeLegacyLink">
<template #icon>
<IconDelete :size="20" />
</template>
{{ t('forms', 'Remove Legacy Link') }}
</NcActionButton>
</NcActions>
</div>

<!-- Internal link -->
<div class="share-div">
<div class="share-div__avatar">
Expand Down Expand Up @@ -229,7 +198,6 @@ import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActionLink from '@nextcloud/vue/dist/Components/NcActionLink.js'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import IconAccountMultiple from 'vue-material-design-icons/AccountMultiple.vue'
import IconAlertCircleOutline from 'vue-material-design-icons/AlertCircleOutline.vue'
import IconCodeBrackets from 'vue-material-design-icons/CodeBrackets.vue'
import IconDelete from 'vue-material-design-icons/Delete.vue'
import IconLinkBoxVariantOutline from 'vue-material-design-icons/LinkBoxVariantOutline.vue'
Expand All @@ -252,7 +220,6 @@ export default {
components: {
FormsIcon,
IconAccountMultiple,
IconAlertCircleOutline,
IconCodeBrackets,
IconCopyAll,
IconDelete,
Expand Down Expand Up @@ -469,11 +436,6 @@ export default {
newAccess.showToAllUsers = newVal
this.$emit('update:formProp', 'access', newAccess)
},
removeLegacyLink() {
const newAccess = { ...this.form.access }
delete newAccess.legacyLink
this.$emit('update:formProp', 'access', newAccess)
},
openQrDialog(share) {
this.qrDialogText = this.getPublicShareLink(share)
Expand Down Expand Up @@ -535,11 +497,5 @@ export default {
}
}
}
&__legacy-warning {
background-size: 18px;
margin-inline-end: 4px;
color: var(--color-error);
}
}
</style>
13 changes: 0 additions & 13 deletions src/views/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,6 @@
<p v-if="infoMessage" class="info-message">
{{ infoMessage }}
</p>
<!-- TODO: remove with Forms 5.0
Show info about legacyLink that will be removed -->
<NcNoteCard
v-if="form.access.legacyLink"
type="warning"
:heading="t('forms', 'Legacy link in use')">
{{
t(
'forms',
'This form still uses a deprecated share link, that will be removed in Forms 5.0. Please use the new sharing mechanism.',
)
}}
</NcNoteCard>
</header>
<section>
Expand Down
13 changes: 0 additions & 13 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@
<p v-if="infoMessage" class="info-message">
{{ infoMessage }}
</p>
<!-- TODO: remove with Forms 5.0
Show info about legacyLink that will be removed -->
<NcNoteCard
v-if="form.access?.legacyLink"
type="warning"
:heading="t('forms', 'Legacy link in use')">
{{
t(
'forms',
'This form still uses a deprecated share link, that will be removed in Forms 5.0. Please use the new sharing mechanism.',
)
}}
</NcNoteCard>
</header>
<NcEmptyContent
Expand Down

0 comments on commit c732219

Please sign in to comment.