summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/web.go1
-rw-r--r--models/user.go13
-rw-r--r--routers/org/setting.go8
-rw-r--r--routers/user/setting.go9
-rw-r--r--templates/org/settings/options.tmpl1
5 files changed, 26 insertions, 6 deletions
diff --git a/cmd/web.go b/cmd/web.go
index 5092fc2b63..e839e37a58 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -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)
diff --git a/models/user.go b/models/user.go
index bd4cace44d..8b90687e32 100644
--- a/models/user.go
+++ b/models/user.go
@@ -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)
diff --git a/routers/org/setting.go b/routers/org/setting.go
index 0b1b512d34..29ce34f5d9 100644
--- a/routers/org/setting.go
+++ b/routers/org/setting.go
@@ -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
diff --git a/routers/user/setting.go b/routers/user/setting.go
index 8d1b24dd8c..c704b67ce0 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -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")
}
diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl
index 64be63b7ef..8041365434 100644
--- a/templates/org/settings/options.tmpl
+++ b/templates/org/settings/options.tmpl
@@ -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>