stonepath 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/stonepath/acl/controller.rb +6 -4
- data/lib/stonepath/acl/role.rb +11 -0
- data/lib/stonepath/task.rb +47 -46
- data/lib/stonepath/work_bench.rb +4 -2
- data/lib/stonepath/work_item.rb +6 -5
- data/lib/stonepath/work_owner.rb +2 -2
- data/lib/stonepath.rb +4 -2
- data/stonepath.gemspec +8 -2
- data/test/app_root/app/models/assignment.rb +0 -1
- data/test/app_root/app/models/case.rb +1 -1
- data/test/app_root/app/models/custom_assignment.rb +22 -0
- data/test/app_root/config/environment.rb +3 -0
- data/test/app_root/db/migrate/02_create_assignments.rb +3 -0
- data/test/app_root/db/migrate/03_create_cases.rb +1 -0
- data/test/custom_task_test.rb +27 -0
- data/test/task_test.rb +43 -0
- metadata +8 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -24,7 +24,7 @@ module StonePath
|
|
24
24
|
unchecked_method = unchecked_method_name(method)
|
25
25
|
|
26
26
|
guarded_class.send(:define_method, checked_method) do |*args|
|
27
|
-
if acl.allowed?(
|
27
|
+
if acl.allowed?(self, current_user, method)
|
28
28
|
self.send(unchecked_method, *args)
|
29
29
|
elsif StonePath::Config.acl_failure_mode == :exception
|
30
30
|
raise "Access Violation"
|
@@ -53,9 +53,11 @@ module StonePath
|
|
53
53
|
yield @states[state_name]
|
54
54
|
end
|
55
55
|
|
56
|
-
def allowed?(
|
57
|
-
|
58
|
-
|
56
|
+
def allowed?(guarded_object, user, method)
|
57
|
+
return true if (guarded_object.nil? || user.nil? || method.nil?)
|
58
|
+
state = guarded_object.aasm_state
|
59
|
+
roles = user.respond_to?(:roles) ? user.roles : [user.role]
|
60
|
+
roles.each { |role| break [true] if states[state].roles[role].allowed?(guarded_object, method) }.uniq[0]
|
59
61
|
end
|
60
62
|
|
61
63
|
private
|
data/lib/stonepath/acl/role.rb
CHANGED
@@ -15,6 +15,17 @@ module StonePath
|
|
15
15
|
@checked_methods = Hash.new
|
16
16
|
end
|
17
17
|
|
18
|
+
def allowed?(guarded_object, method_name)
|
19
|
+
#first, we check to see if it is a checked method. If it is, we return whatever the check method says
|
20
|
+
guard = checked_methods[method_name.to_s]
|
21
|
+
|
22
|
+
return guard.call(guarded_object) if guard
|
23
|
+
|
24
|
+
default_answer = !(Config.acl_default_access == :deny)
|
25
|
+
checklist = default_answer ? denied_methods : allowed_methods
|
26
|
+
checklist.include?(method_name.to_s) ? !default_answer : default_answer
|
27
|
+
end
|
28
|
+
|
18
29
|
def parent_acl
|
19
30
|
@parent_state.parent_acl
|
20
31
|
end
|
data/lib/stonepath/task.rb
CHANGED
@@ -1,38 +1,14 @@
|
|
1
1
|
module StonePath
|
2
2
|
module SPTask
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def assigns_to(workbench)
|
7
|
-
belongs_to :assignee, :class_name => workbench.to_s.classify
|
8
|
-
end
|
9
|
-
|
10
|
-
def task_for(workitem)
|
11
|
-
#belongs_to :workitem, :polymorphic => true
|
12
|
-
belongs_to :workitem, :class_name => workitem.to_s.classify
|
13
|
-
end
|
14
|
-
|
15
|
-
def audits_transitions
|
16
|
-
puts "#{self.class} audits transitions"
|
17
|
-
end
|
18
|
-
|
19
|
-
include AASM
|
20
|
-
|
21
|
-
#we must be attached to a workitem.
|
22
|
-
validates_presence_of :workitem
|
23
|
-
|
24
|
-
# We can have unassigned tasks.
|
25
|
-
#validates_presence_of :assignee
|
26
|
-
|
3
|
+
|
4
|
+
def self.default_config_block
|
5
|
+
lambda {
|
27
6
|
aasm_initial_state :active
|
28
|
-
|
29
|
-
|
30
7
|
aasm_state :active, :after_enter => :notify_created
|
31
8
|
aasm_state :completed, :before_enter => :timestamp_complete, :after_enter => :notify_closed
|
32
9
|
aasm_state :expired, :after_enter => :notify_closed
|
33
10
|
aasm_state :cancelled, :after_enter => :notify_closed
|
34
11
|
|
35
|
-
|
36
12
|
aasm_event :complete do
|
37
13
|
transitions :to => :completed, :from => :active
|
38
14
|
end
|
@@ -45,32 +21,57 @@ module StonePath
|
|
45
21
|
transitions :to => :expired, :from => :active
|
46
22
|
end
|
47
23
|
|
48
|
-
named_scope :unassigned,
|
49
|
-
named_scope :
|
24
|
+
named_scope :unassigned, { :conditions => ['assignee_id IS NULL'] }
|
25
|
+
named_scope :assigned, { :conditions => ['assignee_id IS NOT NULL'] }
|
26
|
+
named_scope :active, { :conditions => ['aasm_state in (?)', ['active']] }
|
27
|
+
named_scope :completed, { :conditions => ['aasm_state in (?)', ['completed']] }
|
28
|
+
named_scope :expired, { :conditions => ['aasm_state in (?)', ['expired']] }
|
29
|
+
named_scope :cancelled, { :conditions => ['aasm_state in (?)', ['cancelled']] }
|
50
30
|
named_scope :overdue, lambda { { :conditions => ['aasm_state in (?) AND due_at < ?', ['active'], Time.now] } }
|
51
|
-
|
52
|
-
|
53
|
-
end
|
31
|
+
}
|
54
32
|
end
|
55
33
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
34
|
+
def self.included(base)
|
35
|
+
base.instance_eval do
|
36
|
+
|
37
|
+
belongs_to :assignee, :polymorphic => true
|
61
38
|
|
62
|
-
def
|
63
|
-
|
64
|
-
|
65
|
-
end
|
39
|
+
def task_for(workitem, options={})
|
40
|
+
options.merge!(:class_name => workitem.to_s.classify)
|
41
|
+
belongs_to :workitem, options
|
66
42
|
end
|
67
|
-
|
68
|
-
def
|
69
|
-
|
70
|
-
workitem.task_closed(self)
|
71
|
-
end
|
43
|
+
|
44
|
+
def audits_transitions
|
45
|
+
puts "#{self.class} audits transitions"
|
72
46
|
end
|
47
|
+
|
48
|
+
include AASM
|
73
49
|
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def overdue?
|
54
|
+
return false if due_at.nil?
|
55
|
+
due_at < Time.now
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def timestamp_complete
|
61
|
+
self.completed_at = Time.now
|
62
|
+
end
|
63
|
+
|
64
|
+
def notify_created
|
65
|
+
if workitem.respond_to?(:task_created)
|
66
|
+
workitem.task_created(self)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def notify_closed
|
71
|
+
if workitem.respond_to?(:task_closed)
|
72
|
+
workitem.task_closed(self)
|
73
|
+
end
|
74
|
+
end
|
74
75
|
|
75
76
|
end
|
76
77
|
end
|
data/lib/stonepath/work_bench.rb
CHANGED
@@ -2,8 +2,10 @@ module StonePath
|
|
2
2
|
module WorkBench
|
3
3
|
def self.included(base)
|
4
4
|
base.instance_eval do
|
5
|
-
def workbench_for(tasks)
|
6
|
-
|
5
|
+
def workbench_for(tasks, options={})
|
6
|
+
#options.merge!(:foreign_key => :assignee_id)
|
7
|
+
#puts options
|
8
|
+
has_many tasks, :as => :assignee
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
data/lib/stonepath/work_item.rb
CHANGED
@@ -4,12 +4,13 @@ module StonePath
|
|
4
4
|
base.instance_eval do
|
5
5
|
include AASM
|
6
6
|
|
7
|
-
def owned_by(owner)
|
8
|
-
|
7
|
+
def owned_by(owner, options={})
|
8
|
+
options.merge!(:class_name => owner.to_s.classify)
|
9
|
+
belongs_to :owner, options
|
9
10
|
end
|
10
11
|
|
11
|
-
def subject_of(tasks)
|
12
|
-
has_many tasks
|
12
|
+
def subject_of(tasks, options={})
|
13
|
+
has_many tasks, options
|
13
14
|
end
|
14
15
|
|
15
16
|
def stonepath_acl()
|
@@ -24,7 +25,7 @@ module StonePath
|
|
24
25
|
|
25
26
|
def self.define_attribute_methods_with_hook
|
26
27
|
define_attribute_methods_without_hook
|
27
|
-
acl.fix_aliases
|
28
|
+
acl.fix_aliases if defined? self.acl
|
28
29
|
end
|
29
30
|
|
30
31
|
class << self
|
data/lib/stonepath/work_owner.rb
CHANGED
data/lib/stonepath.rb
CHANGED
@@ -12,9 +12,11 @@ module StonePath
|
|
12
12
|
include StonePath::WorkItem
|
13
13
|
end
|
14
14
|
|
15
|
-
def stonepath_task
|
15
|
+
def stonepath_task(&config_block)
|
16
16
|
require File.expand_path(File.dirname(__FILE__)) + "/stonepath/task.rb"
|
17
17
|
include StonePath::SPTask
|
18
|
+
config_block ||= StonePath::SPTask.default_config_block
|
19
|
+
instance_eval &config_block
|
18
20
|
end
|
19
21
|
|
20
22
|
def stonepath_workbench
|
@@ -42,7 +44,7 @@ module StonePath
|
|
42
44
|
end
|
43
45
|
|
44
46
|
require 'rubygems'
|
45
|
-
require '
|
47
|
+
require 'active_record'
|
46
48
|
|
47
49
|
load File.expand_path( File.dirname(__FILE__)) + "/stonepath/extensions/activerecordbase.rb"
|
48
50
|
require "stonepath/config"
|
data/stonepath.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{stonepath}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Bock"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-20}
|
13
13
|
s.description = %q{Stateful workflow modeling for Rails}
|
14
14
|
s.email = %q{dbock@codesherpas.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -46,6 +46,7 @@ Gem::Specification.new do |s|
|
|
46
46
|
"test/app_root/app/controllers/application_controller.rb",
|
47
47
|
"test/app_root/app/models/assignment.rb",
|
48
48
|
"test/app_root/app/models/case.rb",
|
49
|
+
"test/app_root/app/models/custom_assignment.rb",
|
49
50
|
"test/app_root/app/models/user.rb",
|
50
51
|
"test/app_root/config/boot.rb",
|
51
52
|
"test/app_root/config/database.yml",
|
@@ -62,10 +63,12 @@ Gem::Specification.new do |s|
|
|
62
63
|
"test/app_root/lib/console_with_fixtures.rb",
|
63
64
|
"test/app_root/log/.gitignore",
|
64
65
|
"test/app_root/script/console",
|
66
|
+
"test/custom_task_test.rb",
|
65
67
|
"test/fixtures/users.yml",
|
66
68
|
"test/group_test.rb",
|
67
69
|
"test/role_test.rb",
|
68
70
|
"test/stonepath_test.rb",
|
71
|
+
"test/task_test.rb",
|
69
72
|
"test/test_helper.rb",
|
70
73
|
"test/workitem_test.rb",
|
71
74
|
"test/workowner_test.rb"
|
@@ -80,6 +83,7 @@ Gem::Specification.new do |s|
|
|
80
83
|
"test/app_root/app/controllers/application_controller.rb",
|
81
84
|
"test/app_root/app/models/assignment.rb",
|
82
85
|
"test/app_root/app/models/case.rb",
|
86
|
+
"test/app_root/app/models/custom_assignment.rb",
|
83
87
|
"test/app_root/app/models/user.rb",
|
84
88
|
"test/app_root/config/boot.rb",
|
85
89
|
"test/app_root/config/environment.rb",
|
@@ -93,9 +97,11 @@ Gem::Specification.new do |s|
|
|
93
97
|
"test/app_root/db/migrate/02_create_assignments.rb",
|
94
98
|
"test/app_root/db/migrate/03_create_cases.rb",
|
95
99
|
"test/app_root/lib/console_with_fixtures.rb",
|
100
|
+
"test/custom_task_test.rb",
|
96
101
|
"test/group_test.rb",
|
97
102
|
"test/role_test.rb",
|
98
103
|
"test/stonepath_test.rb",
|
104
|
+
"test/task_test.rb",
|
99
105
|
"test/test_helper.rb",
|
100
106
|
"test/workitem_test.rb",
|
101
107
|
"test/workowner_test.rb"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CustomAssignment < ActiveRecord::Base
|
2
|
+
set_table_name "assignments"
|
3
|
+
include StonePath
|
4
|
+
|
5
|
+
stonepath_task do
|
6
|
+
aasm_initial_state :active
|
7
|
+
aasm_state :active, :after_enter => :notify_created
|
8
|
+
aasm_state :escalated
|
9
|
+
aasm_state :completed, :before_enter => :timestamp_complete, :after_enter => :notify_closed
|
10
|
+
|
11
|
+
aasm_event :complete do
|
12
|
+
transitions :to => :completed, :from => [:active, :escalated]
|
13
|
+
end
|
14
|
+
|
15
|
+
aasm_event :escalate do
|
16
|
+
transitions :to => :escalated, :from => :active
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task_for :case
|
21
|
+
|
22
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'boot')
|
2
2
|
|
3
3
|
Rails::Initializer.run do |config|
|
4
|
+
|
5
|
+
config.gem "aasm"
|
6
|
+
|
4
7
|
config.cache_classes = false
|
5
8
|
config.whiny_nils = true
|
6
9
|
config.action_controller.session = { :key => "_myapp_session", :secret => "gwirofjweroijger8924rt2zfwehfuiwehb1378rifowenfoqwphf23" }
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class CustomTaskTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
|
8
|
+
should "be able to create a custom assignment" do
|
9
|
+
ca = CustomAssignment.create
|
10
|
+
assert(ca.id != nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "be able to escalate a custom assignment" do
|
14
|
+
ca = CustomAssignment.create
|
15
|
+
ca.escalate!
|
16
|
+
assert_equal("escalated", ca.aasm_state)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "be able to complete a custom assignment" do
|
20
|
+
ca = CustomAssignment.create
|
21
|
+
ca.complete!
|
22
|
+
assert_equal("completed", ca.aasm_state)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
data/test/task_test.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TaskTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
end
|
7
|
+
|
8
|
+
should "create an assignment associated with a case" do
|
9
|
+
c = Case.create
|
10
|
+
c.assignments.create
|
11
|
+
assert_equal(1, c.assignments.size, "Case should have 1 assignment")
|
12
|
+
end
|
13
|
+
|
14
|
+
should "have an initial state of active" do
|
15
|
+
c = Case.create
|
16
|
+
a = c.assignments.create
|
17
|
+
assert_equal("active", a.aasm_state)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "be able to complete an assignment" do
|
21
|
+
c = Case.create
|
22
|
+
a = c.assignments.create
|
23
|
+
a.complete!
|
24
|
+
assert_equal("completed", a.aasm_state)
|
25
|
+
end
|
26
|
+
|
27
|
+
should "be able to cancel an assignment" do
|
28
|
+
c = Case.create
|
29
|
+
a = c.assignments.create
|
30
|
+
a.cancel!
|
31
|
+
assert_equal("cancelled", a.aasm_state)
|
32
|
+
end
|
33
|
+
|
34
|
+
should "be able to expire an assignment" do
|
35
|
+
c = Case.create
|
36
|
+
a = c.assignments.create
|
37
|
+
a.expire!
|
38
|
+
assert_equal("expired", a.aasm_state)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stonepath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Bock
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-20 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- test/app_root/app/controllers/application_controller.rb
|
62
62
|
- test/app_root/app/models/assignment.rb
|
63
63
|
- test/app_root/app/models/case.rb
|
64
|
+
- test/app_root/app/models/custom_assignment.rb
|
64
65
|
- test/app_root/app/models/user.rb
|
65
66
|
- test/app_root/config/boot.rb
|
66
67
|
- test/app_root/config/database.yml
|
@@ -77,10 +78,12 @@ files:
|
|
77
78
|
- test/app_root/lib/console_with_fixtures.rb
|
78
79
|
- test/app_root/log/.gitignore
|
79
80
|
- test/app_root/script/console
|
81
|
+
- test/custom_task_test.rb
|
80
82
|
- test/fixtures/users.yml
|
81
83
|
- test/group_test.rb
|
82
84
|
- test/role_test.rb
|
83
85
|
- test/stonepath_test.rb
|
86
|
+
- test/task_test.rb
|
84
87
|
- test/test_helper.rb
|
85
88
|
- test/workitem_test.rb
|
86
89
|
- test/workowner_test.rb
|
@@ -117,6 +120,7 @@ test_files:
|
|
117
120
|
- test/app_root/app/controllers/application_controller.rb
|
118
121
|
- test/app_root/app/models/assignment.rb
|
119
122
|
- test/app_root/app/models/case.rb
|
123
|
+
- test/app_root/app/models/custom_assignment.rb
|
120
124
|
- test/app_root/app/models/user.rb
|
121
125
|
- test/app_root/config/boot.rb
|
122
126
|
- test/app_root/config/environment.rb
|
@@ -130,9 +134,11 @@ test_files:
|
|
130
134
|
- test/app_root/db/migrate/02_create_assignments.rb
|
131
135
|
- test/app_root/db/migrate/03_create_cases.rb
|
132
136
|
- test/app_root/lib/console_with_fixtures.rb
|
137
|
+
- test/custom_task_test.rb
|
133
138
|
- test/group_test.rb
|
134
139
|
- test/role_test.rb
|
135
140
|
- test/stonepath_test.rb
|
141
|
+
- test/task_test.rb
|
136
142
|
- test/test_helper.rb
|
137
143
|
- test/workitem_test.rb
|
138
144
|
- test/workowner_test.rb
|