Merge pull request #2766 from moltam/feature/delete-org-avatar
Added: Ability to delete org avatar.
This commit is contained in:
commit
922a6f13a3
5 changed files with 26 additions and 6 deletions
|
@ -368,6 +368,7 @@ func runWeb(ctx *cli.Context) {
|
||||||
m.Combo("").Get(org.Settings).
|
m.Combo("").Get(org.Settings).
|
||||||
Post(bindIgnErr(auth.UpdateOrgSettingForm{}), org.SettingsPost)
|
Post(bindIgnErr(auth.UpdateOrgSettingForm{}), org.SettingsPost)
|
||||||
m.Post("/avatar", binding.MultipartForm(auth.UploadAvatarForm{}), org.SettingsAvatar)
|
m.Post("/avatar", binding.MultipartForm(auth.UploadAvatarForm{}), org.SettingsAvatar)
|
||||||
|
m.Post("/avatar/delete", org.SettingsDeleteAvatar)
|
||||||
|
|
||||||
m.Group("/hooks", func() {
|
m.Group("/hooks", func() {
|
||||||
m.Get("", org.Webhooks)
|
m.Get("", org.Webhooks)
|
||||||
|
|
|
@ -346,6 +346,19 @@ func (u *User) UploadAvatar(data []byte) error {
|
||||||
return sess.Commit()
|
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.
|
// IsAdminOfRepo returns true if user has admin or higher access of repository.
|
||||||
func (u *User) IsAdminOfRepo(repo *Repository) bool {
|
func (u *User) IsAdminOfRepo(repo *Repository) bool {
|
||||||
has, err := HasAccess(u, repo, ACCESS_MODE_ADMIN)
|
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")
|
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) {
|
func SettingsDelete(ctx *middleware.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("org.settings")
|
ctx.Data["Title"] = ctx.Tr("org.settings")
|
||||||
ctx.Data["PageIsSettingsDelete"] = true
|
ctx.Data["PageIsSettingsDelete"] = true
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
|
@ -156,12 +155,10 @@ func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func SettingsDeleteAvatar(ctx *middleware.Context) {
|
func SettingsDeleteAvatar(ctx *middleware.Context) {
|
||||||
os.Remove(ctx.User.CustomAvatarPath())
|
if err := ctx.User.DeleteAvatar(); err != nil {
|
||||||
|
ctx.Flash.Error(err.Error())
|
||||||
ctx.User.UseCustomAvatar = false
|
|
||||||
if err := models.UpdateUser(ctx.User); err != nil {
|
|
||||||
ctx.Flash.Error(fmt.Sprintf("UpdateUser: %v", err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Redirect(setting.AppSubUrl + "/user/settings")
|
ctx.Redirect(setting.AppSubUrl + "/user/settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<button class="ui green button">{{$.i18n.Tr "settings.update_avatar"}}</button>
|
<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>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue