<commit_before># encoding: utf-8
#--
#   Copyright (C) 2012-2013 Gitorious AS
#   Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
#   Copyright (C) 2009 <NAME> <<EMAIL>>
#   Copyright (C) 2008 <NAME> <<EMAIL>>
#   Copyright (C) 2007 <NAME> <<EMAIL>>
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Affero General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#++

class KeysController < ApplicationController
  include Gitorious::Messaging::Publisher

  before_filter :login_required
  before_filter :find_user
  before_filter :require_current_user

  renders_in_global_context

  def index
    @ssh_keys = current_user.ssh_keys
    @root = Breadcrumb::Keys.new(current_user)
    respond_to do |format|
      format.html
      format.xml { render :xml => @ssh_keys }
    end
  end

  def new
    if pjax_request?
      render :partial => 'keys/form', :ssh_key => ssh_key
    else
      render 'users/edit', :locals => {
        :user => current_user, :active_tab => 'ssh-keys'
      }, :layout => 'ui3'
    end
  end

  def create
    outcome = CreateSshKey.new(self, current_user).execute(params[:ssh_key])

    respond_to do |format|
      outcome.success do |result|
        flash[:notice] = I18n.t("keys_controller.create_notice")

        format.html do
          head :created
        end

        format.xml do
          key_path = user_key_path(current_user, result)
          render(:xml => result, :status => :created, :location => key_path)
        end
      end

      outcome.failure do |key|
        format.html do
          render :partial => "form", :locals => { :ssh_key => key }, :status => :unprocessable_entity
        end

        format.xml do
          render(:xml => key.errors.full_messages, :status => :unprocessable_entity)
        end
      end
    end
  end

  def show
    @ssh_key = current_user.ssh_keys.find(params[:id])

    respond_to do |format|
      format.html
      format.xml { render :xml => @ssh_key }
    end
  end

  def destroy
    outcome = DestroySshKey.new(self, current_user).execute(params)

    outcome.success do
      flash[:notice] = I18n.t("keys_controller.destroy_notice")
      redirect_to user_keys_index_path and return
    end

    render(:text => "Bad request", :status => 400)
  end

  protected

  def find_user
    @user = User.find_by_login!(params[:user_id])
  end

  def user_keys_index_path
    edit_user_path(current_user) + '#ssh-keys'
  end
end
<commit_msg>Fix styles for ssh key form<commit_after># encoding: utf-8
#--
#   Copyright (C) 2012-2013 Gitorious AS
#   Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
#   Copyright (C) 2009 <NAME> <<EMAIL>>
#   Copyright (C) 2008 <NAME> <<EMAIL>>
#   Copyright (C) 2007 <NAME> <<EMAIL>>
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Affero General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Affero General Public License for more details.
#
#   You should have received a copy of the GNU Affero General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#++

class KeysController < ApplicationController
  include Gitorious::Messaging::Publisher

  before_filter :login_required
  before_filter :find_user
  before_filter :require_current_user

  renders_in_global_context

  def index
    @ssh_keys = current_user.ssh_keys
    @root = Breadcrumb::Keys.new(current_user)
    respond_to do |format|
      format.html
      format.xml { render :xml => @ssh_keys }
    end
  end

  def new
    if pjax_request?
      render :partial => 'keys/form', :ssh_key => ssh_key
    else
      render 'users/edit', :locals => {
        :user => current_user, :active_tab => 'ssh-keys'
      }, :layout => 'ui3'
    end
  end

  def create
    outcome = CreateSshKey.new(self, current_user).execute(params[:ssh_key])

    respond_to do |format|
      outcome.success do |result|
        flash[:notice] = I18n.t("keys_controller.create_notice")

        format.html do
          head :created
        end

        format.xml do
          key_path = user_key_path(current_user, result)
          render(:xml => result, :status => :created, :location => key_path)
        end
      end

      outcome.failure do |key|
        puts key.errors.inspect

        format.html do
          render :partial => "form", :locals => { :ssh_key => key }, :status => :unprocessable_entity
        end

        format.xml do
          render(:xml => key.errors.full_messages, :status => :unprocessable_entity)
        end
      end
    end
  end

  def show
    @ssh_key = current_user.ssh_keys.find(params[:id])

    respond_to do |format|
      format.html
      format.xml { render :xml => @ssh_key }
    end
  end

  def destroy
    outcome = DestroySshKey.new(self, current_user).execute(params)

    outcome.success do
      flash[:notice] = I18n.t("keys_controller.destroy_notice")
      redirect_to user_keys_index_path and return
    end

    render(:text => "Bad request", :status => 400)
  end

  protected

  def find_user
    @user = User.find_by_login!(params[:user_id])
  end

  def user_keys_index_path
    edit_user_path(current_user) + '#ssh-keys'
  end
end

{'fraction_non_alphanumeric': 0.09843621399176955, 'fraction_numerical': 0.011193415637860082, 'mean_word_length': 2.927601809954751, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 16}, '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': '3811029', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1847, 'n_words': 573}