bonita 0.1.0

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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +50 -0
  9. data/Rakefile +6 -0
  10. data/VERSION +1 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/bonita.gemspec +41 -0
  14. data/lib/bonita.rb +52 -0
  15. data/lib/bonita/client.rb +105 -0
  16. data/lib/bonita/error.rb +25 -0
  17. data/lib/bonita/error_handler.rb +20 -0
  18. data/lib/bonita/mappings/bpm/process_mapping.rb +31 -0
  19. data/lib/bonita/mappings/customuserinfo/definition_mapping.rb +23 -0
  20. data/lib/bonita/mappings/customuserinfo/user_mapping.rb +18 -0
  21. data/lib/bonita/mappings/customuserinfo/value_mapping.rb +16 -0
  22. data/lib/bonita/mappings/error_mapping.rb +18 -0
  23. data/lib/bonita/mappings/identity/group_mapping.rb +39 -0
  24. data/lib/bonita/mappings/identity/membership_mapping.rb +26 -0
  25. data/lib/bonita/mappings/identity/role_mapping.rb +30 -0
  26. data/lib/bonita/mappings/identity/user_mapping.rb +53 -0
  27. data/lib/bonita/middleware/csrf.rb +19 -0
  28. data/lib/bonita/models/base_model.rb +29 -0
  29. data/lib/bonita/models/bpm/process.rb +19 -0
  30. data/lib/bonita/models/customuserinfo/definition.rb +10 -0
  31. data/lib/bonita/models/customuserinfo/user.rb +10 -0
  32. data/lib/bonita/models/customuserinfo/value.rb +8 -0
  33. data/lib/bonita/models/identity/group.rb +18 -0
  34. data/lib/bonita/models/identity/membership.rb +12 -0
  35. data/lib/bonita/models/identity/role.rb +15 -0
  36. data/lib/bonita/models/identity/user.rb +23 -0
  37. data/lib/bonita/resources/bpm/process_resource.rb +38 -0
  38. data/lib/bonita/resources/customuserinfo/definition_resource.rb +31 -0
  39. data/lib/bonita/resources/customuserinfo/user_resource.rb +18 -0
  40. data/lib/bonita/resources/customuserinfo/value_resource.rb +18 -0
  41. data/lib/bonita/resources/identity/group_resource.rb +43 -0
  42. data/lib/bonita/resources/identity/membership_resource.rb +31 -0
  43. data/lib/bonita/resources/identity/role_resource.rb +44 -0
  44. data/lib/bonita/resources/identity/user_resource.rb +58 -0
  45. data/lib/bonita/utils.rb +93 -0
  46. data/lib/bonita/version.rb +6 -0
  47. metadata +194 -0
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module ErrorHandler
3
+ def self.included(base)
4
+ base.send(:resources) do
5
+ default_handler do |response|
6
+ next if (200...299).cover?(response.status)
7
+ case response.status
8
+ when 401
9
+ if response.respond_to?(:reason_phrase)
10
+ raise Bonita::UnauthorizedError, response.reason_phrase
11
+ else
12
+ raise Bonita::AuthError
13
+ end
14
+ else
15
+ raise Bonita::Error.new(response.status, response.body)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Bpm
4
+ class ProcessMapping
5
+ include Kartograph::DSL
6
+
7
+ kartograph do
8
+ mapping Process
9
+
10
+ scoped :read do
11
+ property :activationState
12
+ property :actorinitiatorid
13
+ property :configurationState
14
+ property :deployedBy
15
+ property :deploymentDate
16
+ property :description
17
+ property :displayDescription
18
+ property :displayName
19
+ property :id
20
+ property :last_update_date
21
+ property :name
22
+ property :version
23
+ end
24
+
25
+ scoped :instantiated do
26
+ property :caseId
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Customuserinfo
4
+ class DefinitionMapping
5
+ include Kartograph::DSL
6
+
7
+ kartograph do
8
+ mapping Definition
9
+
10
+ scoped :read do
11
+ property :description
12
+ property :id
13
+ property :name
14
+ end
15
+
16
+ scoped :create do
17
+ property :description
18
+ property :name
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Customuserinfo
4
+ class UserMapping
5
+ include Kartograph::DSL
6
+
7
+ kartograph do
8
+ mapping User
9
+
10
+ scoped :read do
11
+ property :definitionId, include: DefinitionMapping
12
+ property :userId
13
+ property :value
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Customuserinfo
4
+ class ValueMapping
5
+ include Kartograph::DSL
6
+
7
+ kartograph do
8
+ mapping Value
9
+
10
+ scoped :create do
11
+ property :value
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ class ErrorMapping
4
+ Error = Struct.new(:exception, :message, :explanations)
5
+
6
+ include Kartograph::DSL
7
+
8
+ kartograph do
9
+ mapping Error
10
+
11
+ scoped :read do
12
+ property :exception
13
+ property :message
14
+ property :explanations
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Identity
4
+ class GroupMapping
5
+ include Kartograph::DSL
6
+
7
+ kartograph do
8
+ mapping Group
9
+
10
+ scoped :read do
11
+ property :created_by_user_id
12
+ property :creation_date
13
+ property :description
14
+ property :displayName
15
+ property :icon
16
+ property :id
17
+ property :last_update_date
18
+ property :name
19
+ property :parent_group_id
20
+ property :parent_path
21
+ property :path
22
+ end
23
+
24
+ scoped :create do
25
+ property :description
26
+ property :displayName
27
+ property :icon
28
+ property :name
29
+ property :parent_group_id
30
+ end
31
+
32
+ scoped :update do
33
+ property :displayName
34
+ property :name
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Identity
4
+ class MembershipMapping
5
+ include Kartograph::DSL
6
+
7
+ kartograph do
8
+ mapping Membership
9
+
10
+ scoped :read do
11
+ property :assigned_by_user_id
12
+ property :assigned_date
13
+ property :group_id
14
+ property :role_id
15
+ property :user_id
16
+ end
17
+
18
+ scoped :create do
19
+ property :group_id
20
+ property :role_id
21
+ property :user_id
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Identity
4
+ class RoleMapping
5
+ include Kartograph::DSL
6
+
7
+ kartograph do
8
+ mapping Role
9
+
10
+ scoped :read do
11
+ property :created_by_user_id
12
+ property :creation_date
13
+ property :description
14
+ property :displayName
15
+ property :icon
16
+ property :id
17
+ property :last_update_date
18
+ property :name
19
+ end
20
+
21
+ scoped :update, :create do
22
+ property :description
23
+ property :displayName
24
+ property :icon
25
+ property :name
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Identity
4
+ class UserMapping
5
+ include Kartograph::DSL
6
+
7
+ kartograph do
8
+ mapping User
9
+
10
+ scoped :read do
11
+ property :created_by_user_id
12
+ property :creation_date
13
+ property :enabled
14
+ property :firstname
15
+ property :icon
16
+ property :id
17
+ property :job_title
18
+ property :last_connection
19
+ property :last_update_date
20
+ property :lastname
21
+ property :manager_id
22
+ property :title
23
+ property :userName
24
+ end
25
+
26
+ scoped :create do
27
+ property :firstname
28
+ property :icon
29
+ property :job_title
30
+ property :lastname
31
+ property :manager_id
32
+ property :password
33
+ property :password_confirm
34
+ property :title
35
+ property :userName
36
+ end
37
+
38
+ scoped :update do
39
+ property :firstname
40
+ property :icon
41
+ property :id
42
+ property :job_title
43
+ property :lastname
44
+ property :manager_id
45
+ property :password
46
+ property :password_confirm
47
+ property :title
48
+ property :userName
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Middleware
4
+ class CSRF
5
+ def initialize(app, options = {})
6
+ @app = app
7
+ @options = options
8
+ end
9
+
10
+ def call(env)
11
+ if env[:request_headers]['Cookie']
12
+ token = /X\-Bonita\-API\-Token=([a-f0-9\-]+)/.match(env[:request_headers]['Cookie'])&.captures&.first
13
+ env[:request_headers]['X-Bonita-API-Token'] = token if token
14
+ end
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bonita
4
+ class BaseModel
5
+ class << self
6
+ attr_reader :attributes
7
+
8
+ def attribute(name)
9
+ @attributes ||= []
10
+
11
+ return if @attributes.include? name
12
+
13
+ @attributes << name
14
+ send(:attr_accessor, name)
15
+ end
16
+ end
17
+
18
+ def initialize(params = {})
19
+ self.class.attributes.each do |key|
20
+ instance_variable_set("@#{key}", params[key])
21
+ end
22
+ end
23
+
24
+ def inspect
25
+ values = Hash[instance_variables.map { |name| [name, instance_variable_get(name)] }]
26
+ "<#{self.class.name} #{values}>"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Bpm
4
+ class Process < BaseModel
5
+ attribute :activationState
6
+ attribute :actorinitiatorid
7
+ attribute :configurationState
8
+ attribute :deployedBy
9
+ attribute :deploymentDate
10
+ attribute :description
11
+ attribute :displayDescription
12
+ attribute :displayName
13
+ attribute :id
14
+ attribute :last_update_date
15
+ attribute :name
16
+ attribute :version
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Customuserinfo
4
+ class Definition < BaseModel
5
+ attribute :description
6
+ attribute :id
7
+ attribute :name
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Customuserinfo
4
+ class User < BaseModel
5
+ attribute :definitionId
6
+ attribute :userId
7
+ attribute :value
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Customuserinfo
4
+ class Value < BaseModel
5
+ attribute :value
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Identity
4
+ class Group < BaseModel
5
+ attribute :created_by_user_id
6
+ attribute :creation_date
7
+ attribute :description
8
+ attribute :displayName
9
+ attribute :icon
10
+ attribute :id
11
+ attribute :last_update_date
12
+ attribute :name
13
+ attribute :parent_group_id
14
+ attribute :parent_path
15
+ attribute :path
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Identity
4
+ class Membership < BaseModel
5
+ attribute :assigned_by_user_id
6
+ attribute :assigned_date
7
+ attribute :group_id
8
+ attribute :role_id
9
+ attribute :user_id
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Identity
4
+ class Role < BaseModel
5
+ attribute :created_by_user_id
6
+ attribute :creation_date
7
+ attribute :description
8
+ attribute :displayName
9
+ attribute :icon
10
+ attribute :id
11
+ attribute :last_update_date
12
+ attribute :name
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ module Bonita
3
+ module Identity
4
+ class User < BaseModel
5
+ attribute :created_by_user_id
6
+ attribute :creation_date
7
+ attribute :enabled
8
+ attribute :firstname
9
+ attribute :icon
10
+ attribute :icon
11
+ attribute :id
12
+ attribute :job_title
13
+ attribute :last_connection
14
+ attribute :last_update_date
15
+ attribute :lastname
16
+ attribute :manager_id
17
+ attribute :password
18
+ attribute :password_confirm
19
+ attribute :title
20
+ attribute :userName
21
+ end
22
+ end
23
+ end