Skip to content

Conversation

HenriquerPimentel
Copy link
Contributor

Implemented #29798

This feature implements:

  • List all badges (screenshot)
  • Create new badges (screenshot)
  • View badge (screenshot)
  • Edit badge (screenshot)
  • Add user to badge (screenshot)

Implemented Badge Management in administration panel

  1. Updated badge model (models/user/badge.go)
  2. Added new type of errors ErrBadgeAlreadyExist and ErrBadgeNotExist (models/user/error.go)
  3. Implemented badge service methods (services/user/badge.go)
  4. Implemented new type of form AdminCreateBadgeForm (services/forms/admin.go)
  5. Implemented new binding rules to check if ImageURL is valid and if is Slug Pattern (modules/validation/binding.go) (modules/web/middleware.go) (modules/validation/helpers.go)
  6. Implemented badge search (routers/web/explore/badge.go) (routers/web/admin/badges.go)
  7. Implemented badges routing (routers/web/web.go)
  8. Implemented templates for create/list/edit/view badges (templates/admin/badge/*) (templates/admin/navbar.tmpl)
    9 Added new translation phrases (en-US): search.badge_kind, form.ImageURL, form.invalid_image_url_error, form.slug_been_taken, admin.badges, admin.badges.badges_manage_panel, admin.badges.details, admin.badges.new_badge, admin.badges.slug, admin.badges.description, admin.badges.image_url, admin.badges.slug.must_fill, admin.badges.new_success, admin.badges.update_success, admin.badges.deletion_success, admin.badges.edit_badge, admin.badges.update_badge, admin.badges.delete_badge, admin.badges.delete_badge_desc

Implemented User Badge Management Interface

  1. Implemented rule to verify if a user badge already exists before insert (models/user/badge.go).
  2. Implemented interface to manage user badge, within administration panel. (routers/web/web.go) (routers/web/explore/badge.go) (routers/web/admin/badges.go) (templates/admin/badge/users.tmpl).
  3. Small bug fixes (view.tmpl, list.tmpl)
  4. Added new translation phrases: admin.badges.users_with_badge, admin.badges.add_user, admin.badges.remove_user, admin.badges.delete_user_desc, admin.badges.not_found, admin.badges.user_add_success, admin.badges.user_remove_success, admin.badges.manage_users.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 5, 2024
@github-actions github-actions bot added modifies/translation modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files labels Jun 5, 2024
@HenriquerPimentel HenriquerPimentel marked this pull request as draft June 5, 2024 14:10
@HenriquerPimentel HenriquerPimentel marked this pull request as ready for review June 14, 2024 12:00
@lunny lunny added this to the 1.23.0 milestone Jun 14, 2024
Copy link
Member

@techknowlogick techknowlogick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! The CI has a few linting reports that came up that I've reported in line :)

@HenriquerPimentel
Copy link
Contributor Author

Thanks for the PR! The CI has a few linting reports that came up that I've reported in line :)

Thank you so much!

@techknowlogick
Copy link
Member

@HenriquerPimentel looks like some different CI steps are failing, also related to linting (some public go functions require comments to document their purpose, eg AdminCreateBadge), although with AdminCreateBadge as it is a wrapper for another function without any transformative properties or checks that one could probably be kept as just CreateBadge without the secondary function.

As a sidenote: force pushing erases some review history as GitHub sees some files as new (even if they remain the same). If you could reduce your force pushes, it'd be helpful to me as a reviewer so I can keep track of what I've seen already
disclaimer: most of the time we try to discourage force pushing to PRs for this reason, although depending on the reviewer of a certain PR they can "call an audible" depending on the situation and might be ok with it.

@techknowlogick techknowlogick requested a review from lunny August 18, 2025 18:54
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Aug 18, 2025
@@ -603,12 +605,15 @@ unknown_error = Unknown error:
captcha_incorrect = The CAPTCHA code is incorrect.
password_not_match = The passwords do not match.
lang_select_error = Select a language from the list.
invalid_image_url_error = `Please provide a valid image URL.`
invalid_slug_error = `Please provide a valid slug.`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crowdin doesn't work with back-quote

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 181 to 184
switch {
default:
ctx.ServerError("UpdateBadge", err)
}
Copy link
Contributor

@wxiaoguang wxiaoguang Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only switch-default?

(many places)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b.ImageURL = form.ImageURL
b.Description = form.Description

if err := user_model.UpdateBadge(ctx, ctx.Data["Badge"].(*user_model.Badge)); err != nil {
Copy link
Contributor

@wxiaoguang wxiaoguang Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it uses dynamic type here ctx.Data["Badge"].(*user_model.Badge))? There should be a static typed variable "badge"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 226 to 229
page := ctx.FormInt("page")
if page <= 0 {
page = 1
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

09b4e68 It should use max.

Comment on lines 268 to 273
if user_model.IsErrBadgeNotExist(err) {
ctx.Flash.Error(ctx.Tr("admin.badges.not_found"))
} else {
ctx.ServerError("AddUserBadge", err)
}
return
Copy link
Contributor

@wxiaoguang wxiaoguang Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx.Flash.Error + return is wrong

(many places)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 334 to 336
func RenderBadgeSearch(ctx *context.Context, opts *user_model.SearchBadgeOptions, tplName templates.TplName) {
// Sitemap index for sitemap paths
opts.Page = int(ctx.PathParamInt64("idx"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "sitemap" in the "admin" routes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type AdminCreateBadgeForm struct {
Slug string `binding:"Required;Slug"`
Description string `binding:"Required"`
ImageURL string `binding:"ValidImageUrl"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is ValidImageUrl?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions github-actions bot added topic/code-linting modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/docs modifies/internal modifies/dependencies modifies/frontend labels Sep 14, 2025
@github-actions github-actions bot removed topic/code-linting modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/docs modifies/internal modifies/dependencies modifies/frontend labels Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/go Pull requests that update Go code modifies/migrations modifies/templates This PR modifies the template files modifies/translation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants