From c6f44766c2d7c3143d0c42770378f0a27ce2b167 Mon Sep 17 00:00:00 2001 From: Jan Halfar Date: Wed, 1 Oct 2014 14:54:30 +0200 Subject: [PATCH 1/4] log level fix --- server/log/log.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/log/log.go b/server/log/log.go index 7a6ae9f..5922d64 100644 --- a/server/log/log.go +++ b/server/log/log.go @@ -59,7 +59,7 @@ func log(msg string, level int) string { } func SetLogLevel(level int) bool { - if level > LOG_LEVEL_ERROR && level <= LOG_LEVEL_DEBUG { + if level >= LOG_LEVEL_ERROR && level <= LOG_LEVEL_DEBUG { logLevel = level return true } else { From d31f10ef33d4542c42b45b0594de144bb0e4ee8e Mon Sep 17 00:00:00 2001 From: Jan Halfar Date: Wed, 1 Oct 2014 14:57:41 +0200 Subject: [PATCH 2/4] code clean up and fix of access rule for groups : allowing access, if nodes groups are empty --- server/repo/content/repoNode.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/server/repo/content/repoNode.go b/server/repo/content/repoNode.go index 1d10f3e..ca21cc7 100644 --- a/server/repo/content/repoNode.go +++ b/server/repo/content/repoNode.go @@ -57,19 +57,18 @@ func (node *RepoNode) InPath(path []*Item) bool { } func (node *RepoNode) InState(state string) bool { - if(len(node.States) == 0) { + if len(node.States) == 0 { return true } else { for _, nodeState := range node.States { - if(state == nodeState) { + if state == nodeState { return true } } - return false; + return false } } - func (node *RepoNode) InRegion(region string) bool { for _, nodeRegion := range node.Regions { if nodeRegion == region { @@ -148,7 +147,7 @@ func (node *RepoNode) IsOneOfTheseMimeTypes(mimeTypes []string) bool { } func (node *RepoNode) CanBeAccessedByGroups(groups []string) bool { - if len(groups) == 0 { + if len(groups) == 0 || len(node.Groups) == 0 { return true } else { // @todo is there sth like in_array ... or some array intersection From 74cee00dc041e1e71073b53e95a4ecabc5c1ba60 Mon Sep 17 00:00:00 2001 From: Jan Halfar Date: Wed, 1 Oct 2014 14:59:23 +0200 Subject: [PATCH 3/4] added public interface to load a node as an object --- server/repo/repo.go | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/server/repo/repo.go b/server/repo/repo.go index d27f4df..bfaa874 100644 --- a/server/repo/repo.go +++ b/server/repo/repo.go @@ -31,7 +31,7 @@ func (repo *Repo) ResolveContent(state string, URI string) (resolved bool, resol parts := strings.Split(URI, content.PATH_SEPARATOR) log.Debug("repo.ResolveContent: " + URI) for i := len(parts); i > -1; i-- { - testURI := strings.Join(parts[0:i], content.PATH_SEPARATOR) + testURI := strings.Join(parts[0:i], content.PATH_SEPARATOR) testURIKey := uriKeyForState(state, testURI) log.Debug(" testing" + testURIKey) if repoNode, ok := repo.URIDirectory[testURIKey]; ok { @@ -175,7 +175,7 @@ func (repo *Repo) GetRepo() *content.RepoNode { } func uriKeyForState(state string, uri string) string { - return state + "-" + uri; + return state + "-" + uri } func builDirectory(dirNode *content.RepoNode, directory map[string]*content.RepoNode, uRIDirectory map[string]*content.RepoNode) { @@ -210,6 +210,23 @@ func wireAliases(directory map[string]*content.RepoNode) { } } +func (repo *Repo) Load(newNode *content.RepoNode) { + newNode.WireParents() + + newDirectory := make(map[string]*content.RepoNode) + newURIDirectory := make(map[string]*content.RepoNode) + + builDirectory(newNode, newDirectory, newURIDirectory) + wireAliases(newDirectory) + + // some more validation anyone? + // invalid destination ids + + repo.Node = newNode + repo.Directory = newDirectory + repo.URIDirectory = newURIDirectory +} + func (repo *Repo) Update() *responses.Update { updateResponse := responses.NewUpdate() @@ -221,22 +238,7 @@ func (repo *Repo) Update() *responses.Update { startTimeOwn := time.Now() updateResponse.Success = ok if ok { - - newNode.WireParents() - - newDirectory := make(map[string]*content.RepoNode) - newURIDirectory := make(map[string]*content.RepoNode) - - builDirectory(newNode, newDirectory, newURIDirectory) - wireAliases(newDirectory) - - // some more validation anyone? - // invalid destination ids - - repo.Node = newNode - repo.Directory = newDirectory - repo.URIDirectory = newURIDirectory - + repo.Load(newNode) updateResponse.Stats.NumberOfNodes = len(repo.Directory) updateResponse.Stats.NumberOfURIs = len(repo.URIDirectory) } else { From 3bf59e0f6e398597f4dcb2a150feb74f3b5b1217 Mon Sep 17 00:00:00 2001 From: Jan Halfar Date: Wed, 1 Oct 2014 15:00:02 +0200 Subject: [PATCH 4/4] extracted Defaults struct from Env --- server/requests/requests.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/server/requests/requests.go b/server/requests/requests.go index df3e170..4c0c2a4 100644 --- a/server/requests/requests.go +++ b/server/requests/requests.go @@ -1,13 +1,15 @@ package requests +type Defaults struct { + Region string `json:"region"` + Language string `json:"language"` +} + type Env struct { - Defaults struct { - Region string `json:"region"` - Language string `json:"language"` - } `json:"defaults"` - Groups []string `json:"groups"` - State string - Data interface{} `json:"data"` + Defaults *Defaults `json:"defaults"` + Groups []string `json:"groups"` + State string + Data interface{} `json:"data"` } type Node struct {