Added setting to disable/enable link sharing
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
kolaente 2019-08-29 21:18:21 +02:00
parent a5a9fbb2d9
commit 43a0c7fce4
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 33 additions and 24 deletions

View File

@ -18,6 +18,8 @@ service:
enablemetrics: false
# Enable the caldav endpoint, see the docs for more details
enablecaldav: true
# Enable sharing of lists via a link
enablelinksharing: true
database:
# Database type to use. Supported types are mysql and sqlite.

View File

@ -61,6 +61,8 @@ service:
enablemetrics: false
# Enable the caldav endpoint, see the docs for more details
enablecaldav: true
# Enable sharing of lists via a link
enablelinksharing: true
database:
# Database type to use. Supported types are mysql and sqlite.

View File

@ -33,14 +33,15 @@ type Key string
// These constants hold all config value keys
const (
ServiceJWTSecret Key = `service.JWTSecret`
ServiceInterface Key = `service.interface`
ServiceFrontendurl Key = `service.frontendurl`
ServiceEnableCaldav Key = `service.enablecaldav`
ServiceRootpath Key = `service.rootpath`
ServicePageCount Key = `service.pagecount`
ServiceEnableMetrics Key = `service.enablemetrics`
ServiceMotd Key = `service.motd`
ServiceJWTSecret Key = `service.JWTSecret`
ServiceInterface Key = `service.interface`
ServiceFrontendurl Key = `service.frontendurl`
ServiceEnableCaldav Key = `service.enablecaldav`
ServiceRootpath Key = `service.rootpath`
ServicePageCount Key = `service.pagecount`
ServiceEnableMetrics Key = `service.enablemetrics`
ServiceMotd Key = `service.motd`
ServiceEnableLinkSharing Key = `service.enablelinksharing`
DatabaseType Key = `database.type`
DatabaseHost Key = `database.host`
@ -146,6 +147,7 @@ func InitConfig() {
ServicePageCount.setDefault(50)
ServiceEnableMetrics.setDefault(false)
ServiceMotd.setDefault("")
ServiceEnableLinkSharing.setDefault(true)
// Database
DatabaseType.setDefault("sqlite")

View File

@ -69,11 +69,11 @@ func (cv *CustomValidator) Validate(i interface{}) error {
}
httperr := models.ValidationHTTPError{
web.HTTPError{
HTTPError: web.HTTPError{
Code: models.ErrCodeInvalidData,
Message: "Invalid Data",
},
errs,
InvalidFields: errs,
}
return httperr
@ -110,16 +110,15 @@ func NewEcho() *echo.Echo {
// Handler config
handler.SetAuthProvider(&web.Auths{
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)
claims := jwtinf.Claims.(jwt.MapClaims)
typ := int(claims["type"].(float64))
switch typ {
case apiv1.AuthTypeUser:
return models.GetUserFromClaims(claims)
case apiv1.AuthTypeLinkShare:
if typ == apiv1.AuthTypeLinkShare && config.ServiceEnableLinkSharing.GetBool() {
return models.GetLinkShareFromClaims(claims)
}
if typ == apiv1.AuthTypeUser {
return models.GetUserFromClaims(claims)
}
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)
// Link share auth
a.POST("/shares/:share/auth", apiv1.AuthenticateLinkShare)
if config.ServiceEnableLinkSharing.GetBool() {
a.POST("/shares/:share/auth", apiv1.AuthenticateLinkShare)
}
// ===== Routes with Authetication =====
// Authetification
@ -209,15 +210,17 @@ func registerAPIRoutes(a *echo.Group) {
a.PUT("/namespaces/:namespace/lists", listHandler.CreateWeb)
a.GET("/lists/:list/listusers", apiv1.ListUsersForList)
listSharingHandler := &handler.WebHandler{
EmptyStruct: func() handler.CObject {
return &models.LinkSharing{}
},
if config.ServiceEnableLinkSharing.GetBool() {
listSharingHandler := &handler.WebHandler{
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{
EmptyStruct: func() handler.CObject {