Commit b5019f2e4156cea5cbbfc39ea2c7dc81ad4cd11c

Authored by Victor Costa
1 parent 89469f71

oauth_client: improve admin view

plugins/oauth_client/lib/oauth_client_plugin.rb
... ... @@ -63,9 +63,7 @@ class OauthClientPlugin < Noosfero::Plugin
63 63 environment = domain.environment rescue Environment.default
64 64 settings = Noosfero::Plugin::Settings.new(environment, OauthClientPlugin)
65 65 providers = settings.get_setting(:providers)
66   -
67   - strategy.options.client_id = providers[provider][:client_id]
68   - strategy.options.client_secret = providers[provider][:client_secret]
  66 + strategy.options.merge!(providers[provider][:options].symbolize_keys)
69 67 }
70 68  
71 69 provider provider, :setup => setup,
... ...
plugins/oauth_client/lib/omniauth/strategies/noosfero_oauth2.rb
... ... @@ -5,17 +5,11 @@ module OmniAuth
5 5 class NoosferoOauth2 < OmniAuth::Strategies::OAuth2
6 6 option :name, :noosfero_oauth2
7 7  
8   - option :client_options, {
9   - :site => "http://noosfero.com:3001",
10   - :authorize_url => "/oauth/authorize"
11   - }
12   -
13 8 uid { raw_info["id"] }
14 9  
15 10 info do
16 11 {
17 12 :email => raw_info["email"]
18   - # and anything else you want to return to your API consumers
19 13 }
20 14 end
21 15  
... ...
plugins/oauth_client/views/oauth_client_plugin_admin/_noosfero_oauth2.html.erb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<%= options.fields_for :client_options, OpenStruct.new(provider.options[:client_options]) do |c| %>
  2 + <div class="client-url">
  3 + <span class="label"><%= _('Client Url') %></span>
  4 + <span class="value"><%= c.text_field :site %></span>
  5 + </div>
  6 +<% end %>
... ...
plugins/oauth_client/views/oauth_client_plugin_admin/index.html.erb
... ... @@ -7,13 +7,15 @@
7 7  
8 8 <% OauthClientPlugin::PROVIDERS.each do |available_provider, options| %>
9 9 <% provider = OpenStruct.new(@providers[available_provider]) %>
  10 + <% provider.options ||= {} %>
10 11  
11   - <%= p.fields_for available_provider, provider do |o| %>
  12 + <%= p.fields_for available_provider, provider do |a| %>
12 13 <div class="provider">
13 14 <div class="name">
14   - <h4><%= o.check_box :enabled, {:class => 'enable', :checked => provider.enabled=='true'}, true, false %>
  15 + <h4><%= a.check_box :enabled, {:class => 'enable', :checked => provider.enabled=='true'}, true, false %>
15 16 <%= options[:name] %></h4>
16 17 </div>
  18 + <%= a.fields_for :options, OpenStruct.new(provider.options) do |o| %>
17 19 <div class="options" style="<%= provider.enabled=='true' ? '':'display:none' %>">
18 20 <div class="client-id">
19 21 <span class="label"><%= _('Client ID') %></span>
... ... @@ -23,7 +25,11 @@
23 25 <span class="label"><%= _('Client Secret') %></span>
24 26 <span class="value"><%= o.text_field :client_secret %></span>
25 27 </div>
  28 + <% if File.exists?(File.join(File.dirname(__FILE__), "_#{available_provider}.html.erb")) %>
  29 + <%= render :partial => "#{available_provider}", :locals => {:options => o, :provider => provider} %>
  30 + <% end %>
26 31 </div>
  32 + <% end %>
27 33 </div>
28 34 <% end %>
29 35 <% end %>
... ...