Skip to content
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

Merged
merged 25 commits into from
Aug 29, 2017
Merged

Permissions api #1244

merged 25 commits into from
Aug 29, 2017

Conversation

kristiandupont
Copy link
Contributor

@kristiandupont kristiandupont commented Aug 24, 2017

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

  • 📝 Changelog entry
  • 🚦 Tests
  • 📝 Public documentation PR created or is not necessary
  • 💥 Breaking label has been applied or is not necessary

If this PR adds or changes public API's:

  • typescript definitions file is updated
  • jsdoc files updated
  • Chrome debug API is updated if API is available on React Native

@bigfish24
Copy link
Contributor

How much is remaining?

@kristiandupont
Copy link
Contributor Author

@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.

Copy link
Contributor

@kneth kneth left a 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)
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"that" -> "who"


// 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.
Copy link
Contributor

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?

return Promise.reject(new Error('realmUrl must be specified'));
}

if (['none', 'read', 'write', 'admin'].indexOf(accessLevel) === -1) {
Copy link
Contributor

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?

@@ -0,0 +1,114 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 Realm Inc.
Copy link
Contributor

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() {
Copy link
Contributor

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?

Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, user) => {
if (error) {
reject(error);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line break after }?

Copy link
Member

@nirinchev nirinchev left a 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.
Copy link
Member

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.
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.
Copy link
Member

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)) {
Copy link
Member

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).

else {
const e = new Error(o.statusMessage);
e.statusCode = o.statusCode;
e.manamgementObject = o;
Copy link
Member

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);
Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet: #763

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

Copy link
Member

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) => {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. 10x

@kneth
Copy link
Contributor

kneth commented Aug 29, 2017

@kristiandupont You can merge it if you create an issue about the failing tests on Chrome debugger.

@kristiandupont kristiandupont merged commit 402bf48 into master Aug 29, 2017
@kristiandupont
Copy link
Contributor Author

@kneth done: #1260

@rodrigopivi
Copy link

this change broke typescript definitions, TS will throw this error when importing realm now:

node_modules/realm/lib/index.d.ts(275,88): error TS2304: Cannot find name 'Permission'.
node_modules/realm/lib/index.d.ts(283,32): error TS2304: Cannot find name 'userId'.
node_modules/realm/lib/index.d.ts(284,32): error TS2304: Cannot find name 'metadataKey'.
node_modules/realm/lib/index.d.ts(284,45): error TS2374: Duplicate string index signature.
node_modules/realm/lib/index.d.ts(284,68): error TS2304: Cannot find name 'metadataValue'.

Issue: #1283

@kneth
Copy link
Contributor

kneth commented Sep 8, 2017

@rodrigopivi And #1285 should fix it.

@blagoev blagoev deleted the kd/permissions-api branch September 25, 2017 12:18
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Permissions API's
7 participants