Mailinglist Archive: yast-commit (2080 mails)

< Previous Next >
[yast-commit] <rest-service> network : call the real YaPI, update tests
  • From: Jiri Suchomel <jsuchome@xxxxxxx>
  • Date: Thu, 10 Sep 2009 16:07:40 +0200
  • Message-id: <E1Mm10y-0002Uj-TT@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit 61f65df178461f324728e5de041e91936a62d2b3
Author: Jiri Suchomel <jsuchome@xxxxxxx>
Date: Thu Sep 10 16:07:16 2009 +0200

call the real YaPI, update tests
---
.../app/controllers/administrator_controller.rb | 9 ++++++++-
plugins/administrator/app/models/administrator.rb | 20 ++++++++++++++++----
.../administrator/test/unit/administrator_test.rb | 19 ++++++++++---------
3 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/plugins/administrator/app/controllers/administrator_controller.rb
b/plugins/administrator/app/controllers/administrator_controller.rb
index 2542c4c..60b90e0 100644
--- a/plugins/administrator/app/controllers/administrator_controller.rb
+++ b/plugins/administrator/app/controllers/administrator_controller.rb
@@ -4,7 +4,10 @@ class AdministratorController < ApplicationController

# GET action
def show
-# @aliases = Administrator.instance.aliases
+ unless
permission_check("org.opensuse.yast.modules.yapi.administrator.read")
+ render ErrorResult.error(403, 1, "no permission for reading") and return
+ end
+
@admin = Administrator.instance
@aliases = @admin.read_aliases

@@ -17,6 +20,10 @@ class AdministratorController < ApplicationController

# PUT action
def update
+
+ unless
permission_check("org.opensuse.yast.modules.yapi.administrator.write")
+ render ErrorResult.error(403, 1, "no permission for writing") and return
+ end

@admin = Administrator.instance

diff --git a/plugins/administrator/app/models/administrator.rb
b/plugins/administrator/app/models/administrator.rb
index c51bbf5..87186fd 100644
--- a/plugins/administrator/app/models/administrator.rb
+++ b/plugins/administrator/app/models/administrator.rb
@@ -22,13 +22,25 @@ class Administrator
end

def save_password(pw)
- Rails.logger.debug "--------------------- saving password #{pw}--------"
+ parameters = {
+ "password" => ["s", pw ]
+ }
+ yapi_ret = YastService.Call("YaPI::ADMINISTRATOR::Write", parameters)
+ Rails.logger.debug "YaPI returns: '#{yapi_ret}'"
end

def save_aliases(new_aliases)
- # TODO compare new_aliases with aliases
- Rails.logger.debug "--------------------- current aliases
#{aliases.inspect}"
- Rails.logger.debug "--------------------- saving aliases
#{new_aliases.inspect}"
+ if @aliases.sort == new_aliases
+ Rails.logger.debug "mail aliases have not been changed"
+ return
+ end
+ parameters = {
+ "aliases" => ["as", new_aliases]
+ }
+ yapi_ret = YastService.Call("YaPI::ADMINISTRATOR::Write", parameters)
+ Rails.logger.debug "YaPI returns: '#{yapi_ret}'"
+
+ raise yapi_ret unless yapi_ret.empty?
@aliases = new_aliases
end

diff --git a/plugins/administrator/test/unit/administrator_test.rb
b/plugins/administrator/test/unit/administrator_test.rb
index bff12ab..1e8ef08 100644
--- a/plugins/administrator/test/unit/administrator_test.rb
+++ b/plugins/administrator/test/unit/administrator_test.rb
@@ -9,21 +9,22 @@ class AdministratorTest < ActiveSupport::TestCase
end

def test_save_password
+ YastService.stubs(:Call).with('YaPI::ADMINISTRATOR::Write', {"password" =>
["s", "new password"]}).returns("")
ret = @model.save_password("new password")
assert ret
end

-# def test_read_aliases
-# assert @model.aliases.size == 0
-# YastService.stubs(:Call).with('YaPI::ADMINISTRATOR::Read').returns({
"aliases" => [ "a@b" ] })
-# ret = @model.read_aliases
-# assert ret
-# assert @model.aliases.size == 1
-# end
+ def test_read_aliases
+ YastService.stubs(:Call).with('YaPI::ADMINISTRATOR::Read').returns({
"aliases" => [ "a@b" ] })
+ ret = @model.read_aliases
+ assert ret
+ assert @model.aliases.size == 1
+ end

def test_save_aliases
- assert @model.aliases.size == 0
- ret = @model.save_aliases([ "test@xxxxxxxxxx", "a@b" ])
+ new_aliases = [ "test@xxxxxxxxxx", "a@b" ];
+ YastService.stubs(:Call).with('YaPI::ADMINISTRATOR::Write', {"aliases" =>
[ "as", new_aliases ]}).returns("")
+ ret = @model.save_aliases(new_aliases)
assert ret
assert @model.aliases.size == 2
end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages