Sending updated patchset, note that condormatic is not updated yet.
From: Jan Provaznik jprovazn@redhat.com
Realm = backend realm provided by a provider FrontendRealm = conductor realm (actually only name)
Frontend realm can be mapped to many provider realms or providers. Provider realm or provider can be mapped to many frontend realms. User defines this mapping in UI. --- src/app/models/cloud_account.rb | 16 -------- src/app/models/frontend_realm.rb | 33 ++++++++++++++++ src/app/models/instance.rb | 2 +- src/app/models/provider.rb | 2 + src/app/models/realm.rb | 45 +-------------------- src/app/models/realm_backend_target.rb | 8 ++++ src/db/migrate/20110126121114_frontend_realms.rb | 26 ++++++++++++ 7 files changed, 73 insertions(+), 59 deletions(-) create mode 100644 src/app/models/frontend_realm.rb create mode 100644 src/app/models/realm_backend_target.rb create mode 100644 src/db/migrate/20110126121114_frontend_realms.rb
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb index 4eba087..d7a4806 100644 --- a/src/app/models/cloud_account.rb +++ b/src/app/models/cloud_account.rb @@ -150,22 +150,6 @@ class CloudAccount < ActiveRecord::Base :name => realm.name ? realm.name : realm.id, :provider_id => provider.id) ar_realm.save! - - frontend_realm = Realm.new(:external_key => ar_realm.external_key, - :name => ar_realm.name, - :provider_id => nil) - - available_realms = Realm.frontend.find(:all, :conditions => { - :external_key => frontend_realm.external_key }) - - if available_realms.empty? - frontend_realm.backend_realms << ar_realm - frontend_realm.save! - else - available_realms.each do |r| - r.backend_realms << ar_realm - end - end end end end diff --git a/src/app/models/frontend_realm.rb b/src/app/models/frontend_realm.rb new file mode 100644 index 0000000..33e51f2 --- /dev/null +++ b/src/app/models/frontend_realm.rb @@ -0,0 +1,33 @@ +# +# Copyright (C) 2009 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. + +class FrontendRealm < ActiveRecord::Base + has_many :realm_backend_targets + has_many :instances + + # there is a problem with has_many through + polymophic in AR: + # http://blog.hasmanythrough.com/2006/4/3/polymorphic-through + # so we define explicitly backend_realms and backend_providers + has_many :backend_realms, :through => :realm_backend_targets, :source => :realm, :conditions => "realm_backend_targets.realm_or_provider_type = 'Realm'" + has_many :backend_providers, :through => :realm_backend_targets, :source => :provider, :conditions => "realm_backend_targets.realm_or_provider_type = 'Provider'" + + validates_presence_of :name +end diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index b84a596..d89ce9c 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -40,7 +40,7 @@ class Instance < ActiveRecord::Base
belongs_to :hardware_profile belongs_to :template - belongs_to :realm + belongs_to :frontend_realm belongs_to :owner, :class_name => "User", :foreign_key => "owner_id" belongs_to :instance_hwp
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb index 1e89958..a8a1d17 100644 --- a/src/app/models/provider.rb +++ b/src/app/models/provider.rb @@ -33,6 +33,8 @@ class Provider < ActiveRecord::Base has_many :hardware_profiles, :dependent => :destroy has_many :replicated_images, :dependent => :destroy has_many :realms, :dependent => :destroy + has_many :realm_backend_targets, :as => :realm_or_provider + has_many :frontend_realms, :through => :realm_backend_targets
validates_presence_of :name validates_uniqueness_of :name diff --git a/src/app/models/realm.rb b/src/app/models/realm.rb index 4695792..0db4443 100644 --- a/src/app/models/realm.rb +++ b/src/app/models/realm.rb @@ -20,55 +20,16 @@ # Likewise, all the methods added will be available for all controllers.
class Realm < ActiveRecord::Base - has_many :instances belongs_to :provider - named_scope :frontend, :conditions => { :provider_id => nil }
- has_and_belongs_to_many :frontend_realms, - :class_name => "Realm", - :join_table => "realm_map", - :foreign_key => "backend_realm_id", - :association_foreign_key => "frontend_realm_id" - - has_and_belongs_to_many :backend_realms, - :class_name => "Realm", - :join_table => "realm_map", - :foreign_key => "frontend_realm_id", - :association_foreign_key => "backend_realm_id" + has_many :realm_backend_targets, :as => :realm_or_provider + has_many :frontend_realms, :through => :realm_backend_targets
validates_presence_of :external_key validates_uniqueness_of :external_key, :scope => :provider_id
validates_presence_of :name - - protected - def validate - if provider.nil? and !frontend_realms.empty? - errors.add(:frontend_realms, "Frontend realms are allowed for backend realms only.") - end - - - if !provider.nil? and !backend_realms.empty? - errors.add(:backend_realms, "Backend realms are allowed for frontend realms only.") - end - - frontend_realms.each do |frealm| - if name != frealm.name - errors.add(:realms, "Frontend realm must have the same name as the appropriate backend realm.") - end - if external_key != frealm.external_key - errors.add(:realms, "Frontend realm must have the same external key as the appropriate backend realm.") - end - end - backend_realms.each do |brealm| - if name != brealm.name - errors.add(:realms, "Frontend realm must have the same name as the appropriate backend realm.") - end - if external_key != brealm.external_key - errors.add(:realms, "Frontend realm must have the same external key as the appropriate backend realm.") - end - end - end + validates_presence_of :provider_id
AGGREGATOR_REALM_PROVIDER_DELIMITER = ":" AGGREGATOR_REALM_ACCOUNT_DELIMITER = "/" diff --git a/src/app/models/realm_backend_target.rb b/src/app/models/realm_backend_target.rb new file mode 100644 index 0000000..a39ee3d --- /dev/null +++ b/src/app/models/realm_backend_target.rb @@ -0,0 +1,8 @@ +class RealmBackendTarget < ActiveRecord::Base + belongs_to :frontend_realm + belongs_to :realm_or_provider, :polymorphic =>true + belongs_to :realm, :class_name => 'Realm', :foreign_key => 'realm_or_provider_id' + belongs_to :provider, :class_name => 'Provider', :foreign_key => 'realm_or_provider_id' + + validates_uniqueness_of :frontend_realm_id, :scope => [:realm_or_provider_id, :realm_or_provider_type] +end diff --git a/src/db/migrate/20110126121114_frontend_realms.rb b/src/db/migrate/20110126121114_frontend_realms.rb new file mode 100644 index 0000000..0be5c22 --- /dev/null +++ b/src/db/migrate/20110126121114_frontend_realms.rb @@ -0,0 +1,26 @@ +class FrontendRealms < ActiveRecord::Migration + def self.up + drop_table :realm_map + create_table :frontend_realms do |t| + t.string :name, :null => false, :limit => 1024 + t.integer :lock_version, :default => 0 + t.timestamps + end + create_table :realm_backend_targets do |t| + t.integer :realm_or_provider_id, :null => false + t.string :realm_or_provider_type, :null => false + t.integer :frontend_realm_id, :null => false + end + rename_column :instances, :realm_id, :frontend_realm_id + end + + def self.down + drop_table :frontend_realms + drop_table :realm_backend_targets + create_table "realm_map", :force => true, :id => false do |t| + t.column "frontend_realm_id", :integer + t.column "backend_realm_id", :integer + end + rename_column :instances, :frontend_realm_id, :realm_id + end +end
On 02/04/2011 09:07 AM, jprovazn@redhat.com wrote:
From: Jan Provaznikjprovazn@redhat.com
Realm = backend realm provided by a provider FrontendRealm = conductor realm (actually only name)
Frontend realm can be mapped to many provider realms or providers. Provider realm or provider can be mapped to many frontend realms. User defines this mapping in UI.
src/app/models/cloud_account.rb | 16 -------- src/app/models/frontend_realm.rb | 33 ++++++++++++++++ src/app/models/instance.rb | 2 +- src/app/models/provider.rb | 2 + src/app/models/realm.rb | 45 +-------------------- src/app/models/realm_backend_target.rb | 8 ++++ src/db/migrate/20110126121114_frontend_realms.rb | 26 ++++++++++++ 7 files changed, 73 insertions(+), 59 deletions(-) create mode 100644 src/app/models/frontend_realm.rb create mode 100644 src/app/models/realm_backend_target.rb create mode 100644 src/db/migrate/20110126121114_frontend_realms.rb
This all seems to work now,
ACK to the series, but we need to hold off pushing to next until the condor bits are in so that we don't break condor.
Scott
From: Jan Provaznik jprovazn@redhat.com
--- src/features/step_definitions/instance_steps.rb | 2 +- src/spec/factories/frontend_realm.rb | 3 ++ src/spec/factories/realm.rb | 3 -- src/spec/factories/realm_backend_target.rb | 4 ++ src/spec/models/realm_spec.rb | 41 +++++----------------- 5 files changed, 18 insertions(+), 35 deletions(-) create mode 100644 src/spec/factories/frontend_realm.rb create mode 100644 src/spec/factories/realm_backend_target.rb
diff --git a/src/features/step_definitions/instance_steps.rb b/src/features/step_definitions/instance_steps.rb index 4324891..b843af2 100644 --- a/src/features/step_definitions/instance_steps.rb +++ b/src/features/step_definitions/instance_steps.rb @@ -56,7 +56,7 @@ Given /^there is "([^"]*)" aggregator hardware profile$/ do |name| end
Given /^there is "([^"]*)" aggregator realm$/ do |name| - Factory :frontend_realm, :provider_id => nil, :name => name + Factory :frontend_realm, :backend_realm => Factory(:provider), :name => name end
Given /^there is "([^"]*)" pool$/ do |arg1| diff --git a/src/spec/factories/frontend_realm.rb b/src/spec/factories/frontend_realm.rb new file mode 100644 index 0000000..215869a --- /dev/null +++ b/src/spec/factories/frontend_realm.rb @@ -0,0 +1,3 @@ +Factory.define :frontend_realm do |r| + r.sequence(:name) { |n| "realm#{n}" } +end diff --git a/src/spec/factories/realm.rb b/src/spec/factories/realm.rb index a13f09d..92a677c 100644 --- a/src/spec/factories/realm.rb +++ b/src/spec/factories/realm.rb @@ -20,6 +20,3 @@ Factory.define :backend_realm, :parent => :realm do |r| r.name 'backend_name' r.external_key 'backend_key' end - -Factory.define :frontend_realm, :parent => :backend_realm do |r| -end diff --git a/src/spec/factories/realm_backend_target.rb b/src/spec/factories/realm_backend_target.rb new file mode 100644 index 0000000..f018cd4 --- /dev/null +++ b/src/spec/factories/realm_backend_target.rb @@ -0,0 +1,4 @@ +Factory.define :realm_backend_target do |r| + r.association(:frontend_realm) + r.association :realm_or_provider, :fatcory => :backend_realm +end diff --git a/src/spec/models/realm_spec.rb b/src/spec/models/realm_spec.rb index 6f8ce19..6d16355 100644 --- a/src/spec/models/realm_spec.rb +++ b/src/spec/models/realm_spec.rb @@ -6,45 +6,24 @@ describe Realm do @provider = Factory :mock_provider @backend_realm = Factory :backend_realm, :provider => @provider
- @frontend_realm = Factory :frontend_realm, :provider => nil - @backend_realm.frontend_realms << @frontend_realm - @frontend_realm.backend_realms << @backend_realm + @frontend_realm1 = Factory :frontend_realm + RealmBackendTarget.create!(:frontend_realm => @frontend_realm1, :realm_or_provider => @backend_realm) + RealmBackendTarget.create!(:frontend_realm => @frontend_realm1, :realm_or_provider => @provider) end
it "should validate backend" do @backend_realm.provider_id.should_not be_nil - @backend_realm.backend_realms.should be_empty - @backend_realm.frontend_realms.should_not be_empty - @backend_realm.frontend_realms.first.id.should == @frontend_realm.id + @backend_realm.frontend_realms.first.id.should == @frontend_realm1.id + @provider.frontend_realms.should_not be_empty + @provider.frontend_realms.first.id.should == @frontend_realm1.id end
it "should validate frontend" do - @frontend_realm.provider_id.should be_nil - @frontend_realm.frontend_realms.should be_empty - - @frontend_realm.backend_realms.should_not be_empty - @frontend_realm.backend_realms.first.id.should == @backend_realm.id - end - - it "should map the frontend and backend names" do - @frontend_realm.name = 'different_from' + @backend_realm.name - @frontend_realm.should_not be_valid - @backend_realm.should_not be_valid - - @frontend_realm.name = @backend_realm.name - @frontend_realm.should be_valid - @backend_realm.should be_valid - end - - it "should map the frontend and backend keys" do - @frontend_realm.external_key = 'different_from' + @backend_realm.external_key - @frontend_realm.should_not be_valid - @backend_realm.should_not be_valid - - @frontend_realm.external_key = @backend_realm.external_key - @frontend_realm.should be_valid - @backend_realm.should be_valid + @frontend_realm1.backend_realms.should_not be_empty + @frontend_realm1.backend_realms.first.id.should == @backend_realm.id + @frontend_realm1.backend_providers.should_not be_nil + @frontend_realm1.backend_providers.first.id.should == @provider.id end
end
From: Jan Provaznik jprovazn@redhat.com
--- src/app/models/pool.rb | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb index 550ca79..68ff641 100644 --- a/src/app/models/pool.rb +++ b/src/app/models/pool.rb @@ -57,8 +57,4 @@ class Pool < ActiveRecord::Base HardwareProfile.find(:all, :conditions => {:provider_id => nil}) end
- def realms - Realm.find(:all, :conditions => { :provider_id => nil }) - end - end
From: Jan Provaznik jprovazn@redhat.com
--- .../controllers/admin/realm_mappings_controller.rb | 35 ++++++++ src/app/controllers/admin/realms_controller.rb | 82 +++++++++++++++++++- .../controllers/resources/instances_controller.rb | 2 +- src/app/views/admin/realm_mappings/new.haml | 9 ++ src/app/views/admin/realm_mappings/show.haml | 5 + src/app/views/admin/realms/_form.haml | 6 ++ src/app/views/admin/realms/_list.haml | 19 +++++ src/app/views/admin/realms/_mapping.haml | 20 +++++ src/app/views/admin/realms/_properties.haml | 3 + src/app/views/admin/realms/edit.haml | 4 + src/app/views/admin/realms/index.haml | 3 +- src/app/views/admin/realms/new.haml | 3 + src/app/views/admin/realms/show.haml | 5 + src/app/views/resources/instances/new.haml | 4 +- src/config/routes.rb | 3 +- 15 files changed, 197 insertions(+), 6 deletions(-) create mode 100644 src/app/controllers/admin/realm_mappings_controller.rb create mode 100644 src/app/views/admin/realm_mappings/new.haml create mode 100644 src/app/views/admin/realm_mappings/show.haml create mode 100644 src/app/views/admin/realms/_form.haml create mode 100644 src/app/views/admin/realms/_list.haml create mode 100644 src/app/views/admin/realms/_mapping.haml create mode 100644 src/app/views/admin/realms/_properties.haml create mode 100644 src/app/views/admin/realms/edit.haml create mode 100644 src/app/views/admin/realms/new.haml create mode 100644 src/app/views/admin/realms/show.haml
diff --git a/src/app/controllers/admin/realm_mappings_controller.rb b/src/app/controllers/admin/realm_mappings_controller.rb new file mode 100644 index 0000000..26b156a --- /dev/null +++ b/src/app/controllers/admin/realm_mappings_controller.rb @@ -0,0 +1,35 @@ +class Admin::RealmMappingsController < ApplicationController + before_filter :require_user + + def new + require_privilege(Privilege::CREATE, Realm) + @realm_target = RealmBackendTarget.new(:frontend_realm_id => params[:frontend_realm_id], :realm_or_provider_type => params[:realm_or_provider_type]) + load_backend_targets + end + + def create + require_privilege(Privilege::CREATE, Realm) + @realm_target = RealmBackendTarget.new(params[:realm_backend_target]) + if @realm_target.save + flash[:notice] = "Realm mapping was added." + redirect_to admin_realm_path(@realm_target.frontend_realm, :details_tab => 'mapping') and return + #redirect_to admin_realms_path and return + end + + load_backend_targets + render :new + end + + def multi_destroy + require_privilege(Privilege::MODIFY, Realm) + # TODO: add permissions checks + destroyed = RealmBackendTarget.destroy(params[:id]) + redirect_to admin_realm_path(destroyed.first.frontend_realm_id, :details_tab => 'mapping') + end + + protected + + def load_backend_targets + @backend_targets = @realm_target.realm_or_provider_type == 'Realm' ? Realm.all : Provider.list_for_user(@current_user, Privilege::VIEW) + end +end diff --git a/src/app/controllers/admin/realms_controller.rb b/src/app/controllers/admin/realms_controller.rb index 5379f25..dee6752 100644 --- a/src/app/controllers/admin/realms_controller.rb +++ b/src/app/controllers/admin/realms_controller.rb @@ -1,6 +1,86 @@ class Admin::RealmsController < ApplicationController before_filter :require_user + before_filter :load_realms, :only =>[:index,:show]
- def index + def new + require_privilege(Privilege::CREATE, Realm) + @realm = FrontendRealm.new + load_backend_realms + end + + def edit + require_privilege(Privilege::MODIFY, Realm) + @realm = FrontendRealm.find(params[:id]) + load_backend_realms + end + + def update + require_privilege(Privilege::MODIFY, Realm) + @realm = FrontendRealm.find(params[:id]) + + if params[:commit] == "Reset" + redirect_to edit_admin_realm_url(@realm) and return + end + + if @realm.update_attributes(params[:frontend_realm]) + flash[:notice] = 'Realm updated successfully!' + redirect_to admin_realms_url and return + end + + load_backend_realms + render :action => 'edit' + end + + def create + require_privilege(Privilege::CREATE, Realm) + @realm = FrontendRealm.new(params[:frontend_realm]) + if @realm.save + flash[:notice] = "Realm was added." + redirect_to admin_realms_path and return + end + + load_backend_realms + render :new + end + + def multi_destroy + require_privilege(Privilege::MODIFY, Realm) + FrontendRealm.destroy(params[:id]) + redirect_to admin_realms_path + end + + def show + @realm = FrontendRealm.find(params[:id]) + + @url_params = params.clone + @tab_captions = ['Properties', 'Mapping'] + @details_tab = params[:details_tab].blank? ? 'properties' : params[:details_tab] + if @details_tab == 'mapping' + @backend_realm_targets = @realm.realm_backend_targets.select {|x| x.realm_or_provider_type == 'Realm'} + @backend_provider_targets = @realm.realm_backend_targets.select {|x| x.realm_or_provider_type == 'Provider'} + end + respond_to do |format| + format.js do + if @url_params.delete :details_pane + render :partial => 'layouts/details_pane' and return + end + render :partial => @details_tab + end + format.html { render :action => 'show'} + end + end + + protected + + def load_backend_realms + #TODO: list only realms user has permission on + @backend_realms = Realm.all + @providers = Provider.list_for_user(current_user, Privilege::VIEW) + end + + def load_realms + @header = [{ :name => "Name", :sort_attr => :name}] + @url_params = params.clone + @realms = FrontendRealm.all end end diff --git a/src/app/controllers/resources/instances_controller.rb b/src/app/controllers/resources/instances_controller.rb index 9d2b5c8..ba32bb5 100644 --- a/src/app/controllers/resources/instances_controller.rb +++ b/src/app/controllers/resources/instances_controller.rb @@ -139,7 +139,7 @@ class Resources::InstancesController < ApplicationController
def init_new_instance_attrs @pools = Pool.list_for_user(@current_user, Privilege::MODIFY, :target_type => Instance) - @realms = Realm.find(:all, :conditions => { :provider_id => nil }) + @realms = FrontendRealm.all @hardware_profiles = HardwareProfile.all( :include => :architecture, :conditions => { diff --git a/src/app/views/admin/realm_mappings/new.haml b/src/app/views/admin/realm_mappings/new.haml new file mode 100644 index 0000000..26c364f --- /dev/null +++ b/src/app/views/admin/realm_mappings/new.haml @@ -0,0 +1,9 @@ += error_messages_for 'realm_target' +%h2 Create a new Realm Mapping +- form_for @realm_target, :url => admin_realm_mappings_path do |f| + = f.hidden_field :frontend_realm_id + = f.hidden_field :realm_or_provider_type + + = select_tag 'realm_backend_target[realm_or_provider_id]', options_from_collection_for_select(@backend_targets, 'id', 'name') + %fieldset.clear + = f.submit "Save", :class => "submit formbutton" diff --git a/src/app/views/admin/realm_mappings/show.haml b/src/app/views/admin/realm_mappings/show.haml new file mode 100644 index 0000000..0c36221 --- /dev/null +++ b/src/app/views/admin/realm_mappings/show.haml @@ -0,0 +1,5 @@ +- content_for 'list' do + = render :partial => 'list' + +- content_for 'details' do + = render :partial => 'layouts/details_pane' diff --git a/src/app/views/admin/realms/_form.haml b/src/app/views/admin/realms/_form.haml new file mode 100644 index 0000000..8c49d63 --- /dev/null +++ b/src/app/views/admin/realms/_form.haml @@ -0,0 +1,6 @@ += form.error_messages +%fieldset.clear + = form.label :name,'Realm Name :' + = form.text_field :name, :title => 'realm_name', :value => @realm.name, :class => "clear grid_4 alpha" +%fieldset.clear + = form.submit "Save", :class => "submit formbutton" diff --git a/src/app/views/admin/realms/_list.haml b/src/app/views/admin/realms/_list.haml new file mode 100644 index 0000000..367dc14 --- /dev/null +++ b/src/app/views/admin/realms/_list.haml @@ -0,0 +1,19 @@ +- form_tag do + = link_to "Create", new_admin_realm_path, :class => "button" + = restful_submit_tag "Delete", 'destroy', multi_destroy_admin_realms_path, 'DELETE', :id => 'delete_button' + + %p + Select: + = link_to "All", @url_params.merge(:select => 'all') + %span> , + = link_to "None", @url_params.merge(:select => 'none') + + %table#realms_table + = sortable_table_header @header + - unless @realms.blank? + - @realms.each do |realm| + %tr + %td + - selected = @url_params[:select] == 'all' + %input{:name => "id[]", :type => "checkbox", :value => realm.id, :id => "realm_id_#{realm.id}", :checked => selected } + = link_to realm.name, admin_realm_path(realm) diff --git a/src/app/views/admin/realms/_mapping.haml b/src/app/views/admin/realms/_mapping.haml new file mode 100644 index 0000000..66b278c --- /dev/null +++ b/src/app/views/admin/realms/_mapping.haml @@ -0,0 +1,20 @@ +- form_tag do + = link_to "Add mapping to realm", new_admin_realm_mapping_path(:frontend_realm_id => @realm.id, :realm_or_provider_type => 'Realm'), :class => "button" + = link_to "Add mapping to provider", new_admin_realm_mapping_path(:frontend_realm_id => @realm.id, :realm_or_provider_type => 'Provider'), :class => "button" + = restful_submit_tag "Delete", 'destroy', multi_destroy_admin_realm_mappings_path(:frontend_realm_id => @realm.id), 'DELETE', :id => 'delete_button' + + - unless @backend_provider_targets.empty? + %h2 Realm '#{@realm.name}' is mapped to providers: + %ul + - @backend_provider_targets.each do |backend| + %li + %input{:name => "id[]", :type => "checkbox", :value => backend.id, :id => "backend_id_#{backend.id}"} + = backend.realm_or_provider.name + + - unless @backend_realm_targets.empty? + %h2 Realm '#{@realm.name}' is mapped to realms: + %ul + - @backend_realm_targets.each do |backend| + %li + %input{:name => "id[]", :type => "checkbox", :value => backend.id, :id => "backend_id_#{backend.id}"} + = backend.realm_or_provider.name diff --git a/src/app/views/admin/realms/_properties.haml b/src/app/views/admin/realms/_properties.haml new file mode 100644 index 0000000..8d5b66d --- /dev/null +++ b/src/app/views/admin/realms/_properties.haml @@ -0,0 +1,3 @@ +.grid_13 + %h2 #{@realm.name} + = link_to t(:edit), edit_admin_realm_path(@realm), :class => 'button formbutton' diff --git a/src/app/views/admin/realms/edit.haml b/src/app/views/admin/realms/edit.haml new file mode 100644 index 0000000..a0aa97f --- /dev/null +++ b/src/app/views/admin/realms/edit.haml @@ -0,0 +1,4 @@ +%h2 Editing Realm: #{@realm.name} + +- form_for @realm, :url => admin_realm_path(@realm), :html => { :method => :put } do |f| + = render :partial => "form", :locals => { :form => f } diff --git a/src/app/views/admin/realms/index.haml b/src/app/views/admin/realms/index.haml index 374f27a..62ccbc6 100644 --- a/src/app/views/admin/realms/index.haml +++ b/src/app/views/admin/realms/index.haml @@ -1 +1,2 @@ -admin/realms/index.haml +- content_for :list do + = render :partial => 'list' diff --git a/src/app/views/admin/realms/new.haml b/src/app/views/admin/realms/new.haml new file mode 100644 index 0000000..c95a306 --- /dev/null +++ b/src/app/views/admin/realms/new.haml @@ -0,0 +1,3 @@ +%h2 Create a new Realm +- form_for @realm, :url => admin_realms_path do |f| + = render :partial => "form", :locals => { :form => f, :cancel_path => admin_realms_path } diff --git a/src/app/views/admin/realms/show.haml b/src/app/views/admin/realms/show.haml new file mode 100644 index 0000000..0c36221 --- /dev/null +++ b/src/app/views/admin/realms/show.haml @@ -0,0 +1,5 @@ +- content_for 'list' do + = render :partial => 'list' + +- content_for 'details' do + = render :partial => 'layouts/details_pane' diff --git a/src/app/views/resources/instances/new.haml b/src/app/views/resources/instances/new.haml index 13c973c..7839ba9 100644 --- a/src/app/views/resources/instances/new.haml +++ b/src/app/views/resources/instances/new.haml @@ -20,8 +20,8 @@ = label :instance, :hardware_profile = select :instance, :hardware_profile_id, @hardware_profiles.map {|p| [ p.name, p.id ]}, { :include_blank => false } %li - = label :instance, :realm - = select :instance, :realm_id, @realms.map {|r| [ r.name, r.id ]}, { :include_blank => true } + = label :instance, :frontend_realm + = select :instance, :frontend_realm_id, @realms.map {|r| [ r.name, r.id ]}, { :include_blank => true }
= submit_tag 'Cancel', :name => 'cancel' = submit_tag 'Launch', :name => 'launch' diff --git a/src/config/routes.rb b/src/config/routes.rb index 01d536e..bf6ab5b 100644 --- a/src/config/routes.rb +++ b/src/config/routes.rb @@ -46,7 +46,6 @@ ActionController::Routing::Routes.draw do |map| end
map.namespace 'admin' do |r| - r.resources :realms r.resources :hardware_profiles, :collection => { :multi_destroy => :delete } r.resources :providers, :collection => { :multi_destroy => :delete } r.resources :users, :collection => { :multi_destroy => :delete } @@ -54,6 +53,8 @@ ActionController::Routing::Routes.draw do |map| r.resources :roles, :collection => { :multi_destroy => :delete } r.resources :settings, :collection => { :self_service => :get, :general_settings => :get } r.resources :pool_families, :collection => { :multi_destroy => :delete } + r.resources :realms, :collection => { :multi_destroy => :delete } + r.resources :realm_mappings, :collection => { :multi_destroy => :delete } end
map.login 'login', :controller => "user_sessions", :action => "new"
From: Jan Provaznik jprovazn@redhat.com
--- src/features/instance.feature | 4 +- src/features/realm.feature | 58 +++++++++++++++++++++++ src/features/step_definitions/instance_steps.rb | 4 +- src/features/step_definitions/realm_steps.rb | 28 +++++++++++ src/features/support/paths.rb | 3 + 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/features/realm.feature create mode 100644 src/features/step_definitions/realm_steps.rb
diff --git a/src/features/instance.feature b/src/features/instance.feature index 583ee49..d55dd6b 100644 --- a/src/features/instance.feature +++ b/src/features/instance.feature @@ -38,7 +38,7 @@ Feature: Mange Instances Given there is an uploaded image for a template And I am on the instances page And there is "mock_profile" aggregator hardware profile - And there is "mock_realm" aggregator realm + And there is "mock_realm" frontend realm And there is "mock_pool" pool When I press "Create" Then I should see "Show Templates" @@ -47,7 +47,7 @@ Feature: Mange Instances When I fill in "instance_name" with "mock1" And I select "mock_profile" from "instance_hardware_profile_id" And I select "mock_pool" from "instance_pool_id" - And I select "mock_realm" from "instance_realm_id" + And I select "mock_realm" from "instance_frontend_realm_id" And I press "Launch" Then I should be on the instances page And I should see "mock1" diff --git a/src/features/realm.feature b/src/features/realm.feature new file mode 100644 index 0000000..53d4e91 --- /dev/null +++ b/src/features/realm.feature @@ -0,0 +1,58 @@ +Feature: Manage Realms + In order to manage realms + As an admin + I want to add/edit/remove realms + + Background: + Given I am an authorised user + And I am logged in + And there's no realm + And a realm "testrealm1" exists + And I am using new UI + + Scenario: Create new frontend realm + Given I am on the admin realms page + When I follow "Create" + Then I should see "Create a new Realm" + When I fill in "frontend_realm[name]" with "testrealm2" + And I press "Save" + Then I should see "Realm was added." + + Scenario: Add realm mapping + Given I am on the admin realms page + And there is a realm "testrealm1" + And a provider "provider1" exists + When I follow "testrealm1" + And I follow "Mapping" + And I follow "Add mapping to provider" + Then I should see "Create a new Realm Mapping" + When I press "Save" + Then I should see "Realm mapping was added." + + Scenario: Change the name + Given I am on the admin realms page + And there is a realm "testrealm1" + When I follow "testrealm1" + And I follow "Edit" + Then I should see "Editing Realm:" + When I fill in "frontend_realm[name]" with "testrealm2" + And I press "Save" + Then I should see "Realm updated successfully!" + + Scenario: Show realm detials + Given a realm "testrealm2" exists + And I am on the admin realms page + When I follow "testrealm2" + Then I should be on testrealm2's realm page + + Scenario: Delete realms + Given a realm "testrealm2" exists + And I am on the admin realms page + And there are 2 realms + When I check "testrealm2" realm + And I check "testrealm1" realm + And I press "Delete" + Then there should be only 0 realms + And I should be on the admin realms page + And I should not see "testrealm1" + And I should not see "testrealm2" diff --git a/src/features/step_definitions/instance_steps.rb b/src/features/step_definitions/instance_steps.rb index b843af2..f7b7e67 100644 --- a/src/features/step_definitions/instance_steps.rb +++ b/src/features/step_definitions/instance_steps.rb @@ -55,8 +55,8 @@ Given /^there is "([^"]*)" aggregator hardware profile$/ do |name| Factory :mock_hwp2, :name => name end
-Given /^there is "([^"]*)" aggregator realm$/ do |name| - Factory :frontend_realm, :backend_realm => Factory(:provider), :name => name +Given /^there is "([^"]*)" frontend realm$/ do |name| + Factory :frontend_realm, :name => name end
Given /^there is "([^"]*)" pool$/ do |arg1| diff --git a/src/features/step_definitions/realm_steps.rb b/src/features/step_definitions/realm_steps.rb new file mode 100644 index 0000000..5462c2c --- /dev/null +++ b/src/features/step_definitions/realm_steps.rb @@ -0,0 +1,28 @@ +Given /there's no realm/ do + FrontendRealm.destroy_all +end + +Given /^a realm "([^"]*)" exists$/ do |realm_name| + FrontendRealm.create(:name => realm_name) +end + +Given /^a provider "([^"]*)" exists$/ do |name| + Factory(:mock_provider, :name => name) +end + +Given /^there is a realm "([^"]*)"$/ do |name| + FrontendRealm.find_by_name(name).should_not == nil +end + +Given /^there are (\d+) realms$/ do |number| + FrontendRealm.count.should == number.to_i +end + +When /^(?:|I )check "([^"]*)" realm$/ do |realm_name| + realm = FrontendRealm.find_by_name(realm_name) + check("realm_id_#{realm.id}") +end + +Then /^there should be only (\d+) realms$/ do |number| + FrontendRealm.count.should == number.to_i +end diff --git a/src/features/support/paths.rb b/src/features/support/paths.rb index d59e780..818ebb5 100644 --- a/src/features/support/paths.rb +++ b/src/features/support/paths.rb @@ -23,6 +23,9 @@ module NavigationHelpers when /^(.*)'s role page$/i admin_role_path(Role.find_by_name($1))
+ when /^(.*)'s realm page$/i + admin_realm_path(FrontendRealm.find_by_name($1)) + when /the account page/ account_path
From: Jan Provaznik jprovazn@redhat.com
--- src/app/models/realm.rb | 4 ++++ src/app/views/admin/realm_mappings/new.haml | 3 ++- 2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/src/app/models/realm.rb b/src/app/models/realm.rb index 0db4443..dbbbe21 100644 --- a/src/app/models/realm.rb +++ b/src/app/models/realm.rb @@ -33,4 +33,8 @@ class Realm < ActiveRecord::Base
AGGREGATOR_REALM_PROVIDER_DELIMITER = ":" AGGREGATOR_REALM_ACCOUNT_DELIMITER = "/" + + def name_with_provider + "#{self.provider.name}: #{self.name}" + end end diff --git a/src/app/views/admin/realm_mappings/new.haml b/src/app/views/admin/realm_mappings/new.haml index 26c364f..0861199 100644 --- a/src/app/views/admin/realm_mappings/new.haml +++ b/src/app/views/admin/realm_mappings/new.haml @@ -4,6 +4,7 @@ = f.hidden_field :frontend_realm_id = f.hidden_field :realm_or_provider_type
- = select_tag 'realm_backend_target[realm_or_provider_id]', options_from_collection_for_select(@backend_targets, 'id', 'name') + - label_method = @realm_target.realm_or_provider_type == 'Realm' ? 'name_with_provider' : 'name' + = select_tag 'realm_backend_target[realm_or_provider_id]', options_from_collection_for_select(@backend_targets, 'id', label_method) %fieldset.clear = f.submit "Save", :class => "submit formbutton"
aeolus-devel@lists.fedorahosted.org