@@ -81,7 +81,13 @@ func NewBadgePost(ctx *context.Context) {
81
81
82
82
if len (form .Slug ) < 1 {
83
83
ctx .Data ["Err_Slug" ] = true
84
- ctx .RenderWithErr (ctx .Tr ("admin.badges.must_fill" ), tplBadgeNew , & form )
84
+ ctx .RenderWithErr (ctx .Tr ("admin.badges.slug.must_fill" ), tplBadgeNew , & form )
85
+ return
86
+ }
87
+
88
+ if len (form .Description ) < 1 {
89
+ ctx .Data ["Err_Description" ] = true
90
+ ctx .RenderWithErr (ctx .Tr ("admin.badges.description.must_fill" ), tplBadgeNew , & form )
85
91
return
86
92
}
87
93
@@ -100,7 +106,7 @@ func NewBadgePost(ctx *context.Context) {
100
106
}
101
107
102
108
func prepareBadgeInfo (ctx * context.Context ) * user_model.Badge {
103
- b , err := user_model .GetBadge (ctx , ctx .PathParam (": badge_slug" ))
109
+ b , err := user_model .GetBadge (ctx , ctx .PathParam ("badge_slug" ))
104
110
if err != nil {
105
111
if user_model .IsErrBadgeNotExist (err ) {
106
112
ctx .Redirect (setting .AppSubURL + "/-/admin/badges" )
@@ -113,9 +119,9 @@ func prepareBadgeInfo(ctx *context.Context) *user_model.Badge {
113
119
114
120
opts := & user_model.GetBadgeUsersOptions {
115
121
ListOptions : db.ListOptions {
116
- PageSize : setting .UI .User . RepoPagingNum ,
122
+ PageSize : setting .UI .Admin . UserPagingNum ,
117
123
},
118
- Badge : b ,
124
+ BadgeSlug : b . Slug ,
119
125
}
120
126
users , count , err := user_model .GetBadgeUsers (ctx , opts )
121
127
if err != nil {
@@ -192,12 +198,12 @@ func EditBadgePost(ctx *context.Context) {
192
198
log .Trace ("Badge updated by admin (%s): %s" , ctx .Doer .Name , b .Slug )
193
199
194
200
ctx .Flash .Success (ctx .Tr ("admin.badges.update_success" ))
195
- ctx .Redirect (setting .AppSubURL + "/-/admin/badges/" + url .PathEscape (ctx .PathParam (": badge_slug" )))
201
+ ctx .Redirect (setting .AppSubURL + "/-/admin/badges/" + url .PathEscape (ctx .PathParam ("badge_slug" )))
196
202
}
197
203
198
204
// DeleteBadge response for deleting a badge
199
205
func DeleteBadge (ctx * context.Context ) {
200
- b , err := user_model .GetBadge (ctx , ctx .PathParam (": badge_slug" ))
206
+ b , err := user_model .GetBadge (ctx , ctx .PathParam ("badge_slug" ))
201
207
if err != nil {
202
208
ctx .ServerError ("GetBadge" , err )
203
209
return
@@ -215,21 +221,21 @@ func DeleteBadge(ctx *context.Context) {
215
221
}
216
222
217
223
func BadgeUsers (ctx * context.Context ) {
218
- ctx .Data ["Title" ] = ctx .Tr ("admin.badges.users_with_badge" , ctx .PathParam (": badge_slug" ))
224
+ ctx .Data ["Title" ] = ctx .Tr ("admin.badges.users_with_badge" , ctx .PathParam ("badge_slug" ))
219
225
ctx .Data ["PageIsAdminBadges" ] = true
220
226
221
227
page := ctx .FormInt ("page" )
222
228
if page <= 0 {
223
229
page = 1
224
230
}
225
231
226
- badge := & user_model.Badge {Slug : ctx .PathParam (": badge_slug" )}
232
+ badge := & user_model.Badge {Slug : ctx .PathParam ("badge_slug" )}
227
233
opts := & user_model.GetBadgeUsersOptions {
228
234
ListOptions : db.ListOptions {
229
235
Page : page ,
230
- PageSize : setting .UI .User . RepoPagingNum ,
236
+ PageSize : setting .UI .Admin . UserPagingNum ,
231
237
},
232
- Badge : badge ,
238
+ BadgeSlug : badge . Slug ,
233
239
}
234
240
users , count , err := user_model .GetBadgeUsers (ctx , opts )
235
241
if err != nil {
@@ -239,7 +245,7 @@ func BadgeUsers(ctx *context.Context) {
239
245
240
246
ctx .Data ["Users" ] = users
241
247
ctx .Data ["Total" ] = count
242
- ctx .Data ["Page" ] = context .NewPagination (int (count ), setting .UI .User . RepoPagingNum , page , 5 )
248
+ ctx .Data ["Page" ] = context .NewPagination (int (count ), setting .UI .Admin . UserPagingNum , page , 5 )
243
249
244
250
ctx .HTML (http .StatusOK , tplBadgeUsers )
245
251
}
@@ -259,7 +265,7 @@ func BadgeUsersPost(ctx *context.Context) {
259
265
return
260
266
}
261
267
262
- if err = user_model .AddUserBadge (ctx , u , & user_model.Badge {Slug : ctx .PathParam (": badge_slug" )}); err != nil {
268
+ if err = user_model .AddUserBadge (ctx , u , & user_model.Badge {Slug : ctx .PathParam ("badge_slug" )}); err != nil {
263
269
if user_model .IsErrBadgeNotExist (err ) {
264
270
ctx .Flash .Error (ctx .Tr ("admin.badges.not_found" ))
265
271
} else {
@@ -283,18 +289,18 @@ func DeleteBadgeUser(ctx *context.Context) {
283
289
return
284
290
}
285
291
}
286
- if err := user_model .RemoveUserBadge (ctx , user , & user_model.Badge {Slug : ctx .PathParam (": badge_slug" )}); err == nil {
292
+ if err := user_model .RemoveUserBadge (ctx , user , & user_model.Badge {Slug : ctx .PathParam ("badge_slug" )}); err == nil {
287
293
ctx .Flash .Success (ctx .Tr ("admin.badges.user_remove_success" ))
288
294
} else {
289
- ctx .Flash . Error ( "DeleteBadgeUser: " + err . Error () )
295
+ ctx .ServerError ( "RemoveUserBadge" , err )
290
296
}
291
297
292
- ctx .JSONRedirect (fmt .Sprintf ("%s/-/admin/badges/%s/users" , setting .AppSubURL , ctx .PathParam (": badge_slug" )))
298
+ ctx .JSONRedirect (fmt .Sprintf ("%s/-/admin/badges/%s/users" , setting .AppSubURL , ctx .PathParam ("badge_slug" )))
293
299
}
294
300
295
301
// ViewBadgeUsers render badge's users page
296
302
func ViewBadgeUsers (ctx * context.Context ) {
297
- badge , err := user_model .GetBadge (ctx , ctx .PathParam (":slug " ))
303
+ badge , err := user_model .GetBadge (ctx , ctx .PathParam ("badge_slug " ))
298
304
if err != nil {
299
305
ctx .ServerError ("GetBadge" , err )
300
306
return
@@ -308,9 +314,9 @@ func ViewBadgeUsers(ctx *context.Context) {
308
314
opts := & user_model.GetBadgeUsersOptions {
309
315
ListOptions : db.ListOptions {
310
316
Page : page ,
311
- PageSize : setting .UI .User . RepoPagingNum ,
317
+ PageSize : setting .UI .Admin . UserPagingNum ,
312
318
},
313
- Badge : badge ,
319
+ BadgeSlug : badge . Slug ,
314
320
}
315
321
users , count , err := user_model .GetBadgeUsers (ctx , opts )
316
322
if err != nil {
@@ -322,6 +328,6 @@ func ViewBadgeUsers(ctx *context.Context) {
322
328
ctx .Data ["Badge" ] = badge
323
329
ctx .Data ["Users" ] = users
324
330
ctx .Data ["Total" ] = count
325
- ctx .Data ["Pages" ] = context .NewPagination (int (count ), setting .UI .User . RepoPagingNum , page , 5 )
331
+ ctx .Data ["Pages" ] = context .NewPagination (int (count ), setting .UI .Admin . UserPagingNum , page , 5 )
326
332
ctx .HTML (http .StatusOK , tplBadgeUsers )
327
333
}
0 commit comments