-
Notifications
You must be signed in to change notification settings - Fork 0
Reworked page authorization to use locals/hooks #24
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| let { tournamentName, teams, rounds } = data; | ||
| let selectedMatch: db.MatchWithTeams | undefined = undefined; | ||
|
|
||
| function onDrop(updatedTeams: db.TeamWithMembers[]) { | ||
| function onDrop(updatedTeams: db.TeamWithMembersAndMatches[]) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine, but in the future please isolate any changes like this to direct commits to the main branch, or a "General Improvements" branch with a list of the improvements you made.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's difficult to tell but this is just a random type safety error fix, and I agree a general improvements branch would be a good idea. |
||
| teams = updatedTeams; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,8 @@ import { error } from '@sveltejs/kit'; | |
| import type { LayoutServerLoad } from './$types'; | ||
| import { StatusCodes } from '$lib/StatusCodes'; | ||
|
|
||
| export const load: LayoutServerLoad = async ({ params, parent }) => { | ||
| const { tournament, user } = await parent(); | ||
| export const load: LayoutServerLoad = async ({ params, parent, locals }) => { | ||
| const { tournament } = await parent(); | ||
|
|
||
| // Retrieve team from tournament and params | ||
| const team = tournament.Teams.find((team) => team.id === parseInt(params.team_id)); | ||
|
|
@@ -17,8 +17,8 @@ export const load: LayoutServerLoad = async ({ params, parent }) => { | |
|
|
||
| // Team captains have a member_order of 0 | ||
| const isTeamCaptain = team.Members.some( | ||
| (member) => member.osuId === user?.id && member.member_order === 0 | ||
| (member) => member.osuId === locals.user?.id && member.member_order === 0 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This bit actually faces the opposite problem:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still can't find explicit documentation saying it runs on every request but all my testing shows that bost
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ); | ||
|
|
||
| return { tournament, user, team, isTeamCaptain }; | ||
| return { team, isTeamCaptain }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,21 +4,17 @@ | |
| import InvitePlayer from '$lib/components/tournament-page/team-page/InvitePlayer.svelte'; | ||
| import TournamentPageTemplate from '$lib/components/tournament-page/TournamentPageTemplate.svelte'; | ||
| import MatchList from '$lib/components/common/MatchList.svelte'; | ||
| import type { PageServerData, ActionData, LayoutServerData } from './$types'; | ||
| import type { PageServerData, ActionData, LayoutServerData, LayoutData } from './$types'; | ||
| import EditPageSetting from '$lib/components/tournament-page/edit-page/EditPageSetting.svelte'; | ||
|
|
||
| export let data: PageServerData & LayoutServerData; | ||
| export let data: PageServerData & LayoutServerData & LayoutData; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you use
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't know that, thanks. |
||
| export let form: ActionData; | ||
| let { tournament, team, isTeamCaptain } = data; | ||
| let { tournament, team, isTeamCaptain, sessionUserTeam } = data; | ||
| let { team_size: maxTeamSize } = tournament; | ||
| let { name, Members, color, InBracketMatches } = team; | ||
|
|
||
| let inTeam: boolean = false; | ||
| function updateInTeam(memberId: number) { | ||
| if (memberId == data.user?.id) { | ||
| inTeam = true; | ||
| } | ||
| return ''; | ||
| } | ||
| // Check if this team is the current user's team | ||
| let inTeam: boolean = (team.id == sessionUserTeam?.id); | ||
| </script> | ||
|
|
||
| <svelte:head> | ||
|
|
@@ -32,19 +28,18 @@ | |
|
|
||
| <section class="team_header"> | ||
| <h1> | ||
| {tournament.team_size == 1 ? 'Player: ' : 'Team: '} | ||
| {maxTeamSize == 1 ? 'Player: ' : 'Team: '} | ||
| {team.name} | ||
| </h1> | ||
| </section> | ||
|
|
||
| <section class="players"> | ||
| {#if tournament.team_size != 1} | ||
| {#if maxTeamSize != 1} | ||
| <h1>Players</h1> | ||
| {/if} | ||
| <div class="player_cards"> | ||
| {#each Members as member} | ||
| <User user={member.User} {color} /> | ||
| {updateInTeam(member.User.id)} | ||
| {/each} | ||
| </div> | ||
| {#if inTeam && !isTeamCaptain} | ||
|
|
@@ -62,13 +57,15 @@ | |
| <h1>Team Settings</h1> | ||
|
|
||
| <form id="team_settings" method="POST" action="?/update_team"> | ||
| <EditPageSetting | ||
| name="name" | ||
| label="Team Name" | ||
| value={name} | ||
| errors={form?.messages} | ||
| type="text" | ||
| /> | ||
| {#if maxTeamSize != 1} | ||
| <EditPageSetting | ||
| name="name" | ||
| label="Team Name" | ||
| value={name} | ||
| errors={form?.messages} | ||
| type="text" | ||
| /> | ||
| {/if} | ||
| <EditPageSetting | ||
| name="color" | ||
| label="Team Color" | ||
|
|
@@ -92,11 +89,11 @@ | |
| {/if} | ||
| </section> | ||
|
|
||
| {#if tournament.team_size != 1 && tournament.allow_registrations} | ||
| {#if maxTeamSize != 1 && tournament.allow_registrations} | ||
| <section class="invites"> | ||
| <h1>Team Invites</h1> | ||
|
|
||
| {#if team.Members.length < tournament.team_size} | ||
| {#if team.Members.length < maxTeamSize} | ||
| <InvitePlayer {data} {form} /> | ||
| {:else} | ||
| <p>Your team is full. You can't invite anymore players.</p> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example of what I was talking about in the initial review comment:
This does not fix the problem of "authorization being in layout files", because the
ifstatement that determines whether the user is able to access the site or not still exists in the layout.