Przeglądaj źródła

Added ability to lock and unlock station queue by admins

theflametrooper 8 lat temu
rodzic
commit
8d0e537ae4

+ 41 - 0
backend/logic/actions/stations.js

@@ -365,6 +365,7 @@ module.exports = {
 					description: station.description,
 					displayName: station.displayName,
 					privacy: station.privacy,
+					locked: station.locked,
 					partyMode: station.partyMode,
 					owner: station.owner,
 					privatePlaylist: station.privatePlaylist
@@ -401,6 +402,35 @@ module.exports = {
 		});
 	},
 
+	/**
+	 * Toggles if a station is locked
+	 *
+	 * @param session
+	 * @param stationId - the station id
+	 * @param locked - the old locked status
+	 * @param cb
+	 */
+	toggleLock: hooks.adminRequired((session, stationId, oldLocked, cb) => {
+		async.waterfall([
+			(next) => {
+				db.models.station.update({ _id: stationId }, { $set: { locked: !oldLocked } }, next);
+			},
+
+			(res, next) => {
+				stations.updateStation(stationId, next);
+			}
+		], (err, station) => {
+			if (err) {
+				err = utils.getError(err);
+				logger.error("STATIONS_UPDATE_LOCKED_STATUS", `Updating station "${stationId}" locked status to "${!oldLocked}" failed. "${err}"`);
+				return cb({ status: 'failure', message: err });
+			} else {
+				logger.success("STATIONS_UPDATE_LOCKED_STATUS", `Updated station "${stationId}" locked status to "${!oldLocked}" successfully.`);
+				return cb({ status: 'success', data: !oldLocked });
+			}
+		});
+	}),
+
 	/**
 	 * Votes to skip a station
 	 *
@@ -845,6 +875,17 @@ module.exports = {
 
 			(station, next) => {
 				if (!station) return next('Station not found.');
+				if (station.locked) {
+					db.models.user.findOne({ _id: userId }, (err, user) => {
+						if (user.role !== 'admin' || station.owner !== userId) return next('Only owners and admins can add songs to a locked queue.');
+						else return next(null, station);
+					});
+				} else {
+					return next(null, station);
+				}
+			},
+
+			(station, next) => {
 				if (station.type !== 'community') return next('That station is not a community station.');
 				utils.canUserBeInStation(station, userId, (canBe) => {
 					if (canBe) return next(null, station);

+ 1 - 1
frontend/components/Modals/AddSongToQueue.vue

@@ -142,4 +142,4 @@
 
 		img { width: 55px; }
 	}
-</style>
+</style>

+ 12 - 0
frontend/components/Station/CommunityHeader.vue

@@ -81,6 +81,18 @@
 					</span>
 					<span class="icon-purpose">Pause station</span>
 				</a>
+				<a class="sidebar-item" href="#" v-if='$parent.station.locked && $parent.$parent.role === "admin"' @click='$parent.toggleLock()'>
+					<span class='icon'>
+						<i class='material-icons'>lock_open</i>
+					</span>
+					<span class="icon-purpose">Unlock station queue</span>
+				</a>
+				<a class="sidebar-item" href="#" @click='$parent.toggleLock()' v-if='!$parent.station.locked && $parent.$parent.role === "admin"'>
+					<span class='icon'>
+						<i class='material-icons'>lock</i>
+					</span>
+					<span class="icon-purpose">Lock Station queue</span>
+				</a>
 				<hr>
 			</div>
 			<div v-if="$parent.$parent.loggedIn && !$parent.noSong">

+ 10 - 0
frontend/components/Station/Station.vue

@@ -321,6 +321,15 @@
 				if (songDuration <= duration) local.player.pauseVideo();
 				if ((!local.paused) && duration <= songDuration) local.timeElapsed = local.formatTime(duration);
 			},
+			toggleLock: function () {
+				let _this = this;
+				socket.emit('stations.toggleLock', this.station._id, this.station.locked, res => {
+					console.log(res);
+					if (res.status === 'success') {
+						_this.station.locked = res.data;
+					}
+				});
+			},
 			changeVolume: function() {
 				let local = this;
 				let volume = $("#volumeSlider").val();
@@ -449,6 +458,7 @@
 							displayName: res.data.displayName,
 							description: res.data.description,
 							privacy: res.data.privacy,
+							locked: res.data.locked,
 							partyMode: res.data.partyMode,
 							owner: res.data.owner,
 							privatePlaylist: res.data.privatePlaylist