mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 15:51:26 +00:00
Projects become publicly browsable after admin approval; management and secret-adjacent reads (logs, variables, exec, connection URLs) require owner/member/admin auth, and platform controls sit behind RequireAdmin. - Backend: OptionalAuth middleware, read/authed/admin route groups, projects.is_approved + service_templates.owner_id migration, visibility-aware sqlc queries, admin overview/users/approval endpoints, EnsureAdminAccount bootstrap (ADMIN_* env), 30 seeded templates with owner CRUD, managed-database connection URLs gated owner+admin, fix DB.Stats() infinite recursion. - Frontend: expandable persisted sidebar + clickable user menu, public landing page with searchable docs browser (GitHub sync, bundled snapshot + localStorage fallback), DocsBrowser shared with /docs, template create/edit/JSON-upload for owned templates, database create dialog, admin console (stats, approvals, project edit/delete, user admin toggles), HA/Security/Usage polish with dead CSS tokens mapped to real theme vars, anonymous-safe gating on every mutation control. - Tests: safe window.localStorage access fixes happy-dom crashes in PlatformShell and canvas storage. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
135 lines
3.2 KiB
SQL
135 lines
3.2 KiB
SQL
-- name: ListServiceTemplatesForUser :many
|
|
SELECT id, name, description, category, logo, config, variables, is_official, owner_id, created_at, updated_at
|
|
FROM service_templates
|
|
WHERE is_official = true OR owner_id = sqlc.narg(owner_id)
|
|
ORDER BY is_official DESC, name ASC;
|
|
|
|
-- name: ListServiceTemplatesByCategoryForUser :many
|
|
SELECT id, name, description, category, logo, config, variables, is_official, owner_id, created_at, updated_at
|
|
FROM service_templates
|
|
WHERE category = sqlc.arg(category)
|
|
AND (is_official = true OR owner_id = sqlc.narg(owner_id))
|
|
ORDER BY is_official DESC, name ASC;
|
|
|
|
-- name: GetServiceTemplateByID :one
|
|
SELECT id, name, description, category, logo, config, variables, is_official, owner_id, created_at, updated_at
|
|
FROM service_templates
|
|
WHERE id = $1;
|
|
|
|
-- name: UpsertServiceTemplate :exec
|
|
INSERT INTO service_templates (id, name, description, category, logo, config, variables, is_official)
|
|
VALUES (
|
|
sqlc.arg(id),
|
|
sqlc.arg(name),
|
|
sqlc.narg(description),
|
|
sqlc.arg(category),
|
|
sqlc.narg(logo),
|
|
sqlc.arg(config),
|
|
sqlc.narg(variables),
|
|
sqlc.arg(is_official)
|
|
)
|
|
ON CONFLICT (id) DO UPDATE
|
|
SET name = EXCLUDED.name,
|
|
description = EXCLUDED.description,
|
|
category = EXCLUDED.category,
|
|
logo = EXCLUDED.logo,
|
|
config = EXCLUDED.config,
|
|
variables = EXCLUDED.variables,
|
|
is_official = EXCLUDED.is_official,
|
|
updated_at = NOW();
|
|
|
|
-- name: CreateUserTemplate :exec
|
|
INSERT INTO service_templates (id, name, description, category, logo, config, variables, is_official, owner_id)
|
|
VALUES (
|
|
sqlc.arg(id),
|
|
sqlc.arg(name),
|
|
sqlc.narg(description),
|
|
sqlc.arg(category),
|
|
sqlc.narg(logo),
|
|
sqlc.arg(config),
|
|
sqlc.narg(variables),
|
|
false,
|
|
sqlc.arg(owner_id)
|
|
);
|
|
|
|
-- name: UpdateUserTemplate :execrows
|
|
UPDATE service_templates
|
|
SET name = sqlc.arg(name),
|
|
description = sqlc.narg(description),
|
|
category = sqlc.arg(category),
|
|
logo = sqlc.narg(logo),
|
|
config = sqlc.arg(config),
|
|
variables = sqlc.narg(variables),
|
|
updated_at = NOW()
|
|
WHERE id = sqlc.arg(id)
|
|
AND owner_id = sqlc.arg(owner_id)
|
|
AND is_official = false;
|
|
|
|
-- name: DeleteUserTemplate :execrows
|
|
DELETE FROM service_templates
|
|
WHERE id = sqlc.arg(id)
|
|
AND owner_id = sqlc.arg(owner_id)
|
|
AND is_official = false;
|
|
|
|
-- name: GetProjectOwnerID :one
|
|
SELECT owner_id
|
|
FROM projects
|
|
WHERE id = $1;
|
|
|
|
-- name: CountServicesByProjectAndName :one
|
|
SELECT COUNT(*)
|
|
FROM services
|
|
WHERE project_id = $1 AND name = $2;
|
|
|
|
-- name: CreateServiceFromTemplate :exec
|
|
INSERT INTO services (
|
|
id,
|
|
project_id,
|
|
name,
|
|
environment_id,
|
|
service_type,
|
|
source_type,
|
|
source_url,
|
|
image_name,
|
|
build_command,
|
|
start_command,
|
|
type,
|
|
status,
|
|
image,
|
|
command,
|
|
environment,
|
|
cpu,
|
|
memory,
|
|
created_at,
|
|
updated_at
|
|
)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
$11,
|
|
$12,
|
|
$13,
|
|
$14,
|
|
$15,
|
|
$16,
|
|
$17,
|
|
$18,
|
|
$19
|
|
);
|
|
|
|
-- name: UpsertEnvironmentVariable :exec
|
|
INSERT INTO environment_variables (id, service_id, key, value, is_secret, created_at, updated_at)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
ON CONFLICT (service_id, key) DO UPDATE
|
|
SET value = EXCLUDED.value,
|
|
is_secret = EXCLUDED.is_secret,
|
|
updated_at = EXCLUDED.updated_at;
|