Browse Source

Removed isUserModifiable playlist attribute

Update liked/disliked playlists: db.playlists.update({"_id": ObjectId("PLAYLIST_ID")}, {$set: {"type": "userSystem"}})
Owen Diffey 4 years ago
parent
commit
5be688577e

+ 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.isUserModifiable = true;
+					if (!showNonModifiablePlaylists) match.type = "user";
 
 					// if a playlist order exists
 					if (orderOfPlaylists > 0) match._id = { $in: orderOfPlaylists };
@@ -629,7 +629,7 @@ export default {
 				},
 
 				(playlist, next) => {
-					if (!playlist.isUserModifiable) return next("Playlist cannot be shuffled.");
+					if (playlist.type !== "user") 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.isUserModifiable) return next("Playlist cannot be modified.");
+					if (playlist.type !== "user" && playlist.type !== "userSystem") 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.isUserModifiable) return next("Playlist cannot be modified.");
+					if (playlist.type !== "user") return next("Playlist cannot be modified.");
 
 					return next(null, playlist);
 				}
@@ -1187,7 +1187,7 @@ export default {
 				},
 
 				(playlist, next) => {
-					if (!playlist.isUserModifiable) return next("Playlist cannot be modified.");
+					if (playlist.type !== "user") return next("Playlist cannot be modified.");
 					return next(null);
 				},
 
@@ -1260,7 +1260,7 @@ export default {
 				},
 
 				(playlist, next) => {
-					if (!playlist.isUserModifiable) return next("Playlist cannot be removed.");
+					if (playlist.type !== "user" && playlist.type !== "userSystem") 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: "user"
+						type: "userSystem"
 					})
 						.then(likedSongsPlaylist => {
 							next(null, likedSongsPlaylist, userId);
@@ -439,7 +439,7 @@ export default {
 					PlaylistsModule.runJob("CREATE_READ_ONLY_PLAYLIST", {
 						userId,
 						displayName: "Disliked Songs",
-						type: "user"
+						type: "userSystem"
 					})
 						.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: "user"
+								type: "userSystem"
 							})
 								.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: "user"
+								type: "userSystem"
 							})
 								.then(dislikedSongsPlaylist => {
 									next(null, { likedSongsPlaylist, dislikedSongsPlaylist }, userId);

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

@@ -1,6 +1,5 @@
 export default {
 	displayName: { type: String, min: 2, max: 32, required: true },
-	isUserModifiable: { type: Boolean, default: true, required: true },
 	songs: [
 		{
 			songId: { type: String },
@@ -13,5 +12,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", "genre"], required: true }
+	type: { type: String, enum: ["user", "userSystem", "genre"], required: true }
 };

+ 0 - 2
backend/logic/playlists.js

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

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

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

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

@@ -7,7 +7,6 @@
 					<tr>
 						<td>Display name</td>
 						<td>Type</td>
-						<td>Is user modifiable</td>
 						<td>Songs #</td>
 						<td>Playlist length</td>
 						<td>Created by</td>
@@ -21,7 +20,6 @@
 					<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>