From: Jan Provaznik <jprovazn(a)redhat.com>
---
src/app/controllers/admin/realms_controller.rb | 77 +++++++++++++++++++-
.../controllers/resources/instances_controller.rb | 2 +-
src/app/views/admin/realms/_form.haml | 17 +++++
src/app/views/admin/realms/_list.haml | 21 ++++++
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/config/routes.rb | 3 +-
9 files changed, 129 insertions(+), 4 deletions(-)
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/_properties.haml
create mode 100644 src/app/views/admin/realms/edit.haml
create mode 100644 src/app/views/admin/realms/new.haml
diff --git a/src/app/controllers/admin/realms_controller.rb
b/src/app/controllers/admin/realms_controller.rb
index 5379f25..13ccb8b 100644
--- a/src/app/controllers/admin/realms_controller.rb
+++ b/src/app/controllers/admin/realms_controller.rb
@@ -1,6 +1,81 @@
class Admin::RealmsController < ApplicationController
before_filter :require_user
+ before_filter :load_realms, :only =>[:index,:show]
- def index
+ # TODO: add permissions checks
+
+ def new
+ @realm = FrontendRealm.new
+ load_backend_realms
+ end
+
+ def edit
+ @realm = FrontendRealm.find(params[:id])
+ load_backend_realms
+ end
+
+ def update
+ @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
+ @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
+ FrontendRealm.destroy(params[:id])
+ redirect_to admin_realms_path
+ end
+
+ def show
+ @realm = FrontendRealm.find(params[:id])
+
+ @url_params = params.clone
+ @tab_captions = ['Properties']
+ @details_tab = params[:details_tab].blank? ? 'properties' :
params[:details_tab]
+ 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 :partial => @details_tab }
+ 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::PROVIDER_VIEW)
+ end
+
+ def load_realms
+ @header = [{ :name => "Name", :sort_attr => :name},
+ { :name => "Mapped to", :sortable => false},
+ ]
+ @realms = FrontendRealm.all
+ @url_params = params.clone
end
end
diff --git a/src/app/controllers/resources/instances_controller.rb
b/src/app/controllers/resources/instances_controller.rb
index 3bd0c45..43d9faa 100644
--- a/src/app/controllers/resources/instances_controller.rb
+++ b/src/app/controllers/resources/instances_controller.rb
@@ -125,7 +125,7 @@ class Resources::InstancesController < ApplicationController
def init_new_instance_attrs
@pools = Pool.list_for_user(@current_user, Privilege::INSTANCE_MODIFY)
- @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/realms/_form.haml
b/src/app/views/admin/realms/_form.haml
new file mode 100644
index 0000000..779f3af
--- /dev/null
+++ b/src/app/views/admin/realms/_form.haml
@@ -0,0 +1,17 @@
+= 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"
+ %p
+ Map to:
+ = form.radio_button :backend_realm_type, 'Provider'
+ = label_tag :frontend_realm_backend_realm_type_provider, 'Provider'
+ = select_tag 'frontend_realm[backend_realm_id]',
options_from_collection_for_select(@providers, 'id', 'name')
+ /= form.select :backend_realm_id, @backend_realms.map {|r| r.name}, {:include_blank
=> true}
+
+
+ = form.radio_button :backend_realm_type, 'Realm'
+ = label_tag :frontend_realm_backend_realm_type_realm, 'Realm'
+ = select_tag 'frontend_realm[backend_realm_id]',
options_from_collection_for_select(@backend_realms, 'id', 'name')
+%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..9a99351
--- /dev/null
+++ b/src/app/views/admin/realms/_list.haml
@@ -0,0 +1,21 @@
+- 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)
+ %td
+ = "#{realm.backend_realm.name} (#{realm.backend_realm_type})"
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 #{(a)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: #{(a)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/config/routes.rb b/src/config/routes.rb
index ad9fb67..eff5a7b 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -48,13 +48,14 @@ ActionController::Routing::Routes.draw do |map|
map.connect '/set_layout', :controller => 'application', :action
=> 'set_layout'
map.namespace 'admin' do |r|
- r.resources :hardware_profiles, :realms
+ r.resources :hardware_profiles
r.resources :providers, :collection => { :multi_destroy => :delete }
r.resources :users, :collection => { :multi_destroy => :delete }
r.resources :provider_accounts, :collection => { :multi_destroy => :delete }
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 }
end
map.resources :pools
--
1.7.3.4