mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-05-07 20:59:37 -05:00
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package fs
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/shroff/phylum/server/internal/api/authenticator"
|
|
"github.com/shroff/phylum/server/internal/api/v1/responses"
|
|
"github.com/shroff/phylum/server/internal/core"
|
|
"github.com/shroff/phylum/server/internal/core/user"
|
|
)
|
|
|
|
type shareParams struct {
|
|
Path string `json:"path" form:"path" binding:"required"`
|
|
Email string `json:"email" form:"email" binding:"required"`
|
|
Permission core.Permission `json:"permission" form:"permission"`
|
|
}
|
|
|
|
func handleShareRequest(c *gin.Context) {
|
|
var params shareParams
|
|
err := c.ShouldBind(¶ms)
|
|
if err != nil {
|
|
err = c.BindQuery(¶ms)
|
|
if err != nil {
|
|
panic(errInvalidParams)
|
|
}
|
|
}
|
|
|
|
fs := authenticator.GetFileSystem(c)
|
|
r, err := fs.ResourceByPathWithRoot(params.Path)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
user, err := user.ManagerFromContext(c).UserByEmail(params.Email)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
r, err = fs.UpdatePermissions(r, user.ID, params.Permission)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
c.JSON(200, responses.ResourceFromFS(r))
|
|
}
|