mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 05:36:16 +00:00
Support delete user email in admin panel (#31690)
![QQ_1721784609320](https://github.com/user-attachments/assets/23f08bf3-93f4-44d7-963d-10380ef8c1f1) ![QQ_1721784616403](https://github.com/user-attachments/assets/667cbd1e-5e21-4489-8d18-2a7be85190db) ![QQ_1721784626722](https://github.com/user-attachments/assets/495beb94-dfa2-481c-aa60-d5115cad1ae1) --------- Co-authored-by: Jason Song <i@wolfogre.com> (cherry picked from commit cc044818c33ff066c4e5869c9e75de9707def6ed)
This commit is contained in:
parent
3d1b8f47c0
commit
d0e52fd641
|
@ -350,6 +350,7 @@ type SearchEmailOptions struct {
|
|||
|
||||
// SearchEmailResult is an e-mail address found in the user or email_address table
|
||||
type SearchEmailResult struct {
|
||||
ID int64
|
||||
UID int64
|
||||
Email string
|
||||
IsActivated bool
|
||||
|
|
|
@ -3094,6 +3094,10 @@ emails.not_updated = Failed to update the requested email address: %v
|
|||
emails.duplicate_active = This email address is already active for a different user.
|
||||
emails.change_email_header = Update Email Properties
|
||||
emails.change_email_text = Are you sure you want to update this email address?
|
||||
emails.delete = Delete Email
|
||||
emails.delete_desc = Are you sure you want to delete this email address?
|
||||
emails.deletion_success = The email address has been deleted.
|
||||
emails.delete_primary_email_error = You can not delete the primary email.
|
||||
|
||||
orgs.org_manage_panel = Manage organizations
|
||||
orgs.name = Name
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/optional"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
"code.gitea.io/gitea/services/user"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -150,3 +151,32 @@ func ActivateEmail(ctx *context.Context) {
|
|||
redirect.RawQuery = q.Encode()
|
||||
ctx.Redirect(redirect.String())
|
||||
}
|
||||
|
||||
// DeleteEmail serves a POST request for delete a user's email
|
||||
func DeleteEmail(ctx *context.Context) {
|
||||
u, err := user_model.GetUserByID(ctx, ctx.FormInt64("Uid"))
|
||||
if err != nil || u == nil {
|
||||
ctx.ServerError("GetUserByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
email, err := user_model.GetEmailAddressByID(ctx, u.ID, ctx.FormInt64("id"))
|
||||
if err != nil || email == nil {
|
||||
ctx.ServerError("GetEmailAddressByID", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := user.DeleteEmailAddresses(ctx, u, []string{email.Email}); err != nil {
|
||||
if user_model.IsErrPrimaryEmailCannotDelete(err) {
|
||||
ctx.Flash.Error(ctx.Tr("admin.emails.delete_primary_email_error"))
|
||||
ctx.JSONRedirect("")
|
||||
return
|
||||
}
|
||||
ctx.ServerError("DeleteEmailAddresses", err)
|
||||
return
|
||||
}
|
||||
log.Trace("Email address deleted: %s %s", u.Name, email.Email)
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("admin.emails.deletion_success"))
|
||||
ctx.JSONRedirect("")
|
||||
}
|
||||
|
|
|
@ -696,6 +696,7 @@ func registerRoutes(m *web.Route) {
|
|||
m.Group("/emails", func() {
|
||||
m.Get("", admin.Emails)
|
||||
m.Post("/activate", admin.ActivateEmail)
|
||||
m.Post("/delete", admin.DeleteEmail)
|
||||
})
|
||||
|
||||
m.Group("/orgs", func() {
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
</th>
|
||||
<th>{{ctx.Locale.Tr "admin.emails.primary"}}</th>
|
||||
<th>{{ctx.Locale.Tr "admin.emails.activated"}}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -59,6 +60,11 @@
|
|||
{{if .IsActivated}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
|
||||
{{end}}
|
||||
</td>
|
||||
<td>
|
||||
<div class="tw-flex tw-gap-2">
|
||||
<a class="delete-button" href="" data-url="{{$.Link}}/delete" data-id="{{.ID}}" data-data-uid="{{.UID}}">{{svg "octicon-trash"}}</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
|
@ -95,4 +101,16 @@
|
|||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="ui g-modal-confirm delete modal">
|
||||
<div class="header">
|
||||
{{svg "octicon-trash"}}
|
||||
{{ctx.Locale.Tr "admin.emails.delete"}}
|
||||
</div>
|
||||
<div class="content">
|
||||
{{ctx.Locale.Tr "admin.emails.delete_desc"}}
|
||||
</div>
|
||||
{{template "base/modal_actions_confirm" .}}
|
||||
</div>
|
||||
|
||||
{{template "admin/layout_footer" .}}
|
||||
|
|
Loading…
Reference in a new issue