-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserPlugin.go
executable file
·105 lines (85 loc) · 2.67 KB
/
UserPlugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package user
import (
"github.com/go-bolo/bolo"
migrations_user "github.com/go-bolo/user/migrations/user"
"github.com/gookit/event"
"github.com/sirupsen/logrus"
)
type UserPlugin struct {
bolo.Pluginer
Controller *Controller
Name string
}
func (r *UserPlugin) GetName() string {
return r.Name
}
func (r *UserPlugin) Init(app bolo.App) error {
logrus.Debug(r.GetName() + " Init")
r.Controller = NewController(&ControllerCfg{App: app})
app.GetEvents().On("bindRoutes", event.ListenerFunc(func(e event.Event) error {
return r.BindRoutes(app)
}), event.Normal)
app.GetEvents().On("setTemplateFunctions", event.ListenerFunc(func(e event.Event) error {
return r.setTemplateFunctions(app)
}), event.Normal)
return nil
}
func (r *UserPlugin) BindRoutes(app bolo.App) error {
logrus.Debug(r.GetName() + " BindRoutes")
ctl := r.Controller
router := app.GetRouter()
router.GET("/user-settings", UserSettingsHandler)
aclRouter := app.SetRouterGroup("acl", "/acl")
aclRouter.GET("/permission", ctl.GetUserRolesAndPermissions)
aclRouter.POST("/user/:userID/roles", ctl.UpdateUserRoles)
app.SetRouterGroup("user", "/api/user")
routerUser := app.GetRouterGroup("user")
app.SetResource("user", r.Controller, routerUser)
// 'get /acl/user/:userId([0-9]+)/roles': {
// 'titleHandler' : 'i18n',
// 'titleI18n' : 'admin.user.roles',
// 'controller' : 'role',
// 'action' : 'updateUserRoles',
// 'model' : 'user',
// 'permission' : 'manage_role',
// 'responseType' : 'json'
// },
// 'post /acl/role/:roleName/permissions/:permissionName': {
// 'controller' : 'role',
// 'action' : 'addPermissionToRole',
// 'permission' : 'manage_permissions'
// },
// 'delete /acl/role/:roleName/permissions/:permissionName': {
// 'controller' : 'role',
// 'action' : 'removePermissionFromRole',
// 'permission' : 'manage_permissions'
// },
// 'get /acl/role': {
// 'name' : 'admin.role.find',
// 'controller' : 'role',
// 'action' : 'find',
// 'permission' : 'manage_permissions',
// 'responseType' : 'json'
// },
// 'post /acl/role': {
// 'controller' : 'role',
// 'action' : 'find',
// 'permission' : 'manage_permissions',
// 'responseType' : 'json'
// }
return nil
}
func (p *UserPlugin) GetMigrations() []*bolo.Migration {
return []*bolo.Migration{
migrations_user.GetInitMigration(),
}
}
func (p *UserPlugin) setTemplateFunctions(app bolo.App) error {
app.SetTemplateFunction("renderClientAppConfigs", renderClientAppConfigs)
return nil
}
type UserPluginCfg struct{}
func NewUserPlugin(cfg *UserPluginCfg) *UserPlugin {
p := UserPlugin{Name: "user"}
return &p
}