Сравнение постов
Различия между постами
#138144 (12.07.2020 17:37)
и
#143520 (29.08.2020 19:24).
1 | func (srv *CompanyPersonService) ServiceGetAuthPerson(ctx context.Context, companyPerson models.CompanyPerson) (result map[string]interface{}) { | |
1 | ||
2 | session, _ := utils.ContextGetSession(ctx) | |
3 | result = srv.getAuthPersonsList(ctx, session, companyPerson) | |
4 | logger.WorkLogger.Debug("ServiceGetAuthPerson", zap.Any("companyPerson", companyPerson)) | |
5 | result["signAllow"] = companyPerson.IsSignAllow == consts.True //srv.compPersonAuth.FindSignAllowOfCompanyPerson(srv.db, companyPerson.ID) | |
6 | result["privileges"] = strings.Split(session.Permissions, ",") | |
7 | result["personType"] = "LegalEntity" // todo: personType.LegalEntity not implemented | |
8 | ||
9 | return | |
10 | } | |
11 | ||
12 | func (srv *CompanyPersonService) getAuthPersonsList(ctx context.Context, session models.Session, companyPerson models.CompanyPerson) (result map[string]interface{}) { | |
13 | result = make(map[string]interface{}) | |
14 | dList := make([]models.CompanyPerson, 0) | |
15 | if list, err := srv.FindAllCompanyPersonByUserAccount(companyPerson.UserAccountID); err == nil { | |
16 | logger.WorkLogger.Debug("getAuthPersonsList", zap.Any("list", list)) | |
17 | if utils.IsFactorPassed(ctx, consts.AuthFactorTypeSignature) { | |
18 | logger.WorkLogger.Debug("getAuthPersonsList 2", zap.Any("list", list)) | |
19 | sessionFactor := utils.GetPassedFactor(ctx, consts.AuthFactorTypeSignature) | |
20 | certificateSerialNumber := sessionFactor.FactorSn | |
21 | if acpList, err := srv.certificate.FindAllBySN(srv.db, certificateSerialNumber); err == nil { | |
22 | authenticatedCompanyPersons := make([]map[string]interface{}, 0) | |
23 | for _, acp := range acpList { | |
24 | authenticatedCompanyPersons = append(authenticatedCompanyPersons, acp.ConvertToDTO()) | |
25 | } | |
26 | if len(authenticatedCompanyPersons) == 0 { | |
27 | list = []models.CompanyPerson{} | |
28 | } else { | |
29 | for _, authCPerson := range authenticatedCompanyPersons { | |
30 | for _, cPerson := range list { | |
31 | if cPerson.ID == authCPerson["id"] { | |
32 | dList = append(dList, cPerson) | |
33 | } | |
34 | } | |
35 | } | |
36 | } | |
37 | } else { | |
38 | logger.WorkLogger.Debug("FindAllBySN", zap.Error(err)) | |
39 | } | |
40 | } else { | |
41 | logger.WorkLogger.Debug("IsFactorPassed", zap.Error(err)) | |
42 | } | |
43 | } else { | |
44 | logger.WorkLogger.Debug("getAuthPersonsList", zap.Error(err)) | |
45 | } | |
46 | ||
47 | intlPersons := make([]interface{}, 0) | |
48 | personList := make([]interface{}, 0) | |
49 | ||
50 | if len(dList) != 0 { | |
51 | for _, person := range dList { | |
52 | personList = append(personList, person) | |
53 | } | |
54 | result["persons"] = personList | |
55 | ||
56 | for _, person := range dList { | |
57 | intlPersons = append(intlPersons, map[string]interface{}{ | |
58 | tools.Int64ToStr(person.ID): "", | |
59 | }) | |
60 | } | |
61 | result["intlPersons"] = intlPersons | |
62 | } | |
63 | ||
64 | result["currentAuthPerson"] = companyPerson.ID | |
65 | result["currentAuthBIN"] = nil | |
66 | result["quickLinks"] = companyPerson.QuickLinks | |
67 | ||
68 | allFactors := make([]string, 0) | |
69 | factors := srv.loginChain.GetAllFactorsName(srv.db) | |
70 | for _, sessionFactor := range session.Factors { | |
71 | if sessionFactor.SessionFactorType == consts.AuthFactorTypeSignature && | |
72 | sessionFactor.AuthPersonID.Int64 == companyPerson.ID || sessionFactor.SessionFactorType != consts.AuthFactorTypeSignature { | |
73 | for _, f := range factors { | |
74 | if f != string(sessionFactor.SessionFactorType) { | |
75 | allFactors = append(allFactors, f) | |
76 | } | |
77 | } | |
78 | } | |
79 | } | |
80 | result["addfactors"] = allFactors | |
81 | return |