瀏覽代碼

refactor: Prevent discogs usage if disabled

Owen Diffey 1 年之前
父節點
當前提交
709652a211

+ 1 - 1
backend/logic/hooks/hasPermission.js

@@ -37,7 +37,7 @@ permissions.moderator = {
 	"admin.view.stations": true,
 	"admin.view.users": true,
 	"admin.view.youtubeVideos": true,
-	"apis.searchDiscogs": true,
+	"apis.searchDiscogs": config.get("apis.discogs.enabled"),
 	"news.create": true,
 	"news.update": true,
 	"playlists.create.admin": true,

+ 10 - 0
frontend/src/components/modals/EditSong/index.vue

@@ -1207,10 +1207,18 @@ watch(
 		if (!value) closeCurrentModal(true);
 	}
 );
+watch(
+	() => hasPermission("apis.searchDiscogs"),
+	value => {
+		if (!value && tab.value === "discogs") showTab("musare-songs");
+	}
+);
 
 onMounted(async () => {
 	editSongStore.init({ song: props.song, songs: props.songs });
 
+	if (!hasPermission("apis.searchDiscogs")) showTab("musare-songs");
+
 	editSongStore.form = {
 		inputs,
 		unsavedChanges,
@@ -2660,6 +2668,7 @@ onBeforeUnmount(() => {
 					<div id="tabs-container">
 						<div id="tab-selection">
 							<button
+								v-if="hasPermission('apis.searchDiscogs')"
 								class="button is-default"
 								:class="{ selected: tab === 'discogs' }"
 								:ref="el => (tabs['discogs-tab'] = el)"
@@ -2694,6 +2703,7 @@ onBeforeUnmount(() => {
 							</button>
 						</div>
 						<discogs
+							v-if="hasPermission('apis.searchDiscogs')"
 							class="tab"
 							v-show="tab === 'discogs'"
 							:bulk="bulk"

+ 12 - 1
frontend/src/components/modals/ImportAlbum.vue

@@ -3,6 +3,7 @@ import {
 	defineAsyncComponent,
 	ref,
 	computed,
+	watch,
 	onMounted,
 	onBeforeUnmount
 } from "vue";
@@ -12,6 +13,7 @@ import { DraggableList } from "vue-draggable-list";
 import { useWebsocketsStore } from "@/stores/websockets";
 import { useModalsStore } from "@/stores/modals";
 import { useImportAlbumStore } from "@/stores/importAlbum";
+import { useUserAuthStore } from "@/stores/userAuth";
 
 const Modal = defineAsyncComponent(() => import("@/components/Modal.vue"));
 const MediaItem = defineAsyncComponent(
@@ -37,7 +39,9 @@ const {
 	updatePlaylistSong
 } = importAlbumStore;
 
-const { openModal, preventCloseCbs } = useModalsStore();
+const { openModal, closeCurrentModal, preventCloseCbs } = useModalsStore();
+
+const { hasPermission } = useUserAuthStore();
 
 const isImportingPlaylist = ref(false);
 const trackSongs = ref([]);
@@ -333,6 +337,13 @@ const updateTrackSong = updatedSong => {
 	});
 };
 
+watch(
+	() => hasPermission("apis.searchDiscogs"),
+	value => {
+		if (!value) closeCurrentModal(true);
+	}
+);
+
 onMounted(() => {
 	setPlaylistSongs(props.songs);
 

+ 3 - 2
frontend/src/pages/Admin/Songs/index.vue

@@ -543,8 +543,9 @@ onMounted(() => {
 				</button>
 				<button
 					v-if="
-						hasPermission('songs.create') ||
-						hasPermission('songs.update')
+						(hasPermission('songs.create') ||
+							hasPermission('songs.update')) &&
+						hasPermission('apis.searchDiscogs')
 					"
 					class="button is-primary"
 					@click="openModal('importAlbum')"