@fui-org/fui-cli 1.3.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -3
- package/dist/fui-cx180e19.js +379 -0
- package/dist/fui.js +1 -1
- package/package.json +3 -6
- package/skills/fui/SKILL.md +9 -41
- package/skills/fui-skill/SKILL.md +95 -225
- package/skills/fui-skill/assets/projectdefaultstyle-3.0.css +555 -0
- package/skills/fui-skill/assets/projectdefaultstyle.css +207 -235
- package/skills/fui-skill/references/INDEX.md +105 -137
- package/skills/fui-skill/references/advanced-techniques.md +76 -68
- package/skills/fui-skill/references/coding-standards.md +56 -56
- package/skills/fui-skill/references/component-design.md +166 -173
- package/skills/fui-skill/references/component-quickref.md +61 -60
- package/skills/fui-skill/references/component-table.md +128 -117
- package/skills/fui-skill/references/components-dialog.md +55 -56
- package/skills/fui-skill/references/components-display.md +24 -30
- package/skills/fui-skill/references/components-echart.md +186 -261
- package/skills/fui-skill/references/components-input.md +72 -96
- package/skills/fui-skill/references/controls-patterns.md +196 -342
- package/skills/fui-skill/references/controls-styling-vocabulary.md +130 -97
- package/skills/fui-skill/references/db-table-design.md +24 -28
- package/skills/fui-skill/references/db-workflow.md +191 -390
- package/skills/fui-skill/references/default-function.md +169 -128
- package/skills/fui-skill/references/design-modes.md +35 -63
- package/skills/fui-skill/references/echart-templates.md +204 -196
- package/skills/fui-skill/references/fastproject.md +62 -60
- package/skills/fui-skill/references/fsheet.md +109 -124
- package/skills/fui-skill/references/fullstack-workflow.md +90 -128
- package/skills/fui-skill/references/module-data-patterns.md +31 -40
- package/skills/fui-skill/references/module-json-anatomy.md +47 -52
- package/skills/fui-skill/references/module-structure.md +80 -196
- package/skills/fui-skill/references/new-session.md +49 -51
- package/skills/fui-skill/references/pdfmake.md +17 -17
- package/skills/fui-skill/references/permission-system.md +89 -108
- package/skills/fui-skill/references/platform-architecture.md +128 -153
- package/skills/fui-skill/references/project-config.md +102 -134
- package/skills/fui-skill/references/project-provisioning.md +139 -244
- package/skills/fui-skill/references/script-map.md +208 -242
- package/skills/fui-skill/references/sql-clr-functions.md +98 -97
- package/skills/fui-skill/references/system-design.md +63 -88
- package/skills/fui-skill/references/tapi-file-api.md +46 -52
- package/skills/fui-skill/references/tapi-permission-patterns.md +51 -53
- package/skills/fui-skill/references/tapi-reference.md +132 -207
- package/skills/fui-skill/references/tools-registry.md +84 -460
- package/skills/fui-skill/references/ui-crosswindow-patterns.md +79 -75
- package/skills/fui-skill/references/ui-dialog-patterns.md +98 -72
- package/skills/fui-skill/references/ui-layout-patterns.md +26 -26
- package/skills/fui-skill/references/ui-patterns.md +71 -83
- package/skills/fui-skill/references/ui-screenshot-review.md +63 -62
- package/skills/fui-skill/references/ui-table-cell-patterns.md +61 -59
- package/skills/fui-skill/references/ui-templates.md +16 -23
- package/skills/fui-skill/references/verification.md +236 -246
- package/skills/fui-skill/references/watcher-patterns.md +30 -63
- package/skills/fui-skill/references/websocket-realtime.md +83 -66
- package/skills/fui-skill/scripts/component-3.0.js +298 -131
- package/skills/fui-skill/scripts/component.js +277 -271
- package/skills/fui-skill/scripts/componentTable-3.0.js +182 -53
- package/skills/fui-skill/scripts/componentTable.js +171 -49
- package/skills/fui-skill/scripts/defaultfunction-3.0.js +88 -3
- package/skills/fui-skill/scripts/defaultfunction.js +88 -3
- package/skills/fui-skill/scripts/fsheet.js +38 -0
- package/skills/fui-target/.claude-plugin/plugin.json +6 -0
- package/skills/fui-target/hooks/hooks.json +1 -0
- package/skills/fui-target/hooks/register.tsx +71 -0
- package/skills/fui-target/types/index.d.ts +7 -0
- package/dist/fui-y8an39cn.js +0 -420
- package/skills/fui-skill/README.md +0 -112
- package/skills/fui-skill/metadata.json +0 -75
- package/skills/fui-skill-cli/SKILL.md +0 -139
- package/skills/fui-skill-cli/references/INDEX.md +0 -110
- package/skills/fui-skill-cli/references/advanced-techniques.md +0 -168
- package/skills/fui-skill-cli/references/coding-standards.md +0 -112
- package/skills/fui-skill-cli/references/component-design.md +0 -448
- package/skills/fui-skill-cli/references/component-quickref.md +0 -78
- package/skills/fui-skill-cli/references/component-table.md +0 -248
- package/skills/fui-skill-cli/references/components-dialog.md +0 -191
- package/skills/fui-skill-cli/references/components-display.md +0 -141
- package/skills/fui-skill-cli/references/components-echart.md +0 -316
- package/skills/fui-skill-cli/references/components-input.md +0 -335
- package/skills/fui-skill-cli/references/controls-patterns.md +0 -701
- package/skills/fui-skill-cli/references/controls-styling-vocabulary.md +0 -137
- package/skills/fui-skill-cli/references/db-table-design.md +0 -73
- package/skills/fui-skill-cli/references/db-workflow.md +0 -288
- package/skills/fui-skill-cli/references/default-function.md +0 -425
- package/skills/fui-skill-cli/references/design-modes.md +0 -57
- package/skills/fui-skill-cli/references/echart-templates.md +0 -489
- package/skills/fui-skill-cli/references/fastproject.md +0 -99
- package/skills/fui-skill-cli/references/fsheet.md +0 -203
- package/skills/fui-skill-cli/references/fullstack-workflow.md +0 -313
- package/skills/fui-skill-cli/references/module-data-patterns.md +0 -117
- package/skills/fui-skill-cli/references/module-json-anatomy.md +0 -132
- package/skills/fui-skill-cli/references/module-structure.md +0 -141
- package/skills/fui-skill-cli/references/new-session.md +0 -85
- package/skills/fui-skill-cli/references/pdfmake.md +0 -60
- package/skills/fui-skill-cli/references/permission-system.md +0 -150
- package/skills/fui-skill-cli/references/platform-architecture.md +0 -269
- package/skills/fui-skill-cli/references/project-config.md +0 -303
- package/skills/fui-skill-cli/references/project-provisioning.md +0 -278
- package/skills/fui-skill-cli/references/script-map.md +0 -262
- package/skills/fui-skill-cli/references/sql-clr-functions.md +0 -225
- package/skills/fui-skill-cli/references/system-design.md +0 -89
- package/skills/fui-skill-cli/references/tapi-file-api.md +0 -185
- package/skills/fui-skill-cli/references/tapi-permission-patterns.md +0 -156
- package/skills/fui-skill-cli/references/tapi-reference.md +0 -474
- package/skills/fui-skill-cli/references/tools-registry.md +0 -84
- package/skills/fui-skill-cli/references/ui-crosswindow-patterns.md +0 -321
- package/skills/fui-skill-cli/references/ui-dialog-patterns.md +0 -255
- package/skills/fui-skill-cli/references/ui-layout-patterns.md +0 -176
- package/skills/fui-skill-cli/references/ui-patterns.md +0 -303
- package/skills/fui-skill-cli/references/ui-screenshot-review.md +0 -95
- package/skills/fui-skill-cli/references/ui-table-cell-patterns.md +0 -318
- package/skills/fui-skill-cli/references/ui-templates.md +0 -22
- package/skills/fui-skill-cli/references/verification.md +0 -236
- package/skills/fui-skill-cli/references/watcher-patterns.md +0 -163
- package/skills/fui-skill-cli/references/websocket-realtime.md +0 -271
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
# tAPI — File API (GET / UPLOAD)
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
SP GET và UPLOAD file qua tAPI: prefix `spAPIFILE_`, cột binary alias `fileContent`, params `@sys_FileContent`/`@sys_FileName`, bảng chuẩn `tblFileData`. Load file này khi module cần upload/download/xem file. **Không tự suy từ training data** — tAPI có quy ước riêng.
|
|
6
|
-
|
|
7
|
-
> Nền tảng SP (naming, params, response): xem [tapi-reference.md](tapi-reference.md).
|
|
3
|
+
> Owns: **file APIs via SP: `spAPIFILE_*`, `tblFileData`, alias `fileContent`, `@sys_FileContent`/`@sys_FileName`**. Load when a module needs upload/download/view of files. **Never infer from training data** — tAPI has its own conventions. SP basics (naming, params, response): [tapi-reference.md](tapi-reference.md).
|
|
8
4
|
|
|
9
5
|
---
|
|
10
6
|
|
|
11
7
|
## GET file
|
|
12
8
|
|
|
13
|
-
SP
|
|
9
|
+
SP must SELECT **at least 3 required columns** (extra metadata columns allowed):
|
|
14
10
|
|
|
15
|
-
|
|
|
16
|
-
|
|
17
|
-
| `FileName`
|
|
18
|
-
| `ContentType` | ✅
|
|
19
|
-
| `fileContent` | ✅
|
|
20
|
-
|
|
|
11
|
+
| Column | Required | Meaning |
|
|
12
|
+
| ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| `FileName` | ✅ | Returned file name — may be an expression, e.g. `FileName + FileType` |
|
|
14
|
+
| `ContentType` | ✅ | MIME type (e.g. `application/pdf`, `image/png`) |
|
|
15
|
+
| `fileContent` | ✅ | Binary content — alias of an **`image` or `varbinary`** column. tAPI detects the file content to stream by this data type |
|
|
16
|
+
| other columns | ❌ | Optional metadata, e.g. `Modified`, `FileSize` — must be normal (non-binary) types |
|
|
21
17
|
|
|
22
18
|
```sql
|
|
23
19
|
-- Ví dụ thực tế: FileName ghép đuôi, thêm cột Modified, binary aliased từ FileContentBIN
|
|
@@ -34,17 +30,17 @@ AS BEGIN
|
|
|
34
30
|
END
|
|
35
31
|
```
|
|
36
32
|
|
|
37
|
-
> `fileContent`
|
|
38
|
-
> `FileName`
|
|
33
|
+
> `fileContent` must alias an `image` or `varbinary(max)` column — tAPI uses the type to detect and stream the file. Table column name is free (`FileContentBIN`, `BinaryContent`, ...).
|
|
34
|
+
> `FileName` should include the extension (`.pdf`, `.xlsx`...) so the browser detects the type.
|
|
39
35
|
|
|
40
|
-
**
|
|
36
|
+
**URL params — `@fileID` and `@filename`:**
|
|
41
37
|
|
|
42
|
-
| Param
|
|
43
|
-
|
|
44
|
-
| `@fileID varchar(...)`
|
|
45
|
-
| `@filename varchar(...)` | ❌
|
|
38
|
+
| Param | Required | Source | Meaning |
|
|
39
|
+
| ------------------------ | -------- | -------------------------------- | ------------------------------------------------------------------------------------ |
|
|
40
|
+
| `@fileID varchar(...)` | ✅ | First segment after FunctionName | ID of the file |
|
|
41
|
+
| `@filename varchar(...)` | ❌ | LAST URL segment | Display file name in the URL (browser/download manager uses it to name the download) |
|
|
46
42
|
|
|
47
|
-
|
|
43
|
+
Extra `@sys_*` auth params may be declared for permission checks.
|
|
48
44
|
|
|
49
45
|
```sql
|
|
50
46
|
CREATE PROCEDURE spAPIFILE_Document
|
|
@@ -57,7 +53,7 @@ AS BEGIN
|
|
|
57
53
|
END
|
|
58
54
|
```
|
|
59
55
|
|
|
60
|
-
**4
|
|
56
|
+
**4 supported routes:**
|
|
61
57
|
|
|
62
58
|
```
|
|
63
59
|
{domain}/{apiName}/{FunctionName}/{fileID}
|
|
@@ -66,25 +62,23 @@ END
|
|
|
66
62
|
{domain}/{apiName}/viewer/{FunctionName}/{fileID}/{filename}
|
|
67
63
|
```
|
|
68
64
|
|
|
69
|
-
`{FunctionName}`
|
|
70
|
-
|
|
71
|
-
Route `/viewer/` dùng để xem trực tiếp trong browser (inline), `/download/` để tải về.
|
|
65
|
+
`{FunctionName}` is the name after the `spAPIFILE_` prefix: SP `spAPIFILE_Document` → URL uses `Document`. `/viewer/` = view inline in browser; `/download/` = download.
|
|
72
66
|
|
|
73
|
-
>
|
|
67
|
+
> **`@filename`:** usually the original name (e.g. `BaoCao_2024.pdf`) used by browser/download manager to name the file; need not match `FileName` in the DB. If the SP doesn't declare `@filename`, tAPI still accepts the route with that segment — the param is simply ignored.
|
|
74
68
|
|
|
75
69
|
## Upload file
|
|
76
70
|
|
|
77
|
-
**
|
|
71
|
+
**Special params injected by tAPI on upload:**
|
|
78
72
|
|
|
79
|
-
| Param
|
|
80
|
-
|
|
81
|
-
| `@sys_FileContent`
|
|
82
|
-
| `@sys_FileName`
|
|
83
|
-
| `@sys_FileContentType` | varchar(100)
|
|
84
|
-
| `@sys_FileSize`
|
|
85
|
-
| `@sys_UploadData`
|
|
73
|
+
| Param | Type | Meaning |
|
|
74
|
+
| ---------------------- | -------------- | --------------------------------- |
|
|
75
|
+
| `@sys_FileContent` | varbinary(max) | File binary content |
|
|
76
|
+
| `@sys_FileName` | nvarchar(200) | Original file name |
|
|
77
|
+
| `@sys_FileContentType` | varchar(100) | MIME type |
|
|
78
|
+
| `@sys_FileSize` | int | File size (bytes) |
|
|
79
|
+
| `@sys_UploadData` | nvarchar(max) | Extra JSON data passed via header |
|
|
86
80
|
|
|
87
|
-
|
|
81
|
+
All `@sys_` auth params are also available: `@sys_UserID`, `@sys_UserName`, `@sys_SessionID`, `@sys_GroupID`, `@sys_DepartmentID`, `@sys_SystemRight`, `@sys_FunctionRight`.
|
|
88
82
|
|
|
89
83
|
```sql
|
|
90
84
|
CREATE PROCEDURE spAPIFILE_UPLOAD_Attachment
|
|
@@ -103,9 +97,9 @@ END
|
|
|
103
97
|
|
|
104
98
|
Route: `POST {domain}/{apiName}/upload/{spName}/{url1}/{url2}...`
|
|
105
99
|
|
|
106
|
-
##
|
|
100
|
+
## Standard file table — `tblFileData`
|
|
107
101
|
|
|
108
|
-
|
|
102
|
+
Standard structure shared by `spAPIFILE_` (GET) and `spAPIFILE_UPLOAD_` (POST). For modules with files, create this table (or similar) before writing SPs.
|
|
109
103
|
|
|
110
104
|
```sql
|
|
111
105
|
CREATE TABLE [dbo].[tblFileData](
|
|
@@ -129,23 +123,23 @@ ALTER TABLE [dbo].[tblFileData] ADD CONSTRAINT [DF_tblFileData_CreateTime]
|
|
|
129
123
|
ALTER TABLE [dbo].[tblFileData] ADD CONSTRAINT [DF_tblFileData_ContentType] DEFAULT ('') FOR [ContentType]
|
|
130
124
|
```
|
|
131
125
|
|
|
132
|
-
> **
|
|
126
|
+
> **DDL:** the `ALTER TABLE ... ADD CONSTRAINT` statements **can run via fui** (ADD is additive). `CREATE TABLE` cannot — fui blocks it; the developer must run it. This is a structure reference.
|
|
133
127
|
|
|
134
|
-
**
|
|
128
|
+
**Fields:**
|
|
135
129
|
|
|
136
|
-
| Field
|
|
137
|
-
|
|
138
|
-
| `FileID`
|
|
139
|
-
| `FileName`
|
|
140
|
-
| `PhysicalName`
|
|
141
|
-
| `PhysicalSegment` | char(10)
|
|
142
|
-
| `CreateTime`
|
|
143
|
-
| `WriteToDisk`
|
|
144
|
-
| `BinaryContent`
|
|
145
|
-
| `ContentType`
|
|
146
|
-
| `Size`
|
|
130
|
+
| Field | Type | Meaning |
|
|
131
|
+
| ----------------- | ------------- | ----------------------------------------------------------------------------- |
|
|
132
|
+
| `FileID` | char(36) PK | Auto UUID via `newid()` — used as the URL key |
|
|
133
|
+
| `FileName` | nvarchar(200) | Original upload name |
|
|
134
|
+
| `PhysicalName` | char(36) | Auto UUID — actual file name on disk (avoids collisions) |
|
|
135
|
+
| `PhysicalSegment` | char(10) | Date-based subfolder from `getPhysicalSegment(date)` |
|
|
136
|
+
| `CreateTime` | datetime | Record creation time, DEFAULT getdate() |
|
|
137
|
+
| `WriteToDisk` | datetime NULL | When the binary was written to disk; `NULL` = DB only, not on file system yet |
|
|
138
|
+
| `BinaryContent` | image NULL | File binary — GET SP must alias it `fileContent` |
|
|
139
|
+
| `ContentType` | varchar(100) | MIME type, e.g. `application/pdf`, `image/png` |
|
|
140
|
+
| `Size` | int NULL | Size in bytes |
|
|
147
141
|
|
|
148
|
-
**
|
|
142
|
+
**GET SP on the table:**
|
|
149
143
|
|
|
150
144
|
```sql
|
|
151
145
|
CREATE PROCEDURE spAPIFILE_Document
|
|
@@ -162,7 +156,7 @@ AS BEGIN
|
|
|
162
156
|
END
|
|
163
157
|
```
|
|
164
158
|
|
|
165
|
-
**
|
|
159
|
+
**UPLOAD SP into the table:**
|
|
166
160
|
|
|
167
161
|
```sql
|
|
168
162
|
CREATE PROCEDURE spAPIFILE_UPLOAD_Document
|
|
@@ -188,4 +182,4 @@ AS BEGIN
|
|
|
188
182
|
END
|
|
189
183
|
```
|
|
190
184
|
|
|
191
|
-
>
|
|
185
|
+
> **`BinaryContent [image]`**: `image` is legacy SQL Server but works fine with tAPI. `varbinary(max)` also works — both map to the `fileContent` alias.
|
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
# tAPI —
|
|
1
|
+
# tAPI — Permission Check Patterns
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
Các pattern kiểm tra quyền trong thân Stored Procedure tAPI. Load file này khi SP cần phân quyền.
|
|
6
|
-
|
|
7
|
-
> Nền tảng SP (naming, params, response, RAISERROR): xem [tapi-reference.md](tapi-reference.md).
|
|
8
|
-
> Khái niệm `SystemRight`/`FunctionRight`, cấu trúc `tblSysRight`/`tblFunction`, và 4 tool quản lý định nghĩa quyền: xem [permission-system.md](permission-system.md).
|
|
3
|
+
> Owns: **5 permission-check patterns in SP bodies (`@sys_SystemRight`, `getSystemRight`, RAISERROR)**. Load when an SP needs authorization. SP basics (naming, params, response, RAISERROR): [tapi-reference.md](tapi-reference.md). `SystemRight`/`FunctionRight` concepts, `tblSysRight`/`tblFunction`, right-definition commands: [permission-system.md](permission-system.md).
|
|
9
4
|
|
|
10
5
|
---
|
|
11
6
|
|
|
12
|
-
##
|
|
7
|
+
## Permission-related system params
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
Injected by tAPI — the client never sends them:
|
|
15
10
|
|
|
16
|
-
|
|
|
17
|
-
|
|
18
|
-
| `@sys_UserID`
|
|
19
|
-
| `@sys_SystemRight`
|
|
20
|
-
| `@sys_FunctionRight` | varchar(2000) |
|
|
11
|
+
| Param | Type | Meaning |
|
|
12
|
+
| -------------------- | ------------- | ------------------------------------- |
|
|
13
|
+
| `@sys_UserID` | varchar(9) | Logged-in user ID |
|
|
14
|
+
| `@sys_SystemRight` | int | User's level on the current module |
|
|
15
|
+
| `@sys_FunctionRight` | varchar(2000) | Function rights like `[AD][RPT][MGR]` |
|
|
21
16
|
|
|
22
|
-
**
|
|
17
|
+
**Declare** at the end of the param list. **No default on any param, including `@sys_*`** ([tapi-reference.md](tapi-reference.md) §2 — tAPI always passes every param, `NULL` when missing, so `DEFAULT` is never used; `fui sp deploy` hard-blocks it):
|
|
23
18
|
|
|
24
19
|
```sql
|
|
25
20
|
CREATE PROCEDURE spAPI_EntityAction
|
|
@@ -30,31 +25,31 @@ CREATE PROCEDURE spAPI_EntityAction
|
|
|
30
25
|
AS
|
|
31
26
|
```
|
|
32
27
|
|
|
33
|
-
##
|
|
28
|
+
## `@sys_SystemRight` levels
|
|
34
29
|
|
|
35
|
-
|
|
30
|
+
Meaning is **defined per project** (`tblSysRight.Note`, managed via `fui right system list`/`update` — [permission-system.md](permission-system.md)). Common convention for SP checks — not platform-fixed, except `9` is always Project Admin:
|
|
36
31
|
|
|
37
|
-
|
|
|
38
|
-
|
|
39
|
-
| `0`
|
|
40
|
-
| `1`
|
|
41
|
-
| `2`
|
|
42
|
-
| `3`
|
|
43
|
-
| `9`
|
|
32
|
+
| Value | Common meaning |
|
|
33
|
+
| ----- | -------------------------------------------------- |
|
|
34
|
+
| `0` | No right / not granted on the module |
|
|
35
|
+
| `1` | Basic view |
|
|
36
|
+
| `2` | Standard operations (read, add, normal edit) |
|
|
37
|
+
| `3` | Advanced (internal management, sensitive ops) |
|
|
38
|
+
| `9` | Module Admin / Project Admin (fixed platform-wide) |
|
|
44
39
|
|
|
45
|
-
## Helper
|
|
40
|
+
## Helper: rights on a specific module
|
|
46
41
|
|
|
47
42
|
```sql
|
|
48
43
|
dbo.getSystemRight(@ModuleID, @sys_UserID)
|
|
49
44
|
```
|
|
50
45
|
|
|
51
|
-
|
|
46
|
+
Returns the user's `SysRight` on a given module — use to check rights on a module **other than** the current one.
|
|
52
47
|
|
|
53
48
|
---
|
|
54
49
|
|
|
55
|
-
## Pattern 1 —
|
|
50
|
+
## Pattern 1 — Basic access block (READ)
|
|
56
51
|
|
|
57
|
-
|
|
52
|
+
Every read SP that needs login. Requires `SysRight >= 2`.
|
|
58
53
|
|
|
59
54
|
```sql
|
|
60
55
|
If @sys_SystemRight < 2
|
|
@@ -64,9 +59,9 @@ Begin
|
|
|
64
59
|
End
|
|
65
60
|
```
|
|
66
61
|
|
|
67
|
-
## Pattern 2 —
|
|
62
|
+
## Pattern 2 — Block only users with no right (minimal)
|
|
68
63
|
|
|
69
|
-
|
|
64
|
+
Allows `SysRight = 1`; blocks only `SysRight = 0`.
|
|
70
65
|
|
|
71
66
|
```sql
|
|
72
67
|
If @sys_SystemRight = 0
|
|
@@ -76,11 +71,12 @@ Begin
|
|
|
76
71
|
End
|
|
77
72
|
```
|
|
78
73
|
|
|
79
|
-
## Pattern 3 —
|
|
74
|
+
## Pattern 3 — 2-tier: global + module admin (WRITE)
|
|
75
|
+
|
|
76
|
+
Writes affecting module config or other users' data. User must meet **either**:
|
|
80
77
|
|
|
81
|
-
|
|
82
|
-
-
|
|
83
|
-
- Là Module Admin (`getSystemRight >= 9`) của module đó.
|
|
78
|
+
- `@sys_SystemRight >= 3` (high global right), **or**
|
|
79
|
+
- Module Admin (`getSystemRight >= 9`) of that module.
|
|
84
80
|
|
|
85
81
|
```sql
|
|
86
82
|
-- Tầng 1: phải có quyền cơ bản
|
|
@@ -98,9 +94,9 @@ Begin
|
|
|
98
94
|
End
|
|
99
95
|
```
|
|
100
96
|
|
|
101
|
-
## Pattern 4 —
|
|
97
|
+
## Pattern 4 — Business-rule check before executing
|
|
102
98
|
|
|
103
|
-
|
|
99
|
+
Authorized but violates a data constraint (e.g. deleting a parent that still has children).
|
|
104
100
|
|
|
105
101
|
```sql
|
|
106
102
|
-- Kiểm tra ràng buộc trước khi xóa
|
|
@@ -113,9 +109,9 @@ End
|
|
|
113
109
|
DELETE tblParent WHERE ParentID = @ParentID
|
|
114
110
|
```
|
|
115
111
|
|
|
116
|
-
## Pattern 5 —
|
|
112
|
+
## Pattern 5 — `@sys_FunctionRight` check
|
|
117
113
|
|
|
118
|
-
|
|
114
|
+
Authorization by specific function (not just numeric level).
|
|
119
115
|
|
|
120
116
|
```sql
|
|
121
117
|
If CHARINDEX('[ADMIN]', @sys_FunctionRight) = 0
|
|
@@ -127,7 +123,7 @@ End
|
|
|
127
123
|
|
|
128
124
|
---
|
|
129
125
|
|
|
130
|
-
##
|
|
126
|
+
## Check order
|
|
131
127
|
|
|
132
128
|
```
|
|
133
129
|
1. Kiểm tra quyền hệ thống (@sys_SystemRight) ← luôn đầu tiên
|
|
@@ -136,23 +132,25 @@ End
|
|
|
136
132
|
4. Kiểm tra ràng buộc nghiệp vụ ← sau cùng, trước khi ghi
|
|
137
133
|
```
|
|
138
134
|
|
|
139
|
-
##
|
|
135
|
+
## Error message conventions
|
|
140
136
|
|
|
141
|
-
|
|
|
142
|
-
|
|
143
|
-
|
|
|
144
|
-
|
|
|
145
|
-
|
|
|
146
|
-
|
|
|
147
|
-
|
|
|
137
|
+
| Case | Standard message |
|
|
138
|
+
| ---------------------------------------- | --------------------------------------------------------------------- |
|
|
139
|
+
| Missing global right | `N'[Unauthorized]Bạn không có quyền trên chức năng này.'` |
|
|
140
|
+
| Missing module right | `N'[Unauthorized]Bạn không có quyền trên Module này.'` |
|
|
141
|
+
| Missing function right (`FunctionRight`) | `N'[Unauthorized]Bạn không có quyền thực hiện chức năng này.'` |
|
|
142
|
+
| Constraint violation | Specific description, **no** prefix: `N'Phải xóa X trước khi xóa Y.'` |
|
|
143
|
+
| Invalid data | `N'Dữ liệu không hợp lệ.'` or specific description, **no** prefix |
|
|
144
|
+
|
|
145
|
+
**Mandatory `RAISERROR` format:**
|
|
148
146
|
|
|
149
|
-
**Format `RAISERROR` bắt buộc:**
|
|
150
147
|
```sql
|
|
151
148
|
RAISERROR(N'Thông báo lỗi tiếng Việt.', 16, 1)
|
|
152
149
|
RETURN
|
|
153
150
|
```
|
|
154
|
-
|
|
155
|
-
-
|
|
156
|
-
- `
|
|
157
|
-
-
|
|
158
|
-
-
|
|
151
|
+
|
|
152
|
+
- **Severity always `16`** — every error kind (validation, unauthorized, business logic)
|
|
153
|
+
- `N` prefix required for Vietnamese Unicode
|
|
154
|
+
- `RETURN` required right after `RAISERROR` — without it the SP keeps running after the error
|
|
155
|
+
- Client receives `{ "Message": "..." }`
|
|
156
|
+
- **Every missing-right error in the 5 patterns must start with `[Unauthorized]`** (e.g. `N'[Unauthorized]Bạn không có quyền...'`) — tAPI uses this prefix to return HTTP `401` instead of the default, and strips `[Unauthorized]` from `Message` before returning. Constraint/business errors (Pattern 4) do **not** use it — mechanism + client 401 handling: [tapi-reference.md](tapi-reference.md) §5.
|