From: Jan Provaznik <jprovazn(a)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((a)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 '#{(a)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 '#{(a)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 #{(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/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"
--
1.7.3.5