mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #5453 from thornbill/playlist-access-checks
Add permission check to playlist editor
This commit is contained in:
commit
7700f15fd9
2 changed files with 34 additions and 2 deletions
|
@ -4,6 +4,7 @@ import { getItemsApi } from '@jellyfin/sdk/lib/utils/api/items-api';
|
|||
import { getPlaylistsApi } from '@jellyfin/sdk/lib/utils/api/playlists-api';
|
||||
import escapeHtml from 'escape-html';
|
||||
|
||||
import toast from 'components/toast/toast';
|
||||
import dom from 'scripts/dom';
|
||||
import globalize from 'scripts/globalize';
|
||||
import { currentSettings as userSettings } from 'scripts/settings/userSettings';
|
||||
|
@ -52,12 +53,14 @@ function onSubmit(this: HTMLElement, e: Event) {
|
|||
addToPlaylist(panel, playlistId)
|
||||
.catch(err => {
|
||||
console.error('[PlaylistEditor] Failed to add to playlist %s', playlistId, err);
|
||||
toast(globalize.translate('PlaylistError.AddFailed'));
|
||||
})
|
||||
.finally(loading.hide);
|
||||
} else {
|
||||
createPlaylist(panel)
|
||||
.catch(err => {
|
||||
console.error('[PlaylistEditor] Failed to create playlist', err);
|
||||
toast(globalize.translate('PlaylistError.CreateFailed'));
|
||||
})
|
||||
.finally(loading.hide);
|
||||
}
|
||||
|
@ -150,6 +153,31 @@ function populatePlaylists(editorOptions: PlaylistEditorOptions, panel: DialogEl
|
|||
recursive: true
|
||||
})
|
||||
.then(({ data }) => {
|
||||
return Promise.all((data.Items || []).map(item => {
|
||||
const playlist = {
|
||||
item,
|
||||
permissions: undefined
|
||||
};
|
||||
|
||||
if (!item.Id) return playlist;
|
||||
|
||||
return getPlaylistsApi(api)
|
||||
.getPlaylistUser({
|
||||
playlistId: item.Id,
|
||||
userId: apiClient.getCurrentUserId()
|
||||
})
|
||||
.then(({ data: permissions }) => ({
|
||||
...playlist,
|
||||
permissions
|
||||
}))
|
||||
.catch((err) => {
|
||||
console.warn('[PlaylistEditor] Failed to fetch playlist permissions', err);
|
||||
|
||||
return playlist;
|
||||
});
|
||||
}));
|
||||
})
|
||||
.then(playlists => {
|
||||
let html = '';
|
||||
|
||||
if ((editorOptions.enableAddToPlayQueue !== false && playbackManager.isPlaying()) || SyncPlay?.Manager.isSyncPlayEnabled()) {
|
||||
|
@ -158,8 +186,10 @@ function populatePlaylists(editorOptions: PlaylistEditorOptions, panel: DialogEl
|
|||
|
||||
html += `<option value="">${globalize.translate('OptionNew')}</option>`;
|
||||
|
||||
html += data.Items?.map(i => {
|
||||
return `<option value="${i.Id}">${escapeHtml(i.Name)}</option>`;
|
||||
html += playlists.map(({ item, permissions }) => {
|
||||
if (!permissions?.CanEdit) return '';
|
||||
|
||||
return `<option value="${item.Id}">${escapeHtml(item.Name)}</option>`;
|
||||
});
|
||||
|
||||
select.innerHTML = html;
|
||||
|
|
|
@ -1263,6 +1263,8 @@
|
|||
"PlayCount": "Play count",
|
||||
"Played": "Played",
|
||||
"PlayFromBeginning": "Play from beginning",
|
||||
"PlaylistError.AddFailed": "Error adding to playlist",
|
||||
"PlaylistError.CreateFailed": "Error creating playlist",
|
||||
"PlaylistPublic": "Allow public access",
|
||||
"PlaylistPublicDescription": "Allow this playlist to be viewed by any logged in user.",
|
||||
"Playlists": "Playlists",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue