Skip to content

Conversation

@bajtos
Copy link
Member

@bajtos bajtos commented Mar 3, 2017

While finalizing strongloop/loopback#3231, I realised the instructions added by #297 are not entirely correct. See also strongloop/loopback#3215 (comment) and next few comments following after that.

This pull request fixes the instructions to what I believe is correct.

cc @beeman

Connect to strongloop/loopback#3215

@bajtos bajtos requested review from crandmck and ebarault March 3, 2017 09:56
@bajtos bajtos added the review label Mar 3, 2017
Copy link
Contributor

@crandmck crandmck left a comment

Choose a reason for hiding this comment

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

I made some wording edits in your branch. I had one specific comment. Otherwise LGTM.

"relations": {
"user": {
"type": "belongsTo",
"model": "user",
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to use a model named "customer" or "myUser" or anything other than "user" which is confusingly close to "User", the name of the built-in model....?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that user is confusingly close to User. On the other hand, using user model is a common workaround for the fact that LoopBack does not provide any easy way how to customise the built-in User model.

@ebarault Unless you object, I will change "user" to "Customer".

Copy link
Contributor

Choose a reason for hiding this comment

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

i'm good with user for @bajtos 's reasons

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW : while being a good practice in any case: is this absolutely required for single user model scenario since you've fixed the possibility of the missing relation with user here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

is this absolutely required for single user model scenario

Well, it's not absolutely required, but only as long as we don't introduce another place that relies of this relation being correctly set up.

In strongloop/loopback#3231, I added a big warning that's printed when this relation is not configured, to prevent situations like that to reappear in the future.

" %}

#### Access control with a single user model
#### Access control with a single user model and built-in AccessToken model
Copy link
Contributor

Choose a reason for hiding this comment

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

I would then suppress this sub-section at the root of the

Preparing access control models section.

And i'd isolate the following text

In the most common scenario, an application uses only one model that extends the built-in User model and uses the built-in AccessToken model

in a

Access control with a single user model

section, adding a note like : "you're all set-up!'

This way we preserve 2 formal sections for single user model / multiple user models, which IMO gives more confidence to people on whether they've done right or have missed something

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll change this L4 heading to Access control with a single user model and then change the heading Customizing the AccessToken model to L5.


A more complex situation is when the different types of users differ not just in their properties, but also by their access rights and relations with other models. For example, applications where the concept of an _organization_ is involved, creating intertwined layers of relationships and thus of access control.
Such circumstances require the application to manage the different user types in separate models.
If however the different types of users have different access rights and relations with other models,
Copy link
Contributor

Choose a reason for hiding this comment

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

'+ or if they basically different too greatly by their properties

"relations": {
"user": {
"type": "belongsTo",
"model": "user",
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm good with user for @bajtos 's reasons

@bajtos
Copy link
Member Author

bajtos commented Mar 7, 2017

Updated, PTAL.

@bajtos bajtos requested review from crandmck and ebarault March 7, 2017 14:56
@beeman
Copy link

beeman commented Mar 7, 2017

I will go over the setup once again based on these instructions later today

@ebarault
Copy link
Contributor

ebarault commented Mar 8, 2017

just pushed one commit to add more clarity (hopefully) and align code syntax in json model excerpts.

Copy link
Contributor

@ebarault ebarault left a comment

Choose a reason for hiding this comment

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

i'm good with your changes @bajtos , please see my additional proposals in the next commit


Normally you should have already implemented at least one custom user model, extending the built-in `User` model, as described in [Using built-in models](Using-built-in-models.html#user-model).
The best practice is to implement at least one custom user model extending the built-in `User` model instead of using the built-in `User` model as-is, as described in [Using built-in models](Using-built-in-models.html#user-model).

Copy link
Contributor

Choose a reason for hiding this comment

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

i just wanted here to avoid the repetition

  1. normally you ..
  2. usually you ..

and tried to be a bit more directive so do get developers' confidence


This is achieved by changing the **hasMany** relation from `User` to `AccessToken` and the **belongsTo** relation from `AccessToken` to `User` by their [polymorphic](Polymorphic-relations.html) equivalents, in which the `principalType` property is used as a _discriminator_ to resolve which of the potential `user` model instance an 'accessToken' instance belongs to.
This is achieved by changing the **hasMany** relation from `User` to `AccessToken` and the **belongsTo** relation from `AccessToken` to `User` by their [polymorphic](Polymorphic-relations.html) equivalents, in which the `principalType` property is used as a _discriminator_ to resolve which of the potential `user` model instance an 'accessToken' instance belongs to. In addition to having custom user models this requires you also define a **custom AccessToken** model extending the built-in `AccessToken` model.

Copy link
Contributor

Choose a reason for hiding this comment

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

i added this part for the sake a clarity
"In addition to having custom user models this requires you also define a custom AccessToken model extending the built-in AccessToken model"

@crandmck
Copy link
Contributor

crandmck commented Mar 8, 2017

LGTM

@bajtos
Copy link
Member Author

bajtos commented Mar 9, 2017

@ebarault thanks, your proposed changes looks good to me too.
@crandmck thank you for the review.

I have squashed the commits to a single one and land this patch once CI passes.

@bajtos bajtos merged commit 4d53ecb into gh-pages Mar 9, 2017
@bajtos bajtos deleted the fix/auth-setup branch March 9, 2017 07:51
@bajtos bajtos removed the review label Mar 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants