瀏覽代碼

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

csx 4 年之前
父節點
當前提交
15b2e8a6cc

+ 107 - 0
controllers/new_mobile_api_controllers/home_api_controller.go 查看文件

@@ -597,3 +597,110 @@ func (this *HomeController) checkParam(mobile string, code string, password stri
597 597
 	}
598 598
 	return nil
599 599
 }
600
+
601
+func (this *HomeController) GetFuncPermission() {
602
+	adminUserInfo := this.GetMobileAdminUserInfo()
603
+	user_id := adminUserInfo.AdminUser.Id
604
+	app_id := adminUserInfo.App.Id
605
+	org_id := adminUserInfo.Org.Id
606
+	create_url := this.GetString("create_url")
607
+	modify_url := this.GetString("modify_url")
608
+	modify_other_url := this.GetString("modify_other_url")
609
+	del_url := this.GetString("del_url")
610
+	del_other_url := this.GetString("del_other_url")
611
+	exce_url := this.GetString("exce_url")
612
+	check_url := this.GetString("check_url")
613
+	modify_exce_url := this.GetString("modify_exce_url")
614
+	module, _ := this.GetInt64("module", 0)
615
+
616
+	app_role, _ := service.GetAppRole(org_id, app_id, user_id)
617
+	var is_has_create bool
618
+	var is_has_modify bool
619
+	var is_has_modify_other bool
620
+	var is_has_del bool
621
+	var is_has_del_other bool
622
+	var is_has_exce bool
623
+	var is_has_check bool
624
+	var is_has_modify_exce bool
625
+
626
+	if app_role != nil {
627
+		if len(app_role.RoleIds) > 0 {
628
+			roles := strings.Split(app_role.RoleIds, ",")
629
+			var userRolePurviews string
630
+			for _, item := range roles {
631
+				role_id, _ := strconv.ParseInt(item, 10, 64)
632
+				purviews, _ := service.GetRoleFuncPurviewIds(role_id)
633
+				if len(userRolePurviews) == 0 {
634
+					userRolePurviews = purviews
635
+				} else {
636
+					userRolePurviews = userRolePurviews + "," + purviews
637
+				}
638
+			}
639
+			userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
640
+			funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
641
+			for _, item := range funcPurviews {
642
+				//for _, url := range strings.Split(item.Urlfor,","){
643
+				if strings.Split(item.Urlfor, ",")[0] == create_url {
644
+					is_has_create = true
645
+				}
646
+				if strings.Split(item.Urlfor, ",")[0] == modify_url {
647
+					is_has_modify = true
648
+				}
649
+				if strings.Split(item.Urlfor, ",")[0] == modify_other_url {
650
+					is_has_modify_other = true
651
+				}
652
+				if strings.Split(item.Urlfor, ",")[0] == del_url {
653
+					is_has_del = true
654
+				}
655
+				if strings.Split(item.Urlfor, ",")[0] == del_other_url {
656
+					is_has_del_other = true
657
+				}
658
+				if strings.Split(item.Urlfor, ",")[0] == exce_url {
659
+					is_has_exce = true
660
+				}
661
+				if strings.Split(item.Urlfor, ",")[0] == check_url {
662
+					is_has_check = true
663
+				}
664
+				if strings.Split(item.Urlfor, ",")[0] == modify_exce_url {
665
+					is_has_modify_exce = true
666
+				}
667
+
668
+			}
669
+		} else {
670
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
671
+			return
672
+		}
673
+		this.ServeSuccessJSON(map[string]interface{}{
674
+			"is_has_create":       is_has_create,
675
+			"is_has_modify":       is_has_modify,
676
+			"is_has_modify_other": is_has_modify_other,
677
+			"is_has_del":          is_has_del,
678
+			"is_has_del_other":    is_has_del_other,
679
+			"is_has_exce":         is_has_exce,
680
+			"is_has_check":        is_has_check,
681
+			"is_has_modify_exce":  is_has_modify_exce,
682
+			"module":              module,
683
+		})
684
+	} else {
685
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
686
+		return
687
+
688
+	}
689
+
690
+}
691
+func RemoveRepeatedPurviewElement2(arr []string) (newArr []string) {
692
+	newArr = make([]string, 0)
693
+	for i := 0; i < len(arr); i++ {
694
+		repeat := false
695
+		for j := i + 1; j < len(arr); j++ {
696
+			if arr[i] == arr[j] {
697
+				repeat = true
698
+				break
699
+			}
700
+		}
701
+		if !repeat {
702
+			newArr = append(newArr, arr[i])
703
+		}
704
+	}
705
+	return
706
+}

+ 2 - 0
controllers/new_mobile_api_controllers/new_mobile_api_router_register.go 查看文件

@@ -60,6 +60,8 @@ func NewMobileAPIControllersRegisterRouters() {
60 60
 
61 61
 	beego.Router("/m/api/func_role/get", &NewRoleApiController{}, "get:GetFuncRolePurviews")
62 62
 
63
+	beego.Router("/m/api/permission/get", &HomeController{}, "get:GetFuncPermission")
64
+
63 65
 	beego.Router("/m/api/patient/getbloodpatientinfo", &NewDialysisApiController{}, "Get:GetBloodPatientInfo")
64 66
 	beego.Router("/m/api/patient/getslowpatientinfo", &NewDialysisApiController{}, "Get:GetSlowPatientInfo")
65 67
 	beego.Router("/m/api/patient/getmemberpatientinfo", &NewDialysisApiController{}, "Get:GetMemberpatientInfo")

+ 8 - 0
enums/error_code.go 查看文件

@@ -188,6 +188,10 @@ const ( // ErrorCode
188 188
 
189 189
 	ErrorCodeForbidden       = 20035
190 190
 	ErrorCodeRoleNameIsExist = 20036
191
+
192
+	ErrorCodeRole = 20037
193
+
194
+	ErrorCodeAdminUserIsExit = 20038
191 195
 )
192 196
 
193 197
 var ErrCodeMsgs = map[int]string{
@@ -375,6 +379,10 @@ var ErrCodeMsgs = map[int]string{
375 379
 	ErrorCodeForbidden: "你已经被管理员禁用,无法使用该系统",
376 380
 
377 381
 	ErrorCodeRoleNameIsExist: "该角色已经不存在",
382
+
383
+	ErrorCodeRole: "尚未配置角色,无访问权限",
384
+
385
+	ErrorCodeAdminUserIsExit: "用户不存在",
378 386
 }
379 387
 
380 388
 type SGJError struct {

+ 6 - 0
service/role_service.go 查看文件

@@ -748,3 +748,9 @@ func FindRoleRecordByRoleName(name string, org_id int64) (total int64) {
748 748
 	readUserDb.Model(&models.Role{}).Where("status = 1 AND role_name = ? AND org_id = ?", name, org_id).Count(&total)
749 749
 	return
750 750
 }
751
+
752
+func FindAllFuncPurview(ids []string) (purview []*models.SgjUserOperatePurview, err error) {
753
+	err = readUserDb.Model(&models.SgjUserOperatePurview{}).Where("status = 1 AND id in (?)", ids).Find(&purview).Error
754
+	return
755
+
756
+}