-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transfer a right #17
Merged
Merged
Transfer a right #17
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c793afb
Use alice and bob for users
sohkai 104f36c
Implement Rights transfers
sohkai 3058771
Add documentation for rights transfers
sohkai de8f03c
Avoid passing secret details of recipient in transfer
sohkai bbe8ec0
Add documentation on end-to-end use case
sohkai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,22 @@ def app(): | |
|
||
|
||
@pytest.fixture | ||
def user(client): | ||
def alice(client): | ||
return client.post(url_for('user_views.userapi')).json | ||
|
||
|
||
@pytest.fixture | ||
def created_manifestation_resp(client, user): | ||
def bob(client): | ||
return client.post(url_for('user_views.userapi')).json | ||
|
||
|
||
@pytest.fixture | ||
def carly(client): | ||
return client.post(url_for('user_views.userapi')).json | ||
|
||
|
||
@pytest.fixture | ||
def created_manifestation_resp(client, alice): | ||
import json | ||
from time import sleep | ||
payload = { | ||
|
@@ -25,7 +35,7 @@ def created_manifestation_resp(client, user): | |
'datePublished': '29-07-1954', | ||
'url': 'http://localhost/lordoftherings.txt', | ||
}, | ||
'copyrightHolder': user, | ||
'copyrightHolder': alice, | ||
'work': { | ||
'name': 'The Lord of the Rings Triology', | ||
'author': 'J. R. R. Tolkien', | ||
|
@@ -39,3 +49,27 @@ def created_manifestation_resp(client, user): | |
# Sleep for a bit to let the transaction become valid | ||
sleep(3) | ||
return resp.json | ||
|
||
|
||
@pytest.fixture | ||
def created_derived_right(client, alice, created_manifestation_resp): | ||
import json | ||
from time import sleep | ||
|
||
copyright_id = created_manifestation_resp['copyright']['@id'] | ||
copyright_id = copyright_id.split('../rights/')[1] | ||
payload = { | ||
'currentHolder': alice, | ||
'right': { | ||
'license': 'http://www.ascribe.io/terms', | ||
}, | ||
'sourceRightId': copyright_id, | ||
} | ||
|
||
resp = client.post(url_for('right_views.rightapi'), | ||
data=json.dumps(payload), | ||
headers={'Content-Type': 'application/json'}) | ||
|
||
# Sleep for a bit to let the transaction become valid | ||
sleep(3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😴 |
||
return resp.json['right'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from flask import Blueprint | ||
from flask_restful import reqparse, Resource, Api | ||
|
||
from coalaip import CoalaIp | ||
from coalaip import CoalaIp, ModelDataError, entities | ||
from coalaip_bigchaindb.plugin import Plugin | ||
from web.models import right_model, user_model | ||
from web.models import right_model, public_user_model, user_model | ||
from web.utils import get_bigchaindb_api_url | ||
|
||
|
||
|
@@ -42,4 +42,49 @@ def post(self): | |
return res | ||
|
||
|
||
class RightTransferApi(Resource): | ||
def post(self): | ||
parser = reqparse.RequestParser() | ||
parser.add_argument('rightId', type=str, required=True, | ||
location='json') | ||
parser.add_argument('currentHolder', type=user_model, required=True, | ||
location='json') | ||
parser.add_argument('to', type=public_user_model, required=True, | ||
location='json') | ||
parser.add_argument('rightsAssignment', type=dict, location='json') | ||
args = parser.parse_args() | ||
|
||
right_id = args['rightId'] | ||
current_holder = args['currentHolder'] | ||
to = args['to'] | ||
rights_assignment = args['rightsAssignment'] | ||
|
||
for user in [current_holder, to]: | ||
user['public_key'] = user.pop('publicKey') | ||
user['private_key'] = user.pop('privateKey') | ||
|
||
# We can't be sure of the type of Right that's given by using just the | ||
# id, so let's assume it's a normal Right first before trying to make a | ||
# Copyright | ||
try: | ||
right = entities.Right.from_persist_id(right_id, | ||
plugin=coalaip.plugin, | ||
force_load=True) | ||
except ModelDataError: | ||
right = entities.Copyright.from_persist_id(right_id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool, we can transfer a copyright as well! |
||
plugin=coalaip.plugin, | ||
force_load=True) | ||
|
||
res = coalaip.transfer_right(right=right, | ||
rights_assignment_data=rights_assignment, | ||
current_holder=current_holder, | ||
to=to) | ||
|
||
res = {'rightsAssignment': res.to_jsonld()} | ||
|
||
return res | ||
|
||
|
||
right_api.add_resource(RightApi, '/rights', strict_slashes=False) | ||
right_api.add_resource(RightTransferApi, '/rights/transfer', | ||
strict_slashes=False) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we'd add a document or sentence here that would state the conditions under which the Right is transferred, we'd also solve #6.