Add authenticated content editing
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
fac7588d23
commit
fd2877da9e
15 changed files with 581 additions and 37 deletions
|
|
@ -80,9 +80,10 @@ func main() {
|
|||
repository.NewSessionRepository(adminDB),
|
||||
cfg.SessionTTL,
|
||||
)
|
||||
content := service.NewContentService(repository.NewContentRepository(applicationDB), auth)
|
||||
google := identity.GoogleProvider{ClientID: cfg.GoogleClientID, ClientSecret: cfg.GoogleClientSecret, RedirectURL: cfg.GoogleRedirectURL}
|
||||
log.Printf("CMS listening on %s", cfg.HTTPAddr)
|
||||
if err = http.ListenAndServe(cfg.HTTPAddr, web.NewHandler(auth, google).Routes(cfg.AllowedOrigins)); err != nil {
|
||||
if err = http.ListenAndServe(cfg.HTTPAddr, web.NewHandlerWithContent(auth, google, content).Routes(cfg.AllowedOrigins)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
32
cmd/server/migrations/postgres/002_content.sql
Normal file
32
cmd/server/migrations/postgres/002_content.sql
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
-- +goose Up
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS role TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS editor BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
CREATE TABLE IF NOT EXISTS content (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
slug TEXT NOT NULL UNIQUE,
|
||||
title TEXT NOT NULL,
|
||||
summary TEXT NOT NULL DEFAULT '',
|
||||
body TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'draft',
|
||||
published BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL,
|
||||
created_by BIGINT REFERENCES users(id),
|
||||
updated_by BIGINT REFERENCES users(id)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_content_updated_at ON content(updated_at DESC, created_at DESC, id DESC);
|
||||
CREATE TABLE IF NOT EXISTS content_history (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
content_id BIGINT NOT NULL REFERENCES content(id) ON DELETE CASCADE,
|
||||
operation TEXT NOT NULL,
|
||||
actor_id BIGINT REFERENCES users(id),
|
||||
actor_admin_id BIGINT,
|
||||
created_at TIMESTAMPTZ NOT NULL,
|
||||
snapshot JSONB NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_content_history_content_id ON content_history(content_id, created_at DESC);
|
||||
-- +goose Down
|
||||
DROP TABLE IF EXISTS content_history;
|
||||
DROP TABLE IF EXISTS content;
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS editor;
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS role;
|
||||
Loading…
Add table
Add a link
Reference in a new issue