update
This commit is contained in:
parent
5bc08a830a
commit
c3d20a9d5f
2
go.mod
2
go.mod
@ -10,7 +10,7 @@ require (
|
|||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.8.4
|
||||||
go.uber.org/zap v1.27.0
|
go.uber.org/zap v1.27.0
|
||||||
google.golang.org/protobuf v1.33.0
|
google.golang.org/protobuf v1.33.0
|
||||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240419144125-64e45ebed8ae
|
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240420091424-34628bcc93eb
|
||||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af
|
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af
|
||||||
)
|
)
|
||||||
|
|
||||||
|
2
go.sum
2
go.sum
@ -149,5 +149,7 @@ penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3
|
|||||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240419144125-64e45ebed8ae h1:FaV/RbCQaMZg48bzvMhNzzC4RtI3wQIPrMA0ZDl3jDA=
|
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240419144125-64e45ebed8ae h1:FaV/RbCQaMZg48bzvMhNzzC4RtI3wQIPrMA0ZDl3jDA=
|
||||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240419144125-64e45ebed8ae/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
|
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240419144125-64e45ebed8ae/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
|
||||||
|
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240420091424-34628bcc93eb h1:INNnspSaEyKlfhQ+E279sNcIzDrwvRfEFmYTuk7bdZw=
|
||||||
|
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240420091424-34628bcc93eb/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
|
||||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af h1:jQ7HaXSutDX5iepU7VRImxhikK7lV/lBKkiloOZ4Emo=
|
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af h1:jQ7HaXSutDX5iepU7VRImxhikK7lV/lBKkiloOZ4Emo=
|
||||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af/go.mod h1:5S5YwjSXWmnEKjBjG6MtyGtFmljjukDRS8CwHk/CF/I=
|
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af/go.mod h1:5S5YwjSXWmnEKjBjG6MtyGtFmljjukDRS8CwHk/CF/I=
|
||||||
|
@ -69,6 +69,8 @@ func (c *Controller) ConnectAccount(ctx *fiber.Ctx) error {
|
|||||||
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//accountID := "64f2cd7a7047f28fdabf6d9e"
|
||||||
|
|
||||||
response, err := c.service.ConnectAccount(ctx.Context(), accountID)
|
response, err := c.service.ConnectAccount(ctx.Context(), accountID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Error("error connect account", zap.Error(err))
|
c.logger.Error("error connect account", zap.Error(err))
|
||||||
|
@ -6,11 +6,11 @@ type RequestGetListUsers struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResponseGetListUsers struct {
|
type ResponseGetListUsers struct {
|
||||||
TotalItems int `json:"_total_items"`
|
TotalItems int `json:"_total_items"`
|
||||||
Page int `json:"_page"`
|
//Page int `json:"_page"`
|
||||||
PageCount int `json:"_page_count"`
|
//PageCount int `json:"_page_count"`
|
||||||
Links LinksSelf `json:"_links"`
|
Links LinksSelf `json:"_links"`
|
||||||
Embedded EmbeddedGetListUsers `json:"_embedded"`
|
Embedded EmbeddedGetListUsers `json:"_embedded"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmbeddedGetListUsers struct {
|
type EmbeddedGetListUsers struct {
|
||||||
@ -26,11 +26,16 @@ type LinksSelf struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Users struct {
|
type Users struct {
|
||||||
ID int32 `json:"id"`
|
ID int32 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Lang string `json:"lang"`
|
UUID string `json:"uuid"`
|
||||||
Rights Rights `json:"rights"`
|
IsConfirmed bool `json:"is_confirmed"`
|
||||||
|
ConfirmLinkSentAt int `json:"confirm_link_sent_at"`
|
||||||
|
Lang string `json:"lang"`
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
Groups Groups `json:"groups"`
|
||||||
|
//Rights Rights `json:"rights"`
|
||||||
Links SelfLink `json:"_links"`
|
Links SelfLink `json:"_links"`
|
||||||
Embedded Embedded `json:"_embedded"`
|
Embedded Embedded `json:"_embedded"`
|
||||||
}
|
}
|
||||||
@ -48,6 +53,7 @@ type Rights struct {
|
|||||||
IsActive bool `json:"is_active"`
|
IsActive bool `json:"is_active"`
|
||||||
GroupID *int `json:"group_id,omitempty"`
|
GroupID *int `json:"group_id,omitempty"`
|
||||||
RoleID *int `json:"role_id,omitempty"`
|
RoleID *int `json:"role_id,omitempty"`
|
||||||
|
Role *string `json:"role,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Leads struct {
|
type Leads struct {
|
||||||
@ -103,7 +109,11 @@ type Groups struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//type Embedded struct {
|
||||||
|
// Roles []Roles `json:"roles"`
|
||||||
|
// Groups []Groups `json:"groups"`
|
||||||
|
//}
|
||||||
|
|
||||||
type Embedded struct {
|
type Embedded struct {
|
||||||
Roles []Roles `json:"roles"`
|
Rights Rights `json:"rights"`
|
||||||
Groups []Groups `json:"groups"`
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"amocrm/internal/models"
|
"amocrm/internal/models"
|
||||||
"amocrm/internal/tools"
|
|
||||||
"context"
|
"context"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||||
@ -30,7 +29,7 @@ func (s *Service) WebhookCreate(ctx context.Context, req ParamsWebhookCreate) er
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// получаем информацию о пользователе по аксес токену и затем по его id
|
// получаем информацию о пользователе по аксес токену
|
||||||
userInfo, err := s.amoClient.GetUserInfo(tokens.AccessToken)
|
userInfo, err := s.amoClient.GetUserInfo(tokens.AccessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("error getting UserInfo in Service:", zap.Error(err))
|
s.logger.Error("error getting UserInfo in Service:", zap.Error(err))
|
||||||
@ -41,12 +40,9 @@ func (s *Service) WebhookCreate(ctx context.Context, req ParamsWebhookCreate) er
|
|||||||
Name: userInfo.Name,
|
Name: userInfo.Name,
|
||||||
Subdomain: userInfo.Subdomain,
|
Subdomain: userInfo.Subdomain,
|
||||||
AmoID: userInfo.ID,
|
AmoID: userInfo.ID,
|
||||||
// подключивший юзер считается тот который прокинул хук сюда
|
|
||||||
Amouserid: userInfo.ID,
|
Amouserid: userInfo.ID,
|
||||||
//Email: userInfoByID.Email,
|
//Group: tools.ConvertUserGroups(userInfo),
|
||||||
Group: tools.ConvertUserGroups(userInfo),
|
|
||||||
Country: userInfo.Country,
|
Country: userInfo.Country,
|
||||||
//Role: *userInfoByID.Role,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.repository.AmoRepo.CreateAccount(ctx, req.AccountID, toUpdate)
|
err = s.repository.AmoRepo.CreateAccount(ctx, req.AccountID, toUpdate)
|
||||||
|
@ -17,13 +17,13 @@ func ConvertUserGroups(groups *models.AmocrmUserInformation) []model.UserGroups
|
|||||||
return userGroups
|
return userGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertGroups(groups models.Users) []model.UserGroups {
|
//func ConvertGroups(groups models.Users) []model.UserGroups {
|
||||||
var userGroups []model.UserGroups
|
// var userGroups []model.UserGroups
|
||||||
for _, group := range groups.Embedded.Groups {
|
// for _, group := range groups.Embedded.Groups {
|
||||||
userGroups = append(userGroups, model.UserGroups{
|
// userGroups = append(userGroups, model.UserGroups{
|
||||||
ID: group.ID,
|
// ID: group.ID,
|
||||||
Name: group.Name,
|
// Name: group.Name,
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
return userGroups
|
// return userGroups
|
||||||
}
|
//}
|
||||||
|
@ -230,7 +230,7 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (wc *DataUpdater) UserUpdater(ctx context.Context, allTokens []model.Token) error {
|
func (wc *DataUpdater) UserUpdater(ctx context.Context, allTokens []model.Token) error {
|
||||||
var listUser []models.Users
|
listUser := make(map[string][]models.Users)
|
||||||
for _, token := range allTokens {
|
for _, token := range allTokens {
|
||||||
page := 1
|
page := 1
|
||||||
limit := 250
|
limit := 250
|
||||||
@ -248,28 +248,36 @@ func (wc *DataUpdater) UserUpdater(ctx context.Context, allTokens []model.Token)
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
listUser = append(listUser, userData.Embedded.Users...)
|
listUser[token.AccountID] = append(listUser[token.AccountID], userData.Embedded.Users...)
|
||||||
|
|
||||||
page++
|
page++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, user := range listUser {
|
for accountID, users := range listUser {
|
||||||
//onlyOneUser, err := wc.amoClient.GetUserByID(user.ID)
|
mainAccount, err := wc.repo.AmoRepo.GetCurrentAccount(ctx, accountID)
|
||||||
//if err != nil {
|
|
||||||
// wc.logger.Error("error getting user by id", zap.Error(err))
|
|
||||||
// continue
|
|
||||||
//}
|
|
||||||
err := wc.repo.AmoRepo.CheckUsers(ctx, user.ID, model.User{
|
|
||||||
Name: user.Name,
|
|
||||||
Group: tools.ConvertGroups(user),
|
|
||||||
Role: "todo",
|
|
||||||
Email: user.Email,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
for _, user := range users {
|
||||||
|
if user.ID == mainAccount.AmoID {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
err := wc.repo.AmoRepo.CheckAndUpdateUsers(ctx, model.User{
|
||||||
|
AmoID: user.ID,
|
||||||
|
Name: user.FullName,
|
||||||
|
Group: int32(*user.Embedded.Rights.GroupID),
|
||||||
|
Role: int32(*user.Embedded.Rights.RoleID),
|
||||||
|
Email: user.Email,
|
||||||
|
Amouserid: mainAccount.Amouserid,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -54,7 +54,7 @@ func NewAmoClient(deps AmoDeps) *Amo {
|
|||||||
func (a *Amo) GetUserList(req models.RequestGetListUsers, accesToken string) (*models.ResponseGetListUsers, error) {
|
func (a *Amo) GetUserList(req models.RequestGetListUsers, accesToken string) (*models.ResponseGetListUsers, error) {
|
||||||
for {
|
for {
|
||||||
if a.rateLimiter.Check() {
|
if a.rateLimiter.Check() {
|
||||||
uri := fmt.Sprintf("%s/api/v4/users?page=%d&limit=%d&with=role,group,uuid", a.baseApiURL, req.Page, req.Limit)
|
uri := fmt.Sprintf("https://penadigitaltech.amocrm.ru/ajax/v3/users?with=rights&page=%s&limit=%s", req.Page, req.Limit)
|
||||||
|
|
||||||
agent := a.fiberClient.Get(uri)
|
agent := a.fiberClient.Get(uri)
|
||||||
agent.Set("Authorization", "Bearer "+accesToken)
|
agent.Set("Authorization", "Bearer "+accesToken)
|
||||||
|
@ -109,14 +109,12 @@ func updateUser(ctx context.Context, repo *dal.AmoDal) error {
|
|||||||
AmoID: 666,
|
AmoID: 666,
|
||||||
Amouserid: int32(i),
|
Amouserid: int32(i),
|
||||||
Email: faker.Email(),
|
Email: faker.Email(),
|
||||||
Group: tools.ConvertUserGroups(&testUserInfo),
|
Group: int32(i),
|
||||||
Country: "Russia",
|
Country: "Russia",
|
||||||
}
|
}
|
||||||
|
|
||||||
if i%2 == 0 {
|
if i%2 == 0 {
|
||||||
role := faker.String()
|
info.Role = int32(i)
|
||||||
role2 := &role
|
|
||||||
info.Role = *role2
|
|
||||||
info.ID = faker.Int64()
|
info.ID = faker.Int64()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,13 +138,11 @@ func checkUsers(ctx context.Context, repo *dal.AmoDal) error {
|
|||||||
info := model.User{
|
info := model.User{
|
||||||
Name: faker.String(),
|
Name: faker.String(),
|
||||||
Email: faker.Email(),
|
Email: faker.Email(),
|
||||||
Group: tools.ConvertUserGroups(&testUserInfo),
|
Group: int32(i),
|
||||||
}
|
}
|
||||||
role := faker.String()
|
info.Role = int32(i)
|
||||||
role2 := &role
|
|
||||||
info.Role = *role2
|
|
||||||
|
|
||||||
err = repo.AmoRepo.CheckUsers(ctx, int32(i), info)
|
err = repo.AmoRepo.CheckAndUpdateUsers(ctx, info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user