Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage User Badges in the interface #29798 #31262

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

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
@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. 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 :)

templates/admin/badge/users.tmpl Show resolved Hide resolved
templates/admin/badge/users.tmpl Outdated Show resolved Hide resolved
@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.

@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 8, 2024
func (opts *SearchBadgeOptions) ToJoins() []db.JoinFunc {
return []db.JoinFunc{
func(e db.Engine) error {
e.Join("INNER", "badge", "badge.badge_id = badge.id")
Copy link
Member

Choose a reason for hiding this comment

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

The join is wrong. badge join badge?

@@ -42,13 +46,27 @@ func GetUserBadges(ctx context.Context, u *User) ([]*Badge, int64, error) {
return badges, count, err
}

// GetBadgeUsers returns the users that have a specific badge.
func GetBadgeUsers(ctx context.Context, b *Badge) ([]*User, int64, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I think pagination is necessary here because you don't know how many users will have the badges which maybe a big number.

Join("INNER", "badge", "badge.id = `user_badge`.badge_id").
Where("`user_badge`.user_id=? AND `badge`.slug=?", u.ID, badge.Slug).
Where("`user_badge`.user_id=?", u.ID).
And(builder.In("badge_id", subQuery)).
Copy link
Member

Choose a reason for hiding this comment

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

Why use subquery instead of delete with join?

ctx.Flash.Success(ctx.Tr("admin.badges.user_remove_success"))
} else {
ctx.Flash.Error("DeleteUser: " + err.Error())
return
Copy link
Member

Choose a reason for hiding this comment

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

Don't return if it's a flash.

}
defer committer.Close()

if err := user_model.DeleteBadge(ctx, b); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This is not right. The badge was deleted but related data in user_badge hasn't been deleted.

@lunny lunny modified the milestones: 1.23.0, 1.24.0 Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/translation size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants