--- src/app/controllers/portal_pool_controller.rb | 6 ++++ src/app/controllers/provider_controller.rb | 6 ++++ src/app/controllers/realms_controller.rb | 39 +++++++++++++++++++++++++ src/app/models/portal_pool.rb | 4 ++ src/app/views/portal_pool/realms.html.erb | 1 + src/app/views/provider/realms.html.erb | 1 + src/app/views/realms/_list.html.erb | 20 +++++++++++++ src/app/views/realms/index.html.erb | 1 + 8 files changed, 78 insertions(+), 0 deletions(-) create mode 100644 src/app/controllers/realms_controller.rb create mode 100644 src/app/views/portal_pool/realms.html.erb create mode 100644 src/app/views/provider/realms.html.erb create mode 100644 src/app/views/realms/_list.html.erb create mode 100644 src/app/views/realms/index.html.erb
diff --git a/src/app/controllers/portal_pool_controller.rb b/src/app/controllers/portal_pool_controller.rb index 90df8a5..21ceaf2 100644 --- a/src/app/controllers/portal_pool_controller.rb +++ b/src/app/controllers/portal_pool_controller.rb @@ -38,6 +38,12 @@ class PortalPoolController < ApplicationController @instances = @pool.instances end
+ def realms + @pool = PortalPool.find(params[:id]) + @realms = @pool.providers.collect { |pr| pr.realms }.flatten + require_privilege(Privilege::INSTANCE_VIEW,@pool) + end + def new require_privilege(Privilege::POOL_MODIFY) @portal_pool = PortalPool.new diff --git a/src/app/controllers/provider_controller.rb b/src/app/controllers/provider_controller.rb index 53056f5..ac703c0 100644 --- a/src/app/controllers/provider_controller.rb +++ b/src/app/controllers/provider_controller.rb @@ -32,6 +32,12 @@ class ProviderController < ApplicationController require_privilege(Privilege::PROVIDER_VIEW, @provider) end
+ def realms + @provider = Provider.find(params[:id]) + @realms = @provider.realms + require_privilege(Privilege::PROVIDER_VIEW, @provider) + end + def new require_privilege(Privilege::PROVIDER_MODIFY) @provider = Provider.new(params[:provider]) diff --git a/src/app/controllers/realms_controller.rb b/src/app/controllers/realms_controller.rb new file mode 100644 index 0000000..667279c --- /dev/null +++ b/src/app/controllers/realms_controller.rb @@ -0,0 +1,39 @@ +# Copyright (C) 2010 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +require 'util/taskomatic' + +class RealmsController < ApplicationController + before_filter :require_user + + def index + @realms = Realm.find(:all) + #require_privilege(Privilege::PROVIDER_VIEW, @realms) ? + end + + def new + end + + def create + end + + def delete + end +end diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb index 28b700e..81de037 100644 --- a/src/app/models/portal_pool.rb +++ b/src/app/models/portal_pool.rb @@ -40,6 +40,10 @@ class PortalPool < ActiveRecord::Base :include => [:role], :order => "permissions.id ASC"
+ def providers + cloud_accounts.collect { |ca| ca.provider } + end + def realms realm_list = [] cloud_accounts.each do |cloud_account| diff --git a/src/app/views/portal_pool/realms.html.erb b/src/app/views/portal_pool/realms.html.erb new file mode 100644 index 0000000..3aca533 --- /dev/null +++ b/src/app/views/portal_pool/realms.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'realms/list' %> diff --git a/src/app/views/provider/realms.html.erb b/src/app/views/provider/realms.html.erb new file mode 100644 index 0000000..3aca533 --- /dev/null +++ b/src/app/views/provider/realms.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'realms/list' %> diff --git a/src/app/views/realms/_list.html.erb b/src/app/views/realms/_list.html.erb new file mode 100644 index 0000000..c95fac3 --- /dev/null +++ b/src/app/views/realms/_list.html.erb @@ -0,0 +1,20 @@ +<% if @realms.size == 0 %> +<h1>There are no realms to display</h1> +<% else %> + <table> + <thead> + <tr> + <th scope="col">Name</th> + <th scope="col">Provider</th> + </tr> + </thead> + <tbody> + <%@realms.each {|realm| %> + <tr> + <td><%= realm.name %></td> + <td><%= realm.provider.name %></td> + </tr> + <% } %> + </tbody> + </table> +<% end %> diff --git a/src/app/views/realms/index.html.erb b/src/app/views/realms/index.html.erb new file mode 100644 index 0000000..c19c3fa --- /dev/null +++ b/src/app/views/realms/index.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'list' %>
requires "spec fixes and updates" patch to be applied first --- .../controllers/portal_pool_controller_spec.rb | 9 +++++++++ src/spec/controllers/provider_controller_spec.rb | 10 ++++++++++ src/spec/controllers/realms_controller_spec.rb | 19 +++++++++++++++++++ src/spec/factories/provider.rb | 8 ++++++++ src/spec/factories/realm.rb | 13 +++++++++++++ src/spec/models/portal_pool_spec.rb | 18 ++++++++++++++++++ 6 files changed, 77 insertions(+), 0 deletions(-) create mode 100644 src/spec/controllers/realms_controller_spec.rb create mode 100644 src/spec/factories/realm.rb create mode 100644 src/spec/models/portal_pool_spec.rb
diff --git a/src/spec/controllers/portal_pool_controller_spec.rb b/src/spec/controllers/portal_pool_controller_spec.rb index bc01a31..c19470f 100644 --- a/src/spec/controllers/portal_pool_controller_spec.rb +++ b/src/spec/controllers/portal_pool_controller_spec.rb @@ -29,5 +29,14 @@ describe PortalPoolController do response.should redirect_to("http://test.host/portal_pool/show/#%7Bid%7D") end
+ it "should provide ui to view realms" do + UserSession.create(@admin) + pool = Factory :tpool + + get :realms, :id => pool.id + response.should be_success + assigns[:realms].size.should == pool.providers.collect { |pr| pr.realms }.flatten.size + response.should render_template("realms") + end
end diff --git a/src/spec/controllers/provider_controller_spec.rb b/src/spec/controllers/provider_controller_spec.rb index 9015a00..6cfb193 100644 --- a/src/spec/controllers/provider_controller_spec.rb +++ b/src/spec/controllers/provider_controller_spec.rb @@ -32,4 +32,14 @@ describe ProviderController do response.should_not be_success end
+ it "should provide ui to view realms" do + UserSession.create(@admin) + provider = @admin_permission.permission_object + + get :realms, :id => provider.id + response.should be_success + assigns[:realms].size.should == provider.realms.size + response.should render_template("realms") + end + end diff --git a/src/spec/controllers/realms_controller_spec.rb b/src/spec/controllers/realms_controller_spec.rb new file mode 100644 index 0000000..8cd9e44 --- /dev/null +++ b/src/spec/controllers/realms_controller_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe RealmsController do + + before(:each) do + @admin_permission = Factory :admin_permission + @admin = @admin_permission.user + activate_authlogic + end + + it "should provide ui to view all realms" do + UserSession.create(@admin) + get :index + response.should be_success + assigns[:realms].size.should == Realm.count + response.should render_template("index") + end + +end diff --git a/src/spec/factories/provider.rb b/src/spec/factories/provider.rb index 921d54b..7c25677 100644 --- a/src/spec/factories/provider.rb +++ b/src/spec/factories/provider.rb @@ -5,4 +5,12 @@ Factory.define :mock_provider, :parent => :provider do |p| p.name 'mock1' p.cloud_type 'mock' p.url 'http://localhost:3001/api' + p.after_create { |p| p.realms << Factory(:realm1, :provider => p) << Factory(:realm2, :provider => p) } +end + +Factory.define :mock_provider2, :parent => :provider do |p| + p.name 'mock2' + p.cloud_type 'mock' + p.url 'http://localhost:3001/api' + p.after_create { |p| p.realms << Factory(:realm3, :provider => p) } end diff --git a/src/spec/factories/realm.rb b/src/spec/factories/realm.rb new file mode 100644 index 0000000..93a6516 --- /dev/null +++ b/src/spec/factories/realm.rb @@ -0,0 +1,13 @@ +Factory.define :realm do |r| + r.sequence(:name) { |n| "realm#{n}" } + r.sequence(:external_key) { |n| "key#{n}" } +end + +Factory.define :realm1, :parent => :realm do |r| +end + +Factory.define :realm2, :parent => :realm do |r| +end + +Factory.define :realm3, :parent => :realm do |r| +end diff --git a/src/spec/models/portal_pool_spec.rb b/src/spec/models/portal_pool_spec.rb new file mode 100644 index 0000000..104064b --- /dev/null +++ b/src/spec/models/portal_pool_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe PortalPool do + before(:each) do + end + + it "should return all associated providers" do + provider1, provider2 = Factory(:mock_provider), Factory(:mock_provider2) + + pool = PortalPool.new + pool.cloud_accounts << CloudAccount.new(:provider => provider1) + pool.cloud_accounts << CloudAccount.new(:provider => provider2) + + providers = pool.providers + providers.include?(provider1).should be_true + providers.include?(provider2).should be_true + end +end
Mohammed Morsi wrote:
src/app/controllers/portal_pool_controller.rb | 6 ++++ src/app/controllers/provider_controller.rb | 6 ++++ src/app/controllers/realms_controller.rb | 39 +++++++++++++++++++++++++ src/app/models/portal_pool.rb | 4 ++ src/app/views/portal_pool/realms.html.erb | 1 + src/app/views/provider/realms.html.erb | 1 + src/app/views/realms/_list.html.erb | 20 +++++++++++++ src/app/views/realms/index.html.erb | 1 + 8 files changed, 78 insertions(+), 0 deletions(-) create mode 100644 src/app/controllers/realms_controller.rb create mode 100644 src/app/views/portal_pool/realms.html.erb create mode 100644 src/app/views/provider/realms.html.erb create mode 100644 src/app/views/realms/_list.html.erb create mode 100644 src/app/views/realms/index.html.erb
diff --git a/src/app/controllers/portal_pool_controller.rb b/src/app/controllers/portal_pool_controller.rb index 90df8a5..21ceaf2 100644 --- a/src/app/controllers/portal_pool_controller.rb +++ b/src/app/controllers/portal_pool_controller.rb @@ -38,6 +38,12 @@ class PortalPoolController < ApplicationController @instances = @pool.instances end
- def realms
- @pool = PortalPool.find(params[:id])
- @realms = @pool.providers.collect { |pr| pr.realms }.flatten
You'll want to call Realms on @pool: @pool.realms. For all of the pool views we want the "front end" resources (i.e. realms, images, HW Profiles defined on the pool), not those that happen to be defined on the back end accounts. Realm is a bit of a special case as realms is a method that returns a list of strings, since pool realms are auto-generated from the back end realms (unlike HWP and Images which have an explicit mapping table)
- require_privilege(Privilege::INSTANCE_VIEW,@pool)
I think we should use POOL_VIEW here. POOL_VIEW would be the default privilege for viewing pool resources except for those with more specialized privileges defined (quotas, instances, accounts)
- end
- def new require_privilege(Privilege::POOL_MODIFY) @portal_pool = PortalPool.new
diff --git a/src/app/controllers/provider_controller.rb b/src/app/controllers/provider_controller.rb index 53056f5..ac703c0 100644 --- a/src/app/controllers/provider_controller.rb +++ b/src/app/controllers/provider_controller.rb @@ -32,6 +32,12 @@ class ProviderController < ApplicationController require_privilege(Privilege::PROVIDER_VIEW, @provider) end
- def realms
- @provider = Provider.find(params[:id])
- @realms = @provider.realms
- require_privilege(Privilege::PROVIDER_VIEW, @provider)
- end
- def new require_privilege(Privilege::PROVIDER_MODIFY) @provider = Provider.new(params[:provider])
diff --git a/src/app/controllers/realms_controller.rb b/src/app/controllers/realms_controller.rb new file mode 100644 index 0000000..667279c --- /dev/null +++ b/src/app/controllers/realms_controller.rb @@ -0,0 +1,39 @@ +# Copyright (C) 2010 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html.
+# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers.
+require 'util/taskomatic'
I don't think you need to include taskomatic here
+class RealmsController < ApplicationController
- before_filter :require_user
- def index
- @realms = Realm.find(:all)
- #require_privilege(Privilege::PROVIDER_VIEW, @realms) ?
- end
I'm not sure we need to support listing all realms regardless of what provider they belong to, as realms don't really make sense apart from the provider and/or pool.
- def new
- end
- def create
- end
- def delete
- end
+end diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb index 28b700e..81de037 100644 --- a/src/app/models/portal_pool.rb +++ b/src/app/models/portal_pool.rb @@ -40,6 +40,10 @@ class PortalPool < ActiveRecord::Base :include => [:role], :order => "permissions.id ASC"
- def providers
- cloud_accounts.collect { |ca| ca.provider }
- end
If you're not doing the provider iteration above, you can probably get rid of this one for now.
def realms realm_list = [] cloud_accounts.each do |cloud_account| diff --git a/src/app/views/portal_pool/realms.html.erb b/src/app/views/portal_pool/realms.html.erb new file mode 100644 index 0000000..3aca533 --- /dev/null +++ b/src/app/views/portal_pool/realms.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'realms/list' %> diff --git a/src/app/views/provider/realms.html.erb b/src/app/views/provider/realms.html.erb new file mode 100644 index 0000000..3aca533 --- /dev/null +++ b/src/app/views/provider/realms.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'realms/list' %> diff --git a/src/app/views/realms/_list.html.erb b/src/app/views/realms/_list.html.erb new file mode 100644 index 0000000..c95fac3 --- /dev/null +++ b/src/app/views/realms/_list.html.erb @@ -0,0 +1,20 @@ +<% if @realms.size == 0 %> +<h1>There are no realms to display</h1> +<% else %>
<table>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Provider</th>
So once this is reformulated to show realms for the pool the provider name will go away here.
</tr>
</thead>
<tbody>
- <%@realms.each {|realm| %>
<tr>
<td><%= realm.name %></td>
<td><%= realm.provider.name %></td>
</tr>
<% } %>
</tbody>
</table>
+<% end %> diff --git a/src/app/views/realms/index.html.erb b/src/app/views/realms/index.html.erb new file mode 100644 index 0000000..c19c3fa --- /dev/null +++ b/src/app/views/realms/index.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'list' %>
Scott
On 03/18/2010 02:39 PM, Scott Seago wrote:
Mohammed Morsi wrote:
src/app/controllers/portal_pool_controller.rb | 6 ++++ src/app/controllers/provider_controller.rb | 6 ++++ src/app/controllers/realms_controller.rb | 39 +++++++++++++++++++++++++ src/app/models/portal_pool.rb | 4 ++ src/app/views/portal_pool/realms.html.erb | 1 + src/app/views/provider/realms.html.erb | 1 + src/app/views/realms/_list.html.erb | 20 +++++++++++++ src/app/views/realms/index.html.erb | 1 + 8 files changed, 78 insertions(+), 0 deletions(-) create mode 100644 src/app/controllers/realms_controller.rb create mode 100644 src/app/views/portal_pool/realms.html.erb create mode 100644 src/app/views/provider/realms.html.erb create mode 100644 src/app/views/realms/_list.html.erb create mode 100644 src/app/views/realms/index.html.erb
diff --git a/src/app/controllers/portal_pool_controller.rb b/src/app/controllers/portal_pool_controller.rb index 90df8a5..21ceaf2 100644 --- a/src/app/controllers/portal_pool_controller.rb +++ b/src/app/controllers/portal_pool_controller.rb @@ -38,6 +38,12 @@ class PortalPoolController < ApplicationController @instances = @pool.instances end
- def realms
- @pool = PortalPool.find(params[:id])
- @realms = @pool.providers.collect { |pr| pr.realms }.flatten
You'll want to call Realms on @pool: @pool.realms. For all of the pool views we want the "front end" resources (i.e. realms, images, HW Profiles defined on the pool), not those that happen to be defined on the back end accounts. Realm is a bit of a special case as realms is a method that returns a list of strings, since pool realms are auto-generated from the back end realms (unlike HWP and Images which have an explicit mapping table)
Ah, hadn't noticed that method. Was looking for a has_many :realms and/or a portal_pool_id column in the realms table.
- require_privilege(Privilege::INSTANCE_VIEW,@pool)
I think we should use POOL_VIEW here. POOL_VIEW would be the default privilege for viewing pool resources except for those with more specialized privileges defined (quotas, instances, accounts)
- end
- def new require_privilege(Privilege::POOL_MODIFY) @portal_pool = PortalPool.new
diff --git a/src/app/controllers/provider_controller.rb b/src/app/controllers/provider_controller.rb index 53056f5..ac703c0 100644 --- a/src/app/controllers/provider_controller.rb +++ b/src/app/controllers/provider_controller.rb @@ -32,6 +32,12 @@ class ProviderController < ApplicationController require_privilege(Privilege::PROVIDER_VIEW, @provider) end
- def realms
- @provider = Provider.find(params[:id])
- @realms = @provider.realms
- require_privilege(Privilege::PROVIDER_VIEW, @provider)
- end
- def new require_privilege(Privilege::PROVIDER_MODIFY) @provider = Provider.new(params[:provider])
diff --git a/src/app/controllers/realms_controller.rb b/src/app/controllers/realms_controller.rb new file mode 100644 index 0000000..667279c --- /dev/null +++ b/src/app/controllers/realms_controller.rb @@ -0,0 +1,39 @@ +# Copyright (C) 2010 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html.
+# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers.
+require 'util/taskomatic'
I don't think you need to include taskomatic here
Had just copied the portal pool controller over (which still includes taskomatic) and made changes. Removed both requires in the updated patch.
+class RealmsController < ApplicationController
- before_filter :require_user
- def index
- @realms = Realm.find(:all)
- #require_privilege(Privilege::PROVIDER_VIEW, @realms) ?
- end
I'm not sure we need to support listing all realms regardless of what provider they belong to, as realms don't really make sense apart from the provider and/or pool.
We're really not losing anything here either. The realm views should really go into their own app/views/realms dir, and since we have that, an extra controller / action is trivial. In the interest of getting this in though, removed.
- def new
- end
- def create
- end
- def delete
- end
+end diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb index 28b700e..81de037 100644 --- a/src/app/models/portal_pool.rb +++ b/src/app/models/portal_pool.rb @@ -40,6 +40,10 @@ class PortalPool < ActiveRecord::Base :include => [:role], :order => "permissions.id ASC"
- def providers
- cloud_accounts.collect { |ca| ca.provider }
- end
If you're not doing the provider iteration above, you can probably get rid of this one for now.
Removed.
def realms realm_list = [] cloud_accounts.each do |cloud_account| diff --git a/src/app/views/portal_pool/realms.html.erb b/src/app/views/portal_pool/realms.html.erb new file mode 100644 index 0000000..3aca533 --- /dev/null +++ b/src/app/views/portal_pool/realms.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'realms/list' %> diff --git a/src/app/views/provider/realms.html.erb b/src/app/views/provider/realms.html.erb new file mode 100644 index 0000000..3aca533 --- /dev/null +++ b/src/app/views/provider/realms.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'realms/list' %> diff --git a/src/app/views/realms/_list.html.erb b/src/app/views/realms/_list.html.erb new file mode 100644 index 0000000..c95fac3 --- /dev/null +++ b/src/app/views/realms/_list.html.erb @@ -0,0 +1,20 @@ +<% if @realms.size == 0 %> +<h1>There are no realms to display</h1> +<% else %>
<table>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Provider</th>
So once this is reformulated to show realms for the pool the provider name will go away here.
Removed.
</tr>
</thead>
<tbody>
- <%@realms.each {|realm| %>
<tr>
<td><%= realm.name %></td>
<td><%= realm.provider.name %></td>
</tr>
- <% } %>
</tbody>
</table>
+<% end %> diff --git a/src/app/views/realms/index.html.erb b/src/app/views/realms/index.html.erb new file mode 100644 index 0000000..c19c3fa --- /dev/null +++ b/src/app/views/realms/index.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'list' %>
Scott
Update patch sent.
-Mo
deltacloud-devel@lists.fedorahosted.org