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 { getPlaylistsApi } from '@jellyfin/sdk/lib/utils/api/playlists-api';
|
||||||
import escapeHtml from 'escape-html';
|
import escapeHtml from 'escape-html';
|
||||||
|
|
||||||
|
import toast from 'components/toast/toast';
|
||||||
import dom from 'scripts/dom';
|
import dom from 'scripts/dom';
|
||||||
import globalize from 'scripts/globalize';
|
import globalize from 'scripts/globalize';
|
||||||
import { currentSettings as userSettings } from 'scripts/settings/userSettings';
|
import { currentSettings as userSettings } from 'scripts/settings/userSettings';
|
||||||
|
@ -52,12 +53,14 @@ function onSubmit(this: HTMLElement, e: Event) {
|
||||||
addToPlaylist(panel, playlistId)
|
addToPlaylist(panel, playlistId)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error('[PlaylistEditor] Failed to add to playlist %s', playlistId, err);
|
console.error('[PlaylistEditor] Failed to add to playlist %s', playlistId, err);
|
||||||
|
toast(globalize.translate('PlaylistError.AddFailed'));
|
||||||
})
|
})
|
||||||
.finally(loading.hide);
|
.finally(loading.hide);
|
||||||
} else {
|
} else {
|
||||||
createPlaylist(panel)
|
createPlaylist(panel)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error('[PlaylistEditor] Failed to create playlist', err);
|
console.error('[PlaylistEditor] Failed to create playlist', err);
|
||||||
|
toast(globalize.translate('PlaylistError.CreateFailed'));
|
||||||
})
|
})
|
||||||
.finally(loading.hide);
|
.finally(loading.hide);
|
||||||
}
|
}
|
||||||
|
@ -150,6 +153,31 @@ function populatePlaylists(editorOptions: PlaylistEditorOptions, panel: DialogEl
|
||||||
recursive: true
|
recursive: true
|
||||||
})
|
})
|
||||||
.then(({ data }) => {
|
.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 = '';
|
let html = '';
|
||||||
|
|
||||||
if ((editorOptions.enableAddToPlayQueue !== false && playbackManager.isPlaying()) || SyncPlay?.Manager.isSyncPlayEnabled()) {
|
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 += `<option value="">${globalize.translate('OptionNew')}</option>`;
|
||||||
|
|
||||||
html += data.Items?.map(i => {
|
html += playlists.map(({ item, permissions }) => {
|
||||||
return `<option value="${i.Id}">${escapeHtml(i.Name)}</option>`;
|
if (!permissions?.CanEdit) return '';
|
||||||
|
|
||||||
|
return `<option value="${item.Id}">${escapeHtml(item.Name)}</option>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
select.innerHTML = html;
|
select.innerHTML = html;
|
||||||
|
|
|
@ -1263,6 +1263,8 @@
|
||||||
"PlayCount": "Play count",
|
"PlayCount": "Play count",
|
||||||
"Played": "Played",
|
"Played": "Played",
|
||||||
"PlayFromBeginning": "Play from beginning",
|
"PlayFromBeginning": "Play from beginning",
|
||||||
|
"PlaylistError.AddFailed": "Error adding to playlist",
|
||||||
|
"PlaylistError.CreateFailed": "Error creating playlist",
|
||||||
"PlaylistPublic": "Allow public access",
|
"PlaylistPublic": "Allow public access",
|
||||||
"PlaylistPublicDescription": "Allow this playlist to be viewed by any logged in user.",
|
"PlaylistPublicDescription": "Allow this playlist to be viewed by any logged in user.",
|
||||||
"Playlists": "Playlists",
|
"Playlists": "Playlists",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue