]> cat aescling's git repositories - mastodon.git/blob - app/controllers/settings/applications_controller.rb
Update AUTHORS.md (#9141)
[mastodon.git] / app / controllers / settings / applications_controller.rb
1 # frozen_string_literal: true
2
3 class Settings::ApplicationsController < ApplicationController
4 layout 'admin'
5
6 before_action :authenticate_user!
7 before_action :set_application, only: [:show, :update, :destroy, :regenerate]
8 before_action :prepare_scopes, only: [:create, :update]
9 before_action :set_body_classes
10
11 def index
12 @applications = current_user.applications.order(id: :desc).page(params[:page])
13 end
14
15 def new
16 @application = Doorkeeper::Application.new(
17 redirect_uri: Doorkeeper.configuration.native_redirect_uri,
18 scopes: 'read write follow'
19 )
20 end
21
22 def show; end
23
24 def create
25 @application = current_user.applications.build(application_params)
26
27 if @application.save
28 redirect_to settings_applications_path, notice: I18n.t('applications.created')
29 else
30 render :new
31 end
32 end
33
34 def update
35 if @application.update(application_params)
36 redirect_to settings_applications_path, notice: I18n.t('generic.changes_saved_msg')
37 else
38 render :show
39 end
40 end
41
42 def destroy
43 @application.destroy
44 redirect_to settings_applications_path, notice: I18n.t('applications.destroyed')
45 end
46
47 def regenerate
48 @access_token = current_user.token_for_app(@application)
49 @access_token.destroy
50
51 redirect_to settings_application_path(@application), notice: I18n.t('applications.token_regenerated')
52 end
53
54 private
55
56 def set_application
57 @application = current_user.applications.find(params[:id])
58 end
59
60 def application_params
61 params.require(:doorkeeper_application).permit(
62 :name,
63 :redirect_uri,
64 :scopes,
65 :website
66 )
67 end
68
69 def prepare_scopes
70 scopes = params.fetch(:doorkeeper_application, {}).fetch(:scopes, nil)
71 params[:doorkeeper_application][:scopes] = scopes.join(' ') if scopes.is_a? Array
72 end
73
74 def set_body_classes
75 @body_classes = 'admin'
76 end
77 end
This page took 0.086259 seconds and 4 git commands to generate.