puavo_organisation 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,34 @@
1
+ Puavo applications need this plugin for configuration of organisations. One Puavo application installation can serve many organisations.
2
+
3
+ *Configuration* *file*: (config/organisations.yml)
4
+
5
+ * host
6
+ * Fully-qualified domain name. This information is used to identify the organisation's (eq. puavo.example.org)
7
+ * ldap_host
8
+ * LDAP server address
9
+ * ldap_base
10
+ * Organisation's LDAP base (eq. dc=edu,dc=example,dc=org)
11
+ * locale
12
+ * Default locale
13
+ * owner
14
+ * Organisation's owner (this is only needed for Cucumber test)
15
+ * owner_pw
16
+ * Organisation's onwer password (this is only needed for Cucumber test)
17
+
18
+ == Copyright
19
+
20
+ Copyright © 2010 Opinsys Oy
21
+
22
+ This program is free software; you can redistribute it and/or modify it
23
+ under the terms of the GNU General Public License as published by the
24
+ Free Software Foundation; either version 2 of the License, or (at your
25
+ option) any later version.
26
+
27
+ This program is distributed in the hope that it will be useful, but
28
+ WITHOUT ANY WARRANTY; without even the implied warranty of
29
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
30
+ Public License for more details.
31
+
32
+ You should have received a copy of the GNU General Public License along
33
+ with this program; if not, write to the Free Software Foundation, Inc.,
34
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the puavo_organisation plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the puavo_organisation plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'PuavoOrganisation'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init.rb"
@@ -0,0 +1,56 @@
1
+ module Puavo
2
+ class Organisation
3
+ @@configurations = YAML.load_file("#{RAILS_ROOT}/config/organisations.yml")
4
+ @@key_by_host = {}
5
+ @@configurations.each do |key, value|
6
+ @@key_by_host[ value["host"] ] = key
7
+ end
8
+
9
+ cattr_accessor :configurations, :key_by_host
10
+ attr_accessor :organisation_key
11
+
12
+ def schools
13
+ School.all
14
+ end
15
+
16
+ def value_by_key(key)
17
+ @@configurations[organisation_key][key]
18
+ end
19
+
20
+ def method_missing(method, *args)
21
+ if @@configurations[organisation_key].has_key?(method.to_s)
22
+ @@configurations[organisation_key][method.to_s]
23
+ else
24
+ super
25
+ end
26
+ end
27
+
28
+ class << self
29
+ def find(key)
30
+ if self.configurations.has_key?(key)
31
+ organisation = Organisation.new
32
+ organisation.organisation_key = key
33
+ organisation
34
+ else
35
+ logger.info "Can not find configuration key: #{key}"
36
+ false
37
+ end
38
+ end
39
+
40
+ def find_by_host(host)
41
+ if @@key_by_host.has_key?(host)
42
+ organisation = Organisation.new
43
+ organisation.organisation_key = @@key_by_host[host]
44
+ organisation
45
+ else
46
+ logger.info "Can not find organisation by host: #{host}"
47
+ false
48
+ end
49
+ end
50
+
51
+ def logger
52
+ RAILS_DEFAULT_LOGGER
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,52 @@
1
+ module PuavoOrganisation
2
+ module Controllers
3
+ module Helpers
4
+ def self.included(controller)
5
+ controller.class_eval do
6
+ before_filter :set_organisation_to_session, :set_locale
7
+ helper_method :theme
8
+ end
9
+ end
10
+ def set_organisation_to_session
11
+ if session[:organisation].nil?
12
+ # Find organisation by request.host.
13
+ # If you don't need multiple organisations you have to only set default organisation
14
+ # with: config/organisations.yml
15
+ # default
16
+ # name: Default organisation
17
+ # host: *
18
+ session[:organisation] = Puavo::Organisation.find_by_host(request.host)
19
+ # Find default organisation (host == "*") if request host not found from configurations.
20
+ session[:organisation] = Puavo::Organisation.find_by_host("*") unless session[:organisation]
21
+ unless session[:organisation]
22
+ # FATAL error
23
+ # FIXME: redirect to login page?
24
+ # FIXME: text localization
25
+ render :text => "Can't find organisation."
26
+ return false
27
+ end
28
+ else
29
+ # Compare session host to client host. This is important security check.
30
+ unless session[:organisation].host == request.host || session[:organisation].host == "*"
31
+ # This is a serious problem. Some one trying to hack this system.
32
+ # FIXME, redirect to login page?
33
+ # FIXME: text localization
34
+ logger.info "Default organisation not found!"
35
+ render :text => "Session error"
36
+ return false
37
+ end
38
+ end
39
+ end
40
+
41
+ def set_locale
42
+ I18n.locale = session[:organisation].value_by_key('locale') ?
43
+ session[:organisation].value_by_key('locale') : :en
44
+ end
45
+
46
+ def theme
47
+ # session[:theme] ? session[:theme] : "tea"
48
+ "gray"
49
+ end
50
+ end
51
+ end
52
+ end
File without changes
data/rails/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'puavo/organisation'
2
+ require 'puavo_organisation/controllers/helpers'
3
+
4
+ ActionController::Base.send :include, PuavoOrganisation::Controllers::Helpers
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puavo_organisation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jouni Korhonen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-09-06 00:00:00 +03:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Organisation configuration plugin for Puavo applications
17
+ email: puavo@opinsys.fi
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - Rakefile
26
+ - init.rb
27
+ - README.rdoc
28
+ - lib/puavo_organisation.rb
29
+ - lib/puavo/organisation.rb
30
+ - lib/puavo_organisation/controllers/helpers.rb
31
+ - rails/init.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/opinsys/puavo_organisation
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.3.5
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Organisation configuration plugin for Puavo applications
60
+ test_files: []
61
+