ref: refs/heads/use-activeresource
commit da1b8e73c81a1b7f5c9abadc17fd96a7306df18d
Author: Jiri Suchomel
Date: Fri Sep 11 15:52:49 2009 +0200
first version of web-client for administrator
---
plugins/administrator/.gitignore | 2 +
plugins/administrator/README | 7 ++
plugins/administrator/Rakefile | 10 +++
.../app/controllers/administrator_controller.rb | 47 ++++++++++++
.../app/views/administrator/index.html.erb | 26 +++++++
plugins/administrator/config/rails_parent.rb | 15 ++++
plugins/administrator/doc/README_FOR_APP | 7 ++
plugins/administrator/init.rb | 2 +
plugins/administrator/install.rb | 1 +
.../package/yast2-webclient-administrator.changes | 5 ++
.../package/yast2-webclient-administrator.spec | 76 ++++++++++++++++++++
plugins/administrator/shortcuts.yml | 8 ++
plugins/administrator/tasks/systemtime_tasks.rake | 6 ++
.../functional/administrator_controller_test.rb | 41 +++++++++++
plugins/administrator/test/test_helper.rb | 55 ++++++++++++++
plugins/administrator/uninstall.rb | 1 +
16 files changed, 309 insertions(+), 0 deletions(-)
diff --git a/plugins/administrator/.gitignore b/plugins/administrator/.gitignore
new file mode 100644
index 0000000..09a651e
--- /dev/null
+++ b/plugins/administrator/.gitignore
@@ -0,0 +1,2 @@
+package/www
+package/www.tar.bz2
diff --git a/plugins/administrator/README b/plugins/administrator/README
new file mode 100644
index 0000000..1e5014f
--- /dev/null
+++ b/plugins/administrator/README
@@ -0,0 +1,7 @@
+Administrator
+=============
+
+Plugin for configurating system administrator's attributes: password and mail forwarders.
+
+
+Copyright (c) 2009 Novell, released under the GPL2 license
diff --git a/plugins/administrator/Rakefile b/plugins/administrator/Rakefile
new file mode 100644
index 0000000..ca63e76
--- /dev/null
+++ b/plugins/administrator/Rakefile
@@ -0,0 +1,10 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+require File.join(File.dirname(__FILE__), 'config', 'rails_parent')
+require File.join(RailsParent.parent, 'config', 'boot')
+require 'tasks/rails'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
diff --git a/plugins/administrator/app/controllers/administrator_controller.rb b/plugins/administrator/app/controllers/administrator_controller.rb
new file mode 100644
index 0000000..5d6ad7c
--- /dev/null
+++ b/plugins/administrator/app/controllers/administrator_controller.rb
@@ -0,0 +1,47 @@
+require 'yast/service_resource'
+
+class AdministratorController < ApplicationController
+ before_filter :login_required
+
+ private
+
+ def client_permissions
+ @client = YaST::ServiceResource.proxy_for('org.opensuse.yast.modules.yapi.administrator')
+ unless @client
+ flash[:notice] = _("Invalid session, please login again.")
+ redirect_to( logout_path ) and return
+ end
+ @permissions = @client.permissions rescue {}
+ end
+
+ # Initialize GetText and Content-Type.
+ init_gettext "yast_webclient_administrator" # textdomain, options(:charset, :content_type)
+
+ public
+
+ def index
+ return unless client_permissions
+ @administrator = @client.find
+ end
+
+ # PUT
+ def update
+ return unless client_permissions
+
+ @administrator = @client.find
+
+ admin = params["administrator"]
+ @administrator.password = admin["password"]
+ @administrator.aliases = admin["aliases"]
+ begin
+ response = @administrator.save
+ rescue ActiveResource::ClientError => e
+ flash[:error] = YaST::ServiceResource.error(e)
+ end
+
+ redirect_to :action => "index"
+ end
+
+end
+
+# vim: ft=ruby
diff --git a/plugins/administrator/app/views/administrator/index.html.erb b/plugins/administrator/app/views/administrator/index.html.erb
new file mode 100644
index 0000000..fdac4da
--- /dev/null
+++ b/plugins/administrator/app/views/administrator/index.html.erb
@@ -0,0 +1,26 @@
+<div class='plugin-icon'><img src='/icons/yast-users.png'/></div>
+
+<h2><%=_("Administrator Settings")%></h2>
+
+<% disabled = ! @permissions[:write] %>
+
+<% form_for(:administrator, @administrator, :url => { :action => "update" }, :html => { :method => :put } ) do |f| %>
+ <%= f.error_messages %>
+ <div class="table">
+ <table class="list" cellpadding="0" cellspacing="0">
+ <tr class="bg">
+ <td class="first"><strong><%=_("Password")%></strong></td>
+ <td class="last"><%= f.password_field :password, :disabled => disabled %></td>
+ </tr>
+ <tr class="bg">
+ <td class="first"><strong><%=_("Forward mail to")%></strong></td>
+ <td class="last"><%= f.text_field :aliases, :disabled => disabled %></td>
+ </tr>
+ </table>
+ <p>
+ <%= f.submit _("Save"), :disabled => disabled %>
+ <%= link_to _('Back'), {:action => :index}, :onclick=>"Element.show('progress')", :class => "button"%>
+ </p>
+ </div>
+<% end %>
+
diff --git a/plugins/administrator/config/rails_parent.rb b/plugins/administrator/config/rails_parent.rb
new file mode 100644
index 0000000..c7bd94f
--- /dev/null
+++ b/plugins/administrator/config/rails_parent.rb
@@ -0,0 +1,15 @@
+class RailsParent
+
+ def RailsParent.parent
+ parent = ENV["RAILS_PARENT"]
+ unless parent
+ parent = File.expand_path(File.join('..','..','..', 'webclient'), File.dirname(__FILE__))
+ unless File.directory?( parent || "" )
+ $stderr.puts "Nope: #{parent}\nPlease set RAILS_PARENT environment"
+ exit 1
+ end
+ end
+ parent
+ end
+
+end
diff --git a/plugins/administrator/doc/README_FOR_APP b/plugins/administrator/doc/README_FOR_APP
new file mode 100644
index 0000000..1e5014f
--- /dev/null
+++ b/plugins/administrator/doc/README_FOR_APP
@@ -0,0 +1,7 @@
+Administrator
+=============
+
+Plugin for configurating system administrator's attributes: password and mail forwarders.
+
+
+Copyright (c) 2009 Novell, released under the GPL2 license
diff --git a/plugins/administrator/init.rb b/plugins/administrator/init.rb
new file mode 100644
index 0000000..2877209
--- /dev/null
+++ b/plugins/administrator/init.rb
@@ -0,0 +1,2 @@
+# Include hook code here
+
diff --git a/plugins/administrator/install.rb b/plugins/administrator/install.rb
new file mode 100644
index 0000000..f7732d3
--- /dev/null
+++ b/plugins/administrator/install.rb
@@ -0,0 +1 @@
+# Install hook code here
diff --git a/plugins/administrator/package/yast2-webclient-administrator.changes b/plugins/administrator/package/yast2-webclient-administrator.changes
new file mode 100644
index 0000000..71b5d4c
--- /dev/null
+++ b/plugins/administrator/package/yast2-webclient-administrator.changes
@@ -0,0 +1,5 @@
+-------------------------------------------------------------------
+Thu Sep 10 16:13:12 CEST 2009 - jsuchome@suse.cz
+
+- initial version
+
diff --git a/plugins/administrator/package/yast2-webclient-administrator.spec b/plugins/administrator/package/yast2-webclient-administrator.spec
new file mode 100644
index 0000000..9668a8e
--- /dev/null
+++ b/plugins/administrator/package/yast2-webclient-administrator.spec
@@ -0,0 +1,76 @@
+#
+# spec file for package yast2-webclient-asministrator
+#
+# Copyright (c) 2008 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# This file and all modifications and additions to the pristine
+# package are under the same license as the package itself.
+#
+# Please submit bugfixes or comments via http://bugs.opensuse.org/
+#
+
+
+Name: yast2-webclient-administrator
+PreReq: yast2-webclient >= 0.0.2
+License: GPL
+Group: Productivity/Networking/Web/Utilities
+Autoreqprov: on
+Version: 0.0.1
+Release: 0
+Summary: YaST2 - Webclient - Administrator
+Source: www.tar.bz2
+BuildRoot: %{_tmppath}/%{name}-%{version}-build
+BuildArch: noarch
+BuildRequires: ruby
+BuildRequires: yast2-webclient
+
+#
+%define pkg_user yast
+%define plugin_name administrator
+#
+
+
+%description
+YaST2 - Webclient - UI for YaST-webservice for for administrator's attributes
+Authors:
+--------
+ Jiri Suchomel
+
+%prep
+%setup -q -n www
+
+%build
+export RAILS_PARENT=/srv/www/yast
+rake makemo
+
+%install
+
+#
+# Install all web and frontend parts.
+#
+mkdir -p $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+cp -a * $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(-,root,root)
+%dir /srv/www/%{pkg_user}
+%dir /srv/www/%{pkg_user}/vendor
+%dir /srv/www/%{pkg_user}/vendor/plugins
+%dir /srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+%dir /srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/config
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/README
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/Rakefile
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/init.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/install.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/uninstall.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/app
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/tasks
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/locale
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/po
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/config/rails_parent.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/doc/README_FOR_APP
+
+%changelog
diff --git a/plugins/administrator/shortcuts.yml b/plugins/administrator/shortcuts.yml
new file mode 100644
index 0000000..38b2e60
--- /dev/null
+++ b/plugins/administrator/shortcuts.yml
@@ -0,0 +1,8 @@
+main:
+ icon: '/icons/yast-users.png'
+ url: /administrator
+ groups: [ Security ]
+ tags: [ users, administrator, security]
+ title: Administrator Settings
+ description: Manage system administrator
+
diff --git a/plugins/administrator/tasks/systemtime_tasks.rake b/plugins/administrator/tasks/systemtime_tasks.rake
new file mode 100644
index 0000000..1568c54
--- /dev/null
+++ b/plugins/administrator/tasks/systemtime_tasks.rake
@@ -0,0 +1,6 @@
+begin
+ require 'tasks/webservice'
+rescue LoadError => e
+ $stderr.puts "Install rubygem-yast2-webservice-tasks.rpm"
+end
+
diff --git a/plugins/administrator/test/functional/administrator_controller_test.rb b/plugins/administrator/test/functional/administrator_controller_test.rb
new file mode 100644
index 0000000..b55e288
--- /dev/null
+++ b/plugins/administrator/test/functional/administrator_controller_test.rb
@@ -0,0 +1,41 @@
+require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
+require 'test/unit'
+require File.expand_path( File.join("test","validation_assert"), RailsParent.parent )
+require 'rubygems'
+
+class AdministratorControllerTest < ActionController::TestCase
+
+ class Proxy
+ attr_accessor :result, :permissions, :timeout
+ def find
+ return result
+ end
+ end
+
+ class Result
+
+ def fill
+ end
+
+ def save
+ return true
+ end
+ end
+
+ def setup
+ @request = ActionController::TestRequest.new
+
+ @result = Result.new
+ @result.fill
+
+ @proxy = Proxy.new
+ @proxy.permissions = { :read => true, :write => true }
+ @proxy.result = @result
+
+ YaST::ServiceResource.stubs(:proxy_for).with('org.opensuse.yast.modules.yapi.administrator').returns(@proxy)
+
+ @controller = AdministratorController.new
+ AdministratorController.any_instance.stubs(:login_required)
+ end
+
+end
diff --git a/plugins/administrator/test/test_helper.rb b/plugins/administrator/test/test_helper.rb
new file mode 100644
index 0000000..d8863e1
--- /dev/null
+++ b/plugins/administrator/test/test_helper.rb
@@ -0,0 +1,55 @@
+# find the rails parent
+require File.join(File.dirname(__FILE__), '..', 'config', 'rails_parent')
+
+ENV["RAILS_ENV"] = "test"
+require File.expand_path( File.join("config","environment"), RailsParent.parent )
+require 'test_help'
+
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'
+
+class ActiveSupport::TestCase
+ # Transactional fixtures accelerate your tests by wrapping each test method
+ # in a transaction that's rolled back on completion. This ensures that the
+ # test database remains unchanged so your fixtures don't have to be reloaded
+ # between every test method. Fewer database queries means faster tests.
+ #
+ # Read Mike Clark's excellent walkthrough at
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
+ #
+ # Every Active Record database supports transactions except MyISAM tables
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
+ # is recommended.
+ #
+ # The only drawback to using transactional fixtures is when you actually
+ # need to test transactions. Since your test is bracketed by a transaction,
+ # any transactions started in your code will be automatically rolled back.
+ self.use_transactional_fixtures = true
+
+ # Instantiated fixtures are slow, but give you @david where otherwise you
+ # would need people(:david). If you don't want to migrate your existing
+ # test cases which use the @david style and don't mind the speed hit (each
+ # instantiated fixtures translates to a database query per test method),
+ # then set this back to true.
+ self.use_instantiated_fixtures = false
+
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
+ #
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
+ # -- they do not yet inherit this setting
+ fixtures :all
+
+ # Add more helper methods to be used by all tests here...
+
+ # See http://pennysmalls.com/2009/03/04/rails-23-breakage-and-fixage/
+ def clean_backtrace(&block)
+ yield
+ rescue ActiveSupport::TestCase::Assertion => error
+ framework_path = Regexp.new(File.expand_path("#{File.dirname(__FILE__)}/assertions"))
+ error.backtrace.reject! { |line| File.expand_path(line) =~ framework_path }
+ raise
+ end
+
+end
diff --git a/plugins/administrator/uninstall.rb b/plugins/administrator/uninstall.rb
new file mode 100644
index 0000000..9738333
--- /dev/null
+++ b/plugins/administrator/uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org