ref: refs/heads/master
commit b5ae0fca0ca695183c17bc34fb7c69b512bef856
Author: Martin Vidner
Date: Fri Aug 14 13:21:20 2009 +0200
Revert "use put method instead of post, return hash with result"
This reverts commit b6bec4d875998b19adffc984ba4dd0e147239cc7.
---
.../app/controllers/services_controller.rb | 16 ++++++++++------
plugins/services/app/models/service.rb | 10 +++++++---
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/plugins/services/app/controllers/services_controller.rb b/plugins/services/app/controllers/services_controller.rb
index 05a6493..e10ba20 100644
--- a/plugins/services/app/controllers/services_controller.rb
+++ b/plugins/services/app/controllers/services_controller.rb
@@ -26,29 +26,33 @@ class ServicesController < ApplicationController
logger.debug "show@service #{@service.inspect}"
end
- # PUT /services/1.xml
- def update
+ # Change the service status. Requires write permissions for services YaPI.
+ # POST /services
+ def create
unless permission_check( "org.opensuse.yast.modules.yapi.services.execute")
render ErrorResult.error(403, 1, "no permission") and return
end
+ services = params[:services]
+ id = services[:name]
begin
- @service = Service.find params[:id]
+ @service = Service.find id
rescue Exception => e
logger.debug e
render ErrorResult.error(404, 106, "no such service") and return
end
- ret = {}
+ @service.execute = services[:execute]
+
begin
- ret = @service.save(params[:execute])
+ @service.save
rescue Exception => e
logger.debug e
render ErrorResult.error(404, @error_id, @error_string) and return
end
- render :xml => ret
+ render :show
end
end
diff --git a/plugins/services/app/models/service.rb b/plugins/services/app/models/service.rb
index 510e543..4a75584 100644
--- a/plugins/services/app/models/service.rb
+++ b/plugins/services/app/models/service.rb
@@ -4,6 +4,7 @@ class Service
attr_accessor :name
attr_accessor :status
+ attr_accessor :execute
def initialize
end
@@ -43,13 +44,15 @@ class Service
end
- def save(cmd)
- ret = YastService.Call("YaPI::SERVICES::Execute", self.name, cmd)
+ def save
+ ret = YastService.Call("YaPI::SERVICES::Execute", self.name, self.execute)
Rails.logger.debug "Command returns: #{ret.inspect}"
- ret
+ raise ret["stdout"] + ret["stderr"] if ret["exit"] != "0"
+ true
end
+
def to_xml( options = {} )
xml = options[:builder] ||= Builder::XmlMarkup.new(options)
xml.instruct! unless options[:skip_instruct]
@@ -57,6 +60,7 @@ class Service
xml.service do
xml.tag!(:name, name )
xml.tag!(:status, status, {:type => "integer"} )
+ xml.tag!(:execute, execute )
end
end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org