Browse Source

Access for any action

Vova Tkach 6 years ago
parent
commit
f09b8bc262
2 changed files with 21 additions and 7 deletions
  1. 3 2
      modules/module_users.go
  2. 18 5
      modules/modules.go

+ 3 - 2
modules/module_users.go

@@ -206,8 +206,9 @@ func (this *Modules) RegisterModule_Users() *Module {
 
 func (this *Modules) RegisterAction_CpAddModifyUser() *Action {
 	return this.newAction(AInfo{
-		WantDB: true,
-		Mount:  "users-modify",
+		WantDB:    true,
+		Mount:     "users-modify",
+		WantAdmin: true,
 	}, func(wrap *wrapper.Wrapper) {
 		pf_id := wrap.R.FormValue("id")
 		pf_first_name := wrap.R.FormValue("first_name")

+ 18 - 5
modules/modules.go

@@ -39,10 +39,11 @@ type Module struct {
 }
 
 type AInfo struct {
-	Id       string
-	WantDB   bool
-	Mount    string
-	WantUser bool
+	Id        string
+	WantDB    bool
+	Mount     string
+	WantUser  bool
+	WantAdmin bool
 }
 
 type Action struct {
@@ -262,11 +263,23 @@ func (this *Modules) XXXActionFire(wrap *wrapper.Wrapper) bool {
 						}
 						defer wrap.DB.Close()
 					}
-					if act.Info.WantUser {
+					if act.Info.WantUser || act.Info.WantAdmin {
 						if !wrap.LoadSessionUser() {
 							wrap.MsgError(`You must be loginned to run this action`)
 							return true
 						}
+						if wrap.User.A_active <= 0 {
+							if !wrap.LoadSessionUser() {
+								wrap.MsgError(`You do not have rights to run this action`)
+								return true
+							}
+						}
+					}
+					if act.Info.WantAdmin && wrap.User.A_admin <= 0 {
+						if !wrap.LoadSessionUser() {
+							wrap.MsgError(`You do not have rights to run this action`)
+							return true
+						}
 					}
 					act.Act(wrap)
 					return true