Skip to content

Refactor fetching of SP attributes#1167

Merged
monfresh merged 1 commit intomasterfrom
mb-refactor-sp-session
Mar 6, 2017
Merged

Refactor fetching of SP attributes#1167
monfresh merged 1 commit intomasterfrom
mb-refactor-sp-session

Conversation

@monfresh
Copy link
Copy Markdown
Contributor

@monfresh monfresh commented Mar 3, 2017

Why: Now that Service Providers are stored in the DB, along
with all of their attributes, we can read the attributes directly
from the DB, as opposed to storing them in the session.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@hursey013 This is what I ended up doing to eliminate the Rubocop offenses:

  • move the flash message text to the existing session decorators
  • eliminate the need for methods like sp_metadata and sp_name in ApplicationController by reading the SP attributes from the DB via current_sp and decorated_session, which fetch the SP from the DB using the issuer provided by either sp_session or params.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is needed because ServiceProvider.from_issuer returns NullServiceProvider if no DB matches were found. From a session decorator standpoint, we want to treat a NullServiceProvider the same as the absence of an SP.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe class.to_s in case the class ever gets renamed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe just leave it nil to avoid confusion? We don't need a string. I wasn't trying to name it the same as the class.

Copy link
Copy Markdown
Contributor

@pkarman pkarman left a comment

Choose a reason for hiding this comment

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

lgtm % comments

Copy link
Copy Markdown
Contributor

@jessieay jessieay left a comment

Choose a reason for hiding this comment

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

👏 this is SO much better than what we have before

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💪

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this might be for a separate PR, but I wonder if it would be better to have an @sp or @current_sp instance var instead of all 3 of these, but to have this info available from that instance var. In general, having more than a couple of instance vars available in any one view is a 🔴 flag to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep. Great minds thing alike. I was going to create a view object in a separate PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we get sp_name from current_sp instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought about that, but that would mean creating a sp_name method in the ServiceProvider model, which goes against our rule of keeping business logic, and especially view-only logic out of models. What we could do is create a ServiceProviderDecorator that defines the logo, name, and return_to_sp_url.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

might prefer def sp_name; end for consistency with other methods that return nil in this class

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure thing.

**Why**: Now that Service Providers are stored in the DB, along
with all of their attributes, we can read the attributes directly
from the DB, as opposed to storing them in the session.
@monfresh monfresh force-pushed the mb-refactor-sp-session branch from 5bdbd1c to 19d38ab Compare March 6, 2017 16:23
end

def requested_attributes
OpenidConnectAttributeScoper.new(scopes).requested_attributes
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this line is the only thing this class does anymore, should we just remove the class entirely and write a @requested_attributes var directly in the controller?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Can we do that in a follow-up PR?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SGTM!

@monfresh monfresh merged commit 6afbdea into master Mar 6, 2017
@monfresh monfresh deleted the mb-refactor-sp-session branch March 6, 2017 17:55
amoose pushed a commit that referenced this pull request Mar 7, 2017
**Why**: Now that Service Providers are stored in the DB, along
with all of their attributes, we can read the attributes directly
from the DB, as opposed to storing them in the session.
amoose pushed a commit that referenced this pull request Mar 8, 2017
**Why**: Now that Service Providers are stored in the DB, along
with all of their attributes, we can read the attributes directly
from the DB, as opposed to storing them in the session.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants