ref: refs/heads/use-activeresource
commit e626e9c0d7067597fff094237547a830f4c95aa4
Author: Martin Kudlvasr
Date: Thu Sep 17 17:32:48 2009 +0200
added support for controller paths discovery (using interface name)
works only with resource-restful rest-service branch
---
.../network/app/controllers/network_controller.rb | 12 +++++++-----
plugins/network/app/models/hostname.rb | 1 -
plugins/network/app/models/interface.rb | 3 +++
plugins/network/app/models/interface_resource.rb | 6 ++++++
plugins/network/app/models/yast_resource.rb | 8 +++++++-
5 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/plugins/network/app/controllers/network_controller.rb b/plugins/network/app/controllers/network_controller.rb
index 73fa590..df10e19 100644
--- a/plugins/network/app/controllers/network_controller.rb
+++ b/plugins/network/app/controllers/network_controller.rb
@@ -48,21 +48,23 @@ class NetworkController < ApplicationController
# GET /network
def index
- @ifcs = load_proxy "org.opensuse.yast.modules.yapi.network.interfaces", :all
+ #@ifcs = load_proxy "org.opensuse.yast.modules.yapi.network.interfaces", :all
+ @ifcs = Interface.init_interface_and_find :all
@iface = params[:interface]
unless @iface
ifc = @ifcs.find {|i| i.bootproto!=nil} || @ifcs[0]
@iface = ifc.id
end
- ifc = load_proxy "org.opensuse.yast.modules.yapi.network.interfaces", @iface
+ ifc = Interface.find @iface
+ #ifc = load_proxy "org.opensuse.yast.modules.yapi.network.interfaces", @iface
return false unless ifc
# TODO use rescue_from "AR::Base not found..."
- Hostname.initialize_from_interface
- hn = Hostname.find :one
- RAILS_DEFAULT_LOGGER.debug YastPermission.check_for("martin", "org.opensuse.yast.modules.yapi.network").inspect
+ hn = Hostname.init_interface_and_find :one
+ RAILS_DEFAULT_LOGGER.debug YastPermission.check_for("webyast_guest", "org.opensuse.yast.modules.yapi.network").inspect
RAILS_DEFAULT_LOGGER.debug hn.permissions.inspect
+ return false unless hn
dns = load_proxy "org.opensuse.yast.modules.yapi.network.dns"
return false unless dns
diff --git a/plugins/network/app/models/hostname.rb b/plugins/network/app/models/hostname.rb
index ffa6739..6014689 100644
--- a/plugins/network/app/models/hostname.rb
+++ b/plugins/network/app/models/hostname.rb
@@ -1,4 +1,3 @@
class Hostname < YastResource
- # TODO maybe unnecessary now that find :one is fixed
uses_interface "org.opensuse.yast.modules.yapi.network.hostname"
end
diff --git a/plugins/network/app/models/interface.rb b/plugins/network/app/models/interface.rb
new file mode 100644
index 0000000..904f511
--- /dev/null
+++ b/plugins/network/app/models/interface.rb
@@ -0,0 +1,3 @@
+class Interface < YastResource
+ uses_interface "org.opensuse.yast.modules.yapi.network.interfaces"
+end
diff --git a/plugins/network/app/models/interface_resource.rb b/plugins/network/app/models/interface_resource.rb
new file mode 100644
index 0000000..aa9da72
--- /dev/null
+++ b/plugins/network/app/models/interface_resource.rb
@@ -0,0 +1,6 @@
+# Replacement for YaST::ServiceResource
+# FIXME capitalize properly "YaSTResource"
+
+class InterfaceResource < YastResource
+ self.collection_name = "resources"
+end
diff --git a/plugins/network/app/models/yast_resource.rb b/plugins/network/app/models/yast_resource.rb
index 1b00f9d..f7a80f3 100644
--- a/plugins/network/app/models/yast_resource.rb
+++ b/plugins/network/app/models/yast_resource.rb
@@ -32,11 +32,17 @@ class YastResource < ActiveResource::Base
rescue ActiveResource::ResourceNotFound => e
raise "Cannot find resource for interface #{@interface}"
end
- self.prefix, self.collection_name = resource.controller.rsplit("/",2)
+ self.prefix, self.collection_name = resource.href.rsplit("/",2)
+ self.prefix += "/"
self.has_policy resource.policy
if resource.singular then self.is_singular_resource end
end
+ def self.init_interface_and_find(*args)
+ initialize_from_interface
+ find(*args)
+ end
+
# TODO push this upstream: "else" added
# Find a single resource from a one-off URL
def self.find_one(options)
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org