Skip to content

Commit 8a8ddda

Browse files
Dev AgentQinYuuuu
authored andcommitted
Return the reason message that why user can not be deleted
1 parent 5a09a0c commit 8a8ddda

File tree

10 files changed

+767
-11
lines changed

10 files changed

+767
-11
lines changed

common/errorx/error_user.go

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
package errorx
2+
3+
const errUserPrefix = "USER-ERR"
4+
5+
const (
6+
needPhone = iota
7+
needDifferentPhone
8+
phoneAlreadyExistsInSSO
9+
forbidChangePhone
10+
failedToUpdatePhone
11+
forbidSendPhoneVerifyCodeFrequently
12+
failedSendPhoneVerifyCode
13+
phoneVerifyCodeExpiredOrNotFound
14+
phoneVerifyCodeInvalid
15+
verificationCodeRequired
16+
verificationCodeLengthInvalid
17+
invalidPhoneNumber
18+
usernameExists
19+
emailExists
20+
adminUserCannotBeDeleted
21+
userHasOrganizations
22+
userHasDeployments
23+
userHasBills
24+
)
25+
26+
var (
27+
// phone number is required
28+
//
29+
// Description: The request must include a phone number in the header or body to identify the target account.
30+
//
31+
// Description_ZH: 请求必须在请求头或正文中包含电话号码以识别目标账户。
32+
//
33+
// en-US: Phone number is required
34+
//
35+
// zh-CN: 需要提供电话号码
36+
//
37+
// zh-HK: 需要電話號碼
38+
ErrNeedPhone error = CustomError{prefix: errUserPrefix, code: needPhone}
39+
// new phone number must be different from current phone number
40+
//
41+
// Description: The new phone number must be different from the current phone number.
42+
//
43+
// Description_ZH: 新电话号码必须与当前电话号码不同。
44+
//
45+
// en-US: New phone number must be different from current phone number
46+
//
47+
// zh-CN: 新电话号码必须与当前电话号码不同
48+
//
49+
// zh-HK: 新電話號碼必須與當前電話號碼不同
50+
ErrNeedDifferentPhone error = CustomError{prefix: errUserPrefix, code: needDifferentPhone}
51+
// new phone number already exists in sso service
52+
//
53+
// Description: The new phone number already exists in sso service.
54+
//
55+
// Description_ZH: 新电话号码已经存在于sso服务中。
56+
//
57+
// en-US: New phone number already exists in sso service
58+
//
59+
// zh-CN: 新电话号码已经存在于sso服务中
60+
//
61+
// zh-HK: 新電話號碼已經存在於sso服務中
62+
ErrPhoneAlreadyExistsInSSO error = CustomError{prefix: errUserPrefix, code: phoneAlreadyExistsInSSO}
63+
// forbid change phone number
64+
//
65+
// Description: The phone number cannot be changed.
66+
//
67+
// Description_ZH: 电话号码不能被更改。
68+
//
69+
// en-US: Forbid change phone number
70+
//
71+
// zh-CN: 禁止更改电话号码
72+
//
73+
// zh-HK: 禁止更改電話號碼
74+
ErrForbidChangePhone error = CustomError{prefix: errUserPrefix, code: forbidChangePhone}
75+
// failed to update phone number
76+
//
77+
// Description: Failed to update phone number.
78+
//
79+
// Description_ZH: 更新电话号码失败。
80+
//
81+
// en-US: Failed to update phone number
82+
//
83+
// zh-CN: 更新电话号码失败
84+
//
85+
// zh-HK: 更新電話號碼失敗
86+
ErrFailedToUpdatePhone error = CustomError{prefix: errUserPrefix, code: failedToUpdatePhone}
87+
// forbid send phone verify code frequently
88+
//
89+
// Description: Send phone verify code frequently.
90+
//
91+
// Description_ZH: 发送手机验证码过于频繁。
92+
//
93+
// en-US: Forbid send phone verify code frequently
94+
//
95+
// zh-CN: 禁止频繁发送手机验证码
96+
//
97+
// zh-HK: 禁止頻繁發送手機驗證碼
98+
ErrForbidSendPhoneVerifyCodeFrequently error = CustomError{prefix: errUserPrefix, code: forbidSendPhoneVerifyCodeFrequently}
99+
// failed to send phone verify code
100+
//
101+
// Description: Failed to send phone verify code.
102+
//
103+
// Description_ZH: 发送手机验证码失败。
104+
//
105+
// en-US: Failed to send phone verify code
106+
//
107+
// zh-CN: 发送手机验证码失败
108+
//
109+
// zh-HK: 發送手機驗證碼失敗
110+
ErrFailedSendPhoneVerifyCode error = CustomError{prefix: errUserPrefix, code: failedSendPhoneVerifyCode}
111+
// phone verify code expired or not found
112+
//
113+
// Description: Phone verify code expired or not found.
114+
//
115+
// Description_ZH: 手机验证码已过期或不存在。
116+
//
117+
// en-US: Phone verify code expired or not found
118+
//
119+
// zh-CN: 手机验证码已过期或不存在
120+
//
121+
// zh-HK: 手機驗證碼已過期或不存在
122+
ErrPhoneVerifyCodeExpiredOrNotFound error = CustomError{prefix: errUserPrefix, code: phoneVerifyCodeExpiredOrNotFound}
123+
// phone verify code is invalid
124+
//
125+
// Description: Phone verify code is invalid.
126+
//
127+
// Description_ZH: 手机验证码无效。
128+
//
129+
// en-US: Phone verify code is invalid
130+
//
131+
// zh-CN: 手机验证码无效
132+
//
133+
// zh-HK: 手機驗證碼無效
134+
ErrPhoneVerifyCodeInvalid error = CustomError{prefix: errUserPrefix, code: phoneVerifyCodeInvalid}
135+
136+
// verification code can not be empty
137+
//
138+
// Description: Verification code can not be empty.
139+
//
140+
// Description_ZH: 验证码不能为空。
141+
//
142+
// en-US: Verification code can not be empty
143+
//
144+
// zh-CN: 验证码不能为空
145+
//
146+
// zh-HK: 驗證碼不能為空
147+
ErrVerificationCodeRequired error = CustomError{prefix: errUserPrefix, code: verificationCodeRequired}
148+
// verification code length must be 6
149+
//
150+
// Description: Verification code length must be 6.
151+
//
152+
// Description_ZH: 验证码长度必须为6。
153+
//
154+
// en-US: Verification code length must be 6
155+
//
156+
// zh-CN: 验证码长度必须为6
157+
//
158+
// zh-HK: 驗證碼長度必須為6
159+
ErrVerificationCodeLength error = CustomError{prefix: errUserPrefix, code: verificationCodeLengthInvalid}
160+
// invalid phone number
161+
//
162+
// Description: Invalid phone number.
163+
//
164+
// Description_ZH: 无效的电话号码。
165+
//
166+
// en-US: Invalid phone number
167+
//
168+
// zh-CN: 无效的电话号码
169+
//
170+
// zh-HK: 無效的電話號碼
171+
ErrInvalidPhoneNumber error = CustomError{prefix: errUserPrefix, code: invalidPhoneNumber}
172+
// username already exists
173+
//
174+
// Description: The username provided already exists in the system.
175+
//
176+
// Description_ZH: 提供的用户名已存在于系统中。
177+
//
178+
// en-US: Username already exists
179+
//
180+
// zh-CN: 用户名已存在
181+
//
182+
// zh-HK: 用戶名已存在
183+
ErrUsernameExists error = CustomError{prefix: errUserPrefix, code: usernameExists}
184+
185+
// email already exists in the system
186+
//
187+
// Description: The email address provided already exists in the system.
188+
//
189+
// Description_ZH: 提供的电子邮件地址已存在于系统中。
190+
//
191+
// en-US: Email already exists
192+
//
193+
// zh-CN: 邮箱已存在
194+
//
195+
// zh-HK: 電郵已存在
196+
ErrEmailExists error = CustomError{prefix: errUserPrefix, code: emailExists}
197+
// admin user cannot be deleted
198+
//
199+
// Description: The admin user cannot be deleted.
200+
//
201+
// Description_ZH: 管理员用户不能被删除。
202+
//
203+
// en-US: Admin user cannot be deleted
204+
//
205+
// zh-CN: 管理员用户不能被删除
206+
//
207+
// zh-HK: 管理員用戶不能被刪除
208+
ErrAdminUserCannotBeDeleted error = CustomError{prefix: errUserPrefix, code: adminUserCannotBeDeleted}
209+
// user has organizations can not be deleted
210+
//
211+
// Description: The user who owns organizations cannot be deleted.
212+
//
213+
// Description_ZH: 拥有组织的用户不能被删除。
214+
//
215+
// en-US: User who owns organizations cannot be deleted
216+
//
217+
// zh-CN: 拥有组织的用户不能被删除
218+
//
219+
// zh-HK: 擁有組織的用戶不能被刪除
220+
ErrUserHasOrganizations error = CustomError{prefix: errUserPrefix, code: userHasOrganizations}
221+
// user has deployments can not be deleted
222+
//
223+
// Description: The user who owns deployments cannot be deleted.
224+
//
225+
// Description_ZH: 拥有部署资源的用户不能被删除。
226+
//
227+
// en-US: User who owns deployments cannot be deleted
228+
//
229+
// zh-CN: 拥有部署资源的用户不能被删除
230+
//
231+
// zh-HK: 擁有部署資源的用戶不能被刪除
232+
ErrUserHasDeployments error = CustomError{prefix: errUserPrefix, code: userHasDeployments}
233+
// user has bills can not be deleted
234+
//
235+
// Description: The user who owns bills cannot be deleted.
236+
//
237+
// Description_ZH: 拥有账单的用户不能被删除。
238+
//
239+
// en-US: User who owns bills cannot be deleted
240+
//
241+
// zh-CN: 拥有账单的用户不能被删除
242+
//
243+
// zh-HK: 擁有賬單的用戶不能被刪除
244+
ErrUserHasBills error = CustomError{prefix: errUserPrefix, code: userHasBills}
245+
)
246+
247+
// UsernameExists creates a specific error for username conflicts with the conflicting username
248+
func UsernameExists(username string) error {
249+
return CustomError{
250+
prefix: errUserPrefix,
251+
code: usernameExists,
252+
context: map[string]interface{}{"username": username},
253+
}
254+
}
255+
256+
// EmailExists creates a specific error for email conflicts with the conflicting email
257+
func EmailExists(email string) error {
258+
return CustomError{
259+
prefix: errUserPrefix,
260+
code: emailExists,
261+
context: map[string]interface{}{"email": email},
262+
}
263+
}

common/i18n/en-US/err_git.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
"error.GIT-ERR-34": {
8787
"other": "replicate repository failed"
8888
},
89+
"error.GIT-ERR-35": {
90+
"other": "Using git in xnet-enabled repository error"
91+
},
8992
"error.GIT-ERR-4": {
9093
"other": "Failed to find commit"
9194
},

common/i18n/en-US/err_user.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"error.USER-ERR-0": {
3+
"other": "Phone number is required"
4+
},
5+
"error.USER-ERR-1": {
6+
"other": "New phone number must be different from current phone number"
7+
},
8+
"error.USER-ERR-10": {
9+
"other": "Verification code length must be 6"
10+
},
11+
"error.USER-ERR-11": {
12+
"other": "Invalid phone number"
13+
},
14+
"error.USER-ERR-12": {
15+
"other": "Username already exists"
16+
},
17+
"error.USER-ERR-13": {
18+
"other": "Email already exists"
19+
},
20+
"error.USER-ERR-14": {
21+
"other": "Admin user cannot be deleted"
22+
},
23+
"error.USER-ERR-15": {
24+
"other": "User who owns organizations cannot be deleted"
25+
},
26+
"error.USER-ERR-16": {
27+
"other": "User who owns deployments cannot be deleted"
28+
},
29+
"error.USER-ERR-17": {
30+
"other": "User who owns bills cannot be deleted"
31+
},
32+
"error.USER-ERR-2": {
33+
"other": "New phone number already exists in sso service"
34+
},
35+
"error.USER-ERR-3": {
36+
"other": "Forbid change phone number"
37+
},
38+
"error.USER-ERR-4": {
39+
"other": "Failed to update phone number"
40+
},
41+
"error.USER-ERR-5": {
42+
"other": "Forbid send phone verify code frequently"
43+
},
44+
"error.USER-ERR-6": {
45+
"other": "Failed to send phone verify code"
46+
},
47+
"error.USER-ERR-7": {
48+
"other": "Phone verify code expired or not found"
49+
},
50+
"error.USER-ERR-8": {
51+
"other": "Phone verify code is invalid"
52+
},
53+
"error.USER-ERR-9": {
54+
"other": "Verification code can not be empty"
55+
}
56+
}

common/i18n/zh-CN/err_git.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
"error.GIT-ERR-34": {
8787
"other": "转移仓库失败"
8888
},
89+
"error.GIT-ERR-35": {
90+
"other": "在 xnet 启用的仓库中使用 git 失败"
91+
},
8992
"error.GIT-ERR-4": {
9093
"other": "查找提交失败"
9194
},

common/i18n/zh-CN/err_user.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"error.USER-ERR-0": {
3+
"other": "需要提供电话号码"
4+
},
5+
"error.USER-ERR-1": {
6+
"other": "新电话号码必须与当前电话号码不同"
7+
},
8+
"error.USER-ERR-10": {
9+
"other": "验证码长度必须为6"
10+
},
11+
"error.USER-ERR-11": {
12+
"other": "无效的电话号码"
13+
},
14+
"error.USER-ERR-12": {
15+
"other": "用户名已存在"
16+
},
17+
"error.USER-ERR-13": {
18+
"other": "邮箱已存在"
19+
},
20+
"error.USER-ERR-14": {
21+
"other": "管理员用户不能被删除"
22+
},
23+
"error.USER-ERR-15": {
24+
"other": "拥有组织的用户不能被删除"
25+
},
26+
"error.USER-ERR-16": {
27+
"other": "拥有部署资源的用户不能被删除"
28+
},
29+
"error.USER-ERR-17": {
30+
"other": "拥有账单的用户不能被删除"
31+
},
32+
"error.USER-ERR-2": {
33+
"other": "新电话号码已经存在于sso服务中"
34+
},
35+
"error.USER-ERR-3": {
36+
"other": "禁止更改电话号码"
37+
},
38+
"error.USER-ERR-4": {
39+
"other": "更新电话号码失败"
40+
},
41+
"error.USER-ERR-5": {
42+
"other": "禁止频繁发送手机验证码"
43+
},
44+
"error.USER-ERR-6": {
45+
"other": "发送手机验证码失败"
46+
},
47+
"error.USER-ERR-7": {
48+
"other": "手机验证码已过期或不存在"
49+
},
50+
"error.USER-ERR-8": {
51+
"other": "手机验证码无效"
52+
},
53+
"error.USER-ERR-9": {
54+
"other": "验证码不能为空"
55+
}
56+
}

0 commit comments

Comments
 (0)