Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions sql/auth/user_platform_usernames.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- Create user_platform_usernames table to store user's platform usernames
CREATE TABLE IF NOT EXISTS user_platform_usernames (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
codeforces_username TEXT,
kattis_username TEXT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE(user_id)
);

-- Create RLS policies for user_platform_usernames table
ALTER TABLE user_platform_usernames ENABLE ROW LEVEL SECURITY;

-- Users can read their own platform usernames
CREATE POLICY "Users can read their own platform usernames" ON user_platform_usernames FOR
SELECT USING (auth.uid() = user_id);

-- Users can insert their own platform usernames
CREATE POLICY "Users can insert their own platform usernames" ON user_platform_usernames FOR
INSERT WITH CHECK (auth.uid() = user_id);

-- Users can update their own platform usernames
CREATE POLICY "Users can update their own platform usernames" ON user_platform_usernames FOR
UPDATE USING (auth.uid() = user_id);

-- Users can delete their own platform usernames
CREATE POLICY "Users can delete their own platform usernames" ON user_platform_usernames FOR
DELETE USING (auth.uid() = user_id);

-- Grant access to authenticated users
GRANT ALL ON user_platform_usernames TO authenticated;
1 change: 1 addition & 0 deletions sql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- Authentication and user management
\i auth/user_roles.sql
\i auth/user_triggers.sql
\i auth/user_platform_usernames.sql

-- Problem-related tables and functions
\i problems/problems.sql
Expand Down
38 changes: 30 additions & 8 deletions src/lib/components/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,31 @@ $: if ($page) {
>About</a
>
</li>
{#if $user && isUserAdmin}
{#if $user}
<li
class="relative {$page.url.pathname === '/submit'
class="relative {$page.url.pathname === '/import'
? "after:absolute after:-bottom-2 after:left-0 after:h-0.5 after:w-full after:rounded-sm after:bg-[var(--color-accent)] after:content-['']"
: ''}"
>
<a
href="/submit"
href="/import"
class="block py-2 text-base font-semibold text-[var(--color-heading)] no-underline transition-colors duration-200 hover:text-[var(--color-accent)]"
>Submit</a
>Import</a
>
</li>
{#if isUserAdmin}
<li
class="relative {$page.url.pathname === '/submit'
? "after:absolute after:-bottom-2 after:left-0 after:h-0.5 after:w-full after:rounded-sm after:bg-[var(--color-accent)] after:content-['']"
: ''}"
>
<a
href="/submit"
class="block py-2 text-base font-semibold text-[var(--color-heading)] no-underline transition-colors duration-200 hover:text-[var(--color-accent)]"
>Submit</a
>
</li>
{/if}
{/if}
</ul>
<div
Expand Down Expand Up @@ -291,14 +304,23 @@ $: if ($page) {
>About</a
>
</li>
{#if $user && isUserAdmin}
{#if $user}
<li>
<a
href="/submit"
class="block py-2 text-base font-semibold text-[var(--color-heading)] no-underline transition-colors duration-200 hover:text-[var(--color-accent)] {$page.url.pathname === '/submit' ? 'text-[var(--color-accent)]' : ''}"
>Submit</a
href="/import"
class="block py-2 text-base font-semibold text-[var(--color-heading)] no-underline transition-colors duration-200 hover:text-[var(--color-accent)] {$page.url.pathname === '/import' ? 'text-[var(--color-accent)]' : ''}"
>Import</a
>
</li>
{#if isUserAdmin}
<li>
<a
href="/submit"
class="block py-2 text-base font-semibold text-[var(--color-heading)] no-underline transition-colors duration-200 hover:text-[var(--color-accent)] {$page.url.pathname === '/submit' ? 'text-[var(--color-accent)]' : ''}"
>Submit</a
>
</li>
{/if}
{/if}
</ul>
<div
Expand Down
Loading