作者 陈志颖

test:增加权限测试

... ... @@ -25,3 +25,4 @@ opp
/vendor
/*.exe~
logs
tmp
\ No newline at end of file
... ...
... ... @@ -9,6 +9,8 @@ require (
github.com/gin-gonic/gin v1.5.0
github.com/go-pg/pg/v10 v10.0.0-beta.2
github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9
github.com/onsi/ginkgo v1.15.0
github.com/onsi/gomega v1.10.5
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
github.com/shopspring/decimal v1.2.0
github.com/tiptok/gocomm v1.0.5
... ...
... ... @@ -384,9 +384,10 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
_ = transactionContext.RollbackTransaction()
}()
// 通过密码或校验码登录的普通用户或通过校验码登录的游客,注册一个账号到配置的公司去
//TODO 通过密码或校验码登录的普通用户或通过校验码登录的游客,注册一个账号到配置的公司去
if request.GrantType == protocol.LoginBySmsCode || request.GrantType == protocol.LoginByPassword {
userErr := loginSvr.RegistryGuest(request.Phone)
//userErr := loginSvr.RegistryGuest(request.Phone)
userErr := loginSvr.OperateGuest(request.Phone)
if userErr != nil {
log.Error(userErr)
}
... ...
... ... @@ -48,20 +48,23 @@ func (svr *PgLoginService) Init(phone string) (err error) {
_, svr.NormalPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "sortByCreateTime": "ASC"})
// 所有公司有效合伙人
_, svr.PartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC"})
// 真实公司有效合伙人
_, svr.IsPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC", "isNot": constant.DEFAULT_GUEST_COMPANY})
// 游客公司合伙人
_, svr.GuestPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "sortByCreateTime": "ASC", "companyId": constant.DEFAULT_GUEST_COMPANY})
// 游客公司有效合伙人
_, svr.GuestPartnerInfoAvailable, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC", "companyId": constant.DEFAULT_GUEST_COMPANY})
// 所有公司用户
// 所有公司非删除用户
_, svr.NormalUsers, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "sortByCreateTime": "ASC", "deleteAtIsNull": true})
// 所有公司有效用户
// 所有公司非删除非禁用用户
_, svr.Users, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true})
// 所有公司有效高管
_, svr.IsSenior, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1})
// 真实公司有效高管
// 真实公司非禁用非删除高管
_, svr.IsRealSenior, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1, "isNot": constant.DEFAULT_GUEST_COMPANY})
return nil
... ... @@ -576,8 +579,8 @@ func (svr *PgLoginService) RegistryUser(phone string) error {
CooperateTime: time.Now(),
CreateAt: time.Now(),
UpdateAt: time.Now(),
PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},
Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}},
PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
})
}
... ... @@ -600,14 +603,74 @@ func (svr *PgLoginService) RegistryUser(phone string) error {
CooperateTime: time.Now(),
CreateAt: time.Now(),
UpdateAt: time.Now(),
PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},
Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}},
PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
})
}
return errPartner
}
/**
* @Author SteveChan
* @Description //TODO 操作游客
* @Date 15:20 2021/2/7
* @Param
* @return
**/
func (svr *PgLoginService) OperateGuest(phone string) error {
var (
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
// 真实公司检索合伙人身份(账号未禁用)
partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "status": 1, "isNot": constant.DEFAULT_GUEST_COMPANY})
// 真实公司检索用户身份(账号未删除且是高管)
user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "isSenior": 1, "deleteAtIsNull": true, "isNot": constant.DEFAULT_GUEST_COMPANY})
// 存在合伙人或者用户身份,不进行游客注册操作
if partnerInfo != nil || user != nil {
return nil
}
if errUser != nil && errPartner != nil { // 合伙人身份和用户身份均不存在,注册游客合伙人
id := time.Now().Unix()
_, errInsert := svr.transactionContext.PgDd.Model(models.PartnerInfo{
Id: id,
CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
PartnerName: phone,
Account: phone,
Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
Status: 1,
PartnerCategory: 1,
RegionInfo: &domain.RegionInfo{
RegionName: "客户区域",
RegionId: 0,
},
CooperateTime: time.Now(),
CreateAt: time.Now(),
UpdateAt: time.Now(),
PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
}).Insert()
if errInsert != nil {
return errInsert
}
} else { // 真实公司存在合伙人或者高管用户,删除游客合伙人
_, errDelete := svr.transactionContext.PgDd.Model((*models.PartnerInfo)(nil)).
Where("account = ?", phone).
Where("company_id = ?", constant.DEFAULT_GUEST_COMPANY).
Delete()
if errDelete != nil {
return errDelete
}
}
return nil
}
// 注册游客到指定的公司
func (svr *PgLoginService) RegistryGuest(phone string) error {
var (
... ... @@ -622,6 +685,7 @@ func (svr *PgLoginService) RegistryGuest(phone string) error {
return nil
}
// 注册用户
if errUser != nil && errPartner != nil {
id := time.Now().Unix()
errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
... ... @@ -639,11 +703,13 @@ func (svr *PgLoginService) RegistryGuest(phone string) error {
CooperateTime: time.Now(),
CreateAt: time.Now(),
UpdateAt: time.Now(),
PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},
Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}},
PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
})
}
// 删除用户
return errPartner
}
... ...
... ... @@ -76,7 +76,6 @@ func (s *PgPartnerAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd,
break
}
}
if misMatch {
err = fmt.Errorf("旧密码不正确") //账号不存在
return
... ...
... ... @@ -33,7 +33,7 @@ type PartnerInfo struct {
//关联业务员
Salesman []*domain.Salesman
//合伙人分类信息
PartnerCategoryInfos []*PartnerCategoryInfo
PartnerCategoryInfos []*domain.PartnerCategoryInfo
//备注
Remark string
}
... ...
... ... @@ -56,6 +56,7 @@ func (repository *UsersRepository) FindOne(queryOptions map[string]interface{})
query.SetWhere("company_id = ?", "companyId")
query.SetWhere(`delete_at is null`, "deleteAtIsNull")
query.SetWhere("is_senior = ?", "isSenior")
query.SetWhere("company_id <> ?", "isNot")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
... ...
/**
@author: stevechan
@date: 2021/2/7
@note:
**/
package auth
import (
"github.com/astaxie/beego"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"net/http"
"net/http/httptest"
"testing"
_ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr"
)
func TestConfig(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Beego APPSVR Auth Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = ginkgo.BeforeSuite(func() {
handler = beego.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = ginkgo.AfterSuite(func() {
server.Close()
})
... ...
不能预览此文件类型