Approval
:ok_woman::no_good:Approval workflow for Rails
Installation
gem 'approval'
Optionally, you can run the generator, which will set up approval models with some useful defaults for you:
$ bin/rails g approval:install
Usage
Prepare
Call acts_as_approval_user
in your resource of user model (User
, AdminUser
, Member
etc):
class User < ApplicationRecord
acts_as_approval_user
end
Call acts_as_approval_resource
in your resource:
class Book < ApplicationRecord
acts_as_approval_resource
end
Request
staff = User.find_or_create_by(email: "[email protected]")
book = 10.times.map { |n| Book.new(name: "my_book_#{n}") }
request = staff.request_for_create(records, reason: "something")
request.save!
You send request, but resources aren't created.
Respond
admin = User.find_or_create_by(email: "[email protected]")
request = Approval::Request.first
respond = admin.approve_request(request, reason: "something")
respond.save!
Then resources are created, if respond user have approved the request.
License
The gem is available as open source under the terms of the MIT License.