From: Jan Provaznik <jprovazn(a)redhat.com>
User object was assigned to id. Also moved name generation into helper.
---
src/app/controllers/instance_controller.rb | 2 +-
src/app/helpers/instance_helper.rb | 10 ++++++++++
src/app/views/instance/index.haml | 4 ++--
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/app/controllers/instance_controller.rb
b/src/app/controllers/instance_controller.rb
index 7f7bc0e..6855635 100644
--- a/src/app/controllers/instance_controller.rb
+++ b/src/app/controllers/instance_controller.rb
@@ -92,7 +92,7 @@ class InstanceController < ApplicationController
@instance = Instance.new(params[:instance])
@instance.state = Instance::STATE_NEW
- @instance.owner_id = current_user
+ @instance.owner = current_user
require_privilege(Privilege::INSTANCE_MODIFY,
Pool.find((a)instance.pool_id))
diff --git a/src/app/helpers/instance_helper.rb b/src/app/helpers/instance_helper.rb
index e0b6e98..fea3cf4 100644
--- a/src/app/helpers/instance_helper.rb
+++ b/src/app/helpers/instance_helper.rb
@@ -20,4 +20,14 @@
# Likewise, all the methods added will be available for all controllers.
module InstanceHelper
+ def owner_name(inst)
+ return '' unless inst.owner
+ # if last_name is set, use full name,
+ # else use login
+ if inst.owner.last_name.blank?
+ inst.owner.login
+ else
+ "#{inst.owner.first_name} #{inst.owner.last_name}"
+ end
+ end
end
diff --git a/src/app/views/instance/index.haml b/src/app/views/instance/index.haml
index 8024a2f..83690b7 100644
--- a/src/app/views/instance/index.haml
+++ b/src/app/views/instance/index.haml
@@ -6,7 +6,7 @@
{:name => 'TEMPLATE', :sort_attr => 'templates.name'},
|
{:name => 'PUBLIC ADDRESS', :sort_attr => 'public_addresses'},
|
{:name => 'PROVIDER', :sortable => false}, |
- {:name => 'STARTED BY', :sort_attr => 'users.last_name'},
|
+ {:name => 'CREATED BY', :sort_attr => 'users.last_name'},
|
] |
- pool_columns = [ |
@@ -124,4 +124,4 @@
%td= inst.template.name
%td= inst.public_addresses
%td= inst.cloud_account ? inst.cloud_account.provider.name : ''
- %td= "#{inst.owner.first_name} #{inst.owner.last_name}" # TODO,
there is "started by" in comps pdf, but we don't save this info
+ %td= owner_name(inst)
--
1.7.2.3