aboutsummaryrefslogtreecommitdiff
path: root/imgs.go
diff options
context:
space:
mode:
authorJulian Hurst <ark@mansus.space>2023-01-25 01:23:58 +0100
committerJulian Hurst <ark@mansus.space>2023-01-25 01:23:58 +0100
commitf416775268085c7fb7f90cf54ea2149267b960e6 (patch)
treed7e38e94795368f39cda882cd61c16b01eb56dd3 /imgs.go
parente7a3649280d20d9b4f68572721684a01049ec40f (diff)
downloaddocspace-f416775268085c7fb7f90cf54ea2149267b960e6.tar.gz
Add user impersonation support for admins
Diffstat (limited to 'imgs.go')
-rw-r--r--imgs.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/imgs.go b/imgs.go
index 78705ca..4ee448b 100644
--- a/imgs.go
+++ b/imgs.go
@@ -17,6 +17,13 @@ const pageSize = 5
func imgs(w http.ResponseWriter, r *http.Request) {
u, err := checkSession(w, r)
if u != nil && err == nil {
+ username := u.Username
+ if u.IsAdmin {
+ name := r.URL.Query().Get("user")
+ if name != "" {
+ username = name
+ }
+ }
fragment := r.URL.Query().Has("fragment")
pageQuery := r.URL.Query().Get("page")
if pageQuery == "" {
@@ -27,7 +34,7 @@ func imgs(w http.ResponseWriter, r *http.Request) {
sendError(w, r, err.Error(), http.StatusInternalServerError)
return
}
- userDocPath := filepath.Join(baseDocDir, u.Username)
+ userDocPath := filepath.Join(baseDocDir, username)
err = os.Mkdir(userDocPath, 0750)
if err != nil && !os.IsExist(err) {
sendError(w, r, err.Error(), http.StatusInternalServerError)
@@ -67,6 +74,7 @@ func imgs(w http.ResponseWriter, r *http.Request) {
start = len(imgs)
}
flasherr := consumeFlash(w, r, "error")
+ userImpersonation := r.URL.Query().Get("user")
data := struct {
Imgs []Doc
Start int
@@ -74,6 +82,7 @@ func imgs(w http.ResponseWriter, r *http.Request) {
NbFiles int
Page int
Error string
+ UserImpersonation string
}{
imgs[start:end],
start + 1,
@@ -81,6 +90,7 @@ func imgs(w http.ResponseWriter, r *http.Request) {
len(imgs),
page,
flasherr,
+ userImpersonation,
}
if fragment {
//serveSimple(w, r, data, "templates/imgs_stub.html")
@@ -92,7 +102,7 @@ func imgs(w http.ResponseWriter, r *http.Request) {
} else if err != nil {
log.Println(err)
}
- sendFlash(w, r, "redirect", "/imgs")
+ sendFlash(w, r, "redirect", r.URL.String())
http.Redirect(w, r, "/login", http.StatusSeeOther)
}