-
Notifications
You must be signed in to change notification settings - Fork 0
Unify access-control service API with resource-based methods #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4b2b2f5
Initial plan
Copilot 8cac118
Refactor AccessControlService to use unified resource-based methods
Copilot 7674f4d
Use proper ResourceType enum values in legacy methods
Copilot 103614a
Remove deprecated methods and unused code per review feedback
Copilot af7e961
Use getAssignableUsers endpoint instead of client-side filtering
Copilot 8689d05
feat: toggle visibility of task
TheRealSeber 774f31b
Update src/routes/dashboard/teacher/contests/contests.remote.ts
TheRealSeber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/lib/components/dashboard/admin/tasks/TaskVisibilityToggle.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| <script lang="ts"> | ||
| import { toggleTaskVisibility } from '$routes/dashboard/teacher/tasks/tasks.remote'; | ||
| import { Checkbox } from '$lib/components/ui/checkbox'; | ||
| import { Label } from '$lib/components/ui/label'; | ||
| import { Button } from '$lib/components/ui/button'; | ||
| import * as Dialog from '$lib/components/ui/dialog'; | ||
| import { toast } from 'svelte-sonner'; | ||
| import * as m from '$lib/paraglide/messages'; | ||
|
|
||
| interface TaskVisibilityToggleProps { | ||
| taskId: number; | ||
| taskTitle: string; | ||
| initialVisibility: boolean; | ||
| onToggled: () => void; | ||
| } | ||
|
|
||
| let { taskId, taskTitle, initialVisibility, onToggled }: TaskVisibilityToggleProps = $props(); | ||
|
|
||
| let isVisible = $state(initialVisibility); | ||
| let showConfirmDialog = $state(false); | ||
| let pendingVisibility = $state(false); | ||
| let checkboxKey = $state(0); | ||
|
|
||
| function handleCheckboxChange(checked: boolean) { | ||
| pendingVisibility = checked; | ||
| showConfirmDialog = true; | ||
| } | ||
|
|
||
| async function confirmToggle() { | ||
| try { | ||
| await toggleTaskVisibility({ taskId, isVisible: pendingVisibility }); | ||
| isVisible = pendingVisibility; | ||
| showConfirmDialog = false; | ||
| toast.success( | ||
| pendingVisibility ? m.admin_tasks_visibility_enabled() : m.admin_tasks_visibility_disabled() | ||
| ); | ||
| onToggled(); | ||
| } catch (error) { | ||
| toast.error(m.admin_tasks_visibility_error()); | ||
| console.error('Failed to toggle visibility:', error); | ||
| } | ||
| } | ||
|
|
||
| function cancelToggle() { | ||
| showConfirmDialog = false; | ||
| checkboxKey++; // Force checkbox to re-render with current isVisible value | ||
| } | ||
| </script> | ||
|
|
||
| <div class="flex items-center space-x-2"> | ||
| {#key checkboxKey} | ||
| <Checkbox | ||
| id="visibility-{taskId}" | ||
| checked={isVisible} | ||
| onCheckedChange={handleCheckboxChange} | ||
| class={isVisible ? '' : 'bg-card'} | ||
| /> | ||
| {/key} | ||
| <Label | ||
| for="visibility-{taskId}" | ||
| class="cursor-pointer text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70" | ||
| > | ||
| {m.admin_tasks_card_visible_to_users()} | ||
| </Label> | ||
| </div> | ||
|
|
||
| <Dialog.Root bind:open={showConfirmDialog}> | ||
| <Dialog.Content> | ||
| <Dialog.Header> | ||
| <Dialog.Title>{m.admin_tasks_visibility_confirm_title()}</Dialog.Title> | ||
| <Dialog.Description> | ||
| {pendingVisibility | ||
| ? m.admin_tasks_visibility_confirm_enable({ taskTitle }) | ||
| : m.admin_tasks_visibility_confirm_disable({ taskTitle })} | ||
| </Dialog.Description> | ||
| </Dialog.Header> | ||
| <Dialog.Footer> | ||
| <Button type="button" variant="outline" onclick={cancelToggle}> | ||
| {m.admin_tasks_form_cancel()} | ||
| </Button> | ||
| <Button type="button" onclick={confirmToggle}> | ||
| {m.admin_tasks_visibility_confirm()} | ||
| </Button> | ||
| </Dialog.Footer> | ||
| </Dialog.Content> | ||
| </Dialog.Root> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.