From 0487889963553c29858d41958e28e4a59b0d33d1 Mon Sep 17 00:00:00 2001 From: konrad Date: Sat, 21 Jul 2018 15:28:09 +0200 Subject: [PATCH] fmt + lint + docs --- Featurecreep.md | 4 ++-- models/team_namespace_readall.go | 5 +++-- models/team_namespace_rights.go | 2 +- routes/crud/paramBinder.go | 17 ++++++++++++++--- routes/crud/read_one.go | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Featurecreep.md b/Featurecreep.md index 6304c04992..a3b814407e 100644 --- a/Featurecreep.md +++ b/Featurecreep.md @@ -108,12 +108,12 @@ Teams sind global, d.h. Ein Team kann mehrere Namespaces verwalten. ~~Ein zu lösendes Problem: Wie regelt man die Berechtigungen um Teams zu verwalten?~~ -* [ ] Namespaces +* [x] Namespaces * [x] Erstellen * [x] Ansehen * [x] Bearbeiten * [x] Löschen - * [ ] Teams hinzufügen. Der Nutzer kriegt nur Teams angezeigt die er erstellt hat. + * [x] Teams hinzufügen. Der Nutzer kriegt nur Teams angezeigt die er erstellt hat. * [x] Alle Listen eines Namespaces anzeigen * [x] Listen * [x] Listen zu einem Namespace hinzufügen diff --git a/models/team_namespace_readall.go b/models/team_namespace_readall.go index 2ac2e8af48..08b54082ac 100644 --- a/models/team_namespace_readall.go +++ b/models/team_namespace_readall.go @@ -1,5 +1,6 @@ package models +// ReadAll implements the method to read all teams of a namespace func (tn *TeamNamespace) ReadAll(user *User) (interface{}, error) { // Check if the user can read the namespace n, err := GetNamespaceByID(tn.NamespaceID) @@ -7,7 +8,7 @@ func (tn *TeamNamespace) ReadAll(user *User) (interface{}, error) { return nil, err } if !n.CanRead(user) { - return nil, ErrNeedToHaveNamespaceReadAccess{NamespaceID:tn.NamespaceID, UserID:user.ID} + return nil, ErrNeedToHaveNamespaceReadAccess{NamespaceID: tn.NamespaceID, UserID: user.ID} } // Get the teams @@ -20,4 +21,4 @@ func (tn *TeamNamespace) ReadAll(user *User) (interface{}, error) { Find(&all) return all, err -} \ No newline at end of file +} diff --git a/models/team_namespace_rights.go b/models/team_namespace_rights.go index d58fa359e7..9d832244b9 100644 --- a/models/team_namespace_rights.go +++ b/models/team_namespace_rights.go @@ -10,4 +10,4 @@ func (tn *TeamNamespace) CanCreate(user *User) bool { func (tn *TeamNamespace) CanDelete(user *User) bool { n, _ := GetNamespaceByID(tn.NamespaceID) return n.IsAdmin(user) -} \ No newline at end of file +} diff --git a/routes/crud/paramBinder.go b/routes/crud/paramBinder.go index 6809f52065..2c774be16a 100644 --- a/routes/crud/paramBinder.go +++ b/routes/crud/paramBinder.go @@ -10,6 +10,18 @@ import ( const paramTagName = "param" +///////////////////////// +// HOW THIS BINDER WORKS +///////////////////////// +// This binder binds all values inside the url to their respective fields in a struct. Those fields need to have a tag +// "param" with the name of the url placeholder which must be the same as in routes. +// +// Whenever one of the standard CRUD methods is invoked, this binder is called, which enables one handler method +// to handle all kinds of different urls with different parameters. +///////////////////////// + +// ParamBinder binds parameters to a struct. +// Currently a working implementation, waiting to implement this officially into echo. func ParamBinder(i interface{}, c echo.Context) (err error) { // Default binder @@ -77,9 +89,7 @@ func ParamBinder(i interface{}, c echo.Context) (err error) { return } -// This is kind of ugly, more a "feature proof", copied from the echo source code. -// Workaround until the pr to implement this nativly in echo is merged. - +// Binder represents a binder type Binder struct{} func (b *Binder) bindData(ptr interface{}, data map[string][]string, tag string) error { @@ -227,6 +237,7 @@ func setFloatField(value string, bitSize int, field reflect.Value) error { return err } +// BindUnmarshaler type type BindUnmarshaler interface { // UnmarshalParam decodes and assigns a value from an form or query param. UnmarshalParam(param string) error diff --git a/routes/crud/read_one.go b/routes/crud/read_one.go index 2ffb69b064..73eda9b44e 100644 --- a/routes/crud/read_one.go +++ b/routes/crud/read_one.go @@ -1,10 +1,10 @@ package crud import ( + "fmt" "git.kolaente.de/konrad/list/models" "github.com/labstack/echo" "net/http" - "fmt" ) // ReadOneWeb is the webhandler to get one object