zaikio-directory 0.0.8 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83519e37312c30b97c65aca908bbbc1065a6781e2050241a6f1c9c8f9d36e32a
4
- data.tar.gz: 90f53637753cb130d93565027def981f13906ea7c940b118345b078bb1972380
3
+ metadata.gz: 7653b475ee39d478558afbbb71d480e290d68d611a41bbb0de24a3e3a50c100e
4
+ data.tar.gz: ee3b15b9e502a5dad7a9ce93dad1d04c16ff580dbab7a8b4271edf17d0cd6c6b
5
5
  SHA512:
6
- metadata.gz: c459a05fdcf957bd0fe8091a9a377480f0467a2978027c4baca49dee853c1f75a3be1b7bfb1864c5f1366736ae5446f729bd6fd55f9cdf0734e1fa3baa6e4554
7
- data.tar.gz: b1f185b1e5c6f9a3b8a5240ad119885694f5a8305cc11d2384119a538fc48aa658a1d160b151d155f8162ddfd7a24f44a7bd4ac2e6f5b9b97dbb12f44e397c87
6
+ metadata.gz: 9cf7796e0a543846086b72f9aa4efca2801a4c6bc406348f540f4b3a5759ba0849c644aae429e1db2580ce3480ec5c862f39a00ec7ebfdbe32aae7a2349cd3c6
7
+ data.tar.gz: d2d639c0786810fb6a05e91372627f390e9742246bcf6fe5f4593fe467fc39c7180b1d64ae39e16c27701485157691ea492843a2527021d307650b17012c3ffb
@@ -8,12 +8,14 @@ require "zaikio/directory/basic_auth_middleware"
8
8
  # Models
9
9
  require "zaikio/error"
10
10
  require "zaikio/directory/base"
11
+ require "zaikio/directory/asset"
11
12
  require "zaikio/directory/organization_membership"
12
13
  require "zaikio/directory/business_relationship"
13
14
  require "zaikio/directory/organization"
14
15
  require "zaikio/directory/person"
15
16
  require "zaikio/directory/machine"
16
17
  require "zaikio/directory/software"
18
+ require "zaikio/directory/specialist"
17
19
  require "zaikio/directory/site"
18
20
  require "zaikio/directory/membership"
19
21
  require "zaikio/directory/current_person"
@@ -0,0 +1,55 @@
1
+ module Zaikio
2
+ module Directory
3
+ module Asset
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ # Callbacks
8
+ after_create :make_organization_owner
9
+ end
10
+
11
+ def make_organization_owner
12
+ if Zaikio::Directory.current_token_data.subject_type == "Organization"
13
+ self.class.request(:post,
14
+ "#{collection_name}/#{id}/#{singular_name}_ownership")
15
+ else
16
+ org_path = "person/organizations/#{organization_id}"
17
+ self.class.request(:post,
18
+ "#{org_path}/#{collection_name}/#{id}/#{singular_name}_ownership")
19
+ end
20
+ end
21
+
22
+ def destroy
23
+ if Zaikio::Directory.current_token_data.subject_type == "Organization"
24
+ self.class.request(:delete,
25
+ "#{collection_name}/#{id}/#{singular_name}_ownership")
26
+ else
27
+ org_path = "person/organizations/#{owner_id || organization_id}"
28
+ self.class.request(:delete,
29
+ "#{org_path}/#{collection_name}/#{id}/#{singular_name}_ownership")
30
+ end
31
+ end
32
+
33
+ def specification
34
+ prefix = if Zaikio::Directory.current_token_data.subject_type == "Person"
35
+ "person/organizations/#{owner_id || organization_id}/"
36
+ else
37
+ ""
38
+ end
39
+ self.class.request(:get,
40
+ "#{prefix}#{collection_name}/#{id}/#{singular_name}_specification")
41
+ &.body&.dig("data")
42
+ end
43
+
44
+ private
45
+
46
+ def collection_name
47
+ self.class.name.demodulize.underscore.pluralize
48
+ end
49
+
50
+ def singular_name
51
+ self.class.name.demodulize.underscore
52
+ end
53
+ end
54
+ end
55
+ end
@@ -22,6 +22,8 @@ module Zaikio
22
22
  uri: "software(/:id)"
23
23
  has_many :machines, class_name: "Zaikio::Directory::Machine",
24
24
  uri: "machines(/:id)"
25
+ has_many :specialists, class_name: "Zaikio::Directory::Specialist",
26
+ uri: "specialists(/:id)"
25
27
  has_many :sites, class_name: "Zaikio::Directory::Site",
26
28
  uri: "sites(/:id)"
27
29
 
@@ -29,6 +31,10 @@ module Zaikio
29
31
  self.attributes = get
30
32
  end
31
33
 
34
+ def reload
35
+ self.attributes = self.class.find.attributes
36
+ end
37
+
32
38
  def members
33
39
  memberships.with_fallback.map(&:person)
34
40
  end
@@ -1,29 +1,10 @@
1
1
  module Zaikio
2
2
  module Directory
3
3
  class Machine < Base
4
+ include Asset
5
+
4
6
  uri "machines(/:id)"
5
7
  include_root_in_json :machine
6
-
7
- # Callbacks
8
- after_create :make_organization_owner
9
-
10
- def make_organization_owner
11
- if Zaikio::Directory.current_token_data.subject_type == "Organization"
12
- self.class.request(:post, "machines/#{id}/machine_ownership")
13
- else
14
- org_path = "person/organizations/#{organization_id}"
15
- self.class.request(:post, "#{org_path}/machines/#{id}/machine_ownership")
16
- end
17
- end
18
-
19
- def destroy
20
- if Zaikio::Directory.current_token_data.subject_type == "Organization"
21
- self.class.request(:delete, "machines/#{id}/machine_ownership")
22
- else
23
- org_path = "person/organizations/#{owner_id || organization_id}"
24
- self.class.request(:delete, "#{org_path}/machines/#{id}/machine_ownership")
25
- end
26
- end
27
8
  end
28
9
  end
29
10
  end
@@ -12,6 +12,8 @@ module Zaikio
12
12
  uri: "person/organizations/:organization_id/software"
13
13
  has_many :machines, class_name: "Zaikio::Directory::Machine",
14
14
  uri: "person/organizations/:organization_id/machines"
15
+ has_many :specialists, class_name: "Zaikio::Directory::Specialist",
16
+ uri: "person/organizations/:organization_id/specialists"
15
17
  has_many :sites, class_name: "Zaikio::Directory::Site",
16
18
  uri: "person/organizations/:organization_id/sites"
17
19
  end
@@ -1,28 +1,15 @@
1
1
  module Zaikio
2
2
  module Directory
3
3
  class Software < Base
4
+ include Asset
5
+
4
6
  uri "software(/:id)"
5
7
  include_root_in_json :software
6
8
 
7
- # Callbacks
8
- after_create :make_organization_owner
9
-
10
- def make_organization_owner
11
- if Zaikio::Directory.current_token_data.subject_type == "Organization"
12
- self.class.request(:post, "software/#{id}/software_ownership")
13
- else
14
- org_path = "person/organizations/#{organization_id}"
15
- self.class.request(:post, "#{org_path}/software/#{id}/software_ownership")
16
- end
17
- end
9
+ private
18
10
 
19
- def destroy
20
- if Zaikio::Directory.current_token_data.subject_type == "Organization"
21
- self.class.request(:delete, "software/#{id}/software_ownership")
22
- else
23
- org_path = "person/organizations/#{owner_id || organization_id}"
24
- self.class.request(:delete, "#{org_path}/software/#{id}/software_ownership")
25
- end
11
+ def collection_name
12
+ "software"
26
13
  end
27
14
  end
28
15
  end
@@ -0,0 +1,10 @@
1
+ module Zaikio
2
+ module Directory
3
+ class Specialist < Base
4
+ include Asset
5
+
6
+ uri "specialists(/:id)"
7
+ include_root_in_json :specialist
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module Directory
3
- VERSION = "0.0.8".freeze
3
+ VERSION = "0.0.9".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-directory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - crispymtn
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-05-11 00:00:00.000000000 Z
13
+ date: 2020-05-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jwt
@@ -81,6 +81,7 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - lib/zaikio/directory.rb
84
+ - lib/zaikio/directory/asset.rb
84
85
  - lib/zaikio/directory/authorization_middleware.rb
85
86
  - lib/zaikio/directory/base.rb
86
87
  - lib/zaikio/directory/basic_auth_middleware.rb
@@ -99,6 +100,7 @@ files:
99
100
  - lib/zaikio/directory/role.rb
100
101
  - lib/zaikio/directory/site.rb
101
102
  - lib/zaikio/directory/software.rb
103
+ - lib/zaikio/directory/specialist.rb
102
104
  - lib/zaikio/directory/version.rb
103
105
  - lib/zaikio/error.rb
104
106
  homepage: https://www.zaikio.com/