2024-04-04 22:20:42 +00:00
|
|
|
import { useAuthorization, useKoelPlus } from '@/composables'
|
|
|
|
import { arrayify } from '@/utils'
|
|
|
|
|
|
|
|
export const usePolicies = () => {
|
|
|
|
const { currentUser, isAdmin } = useAuthorization()
|
|
|
|
const { isPlus } = useKoelPlus()
|
|
|
|
|
|
|
|
const currentUserCan = {
|
2024-06-02 17:15:31 +00:00
|
|
|
editSong: (songs: MaybeArray<Song>) => {
|
2024-10-13 17:37:01 +00:00
|
|
|
if (isAdmin.value) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (!isPlus.value) {
|
|
|
|
return false
|
|
|
|
}
|
2024-06-02 17:15:31 +00:00
|
|
|
return arrayify(songs).every(song => song.owner_id === currentUser.value.id)
|
2024-04-04 22:20:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
editPlaylist: (playlist: Playlist) => playlist.user_id === currentUser.value.id,
|
|
|
|
uploadSongs: () => isAdmin.value || isPlus.value,
|
2024-10-13 17:37:01 +00:00
|
|
|
changeAlbumOrArtistThumbnails: () => isAdmin.value || isPlus.value, // for Plus, the logic is handled in the backend
|
2024-04-04 22:20:42 +00:00
|
|
|
}
|
|
|
|
|
2024-10-13 17:37:01 +00:00
|
|
|
currentUserCan.editSongs = currentUserCan.editSong
|
2024-04-04 22:20:42 +00:00
|
|
|
|
|
|
|
return {
|
2024-10-13 17:37:01 +00:00
|
|
|
currentUserCan,
|
2024-04-04 22:20:42 +00:00
|
|
|
}
|
|
|
|
}
|