Browse Source

refactor: Continued work on permissions

Owen Diffey 2 years ago
parent
commit
1edebb9328

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

@@ -247,7 +247,7 @@ export default {
 	 * @param cb
 	 */
 	getData: useHasPermission(
-		"users.getData",
+		"users.get",
 		async function getSet(session, page, pageSize, properties, sort, queries, operator, cb) {
 			async.waterfall(
 				[

+ 1 - 0
frontend/src/components/RunJobDropdown.vue

@@ -42,6 +42,7 @@ const runJob = job => {
 
 <template>
 	<tippy
+		v-if="jobs.length > 0"
 		class="runJobDropdown"
 		:touch="true"
 		:interactive="true"

+ 16 - 0
frontend/src/pages/Admin/Songs/Import.vue

@@ -5,6 +5,7 @@ import Toast from "toasters";
 import { useWebsocketsStore } from "@/stores/websockets";
 import { useLongJobsStore } from "@/stores/longJobs";
 import { useModalsStore } from "@/stores/modals";
+import { useUserAuthStore } from "@/stores/userAuth";
 import { TableColumn, TableFilter, TableEvents } from "@/types/advancedTable";
 
 const AdvancedTable = defineAsyncComponent(
@@ -246,6 +247,8 @@ const { openModal } = useModalsStore();
 
 const { setJob } = useLongJobsStore();
 
+const { hasPermission } = useUserAuthStore();
+
 const openAdvancedTable = importJob => {
 	const filter = {
 		appliedFilters: [
@@ -510,6 +513,11 @@ const confirmAction = ({ message, action, params }) => {
 						<template #column-options="slotProps">
 							<div class="row-options">
 								<button
+									v-if="
+										hasPermission(
+											'admin.view.youtubeVideos'
+										)
+									"
 									class="button is-primary icon-with-button material-icons"
 									@click="openAdvancedTable(slotProps.item)"
 									:disabled="
@@ -522,6 +530,7 @@ const confirmAction = ({ message, action, params }) => {
 									table_view
 								</button>
 								<button
+									v-if="hasPermission('songs.update')"
 									class="button is-primary icon-with-button material-icons"
 									@click="
 										editSongs(
@@ -539,6 +548,10 @@ const confirmAction = ({ message, action, params }) => {
 									music_note
 								</button>
 								<button
+									v-if="
+										hasPermission('songs.update') &&
+										hasPermission('apis.searchDiscogs')
+									"
 									class="button icon-with-button material-icons import-album-icon"
 									@click="
 										importAlbum(
@@ -556,6 +569,9 @@ const confirmAction = ({ message, action, params }) => {
 									album
 								</button>
 								<button
+									v-if="
+										hasPermission('media.removeImportJobs')
+									"
 									class="button is-danger icon-with-button material-icons"
 									@click.prevent="
 										confirmAction({

+ 28 - 8
frontend/src/pages/Admin/Songs/index.vue

@@ -5,6 +5,7 @@ import Toast from "toasters";
 import { useWebsocketsStore } from "@/stores/websockets";
 import { useLongJobsStore } from "@/stores/longJobs";
 import { useModalsStore } from "@/stores/modals";
+import { useUserAuthStore } from "@/stores/userAuth";
 import { TableColumn, TableFilter, TableEvents } from "@/types/advancedTable";
 
 const AdvancedTable = defineAsyncComponent(
@@ -29,6 +30,8 @@ const { setJob } = useLongJobsStore();
 
 const { socket } = useWebsocketsStore();
 
+const { hasPermission } = useUserAuthStore();
+
 const columnDefault = ref(<TableColumn>{
 	sortable: true,
 	hidable: true,
@@ -293,16 +296,17 @@ const events = ref(<TableEvents>{
 		id: "songId"
 	}
 });
-const jobs = ref([
-	{
+const jobs = ref([]);
+if (hasPermission("songs.updateAll"))
+	jobs.value.push({
 		name: "Update all songs",
 		socket: "songs.updateAll"
-	},
-	{
+	});
+if (hasPermission("media.recalculateAllRatings"))
+	jobs.value.push({
 		name: "Recalculate all ratings",
 		socket: "media.recalculateAllRatings"
-	}
-]);
+	});
 
 const { openModal } = useModalsStore();
 
@@ -557,6 +561,7 @@ onMounted(() => {
 			<template #column-options="slotProps">
 				<div class="row-options">
 					<button
+						v-if="hasPermission('songs.update')"
 						class="button is-primary icon-with-button material-icons"
 						@click="editOne(slotProps.item)"
 						:disabled="slotProps.item.removed"
@@ -566,7 +571,10 @@ onMounted(() => {
 						edit
 					</button>
 					<quick-confirm
-						v-if="slotProps.item.verified"
+						v-if="
+							hasPermission('songs.verify') &&
+							slotProps.item.verified
+						"
 						@confirm="unverifyOne(slotProps.item._id)"
 					>
 						<button
@@ -579,7 +587,7 @@ onMounted(() => {
 						</button>
 					</quick-confirm>
 					<button
-						v-else
+						v-else-if="hasPermission('songs.verify')"
 						class="button is-success icon-with-button material-icons"
 						@click="verifyOne(slotProps.item._id)"
 						:disabled="slotProps.item.removed"
@@ -589,6 +597,7 @@ onMounted(() => {
 						check_circle
 					</button>
 					<button
+						v-if="hasPermission('songs.remove')"
 						class="button is-danger icon-with-button material-icons"
 						@click.prevent="
 							confirmAction({
@@ -685,6 +694,7 @@ onMounted(() => {
 			<template #bulk-actions="slotProps">
 				<div class="bulk-actions">
 					<i
+						v-if="hasPermission('songs.update')"
 						class="material-icons edit-songs-icon"
 						@click.prevent="editMany(slotProps.item)"
 						content="Edit Songs"
@@ -694,6 +704,7 @@ onMounted(() => {
 						edit
 					</i>
 					<i
+						v-if="hasPermission('songs.verify')"
 						class="material-icons verify-songs-icon"
 						@click.prevent="verifyMany(slotProps.item)"
 						content="Verify Songs"
@@ -703,6 +714,7 @@ onMounted(() => {
 						check_circle
 					</i>
 					<quick-confirm
+						v-if="hasPermission('songs.verify')"
 						placement="left"
 						@confirm="unverifyMany(slotProps.item)"
 						tabindex="0"
@@ -716,6 +728,10 @@ onMounted(() => {
 						</i>
 					</quick-confirm>
 					<i
+						v-if="
+							hasPermission('songs.update') &&
+							hasPermission('apis.searchDiscogs')
+						"
 						class="material-icons import-album-icon"
 						@click.prevent="importAlbum(slotProps.item)"
 						content="Import Album"
@@ -725,6 +741,7 @@ onMounted(() => {
 						album
 					</i>
 					<i
+						v-if="hasPermission('songs.update')"
 						class="material-icons tag-songs-icon"
 						@click.prevent="setTags(slotProps.item)"
 						content="Set Tags"
@@ -734,6 +751,7 @@ onMounted(() => {
 						local_offer
 					</i>
 					<i
+						v-if="hasPermission('songs.update')"
 						class="material-icons artists-songs-icon"
 						@click.prevent="setArtists(slotProps.item)"
 						content="Set Artists"
@@ -743,6 +761,7 @@ onMounted(() => {
 						group
 					</i>
 					<i
+						v-if="hasPermission('songs.update')"
 						class="material-icons genres-songs-icon"
 						@click.prevent="setGenres(slotProps.item)"
 						content="Set Genres"
@@ -752,6 +771,7 @@ onMounted(() => {
 						theater_comedy
 					</i>
 					<i
+						v-if="hasPermission('songs.remove')"
 						class="material-icons delete-icon"
 						@click.prevent="
 							confirmAction({

+ 8 - 2
frontend/src/pages/Admin/Users/DataRequests.vue

@@ -2,6 +2,7 @@
 import { defineAsyncComponent, ref } from "vue";
 import Toast from "toasters";
 import { useWebsocketsStore } from "@/stores/websockets";
+import { useUserAuthStore } from "@/stores/userAuth";
 import { TableColumn, TableFilter, TableEvents } from "@/types/advancedTable";
 
 const AdvancedTable = defineAsyncComponent(
@@ -88,6 +89,8 @@ const events = ref(<TableEvents>{
 	}
 });
 
+const { hasPermission } = useUserAuthStore();
+
 const resolveDataRequest = (id, resolved) => {
 	socket.dispatch("dataRequests.resolve", id, resolved, res => {
 		if (res.status === "success") new Toast(res.message);
@@ -116,7 +119,10 @@ const resolveDataRequest = (id, resolved) => {
 			<template #column-options="slotProps">
 				<div class="row-options">
 					<button
-						v-if="slotProps.item.resolved"
+						v-if="
+							hasPermission('dataRequests.resolve') &&
+							slotProps.item.resolved
+						"
 						class="button is-danger material-icons icon-with-button"
 						@click="resolveDataRequest(slotProps.item._id, false)"
 						:disabled="slotProps.item.removed"
@@ -126,7 +132,7 @@ const resolveDataRequest = (id, resolved) => {
 						remove_done
 					</button>
 					<button
-						v-else
+						v-else-if="hasPermission('dataRequests.resolve')"
 						class="button is-success material-icons icon-with-button"
 						@click="resolveDataRequest(slotProps.item._id, true)"
 						:disabled="slotProps.item.removed"

+ 4 - 0
frontend/src/pages/Admin/Users/index.vue

@@ -2,6 +2,7 @@
 import { defineAsyncComponent, ref, onMounted } from "vue";
 import { useRoute } from "vue-router";
 import { useModalsStore } from "@/stores/modals";
+import { useUserAuthStore } from "@/stores/userAuth";
 import { TableColumn, TableFilter, TableEvents } from "@/types/advancedTable";
 
 const AdvancedTable = defineAsyncComponent(
@@ -199,6 +200,8 @@ const events = ref(<TableEvents>{
 
 const { openModal } = useModalsStore();
 
+const { hasPermission } = useUserAuthStore();
+
 const edit = userId => {
 	openModal({ modal: "editUser", data: { userId } });
 };
@@ -229,6 +232,7 @@ onMounted(() => {
 			<template #column-options="slotProps">
 				<div class="row-options">
 					<button
+						v-if="hasPermission('users.update')"
 						class="button is-primary icon-with-button material-icons"
 						@click="edit(slotProps.item._id)"
 						:disabled="slotProps.item.removed"