Skip to content

Manage User Badges in the UI #31262

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

Draft
wants to merge 15 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
@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!

HenriquerPimentel and others added 3 commits June 19, 2024 13:53
Co-authored-by: Diogo Vicente <diogo.m.s.vicente@tecnico.ulisboa.pt>
Co-authored-by: Diogo Vicente <diogo.m.s.vicente@tecnico.ulisboa.pt>
@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
Copy link
Member

@lunny updated this PR per your feedback including adding some pagination

@lunny lunny changed the title Manage User Badges in the interface #29798 Manage User Badges in the UI Jan 16, 2025
@techknowlogick
Copy link
Member

@lunny any additional feedback?

// GetBadgeUsersOptions contains options for getting users with a specific badge
type GetBadgeUsersOptions struct {
db.ListOptions
Badge *Badge
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear to use a slug here. Why not directly use a BadgeSlug string here?

<label for="slug">{{ctx.Locale.Tr "admin.badges.slug"}}</label>
<input autofocus required id="slug" name="slug" value="{{.slug}}">
</div>
<div class="field {{if .Err_Description}}error{{end}}">
Copy link
Member

Choose a reason for hiding this comment

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

Should a name and description be necessary?

@lunny
Copy link
Member

lunny commented Jan 22, 2025

When creating a badge with only slug, it reports 500.
image

</div>
</div>
<div class="flex-item-trailing">
<button class="ui red tiny button inline delete-button" data-url="{{$.Link}}/delete" data-id="{{.ID}}">
Copy link
Contributor

Choose a reason for hiding this comment

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

image

if err := user_model.RemoveUserBadge(ctx, user, &user_model.Badge{Slug: ctx.PathParam(":badge_slug")}); err == nil {
ctx.Flash.Success(ctx.Tr("admin.badges.user_remove_success"))
} else {
ctx.Flash.Error("DeleteBadgeUser: " + err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

ServerError

ctx.Flash.Error("DeleteBadgeUser: " + err.Error())
}

ctx.JSONRedirect(fmt.Sprintf("%s/-/admin/badges/%s/users", setting.AppSubURL, ctx.PathParam(":badge_slug")))
Copy link
Contributor

Choose a reason for hiding this comment

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

escape

opts := &user_model.GetBadgeUsersOptions{
ListOptions: db.ListOptions{
Page: page,
PageSize: setting.UI.User.RepoPagingNum,
Copy link
Contributor

Choose a reason for hiding this comment

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

ui.admin

image

</h4>
<div class="ui attached segment">
<form class="ui form" action="./edit" method="post">
{{template "base/disable_form_autofill"}}
Copy link
Contributor

Choose a reason for hiding this comment

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

No password field then do not use this trick

@@ -0,0 +1,30 @@
{{template "admin/layout_head" (dict "ctxData" . "pageClass" "admin new user")}}
Copy link
Contributor

Choose a reason for hiding this comment

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

admin new user?

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants