26 KiB
LMS Personas — Admin Panel Integration Guide
This guide documents how to integrate the LMS persona catalog into the Rezina admin panel. Personas are coach/character profiles (name, description, avatar, gender) stored centrally and linked to practice shells in Learn English (LMS) and exam-prep via persona_id.
Naming note: This feature is
/api/v1/personas(catalog rows inlms_personas). It is not the same as question-set user personas (/question-sets/:id/personas), which assign real users to a question set for role-play scenarios. Both are covered below; the admin Personas menu usually means the catalog.
Table of contents
- Feature overview
- Architecture
- Authentication & permissions
- RBAC setup & troubleshooting 403
- Data model
- Response envelopes
- Persona catalog API reference
- Linking personas to practices
- Recommended admin UI screens
- TypeScript types & API client
- Question-set user personas (separate feature)
- Error handling
- Integration checklist
- Limitations & future work
- Quick reference
Feature overview
| Capability | Admin panel | Learner app |
|---|---|---|
| Create / edit / delete catalog personas | Yes — /personas CRUD |
No |
| List personas (picker / management) | Yes | Uses practice payload (persona_id resolved server-side) |
| Assign persona to practice | Yes — persona_id on practice create/update |
Sees persona in practice content |
| Upload profile image via persona API | No — URL string only | Displays profile_picture URL |
| Deactivate persona (hide from pickers) | Yes — is_active: false |
Inactive personas excluded when active_only=true |
Default seeded personas (migration 000063)
After migration, three catalog rows are inserted with stable IDs:
| ID | Name | Description |
|---|---|---|
1 |
Friendly Coach | Warm, encouraging tutor for everyday conversational practice. |
2 |
Exam Coach | Structured, exam-style guidance and clear checkpoints. |
3 |
Story Narrator | Story-led scenarios with character-driven prompts. |
Use GET /personas?active_only=false to verify seeds in a new environment.
Architecture
flowchart LR
subgraph AdminPanel["Admin panel"]
PersonaList[Persona list / CRUD]
PersonaForm[Create / edit form]
PracticeEditor[Practice editor persona picker]
end
subgraph API["Rezina API"]
PersonaRoutes["/api/v1/personas CRUD"]
LmsPractice["/api/v1/practices*"]
EpPractice["/api/v1/exam-prep/practices*"]
end
subgraph DB["PostgreSQL"]
PersonasTable["lms_personas"]
LmsPractices["lms_practices.persona_id"]
EpPractices["exam_prep.lesson_practices.persona_id"]
end
PersonaList --> PersonaRoutes
PersonaForm --> PersonaRoutes
PracticeEditor --> PersonaRoutes
PracticeEditor --> LmsPractice
PracticeEditor --> EpPractice
PersonaRoutes --> PersonasTable
LmsPractice --> LmsPractices
EpPractice --> EpPractices
LmsPractices --> PersonasTable
EpPractices --> PersonasTable
- Migrations:
000063_lms_personas— table, seeds, FK onlms_practicesandexam_prep.lesson_practices(ON DELETE SET NULL)000064_lms_personas_profile_picture— renamesavatar_url→profile_picture000065_lms_personas_gender— addsgendercolumn
- Postman:
postman/LMS-Personas.postman_collection.json - Handlers:
internal/web_server/handlers/lms_persona_handler.go - Service:
internal/services/personas/service.go
Routes live at /api/v1/personas (not under /admin/). Staff authenticate with team or platform admin tokens.
Authentication & permissions
All persona catalog endpoints require:
Authorization: Bearer <access_token>
Content-Type: application/json
How to obtain a token
| Login flow | Endpoint | Typical use |
|---|---|---|
| Team member (recommended) | POST /api/v1/team/login |
Admin panel staff |
| Platform admin | POST /api/v1/auth/admin-login |
users.role = ADMIN / SUPER_ADMIN |
RBAC permission keys (catalog)
| Action | Permission | HTTP |
|---|---|---|
| List personas | personas.list |
GET /personas |
| Get one persona | personas.get |
GET /personas/:id |
| Create persona | personas.create |
POST /personas |
| Update persona | personas.update |
PUT /personas/:id |
| Delete persona | personas.delete |
DELETE /personas/:id |
Default role access
| Role | Catalog CRUD |
|---|---|
ADMIN |
Full (middleware bypass) |
SUPER_ADMIN |
Full (bypass) |
INSTRUCTOR |
Full (personas.* in seeds) |
SUPPORT |
Read only (personas.list, personas.get) |
STUDENT / OPEN_LEARNER |
No persona admin permissions by default |
UI gating
- Show Personas menu when user has
personas.list(or isADMIN/SUPER_ADMIN). - Hide create/edit/delete for roles with list/get only.
- Practice editor persona dropdown: call
GET /personas?active_only=true(requirespersonas.list).
RBAC setup & troubleshooting 403
If persona endpoints return 403 Forbidden:
- Decode JWT
Role— confirm staff role (ADMIN,INSTRUCTOR, etc.). - Apply migrations —
SELECT to_regclass('public.lms_personas');must not beNULL. - Sync RBAC:
POST /api/v1/rbac/permissions/sync Authorization: Bearer <admin_token> - Re-login after sync.
- For custom roles, assign
personas.list,personas.create, etc. via RBAC UI.
Data model
Persona object (data in responses)
{
"id": 1,
"name": "Friendly Coach",
"description": "Warm, encouraging tutor for everyday conversational practice.",
"profile_picture": null,
"gender": null,
"is_active": true,
"created_at": "2026-04-01T10:00:00Z",
"updated_at": null
}
| Field | Type | Required | Description |
|---|---|---|---|
id |
int64 | — | Primary key |
name |
string | Yes (create) | Display name; trimmed; cannot be empty on create/update |
description |
string | null | No | Longer bio / coaching style text |
profile_picture |
string | null | No | Image URL (HTTPS or MinIO public URL). Key always present in JSON (null when unset) |
gender |
string | null | No | Free-text label (e.g. female, male). Key always present (null when unset) |
is_active |
boolean | No | Default true on create. Inactive personas hidden when listing with active_only=true |
created_at |
string (time) | — | Server timestamp |
updated_at |
string | null | — | Set on first update |
Create body (CreateLmsPersonaInput)
{
"name": "Business Mentor",
"description": "Formal tone for workplace English.",
"profile_picture": "https://cdn.example.com/personas/business-mentor.png",
"gender": "neutral",
"is_active": true
}
| Field | Validation |
|---|---|
name |
Required, non-empty after trim |
description |
Optional |
profile_picture |
Optional URL string |
gender |
Optional; whitespace-only omitted on create |
is_active |
Optional; defaults to true |
Update body (UpdateLmsPersonaInput)
All fields optional — partial update. Only sent fields change.
{
"name": "Business Mentor (Updated)",
"is_active": false
}
| Behavior | Detail |
|---|---|
Clear gender |
Send "gender": "" (stored as empty string) |
Clear description / profile_picture |
Send "" for that field |
| Omit field | Unchanged |
List payload (data for GET /personas)
{
"personas": [ /* persona objects */ ],
"total_count": 3,
"limit": 20,
"offset": 0
}
Sort order: name ASC, then created_at DESC.
Response envelopes
Success (domain.Response)
{
"message": "Persona created successfully",
"data": { },
"success": true,
"status_code": 201
}
Rely on HTTP status code as source of truth.
Error (domain.ErrorResponse)
{
"message": "Validation failed",
"error": "name is required"
}
Persona catalog API reference
Base path: {API_BASE_URL}/api/v1
1. List personas
GET /personas
Permission: personas.list
Query parameters
| Param | Default | Description |
|---|---|---|
active_only |
true |
Pass false to include inactive personas. Any value other than literal false keeps active-only filter |
limit |
20 |
Page size (max 200 server-side) |
offset |
0 |
Pagination offset |
Example — admin management table (all personas)
GET /api/v1/personas?active_only=false&limit=50&offset=0
Authorization: Bearer <team_access_token>
Example — practice editor dropdown (active only)
GET /api/v1/personas?active_only=true&limit=200&offset=0
Authorization: Bearer <team_access_token>
Response 200
{
"message": "Personas retrieved successfully",
"data": {
"personas": [
{
"id": 1,
"name": "Friendly Coach",
"description": "Warm, encouraging tutor...",
"profile_picture": null,
"gender": null,
"is_active": true,
"created_at": "2026-04-01T10:00:00.000000 +0000 UTC",
"updated_at": null
}
],
"total_count": 3,
"limit": 50,
"offset": 0
},
"success": true,
"status_code": 200
}
2. Get persona by ID
GET /personas/:id
Permission: personas.get
Example
GET /api/v1/personas/1
Authorization: Bearer <team_access_token>
Response 200
Returns single persona in data.
Errors
| HTTP | When |
|---|---|
400 |
Invalid ID |
404 |
Persona not found |
403 |
Missing permission |
3. Create persona
POST /personas
Permission: personas.create
Example
POST /api/v1/personas
Authorization: Bearer <team_access_token>
Content-Type: application/json
{
"name": "Postman Coach",
"description": "Smoke-test persona from admin panel",
"profile_picture": "https://cdn.example.com/personas/postman-coach.png",
"gender": "female",
"is_active": true
}
Response 201
{
"message": "Persona created successfully",
"data": {
"id": 4,
"name": "Postman Coach",
"description": "Smoke-test persona from admin panel",
"profile_picture": "https://cdn.example.com/personas/postman-coach.png",
"gender": "female",
"is_active": true,
"created_at": "...",
"updated_at": null
},
"success": true,
"status_code": 201
}
Errors
| HTTP | When |
|---|---|
400 |
Validation failed / empty name |
403 |
Missing personas.create |
4. Update persona
PUT /personas/:id
Permission: personas.update
Partial update — include only fields to change.
Example — deactivate
PUT /api/v1/personas/4
Authorization: Bearer <team_access_token>
Content-Type: application/json
{
"is_active": false
}
Response 200
{
"message": "Persona updated successfully",
"data": { /* updated persona */ }
}
Errors
| HTTP | When |
|---|---|
400 |
Empty name on update |
404 |
Persona not found |
5. Delete persona
DELETE /personas/:id
Permission: personas.delete
Hard delete from lms_personas.
Database side effect
Foreign keys on practices use ON DELETE SET NULL:
lms_practices.persona_id→ cleared when persona deletedexam_prep.lesson_practices.persona_id→ cleared when persona deleted
Learner-facing practices remain; they simply lose the assigned coach until re-linked.
Example
DELETE /api/v1/personas/4
Authorization: Bearer <team_access_token>
Response 200
{
"message": "Persona deleted successfully",
"success": true,
"status_code": 200
}
Note: Delete currently returns 200 even if the ID does not exist (no row-affected check). Prefer confirming ID via GET first, or refresh the list after delete.
Show a confirmation dialog in the admin UI — deletion affects any practices that referenced this persona.
Linking personas to practices
Personas are not embedded in practice JSON. Practices store persona_id (FK to lms_personas.id).
LMS (Learn English) practices
When creating or updating an LMS practice, set persona_id:
PUT /api/v1/practices/:id
Authorization: Bearer <token>
Content-Type: application/json
{
"persona_id": 1
}
Or on create:
POST /api/v1/practices
Content-Type: application/json
{
"parent_kind": "LESSON",
"parent_id": 42,
"question_set_id": 10,
"persona_id": 2,
"title": "Speaking practice"
}
Clear assignment: send "persona_id": null or omit on update depending on your practice update API semantics (check practice handler — persona_id uses COALESCE on update).
Validation: If persona_id is set to a non-existent catalog ID, practice create/update returns an error (persona not found).
Exam-prep practices
Same field on exam-prep practice endpoints:
PUT /api/v1/exam-prep/practices/:id
Content-Type: application/json
{
"persona_id": 2
}
Permissions: exam_prep.practices.create / exam_prep.practices.update (not personas.* alone).
Admin UI pattern — persona picker
- On practice create/edit screen load:
GET /api/v1/personas?active_only=true&limit=200&offset=0 - Render
<select>or searchable list:{ id, name, profile_picture }. - Save selected
idaspersona_idon practice save. - Optional: show persona preview card using
GET /personas/:id.
Profile picture upload workflow
The persona API accepts a URL string only. Typical admin flow:
- Upload image via your existing asset pipeline (MinIO / media upload used elsewhere in admin).
- Paste resulting public URL into
profile_pictureon create/update.
There is no multipart/form-data upload on POST /personas.
Recommended admin UI screens
1. Persona catalog list
Route: /admin/personas
| Column | Source |
|---|---|
| Avatar | profile_picture thumbnail or placeholder |
| Name | name |
| Gender | gender or "—" |
| Status | Badge: Active / Inactive (is_active) |
| Updated | updated_at |
| Actions | Edit, Delete |
Filters:
- Toggle "Show inactive" →
active_only=false - Pagination via
limit/offsetandtotal_count
Actions:
- New persona → create form →
POST /personas - Edit →
GET /personas/:id+PUT /personas/:id - Deactivate →
PUTwithis_active: false(prefer over delete if practices still reference it) - Delete → confirm modal →
DELETE /personas/:id
┌──────────────────────────────────────────────────────────────┐
│ Personas [+ New persona] │
├──────────────────────────────────────────────────────────────┤
│ [ ] Show inactive │
├──────────────────────────────────────────────────────────────┤
│ Avatar │ Name │ Gender │ Status │ Actions │
│ (img) │ Friendly Coach │ — │ Active │ Edit · Delete │
│ (img) │ Exam Coach │ — │ Active │ Edit · Delete │
├──────────────────────────────────────────────────────────────┤
│ ← Prev Page 1 of 1 Next → │
└──────────────────────────────────────────────────────────────┘
2. Create / edit persona form
| Field | Input type | API field |
|---|---|---|
| Name | Text (required) | name |
| Description | Textarea | description |
| Profile picture | URL input + image preview (optional file upload elsewhere) | profile_picture |
| Gender | Text or select | gender |
| Active | Toggle | is_active |
Validate non-empty name client-side before submit.
3. Practice editor integration
Add Coach / Persona dropdown to LMS and exam-prep practice forms:
- Load options from
GET /personas?active_only=true - Display persona name + thumbnail in dropdown
- Persist
persona_idon practice save - Show warning if selected persona is later deactivated (still linked until admin changes practice)
TypeScript types & API client
Types
export interface LmsPersona {
id: number;
name: string;
description?: string | null;
profile_picture: string | null;
gender: string | null;
is_active: boolean;
created_at: string;
updated_at?: string | null;
}
export interface PersonaListData {
personas: LmsPersona[];
total_count: number;
limit: number;
offset: number;
}
export interface CreatePersonaInput {
name: string;
description?: string | null;
profile_picture?: string | null;
gender?: string | null;
is_active?: boolean;
}
export interface UpdatePersonaInput {
name?: string;
description?: string | null;
profile_picture?: string | null;
gender?: string | null;
is_active?: boolean;
}
export interface ApiResponse<T> {
message: string;
data: T;
success?: boolean;
status_code?: number;
}
export interface ApiError {
message: string;
error?: string;
}
Example client (fetch)
const API_BASE = import.meta.env.VITE_API_BASE_URL;
function authHeaders(token: string): HeadersInit {
return {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};
}
export async function listPersonas(
token: string,
options: { activeOnly?: boolean; limit?: number; offset?: number } = {}
): Promise<PersonaListData> {
const qs = new URLSearchParams({
active_only: String(options.activeOnly !== false),
limit: String(options.limit ?? 20),
offset: String(options.offset ?? 0),
});
const res = await fetch(`${API_BASE}/api/v1/personas?${qs}`, {
headers: authHeaders(token),
});
if (!res.ok) throw await res.json();
const body: ApiResponse<PersonaListData> = await res.json();
return body.data;
}
export async function getPersona(token: string, id: number): Promise<LmsPersona> {
const res = await fetch(`${API_BASE}/api/v1/personas/${id}`, {
headers: authHeaders(token),
});
if (!res.ok) throw await res.json();
const body: ApiResponse<LmsPersona> = await res.json();
return body.data;
}
export async function createPersona(
token: string,
input: CreatePersonaInput
): Promise<LmsPersona> {
const res = await fetch(`${API_BASE}/api/v1/personas`, {
method: "POST",
headers: authHeaders(token),
body: JSON.stringify(input),
});
if (!res.ok) throw await res.json();
const body: ApiResponse<LmsPersona> = await res.json();
return body.data;
}
export async function updatePersona(
token: string,
id: number,
input: UpdatePersonaInput
): Promise<LmsPersona> {
const res = await fetch(`${API_BASE}/api/v1/personas/${id}`, {
method: "PUT",
headers: authHeaders(token),
body: JSON.stringify(input),
});
if (!res.ok) throw await res.json();
const body: ApiResponse<LmsPersona> = await res.json();
return body.data;
}
export async function deletePersona(token: string, id: number): Promise<void> {
const res = await fetch(`${API_BASE}/api/v1/personas/${id}`, {
method: "DELETE",
headers: authHeaders(token),
});
if (!res.ok) throw await res.json();
}
/** Options for practice editor dropdown */
export async function listActivePersonasForPicker(token: string): Promise<LmsPersona[]> {
const data = await listPersonas(token, { activeOnly: true, limit: 200, offset: 0 });
return data.personas;
}
React Query example
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
export function usePersonas(page: number, includeInactive: boolean, token: string) {
const limit = 20;
return useQuery({
queryKey: ["personas", page, includeInactive],
queryFn: () =>
listPersonas(token, {
activeOnly: !includeInactive,
limit,
offset: page * limit,
}),
enabled: !!token,
});
}
export function useCreatePersona(token: string) {
const qc = useQueryClient();
return useMutation({
mutationFn: (input: CreatePersonaInput) => createPersona(token, input),
onSuccess: () => qc.invalidateQueries({ queryKey: ["personas"] }),
});
}
Question-set user personas (separate feature)
Some speaking / role-play question sets assign platform users as dialogue characters. This uses a different table (question_set_personas) and routes under question sets, not the LMS persona catalog.
| Action | Permission | HTTP |
|---|---|---|
| List user personas on set | question_set_personas.list |
GET /question-sets/:setId/personas |
| Add user to set | question_set_personas.add |
POST /question-sets/:setId/personas |
| Remove user from set | question_set_personas.remove |
DELETE /question-sets/:setId/personas/:userId |
Add body
{
"user_id": 1001,
"display_order": 1
}
Response rows include user profile fields (name, email, etc.) for display in question-set authoring UI.
Do not confuse:
| Concept | Table / API | Purpose |
|---|---|---|
| LMS persona catalog | lms_personas, /personas |
Fictional coach/character profile on practice shell |
| Question-set user persona | question_set_personas, /question-sets/:id/personas |
Real user cast for a specific question set |
The admin Personas menu item typically manages the catalog only. Question-set persona assignment belongs on the question set / practice content authoring screen.
Error handling
| HTTP | Typical cause | Admin UI action |
|---|---|---|
400 |
Invalid ID, validation (name required / empty) |
Show field errors from error |
401 |
Missing/expired token | Redirect to login |
403 |
Missing RBAC permission | "No permission" message |
404 |
Persona not found (GET / PUT) |
Toast + redirect to list |
500 |
Server error | Generic error + retry |
Practice save with invalid persona_id
When linking a practice to a deleted or invalid persona ID, the practice API may return 400/404 with persona not found. Refresh the persona picker and re-select.
Empty list
| Scenario | UI |
|---|---|
| Seeds missing (migration not run) | Error state + DevOps note |
All inactive with active_only=true |
"No active personas" + link to show inactive |
| New environment | Prompt to create first persona |
Integration checklist
Backend / access
- Migrations
000063–000065applied - Default personas visible (
GET /personas?active_only=false) - Staff token with
personas.list(+ create/update/delete as needed) - RBAC sync run if permissions missing
Persona catalog screens
- List with pagination (
total_count,limit,offset) - "Show inactive" filter (
active_only=false) - Create form →
POST /personas - Edit form →
GET /personas/:id+PUT /personas/:id - Delete with confirmation →
DELETE /personas/:id - Deactivate via
is_active: falsedocumented for content team
Practice integration
- Persona dropdown on LMS practice create/edit
- Persona dropdown on exam-prep practice create/edit
persona_idsaved on practice payload- Profile picture URL workflow documented for content authors
QA scenarios
- Create persona → appears in list and practice picker
- Deactivate persona → hidden from
active_only=truepicker - Delete persona → practices lose
persona_idbut remain editable - Assign persona to practice → learner practice shows coach (client-dependent)
INSTRUCTORcan CRUD;SUPPORTread-only- Invalid
persona_idon practice rejected with clear error
Limitations & future work
| Topic | Current behavior |
|---|---|
No /admin/personas prefix |
Use /api/v1/personas |
| No image upload on persona API | URL string only |
| Delete idempotency | DELETE returns 200 even if ID missing |
| No soft delete | Hard delete; use is_active: false to retire |
| No usage count API | Cannot show "used by N practices" without custom queries |
| No reorder API | List sorted by name |
| Gender free text | No enum validation |
| Question-set personas | Separate API; not merged into catalog UI |
Legacy question_sets.persona text field |
Old string column on question sets — distinct from persona_id on practices |
Suggested future endpoints
GET /admin/personaswith usage countsPOST /personas/:id/profile-picturemultipart upload- Soft delete / archive flag with restore
GET /personas/:id/practices— reverse lookup
Quick reference
| Method | Path | Permission | Purpose |
|---|---|---|---|
GET |
/api/v1/personas |
personas.list |
List catalog (paginated) |
GET |
/api/v1/personas/:id |
personas.get |
Get one |
POST |
/api/v1/personas |
personas.create |
Create |
PUT |
/api/v1/personas/:id |
personas.update |
Update |
DELETE |
/api/v1/personas/:id |
personas.delete |
Delete (practices SET NULL) |
Practice assignment (LMS)
| Method | Path | Field |
|---|---|---|
POST / PUT |
/api/v1/practices* |
persona_id |
Practice assignment (exam-prep)
| Method | Path | Field |
|---|---|---|
POST / PUT |
/api/v1/exam-prep/practices* |
persona_id |
List for picker
GET /api/v1/personas?active_only=true&limit=200&offset=0
Authorization: Bearer <team_access_token>