Skip to content

Commit 3d26519

Browse files
authored
Merge pull request #4471 from nickmango/release-ecla-ack
Release ecla ack
2 parents 5c501a8 + edd3e46 commit 3d26519

File tree

3 files changed

+81
-13
lines changed

3 files changed

+81
-13
lines changed

cla-backend-go/signatures/repository.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4628,6 +4628,19 @@ func (repo repository) GetClaGroupCorporateContributors(ctx context.Context, cla
46284628
totalCountChannel := make(chan int64, 1)
46294629
go repo.getTotalCorporateContributorCount(ctx, claGroupID, companyID, searchTerm, totalCountChannel)
46304630

4631+
totalCount := <-totalCountChannel
4632+
log.WithFields(f).Debugf("total corporate contributor count: %d", totalCount)
4633+
// If the page size is nil, set it to the default
4634+
if pageSize == nil {
4635+
pageSize = aws.Int64(10)
4636+
}
4637+
4638+
if *pageSize > totalCount {
4639+
pageSize = aws.Int64(totalCount)
4640+
}
4641+
4642+
log.WithFields(f).Debugf("total corporate contributor count: %d, page size: %d", totalCount, *pageSize)
4643+
46314644
condition := expression.Key("signature_project_id").Equal(expression.Value(claGroupID))
46324645
// if companyID != nil {
46334646
// sortKey := fmt.Sprintf("%s#%v#%v#%v", utils.ClaTypeECLA, true, true, *companyID)
@@ -4660,11 +4673,6 @@ func (repo repository) GetClaGroupCorporateContributors(ctx context.Context, cla
46604673
return nil, err
46614674
}
46624675

4663-
// If the page size is nil, set it to the default
4664-
if pageSize == nil {
4665-
pageSize = aws.Int64(10)
4666-
}
4667-
46684676
// Assemble the query input parameters
46694677
queryInput := &dynamodb.QueryInput{
46704678
ExpressionAttributeNames: expr.Names(),
@@ -4692,7 +4700,9 @@ func (repo repository) GetClaGroupCorporateContributors(ctx context.Context, cla
46924700
out := &models.CorporateContributorList{List: make([]*models.CorporateContributor, 0)}
46934701
var lastEvaluatedKey string
46944702

4695-
for ok := true; ok; ok = lastEvaluatedKey != "" {
4703+
currentCount := int64(0)
4704+
4705+
for ok := true; ok; ok = lastEvaluatedKey != "" && currentCount < *pageSize {
46964706
// Make the DynamoDB Query API call
46974707
log.WithFields(f).Debug("querying signatures...")
46984708
results, queryErr := repo.dynamoDBClient.Query(queryInput)
@@ -4766,26 +4776,28 @@ func (repo repository) GetClaGroupCorporateContributors(ctx context.Context, cla
47664776
SignatureApproved: sig.SignatureApproved,
47674777
SignatureSigned: sig.SignatureSigned,
47684778
})
4779+
4780+
// Increment the current count
4781+
currentCount++
4782+
if currentCount >= *pageSize {
4783+
break
4784+
}
47694785
}
47704786

4771-
if results.LastEvaluatedKey["signature_id"] != nil {
4787+
if results.LastEvaluatedKey["signature_id"] != nil && currentCount < *pageSize {
47724788
lastEvaluatedKey = *results.LastEvaluatedKey["signature_id"].S
47734789
queryInput.ExclusiveStartKey = results.LastEvaluatedKey
47744790
} else {
47754791
lastEvaluatedKey = ""
47764792
}
47774793

4778-
if int64(len(out.List)) >= *pageSize {
4779-
break
4780-
}
4781-
47824794
}
47834795
sort.Slice(out.List, func(i, j int) bool {
47844796
return out.List[i].Name < out.List[j].Name
47854797
})
47864798

4787-
out.ResultCount = int64(len(out.List))
4788-
out.TotalCount = <-totalCountChannel
4799+
out.ResultCount = currentCount
4800+
out.TotalCount = totalCount
47894801
out.NextKey = lastEvaluatedKey
47904802

47914803
return out, nil

cla-backend/cla/models/docusign_models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import xml.etree.ElementTree as ET
1919
from typing import Any, Dict, List, Optional
2020
from urllib.parse import urlparse
21+
from datetime import datetime
2122

2223
import cla
2324
import pydocusign # type: ignore
@@ -784,6 +785,8 @@ def _save_employee_signature(self,signature):
784785
'signature_approved': {'BOOL': signature.get_signature_approved()},
785786
'signature_acl': {'SS': list(signature.get_signature_acl())},
786787
'signature_user_ccla_company_id': {'S': signature.get_signature_user_ccla_company_id()},
788+
'date_modified': {'S': datetime.now().isoformat()},
789+
'date_created': {'S': datetime.now().isoformat()}
787790
}
788791

789792
if signature.get_signature_return_url() is not None:
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import unittest
2+
from unittest.mock import Mock, patch
3+
import datetime
4+
5+
from cla.models.docusign_models import DocuSign
6+
7+
def test_save_employee_signature(project, company, user_instance):
8+
""" Test _save_employee_signature """
9+
# Mock DocuSign method and related class methods
10+
DocuSign.check_and_prepare_employee_signature = Mock(return_value={'success': {'the employee is ready to sign the CCLA'}})
11+
12+
# Create an instance of DocuSign and mock its dynamo_client
13+
docusign = DocuSign()
14+
docusign.dynamo_client = Mock() # Mock the dynamo_client on the instance
15+
mock_put_item = docusign.dynamo_client.put_item = Mock()
16+
17+
# Mock ecla signature object with necessary attributes for the helper method
18+
signature = Mock()
19+
signature.get_signature_id.return_value = "sig_id"
20+
signature.get_signature_project_id.return_value = "proj_id"
21+
signature.get_signature_document_minor_version.return_value = 1
22+
signature.get_signature_document_major_version.return_value = 2
23+
signature.get_signature_reference_id.return_value = "ref_id"
24+
signature.get_signature_reference_type.return_value = "user"
25+
signature.get_signature_type.return_value = "cla"
26+
signature.get_signature_signed.return_value = True
27+
signature.get_signature_approved.return_value = True
28+
signature.get_signature_acl.return_value = ['acl1', 'acl2']
29+
signature.get_signature_user_ccla_company_id.return_value = "company_id"
30+
signature.get_signature_return_url.return_value = None
31+
signature.get_signature_reference_name.return_value = None
32+
33+
# Call the helper method
34+
docusign._save_employee_signature(signature)
35+
36+
# Check if dynamo_client.put_item was called
37+
assert mock_put_item.called
38+
39+
# Extract the 'Item' argument passed to put_item
40+
_, kwargs = mock_put_item.call_args
41+
item = kwargs['Item']
42+
43+
# Assert that 'date_modified' and 'date_created' are in the item
44+
assert 'date_modified' in item
45+
assert 'date_created' in item
46+
47+
48+
# Optionally, check if they are correctly formatted ISO timestamps
49+
try:
50+
datetime.datetime.fromisoformat(item['date_modified']['S'])
51+
datetime.datetime.fromisoformat(item['date_created']['S'])
52+
except ValueError:
53+
assert False, "date_modified or date_created are not valid ISO format timestamps"

0 commit comments

Comments
 (0)