-
Notifications
You must be signed in to change notification settings - Fork 33
feat/policiesForRecords #108
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #108 +/- ##
==========================================
- Coverage 96.6% 94.75% -1.85%
==========================================
Files 8 9 +1
Lines 206 248 +42
Branches 48 57 +9
==========================================
+ Hits 199 235 +36
- Misses 7 13 +6
Continue to review full report at Codecov.
|
| 'sender': user1 | ||
| }; | ||
|
|
||
| assert.equal(tx.logs[0].event, 'LinniaPolicyChecked'); |
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.
It would be good to check for the new event logs.
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.
The new event logs aren't available in the returned transaction logs. I test for them in the method that emits them though
|
|
||
|
|
||
| contract /* interface */ PermissionPolicyMock is PermissionPolicyI { | ||
| contract /* interface */ PolicyMock is PolicyI { |
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.
remove /* interface */
godfreyhobbs
left a comment
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.
I don't think this makes sense to have the policies in a different contract. If we update the new policy contract we will remove all of the records policies. This seems to be a security hole.
I think this all needs to be in the same contract until we have a way of migrating data when contracts are updated.
836308a to
ad50229
Compare
| const LinniaRecords = artifacts.require('./LinniaRecords.sol'); | ||
| const LinniaPolicies = artifacts.require('./LinniaPolicies.sol'); | ||
| const irisScoreProvider = artifacts.require('./mock/IrisScoreProviderMock.sol'); | ||
| const Policy = artifacts.require('./mock/PolicyMock.sol'); |
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.
consider naming PolicyMock
|
consider adding the following to the 3_records_test.js and 5_records-token_test.js |
| /* @param viewer the address of the person being given access the record */ | ||
| /* @param dataUri where the record is */ | ||
| /* @param policies an array of the policy conforming addresses */ | ||
| function policyIsValid( |
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.
I think this should be internal
| /* @param dataHash the dataHash of the record being checked */ | ||
| /* @param viewer the address of the person being given access the record */ | ||
| /* @param dataUri where the record is */ | ||
| function followsExistingPolicies( |
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.
I think this should be internal
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.
Agreed. I'll change
| /* @param viewer the address of the person being given access the record */ | ||
| /* @param dataUri where the record is */ | ||
| /* @param policies an array of the policy conforming addresses */ | ||
| function policiesAreValid( |
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.
I think this should be internal
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.
People may want to reveal to people which policies their records and permissions can/will conform with from a UI. Keeping public also allows people to surface better error messages from the UI
| public | ||
| returns (bool) | ||
| { | ||
| return policiesAreValid( |
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.
why not inline this method. Seems easier to be calling policiesAreValid directly rather than using this wrapper and spending gas.
|
|
||
| /* @dev allows a record owner to add a policy to a record as long as it conforms */ | ||
| /* @param dataHash the record the owner is adding a policy to */ | ||
| /* @param policy an address of a contract that conforms to the policy interface to add */ |
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.
consider rewording:
an address of a contract that conforms to the policy interface to add
| require(hub.policiesContract().policyIsValid( | ||
| dataHash, | ||
| msg.sender, | ||
| records[dataHash].dataUri, |
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.
I am not sure why this check is needed. Can you explain?
| policy | ||
| )); | ||
|
|
||
| policies[dataHash].push(policy); |
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.
A few things:
- It would be good to revert if the policy has already been added.
- Also would be good to check for address(0)
- It would be good to check that this address conforms to the interface (not sure how todo this)
| external | ||
| returns (bool) | ||
| { | ||
| /* @dev search through the policies for the record */ |
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.
consider reverting if nothing is deleted.
| returns (bool) | ||
| { | ||
| /* @dev search through the policies for the record */ | ||
| for (uint i = 0; i < policies[dataHash].length; i++) { |
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.
consider saving policies[dataHash].length to local var. This may be doing the lookup for every loop.
| } | ||
| } | ||
|
|
||
| return true; |
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.
I would only return true if something was actually deleted.
| /* @dev if one is found */ | ||
| if (policies[dataHash][i] == policy) { | ||
| /* @dev remove the policy by shifting everything over and shortening array */ | ||
| while (i < policies[dataHash].length - 1) { |
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.
use the swap method here it will use much less gas.
| i++; | ||
| } | ||
|
|
||
| policies[dataHash].length--; |
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.
move return true here.
| returns (bool) | ||
| { | ||
|
|
||
| require(_addRecord(dataHash, msg.sender, metadata, dataUri)); |
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.
Should this come after the policy check? Please add a comment on why this is first.
| require(_addRecord(dataHash, msg.sender, metadata, dataUri)); | ||
|
|
||
| for (uint i = 0; i < newPolicies.length; i++) { | ||
| /* @dev make sure the record conforms with each of the policies,then add*/ |
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.
comment suggest adding is after this but it is before.
Implements policy constrained record appending and persistent record based policies.
Users now have the option to check against policies when appending data. These policies are stored, and again checked when user grants access for file to new users.
Also allows users to add and remove policies for their records.