Read about our upcoming Code of Conduct on this issue

This instance was upgraded to Heptapod 0.28.0 today

applications_controller.rb 1.69 KB
Newer Older
Valery Sizov's avatar
Valery Sizov committed
1
class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
2
  include Gitlab::GonHelper
3
  include PageLayoutHelper
4
  include OauthApplications
5

6
  before_action :verify_user_oauth_applications_enabled
7
  before_action :authenticate_user!
8
  before_action :add_gon_variables
9
  before_action :load_scopes, only: [:index, :create, :edit]
10
11

  layout 'profile'
Valery Sizov's avatar
Valery Sizov committed
12
13

  def index
14
    set_index_vars
15
16
  end

Valery Sizov's avatar
Valery Sizov committed
17
  def create
James Lopez's avatar
James Lopez committed
18
    @application = Applications::CreateService.new(current_user, create_application_params).execute(request)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
19

20
21
    if @application.persisted?
      flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
James Lopez's avatar
James Lopez committed
22
23

      redirect_to oauth_application_url(@application)
Valery Sizov's avatar
Valery Sizov committed
24
    else
25
26
      set_index_vars
      render :index
Valery Sizov's avatar
Valery Sizov committed
27
28
29
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
30
31
  private

32
  def verify_user_oauth_applications_enabled
33
    return if Gitlab::CurrentSettings.user_oauth_applications?
34

35
    redirect_to profile_path
36
37
  end

38
39
40
41
42
43
44
45
46
47
48
  def set_index_vars
    @applications = current_user.oauth_applications
    @authorized_tokens = current_user.oauth_authorized_tokens
    @authorized_anonymous_tokens = @authorized_tokens.reject(&:application)
    @authorized_apps = @authorized_tokens.map(&:application).uniq.reject(&:nil?)

    # Don't overwrite a value possibly set by `create`
    @application ||= Doorkeeper::Application.new
  end

  # Override Doorkeeper to scope to the current user
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
49
50
51
52
53
54
55
  def set_application
    @application = current_user.oauth_applications.find(params[:id])
  end

  rescue_from ActiveRecord::RecordNotFound do |exception|
    render "errors/not_found", layout: "errors", status: 404
  end
56
57
58
59
60
61

  def create_application_params
    application_params.tap do |params|
      params[:owner] = current_user
    end
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
62
end