Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
Add license acceptance sync for revision creation. Addresses #138
Browse files Browse the repository at this point in the history
This will sync the license acceptance with publishing when a revision
is created.
  • Loading branch information
mmulich committed Dec 11, 2014
1 parent 12fa05c commit 842db99
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cnxauthoring/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions cnxauthoring/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 = {
Expand Down

0 comments on commit 842db99

Please sign in to comment.