mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Add permission check for reordering playlist items
This commit is contained in:
parent
99bbd814f4
commit
3e62933461
1 changed files with 42 additions and 17 deletions
|
@ -1,48 +1,73 @@
|
||||||
import listView from '../components/listview/listview';
|
import { getPlaylistsApi } from '@jellyfin/sdk/lib/utils/api/playlists-api';
|
||||||
|
|
||||||
function getFetchPlaylistItemsFn(itemId) {
|
import ServerConnections from 'components/ServerConnections';
|
||||||
|
import listView from 'components/listview/listview';
|
||||||
|
import { toApi } from 'utils/jellyfin-apiclient/compat';
|
||||||
|
|
||||||
|
function getFetchPlaylistItemsFn(apiClient, itemId) {
|
||||||
return function () {
|
return function () {
|
||||||
const query = {
|
const query = {
|
||||||
Fields: 'PrimaryImageAspectRatio',
|
Fields: 'PrimaryImageAspectRatio',
|
||||||
EnableImageTypes: 'Primary,Backdrop,Banner,Thumb',
|
EnableImageTypes: 'Primary,Backdrop,Banner,Thumb',
|
||||||
UserId: ApiClient.getCurrentUserId()
|
UserId: apiClient.getCurrentUserId()
|
||||||
};
|
};
|
||||||
return ApiClient.getJSON(ApiClient.getUrl(`Playlists/${itemId}/Items`, query));
|
return apiClient.getJSON(apiClient.getUrl(`Playlists/${itemId}/Items`, query));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getItemsHtmlFn(itemId) {
|
function getItemsHtmlFn(playlistId, isEditable = false) {
|
||||||
return function (items) {
|
return function (items) {
|
||||||
return listView.getListViewHtml({
|
return listView.getListViewHtml({
|
||||||
items: items,
|
items,
|
||||||
showIndex: false,
|
showIndex: false,
|
||||||
showRemoveFromPlaylist: true,
|
|
||||||
playFromHere: true,
|
playFromHere: true,
|
||||||
action: 'playallfromhere',
|
action: 'playallfromhere',
|
||||||
smallIcon: true,
|
smallIcon: true,
|
||||||
dragHandle: true,
|
dragHandle: isEditable,
|
||||||
playlistId: itemId
|
playlistId
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(page, item) {
|
async function init(page, item) {
|
||||||
|
const apiClient = ServerConnections.getApiClient(item.ServerId);
|
||||||
|
const api = toApi(apiClient);
|
||||||
|
|
||||||
|
let isEditable = false;
|
||||||
|
const { data } = await getPlaylistsApi(api)
|
||||||
|
.getPlaylistUser({
|
||||||
|
playlistId: item.Id,
|
||||||
|
userId: apiClient.getCurrentUserId()
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
// If a user doesn't have access, then the request will 404 and throw
|
||||||
|
return { data: {} };
|
||||||
|
});
|
||||||
|
isEditable = !!data.CanEdit;
|
||||||
|
|
||||||
const elem = page.querySelector('#childrenContent .itemsContainer');
|
const elem = page.querySelector('#childrenContent .itemsContainer');
|
||||||
elem.classList.add('vertical-list');
|
elem.classList.add('vertical-list');
|
||||||
elem.classList.remove('vertical-wrap');
|
elem.classList.remove('vertical-wrap');
|
||||||
elem.enableDragReordering(true);
|
elem.enableDragReordering(isEditable);
|
||||||
elem.fetchData = getFetchPlaylistItemsFn(item.Id);
|
elem.fetchData = getFetchPlaylistItemsFn(apiClient, item.Id);
|
||||||
elem.getItemsHtml = getItemsHtmlFn(item.Id);
|
elem.getItemsHtml = getItemsHtmlFn(item.Id, isEditable);
|
||||||
|
}
|
||||||
|
|
||||||
|
function refresh(page) {
|
||||||
|
page.querySelector('#childrenContent').classList.add('verticalSection-extrabottompadding');
|
||||||
|
page.querySelector('#childrenContent .itemsContainer').refreshItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
function render(page, item) {
|
function render(page, item) {
|
||||||
if (!page.playlistInit) {
|
if (!page.playlistInit) {
|
||||||
page.playlistInit = true;
|
page.playlistInit = true;
|
||||||
init(page, item);
|
init(page, item)
|
||||||
|
.finally(() => {
|
||||||
|
refresh(page);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
refresh(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
page.querySelector('#childrenContent').classList.add('verticalSection-extrabottompadding');
|
|
||||||
page.querySelector('#childrenContent .itemsContainer').refreshItems();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const PlaylistViewer = {
|
const PlaylistViewer = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue