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

Omniauth developer strategy #41

Merged
merged 15 commits into from
Nov 12, 2012
Merged

Conversation

KitaitiMakoto
Copy link
Collaborator

@kentaro san said "I want you to do with omniauth developer mode." to me at issue #29.
I'v done it at RubyWorld Conference 2012.

Usage:

  1. Create a user anyway.
  2. Click "Dev sign in" at /caveat.
  3. Enter the user's name and uid, then push "sign in" button.

Required Considerations

  • POST request to /auth/developer/callback is accepted. Is it OK?
  • No test. Is it needed even though developer strategy is activated only when RAILS_ENV=development?

Thanks!

@@ -1,5 +1,5 @@
def auth_params_for (user)
{
Hashie::Mash.new({
Copy link
Owner

Choose a reason for hiding this comment

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

Gemfileに依存かかかなくてもだいじょうぶですか?

Copy link
Owner

Choose a reason for hiding this comment

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

omniauthの依存で入ってくるんですねー

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

そうなんです。
実装の方でも使っていて、OmuniAuthが使うのをやめた時はこけてほしいので書かないままがいいと思います。
便利なので他で使うなら勿論入れちゃっていいと思いますが。

Copy link
Owner

Choose a reason for hiding this comment

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

了解ですー

Copy link
Collaborator

Choose a reason for hiding this comment

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

何かのライブラリで依存しているものを暗黙的に利用すると見通しが悪くなる気がするのですが、そうでもないのですかね?

Copy link
Owner

Choose a reason for hiding this comment

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

そうかもしれぬ

Copy link
Contributor

Choose a reason for hiding this comment

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

ここ、auth_params_for(:foo).uid みたいにすることが無いなら Hash でも良いような。

Copy link
Owner

Choose a reason for hiding this comment

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

Hasie::Mashを使いたいという強い意図を感じたのでそのままにしてありますw

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

あ、俺か。遅れてすんません。

Hashie::Mashを使いたいという強い意図のみなもとはここです。
https://github.com/kentaro/triglav/pull/41/files#L0R14

developer strategyではauth_paramsupdate_image(auth_params['extra']['raw_info']['avatar_url'])という物が入ってこないので、

update_image(auth_params['extra'] && auth_params['extra']['raw_info'] && auth_params['extra']['raw_info']['avatar_url'])

といったことをしなくちゃいけなくてだるいなあと思ってドットでつなげてtryとかpresent?とかを使えるようにしたかったです。
(その他の場所でドットを使うようにしたのはほとんどおまけです)

で、

何かのライブラリで依存しているものを暗黙的に利用すると見通しが悪くなる気がするのですが、

なんですが、OmuniAuthが渡してくれるrequest.env['omniauth.auth']auth_paramsはこれを返すだけのメソッド)が
そもそもHashie::Mashなのでテストデータの方でそれに揃えるのは妥当か、(だから↑のように楽しても許されるよね)と思って使いました。

ただまあ、こんな長い説明を要するのを見るに、すっきりしたストラテジーを自作するべきかも知れません……。

@kentaro
Copy link
Owner

kentaro commented Nov 8, 2012

POST request to /auth/developer/callback is accepted. Is it OK?

Seems OK. Go ahead.

No test. Is it needed even though developer strategy is activated only when RAILS_ENV=development?

Do you have any idea how you can test that?

@hsbt
Copy link
Contributor

hsbt commented Nov 8, 2012

No test. Is it needed even though developer strategy is activated only when RAILS_ENV=development?

Do you have any idea how you can test that?

To use Rails.stub(:env) { "development" } when running test.

@KitaitiMakoto
Copy link
Collaborator Author

Naruhodo! Thank you.
The rest of my worry is about database. I'll research and try to resolve it if problems there.

@kentaro
Copy link
Owner

kentaro commented Nov 8, 2012

Rails.stub(:env) { "development" }

I never came up with such an idea!

@KitaitiMakoto
Copy link
Collaborator Author

@kentaro san
I think this branch is ready to be merged.
Could you review it?

def update_privilege
if Settings.github.try(:organizations).present?
def update_privilege(provider)
if provider == 'github' && Settings.github.try(:organizations).present?
Copy link
Contributor

Choose a reason for hiding this comment

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

To use Settings.github.organizations.presence instead of `Settings.github.try(:organizations).present?``

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

確かにtryは全然いりませんね。
if節の中では述語のpresent?の方がしっくりくるのですがどうでしょう。

@kentaro
Copy link
Owner

kentaro commented Nov 11, 2012

@KitaitiMakoto
I'll merge this pull request after you do with the points @hsbt said

@kentaro
Copy link
Owner

kentaro commented Nov 12, 2012

Merge origin/master to this branch, plz.

@hsbt
Copy link
Contributor

hsbt commented Nov 12, 2012

コメントが消えていた! try(:attr).present? でも許容出来る範囲なのですが、try で存在するかどうかをチェックしてなおかつ present? でチェックというのは何かむずむずするなあと思った次第です。

@KitaitiMakoto
Copy link
Collaborator Author

コメントが消えていた!

ソースから該当行が無くなったので「hsbt discussed an outdated diff 2 days ago Show outdated diff」というところに隠れてしまいました。
http://gyazo.com/6560535af460f3231856d27ff9147ce0
(何日か前の @glidenote さんと @kyanny さんのやり取りで知りました)

何かむずむずするなあ

指摘されて僕もそう思いました。
24c0dcf
↑でtryだけ外しました。

kentaro added a commit that referenced this pull request Nov 12, 2012
@kentaro kentaro merged commit 36f6527 into kentaro:master Nov 12, 2012
@kentaro
Copy link
Owner

kentaro commented Nov 12, 2012

Thanks!!1 Great job!!1

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.

None yet

4 participants