Jiri Suchomel wrote:
ref: refs/heads/master commit 61f65df178461f324728e5de041e91936a62d2b3 Author: Jiri Suchomel <jsuchome@suse.cz> 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 +
Hi, new error reporting uses exceptions os for check if permission is set use just permission_check("org.opensuse.yast.modules.yapi.administrator.read") and because I create for yapi shortcut you can use just yapi_perm_check "administrator.read"
@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@domain.com", "a@b" ]) + new_aliases = [ "test@domain.com", "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
-- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, webyast modules language and time -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org