Added setting to disable/enable link sharing
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
parent
a5a9fbb2d9
commit
43a0c7fce4
|
@ -18,6 +18,8 @@ service:
|
||||||
enablemetrics: false
|
enablemetrics: false
|
||||||
# Enable the caldav endpoint, see the docs for more details
|
# Enable the caldav endpoint, see the docs for more details
|
||||||
enablecaldav: true
|
enablecaldav: true
|
||||||
|
# Enable sharing of lists via a link
|
||||||
|
enablelinksharing: true
|
||||||
|
|
||||||
database:
|
database:
|
||||||
# Database type to use. Supported types are mysql and sqlite.
|
# Database type to use. Supported types are mysql and sqlite.
|
||||||
|
|
|
@ -61,6 +61,8 @@ service:
|
||||||
enablemetrics: false
|
enablemetrics: false
|
||||||
# Enable the caldav endpoint, see the docs for more details
|
# Enable the caldav endpoint, see the docs for more details
|
||||||
enablecaldav: true
|
enablecaldav: true
|
||||||
|
# Enable sharing of lists via a link
|
||||||
|
enablelinksharing: true
|
||||||
|
|
||||||
database:
|
database:
|
||||||
# Database type to use. Supported types are mysql and sqlite.
|
# Database type to use. Supported types are mysql and sqlite.
|
||||||
|
|
|
@ -33,14 +33,15 @@ type Key string
|
||||||
|
|
||||||
// These constants hold all config value keys
|
// These constants hold all config value keys
|
||||||
const (
|
const (
|
||||||
ServiceJWTSecret Key = `service.JWTSecret`
|
ServiceJWTSecret Key = `service.JWTSecret`
|
||||||
ServiceInterface Key = `service.interface`
|
ServiceInterface Key = `service.interface`
|
||||||
ServiceFrontendurl Key = `service.frontendurl`
|
ServiceFrontendurl Key = `service.frontendurl`
|
||||||
ServiceEnableCaldav Key = `service.enablecaldav`
|
ServiceEnableCaldav Key = `service.enablecaldav`
|
||||||
ServiceRootpath Key = `service.rootpath`
|
ServiceRootpath Key = `service.rootpath`
|
||||||
ServicePageCount Key = `service.pagecount`
|
ServicePageCount Key = `service.pagecount`
|
||||||
ServiceEnableMetrics Key = `service.enablemetrics`
|
ServiceEnableMetrics Key = `service.enablemetrics`
|
||||||
ServiceMotd Key = `service.motd`
|
ServiceMotd Key = `service.motd`
|
||||||
|
ServiceEnableLinkSharing Key = `service.enablelinksharing`
|
||||||
|
|
||||||
DatabaseType Key = `database.type`
|
DatabaseType Key = `database.type`
|
||||||
DatabaseHost Key = `database.host`
|
DatabaseHost Key = `database.host`
|
||||||
|
@ -146,6 +147,7 @@ func InitConfig() {
|
||||||
ServicePageCount.setDefault(50)
|
ServicePageCount.setDefault(50)
|
||||||
ServiceEnableMetrics.setDefault(false)
|
ServiceEnableMetrics.setDefault(false)
|
||||||
ServiceMotd.setDefault("")
|
ServiceMotd.setDefault("")
|
||||||
|
ServiceEnableLinkSharing.setDefault(true)
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
DatabaseType.setDefault("sqlite")
|
DatabaseType.setDefault("sqlite")
|
||||||
|
|
|
@ -69,11 +69,11 @@ func (cv *CustomValidator) Validate(i interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
httperr := models.ValidationHTTPError{
|
httperr := models.ValidationHTTPError{
|
||||||
web.HTTPError{
|
HTTPError: web.HTTPError{
|
||||||
Code: models.ErrCodeInvalidData,
|
Code: models.ErrCodeInvalidData,
|
||||||
Message: "Invalid Data",
|
Message: "Invalid Data",
|
||||||
},
|
},
|
||||||
errs,
|
InvalidFields: errs,
|
||||||
}
|
}
|
||||||
|
|
||||||
return httperr
|
return httperr
|
||||||
|
@ -110,16 +110,15 @@ func NewEcho() *echo.Echo {
|
||||||
// Handler config
|
// Handler config
|
||||||
handler.SetAuthProvider(&web.Auths{
|
handler.SetAuthProvider(&web.Auths{
|
||||||
AuthObject: func(c echo.Context) (web.Auth, error) {
|
AuthObject: func(c echo.Context) (web.Auth, error) {
|
||||||
// TODO: make a switch to determine if this is a user or a link share
|
|
||||||
jwtinf := c.Get("user").(*jwt.Token)
|
jwtinf := c.Get("user").(*jwt.Token)
|
||||||
claims := jwtinf.Claims.(jwt.MapClaims)
|
claims := jwtinf.Claims.(jwt.MapClaims)
|
||||||
typ := int(claims["type"].(float64))
|
typ := int(claims["type"].(float64))
|
||||||
switch typ {
|
if typ == apiv1.AuthTypeLinkShare && config.ServiceEnableLinkSharing.GetBool() {
|
||||||
case apiv1.AuthTypeUser:
|
|
||||||
return models.GetUserFromClaims(claims)
|
|
||||||
case apiv1.AuthTypeLinkShare:
|
|
||||||
return models.GetLinkShareFromClaims(claims)
|
return models.GetLinkShareFromClaims(claims)
|
||||||
}
|
}
|
||||||
|
if typ == apiv1.AuthTypeUser {
|
||||||
|
return models.GetUserFromClaims(claims)
|
||||||
|
}
|
||||||
return nil, echo.NewHTTPError(http.StatusBadRequest, models.Message{Message: "Invalid JWT token."})
|
return nil, echo.NewHTTPError(http.StatusBadRequest, models.Message{Message: "Invalid JWT token."})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -178,7 +177,9 @@ func registerAPIRoutes(a *echo.Group) {
|
||||||
a.GET("/info", apiv1.Info)
|
a.GET("/info", apiv1.Info)
|
||||||
|
|
||||||
// Link share auth
|
// Link share auth
|
||||||
a.POST("/shares/:share/auth", apiv1.AuthenticateLinkShare)
|
if config.ServiceEnableLinkSharing.GetBool() {
|
||||||
|
a.POST("/shares/:share/auth", apiv1.AuthenticateLinkShare)
|
||||||
|
}
|
||||||
|
|
||||||
// ===== Routes with Authetication =====
|
// ===== Routes with Authetication =====
|
||||||
// Authetification
|
// Authetification
|
||||||
|
@ -209,15 +210,17 @@ func registerAPIRoutes(a *echo.Group) {
|
||||||
a.PUT("/namespaces/:namespace/lists", listHandler.CreateWeb)
|
a.PUT("/namespaces/:namespace/lists", listHandler.CreateWeb)
|
||||||
a.GET("/lists/:list/listusers", apiv1.ListUsersForList)
|
a.GET("/lists/:list/listusers", apiv1.ListUsersForList)
|
||||||
|
|
||||||
listSharingHandler := &handler.WebHandler{
|
if config.ServiceEnableLinkSharing.GetBool() {
|
||||||
EmptyStruct: func() handler.CObject {
|
listSharingHandler := &handler.WebHandler{
|
||||||
return &models.LinkSharing{}
|
EmptyStruct: func() handler.CObject {
|
||||||
},
|
return &models.LinkSharing{}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
a.PUT("/lists/:list/shares", listSharingHandler.CreateWeb)
|
||||||
|
a.GET("/lists/:list/shares", listSharingHandler.ReadAllWeb)
|
||||||
|
a.GET("/lists/:list/shares/:share", listSharingHandler.ReadOneWeb)
|
||||||
|
a.DELETE("/lists/:list/shares/:share", listSharingHandler.DeleteWeb)
|
||||||
}
|
}
|
||||||
a.PUT("/lists/:list/shares", listSharingHandler.CreateWeb)
|
|
||||||
a.GET("/lists/:list/shares", listSharingHandler.ReadAllWeb)
|
|
||||||
a.GET("/lists/:list/shares/:share", listSharingHandler.ReadOneWeb)
|
|
||||||
a.DELETE("/lists/:list/shares/:share", listSharingHandler.DeleteWeb)
|
|
||||||
|
|
||||||
taskHandler := &handler.WebHandler{
|
taskHandler := &handler.WebHandler{
|
||||||
EmptyStruct: func() handler.CObject {
|
EmptyStruct: func() handler.CObject {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user