public
Description: A Rails plugin for managing approval flows
Homepage: http://subwindow.com
Clone URL: git://github.com/subwindow/needs_approval.git
needs_approval / README
100644 66 lines (51 sloc) 3.027 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Needs Approval Plugin
================
 
This is a pretty simple plugin designed to help you manage approval flows. If you have records that need to be approved by users, this plugin might help you out. It also has the following features:
  -Ladder-based approvals (where one user can only approve after the users listed previous to him have approved as well)
  -Approval requirement conditions (where a user only needs to approve on certain conditions)
  -Optional, built-in authentication (where a user must enter in their password whenever they approve something- often required by 21 CFR Part 11 and ISO 9001)
 
Install using the command
  script/plugin install git://github.com/subwindow/needs_approval.git
 
Generate a scaffolded approval model/controller using the command
  script/generate approval APPROVALMODEL USERMODEL [--include-authentication] [--skip-migration]
Example
  script/generate approval approval user
  
Put the approval structure definition in your desired models
  class Order < ActiveRecord::Base
    needs_approval do
      of User.find_by_login("boss")
      of User.find_by_login("bigboss") if total_price > 1000
    end
  end
  
For ladder-based approvals, use the following. The function next_approvers goes in order of approval definition.
  needs_approval(:ladder => true)
 
Include approval information in the show page of an approved object
  <%= approvals_for(@order) %>
 
Other useful functions:
  # Boolean, returns true if all approvals have been satisfied
  @order.has_all_approvals?
 
  # Returns an array of all users that are required to approve this object
  @order.approvals_needed
 
  # Returns an array of users that have approved this object
  @order.approvals
 
  # Returns an array of users that need to approve this object, but have not yet
  @order.failed_approvals
 
  # Boolean, returns true if this object requires and does not yet have the approval of this user
  @order.needs_approval_of(user)
 
  # Boolean, returns true if this user has approved this object
  @order.passes_approval(user)
 
  # Returns an array of users that are set to approve this next (for ladder-based approvals)
  @order.next_approvers # Useful for email notifications!
  
Note
  This plugin kind of depends on restful_authentication or something similar. A "current_user" method must be accessible which returns the currently logged in user.
  If the current_user function is named differently, either:
    define an alias, or
    change the references in the approvals controller and pass in the current user as a second argument to the approvals_for helper [eg: "approvals_for(@order, active_user)"]
 
An example app is located in the directory example_app. You can delete this if you don't want it (especially if you use TextMate-style "Go To File").
  To run, execute the following commands:
    cd vendor/plugins/needs_approval/example_app
    script/plugin install git://github.com/subwindow/needs_approval.git
    rake db:create
    rake db:migrate
    rake db:fixtures:load
    script/server