Paste #138144

   
pasted on 12.07.2020 17:37
  • Edit to this paste
  • Print
  • Raw
  • The following pastes replied to this paste:  # 143520 # 154592
  • Show paste tree
  • Compare with paste
    #  
  • Toggle line numbers
  • Syntax highlighting  
Text paste
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
func (srv *CompanyPersonService) ServiceGetAuthPerson(ctx context.Context, companyPerson models.CompanyPerson) (result map[string]interface{}) {
	session, _ := utils.ContextGetSession(ctx)
	result = srv.getAuthPersonsList(ctx, session, companyPerson)
	logger.WorkLogger.Debug("ServiceGetAuthPerson", zap.Any("companyPerson", companyPerson))
	result["signAllow"] = companyPerson.IsSignAllow == consts.True //srv.compPersonAuth.FindSignAllowOfCompanyPerson(srv.db, companyPerson.ID)
	result["privileges"] = strings.Split(session.Permissions, ",")
	result["personType"] = "LegalEntity" // todo: personType.LegalEntity not implemented

	return
}

func (srv *CompanyPersonService) getAuthPersonsList(ctx context.Context, session models.Session, companyPerson models.CompanyPerson) (result map[string]interface{}) {
	result = make(map[string]interface{})
	dList := make([]models.CompanyPerson, 0)
	if list, err := srv.FindAllCompanyPersonByUserAccount(companyPerson.UserAccountID); err == nil {
		logger.WorkLogger.Debug("getAuthPersonsList", zap.Any("list", list))
		if utils.IsFactorPassed(ctx, consts.AuthFactorTypeSignature) {
			logger.WorkLogger.Debug("getAuthPersonsList 2", zap.Any("list", list))
			sessionFactor := utils.GetPassedFactor(ctx, consts.AuthFactorTypeSignature)
			certificateSerialNumber := sessionFactor.FactorSn
			if acpList, err := srv.certificate.FindAllBySN(srv.db, certificateSerialNumber); err == nil {
				authenticatedCompanyPersons := make([]map[string]interface{}, 0)
				for _, acp := range acpList {
					authenticatedCompanyPersons = append(authenticatedCompanyPersons, acp.ConvertToDTO())
				}
				if len(authenticatedCompanyPersons) == 0 {
					list = []models.CompanyPerson{}
				} else {
					for _, authCPerson := range authenticatedCompanyPersons {
						for _, cPerson := range list {
							if cPerson.ID == authCPerson["id"] {
								dList = append(dList, cPerson)
							}
						}
					}
				}
			} else {
				logger.WorkLogger.Debug("FindAllBySN", zap.Error(err))
			}
		} else {
			logger.WorkLogger.Debug("IsFactorPassed", zap.Error(err))
		}
	} else {
		logger.WorkLogger.Debug("getAuthPersonsList", zap.Error(err))
	}

	intlPersons := make([]interface{}, 0)
	personList := make([]interface{}, 0)

	if len(dList) != 0 {
		for _, person := range dList {
			personList = append(personList, person)
		}
		result["persons"] = personList

		for _, person := range dList {
			intlPersons = append(intlPersons, map[string]interface{}{
				tools.Int64ToStr(person.ID): "",
			})
		}
		result["intlPersons"] = intlPersons
	}

	result["currentAuthPerson"] = companyPerson.ID
	result["currentAuthBIN"] = nil
	result["quickLinks"] = companyPerson.QuickLinks

	allFactors := make([]string, 0)
	factors := srv.loginChain.GetAllFactorsName(srv.db)
	for _, sessionFactor := range session.Factors {
		if sessionFactor.SessionFactorType == consts.AuthFactorTypeSignature &&
			sessionFactor.AuthPersonID.Int64 == companyPerson.ID || sessionFactor.SessionFactorType != consts.AuthFactorTypeSignature {
			for _, f := range factors {
				if f != string(sessionFactor.SessionFactorType) {
					allFactors = append(allFactors, f)
				}
			}
		}
	}
	result["addfactors"] = allFactors
	return
}
Add Comment
Author