Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit f8f20bdf12fcc3d141be7cfeb95b7bb974e3ac5c @simcha committed Mar 15, 2011
Showing with 1,926 additions and 0 deletions.
  1. +23 −0 Gemfile
  2. +20 −0 MIT-LICENSE
  3. +26 −0 README.textile
  4. +37 −0 Rakefile
  5. +1 −0 VERSION
  6. +20 −0 app/controllers/definitions_controller.rb
  7. +23 −0 app/controllers/processes_controller.rb
  8. +22 −0 app/controllers/rails_bpm_controller.rb
  9. +32 −0 app/controllers/sessions_controller.rb
  10. +41 −0 app/controllers/task_form_controller.rb
  11. +23 −0 app/controllers/tasks_controller.rb
  12. +2 −0 app/helpers/application_helper.rb
  13. +5 −0 app/helpers/tasks_helper.rb
  14. +98 −0 app/models/user.rb
  15. +75 −0 app/models/workitem.rb
  16. +13 −0 app/processes/my_process.rb
  17. +28 −0 app/views/definitions/index.haml
  18. +21 −0 app/views/definitions/show.haml
  19. +26 −0 app/views/forms/index.haml
  20. +83 −0 app/views/forms/show.haml
  21. +54 −0 app/views/layouts/rails_bpm.haml
  22. +18 −0 app/views/layouts/tasks_base.haml
  23. +25 −0 app/views/processes/index.haml
  24. +15 −0 app/views/sessions/new.haml
  25. +7 −0 app/views/shared/_flash.haml
  26. +11 −0 app/views/tasks/_buttons.haml
  27. +30 −0 app/views/tasks/index.haml
  28. +27 −0 app/views/tasks/show.haml
  29. +97 −0 config/locales/en.yml
  30. +32 −0 config/routes.rb
  31. +2 −0 init.rb
  32. +1 −0 install.rb
  33. +13 −0 lib/generators/rails_bpm/example_generator.rb
  34. +21 −0 lib/generators/rails_bpm/install_generator.rb
  35. +16 −0 lib/generators/templates/app/controllers/tasks/collect_data_controller.rb
  36. +10 −0 lib/generators/templates/app/models/room.rb
  37. +19 −0 lib/generators/templates/app/participants/publish_participant.rb
  38. +17 −0 lib/generators/templates/app/processes/my_process.rb
  39. +7 −0 lib/generators/templates/app/views/tasks/collect_data/show.haml
  40. +3 −0 lib/generators/templates/app/views/tasks/my_task/_title.haml
  41. +13 −0 lib/generators/templates/password
  42. BIN lib/generators/templates/public/images/rails.png
  43. BIN lib/generators/templates/public/images/ruote.png
  44. 0 lib/generators/templates/public/stylesheets/.gitkeep
  45. +145 −0 lib/generators/templates/public/stylesheets/formtastic.css
  46. +14 −0 lib/generators/templates/public/stylesheets/formtastic_changes.css
  47. +336 −0 lib/generators/templates/public/stylesheets/rails_bpm.css
  48. +53 −0 lib/generators/templates/public/stylesheets/reset.css
  49. +40 −0 lib/rack/ruote_admin_only.rb
  50. +30 −0 lib/rails_bpm.rb
  51. +16 −0 lib/rails_bpm/model.rb
  52. +30 −0 lib/rails_bpm/participant.rb
  53. +45 −0 lib/rails_bpm/process.rb
  54. +69 −0 lib/ruote_kit_init.rb
  55. +90 −0 rails_bpm.gemspec
  56. +1 −0 uninstall.rb
23 Gemfile
@@ -0,0 +1,23 @@
+
+source 'http://rubygems.org'
+
+# Rails
+#
+
+gem 'haml'
+
+gem 'formtastic', '1.2.3'
+
+gem 'sinatra', '1.0'
+gem 'sinatra-respond_to', '0.5.0'
+#gem 'sinatra', '1.1.0'
+#gem 'sinatra-respond_to', :git => 'http://github.com/cehoffman/sinatra-respond_to.git'
+
+gem 'yajl-ruby', :require => 'yajl'
+#gem 'ruote-kit', '2.1.11'
+gem 'ruote', :git => 'http://github.com/jmettraux/ruote.git'
+gem 'ruote-kit', :git => 'http://github.com/tosch/ruote-kit.git'
+
+gem 'bcrypt-ruby'
+ # for app/models/user.rb
+
@@ -0,0 +1,20 @@
+Copyright (c) 2011 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
+h1. RailsBpm
+
+Rails BPM is a _proof_of_concept_ of Ruby on Rails plugin/engine for building Business Process Management solutions. It is based on "Route":http://ruote.rubyforge.org/ and "RouteKit":https://github.com/tosch/ruote-kit was created by extending "ruote-on-rails.":https://github.com/tosch/ruote-on-rails
+
+Idea is to put your process into app/processes your tasks into app/controllers/tasks and app/views/tasks and participants into app/participants and let RailsBpm do the rest of the job. For now it is really implemented only to show haw can it be done it is far from complete.
+
+h2. Install
+
+Make new rails application and remove index.html file.
+
+Install the plugin by adding it to Gemfile:
+
+<pre><code>gem 'rails_bpm', :git => 'http://github.com/simcha/rails_bpm.git'
+</pre></code>
+
+And running
+
+<pre><code>bundle install
+
+rails generate rails_bpm:install
+
+rails generate rails_bpm:example
+</pre></code>
+
+
+Copyright (c) 2011 by simcha, released under the MIT license
@@ -0,0 +1,37 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the rails_bpm plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the rails_bpm plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'RailsBpm'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+begin
+ require "jeweler"
+ Jeweler::Tasks.new do |gem|
+ gem.name = "rails_bpm"
+ gem.summary = "Route based BPM Engine for Rails 3"
+ gem.files = Dir["{lib}/**/*", "{app}/**/*", "{config}/**/*"]
+ # other fields that would normally go in your gemspec
+ # like authors, email and has_rdoc can also be included here
+
+ end
+rescue
+ puts "Jeweler or one of its dependencies is not installed."
+end
@@ -0,0 +1 @@
+0.1.0
@@ -0,0 +1,20 @@
+
+#
+# process definitions
+#
+class DefinitionsController < RailsBpmController
+
+ def index
+
+ @definitions = RailsBpm::Process.all
+ end
+
+ def show
+
+ @definition = RailsBpm::Process.find(params[:id])
+ end
+ def launch
+ redirect_to :controller => 'processes', :action => 'create', :definition => params[:id]
+ end
+end
+
@@ -0,0 +1,23 @@
+
+#
+# ruote process instances
+#
+class ProcessesController < RailsBpmController
+
+ def index
+
+ @processes = RuoteKit.engine.processes
+ end
+
+ def create
+
+ definition = RailsBpm::Process.find(params[:definition])
+
+ wfid = RuoteKit.engine.launch(definition.definition)
+
+ flash[:notice] = I18n.t('flash.notice.launched', :wfid => wfid)
+
+ redirect_to :controller => 'definitions', :action => 'index'
+ end
+end
+
@@ -0,0 +1,22 @@
+
+class RailsBpmController < ActionController::Base
+
+ protect_from_forgery
+
+ before_filter :login_required
+
+ layout 'rails_bpm'
+
+ protected # if it makes any sense
+
+ def login_required
+
+ return true if self.class == SessionsController
+ # no login required for the login/logout screens
+
+ return true if session[:username]
+
+ redirect_to :controller => 'sessions', :action => 'new'
+ false
+ end
+end
@@ -0,0 +1,32 @@
+
+#
+# dummy session/login management
+#
+class SessionsController < RailsBpmController
+
+ def new
+
+ # simply letting app/sessions/new.haml get shown
+ end
+
+ def create
+
+ if u = User.authentify(params[:username], params[:password])
+ session[:username] = params[:username]
+ session[:locale] = u.locale
+ redirect_to '/'
+ else
+ flash[:error] = I18n.t('flash.errors.login_failed')
+ render :action => :new
+ end
+ end
+
+ def destroy
+
+ session.delete(:username)
+ # logging out
+
+ render :action => :new
+ end
+end
+
@@ -0,0 +1,41 @@
+class TaskFormController < RailsBpmController
+ helper :tasks
+
+ before_filter :get_process_data, :except => [ :index]
+
+ def update()
+ unless params[:workitem].blank? or params[:workitem][:fields].blank?
+ fields = Rufus::Json.decode(params[:workitem][:fields])
+ @workitem.fields.merge!(fields)
+ end
+ @workitem.fields.merge!(@task_fields)
+
+ if params[:proceed_subaction]
+
+ RuoteKit.storage_participant.reply(@workitem)
+
+ flash[:notice] = I18n.t('flash.notice.proceeded', :fei => @workitem.fei.sid)
+ else
+
+ if params[:release_subaction]
+ @workitem.participant_name = 'anyone'
+ elsif params[:take_subaction]
+ @workitem.participant_name = session[:username]
+ end
+
+ RuoteKit.storage_participant.update(@workitem)
+ end
+
+ redirect_to :controller => :tasks, :action => :index
+ end
+
+ private
+
+ def get_process_data
+ @workitem =
+ RuoteKit.storage_participant[params[:id]]
+ @task_fields = @workitem.fields
+ @route_process_state_tree =
+ Rufus::Json.encode(RuoteKit.engine.process(@workitem.wfid).current_tree)
+ end
+end
@@ -0,0 +1,23 @@
+class TasksController < TaskFormController
+
+ def index
+
+ @workitems = Ruote::Workitem.for_user(session[:username])
+ end
+ def show
+
+ @workitem =
+ RuoteKit.storage_participant[params[:id]]
+ @tree =
+ Rufus::Json.encode(RuoteKit.engine.process(@workitem.wfid).current_tree)
+ end
+ class Base < TaskFormController
+ layout 'tasks_base'
+ helper :tasks
+
+ def index
+ redirect_to :controller => :tasks, :action => :index
+ end
+ end
+
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,5 @@
+module TasksHelper
+ def task_buttons(workitem = @workitem)
+ render :partial => "/tasks/buttons", :locals => {:workitem => workitem}
+ end
+end
@@ -0,0 +1,98 @@
+
+#
+# This is a very simple User model, ready to be torn off and replaced by
+# another mechanism / library, like for example :
+#
+# http://github.com/hassox/warden/
+#
+
+require 'bcrypt'
+
+
+#
+# User information is stored in config/passwd
+#
+# username:locale:pass_bcrypted:groupa,groupb
+#
+class User
+
+ attr_reader :name
+ attr_reader :locale
+ attr_reader :pass
+ attr_reader :groups
+
+ def initialize(name, locale, pass, groups)
+
+ @name = name
+ @locale = locale
+ @pass = pass
+ @groups = groups
+ end
+
+ def in_group?(group_name)
+
+ @groups.include?(group_name)
+ end
+
+ def admin?
+
+ in_group?('admin')
+ end
+
+ def self.admin?(name)
+
+ if u = find(name)
+ u.admin?
+ else
+ false
+ end
+ end
+
+ def self.find(name)
+
+ all.find { |u| u.name == name }
+ end
+
+ def self.authentify(user, pass)
+
+ all.each do |u|
+ next unless u.name == user
+ return u if u.pass == pass
+ end
+
+ nil
+ end
+
+ def self.all
+
+ fn = Rails.root.join('config', "password.#{Rails.env}")
+ fn = File.exist?(fn) ? fn : Rails.root.join(*%w[ config password ])
+
+ lines = File.readlines(fn)
+
+ lines.inject([]) { |a, line|
+
+ line = line.strip
+
+ if line.length > 0 && ( ! line.match(/^#/))
+
+ name, locale, password, groups = line.split(':')
+ password = BCrypt::Password.new(password)
+ groups = (groups || '').split(',')
+
+ a << User.new(name, locale, password, groups)
+ end
+
+ a
+ }
+ end
+
+ # Returns a list of all the known groups (all the groups mentioned in
+ # the passwd file).
+ #
+ def self.groups
+
+ all.collect { |user| user.groups }.flatten.uniq.sort
+ end
+end
+
Oops, something went wrong.

0 comments on commit f8f20bd

Please sign in to comment.