-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from Open-Model-Initiative/73-user-is-active-t…
…oggling Add user is_active toggling to the admin dashboard
- Loading branch information
Showing
11 changed files
with
141 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
52 changes: 52 additions & 0 deletions
52
...s/odr_datamodel/alembic/versions/e06f931c3c84_update_users_table_to_have_non_nullable_.py
This file contains 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,52 @@ | ||
"""'Update users table to have non nullable and default values for flags' | ||
Revision ID: e06f931c3c84 | ||
Revises: 6917b71d9140 | ||
Create Date: 2024-10-03 18:14:20.255813 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'e06f931c3c84' | ||
down_revision: Union[str, None] = '6917b71d9140' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('users', 'is_active', | ||
existing_type=sa.BOOLEAN(), | ||
nullable=False, | ||
server_default=sa.text('true')) | ||
op.alter_column('users', 'is_superuser', | ||
existing_type=sa.BOOLEAN(), | ||
nullable=False, | ||
server_default=sa.text('false')) | ||
op.alter_column('users', 'dco_accepted', | ||
existing_type=sa.BOOLEAN(), | ||
nullable=False, | ||
server_default=sa.text('false')) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('users', 'dco_accepted', | ||
existing_type=sa.BOOLEAN(), | ||
nullable=True, | ||
server_default=sa.text('false')) | ||
op.alter_column('users', 'is_superuser', | ||
existing_type=sa.BOOLEAN(), | ||
nullable=True, | ||
server_default=sa.text('false')) | ||
op.alter_column('users', 'is_active', | ||
existing_type=sa.BOOLEAN(), | ||
nullable=True, | ||
server_default=sa.text('true')) | ||
# ### end Alembic commands ### |
This file contains 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 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,14 @@ | ||
<script lang="ts"> | ||
import type { IDBUser } from '$lib/server/pg'; | ||
import { SlideToggle } from '@skeletonlabs/skeleton'; | ||
import { toggleActive } from './utils'; | ||
export let checked: boolean = false; | ||
export let user: IDBUser; | ||
function _toggleActive(e: Event) { | ||
toggleActive(user); | ||
} | ||
</script> | ||
|
||
<SlideToggle name="slide" bind:checked on:change={_toggleActive} /> |
This file contains 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 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 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
<th>id</th> | ||
<th>name</th> | ||
<th>isSuperUser?</th> | ||
<th>isActive?</th> | ||
<th>email</th> | ||
</tr> | ||
</thead> | ||
|
This file contains 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
22 changes: 22 additions & 0 deletions
22
modules/odr_frontend/src/routes/admin/users/api/toggleActive/+server.ts
This file contains 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,22 @@ | ||
import { pgClient, type IDBUser } from '$lib/server/pg'; | ||
import type { RequestHandler } from '@sveltejs/kit'; | ||
export const PUT: RequestHandler = async ({ request }) => { | ||
const body = await request.json(); | ||
if (!body.user) { | ||
return new Response(JSON.stringify({ success: false, error: 'No user provided' })); | ||
} | ||
const user: IDBUser = body.user; | ||
try { | ||
const result = await pgClient.query('UPDATE users SET is_active=$1 WHERE id=$2', [ | ||
user.is_active, | ||
user.id | ||
]); | ||
console.info(`Set user ${user.id} as ${user.is_active ? 'active' : 'not active'}`); | ||
return new Response(JSON.stringify({ success: true, result: result })); | ||
} catch (e) { | ||
console.error( | ||
`Failed to set user ${user.id} as ${user.is_active ? 'active' : 'not active'}` | ||
); | ||
return new Response(JSON.stringify({ success: false, error: e })); | ||
} | ||
}; |
File renamed without changes.
This file contains 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,29 @@ | ||
<svelte:head> | ||
<title>Inactive User | OMI Data Pipeline</title> | ||
</svelte:head> | ||
|
||
<div class="flex flex-col overflow-y-auto"> | ||
<main class="container mx-auto p-4"> | ||
|
||
<h1 class="text-3xl font-bold mb-4">Inactive User</h1> | ||
|
||
<p> | ||
Your user account is inactive. If you believe this is in error, please reach out in our | ||
<a href="https://discord.gg/vANKjzDDkQ" | ||
class="underline" | ||
target="_blank" | ||
rel="noopener noreferrer"> | ||
Discord | ||
</a> | ||
for support. | ||
</p> | ||
|
||
</main> | ||
</div> | ||
|
||
<style> | ||
.container { | ||
max-width: 800px; | ||
padding-bottom: 2rem; | ||
} | ||
</style> |