浏览代码

feat(Playlists): prevent liked/disliked playlist from being user modifiable

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan 4 年之前
父节点
当前提交
64de22a943
共有 2 个文件被更改,包括 49 次插入12 次删除
  1. 32 4
      backend/logic/actions/playlists.js
  2. 17 8
      frontend/src/components/modals/EditPlaylist.vue

+ 32 - 4
backend/logic/actions/playlists.js

@@ -452,10 +452,10 @@ export default {
 				},
 
 				(playlist, next) => {
-					UtilsModule.runJob("SHUFFLE", { array: playlist.songs }, this)
-						.then(result => {
-							next(null, result.array);
-						})
+					if (!playlist.isUserModifiable) return next("Playlist cannot be shuffled.");
+
+					return UtilsModule.runJob("SHUFFLE", { array: playlist.songs }, this)
+						.then(result => next(null, result.array))
 						.catch(next);
 				},
 
@@ -690,6 +690,8 @@ export default {
 
 				(playlist, next) => {
 					if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found.");
+					if (!playlist.isUserModifiable) return next("Playlist cannot be modified.");
+
 					return next(null, playlist);
 				}
 			],
@@ -820,6 +822,17 @@ export default {
 		);
 		async.waterfall(
 			[
+				next => {
+					PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
+						.then(playlist => next(null, playlist))
+						.catch(next);
+				},
+
+				(playlist, next) => {
+					if (!playlist.isUserModifiable) return next("Playlist cannot be modified.");
+					return next(null);
+				},
+
 				next => {
 					playlistModel.updateOne(
 						{ _id: playlistId, createdBy: session.userId },
@@ -896,6 +909,8 @@ export default {
 
 				(playlist, next) => {
 					if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found");
+					if (!playlist.isUserModifiable) return next("Playlist cannot be modified.");
+
 					return async.each(
 						playlist.songs,
 						(song, next) => {
@@ -1001,6 +1016,8 @@ export default {
 
 				(playlist, next) => {
 					if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found");
+					if (!playlist.isUserModifiable) return next("Playlist cannot be modified.");
+
 					return async.each(
 						playlist.songs,
 						(song, next) => {
@@ -1093,6 +1110,17 @@ export default {
 
 		async.waterfall(
 			[
+				next => {
+					PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
+						.then(playlist => next(null, playlist))
+						.catch(next);
+				},
+
+				(playlist, next) => {
+					if (!playlist.isUserModifiable) return next("Playlist cannot be removed.");
+					return next(null);
+				},
+
 				next => {
 					PlaylistsModule.runJob("DELETE_PLAYLIST", { playlistId }, this).then(next).catch(next);
 				},

+ 17 - 8
frontend/src/components/modals/EditPlaylist.vue

@@ -16,7 +16,7 @@
 				<ul class="menu-list">
 					<li v-for="(song, index) in playlist.songs" :key="index">
 						<a href="#" target="_blank">{{ song.title }}</a>
-						<div class="controls">
+						<div class="controls" v-if="playlist.isUserModifiable">
 							<a href="#" @click="promoteSong(song.songId)">
 								<i class="material-icons" v-if="index > 0"
 									>keyboard_arrow_up</i
@@ -52,7 +52,7 @@
 				</ul>
 				<br />
 			</aside>
-			<div class="control is-grouped">
+			<div class="control is-grouped" v-if="playlist.isUserModifiable">
 				<p class="control is-expanded">
 					<input
 						v-model="searchSongQuery"
@@ -69,7 +69,10 @@
 					>
 				</p>
 			</div>
-			<table v-if="songQueryResults.length > 0" class="table">
+			<table
+				v-if="songQueryResults.length > 0 && playlist.isUserModifiable"
+				class="table"
+			>
 				<tbody>
 					<tr
 						v-for="(result, index) in songQueryResults"
@@ -90,7 +93,7 @@
 					</tr>
 				</tbody>
 			</table>
-			<div class="control is-grouped">
+			<div class="control is-grouped" v-if="playlist.isUserModifiable">
 				<p class="control is-expanded">
 					<input
 						v-model="directSongQuery"
@@ -107,7 +110,7 @@
 					>
 				</p>
 			</div>
-			<div class="control is-grouped">
+			<div class="control is-grouped" v-if="playlist.isUserModifiable">
 				<p class="control is-expanded">
 					<input
 						v-model="importQuery"
@@ -134,9 +137,15 @@
 					>
 				</p>
 			</div>
-			<button class="button is-info" @click="shuffle()">Shuffle</button>
+			<button
+				class="button is-info"
+				@click="shuffle()"
+				v-if="playlist.isUserModifiable"
+			>
+				Shuffle
+			</button>
 			<h5>Edit playlist details:</h5>
-			<div class="control is-grouped">
+			<div class="control is-grouped" v-if="playlist.isUserModifiable">
 				<p class="control is-expanded">
 					<input
 						v-model="playlist.displayName"
@@ -166,7 +175,7 @@
 				</p>
 			</div>
 		</div>
-		<div slot="footer">
+		<div slot="footer" v-if="playlist.isUserModifiable">
 			<a class="button is-danger" @click="removePlaylist()" href="#"
 				>Remove Playlist</a
 			>