作者 陈志颖

test:增加权限测试

@@ -25,3 +25,4 @@ opp @@ -25,3 +25,4 @@ opp
25 /vendor 25 /vendor
26 /*.exe~ 26 /*.exe~
27 logs 27 logs
  28 +tmp
@@ -9,6 +9,8 @@ require ( @@ -9,6 +9,8 @@ require (
9 github.com/gin-gonic/gin v1.5.0 9 github.com/gin-gonic/gin v1.5.0
10 github.com/go-pg/pg/v10 v10.0.0-beta.2 10 github.com/go-pg/pg/v10 v10.0.0-beta.2
11 github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 11 github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9
  12 + github.com/onsi/ginkgo v1.15.0
  13 + github.com/onsi/gomega v1.10.5
12 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect 14 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
13 github.com/shopspring/decimal v1.2.0 15 github.com/shopspring/decimal v1.2.0
14 github.com/tiptok/gocomm v1.0.5 16 github.com/tiptok/gocomm v1.0.5
@@ -384,9 +384,10 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -384,9 +384,10 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
384 _ = transactionContext.RollbackTransaction() 384 _ = transactionContext.RollbackTransaction()
385 }() 385 }()
386 386
387 - // 通过密码或校验码登录的普通用户或通过校验码登录的游客,注册一个账号到配置的公司去 387 + //TODO 通过密码或校验码登录的普通用户或通过校验码登录的游客,注册一个账号到配置的公司去
388 if request.GrantType == protocol.LoginBySmsCode || request.GrantType == protocol.LoginByPassword { 388 if request.GrantType == protocol.LoginBySmsCode || request.GrantType == protocol.LoginByPassword {
389 - userErr := loginSvr.RegistryGuest(request.Phone) 389 + //userErr := loginSvr.RegistryGuest(request.Phone)
  390 + userErr := loginSvr.OperateGuest(request.Phone)
390 if userErr != nil { 391 if userErr != nil {
391 log.Error(userErr) 392 log.Error(userErr)
392 } 393 }
@@ -48,20 +48,23 @@ func (svr *PgLoginService) Init(phone string) (err error) { @@ -48,20 +48,23 @@ func (svr *PgLoginService) Init(phone string) (err error) {
48 _, svr.NormalPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "sortByCreateTime": "ASC"}) 48 _, svr.NormalPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "sortByCreateTime": "ASC"})
49 // 所有公司有效合伙人 49 // 所有公司有效合伙人
50 _, svr.PartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC"}) 50 _, svr.PartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC"})
  51 +
51 // 真实公司有效合伙人 52 // 真实公司有效合伙人
52 _, svr.IsPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC", "isNot": constant.DEFAULT_GUEST_COMPANY}) 53 _, svr.IsPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC", "isNot": constant.DEFAULT_GUEST_COMPANY})
  54 +
53 // 游客公司合伙人 55 // 游客公司合伙人
54 _, svr.GuestPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "sortByCreateTime": "ASC", "companyId": constant.DEFAULT_GUEST_COMPANY}) 56 _, svr.GuestPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "sortByCreateTime": "ASC", "companyId": constant.DEFAULT_GUEST_COMPANY})
55 // 游客公司有效合伙人 57 // 游客公司有效合伙人
56 _, svr.GuestPartnerInfoAvailable, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC", "companyId": constant.DEFAULT_GUEST_COMPANY}) 58 _, svr.GuestPartnerInfoAvailable, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC", "companyId": constant.DEFAULT_GUEST_COMPANY})
57 59
58 - // 所有公司用户 60 + // 所有公司非删除用户
59 _, svr.NormalUsers, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "sortByCreateTime": "ASC", "deleteAtIsNull": true}) 61 _, svr.NormalUsers, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "sortByCreateTime": "ASC", "deleteAtIsNull": true})
60 - // 所有公司有效用户 62 + // 所有公司非删除非禁用用户
61 _, svr.Users, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true}) 63 _, svr.Users, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true})
62 // 所有公司有效高管 64 // 所有公司有效高管
63 _, svr.IsSenior, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1}) 65 _, svr.IsSenior, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1})
64 - // 真实公司有效高管 66 +
  67 + // 真实公司非禁用非删除高管
65 _, svr.IsRealSenior, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1, "isNot": constant.DEFAULT_GUEST_COMPANY}) 68 _, svr.IsRealSenior, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1, "isNot": constant.DEFAULT_GUEST_COMPANY})
66 69
67 return nil 70 return nil
@@ -576,8 +579,8 @@ func (svr *PgLoginService) RegistryUser(phone string) error { @@ -576,8 +579,8 @@ func (svr *PgLoginService) RegistryUser(phone string) error {
576 CooperateTime: time.Now(), 579 CooperateTime: time.Now(),
577 CreateAt: time.Now(), 580 CreateAt: time.Now(),
578 UpdateAt: time.Now(), 581 UpdateAt: time.Now(),
579 - PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},  
580 - Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}}, 582 + PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
  583 + Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
581 }) 584 })
582 } 585 }
583 586
@@ -600,14 +603,74 @@ func (svr *PgLoginService) RegistryUser(phone string) error { @@ -600,14 +603,74 @@ func (svr *PgLoginService) RegistryUser(phone string) error {
600 CooperateTime: time.Now(), 603 CooperateTime: time.Now(),
601 CreateAt: time.Now(), 604 CreateAt: time.Now(),
602 UpdateAt: time.Now(), 605 UpdateAt: time.Now(),
603 - PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},  
604 - Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}}, 606 + PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
  607 + Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
605 }) 608 })
606 } 609 }
607 610
608 return errPartner 611 return errPartner
609 } 612 }
610 613
  614 +/**
  615 + * @Author SteveChan
  616 + * @Description //TODO 操作游客
  617 + * @Date 15:20 2021/2/7
  618 + * @Param
  619 + * @return
  620 + **/
  621 +func (svr *PgLoginService) OperateGuest(phone string) error {
  622 + var (
  623 + PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
  624 + UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
  625 + )
  626 +
  627 + // 真实公司检索合伙人身份(账号未禁用)
  628 + partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "status": 1, "isNot": constant.DEFAULT_GUEST_COMPANY})
  629 +
  630 + // 真实公司检索用户身份(账号未删除且是高管)
  631 + user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "isSenior": 1, "deleteAtIsNull": true, "isNot": constant.DEFAULT_GUEST_COMPANY})
  632 +
  633 + // 存在合伙人或者用户身份,不进行游客注册操作
  634 + if partnerInfo != nil || user != nil {
  635 + return nil
  636 + }
  637 +
  638 + if errUser != nil && errPartner != nil { // 合伙人身份和用户身份均不存在,注册游客合伙人
  639 + id := time.Now().Unix()
  640 + _, errInsert := svr.transactionContext.PgDd.Model(models.PartnerInfo{
  641 + Id: id,
  642 + CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
  643 + PartnerName: phone,
  644 + Account: phone,
  645 + Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
  646 + Status: 1,
  647 + PartnerCategory: 1,
  648 + RegionInfo: &domain.RegionInfo{
  649 + RegionName: "客户区域",
  650 + RegionId: 0,
  651 + },
  652 + CooperateTime: time.Now(),
  653 + CreateAt: time.Now(),
  654 + UpdateAt: time.Now(),
  655 + PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
  656 + Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
  657 + }).Insert()
  658 + if errInsert != nil {
  659 + return errInsert
  660 + }
  661 + } else { // 真实公司存在合伙人或者高管用户,删除游客合伙人
  662 + _, errDelete := svr.transactionContext.PgDd.Model((*models.PartnerInfo)(nil)).
  663 + Where("account = ?", phone).
  664 + Where("company_id = ?", constant.DEFAULT_GUEST_COMPANY).
  665 + Delete()
  666 + if errDelete != nil {
  667 + return errDelete
  668 + }
  669 + }
  670 +
  671 + return nil
  672 +}
  673 +
611 // 注册游客到指定的公司 674 // 注册游客到指定的公司
612 func (svr *PgLoginService) RegistryGuest(phone string) error { 675 func (svr *PgLoginService) RegistryGuest(phone string) error {
613 var ( 676 var (
@@ -622,6 +685,7 @@ func (svr *PgLoginService) RegistryGuest(phone string) error { @@ -622,6 +685,7 @@ func (svr *PgLoginService) RegistryGuest(phone string) error {
622 return nil 685 return nil
623 } 686 }
624 687
  688 + // 注册用户
625 if errUser != nil && errPartner != nil { 689 if errUser != nil && errPartner != nil {
626 id := time.Now().Unix() 690 id := time.Now().Unix()
627 errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{ 691 errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
@@ -639,11 +703,13 @@ func (svr *PgLoginService) RegistryGuest(phone string) error { @@ -639,11 +703,13 @@ func (svr *PgLoginService) RegistryGuest(phone string) error {
639 CooperateTime: time.Now(), 703 CooperateTime: time.Now(),
640 CreateAt: time.Now(), 704 CreateAt: time.Now(),
641 UpdateAt: time.Now(), 705 UpdateAt: time.Now(),
642 - PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},  
643 - Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}}, 706 + PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
  707 + Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
644 }) 708 })
645 } 709 }
646 710
  711 + // 删除用户
  712 +
647 return errPartner 713 return errPartner
648 } 714 }
649 715
@@ -76,7 +76,6 @@ func (s *PgPartnerAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, @@ -76,7 +76,6 @@ func (s *PgPartnerAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd,
76 break 76 break
77 } 77 }
78 } 78 }
79 -  
80 if misMatch { 79 if misMatch {
81 err = fmt.Errorf("旧密码不正确") //账号不存在 80 err = fmt.Errorf("旧密码不正确") //账号不存在
82 return 81 return
@@ -33,7 +33,7 @@ type PartnerInfo struct { @@ -33,7 +33,7 @@ type PartnerInfo struct {
33 //关联业务员 33 //关联业务员
34 Salesman []*domain.Salesman 34 Salesman []*domain.Salesman
35 //合伙人分类信息 35 //合伙人分类信息
36 - PartnerCategoryInfos []*PartnerCategoryInfo 36 + PartnerCategoryInfos []*domain.PartnerCategoryInfo
37 //备注 37 //备注
38 Remark string 38 Remark string
39 } 39 }
@@ -56,6 +56,7 @@ func (repository *UsersRepository) FindOne(queryOptions map[string]interface{}) @@ -56,6 +56,7 @@ func (repository *UsersRepository) FindOne(queryOptions map[string]interface{})
56 query.SetWhere("company_id = ?", "companyId") 56 query.SetWhere("company_id = ?", "companyId")
57 query.SetWhere(`delete_at is null`, "deleteAtIsNull") 57 query.SetWhere(`delete_at is null`, "deleteAtIsNull")
58 query.SetWhere("is_senior = ?", "isSenior") 58 query.SetWhere("is_senior = ?", "isSenior")
  59 + query.SetWhere("company_id <> ?", "isNot")
59 60
60 if err := query.First(); err != nil { 61 if err := query.First(); err != nil {
61 return nil, fmt.Errorf("query row not found") 62 return nil, fmt.Errorf("query row not found")
  1 +/**
  2 + @author: stevechan
  3 + @date: 2021/2/7
  4 + @note:
  5 +**/
  6 +
  7 +package auth
  8 +
  9 +import (
  10 + "github.com/astaxie/beego"
  11 + "github.com/onsi/ginkgo"
  12 + "github.com/onsi/gomega"
  13 + "net/http"
  14 + "net/http/httptest"
  15 + "testing"
  16 +
  17 + _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg"
  18 + _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr"
  19 +)
  20 +
  21 +func TestConfig(t *testing.T) {
  22 + gomega.RegisterFailHandler(ginkgo.Fail)
  23 + ginkgo.RunSpecs(t, "Beego APPSVR Auth Correlations Test Case Suite")
  24 +}
  25 +
  26 +var handler http.Handler
  27 +var server *httptest.Server
  28 +
  29 +var _ = ginkgo.BeforeSuite(func() {
  30 + handler = beego.BeeApp.Handlers
  31 + server = httptest.NewServer(handler)
  32 +})
  33 +
  34 +var _ = ginkgo.AfterSuite(func() {
  35 + server.Close()
  36 +})
不能预览此文件类型