RezinaLMS-BackEnd/docs/demo-and-public-catalog.md

150 lines
7.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Public discovery and pre-production demo
## Browse without signing in
Public discovery is intended for customer-facing web and mobile learning apps.
The admin panel is a staff application: signed-out visitors to `/` are redirected
to `/login`, and signed-in staff go to their role's default management page.
The admin panel does not host customer catalog pages or use anonymous catalog APIs
for content management. Its course, chapter, lesson, and quiz tools continue to
use authenticated `/api/v1/admin` endpoints.
Anonymous APIs:
| Endpoint | Result |
| --- | --- |
| `GET /api/v1/catalog/courses?q=&limit=20&offset=0` | Searchable published course highlights, access tiers, chapter/lesson/quiz counts and pagination |
| `GET /api/v1/catalog/courses/:id` | Published course outline with chapter descriptions, lesson highlights, and quiz titles/question counts |
These endpoints accept no authentication requirement and never expand their
visibility for staff tokens. Draft courses return 404; draft chapters, lessons,
quiz shells and question sets are excluded. Public DTOs contain no video URLs,
questions, correct answers, author identities, or learner progress. Playback,
question delivery, and completion remain behind the existing learning endpoints
and their authentication/subscription rules. Previewing a premium lesson does not
grant access to it.
### Client app integration
Use the backend's public API base (for example `https://api.example.com/api/v1`)
in the customer app, without the `/admin` suffix. No bearer token is required.
Render course highlights from the list response and load the course outline
when a visitor selects a course. For browser requests, omit staff credentials:
```javascript
const apiBase = "https://api.example.com/api/v1";
const response = await fetch(`${apiBase}/catalog/courses?limit=20&offset=0`, {
credentials: "omit",
});
if (!response.ok) throw new Error("Unable to load course highlights");
const { data } = await response.json();
// data.courses, data.total_count, data.limit, data.offset
```
Use `GET /catalog/courses/{id}` on the same base for the published outline.
Customer apps should offer their own learner sign-in flow when visitors choose
to start learning; authenticated playback, quiz, and progress APIs enforce access.
## Install the demo fixture
Apply database migrations through `000003_chapters_and_quizzes`, then run from
the backend directory:
```powershell
go run ./cmd/demo-seed -environment development
```
The command reads `DB_URL` from the environment or the backend `.env`. It needs
only PostgreSQL; it does not start the application or require payment, email,
SMS, or storage provider credentials. `-environment` must explicitly be
`development`, `test`, or `staging`. `APP_ENV`, `ENVIRONMENT`, or `GO_ENV` set to
`production`/`prod` prevents seeding.
For the repository's Docker PostgreSQL:
```powershell
docker compose up -d postgres
docker compose run --rm migrate
$env:DB_URL = 'postgresql://root:secret@localhost:5592/gh?sslmode=disable'
go run ./cmd/demo-seed -environment development
```
The Docker host mapping is `5592:5432`. Use your actual database credentials when
connecting to another development or staging database. A Docker app image also
contains `/app/bin/demo-seed` for explicitly running the same command; it never
runs automatically on application startup. Do not use the older broad
`db/data`/`db/dev_data` scripts for this new hierarchy fixture.
Optional settings:
| Variable | Default / purpose |
| --- | --- |
| `DEMO_SEED_PASSWORD` | `RezinaDemo!2026`; set a custom password of 12–72 bytes for every demo account |
| `DEMO_VIDEO_URL` | Public Big Buck Bunny sample clip for testing playback; replace with your own media URL for realistic lesson videos |
| `DEMO_TEST_DB_URL` | Disposable, fully migrated PostgreSQL database used only by the opt-in integration test |
The supplied videos are playback fixtures, not instructional recordings for the
lesson subjects. A local SVG course cover is included in the backend image.
## Demo accounts
All accounts use **`RezinaDemo!2026`** unless `DEMO_SEED_PASSWORD` is set.
| Email | Role | Login endpoint | Expected access |
| --- | --- | --- | --- |
| `superadmin@demo.rezina.test` | `SUPER_ADMIN` | `POST /api/v1/admin/team/login` | Full staff permissions, including team invitations |
| `admin@demo.rezina.test` | `ADMIN` | `POST /api/v1/admin/team/login` | Administrative permissions under existing role rules |
| `contentmanager@demo.rezina.test` | `CONTENT_MANAGER` | `POST /api/v1/admin/team/login` | Content management permissions and restricted admin navigation |
| `student@demo.rezina.test` | `STUDENT` | `POST /api/v1/auth/customer-login` | Unsubscribed learner; verifies premium restrictions |
| `premium@demo.rezina.test` | `STUDENT` | `POST /api/v1/auth/customer-login` | 30-day Education subscription, refreshed on seed rerun |
| `openlearner@demo.rezina.test` | `OPEN_LEARNER` | `POST /api/v1/auth/customer-login` | Existing unrestricted learner access rules |
Both login endpoints accept `{"email":"...","password":"..."}`. Staff sign in
through the admin web app. Customer accounts use the customer API or learning
app; they do not sign in through the staff form. Accounts are active, email
verified, and use bcrypt password hashes compatible with the real login paths.
No email delivery or invitation acceptance is required for these fixtures.
These cover all currently assignable staff roles and both customer learner roles.
Legacy names such as Instructor, Support Agent, Finance, HR, and Analyst are not
seeded as team accounts: the current database and team service allow only Super
Admin, Admin, and Content Manager. The seeder does not change role restrictions
or grant every role administrator permissions. Standard RBAC seeds are applied;
restart a running backend after seeding so its permission cache reloads.
## Included learning data and reruns
- Everyday English: 2 chapters, 6 lessons, 2 quizzes; free course.
- Workplace Communication: 2 chapters, 6 lessons, 2 quizzes; premium course.
- Digital Skills Essentials: 2 chapters, 6 lessons, 2 quizzes; free course.
- Each quiz contains 3 published multiple-choice questions with correct answers.
- One unpublished course verifies that public discovery hides drafts.
- One inactive demo subscription plan provides the premium test account access
without appearing as a purchasable production plan.
The fixture runs in one transaction under an advisory lock. It uses generated
IDs and the `demo_seed_entities` ownership map rather than fixed IDs or table
truncation. Reruns reuse existing content, preserve edits to it, reset the six
demo account passwords/statuses to the configured test credentials, and refresh
the seed-owned premium subscription. Existing unrelated accounts and learning
content are not deleted. Keep these fixtures in a separate pre-production
database; this command is not part of production migration or startup.
## Verification
```powershell
go test ./internal/demoseed ./internal/services/examprep ./internal/web_server/... ./internal/apidocs/...
```
For the database-backed seed and catalog test, use a disposable migrated database:
```powershell
$env:DEMO_TEST_DB_URL = '<disposable migrated PostgreSQL URL>'
go test ./internal/demoseed -run TestDemoSeedAndPublicCatalogIntegration -count=1 -v
```
That test writes demo data, runs the seed twice, checks login password hashes,
and verifies unpublished-course/descendant filtering. It is skipped unless
`DEMO_TEST_DB_URL` is explicitly provided and never reads application `DB_URL`.
In `RezinaLMS-Admin`, run `npm run test:learning` and `npm run build`.