🐛 Fix new own share not being accessible

This commit is contained in:
Andreas Schneider 2020-11-01 15:22:59 +01:00
parent eced1e67f8
commit e5a996452d
2 changed files with 23 additions and 2 deletions

View File

@ -62,6 +62,6 @@
<a href="share-add-user?share={{ $share.UUID }}" class="share-add-user">Add User</a>
</div>
{{ end }}
<a href="create-share" class="create-share">Create Share</a>
<a href="create-share?owned=true" class="create-share">Create Share</a>
</div>
{{ end }}

View File

@ -477,11 +477,24 @@ Are you sure you want to continue?`, loginName)
ar.Route("/create-share", func(r chi.Router) {
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
sessionContext := h.buildSessionContext(w, r)
owned := r.FormValue("owned") == "true"
if !owned && sessionContext.user.Role != GlobalRoleAdmin {
sessionContext.Unauthorized()
return
}
sessionContext.RenderPage(h.tplCreateShare, nil)
})
r.Post("/", func(w http.ResponseWriter, r *http.Request) {
sessionContext := h.buildSessionContext(w, r)
owned := r.FormValue("owned") == "true"
if !owned && sessionContext.user.Role != GlobalRoleAdmin {
sessionContext.Unauthorized()
return
}
share, err := app.shareStore.CreateShare()
if err != nil {
sessionContext.RenderError(template.HTML("Cannot create share: "+err.Error()), "")
@ -496,7 +509,15 @@ Are you sure you want to continue?`, loginName)
return
}
if owned {
if err := app.shareStore.AddUserToShare(share, sessionContext.user.Username, ShareRoleAdmin); err != nil {
sessionContext.RenderError(template.HTML("Cannot add self to share: "+err.Error()), "")
return
}
sessionContext.Redirect("my-shares#share-" + share.UUID.String())
} else {
sessionContext.Redirect("shares#share-" + share.UUID.String())
}
})
})
ar.Post("/delete-share", func(w http.ResponseWriter, r *http.Request) {