Browse Source

Revert "Removed isUserModifiable playlist attribute"

This reverts commit 5be688577e1320046874389bf664ce4a439b83c3.
Jonathan 4 years ago
parent
commit
fb55ee2aae

+ 6 - 6
backend/logic/actions/playlists.js

@@ -337,7 +337,7 @@ export default {
 					};
 
 					// if non modifiable playlists should be shown as well
-					if (!showNonModifiablePlaylists) match.type = "user";
+					if (!showNonModifiablePlaylists) match.isUserModifiable = true;
 
 					// if a playlist order exists
 					if (orderOfPlaylists > 0) match._id = { $in: orderOfPlaylists };
@@ -629,7 +629,7 @@ export default {
 				},
 
 				(playlist, next) => {
-					if (playlist.type !== "user") return next("Playlist cannot be shuffled.");
+					if (!playlist.isUserModifiable) return next("Playlist cannot be shuffled.");
 
 					return UtilsModule.runJob("SHUFFLE", { array: playlist.songs }, this)
 						.then(result => next(null, result.array))
@@ -767,7 +767,7 @@ export default {
 
 				(playlist, next) => {
 					if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found");
-					if (playlist.type !== "user" && playlist.type !== "userSystem") return next("Playlist cannot be modified.");
+					if (!playlist.isUserModifiable) return next("Playlist cannot be modified.");
 
 					// sort array by position
 					playlist.songs.sort((a, b) => a.position - b.position);
@@ -1024,7 +1024,7 @@ export default {
 
 				(playlist, next) => {
 					if (!playlist || playlist.createdBy !== session.userId) return next("Playlist not found.");
-					if (playlist.type !== "user") return next("Playlist cannot be modified.");
+					if (!playlist.isUserModifiable) return next("Playlist cannot be modified.");
 
 					return next(null, playlist);
 				}
@@ -1187,7 +1187,7 @@ export default {
 				},
 
 				(playlist, next) => {
-					if (playlist.type !== "user") return next("Playlist cannot be modified.");
+					if (!playlist.isUserModifiable) return next("Playlist cannot be modified.");
 					return next(null);
 				},
 
@@ -1260,7 +1260,7 @@ export default {
 				},
 
 				(playlist, next) => {
-					if (playlist.type !== "user" && playlist.type !== "userSystem") return next("Playlist cannot be removed.");
+					if (!playlist.isUserModifiable) return next("Playlist cannot be removed.");
 					return next(null, playlist);
 				},
 

+ 2 - 2
backend/logic/actions/users.js

@@ -426,7 +426,7 @@ export default {
 					PlaylistsModule.runJob("CREATE_READ_ONLY_PLAYLIST", {
 						userId,
 						displayName: "Liked Songs",
-						type: "userSystem"
+						type: "user"
 					})
 						.then(likedSongsPlaylist => {
 							next(null, likedSongsPlaylist, userId);
@@ -439,7 +439,7 @@ export default {
 					PlaylistsModule.runJob("CREATE_READ_ONLY_PLAYLIST", {
 						userId,
 						displayName: "Disliked Songs",
-						type: "userSystem"
+						type: "user"
 					})
 						.then(dislikedSongsPlaylist => {
 							next(null, { likedSongsPlaylist, dislikedSongsPlaylist }, userId);

+ 2 - 2
backend/logic/app.js

@@ -329,7 +329,7 @@ class _AppModule extends CoreClass {
 							PlaylistsModule.runJob("CREATE_READ_ONLY_PLAYLIST", {
 								userId,
 								displayName: "Liked Songs",
-								type: "userSystem"
+								type: "user"
 							})
 								.then(likedSongsPlaylist => {
 									next(null, likedSongsPlaylist, userId);
@@ -342,7 +342,7 @@ class _AppModule extends CoreClass {
 							PlaylistsModule.runJob("CREATE_READ_ONLY_PLAYLIST", {
 								userId,
 								displayName: "Disliked Songs",
-								type: "userSystem"
+								type: "user"
 							})
 								.then(dislikedSongsPlaylist => {
 									next(null, { likedSongsPlaylist, dislikedSongsPlaylist }, userId);

+ 2 - 1
backend/logic/db/schemas/playlist.js

@@ -1,5 +1,6 @@
 export default {
 	displayName: { type: String, min: 2, max: 32, required: true },
+	isUserModifiable: { type: Boolean, default: true, required: true },
 	songs: [
 		{
 			songId: { type: String },
@@ -12,5 +13,5 @@ export default {
 	createdAt: { type: Date, default: Date.now, required: true },
 	createdFor: { type: String },
 	privacy: { type: String, enum: ["public", "private"], default: "private" },
-	type: { type: String, enum: ["user", "userSystem", "genre"], required: true }
+	type: { type: String, enum: ["user", "genre"], required: true }
 };

+ 2 - 0
backend/logic/playlists.js

@@ -118,6 +118,7 @@ class _PlaylistsModule extends CoreClass {
 		return new Promise((resolve, reject) => {
 			PlaylistsModule.playlistModel.create(
 				{
+					isUserModifiable: false,
 					displayName: payload.displayName,
 					songs: [],
 					createdBy: payload.userId,
@@ -150,6 +151,7 @@ class _PlaylistsModule extends CoreClass {
 					if (err.message === "Playlist not found") {
 						PlaylistsModule.playlistModel.create(
 							{
+								isUserModifiable: false,
 								displayName: `Genre - ${payload.genre}`,
 								songs: [],
 								createdBy: "Musare",

+ 9 - 14
frontend/src/components/modals/EditPlaylist.vue

@@ -36,10 +36,7 @@
 							>
 							<div
 								class="controls"
-								v-if="
-									playlist.type === 'user' ||
-										playlist.type === 'userSystem'
-								"
+								v-if="playlist.isUserModifiable"
 							>
 								<a href="#" @click="moveSongToTop(index)">
 									<i class="material-icons" v-if="index > 0"
@@ -79,7 +76,7 @@
 				</draggable>
 				<br />
 			</aside>
-			<div class="control is-grouped" v-if="playlist.type === 'user'">
+			<div class="control is-grouped" v-if="playlist.isUserModifiable">
 				<p class="control is-expanded">
 					<input
 						v-model="searchSongQuery"
@@ -97,7 +94,7 @@
 				</p>
 			</div>
 			<table
-				v-if="songQueryResults.length > 0 && playlist.type === 'user'"
+				v-if="songQueryResults.length > 0 && playlist.isUserModifiable"
 				class="table"
 			>
 				<tbody>
@@ -120,7 +117,7 @@
 					</tr>
 				</tbody>
 			</table>
-			<div class="control is-grouped" v-if="playlist.type === 'user'">
+			<div class="control is-grouped" v-if="playlist.isUserModifiable">
 				<p class="control is-expanded">
 					<input
 						v-model="directSongQuery"
@@ -137,7 +134,7 @@
 					>
 				</p>
 			</div>
-			<div class="control is-grouped" v-if="playlist.type === 'user'">
+			<div class="control is-grouped" v-if="playlist.isUserModifiable">
 				<p class="control is-expanded">
 					<input
 						v-model="importQuery"
@@ -167,12 +164,12 @@
 			<button
 				class="button is-info"
 				@click="shuffle()"
-				v-if="playlist.type === 'user'"
+				v-if="playlist.isUserModifiable"
 			>
 				Shuffle
 			</button>
 			<h5>Edit playlist details:</h5>
-			<div class="control is-grouped" v-if="playlist.type === 'user'">
+			<div class="control is-grouped" v-if="playlist.isUserModifiable">
 				<p class="control is-expanded">
 					<input
 						v-model="playlist.displayName"
@@ -202,7 +199,7 @@
 				</p>
 			</div>
 		</div>
-		<div slot="footer" v-if="playlist.type === 'user'">
+		<div slot="footer" v-if="playlist.isUserModifiable">
 			<a class="button is-danger" @click="removePlaylist()" href="#"
 				>Remove Playlist</a
 			>
@@ -241,9 +238,7 @@ export default {
 			return {
 				animation: 200,
 				group: "description",
-				disabled:
-					this.playlist.type !== "user" &&
-					this.playlist.type !== "userSystem",
+				disabled: !this.playlist.isUserModifiable,
 				ghostClass: "draggable-list-ghost"
 			};
 		}

+ 2 - 0
frontend/src/pages/Admin/tabs/Playlists.vue

@@ -7,6 +7,7 @@
 					<tr>
 						<td>Display name</td>
 						<td>Type</td>
+						<td>Is user modifiable</td>
 						<td>Songs #</td>
 						<td>Playlist length</td>
 						<td>Created by</td>
@@ -20,6 +21,7 @@
 					<tr v-for="playlist in playlists" :key="playlist._id">
 						<td>{{ playlist.displayName }}</td>
 						<td>{{ playlist.type }}</td>
+						<td>{{ playlist.isUserModifiable }}</td>
 						<td>{{ playlist.songs.length }}</td>
 						<td>{{ totalLengthForPlaylist(playlist.songs) }}</td>
 						<td v-if="playlist.createdBy === 'Musare'">Musare</td>