diff --git a/cnxauthoring/tests/test_functional.py b/cnxauthoring/tests/test_functional.py index 9e49943..2a123ba 100644 --- a/cnxauthoring/tests/test_functional.py +++ b/cnxauthoring/tests/test_functional.py @@ -1011,6 +1011,11 @@ def test_post_content_revision_w_multiroles(self): # Test the object for internal data correctness from ..storage import storage document = storage.get(id=result['id']) + self.assertEqual( + sorted(document.licensor_acceptance, key=lambda v: v['id']), + [{'has_accepted': True, 'id': 'OSCRiceUniversity'}, + {'has_accepted': True, 'id': 'OpenStaxCollege'}, + {'has_accepted': True, 'id': 'cnxcap'}]) # Test the response data license = result.pop('license') self.assertEqual(license['url'], DEFAULT_LICENSE.url) diff --git a/cnxauthoring/utils.py b/cnxauthoring/utils.py index b8ab302..447845b 100644 --- a/cnxauthoring/utils.py +++ b/cnxauthoring/utils.py @@ -526,6 +526,8 @@ def declare_licensors(model): else: upstream_license_info = response.json() upstream = upstream_license_info.get('licensors', []) + upstream_user_ids = [x['uid'] for x in upstream] + existing_licensor_ids = set([l['id'] for l in model.licensor_acceptance]) # Scan the roles for newly added attribution. In the event that # one or more has been added, add them to the licensor_acceptance. @@ -534,10 +536,15 @@ def declare_licensors(model): for role_type in PUBLISHING_ROLES_MAPPING.values(): local_roles.extend(model.metadata.get(role_type, [])) local_role_ids = set([r['id'] for r in local_roles]) - existing_licensor_ids = set([l['id'] for l in model.licensor_acceptance]) - for new_role in local_role_ids.difference(existing_licensor_ids): - model.licensor_acceptance.append({'id': new_role, - 'has_accepted': None}) + for uid in local_role_ids.difference(existing_licensor_ids): + has_accepted = None + if uid in upstream_user_ids: + # In the event that the role exists upstream, + # use their previous acceptance value. + idx = upstream_user_ids.index(uid) + has_accepted = upstream[idx]['has_accepted'] + model.licensor_acceptance.append({'id': uid, + 'has_accepted': has_accepted}) # Send licensors to publishing. payload = {