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

Force accept agreement before uploading #623

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
2 changes: 1 addition & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { grantAdminRole, deleteUser } from "./cypress/e2e/contexts/user/tasks";
import { deleteTorrent, deleteTorrentsInfoFromDatabase } from "./cypress/e2e/contexts/torrent/tasks";
import { deleteCategory, addCategory } from "./cypress/e2e/contexts/category/tasks";
import { deleteTags, addTag } from "./cypress/e2e/contexts/tag/tasks";
import { DatabaseConfig } from "./cypress/e2e/common/database";
import type { DatabaseConfig } from "./cypress/e2e/common/database";

function databaseConfig (config: Cypress.PluginConfigOptions): DatabaseConfig {
return {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/contexts/torrent/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Cypress.Commands.add("upload_torrent", (torrent_info) => {
// the tags context. We could even create some tags before running all the
// tests.
// cy.get("input[data-cy=\"upload-form-torrent-upload\"]").select('fractals');

cy.get("input[data-cy=\"upload-form-agree-terms\"]").check();
cy.get("button[data-cy=\"upload-form-submit\"]").click();
});

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/contexts/torrent/specs/upload.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("A registered user", () => {
// the tags context. We could even create some tags before running all the
// tests.
// cy.get("input[data-cy=\"upload-form-torrent-upload\"]").select('fractals');

cy.get("input[data-cy=\"upload-form-agree-terms\"]").check();
cy.get("button[data-cy=\"upload-form-submit\"]").click();

cy.get("@infohash").then((infohash) => {
Expand Down
30 changes: 28 additions & 2 deletions pages/upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
</div>
</template>
</div>

<template v-if="categories?.length > 0">
<div>
<label for="category" class="px-2">Category</label>
Expand All @@ -53,6 +54,7 @@
</select>
</div>
</template>

<template v-if="tags?.length > 0">
<div>
<label for="tags" class="px-2">Tags</label>
Expand All @@ -67,14 +69,25 @@
<div>
<UploadFile sub-title="Only .torrent files allowed. BitTorrent v2 files are NOT supported." accept=".torrent" @on-change="setFile" />
</div>

<!-- Checkbox for Terms and Conditions Agreement -->
<div>
<label for="agree-to-terms" class="px-2">Agreement</label>
<div class="mt-1">
<input v-model="agreeToTerms" name="agree-to-terms" type="checkbox" class="max-w-5" data-cy="upload-form-agree-terms">
<span class="px-2">I have read the <NuxtLink to="/terms" target="_blank">{{ contentUploadAgreement }}</NuxtLink>.</span>
</div>
</div>

<template v-if="user?.username">
<TorrustButton
label="submit"
data-cy="upload-form-submit"
:disabled="!formValid() || uploading"
:disabled="!formValid() || !agreeToTerms || uploading"
@click="submitForm"
/>
</template>

<template v-else>
<div class="relative flex justify-center text-sm">
<NuxtLink to="/signin">
Expand All @@ -101,7 +114,7 @@ import {
useTags,
useUser
} from "#imports";
import { useCategories } from "~/composables/states";
import { useCategories, useSettings } from "~/composables/states";

type FormUploadTorrent = {
title: string;
Expand All @@ -111,11 +124,13 @@ type FormUploadTorrent = {
torrentFile: any;
}

const settings = useSettings();
const categories = useCategories();
const tags = useTags();
const user = useUser();
const rest = useRestApi();

const agreeToTerms: Ref<boolean> = ref(false);
const uploading: Ref<boolean> = ref(false);
const descriptionView = ref("edit");
const form: Ref<FormUploadTorrent> = ref({
Expand All @@ -125,12 +140,23 @@ const form: Ref<FormUploadTorrent> = ref({
tags: [],
torrentFile: ""
});
const contentUploadAgreement = ref("");

onMounted(() => {
getCategories();
getTags();
});

watch(
() => settings.value,
(newSettings) => {
if (newSettings?.website?.terms?.upload?.content_upload_agreement) {
contentUploadAgreement.value = newSettings.website.terms.page.title;
}
},
{ immediate: true }
);

function formValid () {
return form.value.title && form.value.category && form.value.torrentFile;
}
Expand Down