]> git.openstreetmap.org Git - rails.git/blob - app/controllers/oauth_clients_controller.rb
Merge branch 'master' into cancancan
[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   before_action :require_user
7
8   def index
9     @client_applications = current_user.client_applications
10     @tokens = current_user.oauth_tokens.authorized
11   end
12
13   def new
14     @client_application = ClientApplication.new
15   end
16
17   def create
18     @client_application = current_user.client_applications.build(application_params)
19     if @client_application.save
20       flash[:notice] = t "oauth_clients.create.flash"
21       redirect_to :action => "show", :id => @client_application.id
22     else
23       render :action => "new"
24     end
25   end
26
27   def show
28     @client_application = current_user.client_applications.find(params[:id])
29   rescue ActiveRecord::RecordNotFound
30     @type = "client application"
31     render :action => "not_found", :status => :not_found
32   end
33
34   def edit
35     @client_application = current_user.client_applications.find(params[:id])
36   rescue ActiveRecord::RecordNotFound
37     @type = "client application"
38     render :action => "not_found", :status => :not_found
39   end
40
41   def update
42     @client_application = current_user.client_applications.find(params[:id])
43     if @client_application.update(application_params)
44       flash[:notice] = t "oauth_clients.update.flash"
45       redirect_to :action => "show", :id => @client_application.id
46     else
47       render :action => "edit"
48     end
49   rescue ActiveRecord::RecordNotFound
50     @type = "client application"
51     render :action => "not_found", :status => :not_found
52   end
53
54   def destroy
55     @client_application = current_user.client_applications.find(params[:id])
56     @client_application.destroy
57     flash[:notice] = t "oauth_clients.destroy.flash"
58     redirect_to :action => "index"
59   rescue ActiveRecord::RecordNotFound
60     @type = "client application"
61     render :action => "not_found", :status => :not_found
62   end
63
64   private
65
66   def application_params
67     params.require(:client_application).permit(:name, :url, :callback_url, :support_url, ClientApplication.all_permissions)
68   end
69 end