Giao diện
Database Schema
ER Diagram
Bảng users — chi tiết tất cả field
| Field | Type | Ràng buộc | Mặc định | Mô tả |
|---|---|---|---|---|
id | bigInt | PK, autoIncrement, NOT NULL | — | ID duy nhất của user |
displayname | string | — | — | Tên hiển thị. Là titleField của collection |
username | string | UNIQUE | — | Tên đăng nhập. Validator: username: true |
email | string | UNIQUE | — | Email. Validator: email |
phone | string | UNIQUE | — | Số điện thoại |
password | password | hidden: true | — | Mật khẩu, hash bằng bcrypt. Không bao giờ trả về qua API (bị desensitize() loại bỏ) |
passwordChangeTz | bigInt | — | — | Timestamp (ms) lần đổi password gần nhất. Được set tự động trong hook beforeUpdate |
appLang | string | — | — | Mã ngôn ngữ giao diện (vd: vi-VN, en-US) |
resetToken | string | UNIQUE, hidden: true | — | Token dùng cho reset password. Không trả về qua API |
systemSettings | json | — | {} | Object JSON lưu cài đặt cá nhân của user |
createdAt | date | — | auto | Thời điểm tạo user (interface createdAt) |
updatedAt | date | — | auto | Thời điểm cập nhật gần nhất (interface updatedAt) |
createdById | bigInt | FK → users.id, INDEX | auto | ID người tạo (auto-inject, createOnly) |
updatedById | bigInt | FK → users.id, INDEX | auto | ID người cập nhật gần nhất (auto-inject) |
Thuộc tính collection
| Thuộc tính | Giá trị | Ý nghĩa |
|---|---|---|
model | UserModel | Sử dụng model tùy chỉnh với desensitize() |
titleField | displayname | Field hiển thị khi dùng làm relation label |
sortable | sort | Hỗ trợ sắp xếp tùy chỉnh |
createdBy | true | Tự động thêm field createdBy |
updatedBy | true | Tự động thêm field updatedBy |
logging | true | Ghi log thay đổi |
shared | true | Collection dùng chung giữa các data source |
Field ẩn (hidden)
Hai field có hidden: true sẽ bị desensitize() loại ra khỏi response:
password— mật khẩu đã hashresetToken— token reset password
Điều này đảm bảo dù admin gọi users:list hay users:get, các field nhạy cảm không bao giờ xuất hiện trong response.
Mở rộng bảng systemSettings
Plugin sử dụng extendCollection để thêm 2 field boolean vào bảng systemSettings có sẵn:
| Field | Type | Mặc định | Mô tả |
|---|---|---|---|
enableEditProfile | boolean | true | Cho phép user tự sửa profile qua updateProfile. Khi false, server trả 403 |
enableChangePassword | boolean | true | Cho phép user tự đổi mật khẩu. Dùng bởi client để ẩn/hiện form đổi mật khẩu |
Hai field này được quản lý qua API users:getSystemSettings và users:updateSystemSettings.
Auto-inject createdBy/updatedBy cho collection khác
Khi bất kỳ collection nào trong hệ thống được định nghĩa với createdBy: true hoặc updatedBy: true, plugin tự động thêm:
| Field inject | Type | Target | Hành vi |
|---|---|---|---|
createdById | context (bigInt) | — | Lấy từ state.currentUser.id, chỉ ghi khi tạo (createOnly) |
createdBy | belongsTo | users | Relation đến users, foreignKey = createdById, label = displayname |
updatedById | context (bigInt) | — | Lấy từ state.currentUser.id, cập nhật mỗi lần sửa |
updatedBy | belongsTo | users | Relation đến users, foreignKey = updatedById, label = displayname |
Tất cả field inject đều có index: true để tối ưu query.