diff options
author | Valery Sizov <valery@gitlab.com> | 2015-01-18 02:37:27 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-18 09:23:26 +0300 |
commit | 20d10b63919e876aea3288e374366994a73f17b6 (patch) | |
tree | 42497190df6f39c30d8fdea3ade83a7df86ab391 /app | |
parent | ea4b0d75ddd316082daa9bb6e1c8e3ecc714e731 (diff) |
Application admin scaffold
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin/applications_controller.rb | 52 | ||||
-rw-r--r-- | app/controllers/oauth/applications_controller.rb | 6 | ||||
-rw-r--r-- | app/views/admin/applications/_delete_form.html.haml | 4 | ||||
-rw-r--r-- | app/views/admin/applications/_form.html.haml | 24 | ||||
-rw-r--r-- | app/views/admin/applications/edit.html.haml | 3 | ||||
-rw-r--r-- | app/views/admin/applications/index.html.haml | 16 | ||||
-rw-r--r-- | app/views/admin/applications/new.html.haml | 3 | ||||
-rw-r--r-- | app/views/admin/applications/show.html.haml | 26 | ||||
-rw-r--r-- | app/views/layouts/nav/_admin.html.haml | 6 |
9 files changed, 136 insertions, 4 deletions
diff --git a/app/controllers/admin/applications_controller.rb b/app/controllers/admin/applications_controller.rb new file mode 100644 index 00000000000..cba19184dba --- /dev/null +++ b/app/controllers/admin/applications_controller.rb @@ -0,0 +1,52 @@ +class Admin::ApplicationsController < Admin::ApplicationController + before_action :set_application, only: [:show, :edit, :update, :destroy] + + def index + @applications = Doorkeeper::Application.where("owner_id IS NULL") + end + + def show + end + + def new + @application = Doorkeeper::Application.new + end + + def edit + end + + def create + @application = Doorkeeper::Application.new(application_params) + + if @application.save + flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create]) + redirect_to admin_application_url(@application) + else + render :new + end + end + + def update + if @application.update(application_params) + redirect_to admin_application_path(@application), notice: 'Application was successfully updated.' + else + render :edit + end + end + + def destroy + @application.destroy + redirect_to admin_applications_url, notice: 'Application was successfully destroyed.' + end + + private + + def set_application + @application = Doorkeeper::Application.where("owner_id IS NULL").find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def application_params + params[:doorkeeper_application].permit(:name, :redirect_uri) + end +end diff --git a/app/controllers/oauth/applications_controller.rb b/app/controllers/oauth/applications_controller.rb index 3407490e498..efa291d9397 100644 --- a/app/controllers/oauth/applications_controller.rb +++ b/app/controllers/oauth/applications_controller.rb @@ -9,10 +9,8 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController def create @application = Doorkeeper::Application.new(application_params) - if Doorkeeper.configuration.confirm_application_owner? - @application.owner = current_user - end - + @application.owner = current_user + if @application.save flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create]) redirect_to oauth_application_url(@application) diff --git a/app/views/admin/applications/_delete_form.html.haml b/app/views/admin/applications/_delete_form.html.haml new file mode 100644 index 00000000000..371ac55209f --- /dev/null +++ b/app/views/admin/applications/_delete_form.html.haml @@ -0,0 +1,4 @@ +- submit_btn_css ||= 'btn btn-link btn-remove btn-small' += form_tag admin_application_path(application) do + %input{:name => "_method", :type => "hidden", :value => "delete"}/ + = submit_tag 'Destroy', onclick: "return confirm('Are you sure?')", class: submit_btn_css
\ No newline at end of file diff --git a/app/views/admin/applications/_form.html.haml b/app/views/admin/applications/_form.html.haml new file mode 100644 index 00000000000..b77d188a38d --- /dev/null +++ b/app/views/admin/applications/_form.html.haml @@ -0,0 +1,24 @@ += form_for [:admin, @application], url: @url, html: {class: 'form-horizontal', role: 'form'} do |f| + - if application.errors.any? + .alert.alert-danger{"data-alert" => ""} + %p Whoops! Check your form for possible errors + = content_tag :div, class: "form-group#{' has-error' if application.errors[:name].present?}" do + = f.label :name, class: 'col-sm-2 control-label' + .col-sm-10 + = f.text_field :name, class: 'form-control' + = doorkeeper_errors_for application, :name + = content_tag :div, class: "form-group#{' has-error' if application.errors[:redirect_uri].present?}" do + = f.label :redirect_uri, class: 'col-sm-2 control-label' + .col-sm-10 + = f.text_area :redirect_uri, class: 'form-control' + = doorkeeper_errors_for application, :redirect_uri + %span.help-block + Use one line per URI + - if Doorkeeper.configuration.native_redirect_uri + %span.help-block + Use + %code= Doorkeeper.configuration.native_redirect_uri + for local tests + .form-actions + = f.submit 'Submit', class: "btn btn-primary wide" + = link_to "Cancel", admin_applications_path, class: "btn btn-default" diff --git a/app/views/admin/applications/edit.html.haml b/app/views/admin/applications/edit.html.haml new file mode 100644 index 00000000000..e408ae2f29d --- /dev/null +++ b/app/views/admin/applications/edit.html.haml @@ -0,0 +1,3 @@ +%h3.page-title Edit application +- @url = admin_application_path(@application) += render 'form', application: @application
\ No newline at end of file diff --git a/app/views/admin/applications/index.html.haml b/app/views/admin/applications/index.html.haml new file mode 100644 index 00000000000..b0af75573b0 --- /dev/null +++ b/app/views/admin/applications/index.html.haml @@ -0,0 +1,16 @@ +%h3.page-title Your applications +%p= link_to 'New Application', new_admin_application_path, class: 'btn btn-success' +%table.table.table-striped + %thead + %tr + %th Name + %th Callback URL + %th + %th + %tbody + - @applications.each do |application| + %tr{:id => "application_#{application.id}"} + %td= link_to application.name, admin_application_path(application) + %td= application.redirect_uri + %td= link_to 'Edit', edit_admin_application_path(application), class: 'btn btn-link' + %td= render 'delete_form', application: application
\ No newline at end of file diff --git a/app/views/admin/applications/new.html.haml b/app/views/admin/applications/new.html.haml new file mode 100644 index 00000000000..7c62425f19c --- /dev/null +++ b/app/views/admin/applications/new.html.haml @@ -0,0 +1,3 @@ +%h3.page-title New application +- @url = admin_applications_path += render 'form', application: @application
\ No newline at end of file diff --git a/app/views/admin/applications/show.html.haml b/app/views/admin/applications/show.html.haml new file mode 100644 index 00000000000..2abe390ce13 --- /dev/null +++ b/app/views/admin/applications/show.html.haml @@ -0,0 +1,26 @@ +%h3.page-title + Application: #{@application.name} + + +%table.table + %tr + %td + Application Id + %td + %code#application_id= @application.uid + %tr + %td + Secret: + %td + %code#secret= @application.secret + + %tr + %td + Callback url + %td + - @application.redirect_uri.split.each do |uri| + %div + %span.monospace= uri +.form-actions + = link_to 'Edit', edit_admin_application_path(@application), class: 'btn btn-primary wide pull-left' + = render 'delete_form', application: @application, submit_btn_css: 'btn btn-danger prepend-left-10' diff --git a/app/views/layouts/nav/_admin.html.haml b/app/views/layouts/nav/_admin.html.haml index fdc517617e3..d48dfcd4e94 100644 --- a/app/views/layouts/nav/_admin.html.haml +++ b/app/views/layouts/nav/_admin.html.haml @@ -45,3 +45,9 @@ %i.fa.fa-cogs %span Settings + + = nav_link(controller: :applications) do + = link_to admin_applications_path do + %i.fa.fa-unlock-alt + %span + Application |