-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 :)
Thank you so much! |
Co-authored-by: Diogo Vicente <[email protected]>
Co-authored-by: Diogo Vicente <[email protected]>
@HenriquerPimentel looks like some different CI steps are failing, also related to linting (some public go functions require comments to document their purpose, eg 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 |
models/user/badge.go
Outdated
func (opts *SearchBadgeOptions) ToJoins() []db.JoinFunc { | ||
return []db.JoinFunc{ | ||
func(e db.Engine) error { | ||
e.Join("INNER", "badge", "badge.badge_id = badge.id") |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)). |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
Implemented #29798
This feature implements:
Implemented Badge Management in administration panel
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