<commit_before># frozen_string_literal: true

module API
  # External applications API
  class Applications < Grape::API
    before { authenticated_as_admin! }

    resource :applications do
      desc 'Create a new application' do
        detail 'This feature was introduced in GitLab 10.5'
        success Entities::ApplicationWithSecret
      end
      params do
        requires :name, type: String, desc: 'Application name'
        requires :redirect_uri, type: String, desc: 'Application redirect URI'
        requires :scopes, type: String, desc: 'Application scopes'
      end
      post do
        application = Doorkeeper::Application.new(declared_params)

        if application.save
          present application, with: Entities::ApplicationWithSecret
        else
          render_validation_error! application
        end
      end

      desc 'Get applications' do
        success Entities::ApplicationWithSecret
      end
      get do
        applications = Doorkeeper::Application.where("owner_id IS NULL")
        present applications, with: Entities::Application
      end

      # rubocop: disable CodeReuse/ActiveRecord
      desc 'Delete an application'
      delete ':id' do
        Doorkeeper::Application.find_by(id: params[:id]).destroy

        status 204<commit_msg>disable CodeReuse/ActiveRecord<commit_after># frozen_string_literal: true

module API
  # External applications API
  class Applications < Grape::API
    before { authenticated_as_admin! }

    resource :applications do
      desc 'Create a new application' do
        detail 'This feature was introduced in GitLab 10.5'
        success Entities::ApplicationWithSecret
      end
      params do
        requires :name, type: String, desc: 'Application name'
        requires :redirect_uri, type: String, desc: 'Application redirect URI'
        requires :scopes, type: String, desc: 'Application scopes'
      end
      post do
        application = Doorkeeper::Application.new(declared_params)

        if application.save
          present application, with: Entities::ApplicationWithSecret
        else
          render_validation_error! application
        end
      end

      # rubocop: disable CodeReuse/ActiveRecord
      desc 'Get applications' do
        success Entities::ApplicationWithSecret
      end
      get do
        applications = Doorkeeper::Application.where("owner_id IS NULL")
        present applications, with: Entities::Application
      end
      # rubocop: enable CodeReuse/ActiveRecord

      # rubocop: disable CodeReuse/ActiveRecord
      desc 'Delete an application'
      delete ':id' do
        Doorkeeper::Application.find_by(id: params[:id]).destroy

        status 204
{'fraction_non_alphanumeric': 0.06703703703703703, 'fraction_numerical': 0.0044444444444444444, 'mean_word_length': 2.767085076708508, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7451302', 'n_tokens_mistral': 695, 'n_tokens_neox': 666, 'n_words': 216}