diff --git a/backend/src/activitypub/actors/index.ts b/backend/src/activitypub/actors/index.ts index cd89ef5..6a6b324 100644 --- a/backend/src/activitypub/actors/index.ts +++ b/backend/src/activitypub/actors/index.ts @@ -151,7 +151,8 @@ export async function createPerson( db: Database, userKEK: string, email: string, - properties: PersonProperties = {} + properties: PersonProperties = {}, + admin: boolean = false ): Promise { const userKeyPair = await generateUserKey(userKEK) @@ -199,12 +200,12 @@ export async function createPerson( const row = await db .prepare( ` - INSERT INTO actors(id, type, email, pubkey, privkey, privkey_salt, properties) - VALUES(?, ?, ?, ?, ?, ?, ?) + INSERT INTO actors(id, type, email, pubkey, privkey, privkey_salt, properties, is_admin) + VALUES(?, ?, ?, ?, ?, ?, ?, ?) RETURNING * ` ) - .bind(id, PERSON, email, userKeyPair.pubKey, privkey, salt, JSON.stringify(properties)) + .bind(id, PERSON, email, userKeyPair.pubKey, privkey, salt, JSON.stringify(properties), admin ? 1 : null) .first() return personFromRow(row) diff --git a/frontend/mock-db/init.ts b/frontend/mock-db/init.ts index dc97a27..37f852d 100644 --- a/frontend/mock-db/init.ts +++ b/frontend/mock-db/init.ts @@ -7,6 +7,8 @@ import { createReply as createReplyInBackend } from 'wildebeest/backend/test/sha import { createStatus } from 'wildebeest/backend/src/mastodon/status' import type { APObject } from 'wildebeest/backend/src/activitypub/objects' import { type Database } from 'wildebeest/backend/src/database' +import { upsertRule } from 'wildebeest/functions/api/wb/settings/server/rules' +import { upsertServerSettings } from 'wildebeest/functions/api/wb/settings/server/server' /** * Run helper commands to initialize the database with actors, statuses, etc. @@ -41,6 +43,17 @@ export async function init(domain: string, db: Database) { for (const reply of replies) { await createReply(domain, db, reply, loadedStatuses) } + + await createServerData(db) +} + +async function createServerData(db: Database) { + await upsertServerSettings(db, { + 'extended description': 'this is a test wildebeest instance!', + }) + await upsertRule(db, "don't be mean") + await upsertRule(db, "don't insult people") + await upsertRule(db, 'respect the rules') } /** @@ -74,12 +87,21 @@ async function getOrCreatePerson( db: Database, { username, avatar, display_name }: Account ): Promise { - const person = await getPersonByEmail(db, username) + const isAdmin = username === 'george' + const email = `${username}@test.email` + const person = await getPersonByEmail(db, email) if (person) return person - const newPerson = await createPerson(domain, db, 'test-kek', username, { - icon: { url: avatar }, - name: display_name, - }) + const newPerson = await createPerson( + domain, + db, + 'test-kek', + email, + { + icon: { url: avatar }, + name: display_name, + }, + isAdmin + ) if (!newPerson) { throw new Error('Could not create Actor ' + username) } diff --git a/frontend/package.json b/frontend/package.json index dd75947..48d8ceb 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,11 +10,11 @@ "lint": "eslint src mock-db adaptors", "build": "vite build && vite build -c adaptors/cloudflare-pages/vite.config.ts", "dev": "vite --mode ssr", - "watch": "concurrently \"vite build -w\" \"vite build -w -c adaptors/cloudflare-pages/vite.config.ts\"" + "watch": "nodemon -w ./src --ext tsx,ts --exec npm run build" }, "devDependencies": { - "@builder.io/qwik": "0.18.1", - "@builder.io/qwik-city": "0.2.1", + "@builder.io/qwik": "0.19.2", + "@builder.io/qwik-city": "0.4.0", "@types/eslint": "8.4.10", "@types/jest": "^29.2.4", "@types/node": "^18.11.16", @@ -22,12 +22,12 @@ "@typescript-eslint/eslint-plugin": "5.46.1", "@typescript-eslint/parser": "5.46.1", "autoprefixer": "10.4.11", - "concurrently": "^7.6.0", "eslint": "8.30.0", "eslint-plugin-qwik": "0.16.1", "jest": "^29.3.1", "lorem-ipsum": "^2.0.8", "node-fetch": "3.3.0", + "nodemon": "^2.0.20", "postcss": "^8.4.16", "prettier": "2.8.1", "sass": "^1.57.0", diff --git a/frontend/src/components/Settings/TextArea.tsx b/frontend/src/components/Settings/TextArea.tsx new file mode 100644 index 0000000..f83f302 --- /dev/null +++ b/frontend/src/components/Settings/TextArea.tsx @@ -0,0 +1,34 @@ +import { component$, useSignal } from '@builder.io/qwik' + +type Props = { + label: string + name?: string + description?: string + class?: string + invalid?: boolean + value?: string + required?: boolean +} + +export const TextArea = component$( + ({ class: className, label, name, description, invalid, value, required }) => { + const inputId = useSignal(`${label.replace(/\s+/g, '_')}___${crypto.randomUUID()}`).value + return ( +
+ + {!!description &&
{description}
} +