Skip to content

Commit 84fa730

Browse files
committed
Merge #487: Rename button "download torrent" to "download private torrent" when the tracker is in close mode
385b695 refactor: improve error messages for cypress DB user tasks (Jose Celano) e7ac640 fix: helper to check if the tracker is open (Jose Celano) e2171b6 fix: redirect to sign in to download a torrent (Jose Celano) 2d8a446 refactor: rename helper (Jose Celano) 1d99c2a fix: download torrent button is always shown (Jose Celano) Pull request description: - [x] Fix bug. The button was always shown even when the tracker was private and the user was not logged in. - [x] Fix bug. The function to detect tracker mode was not working. - [x] Rename the button for private trackers. - [x] Improve error message when tasks in the database for users fail. ACKs for top commit: josecelano: ACK 385b695 Tree-SHA512: 1a826d76c74f53bbcb4d42eaa835a3d0df55f50cd4eb1b876d0169f35987e09451c2fe9ab52a5ad8df3272d5bfb0595c44805e4ae4b785013788f7bcf30996bf
2 parents f91d257 + 385b695 commit 84fa730

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

components/torrent/TorrentActionCard.vue

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@
9999
<div />
100100

101101
<div class="flex flex-row gap-3">
102-
<template v-if="showDownloadButtons">
102+
<template v-if="showDownloadButtons()">
103103
<button class="btn btn-primary grow" data-cy="torrent-action-download" @click="downloadTorrent(torrent.info_hash, torrent.name)">
104-
download torrent
104+
download {{ isTrackerClose()? 'private' : '' }} torrent
105105
</button>
106106
<button class="w-12 p-0 btn btn-primary">
107107
<a data-cy="torrent-action-magnet-link" class="flex items-center" :href="torrent.magnet_link">
@@ -110,18 +110,7 @@
110110
</button>
111111
</template>
112112
<template v-else>
113-
<button
114-
class="h-12 px-4 mt-3 text-sm font-medium text-black bg-white rounded-2xl"
115-
@click="$store.dispatch('openAuthModal')"
116-
>
117-
Please sign in to download
118-
</button>
119-
<button
120-
class="h-12 px-4 mt-3 text-sm font-medium text-white bg-sky-500 rounded-2xl"
121-
@click="$store.dispatch('openAuthModal')"
122-
>
123-
Please sign in to download
124-
</button>
113+
<NuxtLink to="/signin">Private tracker. Sign in to download torrent or magnet link.</NuxtLink>
125114
</template>
126115
</div>
127116

@@ -156,7 +145,7 @@ import {
156145
downloadTorrent,
157146
useRestApi,
158147
isUserLoggedIn,
159-
isTrackerPublic, navigateTo
148+
isTrackerOpen, isTrackerClose, navigateTo
160149
} from "#imports";
161150
import { canEditThisTorrent } from "~/composables/helpers";
162151
@@ -178,8 +167,8 @@ function hasEditRights (): boolean {
178167
return canEditThisTorrent(props.torrent);
179168
}
180169
181-
function showDownloadButtons () {
182-
return isUserLoggedIn() || isTrackerPublic();
170+
function showDownloadButtons (): boolean {
171+
return isUserLoggedIn() || isTrackerOpen();
183172
}
184173
185174
function seedersPercentage () {
@@ -209,4 +198,8 @@ function deleteTorrent () {
209198
}, 10000);
210199
});
211200
}
201+
202+
function navigateToSignIn () {
203+
navigateTo("/signin", { replace: true });
204+
}
212205
</script>

composables/helpers.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { TorrentResponse, TrackerMode } from "torrust-index-types-lib";
22
import { useRestApi, useSettings, useUser } from "~/composables/states";
33

4-
export function isTrackerPublic (): boolean {
4+
export function isTrackerOpen (): boolean {
55
const settings = useSettings();
66

7-
return settings.value.tracker_mode === TrackerMode.Public ||
8-
settings.value.tracker_mode === TrackerMode.Whitelisted;
7+
// todo: we are not using the type TrackerMode in
8+
// settings.value.tracker_mode
9+
10+
return settings.value.tracker_mode === "Public" ||
11+
settings.value.tracker_mode === "Whitelisted";
12+
}
13+
14+
export function isTrackerClose (): boolean {
15+
return !isTrackerOpen();
916
}
1017

1118
export function isUserLoggedIn (): boolean {

cypress/e2e/contexts/user/tasks.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export const grantAdminRole = async (username: string, db_config: DatabaseConfig
99
try {
1010
const result = await runDatabaseQuery(getUserIdByUsernameQuery(username), db_config);
1111

12+
if (result === undefined || result.user_id === undefined) {
13+
throw new Error(`Can't grant admin role to user. No user found with username: ${username} in database: ${db_config.filepath}`);
14+
}
15+
1216
const user_id = result.user_id;
1317

1418
await runDatabaseQuery(grantAdminRoleQuery(user_id), db_config);
@@ -26,6 +30,10 @@ export const deleteUser = async (username: string, db_config: DatabaseConfig): P
2630
try {
2731
const result = await runDatabaseQuery(getUserIdByUsernameQuery(username), db_config);
2832

33+
if (result === undefined || result.user_id === undefined) {
34+
throw new Error(`Can't delete user. No user found with username: ${username} in database: ${db_config.filepath}`);
35+
}
36+
2937
const user_id = result.user_id;
3038

3139
await runDatabaseQuery(deleteUserAuthenticationQuery(user_id), db_config);

0 commit comments

Comments
 (0)