Skip to content
Snippets Groups Projects
Verified Commit a7cc51d3 authored by Gabriel Zachmann's avatar Gabriel Zachmann
Browse files

improve code

parent 0668d04f
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ type MytokenEntry struct {
// MytokenEntryTree is a tree of MytokenEntry
type MytokenEntryTree struct {
Token MytokenEntry `json:"token"`
Token *MytokenEntry `json:"token"`
Children []MytokenEntryTree `json:"children,omitempty"`
}
......@@ -64,7 +64,7 @@ func TokenSubTree(rlog log.Ext1FieldLogger, tx *sqlx.Tx, tokenID mtid.MTID) (Myt
break
}
}
tree, _ := tokensToTree(root, tokens)
tree, _ := tokensToTree(&root, tokens)
return tree, nil
}
......@@ -81,26 +81,26 @@ func tokensToTrees(tokens []MytokenEntry) (trees []MytokenEntryTree) {
}
var tmp MytokenEntryTree
for _, r := range roots {
tmp, tokens = tokensToTree(r, tokens)
tmp, tokens = tokensToTree(&r, tokens)
trees = append(trees, tmp)
}
return
}
func tokensToTree(root MytokenEntry, tokens []MytokenEntry) (MytokenEntryTree, []MytokenEntry) {
func tokensToTree(root *MytokenEntry, tokens []MytokenEntry) (MytokenEntryTree, []MytokenEntry) {
tree := MytokenEntryTree{
Token: root,
}
children := popChildren(root, &tokens)
var cTree MytokenEntryTree
for _, c := range children {
cTree, tokens = tokensToTree(c, tokens)
cTree, tokens = tokensToTree(&c, tokens)
tree.Children = append(tree.Children, cTree)
}
return tree, tokens
}
func popChildren(root MytokenEntry, tokens *[]MytokenEntry) (children []MytokenEntry) {
func popChildren(root *MytokenEntry, tokens *[]MytokenEntry) (children []MytokenEntry) {
i := 0
for i < len(*tokens) {
t := (*tokens)[i]
......
......@@ -168,11 +168,13 @@ func (c webCapability) getDangerLevel() int {
}
// ColorClass returns the html class for coloring this Capability
// skipcq: CRT-P0003
func (c webCapability) ColorClass() string {
return textColorByDanger(c.getDangerLevel())
}
// CapabilityLevel returns a string describing the power of this capability
// skipcq: CRT-P0003
func (c webCapability) CapabilityLevel() string {
intClass := c.getIntClass()
switch intClass {
......@@ -187,6 +189,7 @@ func (c webCapability) CapabilityLevel() string {
}
// IsCreateMT checks if this WebCapability is api.CapabilityCreateMT
// skipcq: CRT-P0003
func (c WebCapability) IsCreateMT() bool {
return c.ReadWriteCapability.Name == api.CapabilityCreateMT.Name
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment