Skip to content
Merged
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
28 changes: 1 addition & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,14 @@ export function calculateMarketPrice(
return Math.round(-m * shopScoreRemainder + maxPrice);
}
}

export function getProjectLinkType(
editorFileType: string | null,
editorUrl: string | null,
uploadedFileUrl: string | null
): string {
if (editorFileType === 'url' && editorUrl?.includes('cad.onshape.com')) return 'onshape';
if (editorFileType === 'url' && editorUrl?.includes('autodesk360.com')) return 'fusion-link';
if (editorFileType === 'upload' && uploadedFileUrl?.endsWith('.f3d')) return 'fusion-file';
return 'unknown';
}
44 changes: 44 additions & 0 deletions src/routes/dashboard/admin/admin/users/[id]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,50 @@ export const actions = {
};
},

changeTrust: async ({ locals, request, params }) => {
if (!locals.user) {
throw error(500);
}
if (!locals.user.hasAdmin) {
throw error(403, { message: 'oi get out' });
}

const id: number = parseInt(params.id);

const data = await request.formData();
const trust = data.get('trust');

if (!trust || !['green', 'blue', 'yellow', 'red'].includes(trust.toString())) {
return fail(400, {
changeTrust: {
invalidTrust: true
}
});
}

// Log out user if trust is set to red
if (trust === 'red') {
await db.delete(session).where(eq(session.userId, id));
}

await db
.update(user)
.set({
trust: trust.toString() as 'green' | 'blue' | 'yellow' | 'red'
})
.where(eq(user.id, id));

const [queriedUser] = await db.select().from(user).where(eq(user.id, id));

if (!queriedUser) {
throw error(404, { message: 'user not found' });
}

return {
queriedUser
};
},

impersonate: async (event) => {
const { locals, params } = event;

Expand Down
32 changes: 32 additions & 0 deletions src/routes/dashboard/admin/admin/users/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
let impersonatePending = $state(false);
let logoutPending = $state(false);
let fetchPIIPending = $state(false);
let changeTrustPending = $state(false);
</script>

<Head title={'User: ' + user.name} />
Expand Down Expand Up @@ -239,6 +240,37 @@
</form>
</div>

<h2 class="mt-2 text-2xl font-bold">Trust Level</h2>
<div class="themed-box flex flex-col gap-3 p-3 shadow-lg">
<form
action="?/changeTrust"
method="POST"
use:enhance={() => {
changeTrustPending = true;
return async ({ update }) => {
await update({ reset: false });
changeTrustPending = false;
};
}}
>
<label class="flex flex-col gap-1">
<span class="text-sm font-medium">User Trust Level</span>
<select name="trust" value={user.trust} class="themed-input-on-box text-sm" required>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="yellow">Yellow</option>
<option value="red">Red</option>
</select>
</label>
{#if form?.changeTrust?.invalidTrust}
<p class="w-full text-center text-sm">Invalid trust level</p>
{/if}
<button type="submit" class="button md primary mt-3 w-full" disabled={changeTrustPending}
>Apply!</button
>
</form>
</div>

<h2 class="mt-2 text-2xl font-bold">yummy stuff</h2>
<div class="mb-5">
{#if form?.fetchPII?.success}
Expand Down
Loading
Loading