Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
161 lines
2.5 KiB
Go
161 lines
2.5 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func (s *Server) handleLinkManager(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
|
|
objectUUID := ""
|
|
|
|
if strings.HasPrefix(r.URL.Path, "/l/uuid:") {
|
|
|
|
objectUUID =
|
|
strings.TrimPrefix(
|
|
r.URL.Path,
|
|
"/l/uuid:",
|
|
)
|
|
}
|
|
|
|
if objectUUID == "" {
|
|
|
|
http.NotFound(
|
|
w,
|
|
r,
|
|
)
|
|
|
|
return
|
|
}
|
|
|
|
if r.Method == http.MethodPost {
|
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
|
http.Error(w, err.Error(), 400)
|
|
return
|
|
}
|
|
|
|
action :=
|
|
r.FormValue(
|
|
"action",
|
|
)
|
|
|
|
path :=
|
|
strings.TrimSpace(
|
|
r.FormValue("path"),
|
|
)
|
|
if s.authorizeObjectForRequest(r, "link", objectUUID) != nil {
|
|
http.Error(w, "forbidden", http.StatusForbidden)
|
|
return
|
|
}
|
|
|
|
switch action {
|
|
|
|
case "add":
|
|
|
|
if path == "" {
|
|
http.Error(w, "path is required", 400)
|
|
return
|
|
}
|
|
|
|
if !strings.HasPrefix(path, "/") {
|
|
path = "/" + path
|
|
}
|
|
if s.authorizePathRequest(r, "link", path) != nil || s.authorizePathRequest(r, "create", path) != nil {
|
|
http.Error(w, "forbidden", http.StatusForbidden)
|
|
return
|
|
}
|
|
|
|
err = s.store.AddPathLinkInDomain(
|
|
s.domainUUIDForRequest(r),
|
|
objectUUID,
|
|
path,
|
|
)
|
|
|
|
case "delete":
|
|
if s.authorizePathRequest(r, "link", path) != nil {
|
|
http.Error(w, "forbidden", http.StatusForbidden)
|
|
return
|
|
}
|
|
|
|
err = s.store.DeletePathLinkInDomain(
|
|
s.domainUUIDForRequest(r),
|
|
objectUUID,
|
|
path,
|
|
)
|
|
|
|
case "primary":
|
|
if s.authorizePathRequest(r, "link", path) != nil {
|
|
http.Error(w, "forbidden", http.StatusForbidden)
|
|
return
|
|
}
|
|
|
|
err = s.store.SetPrimaryPathLinkInDomain(
|
|
s.domainUUIDForRequest(r),
|
|
objectUUID,
|
|
path,
|
|
)
|
|
|
|
default:
|
|
|
|
http.Error(w, "unknown action", 400)
|
|
return
|
|
}
|
|
|
|
if err != nil {
|
|
http.Error(w, err.Error(), 500)
|
|
return
|
|
}
|
|
|
|
http.Redirect(
|
|
w,
|
|
r,
|
|
"/l/uuid:"+objectUUID,
|
|
http.StatusFound,
|
|
)
|
|
|
|
return
|
|
}
|
|
|
|
links, err :=
|
|
s.store.ListPathLinksInDomain(
|
|
s.domainUUIDForRequest(r),
|
|
objectUUID,
|
|
)
|
|
|
|
if err != nil {
|
|
http.Error(w, err.Error(), 500)
|
|
return
|
|
}
|
|
visibleLinks := links[:0]
|
|
for _, link := range links {
|
|
if s.requestCanReadPath(r, link.Path) {
|
|
visibleLinks = append(visibleLinks, link)
|
|
}
|
|
}
|
|
links = visibleLinks
|
|
|
|
s.renderWithContext(
|
|
w,
|
|
r,
|
|
"link_manager.gohtml",
|
|
map[string]any{
|
|
"NavItems": resolveNavItems(
|
|
s.getSystemNavItems(s.domainUUIDForRequest(r)),
|
|
NavContext{
|
|
ObjectUUID: objectUUID,
|
|
ObjectURI: "uuid:" + objectUUID,
|
|
},
|
|
),
|
|
"ObjectUUID": objectUUID,
|
|
"ObjectURI": "uuid:" + objectUUID,
|
|
"Links": links,
|
|
},
|
|
)
|
|
}
|