Browse Source

Merge branch 'master' of http://git.shengws.com/csx/XT_New

csx 5 years ago
parent
commit
34f2799d19

+ 55 - 53
controllers/mobile_api_controllers/mobile_api_base_controller.go View File

@@ -66,64 +66,66 @@ func (this *MobileBaseAPIAuthController) Prepare() {
66 66
 	//		this.StopRun()
67 67
 	//	}
68 68
 	//}
69
+	if !adminUserInfo.AdminUser.IsSuperAdmin || adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
69 70
 
70
-	if this.Ctx.Request.Header.Get("Permission") == "1" {
71
-		isPermission := false
72
-		adminUserInfo := this.GetMobileAdminUserInfo()
73
-		//该机构下该用户有多少个
74
-		role, _ := service.GetUserAllRole(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id)
75
-		var roles []string
76
-		if len(role.RoleIds) <= 0 { //该用户没有设置角色
71
+		if this.Ctx.Request.Header.Get("Permission") == "1" {
72
+			isPermission := false
73
+			adminUserInfo := this.GetMobileAdminUserInfo()
74
+			//该机构下该用户有多少个
75
+			role, _ := service.GetUserAllRole(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id)
76
+			var roles []string
77
+			if len(role.RoleIds) <= 0 { //该用户没有设置角色
77 78
 
78
-		} else {
79
-			roles = strings.Split(role.RoleIds, ",")
80
-		}
81
-		fmt.Println(roles)
82
-
83
-		//获取该用户下所有角色的权限总集
84
-		var userRolePurviews string
85
-		var userRolePurviewsArr []string
86
-		for _, item := range roles {
87
-			role_id, _ := strconv.ParseInt(item, 10, 64)
88
-			purviews, _ := service.GetRoleFuncPurviewIds(role_id)
89
-			if len(userRolePurviews) == 0 {
90
-				userRolePurviews = purviews
91 79
 			} else {
92
-				userRolePurviews = userRolePurviews + "," + purviews
80
+				roles = strings.Split(role.RoleIds, ",")
93 81
 			}
94
-		}
95
-		//该用户所拥有角色的权限的总集
96
-		userRolePurviewsArr = RemoveRepeatedPurviewElement(strings.Split(userRolePurviews, ","))
97
-		fmt.Println(userRolePurviewsArr)
98
-		//系统所记录的权限列表
99
-		allPermission, _ := service.GetAllFunctionPurview()
100
-
101
-		for _, item := range allPermission {
102
-			fmt.Println(strings.Split(item.Urlfor, ",")[0])
103
-			fmt.Println(strings.Split(this.Ctx.Request.RequestURI, "?")[0] + "?" + "mode=" + this.GetString("mode"))
104
-
105
-			//判断当前路由是否在权限路由列表里面
106
-			if strings.Split(item.Urlfor, ",")[0] == strings.Split(this.Ctx.Request.RequestURI, "?")[0]+"?"+"mode="+this.GetString("mode") {
107
-
108
-				//获取该角色的所有权限
109
-				for _, items := range userRolePurviewsArr {
110
-					id, _ := strconv.ParseInt(items, 10, 64)
111
-					fmt.Println(id)
112
-					fmt.Println(item.ID)
113
-
114
-					if id == item.ID {
115
-						isPermission = true
116
-					}
82
+			fmt.Println(roles)
83
+
84
+			//获取该用户下所有角色的权限总集
85
+			var userRolePurviews string
86
+			var userRolePurviewsArr []string
87
+			for _, item := range roles {
88
+				role_id, _ := strconv.ParseInt(item, 10, 64)
89
+				purviews, _ := service.GetRoleFuncPurviewIds(role_id)
90
+				if len(userRolePurviews) == 0 {
91
+					userRolePurviews = purviews
92
+				} else {
93
+					userRolePurviews = userRolePurviews + "," + purviews
117 94
 				}
118
-				if !isPermission {
119
-					msg, _ := service.FindErrorMsgByStr(strings.Split(this.Ctx.Request.RequestURI, "?")[0] + "?" + "mode=" + this.GetString("mode"))
120
-					json := make(map[string]interface{})
121
-					json["msg"] = msg
122
-					json["code"] = 0
123
-					json["state"] = 0
124
-					this.Data["json"] = json
125
-					this.ServeJSON()
126
-					this.StopRun()
95
+			}
96
+			//该用户所拥有角色的权限的总集
97
+			userRolePurviewsArr = RemoveRepeatedPurviewElement(strings.Split(userRolePurviews, ","))
98
+			fmt.Println(userRolePurviewsArr)
99
+			//系统所记录的权限列表
100
+			allPermission, _ := service.GetAllFunctionPurview()
101
+
102
+			for _, item := range allPermission {
103
+				fmt.Println(strings.Split(item.Urlfor, ",")[0])
104
+				fmt.Println(strings.Split(this.Ctx.Request.RequestURI, "?")[0] + "?" + "mode=" + this.GetString("mode"))
105
+
106
+				//判断当前路由是否在权限路由列表里面
107
+				if strings.Split(item.Urlfor, ",")[0] == strings.Split(this.Ctx.Request.RequestURI, "?")[0]+"?"+"mode="+this.GetString("mode") {
108
+
109
+					//获取该角色的所有权限
110
+					for _, items := range userRolePurviewsArr {
111
+						id, _ := strconv.ParseInt(items, 10, 64)
112
+						fmt.Println(id)
113
+						fmt.Println(item.ID)
114
+
115
+						if id == item.ID {
116
+							isPermission = true
117
+						}
118
+					}
119
+					if !isPermission {
120
+						msg, _ := service.FindErrorMsgByStr(strings.Split(this.Ctx.Request.RequestURI, "?")[0] + "?" + "mode=" + this.GetString("mode"))
121
+						json := make(map[string]interface{})
122
+						json["msg"] = msg
123
+						json["code"] = 0
124
+						json["state"] = 0
125
+						this.Data["json"] = json
126
+						this.ServeJSON()
127
+						this.StopRun()
128
+					}
127 129
 				}
128 130
 			}
129 131
 		}

+ 26 - 18
controllers/verify_login_controller.go View File

@@ -6,11 +6,10 @@ import (
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8 8
 	"fmt"
9
+	"github.com/astaxie/beego"
9 10
 	"net/url"
10 11
 	"strconv"
11 12
 	"strings"
12
-
13
-	"github.com/astaxie/beego"
14 13
 )
15 14
 
16 15
 func VerifyUserLoginControllerRegistRouters() {
@@ -194,27 +193,36 @@ func (this *VerifyUserLoginAPIController) VerifyToken() {
194 193
 			curAppUrlfors := adminUserInfo.AppUrlfors[adminUserInfo.CurrentAppId]
195 194
 
196 195
 			if len(curAppUrlfors) == 0 {
197
-				appRole, _ := service.FindAdminUserIDA(appRole.Id)
198
-				role_arr := strings.Split(appRole.RoleIds, ",")
199
-				var ids string
200
-				for _, role_id := range role_arr {
201
-					id, _ := strconv.ParseInt(role_id, 10, 64)
202
-					purview_ids, _ := service.GetRolePurviewIds(id)
203
-					if len(ids) == 0 {
204
-						ids = purview_ids
205
-					} else {
206
-						ids = ids + "," + purview_ids
196
+				if adminUser.Id == curOrg.Creator {
197
+
198
+					urlfors, _, _ := service.GetSuperAdminUsersPurviewTreeAndUrlfors(3)
199
+					curAppUrlfors = urlfors
200
+
201
+				} else {
202
+					appRole, _ := service.FindAdminUserIDA(appRole.Id)
203
+					role_arr := strings.Split(appRole.RoleIds, ",")
204
+					var ids string
205
+					for _, role_id := range role_arr {
206
+						id, _ := strconv.ParseInt(role_id, 10, 64)
207
+						purview_ids, _ := service.GetRolePurviewIds(id)
208
+						if len(ids) == 0 {
209
+							ids = purview_ids
210
+						} else {
211
+							ids = ids + "," + purview_ids
212
+						}
207 213
 					}
208
-				}
209 214
 
210
-				pruviews, _ := service.GetPurviewById(ids)
215
+					pruviews, _ := service.GetPurviewById(ids)
211 216
 
212
-				for _, item := range pruviews {
213
-					if item.Module == 3 && item.Parentid > 0 {
214
-						fmt.Println(item.Urlfor)
215
-						curAppUrlfors = append(curAppUrlfors, item.Urlfor)
217
+					for _, item := range pruviews {
218
+						if item.Module == 3 && item.Parentid > 0 {
219
+							fmt.Println(item.Urlfor)
220
+							curAppUrlfors = append(curAppUrlfors, item.Urlfor)
221
+						}
216 222
 					}
223
+
217 224
 				}
225
+
218 226
 			}
219 227
 
220 228
 			//subscibe := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]

+ 1 - 1
service/role_service.go View File

@@ -496,7 +496,7 @@ func GetAllAdminUsersAndRole(orgID int64, appID int64, page int, count int) ([]*
496 496
 	var viewModels []*NewAdminUserModel = make([]*NewAdminUserModel, 0)
497 497
 	var rows *sql.Rows
498 498
 	var err error
499
-	rows, err = readUserDb.Raw("SELECT u_a_r.id, u_a_r.admin_user_id, u_a_r.user_name,  u_a_r.user_title, u_a_r.status,u_a_r.avatar,u_a_r.role_ids FROM sgj_user_admin_role AS u_a_r  WHERE org_id = ? AND app_id = ?  ORDER BY ctime DESC", orgID, appID).Rows()
499
+	rows, err = readUserDb.Raw("SELECT u_a_r.id, u_a_r.admin_user_id, u_a_r.user_name,  u_a_r.user_title, u_a_r.status,u_a_r.avatar,u_a_r.role_ids FROM sgj_user_admin_role AS u_a_r  WHERE org_id = ? AND app_id = ? AND user_type <> 1 ORDER BY ctime DESC", orgID, appID).Rows()
500 500
 	defer rows.Close()
501 501
 	if err != nil {
502 502
 		if err == gorm.ErrRecordNotFound {

+ 55 - 0
service/verify_login_token_service.go View File

@@ -2,6 +2,7 @@ package service
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
+	"github.com/jinzhu/gorm"
5 6
 	"io/ioutil"
6 7
 	"net/http"
7 8
 	"net/url"
@@ -394,3 +395,57 @@ func FindAdminUserIDA(id int64) (role models.App_Role, err error) {
394 395
 	err = readUserDb.Model(&models.App_Role{}).Where("id = ?", id).First(&role).Error
395 396
 	return
396 397
 }
398
+
399
+func GetSuperAdminUsersPurviewTreeAndUrlfors(appType int) ([]string, []*models.Purview, error) {
400
+	originPurviews, getPurviewErr := getAllOriginPurviews(appType)
401
+	if getPurviewErr != nil {
402
+		return nil, nil, getPurviewErr
403
+	}
404
+	urlfors, processedPurviews := getUrlforsAndProcessPurviews2Tree(originPurviews)
405
+	return urlfors, processedPurviews, nil
406
+}
407
+
408
+// 加工这些规则:树形化;以及从中取出不为空的 urlfor
409
+// 正确结果的前提是 originPurviews 以 parentid asc 排好序了的
410
+func getUrlforsAndProcessPurviews2Tree(originPurviews []*models.Purview) ([]string, []*models.Purview) {
411
+	processedPurviews := make([]*models.Purview, 0)
412
+	pid_childs := make(map[int][]*models.Purview)
413
+	urlfors := make([]string, 0, len(originPurviews))
414
+	for _, purview := range originPurviews {
415
+		if len(purview.Urlfor) != 0 {
416
+			urlfors = append(urlfors, purview.Urlfor)
417
+		}
418
+
419
+		// warning:下面这个算法只适用最多两层树形结构的菜单,对于两层以上的会丢失掉第三层及其以下的节点
420
+		// 因为取出 originPurviews 的时候已经排过序了,所以顶级节点肯定最先处理,不需要担心子节点比父节点先处理
421
+		if purview.Parentid == 0 {
422
+			processedPurviews = append(processedPurviews, purview)
423
+		} else {
424
+			childs := pid_childs[int(purview.Parentid)]
425
+			if pid_childs[int(purview.Parentid)] == nil {
426
+				childs = make([]*models.Purview, 0)
427
+			}
428
+			childs = append(childs, purview)
429
+			pid_childs[int(purview.Parentid)] = childs
430
+		}
431
+	}
432
+
433
+	for _, proPurview := range processedPurviews {
434
+		proPurview.Childs = pid_childs[int(proPurview.Id)]
435
+	}
436
+
437
+	return urlfors, processedPurviews
438
+}
439
+
440
+func getAllOriginPurviews(appType int) ([]*models.Purview, error) {
441
+	var purviews []*models.Purview
442
+	getPurviewErr := readUserDb.Model(models.Purview{}).Where("module = ? AND status = 1", appType).Order("listorder asc").Order("id asc").Find(&purviews).Error
443
+	if getPurviewErr != nil {
444
+		if getPurviewErr == gorm.ErrRecordNotFound {
445
+			return nil, nil
446
+		} else {
447
+			return nil, getPurviewErr
448
+		}
449
+	}
450
+	return purviews, nil
451
+}