Skip to content

Instantly share code, notes, and snippets.

class ApplicationController < ActionController::Base
protect_from_forgery
before_filter proc { |controller| (controller.action_has_layout = false) if controller.request.xhr? }
before_filter :ensure_current_user
before_filter :km_init
analytical :modules=>[:kiss_metrics]
# store some additional info in the papertrail changelog
def info_for_paper_trail
{ :ip => request.remote_ip, :user_agent => request.user_agent }
def ensure_admin
redirect_to '/wait_for_approval' and return unless current_user.approved?
redirect_to '/' unless current_user.admin?
end
def to_json
attributes = [
:name,
     :description,
     :website,
     :organization,
     :support_url]
json = {}
attributes.each { |attr| json[attr] = self.send(attr.to_s)}
json.to_json
def create
@client_application = current_user.client_applications.build(params[:client_application])
if @client_application.save
flash[:notice] = "Registered the information successfully"
redirect_to :action => "show", :id => @client_application.id
else
render :action => "new"
end
end
Feature: Client Applications
In order to find new apps a user can browse and authorize them
@javascript @wip
Scenario: User browses the app catalog and installs a new app
Given Carol is an approved, registered user
And Carol logs in
And TestApp is a public registered app
And Carol has not yet authorized the TestApp app
When Carol goes to the apps list page
Then she sees the TestApp listing
Scenario: User browses the app catalog and uses an app she has already installed
Given Carol is an approved, registered user
And Carol logs in
And TestApp is a public registered app
And Carol has already authorized the TestApp app
When Carol goes to the apps list page
Then she sees the TestApp listing
When Carol clicks on the TestApp listing link to "Use" the app
Then She is redirected back to the TestApp link page
def clientapp_register
begin
Timeout::timeout(7) do
resp = RestClient.get('http://' + Identity::Config.settings[:authorization_server] + '/consumer/clientapp/register', :params => params[:clientapp])
ClientApplication.create_from_key_manager_xml(resp, params[:clientapp])
success resp
end
rescue => e
Rails.logger.debug e.message
Rails.logger.debug e.http_body if e.respond_to?(:http_body)
def set_hostname
App.class_eval("@@hostname = '#{request.protocol}#{["test", "development"].include?(Rails.env) ? request.host_with_port : request.host}'")
end
def keymanager_call(method, additional_params = {})
params = {
'clientapp[client_app_name]' => self.name,
'clientapp[type]' => self.app_type,
'clientapp[consumerid]' => self.consumer_id,
'clientapp[att_guid]' => self.user.att_uid,
'clientapp[description]' => self.description,
'clientapp[api_group_name]' => ENV['KEYMANAGER_API_GROUP'],
'clientapp[voice_app]' => self.voice_app,
'clientapp[voice_app_type]' => self.voice_app_type,
protected
def keymanager_call(method, additional_params = {})
params = {
'clientapp[client_app_name]' => self.name,
'clientapp[type]' => self.app_type,
'clientapp[consumerid]' => self.consumer_id,
'clientapp[att_guid]' => self.user.att_uid,
'clientapp[description]' => self.description,
'clientapp[api_group_name]' => ENV['KEYMANAGER_API_GROUP'],
'clientapp[voice_app]' => self.voice_app,