applications_controller.rb 1.6 KB
Newer Older
V
Valery Sizov 已提交
1
class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
2
  include Gitlab::CurrentSettings
3
  include Gitlab::GonHelper
4
  include PageLayoutHelper
5
  include OauthApplications
6

7
  before_action :verify_user_oauth_applications_enabled
8
  before_action :authenticate_user!
9
  before_action :add_gon_variables
10 11

  layout 'profile'
V
Valery Sizov 已提交
12 13

  def index
14
    set_index_vars
15 16
  end

17 18 19 20
  def edit
    @scopes = Doorkeeper.configuration.scopes
  end

V
Valery Sizov 已提交
21 22
  def create
    @application = Doorkeeper::Application.new(application_params)
D
Dmitriy Zaporozhets 已提交
23

V
Valery Sizov 已提交
24
    @application.owner = current_user
25

V
Valery Sizov 已提交
26 27 28 29
    if @application.save
      flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
      redirect_to oauth_application_url(@application)
    else
30 31
      set_index_vars
      render :index
V
Valery Sizov 已提交
32 33 34
    end
  end

D
Dmitriy Zaporozhets 已提交
35 36
  private

37 38 39
  def verify_user_oauth_applications_enabled
    return if current_application_settings.user_oauth_applications?

40
    redirect_to profile_path
41 42
  end

43 44 45 46 47
  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?)
48
    @scopes = Doorkeeper.configuration.scopes
49 50 51 52 53 54

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

  # Override Doorkeeper to scope to the current user
D
Dmitriy Zaporozhets 已提交
55 56 57 58 59 60 61
  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
D
Dmitriy Zaporozhets 已提交
62
end