Skip to content

Auto-configure models required by app.enableAuth - #1323

Merged
bajtos merged 2 commits into
masterfrom
feature/autoconfigure-auth-models
Jun 2, 2015
Merged

bajtos merged 2 commits into
masterfrom
feature/autoconfigure-auth-models

Conversation

@bajtos

@bajtos bajtos commented Apr 21, 2015

Copy link
Copy Markdown
Member

Modify app.enableAuth to automaticaly setup all required models that are not attached to the app nor a datasource.

Users wishing to use this option must provide the name of the data-source to use for these models.

Example usage:

var app = loopback();
app.dataSource('db', { connector: 'memory' });
app.enableAuth({ dataSource: 'db' });

app.use(loopback.rest());
app.listen(3000);

The purpose of this new API is to make it easier to setup authentication from code that does not use "slc loopback" project scaffolding, typically from unit-tests.

/to @ritch @raymondfeng please review

Comment thread lib/application.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's going to happen if these models are sub-classed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's a good question. This shortcut is intended only for the simple situations where you typically don't create subclasses. To keep the implementation simple, I can modify the condition determining whether a base model should be attached or not, and do not attach a base model if there is a subclassed model already attached?

From user perspective, if you create let's say Customer extending User:

  • If Customer is attached to a data source or the app, then the builtin User model is left unchanged.
  • If Customer is not attached to the app nor the datasource, then we attach the builtin User model for you.

Thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good.

@ghost ghost changed the title Auto-configure models required by app.enableAuth 69- Auto-configure models required by app.enableAuth Apr 22, 2015
@ghost ghost changed the title 69- Auto-configure models required by app.enableAuth Auto-configure models required by app.enableAuth Apr 22, 2015
@bajtos

bajtos commented Apr 27, 2015

Copy link
Copy Markdown
Member Author

@ritch @raymondfeng ping

@ritch

ritch commented Apr 29, 2015

Copy link
Copy Markdown
Member

👍

Miroslav Bajtoš added 2 commits June 1, 2015 12:19
When creating an application with a local registry, the default
behaviour is to define only two core models Model & PersistedModel.

The new flag `loadBuiltinModels` modifies this behaviour and instructs
loopback to define all builtin models in the local registry too.
Modify `app.enableAuth` to automaticaly setup all required models
that are not attached to the app nor a datasource.

Users wishing to use this option must provide the name of the
data-source to use for these models.

Example usage:

    var app = loopback();
    app.dataSource('db', { connector: 'memory' });
    app.enableAuth({ dataSource: 'db' });

    app.use(loopback.rest());
    app.listen(3000);
@bajtos
bajtos force-pushed the feature/autoconfigure-auth-models branch from 30e0580 to 3115e50 Compare June 1, 2015 10:20
@bajtos

bajtos commented Jun 1, 2015

Copy link
Copy Markdown
Member Author

Reworked.

@raymondfeng PTAL again.

@ritch FYI, I have added a new loopback option loadBuiltinModels that can be used together with localRegistry, see 0ccc1e2.

@bajtos bajtos assigned raymondfeng and unassigned bajtos Jun 1, 2015
@ritch

ritch commented Jun 1, 2015

Copy link
Copy Markdown
Member

I have added a new loopback option loadBuiltinModels

Cool. We should start marking code like this somehow... so we can easily review it / modify it during major version changes.

@bajtos

bajtos commented Jun 1, 2015

Copy link
Copy Markdown
Member Author

@slnode test please

@ritch

ritch commented Jun 2, 2015

Copy link
Copy Markdown
Member

LGTM

1 similar comment
@raymondfeng

Copy link
Copy Markdown
Member

LGTM

@raymondfeng raymondfeng assigned bajtos and unassigned raymondfeng Jun 2, 2015
bajtos added a commit that referenced this pull request Jun 2, 2015
…odels

Auto-configure models required by `app.enableAuth`
@bajtos
bajtos merged commit 70ca7c5 into master Jun 2, 2015
@bajtos bajtos removed the #review label Jun 2, 2015
@bajtos
bajtos deleted the feature/autoconfigure-auth-models branch June 2, 2015 15:27
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.

3 participants