Browse Source

Added delete station button on community stations and fixed profile demote/promote button.

KrisVos130 8 years ago
parent
commit
400d1c0a85

+ 24 - 0
backend/logic/actions/users.js

@@ -375,5 +375,29 @@ module.exports = {
 				});
 			}
 		});
+	}),
+
+	/**
+	 * Updates a user's role
+	 *
+	 * @param {Object} session - the session object automatically added by socket.io
+	 * @param {String} updatingUserId - the updating user's id
+	 * @param {String} newRole - the new role
+	 * @param {Function} cb - gets called with the result
+	 * @param {String} userId - the userId automatically added by hooks
+	 */
+	updateRole: hooks.adminRequired((session, updatingUserId, newRole, cb, userId) => {
+		newRole = newRole.toLowerCase();
+		db.models.user.update({_id: updatingUserId}, {$set: {role: newRole}}, (err) => {
+			if (err) {
+				logger.error("UPDATE_ROLE", `Failed updating user. Mongo error. '${err.message}'.`);
+				return cb({ status: 'error', message: 'Something went wrong.' });
+			}
+			logger.error("UPDATE_ROLE", `User '${userId}' updated the role of user '${updatingUserId}' to role '${newRole}'.`);
+			cb({
+				status: 'success',
+				message: 'Role successfully updated.'
+			});
+		});
 	})
 };

+ 9 - 0
frontend/components/Modals/EditStation.vue

@@ -45,6 +45,7 @@
 					<a class='button is-info' @click='updatePartyMode()' href='#'>Update</a>
 				</p>
 			</div>
+			<button class='button is-danger' @click='deleteStation()' v-if="$parent.type === 'community'">Delete station</button>
 		</div>
 	</modal>
 </template>
@@ -100,6 +101,14 @@
 					}
 					Toast.methods.addToast(res.message, 8000);
 				});
+			},
+			deleteStation: function() {
+				this.socket.emit('stations.remove', this.data.stationId, res => {
+					Toast.methods.addToast(res.message, 8000);
+					if (res.status === 'success') {
+						location.href = '/';
+					}
+				});
 			}
 		},
 		ready: function () {

+ 1 - 1
frontend/components/User/Show.vue

@@ -48,7 +48,7 @@
 		},
 		methods: {
 			changeRank(newRank) {
-				this.socket.emit('users.update', this.$route.params.username, 'role', ((newRank == 'admin') ? 'admin' : 'default'), res => {
+				this.socket.emit('users.updateRole', this.user._id, 'role', ((newRank == 'admin') ? 'admin' : 'default'), res => {
 					if (res.status == 'error') Toast.methods.addToast(res.message, 2000);
 					else this.user.role = newRank; Toast.methods.addToast(`User ${this.$route.params.username}'s rank has been changed to: ${newRank}`, 2000);
 				});