Skip to content

Commit

Permalink
Fix video deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
NeKzor committed Jun 15, 2024
1 parent 6796517 commit 9f2df35
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/server/app/assets/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,9 @@ if (location.pathname.startsWith('/videos/') && location.pathname.length === 19)
fetch(`/api/v1${location.pathname}/views`, { method: 'POST' });

initShareModal();
initDeleteModal();
}

initDeleteModal();
initRerenderModal();
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Body, Head } from './App.tsx';
import { AppState } from './AppState.ts';

// NOTE: Always bump this version before deployment when module.js changed.
const jsModuleVersion = '1.0.4';
const jsModuleVersion = '1.0.5';

const isHotReloadEnabled = Deno.env.get('HOT_RELOAD')!.toLowerCase() === 'true';

Expand Down
2 changes: 1 addition & 1 deletion src/server/app/views/NotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const NotFound = ({ resource }: { resource?: string }) => {
{resource ?? 'Page'} not found
</h1>
<p className={tw`mt-4 text-gray-500 dark:text-gray-400`}>
The {resource?.toLowerCase() ?? 'page'} you are looking for does not exist or has been moved.
The {resource?.toLowerCase() ?? 'page'} you are looking for does not exist or has been (re)moved.
</p>
<div className={tw`flex items-center mt-6 gap-x-3`}>
<button
Expand Down
93 changes: 60 additions & 33 deletions src/server/app/views/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,18 @@ export const VideoView = () => {
<div>
Failed to render video
</div>
{isAllowedToRerender &&
(
<div className={tw`mt-4`}>
<div className={tw`flex-wrap mt-3 flex gap-2`}>
{isAllowedToRerender && (
<div>
<button
data-modal-target='rerender-modal'
data-modal-toggle='rerender-modal'
id='video-try-rerender-button'
type='button'
className={tw`flex items-center gap-2 text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800`}
className={tw`flex items-center gap-2 text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-3 py-2 mr-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800`}
>
<svg
className={tw`w-4 h-4 text-gray-800 dark:text-white`}
className={tw`w-[18px] h-[18px] text-gray-800 dark:text-white`}
aria-hidden='true'
xmlns='http://www.w3.org/2000/svg'
fill='none'
Expand All @@ -189,6 +189,35 @@ export const VideoView = () => {
</button>
</div>
)}
{isAllowedToDelete && (
<div>
<button
data-modal-target='delete-modal'
data-modal-toggle='delete-modal'
id='video-delete-button'
type='button'
className={tw`flex items-center gap-2 text-white bg-red-700 hover:bg-red-800 focus:ring-4 focus:ring-red-300 font-medium rounded-lg text-sm px-3 py-2 dark:bg-red-600 dark:hover:bg-red-700 focus:outline-none dark:focus:ring-red-800`}
>
<svg
className={tw`w-[18px] h-[18px] text-white dark:text-white`}
aria-hidden='true'
xmlns='http://www.w3.org/2000/svg'
fill='none'
viewBox='0 0 24 24'
>
<path
stroke='currentColor'
stroke-linecap='round'
stroke-linejoin='round'
stroke-width='2'
d='M5 7h14m-9 3v8m4-8v8M10 3h4a1 1 0 0 1 1 1v3H9V4a1 1 0 0 1 1-1ZM6 7h12v13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V7Z'
/>
</svg>
Delete
</button>
</div>
)}
</div>
</>
)}
{data.pending !== PendingStatus.FinishedRender && (
Expand Down Expand Up @@ -304,35 +333,33 @@ export const VideoView = () => {
</a>
</div>
)}
{hasVideo && (
<div>
<button
data-modal-target='share-modal'
data-modal-toggle='share-modal'
id={`video-share-button-${data.share_id}`}
type='button'
className={tw`video-share-button flex items-center gap-2 text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-3 py-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800`}
<div>
<button
data-modal-target='share-modal'
data-modal-toggle='share-modal'
id={`video-share-button-${data.share_id}`}
type='button'
className={tw`video-share-button flex items-center gap-2 text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-3 py-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800`}
>
<svg
className={tw`w-4 h-4 text-white dark:text-white`}
aria-hidden='true'
xmlns='http://www.w3.org/2000/svg'
fill='none'
viewBox='0 0 18 16'
>
<svg
className={tw`w-4 h-4 text-white dark:text-white`}
aria-hidden='true'
xmlns='http://www.w3.org/2000/svg'
fill='none'
viewBox='0 0 18 16'
>
<path
stroke='currentColor'
stroke-linecap='round'
stroke-linejoin='round'
stroke-width='2'
d='M1.248 15C.22 11.77 2.275 4.232 9.466 4.232V2.079a1.025 1.025 0 0 1 1.644-.862l5.479 4.307a1.108 1.108 0 0 1 0 1.723l-5.48 4.307a1.026 1.026 0 0 1-1.643-.861V8.539C2.275 9.616 1.248 15 1.248 15Z'
/>
</svg>
Share Video
</button>
</div>
)}
{hasVideo && data.pending === PendingStatus.FinishedRender && isAllowedToRerender && (
<path
stroke='currentColor'
stroke-linecap='round'
stroke-linejoin='round'
stroke-width='2'
d='M1.248 15C.22 11.77 2.275 4.232 9.466 4.232V2.079a1.025 1.025 0 0 1 1.644-.862l5.479 4.307a1.108 1.108 0 0 1 0 1.723l-5.48 4.307a1.026 1.026 0 0 1-1.643-.861V8.539C2.275 9.616 1.248 15 1.248 15Z'
/>
</svg>
Share Video
</button>
</div>
{data.pending === PendingStatus.FinishedRender && isAllowedToRerender && (
<div>
<button
data-modal-target='rerender-modal'
Expand Down
2 changes: 1 addition & 1 deletion src/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ apiV1

const authUser = ctx.state.session.get('user')!;

if (video.requested_by_id !== authUser.discord_id || !hasPermission(ctx, UserPermissions.DeleteVideos)) {
if (video.requested_by_id !== authUser.discord_id && !hasPermission(ctx, UserPermissions.DeleteVideos)) {
return Err(ctx, Status.Unauthorized, 'You are not allowed to delete this resource.');
}

Expand Down

0 comments on commit 9f2df35

Please sign in to comment.