Tried to do this in a way that the
convenience method I add here will be useful
in the new design as well.
---
src/app/controllers/application_controller.rb | 5 ++-
src/app/models/permissioned_object.rb | 19 ++++++++++++
src/app/views/layouts/_main_nav.html.erb | 38 ++++++++++++++----------
src/public/stylesheets/dcloud.css | 9 +++--
4 files changed, 50 insertions(+), 21 deletions(-)
diff --git a/src/app/controllers/application_controller.rb
b/src/app/controllers/application_controller.rb
index 63d908f..214eb2b 100644
--- a/src/app/controllers/application_controller.rb
+++ b/src/app/controllers/application_controller.rb
@@ -48,7 +48,10 @@ class ApplicationController < ActionController::Base
end
def get_nav_items
- @providers = Provider.find(:all)
+ if !current_user.nil?
+ @providers = Provider.list_for_user(@current_user,
Privilege::PROVIDER_VIEW)
+ @pools = PortalPool.list_for_user(@current_user, Privilege::POOL_VIEW)
+ end
end
perm_helper_string = ""
diff --git a/src/app/models/permissioned_object.rb
b/src/app/models/permissioned_object.rb
index e4efaad..a253410 100644
--- a/src/app/models/permissioned_object.rb
+++ b/src/app/models/permissioned_object.rb
@@ -80,4 +80,23 @@ module PermissionedObject
{ :user => user.id,
:priv => privilege }])
end
+
+ # Any methods here will be able to use the context of the
+ # ActiveRecord model the module is included in.
+ def self.included(base)
+ base.class_eval do
+ def self.list_for_user(user, privilege)
+ if BasePortalObject.general_permission_scope.has_privilege(user,
privilege)
+ all
+ else
+ find(:all, :include => {:permissions => {:role => :privileges}},
+ :conditions => ["permissions.user_id=:user and
+ privileges.name=:priv",
+ {:user => user.id,
+ :priv => privilege }])
+ end
+ end
+ end
+ end
+
end
diff --git a/src/app/views/layouts/_main_nav.html.erb
b/src/app/views/layouts/_main_nav.html.erb
index 18ee43a..1894cb4 100644
--- a/src/app/views/layouts/_main_nav.html.erb
+++ b/src/app/views/layouts/_main_nav.html.erb
@@ -1,8 +1,13 @@
+<%=link_to "Add a provider", {:controller => "provider", :action => "new"},
:class => "actionlink" %>
+
+<%=link_to "Add a pool", {:controller => "portal_pool", :action => "new"},
:class => "actionlink" %>
+<h3>Providers</h3>
<ul id="providers">
- <% curId = params[:id].to_i %>
+ <% cur_id = params[:id].to_i %>
+ <% if [email protected]? %>
<% @providers.each { |provider| %>
<%#Note that this is a temporary way to selected proper list item for
demo, and is not expected to stay this way%>
- <% if controller.controller_name == "provider" && provider.id == curId
+ <% if controller.controller_name == "provider" && provider.id == cur_id
selected_provider = "selected"
else
selected_provider = ""
@@ -10,20 +15,21 @@
<li><%= link_to provider.name,
{:controller => "provider", :action => "show", :id => provider},
:class => "providername #{selected_provider}"%>
- <% provider.portal_pools.each { |pool| %>
- <ul id="portal_pool-<%=provider.id%>">
- <% if controller.controller_name == "portal_pool" && pool.id == curId
- selected_pool = "selected"
- else selected_pool = ""
- end %>
- <li><%= link_to pool.name,
- {:controller => "portal_pool", :action => "show", :id => pool},
- :class => "poolname #{selected_pool}" %></li>
- </ul>
- <% } %>
</li>
<% } %>
+ <% end %>
</ul>
-<%=link_to "Add a provider", {:controller => "provider", :action => "new"},
:class => "actionlink" %>
-
-<%=link_to "Add a pool", {:controller => "portal_pool", :action => "new"},
:class => "actionlink" %>
+<h3>Pools</h3>
+<ul id="portal_pools">
+ <% if [email protected]? %>
+ <% @pools.each { |pool| %>
+ <% if controller.controller_name == "portal_pool" && pool.id == cur_id
+ selected_pool = "selected"
+ else selected_pool = ""
+ end %>
+ <li><%= link_to pool.name,
+ {:controller => "portal_pool", :action => "show", :id => pool},
+ :class => "poolname #{selected_pool}" %></li>
+ <% } %>
+ <% end %>
+</ul>
\ No newline at end of file
diff --git a/src/public/stylesheets/dcloud.css
b/src/public/stylesheets/dcloud.css
index 96cb95c..5b68ab6 100644
--- a/src/public/stylesheets/dcloud.css
+++ b/src/public/stylesheets/dcloud.css
@@ -210,24 +210,25 @@ ul#providers li a:hover {
background: #efefef;
}
-ul#providers li ul {
+ul#portal_pools {
list-style-type: none;
line-height: 36px;
margin: 0;
padding: 0 0 0 10px;
}
-ul#providers li ul li {
+ul#portal_pools li {
border-bottom: none;
}
-ul#providers li ul li a {
+ul#portal_pools li a {
+ display: block;
line-height: 36px;
padding-left: 32px;
border-bottom: none;
}
-ul#providers li ul li a:hover {
+ul#portal_pools li a:hover {
background: #efefef url(../images/icon_vmpool.png) no-repeat 2px 50%;
}
--
1.6.6.1
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel