]> git.openstreetmap.org Git - rails.git/blob - app/controllers/oauth_clients_controller.rb
Set OpenID URL input value in html instead of javascript
[rails.git] / app / controllers / oauth_clients_controller.rb
1 class OauthClientsController < ApplicationController
2   layout "site"
3
4   before_action :authorize_web
5   before_action :set_locale
6
7   authorize_resource :class => ClientApplication
8
9   def index
10     @client_applications = current_user.client_applications
11     @tokens = current_user.oauth_tokens.authorized
12   end
13
14   def show
15     @client_application = current_user.client_applications.find(params[:id])
16   rescue ActiveRecord::RecordNotFound
17     @type = "client application"
18     render :action => "not_found", :status => :not_found
19   end
20
21   def new
22     if Settings.oauth_10_registration
23       @client_application = ClientApplication.new
24     else
25       flash[:error] = t ".disabled"
26       redirect_to :action => "index"
27     end
28   end
29
30   def edit
31     @client_application = current_user.client_applications.find(params[:id])
32   rescue ActiveRecord::RecordNotFound
33     @type = "client application"
34     render :action => "not_found", :status => :not_found
35   end
36
37   def create
38     @client_application = current_user.client_applications.build(application_params)
39     if @client_application.save
40       flash[:notice] = t ".flash"
41       redirect_to :action => "show", :id => @client_application.id
42     else
43       render :action => "new"
44     end
45   end
46
47   def update
48     @client_application = current_user.client_applications.find(params[:id])
49     if @client_application.update(application_params)
50       flash[:notice] = t ".flash"
51       redirect_to :action => "show", :id => @client_application.id
52     else
53       render :action => "edit"
54     end
55   rescue ActiveRecord::RecordNotFound
56     @type = "client application"
57     render :action => "not_found", :status => :not_found
58   end
59
60   def destroy
61     @client_application = current_user.client_applications.find(params[:id])
62     @client_application.destroy
63     flash[:notice] = t ".flash"
64     redirect_to :action => "index"
65   rescue ActiveRecord::RecordNotFound
66     @type = "client application"
67     render :action => "not_found", :status => :not_found
68   end
69
70   private
71
72   def application_params
73     params.require(:client_application).permit(:name, :url, :callback_url, :support_url, ClientApplication.all_permissions)
74   end
75 end