Refactor authentication & authorization modules

This commit is contained in:
cuigh
2018-02-24 12:26:38 +08:00
parent 81081c8164
commit 5b60a024c5
14 changed files with 340 additions and 335 deletions

View File

@@ -2,6 +2,7 @@ package controller
import (
"github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/data/set"
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz"
"github.com/cuigh/swirl/model"
@@ -21,11 +22,7 @@ func permEdit(ctx web.Context, resType, resID, tpl string, m data.Map) error {
return err
}
checkedRoles := data.Set{}
checkedRoles.AddSlice(perm.Roles, func(i int) interface{} {
return perm.Roles[i]
})
checkedRoles := set.NewStringSet(perm.Roles...)
var users []*model.User
for _, id := range perm.Users {
var user *model.User

View File

@@ -1,10 +1,11 @@
package controller
import (
"github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz"
"github.com/cuigh/swirl/misc"
"github.com/cuigh/swirl/model"
"github.com/cuigh/swirl/security"
)
// RoleController is a controller of user role
@@ -42,7 +43,7 @@ func roleIndex(ctx web.Context) error {
}
func roleNew(ctx web.Context) error {
m := newModel(ctx).Set("Perms", misc.Perms)
m := newModel(ctx).Set("Perms", security.Perms)
return ctx.Render("system/role/new", m)
}
@@ -73,9 +74,9 @@ func roleDetail(ctx web.Context) error {
perms := make(map[string]struct{})
for _, p := range role.Perms {
perms[p] = model.Placeholder
perms[p] = data.Empty
}
m := newModel(ctx).Set("Role", role).Set("Perms", misc.Perms).Set("CheckedPerms", perms)
m := newModel(ctx).Set("Role", role).Set("Perms", security.Perms).Set("CheckedPerms", perms)
return ctx.Render("system/role/detail", m)
}
@@ -91,9 +92,9 @@ func roleEdit(ctx web.Context) error {
perms := make(map[string]struct{})
for _, p := range role.Perms {
perms[p] = model.Placeholder
perms[p] = data.Empty
}
m := newModel(ctx).Set("Role", role).Set("Perms", misc.Perms).Set("CheckedPerms", perms)
m := newModel(ctx).Set("Role", role).Set("Perms", security.Perms).Set("CheckedPerms", perms)
return ctx.Render("system/role/edit", m)
}

View File

@@ -4,7 +4,7 @@ import (
"strconv"
"strings"
"github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/data/set"
"github.com/cuigh/auxo/errors"
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/auxo/util/cast"
@@ -162,11 +162,7 @@ func serviceNew(ctx web.Context) error {
return err
}
checkedNetworks := data.NewSet()
checkedNetworks.AddSlice(info.Networks, func(i int) interface{} {
return info.Networks[i]
})
checkedNetworks := set.NewStringSet(info.Networks...)
m := newModel(ctx).Set("Service", info).Set("Registries", registries).
Set("Networks", networks).Set("CheckedNetworks", checkedNetworks).
Set("Secrets", secrets).Set("Configs", configs)
@@ -221,8 +217,8 @@ func serviceEdit(ctx web.Context) error {
}
stack := service.Spec.Labels["com.docker.stack.namespace"]
checkedNetworks := data.NewSet()
checkedNetworks.AddSlice(service.Endpoint.VirtualIPs, func(i int) interface{} { return service.Endpoint.VirtualIPs[i].NetworkID })
checkedNetworks := set.StringSet{}
checkedNetworks.AddSlice(service.Endpoint.VirtualIPs, func(i int) string { return service.Endpoint.VirtualIPs[i].NetworkID })
m := newModel(ctx).Set("Service", model.NewServiceInfo(service)).Set("Stack", stack).
Set("Networks", networks).Set("CheckedNetworks", checkedNetworks).

View File

@@ -3,7 +3,7 @@ package controller
import (
"encoding/json"
"github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/data/set"
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz"
"github.com/cuigh/swirl/biz/docker"
@@ -73,7 +73,7 @@ func templateNew(ctx web.Context) error {
return err
}
m := newModel(ctx).Set("Action", "New").Set("Service", service).Set("Registries", registries).
Set("Networks", networks).Set("CheckedNetworks", data.Set{}).
Set("Networks", networks).Set("CheckedNetworks", set.StringSet{}).
Set("Secrets", secrets).Set("Configs", configs)
return ctx.Render("service/template/edit", m)
}
@@ -143,9 +143,7 @@ func templateEdit(ctx web.Context) error {
return err
}
checkedNetworks := data.NewSet()
checkedNetworks.AddSlice(service.Networks, func(i int) interface{} { return service.Networks[i] })
checkedNetworks := set.NewStringSet(service.Networks...)
m := newModel(ctx).Set("Action", "Edit").Set("Service", service).Set("Registries", registries).
Set("Networks", networks).Set("CheckedNetworks", checkedNetworks).
Set("Secrets", secrets).Set("Configs", configs)

View File

@@ -1,6 +1,7 @@
package controller
import (
"github.com/cuigh/auxo/data"
"github.com/cuigh/auxo/log"
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz"
@@ -129,7 +130,7 @@ func userEdit(ctx web.Context) error {
userRoles := make(map[string]struct{})
for _, id := range user.Roles {
userRoles[id] = model.Placeholder
userRoles[id] = data.Empty
}
m := newModel(ctx).Set("User", user).Set("Roles", roles).Set("UserRoles", userRoles)
return ctx.Render("system/user/edit", m)