-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
base: main
Are you sure you want to change the base?
Manage User Badges in the UI #31262
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 <diogo.m.s.vicente@tecnico.ulisboa.pt>
Co-authored-by: Diogo Vicente <diogo.m.s.vicente@tecnico.ulisboa.pt>
@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 |
if err != nil { | ||
if user_model.IsErrUserNotExist(err) { | ||
ctx.Flash.Error(ctx.Tr("form.user_not_exist")) | ||
ctx.JSONRedirect(fmt.Sprintf("%s/-/admin/badges/%s/users", setting.AppSubURL, ctx.PathParam("badge_slug"))) |
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.
Two bugs:
- string variables used in a URL should be escaped (and other places)
- this
if
block will continue executing, then you have 2 JSONRedirect calls in one response.
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.
@go-gitea/maintainers
I have suggested many times to have a better framework to handle various errors and returns.
You can see that how many bugs caused by our stupid framework in this PR.
// UpdateBadgeDescription changes the description and/or image of a badge | ||
func UpdateBadge(ctx context.Context, b *user_model.Badge) error { | ||
return db.WithTx(ctx, func(ctx context.Context) error { | ||
return user_model.UpdateBadge(ctx, b) |
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 single SQL needs transaction?
return db.WithTx(ctx, func(ctx context.Context) error { | ||
if err := user_model.DeleteBadge(ctx, b); err != nil { | ||
return fmt.Errorf("DeleteBadge: %w", err) | ||
} | ||
return 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.
There is already a transaction in DeleteBadge
.
So why we need this wrap function in service package?
<div class="non-local field {{if .Err_Slug}}error{{end}}" disabled=disabled> | ||
<label for="slug">{{ctx.Locale.Tr "admin.badges.slug"}}</label> | ||
<input disabled=disabled id="slug" name="slug" value="{{.Badge.Slug}}"> | ||
</div> |
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.
Some questions:
- Why parent "div" has "disabled=disabled" and inner "input" also has "disabled=disabled"?
- If there is no input (no change), why
{{if .Err_Slug}}
would occurs? - If the input is disabled, why the "label" has "for"?
- What does "non-local" mean here?
<label for="description">{{ctx.Locale.Tr "admin.badges.description"}}</label> | ||
<textarea id="description" type="text" name="description" rows="2">{{.Badge.Description}}</textarea> |
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.
Our frontend framework can handle most a11y cases, so no need to repeat id
and for
(and other places)
</div> | ||
</div> | ||
|
||
<div class="ui g-modal-confirm delete modal" id="delete-badge-modal"> |
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.
delete
class is a no-op IIRC
{{end}} | ||
{{template "base/paginate" .}} | ||
<div class="ui bottom attached segment"> | ||
<form class="ui form" id="search-badge-user-form" action="{{.Link}}" method="post"> |
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 the search form is at the bottom?
IIRC for all (at least almost) cases Gitea layout is like this: search form at top, table at bottom.
ps: why it needs an id
? I don't see it is used anywhere.
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.
Hmm ... it is not a real "search" form, but it is used to add a new user, so maybe it's fine.
But still have the question why there are unused id
attributes.
<div class="flex-list"> | ||
<div class="flex-item"> | ||
{{if .Image}} | ||
<div class="flex-item-leading"> | ||
<img width="64" height="64" src="{{.Badge.ImageURL}}" alt="{{.Badge.Description}}" data-tooltip-content="{{.Badge.Description}}"> | ||
</div> | ||
{{end}} | ||
<div class="flex-item-main"> | ||
<div class="flex-item-title"> | ||
{{.Badge.Slug}} | ||
</div> | ||
<div class="flex-item-body"> | ||
{{.Badge.Description}} | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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.
Many "div" open/close tags misaligned, I think it's better to make the tags align correctly to make code readable.
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