Added: Ability to delete org avatar.
This commit is contained in:
Родитель
c2ca103d30
Коммит
9c91e27933
|
@ -368,6 +368,7 @@ func runWeb(ctx *cli.Context) {
|
|||
m.Combo("").Get(org.Settings).
|
||||
Post(bindIgnErr(auth.UpdateOrgSettingForm{}), org.SettingsPost)
|
||||
m.Post("/avatar", binding.MultipartForm(auth.UploadAvatarForm{}), org.SettingsAvatar)
|
||||
m.Post("/avatar/delete", org.SettingsDeleteAvatar)
|
||||
|
||||
m.Group("/hooks", func() {
|
||||
m.Get("", org.Webhooks)
|
||||
|
|
|
@ -346,6 +346,19 @@ func (u *User) UploadAvatar(data []byte) error {
|
|||
return sess.Commit()
|
||||
}
|
||||
|
||||
// DeleteAvatar deletes the user's custom avatar.
|
||||
func (u *User) DeleteAvatar() error {
|
||||
log.Info("Deleting user avatar: %s", u.CustomAvatarPath())
|
||||
os.Remove(u.CustomAvatarPath())
|
||||
|
||||
u.UseCustomAvatar = false
|
||||
if err := UpdateUser(u); err != nil {
|
||||
return fmt.Errorf("updateUser: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsAdminOfRepo returns true if user has admin or higher access of repository.
|
||||
func (u *User) IsAdminOfRepo(repo *Repository) bool {
|
||||
has, err := HasAccess(u, repo, ACCESS_MODE_ADMIN)
|
||||
|
|
|
@ -96,6 +96,14 @@ func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
|
|||
ctx.Redirect(ctx.Org.OrgLink + "/settings")
|
||||
}
|
||||
|
||||
func SettingsDeleteAvatar(ctx *middleware.Context) {
|
||||
if err := ctx.Org.Organization.DeleteAvatar(); err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
}
|
||||
|
||||
ctx.Redirect(ctx.Org.OrgLink + "/settings")
|
||||
}
|
||||
|
||||
func SettingsDelete(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("org.settings")
|
||||
ctx.Data["PageIsSettingsDelete"] = true
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Unknwon/com"
|
||||
|
@ -156,12 +155,10 @@ func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
|
|||
}
|
||||
|
||||
func SettingsDeleteAvatar(ctx *middleware.Context) {
|
||||
os.Remove(ctx.User.CustomAvatarPath())
|
||||
|
||||
ctx.User.UseCustomAvatar = false
|
||||
if err := models.UpdateUser(ctx.User); err != nil {
|
||||
ctx.Flash.Error(fmt.Sprintf("UpdateUser: %v", err))
|
||||
if err := ctx.User.DeleteAvatar(); err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
}
|
||||
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/settings")
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
|
||||
<div class="field">
|
||||
<button class="ui green button">{{$.i18n.Tr "settings.update_avatar"}}</button>
|
||||
<a class="ui red button delete-post" data-request-url="{{.Link}}/avatar/delete" data-done-url="{{.Link}}">{{$.i18n.Tr "settings.delete_current_avatar"}}</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
Загрузка…
Ссылка в новой задаче