mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Add permission check for removing playlist item
This commit is contained in:
parent
3e62933461
commit
6c226ba59f
2 changed files with 57 additions and 28 deletions
|
@ -280,11 +280,11 @@ export function getCommands(options) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.PlaylistItemId && options.playlistId) {
|
if (item.PlaylistItemId && options.playlistId && options.canEditPlaylist) {
|
||||||
commands.push({
|
commands.push({
|
||||||
name: globalize.translate('RemoveFromPlaylist'),
|
name: globalize.translate('RemoveFromPlaylist'),
|
||||||
id: 'removefromplaylist',
|
id: 'removefromplaylist',
|
||||||
icon: 'remove'
|
icon: 'playlist_remove'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ export function getCommands(options) {
|
||||||
commands.push({
|
commands.push({
|
||||||
name: globalize.translate('RemoveFromCollection'),
|
name: globalize.translate('RemoveFromCollection'),
|
||||||
id: 'removefromcollection',
|
id: 'removefromcollection',
|
||||||
icon: 'remove'
|
icon: 'playlist_remove'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,6 +696,6 @@ export function show(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getCommands: getCommands,
|
getCommands,
|
||||||
show: show
|
show
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* Module shortcuts.
|
* Module shortcuts.
|
||||||
* @module components/shortcuts
|
* @module components/shortcuts
|
||||||
*/
|
*/
|
||||||
|
import { getPlaylistsApi } from '@jellyfin/sdk/lib/utils/api/playlists-api';
|
||||||
|
|
||||||
import { playbackManager } from './playback/playbackmanager';
|
import { playbackManager } from './playback/playbackmanager';
|
||||||
import inputManager from '../scripts/inputManager';
|
import inputManager from '../scripts/inputManager';
|
||||||
|
@ -12,6 +13,7 @@ import recordingHelper from './recordingcreator/recordinghelper';
|
||||||
import ServerConnections from './ServerConnections';
|
import ServerConnections from './ServerConnections';
|
||||||
import toast from './toast/toast';
|
import toast from './toast/toast';
|
||||||
import * as userSettings from '../scripts/settings/userSettings';
|
import * as userSettings from '../scripts/settings/userSettings';
|
||||||
|
import { toApi } from 'utils/jellyfin-apiclient/compat';
|
||||||
|
|
||||||
function playAllFromHere(card, serverId, queue) {
|
function playAllFromHere(card, serverId, queue) {
|
||||||
const parent = card.parentNode;
|
const parent = card.parentNode;
|
||||||
|
@ -100,7 +102,7 @@ function notifyRefreshNeeded(childElement, itemsContainer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showContextMenu(card, options) {
|
function showContextMenu(card, options = {}) {
|
||||||
getItem(card).then(item => {
|
getItem(card).then(item => {
|
||||||
const playlistId = card.getAttribute('data-playlistid');
|
const playlistId = card.getAttribute('data-playlistid');
|
||||||
const collectionId = card.getAttribute('data-collectionid');
|
const collectionId = card.getAttribute('data-collectionid');
|
||||||
|
@ -110,28 +112,55 @@ function showContextMenu(card, options) {
|
||||||
item.PlaylistItemId = elem ? elem.getAttribute('data-playlistitemid') : null;
|
item.PlaylistItemId = elem ? elem.getAttribute('data-playlistitemid') : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
import('./itemContextMenu').then((itemContextMenu) => {
|
const apiClient = ServerConnections.getApiClient(item.ServerId);
|
||||||
ServerConnections.getApiClient(item.ServerId).getCurrentUser().then(user => {
|
const api = toApi(apiClient);
|
||||||
itemContextMenu.show(Object.assign({
|
|
||||||
item: item,
|
Promise.all([
|
||||||
|
// Import the item menu component
|
||||||
|
import('./itemContextMenu'),
|
||||||
|
// Fetch the current user
|
||||||
|
apiClient.getCurrentUser(),
|
||||||
|
// Fetch playlist perms if item is a child of a playlist
|
||||||
|
playlistId ?
|
||||||
|
getPlaylistsApi(api)
|
||||||
|
.getPlaylistUser({
|
||||||
|
playlistId,
|
||||||
|
userId: apiClient.getCurrentUserId()
|
||||||
|
})
|
||||||
|
.then(({ data }) => data)
|
||||||
|
.catch(() => {
|
||||||
|
// If a user doesn't have access, then the request will 404 and throw
|
||||||
|
return { CanEdit: false };
|
||||||
|
}) :
|
||||||
|
// Not a playlist item
|
||||||
|
Promise.resolve({ CanEdit: false })
|
||||||
|
])
|
||||||
|
.then(([
|
||||||
|
itemContextMenu,
|
||||||
|
user,
|
||||||
|
playlistPerms
|
||||||
|
]) => {
|
||||||
|
return itemContextMenu.show({
|
||||||
|
item,
|
||||||
play: true,
|
play: true,
|
||||||
queue: true,
|
queue: true,
|
||||||
playAllFromHere: item.Type === 'Season' || !item.IsFolder,
|
playAllFromHere: item.Type === 'Season' || !item.IsFolder,
|
||||||
queueAllFromHere: !item.IsFolder,
|
queueAllFromHere: !item.IsFolder,
|
||||||
playlistId: playlistId,
|
playlistId,
|
||||||
collectionId: collectionId,
|
canEditPlaylist: !!playlistPerms.CanEdit,
|
||||||
user: user
|
collectionId,
|
||||||
}, options || {}))
|
user,
|
||||||
.then(result => {
|
...options
|
||||||
if (result.command === 'playallfromhere' || result.command === 'queueallfromhere') {
|
});
|
||||||
executeAction(card, options.positionTo, result.command);
|
})
|
||||||
} else if (result.updated || result.deleted) {
|
.then(result => {
|
||||||
notifyRefreshNeeded(card, options.itemsContainer);
|
if (result.command === 'playallfromhere' || result.command === 'queueallfromhere') {
|
||||||
}
|
executeAction(card, options.positionTo, result.command);
|
||||||
})
|
} else if (result.updated || result.deleted) {
|
||||||
.catch(() => { /* no-op */ });
|
notifyRefreshNeeded(card, options.itemsContainer);
|
||||||
});
|
}
|
||||||
});
|
})
|
||||||
|
.catch(() => { /* no-op */ });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,8 +435,8 @@ export function getShortcutAttributesHtml(item, serverId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
on: on,
|
on,
|
||||||
off: off,
|
off,
|
||||||
onClick: onClick,
|
onClick,
|
||||||
getShortcutAttributesHtml: getShortcutAttributesHtml
|
getShortcutAttributesHtml
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue