---
 src/app/controllers/portal_pool_controller.rb      |   27 ++++++++++++++++--
 src/app/views/portal_pool/new_user.html.erb        |   29 ++++++++++++++++++++
 src/app/views/portal_pool/show.html.erb            |    1 +
 .../controllers/portal_pool_controller_spec.rb     |   20 +++++++++++++
 4 files changed, 74 insertions(+), 3 deletions(-)
 create mode 100644 src/app/views/portal_pool/new_user.html.erb

diff --git a/src/app/controllers/portal_pool_controller.rb 
b/src/app/controllers/portal_pool_controller.rb
index 69208fa..a897bb4 100644
--- a/src/app/controllers/portal_pool_controller.rb
+++ b/src/app/controllers/portal_pool_controller.rb
@@ -64,9 +64,6 @@ class PortalPoolController < ApplicationController
   def create
     require_privilege(Privilege::POOL_MODIFY)
 
-    #FIXME: owner is set to current user for self-service account creation,
-    # but in the more general case we need a way for the admin to pick
-    # a user
     params[:portal_pool][:owner_id] = @current_user.id
 
     #FIXME: This should probably be in a transaction
@@ -81,6 +78,30 @@ class PortalPoolController < ApplicationController
     redirect_to :action => 'show', :id => @portal_pool.id
   end
 
+  def new_user
+    require_privilege(Privilege::POOL_MODIFY)
+    require_privilege(Privilege::USER_MODIFY)
+
+    @users = User.find(:all)
+    @roles = Role.find(:all, :conditions => [ 'scope = ?', 'PortalPool' ])
+    @pool  = PortalPool.find(params[:id])
+  end
+
+  def create_user
+    require_privilege(Privilege::POOL_MODIFY)
+    require_privilege(Privilege::USER_MODIFY)
+
+    pool  = PortalPool.find(params[:pool_id])
+    role  = Role.find(params[:role_id])
+    user  = User.find(params[:user_id])
+    @permission = Permission.create! :user => user,
+                                     :role => role,
+                                     :permission_object => pool
+
+    flash[:notice] = "User added to pool"
+    redirect_to :action => 'show', :id => pool.id
+  end
+
   def delete
   end
 
diff --git a/src/app/views/portal_pool/new_user.html.erb 
b/src/app/views/portal_pool/new_user.html.erb
new file mode 100644
index 0000000..1e18cb7
--- /dev/null
+++ b/src/app/views/portal_pool/new_user.html.erb
@@ -0,0 +1,29 @@
+<div class="dcloud_form">
+  <%= error_messages_for 'permission' %>
+
+  <h2>Add user to pool</h2><br />
+
+  <% form_tag :action => 'create_user' do -%>
+    <fieldset>
+    <ul>
+      <li><label>User</label>
+      <select id="user_id" name="user_id">
+      <% @users.each { |user| %>
+        <option value="<%= user.id %>"><%= user.login %></option>
+      <% } %>
+      </select>
+      </li>
+      <li><label>Role</label>
+      <select id="role_id" name="role_id">
+      <% @roles.each { |role| %>
+        <option value="<%= role.id %>"><%= role.name %></option>
+      <% } %>
+      </select>
+      </li>
+      <input type="hidden" name="pool_id" value="<%= @pool.id %>" />
+    <ul>
+    </fieldset>
+
+    <%= submit_tag "Save", :class => "submit" %>
+  <% end %>
+</div>
diff --git a/src/app/views/portal_pool/show.html.erb 
b/src/app/views/portal_pool/show.html.erb
index 128d74c..80b8636 100644
--- a/src/app/views/portal_pool/show.html.erb
+++ b/src/app/views/portal_pool/show.html.erb
@@ -40,3 +40,4 @@
 <%= link_to "Hardware Profiles",  {:action => "hardware_profiles", :id => 
@pool.id}, :class=>"actionlink"%>
 <%=link_to "View Images", {:controller => "portal_pool", :action => "images", 
:portal_pool => @pool}, :class => "actionlink" %>
 <%= link_to "Realms",  {:action => "realms", :id => @pool.id}, 
:class=>"actionlink"%>
+<%= link_to "Add user",  {:action => "new_user", :id => @pool.id}, 
:class=>"actionlink"%>
diff --git a/src/spec/controllers/portal_pool_controller_spec.rb 
b/src/spec/controllers/portal_pool_controller_spec.rb
index 2ea6b4d..7d8e920 100644
--- a/src/spec/controllers/portal_pool_controller_spec.rb
+++ b/src/spec/controllers/portal_pool_controller_spec.rb
@@ -58,4 +58,24 @@ describe PortalPoolController do
      response.should render_template("realms")
   end
 
+  it "should allow an admin to add a user to a pool" do
+     pool = Factory :tpool
+     UserSession.create(@admin)
+     get :new_user, :id => pool.id
+     response.should be_success
+     response.should render_template("new_user")
+
+     tuser = Factory :tuser
+     role  = Role.find(:first, :conditions => [ 'name = ?', 'Instance 
Controller'])
+     lambda {
+       post :create_user, :id => pool.id, :user_id => tuser.id, :role_id => 
role.id
+     }.should change(Permission, :count).by(1)
+     Permission.find(:first, 
+                     :conditions => [ 'user_id                = ? AND ' +  
+                                      'role_id                = ? AND ' +
+                                      'permission_object_id   = ? AND ' +
+                                      'permission_object_type = ?', 
+                                      tuser.id, role.id, pool.id, 'PortalPool' 
]).should_not be_nil
+  end
+
 end
-- 
1.6.2.5

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to