Plugins - needs_approval

StarAdd to favorites

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)

Installation

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) %>

Advanced Usage

  # 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
    rake db:create
    rake db:migrate
    rake db:fixtures:load
    script/server

Erik Peterson

http://subwindow.com/articles/22

git://github.com/subwindow/needs_approval.git

Rails' (MIT)

  • Currently 0.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Model

Tags

Comments

Add a comment

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?