Project

General

Profile

Feature #24808 » 0004-Redmine-style-UI-for-Doorkeeper-OAuth2-provider.patch

Jan from Planio www.plan.io, 2017-01-18 17:46

View differences:

app/views/doorkeeper/applications/_form.html.erb
1
<%= error_messages_for 'application' %>
2
<div class="box tabular">
3
  <p><%= f.text_field :name, :required => true %></p>
4

  
5
  <p>
6
    <%= f.text_area :redirect_uri, :required => true, :size => 60, :label => :'activerecord.attributes.doorkeeper/application.redirect_uri' %>
7
    <em class="info">
8
      <%= t('doorkeeper.applications.help.redirect_uri') %>
9
      <% if Doorkeeper.configuration.native_redirect_uri %>
10
        <br/><%= raw t('doorkeeper.applications.help.native_redirect_uri',
11
                native_redirect_uri: "<code>#{ Doorkeeper.configuration.native_redirect_uri }</code>") %>
12
      <% end %>
13
    </em>
14
  </p>
15

  
16
  <p>
17
    <%= f.text_field :scopes, :size => 60, :label => :'activerecord.attributes.doorkeeper/application.scopes'  %>
18
    <em class="info">
19
      <%= t('doorkeeper.applications.help.scopes') %>
20
    </em>
21
  </p>
22

  
23

  
24

  
25
</div>
app/views/doorkeeper/applications/edit.html.erb
1
<%= title [t('doorkeeper.applications.index.title'), oauth_applications_path], @application.name %>
2

  
3
<%= labelled_form_for @application, url: doorkeeper_submit_path(@application) do |f| %>
4
  <%= render :partial => 'form', :locals => {:f => f} %>
5
  <%= submit_tag l(:button_save) %>
6
<% end %>
app/views/doorkeeper/applications/index.html.erb
1
<div class="contextual">
2
<%= link_to t('.new'), new_oauth_application_path, :class => 'icon icon-add' %>
3
</div>
4

  
5
<%= title t('.title') %>
6

  
7
<% if @applications.any? %>
8
<div class="autoscroll">
9
<table class="list">
10
  <thead><tr>
11
    <th><%= t('.name') %></th>
12
    <th><%= t('.callback_url') %></th>
13
    <th><%= t('.scopes') %></th>
14
    <th></th>
15
  </tr></thead>
16
  <tbody>
17
  <% @applications.each do |application| %>
18
    <tr id="application_<%= application.id %>" class="<%= cycle("odd", "even") %>">
19
      <td class="name"><span><%= link_to application.name, oauth_application_path(application) %></span></td>
20
      <td class="description"><%= truncate application.redirect_uri.split.join(', '), length: 50 %></td>
21
      <td class="description"><%= h application.scopes %></td>
22
      <td class="buttons">
23
        <%= link_to t('doorkeeper.applications.buttons.edit'), edit_oauth_application_path(application), class: 'icon icon-edit' %>
24
        <%= link_to t('doorkeeper.applications.buttons.destroy'), oauth_application_path(application), :data => {:confirm => t('doorkeeper.applications.confirmations.destroy')}, :method => :delete, :class => 'icon icon-del' %>
25
      </td>
26
    </tr>
27
  <% end %>
28
  </tbody>
29
</table>
30
</div>
31
<% else %>
32
  <p class="nodata"><%= l(:label_no_data) %></p>
33
<% end %>
app/views/doorkeeper/applications/new.html.erb
1
<%= title [t('doorkeeper.applications.index.title'), oauth_applications_path], t('.title') %>
2

  
3
<%= labelled_form_for @application, url: doorkeeper_submit_path(@application)  do |f| %>
4
<%= render :partial => 'form', :locals => { :f => f } %>
5
<%= submit_tag l(:button_create) %>
6
<% end %>
app/views/doorkeeper/applications/show.html.erb
1
<div class="contextual">
2
<%= link_to t('doorkeeper.applications.buttons.edit'), edit_oauth_application_path(@application), :accesskey => accesskey(:edit), class: 'icon icon-edit' %>
3
<%= link_to t('doorkeeper.applications.buttons.destroy'), oauth_application_path(@application), :data => {:confirm => t('doorkeeper.applications.confirmations.destroy')}, :method => :delete, :class => 'icon icon-del' %>
4
</div>
5

  
6
<%= title [t('doorkeeper.applications.index.title'), oauth_applications_path], @application.name %>
7

  
8
<fieldset class="tabular"><legend><%= l(:label_information_plural) %></legend>
9
  <p>
10
    <label><%= t('.application_id') %>:</label>
11
    <code><%= h @application.uid %></code>
12
  </p>
13
  <p>
14
    <label><%= t('.secret') %>:</label>
15
    <code><%= h @application.secret %></code>
16
  </p>
17
  <p>
18
    <label><%= t('.scopes') %>:</label>
19
    <code><%= h @application.scopes %></code>
20
  </p>
21
</fieldset>
22
<br/>
23

  
24
<h3><%= t('.callback_urls') %></h3>
25

  
26
<div class="autoscroll">
27
<table class="list">
28
  <thead><tr>
29
    <th><%= t('.callback_url') %></th>
30
    <th></th>
31
  </tr></thead>
32
  <tbody>
33
  <% @application.redirect_uri.split.each do |uri| %>
34
    <tr class="<%= cycle("odd", "even") %>">
35
      <td class="name"><span><%= uri %></span></td>
36
      <td class="buttons">
37
        <%= link_to t('doorkeeper.applications.buttons.authorize'), oauth_authorization_path(client_id: @application.uid, redirect_uri: uri, response_type: 'code', scope: @application.scopes), class: 'icon icon-authorize', target: '_blank' %>
38
      </td>
39
    </tr>
40
  <% end %>
41
  </tbody>
42
</table>
43
</div>
app/views/doorkeeper/authorizations/error.html.erb
1
<h2><%= t('doorkeeper.authorizations.error.title') %></h2>
2

  
3
<p id="errorExplanation"><%= @pre_auth.error_response.body[:error_description] %></p>
4
<p><a href="javascript:history.back()"><%= l(:button_back) %></a></p>
5

  
6
<% html_title t('doorkeeper.authorizations.error.title') %>
app/views/doorkeeper/authorizations/new.html.erb
1
<%= title t('.title') %>
2

  
3
<div class="warning">
4
<p><strong><%=h @pre_auth.client.name %></strong></p>
5

  
6
<p><%= raw t('.prompt', client_name: "<strong class=\"text-info\">#{ @pre_auth.client.name }</strong>") %></p>
7

  
8
<% if @pre_auth.scopes.count > 0 %>
9
  <div class="oauth-permissions">
10
    <p><%= t('.able_to') %>:
11
    <ul>
12
      <% @pre_auth.scopes.each do |scope| %>
13
        <li><%= t scope, scope: [:doorkeeper, :scopes] %></li>
14
      <% end %>
15
    </ul>
16
    </p>
17
  </div>
18
<% end %>
19
</div>
20

  
21
<p>
22
  <%= form_tag oauth_authorization_path, method: :post do %>
23
    <%= hidden_field_tag :client_id, @pre_auth.client.uid %>
24
    <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
25
    <%= hidden_field_tag :state, @pre_auth.state %>
26
    <%= hidden_field_tag :response_type, @pre_auth.response_type %>
27
    <%= hidden_field_tag :scope, @pre_auth.scope %>
28
    <%= submit_tag t('doorkeeper.authorizations.buttons.authorize'), class: "btn btn-success btn-lg btn-block" %>
29
  <% end %>
30
  <%= form_tag oauth_authorization_path, method: :delete do %>
31
    <%= hidden_field_tag :client_id, @pre_auth.client.uid %>
32
    <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
33
    <%= hidden_field_tag :state, @pre_auth.state %>
34
    <%= hidden_field_tag :response_type, @pre_auth.response_type %>
35
    <%= hidden_field_tag :scope, @pre_auth.scope %>
36
    <%= submit_tag t('doorkeeper.authorizations.buttons.deny'), class: "btn btn-danger btn-lg btn-block" %>
37
  <% end %>
38
</p>
app/views/doorkeeper/authorizations/show.html.erb
1
<%= title [t('doorkeeper.authorized_applications.index.title'), oauth_authorized_applications_path]  %>
2

  
3
<fieldset class="tabular"><legend><%= l(:label_information_plural) %></legend>
4
  <p>
5
    <label><%= t('.title') %>:</label>
6
    <code><%= params[:code] %></code>
7
  </p>
8
</fieldset>
app/views/doorkeeper/authorized_applications/index.html.erb
1
<%= title [t(:label_my_account), my_account_path], t('doorkeeper.authorized_applications.index.title') %>
2

  
3
<% if @applications.any? %>
4
<div class="autoscroll">
5
<table class="list">
6
  <thead><tr>
7
    <th><%= t('doorkeeper.authorized_applications.index.application') %></th>
8
    <th><%= t('doorkeeper.authorized_applications.index.created_at') %></th>
9
    <th></th>
10
  </tr></thead>
11
  <tbody>
12
  <% @applications.each do |application| %>
13
    <tr id="application_<%= application.id %>" class="<%= cycle("odd", "even") %>">
14
      <td class="name"><span><%= application.name %></span></td>
15
      <td ><%= format_date application.created_at %></td>
16
      <td class="buttons">
17
        <%= link_to t('doorkeeper.authorized_applications.buttons.revoke'), oauth_authorized_application_path(application), :data => {:confirm => t('doorkeeper.authorized_applications.confirmations.revoke')}, :method => :delete, :class => 'icon icon-del' %>
18
      </td>
19
    </tr>
20
  <% end %>
21
  </tbody>
22
</table>
23
</div>
24
<% else %>
25
  <p class="nodata"><%= l(:label_no_data) %></p>
26
<% end %>
27

  
28
<% content_for :sidebar do %>
29
<% @user = User.current %>
30
<%= render :partial => 'my/sidebar' %>
31
<% end %>
config/application.rb
76 76
      :key => '_redmine_session',
77 77
      :path => config.relative_url_root || '/'
78 78

  
79
    # Use Redmine standard layouts and helpers for Doorkeeper OAuth2 screens
80
    config.to_prepare do
81
      Doorkeeper::ApplicationsController.layout "admin"
82
      Doorkeeper::ApplicationsController.main_menu = false
83
      Doorkeeper::AuthorizationsController.layout "base"
84
      Doorkeeper::AuthorizedApplicationsController.layout "base"
85
      Doorkeeper::AuthorizedApplicationsController.main_menu = false
86
    end
87

  
79 88
    if File.exists?(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
80 89
      instance_eval File.read(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
81 90
    end
config/initializers/doorkeeper.rb
2 2
  use_refresh_token
3 3
  reuse_access_token
4 4
  realm           Redmine::Info.app_name
5
  base_controller 'ApplicationController'
5 6
  default_scopes  :public
6 7

  
7 8
  resource_owner_authenticator do
8
    if Setting.rest_api_enabled?
9
      User.active.find_by_id(session[:user_id]) || redirect_to(signin_path(:back_url => request.original_url))
10
    else
11
      render(:text => 'Forbidden', :status => 403)
9
    if require_login
10
      if Setting.rest_api_enabled?
11
        User.current
12
      else
13
        deny_access
14
      end
12 15
    end
13 16
  end
14 17

  
15 18
  admin_authenticator do
16
    if !Setting.rest_api_enabled? || !User.active.where(admin: true).find_by_id(session[:user_id])
17
      render(:text => 'Forbidden', :status => 403)
19
    if !Setting.rest_api_enabled? || !User.current.admin?
20
      deny_access
18 21
    end
19 22
  end
20

  
21 23
end
public/stylesheets/application.css
862 862
  color: #A6750C;
863 863
}
864 864

  
865
.warning .oauth-permissions { display:inline-block;text-align:left; }
866
.warning .oauth-permissions p { margin-top:0;-webkit-margin-before:0;}
867

  
865 868
#errorExplanation ul { font-size: 0.9em;}
866 869
#errorExplanation h2, #errorExplanation p { display: none; }
867 870

  
......
1265 1268
.icon-custom-fields { background-image: url(../images/textfield.png); }
1266 1269
.icon-plugins { background-image: url(../images/plugin.png); }
1267 1270
.icon-applications { background-image: url(../images/application_view_tile.png); }
1271
.icon-authorize { background-image: url(../images/application_key.png); }
1268 1272
.icon-news { background-image: url(../images/news.png); }
1269 1273
.icon-issue-closed { background-image: url(../images/ticket_checked.png); }
1270 1274
.icon-issue-note { background-image: url(../images/ticket_note.png); }
(8-8/24)