Tried to do this in a way that some of the
convenience methods I add here will be useful
in the new design as well.
---
 src/app/controllers/application_controller.rb |   10 ++++++-
 src/app/models/permissioned_object.rb         |   15 ++++++++++
 src/app/services/application_service.rb       |    7 ++++
 src/app/views/layouts/_main_nav.html.erb      |   38 ++++++++++++++----------
 src/public/stylesheets/dcloud.css             |    9 +++--
 5 files changed, 58 insertions(+), 21 deletions(-)

diff --git a/src/app/controllers/application_controller.rb 
b/src/app/controllers/application_controller.rb
index 63d908f..d6db0f6 100644
--- a/src/app/controllers/application_controller.rb
+++ b/src/app/controllers/application_controller.rb
@@ -48,7 +48,15 @@ class ApplicationController < ActionController::Base
   end
 
   def get_nav_items
-    @providers = Provider.find(:all)
+    if !current_user.nil?
+      if is_admin?(@current_user)
+        @providers = Provider.all
+        @pools = PortalPool.all
+      else
+        @providers = Provider.list_for_user(@current_user, 
Privilege::PROVIDER_VIEW)
+        @pools = PortalPool.list_for_user(@current_user, Privilege::POOL_VIEW)
+      end
+    end
   end
 
   perm_helper_string = ""
diff --git a/src/app/models/permissioned_object.rb 
b/src/app/models/permissioned_object.rb
index e4efaad..8b9a1e4 100644
--- a/src/app/models/permissioned_object.rb
+++ b/src/app/models/permissioned_object.rb
@@ -80,4 +80,19 @@ 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)
+        find(:all, :include => {:permissions => {:role => :privileges}},
+               :conditions => ["permissions.user_id=:user and
+                                privileges.name=:priv",
+                               {:user => user.id,
+                                :priv => privilege }])
+      end
+    end
+  end
+
 end
diff --git a/src/app/services/application_service.rb 
b/src/app/services/application_service.rb
index e2c45cb..ce774c6 100644
--- a/src/app/services/application_service.rb
+++ b/src/app/services/application_service.rb
@@ -55,4 +55,11 @@ module ApplicationService
                'You have insufficient privileges to perform action.')
     end
   end
+
+  def is_admin?(user)
+    p = Permission.first(:include => :role,
+                         :conditions => ["roles.name =:role and 
permissions.user_id=:user",
+                                      {:role => "Administrator", :user => 
user.id}])
+    p.nil? ? false : true
+  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

Reply via email to