-
Notifications
You must be signed in to change notification settings - Fork 577
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
Permissions api #1244
Permissions api #1244
Conversation
cbed574
to
c70c5e3
Compare
How much is remaining? |
@bigfish24 it's done, save for some documentation. At least I think so -- I am having problems with the tests on my machine -- I hope I will have it done by today. |
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.
Looks good to me. But I only see tests for read permissions. Don't we need to test that write implies read, etc.?
CHANGELOG.md
Outdated
@@ -8,6 +8,7 @@ X.Y.Z Release notes | |||
* Added property `Realm.isInTransaction` which indicates if write transaction is in progress. | |||
* Added `shouldCompactOnLaunch` to configuration (#507). | |||
* Added `Realm.compact()` for manually compacting Realm files. | |||
* Added various methods for permission management (#1204) |
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.
.
missing
docs/sync.js
Outdated
* @param {string} recipient the optional recipient of the permission. Can be either | ||
* 'any' which is the default, or 'currentUser' or 'otherUser' if you want only permissions | ||
* belonging to the user or *not* belonging to the user. | ||
* @returns {Results} a queryable collection of permission objects that provide detailed |
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.
"provide" -> "provides"?
docs/sync.js
Outdated
* Changes the permissions of a Realm. | ||
* @param {string} condition - A condition that will be used to match existing users against. | ||
* This should be an object, containing either the key 'userId', or 'metadataKey' and 'metadataValue'. | ||
* @param {string} realmUrl - The path to the realm that you want to apply permissions to. |
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.
"realm" -> "Realm"
docs/sync.js
Outdated
* @param {string} realmUrl - The path to the realm that you want to apply permissions to. | ||
* @param {string} accessLevel - The access level you want to set: 'none', 'read', 'write' or 'admin'. | ||
* @returns {Promise} a Promise that, upon completion, indicates that the permissions have been | ||
* successfully applied by the server. It will be resolved with the PermissionChange object that refers |
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.
"PermissionChange" - why not crossreference using @link
?
docs/sync.js
Outdated
* @param {string} realmUrl - The Realm URL whose permissions settings should be changed. Use * to change | ||
* the permissions of all Realms managed by this user. | ||
* @param {string} accessLevel - The access level to grant matching users. Note that the access level | ||
* setting is absolute, i.e. it may revoke permissions for users that previously had a higher access level. |
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.
"that" -> "who"
lib/permission-api.js
Outdated
|
||
// FIXME: I don't understand why, but removing the following setTimeout causes the subsequent | ||
// setTimeout call (when resolving the promise) to hang on RN iOS. | ||
// This might be related to our general makeCallback issues. |
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.
Do we have a Github issue?
lib/permission-api.js
Outdated
return Promise.reject(new Error('realmUrl must be specified')); | ||
} | ||
|
||
if (['none', 'read', 'write', 'admin'].indexOf(accessLevel) === -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.
Declare as constant validAccessLevels
and do validAccessLevels.join(',')
in error message?
tests/js/permission-tests.js
Outdated
@@ -0,0 +1,114 @@ | |||
//////////////////////////////////////////////////////////////////////////// | |||
// | |||
// Copyright 2016 Realm Inc. |
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.
"2016" -> "2017"
var Realm = require('realm'); | ||
var TestCase = require('./asserts'); | ||
|
||
function uuid() { |
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 we promote it to a general utility method?
tests/js/permission-tests.js
Outdated
Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, user) => { | ||
if (error) { | ||
reject(error); | ||
} else { |
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.
Line break after }
?
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.
Looks good. Probably needs a few more tests, but those can be added later on.
docs/sync.js
Outdated
|
||
/** | ||
* Changes the permissions of a Realm. | ||
* @param {string} condition - A condition that will be used to match existing users against. |
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 be {object}
rather than {string}
?
docs/sync.js
Outdated
* @param {string} realmUrl - The Realm URL whose permissions settings should be changed. Use * to change | ||
* the permissions of all Realms managed by this user. | ||
* @param {string} accessLevel - The access level to grant matching users. Note that the access level | ||
* setting is absolute, i.e. it may revoke permissions for users that previously had a higher access level. |
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.
My understanding is that the offerPermissions
access level setting is complimentary rather than absolute.
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.
This is copied from your documentation of the .NET equivalent: https://github.com/realm/realm-dotnet/blob/master/Realm/Realm.Sync/User.cs#L405
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.
Oh, shoot. Filed an issue to fix it: realm/realm-dotnet#1540
docs/sync.js
Outdated
offerPermissions(realmUrl, accessLevel, expiresAt) { } | ||
|
||
/** | ||
* Consumes a token generated by <see cref="OfferPermissions"/> to obtain permissions to a shared Realm. |
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.
Is the cref
correct?
const specialPurposeRealmsKey = '_specialPurposeRealms'; | ||
|
||
function getSpecialPurposeRealm(user, realmName, schema) { | ||
if (!user.hasOwnProperty(specialPurposeRealmsKey)) { |
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.
Perhaps there should be a comment explaining why we need to cache those realms (it's not clear to me and probably other people will wonder as well).
lib/permission-api.js
Outdated
else { | ||
const e = new Error(o.statusMessage); | ||
e.statusCode = o.statusCode; | ||
e.manamgementObject = o; |
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.
typo - manamgementObject
} | ||
} | ||
|
||
managementRealm.addListener('change', listener); |
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.
Doesn't js support object level notifications?
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.
Not yet: #763
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.
no
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.
😿
const _Realm = user.constructor._realmConstructor; | ||
|
||
return new Promise((resolve, reject) => { | ||
_Realm._waitForDownload(config, (error) => { |
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 use Realm.open. Seems this is duplicating the same logic
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 guess I could, it's just that it hasn't been added at this point, so I would have to reference the function directly through extensions.js somehow. Seemed hacky anyway.
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.
got it. 10x
@kristiandupont You can merge it if you create an issue about the failing tests on Chrome debugger. |
this change broke typescript definitions, TS will throw this error when importing realm now:
Issue: #1283 |
@rodrigopivi And #1285 should fix it. |
What, How & Why?
This creates an abstraction on top of the permissions system, making it simpler to apply, query and offer permissions.
Reference to the issue(s) addressed by this PR:
This fixes #1204
☑️ ToDos
Breaking
label has been applied or is not necessaryIf this PR adds or changes public API's: