code42 0.2.5 → 0.2.6

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/code42.rb +1 -0
  3. data/lib/code42/api/role.rb +30 -0
  4. data/lib/code42/api/user.rb +7 -0
  5. data/lib/code42/attribute_serializer.rb +1 -1
  6. data/lib/code42/client.rb +1 -1
  7. data/lib/code42/permission.rb +13 -0
  8. data/lib/code42/resource.rb +3 -2
  9. data/lib/code42/role.rb +8 -1
  10. data/lib/code42/role_collection.rb +4 -0
  11. data/lib/code42/user.rb +10 -0
  12. data/lib/code42/version.rb +1 -1
  13. data/spec/cassettes/Code42_Client/_create_org/returns_created_org.yml +7 -41
  14. data/spec/cassettes/Code42_Client/_create_role/creates_a_role.yml +42 -0
  15. data/spec/cassettes/Code42_Client/_create_user/returns_created_user.yml +8 -32
  16. data/spec/cassettes/Code42_Client/_create_user/when_sending_an_invalid_email/raises_an_exception.yml +8 -7
  17. data/spec/cassettes/Code42_Client/_deactivate_org/puts_to_the_correct_route.yml +6 -8
  18. data/spec/cassettes/Code42_Client/_delete_role/deletes_a_role.yml +67 -0
  19. data/spec/cassettes/Code42_Client/_find_org_by_name/returns_the_org_with_the_specified_name.yml +9 -44
  20. data/spec/cassettes/Code42_Client/_get_token/returns_valid_tokens.yml +9 -17
  21. data/spec/cassettes/Code42_Client/_get_token/when_providing_invalid_credentials/should_raise_an_exception.yml +6 -5
  22. data/spec/cassettes/Code42_Client/_org/when_ID_is_not_passed/returns_my_org.yml +7 -41
  23. data/spec/cassettes/Code42_Client/_org/when_ID_is_passed_in/returns_a_specific_org.yml +7 -41
  24. data/spec/cassettes/Code42_Client/_permissions/returns_an_enumerable_of_permissions.yml +120 -0
  25. data/spec/cassettes/Code42_Client/_ping/returns_a_ping.yml +9 -14
  26. data/spec/cassettes/Code42_Client/_reset_password/when_sending_a_user_id/as_a_string/behaves_like_reset_password/is_successful.yml +41 -3
  27. data/spec/cassettes/Code42_Client/_reset_password/when_sending_a_user_id/as_an_integer/behaves_like_reset_password/is_successful.yml +41 -3
  28. data/spec/cassettes/Code42_Client/_reset_password/when_sending_a_username/behaves_like_reset_password/is_successful.yml +41 -3
  29. data/spec/cassettes/Code42_Client/_reset_password/when_sending_a_view_url/behaves_like_reset_password/is_successful.yml +41 -3
  30. data/spec/cassettes/Code42_Client/_roles/returns_an_enumerable.yml +243 -0
  31. data/spec/cassettes/Code42_Client/_unassign_role/removes_the_role.yml +107 -0
  32. data/spec/cassettes/Code42_Client/_update_role/updates_a_role.yml +155 -0
  33. data/spec/cassettes/Code42_Client/_update_user/returns_the_updated_user.yml +14 -12
  34. data/spec/cassettes/Code42_Client/_update_user/when_sending_an_invalid_email/raises_an_exception.yml +11 -10
  35. data/spec/cassettes/Code42_Client/_user/when_ID_is_not_passed/returns_my_user.yml +7 -32
  36. data/spec/cassettes/Code42_Client/_user/when_ID_is_passed_in/returns_a_specific_user.yml +8 -32
  37. data/spec/cassettes/Code42_Client/_user/when_blocked/returns_the_blocked_status.yml +15 -39
  38. data/spec/cassettes/Code42_Client/_user/when_unblocked/returns_the_blocked_status.yml +17 -38
  39. data/spec/cassettes/Code42_Client/_user_roles/returns_an_enumerable.yml +7 -19
  40. data/spec/cassettes/Code42_Client/_validate_token/returns_a_valid_response.yml +18 -34
  41. data/spec/code42/client_spec.rb +57 -2
  42. metadata +15 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e4779f663016dbb2239a99c9cee391ce4c03627
4
- data.tar.gz: 599b65430440a9aea5cc384675af10739f6e7b8c
3
+ metadata.gz: 204c4d637432178116bea0a22a7c4e96cb23fa4f
4
+ data.tar.gz: db890339d0aa2ad510ff27e2d4d1c6fef6e674ca
5
5
  SHA512:
6
- metadata.gz: d7ef9ef0c96aff020be4c584cae265ed8ed365834d9effdfa582e4e98b4cc6c240d4bcc399fc17ef5d23325c440df223b488524081e4c1caacb1fa54196f10ba
7
- data.tar.gz: 630b13729bb81af29b7fb072cce7da8981127f170a9666403637e70554cb0be4d2efa7f4ec971d79e6c04d7e9bac511b7b46a4fb69176bedfb76b26d92e86034
6
+ metadata.gz: 15576c7015eed483f0b87b9f95400e6ef24442ceb6bedcd805bf58f272544e4b4dba047feef0ef1a53af91e7bac91ce27aff11dafc6a17867509087b66670279
7
+ data.tar.gz: ef2c016a06290d0440b70ab303f0015e7e1895584f68d5483215d0cfe7444b00464e01a0e1a9990cc26a7e375d8d4d60d9fd6aa37f8fd39d7f1b104296946a06
@@ -22,6 +22,7 @@ require "code42/token"
22
22
  require "code42/role"
23
23
  require "code42/role_collection"
24
24
  require "code42/token_validation"
25
+ require "code42/permission"
25
26
 
26
27
  module Code42
27
28
  class << self
@@ -18,6 +18,36 @@ module Code42
18
18
  def user_roles(id = 'my')
19
19
  collection_from_response(Code42::RoleCollection, Code42::Role, :get, "userRole/#{id}")
20
20
  end
21
+
22
+ # Unassign a role from a user
23
+ # @return true if role was unassigned
24
+ # @param id [String, Integer] The id of the user to return roles for
25
+ # @param id [String] The role name to unassign
26
+ # @example
27
+ # client.unassign_role(2, 'Admin')
28
+ def unassign_role(id, role_name)
29
+ delete('UserRole', { :userId => id, :roleName => role_name })
30
+ end
31
+
32
+ def roles(attrs = {})
33
+ collection_from_response(Code42::RoleCollection, Code42::Role, :get, "role", attrs)
34
+ end
35
+
36
+ def role(id)
37
+ object_from_response(Code42::Role, :get, "role/#{id}")
38
+ end
39
+
40
+ def create_role(name, permissions)
41
+ object_from_response(Code42::Role, :post, "role", role_name: name, permissions: permissions)
42
+ end
43
+
44
+ def update_role(id, attrs = {})
45
+ object_from_response(Code42::Role, :put, "role/#{id}", attrs)
46
+ end
47
+
48
+ def delete_role(id)
49
+ delete("Role/#{id}")
50
+ end
21
51
  end
22
52
  end
23
53
  end
@@ -85,6 +85,13 @@ module Code42
85
85
  def activate_user(id)
86
86
  delete("UserDeactivation/#{id}")
87
87
  end
88
+
89
+ # Returns a list of permissions for the session user
90
+ # @return [Array] An array of matching permissions
91
+ def permissions
92
+ objects_from_response(Code42::Permission, :get, 'permission')
93
+ end
94
+
88
95
  end
89
96
  end
90
97
  end
@@ -58,7 +58,7 @@ module Code42
58
58
  elsif klass.respond_to?(:from_response)
59
59
  klass.from_response(value)
60
60
  elsif klass.respond_to?(:parse)
61
- klass.parse(value)
61
+ klass.parse(value) unless value.nil?
62
62
  else
63
63
  value
64
64
  end
@@ -10,7 +10,7 @@ module Code42
10
10
  include Code42::API::Token
11
11
  include Code42::API::PasswordReset
12
12
 
13
- attr_accessor :settings
13
+ attr_reader :settings
14
14
 
15
15
  def initialize(options = {})
16
16
  self.settings = options
@@ -0,0 +1,13 @@
1
+ module Code42
2
+ class Permission < Resource
3
+ # @!attribute [rw] name
4
+ # @return [String] The name of the permission
5
+ # @!attribute [rw] value
6
+ # @return [String] The value of the permission
7
+ # @!attribute [rw] description
8
+ # @return [String] The description of the permission
9
+ attribute :name
10
+ attribute :value
11
+ attribute :description
12
+ end
13
+ end
@@ -31,9 +31,10 @@ module Code42
31
31
  end
32
32
 
33
33
  def collection_from_response(array)
34
- array.map { |element| self.deserialize_and_initialize(element, self) }
34
+ (array || []).map { |element| self.deserialize_and_initialize(element, self) }
35
35
  end
36
36
  end
37
+
37
38
  attr_accessor :client, :attributes
38
39
 
39
40
  def initialize(data = {}, client = nil)
@@ -47,7 +48,7 @@ module Code42
47
48
  self.class.instance_eval { attr_reader key.to_sym }
48
49
  end
49
50
  self.send("#{key}=", value)
50
- attributes[key.to_sym] = send(key.to_sym)
51
+ attributes[key.to_sym] = self.send(key.to_sym)
51
52
  end
52
53
  end
53
54
 
@@ -12,7 +12,6 @@ module Code42
12
12
  # @!attribute [rw] updated_at
13
13
  # @return [DateTime] The timestamp for the time the role was updated
14
14
 
15
- attribute :user_id
16
15
  attribute :id, :from => :roleId
17
16
  attribute :name, :from => :roleName
18
17
  attribute :created_at, :from => :creationDate, :as => DateTime
@@ -22,5 +21,13 @@ module Code42
22
21
  def permissions=(permissions = [])
23
22
  @permissions = permissions.map { |p| p['permission'] }
24
23
  end
24
+
25
+ def update(attrs = {})
26
+ client.update_role(id, attrs)
27
+ end
28
+
29
+ def delete
30
+ client.delete_role(id)
31
+ end
25
32
  end
26
33
  end
@@ -31,5 +31,9 @@ module Code42
31
31
  def includes_name?(name)
32
32
  map(&:name).include? name
33
33
  end
34
+
35
+ def empty?
36
+ @roles.empty?
37
+ end
34
38
  end
35
39
  end
@@ -50,6 +50,11 @@ module Code42
50
50
  client.assign_role(attrs)
51
51
  end
52
52
 
53
+ # Delete a role from this user
54
+ def unassign_role(role_name)
55
+ client.unassign_role(id, role_name)
56
+ end
57
+
53
58
  def block
54
59
  client.block_user(id)
55
60
  client.user id
@@ -69,5 +74,10 @@ module Code42
69
74
  client.deactivate_user(id)
70
75
  client.user(id, active: false)
71
76
  end
77
+
78
+ def permissions
79
+ client.permissions
80
+ end
81
+
72
82
  end
73
83
  end
@@ -1,3 +1,3 @@
1
1
  module Code42
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -2,13 +2,13 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: http://admin:admin@localhost:7280/api/org
5
+ uri: http://admin:admin@localhost:4280/api/org
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"orgName":"IBM"}'
9
9
  headers:
10
10
  User-Agent:
11
- - Faraday v0.8.7
11
+ - Faraday v0.9.0
12
12
  Content-Type:
13
13
  - application/json
14
14
  Accept-Encoding:
@@ -24,51 +24,17 @@ http_interactions:
24
24
  - no-store
25
25
  Pragma:
26
26
  - no-cache
27
+ Content-Location:
28
+ - http://localhost:4280/api/v1/org
27
29
  Content-Type:
28
- - application/json; charset=utf-8
30
+ - application/json;charset=UTF-8
29
31
  Transfer-Encoding:
30
32
  - chunked
31
33
  Server:
32
34
  - Jetty(7.6.3.v20120416)
33
35
  body:
34
36
  encoding: UTF-8
35
- string: |-
36
- {
37
- "metadata": {
38
- "timestamp": "2013-06-13T15:16:29.975-05:00",
39
- "params": {}
40
- },
41
- "data": {
42
- "orgId": 87,
43
- "orgUid": "587885375444888214",
44
- "orgName": "IBM",
45
- "status": "Active",
46
- "active": true,
47
- "blocked": false,
48
- "parentOrgId": null,
49
- "type": "ENTERPRISE",
50
- "externalId": "587885375444888214",
51
- "hierarchyCounts": {},
52
- "configInheritanceCounts": {},
53
- "creationDate": "2013-06-13T15:16:29.859-05:00",
54
- "modificationDate": "2013-06-13T15:16:29.957-05:00",
55
- "registrationKey": "SCTR-799T-224R-JWTW",
56
- "reporting": {},
57
- "customConfig": false,
58
- "settings": {
59
- "maxSeats": null,
60
- "maxBytes": null
61
- },
62
- "settingsInherited": {
63
- "maxSeats": "",
64
- "maxBytes": ""
65
- },
66
- "settingsSummary": {
67
- "maxSeats": "",
68
- "maxBytes": ""
69
- }
70
- }
71
- }
37
+ string: '{"metadata":{"timestamp":"2014-07-09T10:34:43.890-05:00","params":{}},"data":{"orgId":444,"orgUid":"644534473905930608","orgName":"IBM","status":"Active","active":true,"blocked":false,"parentOrgId":null,"type":"ENTERPRISE","classification":"BASIC","externalId":"644534473905930608","hierarchyCounts":{},"configInheritanceCounts":{},"creationDate":"2014-07-09T10:34:43.764-05:00","modificationDate":"2014-07-09T10:34:43.854-05:00","registrationKey":"TTT2-2T4R-MJWR-HR84","reporting":{},"customConfig":false,"settings":{"maxSeats":null,"maxBytes":null},"settingsInherited":{"maxSeats":"","maxBytes":""},"settingsSummary":{"maxSeats":"","maxBytes":""}}}'
72
38
  http_version:
73
- recorded_at: Thu, 13 Jun 2013 20:16:29 GMT
39
+ recorded_at: Wed, 09 Jul 2014 15:34:43 GMT
74
40
  recorded_with: VCR 2.5.0
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://admin:admin@localhost:4280/api/role
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"roleName":"My Role","permissions":["admin.user.read"]}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Content-Type:
13
+ - application/json
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - '*/*'
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - no-store
25
+ Pragma:
26
+ - no-cache
27
+ Content-Location:
28
+ - http://localhost:4280/api/v1/role
29
+ Content-Type:
30
+ - application/json;charset=UTF-8
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Server:
34
+ - Jetty(7.6.3.v20120416)
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"metadata":{"timestamp":"2014-07-09T10:46:21.189-05:00","params":{}},"data":{"roleId":62,"roleName":"My
38
+ Role","locked":false,"numberOfUsers":0,"creationDate":"2014-07-09T10:46:21.181-05:00","modificationDate":"2014-07-09T10:46:21.181-05:00","permissions":[{"permission":"admin.user.read","description":"Permission
39
+ to view user information"}]}}'
40
+ http_version:
41
+ recorded_at: Wed, 09 Jul 2014 15:46:21 GMT
42
+ recorded_with: VCR 2.5.0
@@ -2,13 +2,13 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: http://admin:admin@localhost:7280/api/user
5
+ uri: http://admin:admin@localhost:4280/api/user
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"orgId":2,"username":"testuser"}'
9
9
  headers:
10
10
  User-Agent:
11
- - Faraday v0.8.7
11
+ - Faraday v0.9.0
12
12
  Content-Type:
13
13
  - application/json
14
14
  Accept-Encoding:
@@ -24,42 +24,18 @@ http_interactions:
24
24
  - no-store
25
25
  Pragma:
26
26
  - no-cache
27
+ Content-Location:
28
+ - http://localhost:4280/api/v1/user
27
29
  Content-Type:
28
- - application/json; charset=utf-8
30
+ - application/json;charset=UTF-8
29
31
  Transfer-Encoding:
30
32
  - chunked
31
33
  Server:
32
34
  - Jetty(7.6.3.v20120416)
33
35
  body:
34
36
  encoding: UTF-8
35
- string: |-
36
- {
37
- "metadata": {
38
- "timestamp": "2013-06-13T15:16:29.797-05:00",
39
- "params": {}
40
- },
41
- "data": {
42
- "userId": 3,
43
- "userUid": "2062352522e63ee1",
44
- "status": "Active",
45
- "username": "testuser",
46
- "email": null,
47
- "firstName": null,
48
- "lastName": null,
49
- "quotaInBytes": -1,
50
- "orgId": 2,
51
- "orgUid": "proserverdemo",
52
- "orgName": "PROServer Demo",
53
- "active": true,
54
- "blocked": false,
55
- "emailPromo": true,
56
- "invited": true,
57
- "orgType": "ENTERPRISE",
58
- "usernameIsAnEmail": null,
59
- "creationDate": "2013-06-13T15:14:39.703-05:00",
60
- "modificationDate": "2013-06-13T15:16:29.777-05:00"
61
- }
62
- }
37
+ string: '{"metadata":{"timestamp":"2014-07-09T10:34:44.846-05:00","params":{}},"data":{"userId":38,"userUid":"7a1c8ea53caabfe3","status":"Active","username":"testuser","email":null,"firstName":null,"lastName":"Jenkins","quotaInBytes":-1,"orgId":2,"orgUid":"proserverdemo","orgName":"PROServer
38
+ Demo","active":true,"blocked":false,"emailPromo":true,"invited":true,"orgType":"ENTERPRISE","usernameIsAnEmail":null,"creationDate":"2014-07-09T10:27:12.465-05:00","modificationDate":"2014-07-09T10:34:44.835-05:00","passwordReset":false}}'
63
39
  http_version:
64
- recorded_at: Thu, 13 Jun 2013 20:16:29 GMT
40
+ recorded_at: Wed, 09 Jul 2014 15:34:44 GMT
65
41
  recorded_with: VCR 2.5.0
@@ -2,13 +2,13 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: http://admin:admin@localhost:7280/api/user
5
+ uri: http://admin:admin@localhost:4280/api/user
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"orgId":2,"username":"testuser","email":"testuser"}'
9
9
  headers:
10
10
  User-Agent:
11
- - Faraday v0.8.7
11
+ - Faraday v0.9.0
12
12
  Content-Type:
13
13
  - application/json
14
14
  Accept-Encoding:
@@ -18,22 +18,23 @@ http_interactions:
18
18
  response:
19
19
  status:
20
20
  code: 500
21
- message: '[{ "name": "EMAIL_INVALID", "description": "Email is invalid", "objects":
22
- [] }]'
21
+ message: '[{"name":"EMAIL_INVALID","description":"com.code42.core.BuilderException","objects":[]}]'
23
22
  headers:
24
23
  Pragma:
25
24
  - no-cache
25
+ Content-Location:
26
+ - http://localhost:4280/api/v1/user
26
27
  Content-Type:
27
28
  - text/html;charset=ISO-8859-1
28
29
  Cache-Control:
29
30
  - must-revalidate,no-cache,no-store
30
31
  Content-Length:
31
- - '72'
32
+ - '88'
32
33
  Server:
33
34
  - Jetty(7.6.3.v20120416)
34
35
  body:
35
36
  encoding: UTF-8
36
- string: '[{"name":"EMAIL_INVALID","description":"Email is invalid","objects":[]}]'
37
+ string: '[{"name":"EMAIL_INVALID","description":"com.code42.core.BuilderException","objects":[]}]'
37
38
  http_version:
38
- recorded_at: Thu, 13 Jun 2013 20:16:29 GMT
39
+ recorded_at: Wed, 09 Jul 2014 15:34:44 GMT
39
40
  recorded_with: VCR 2.5.0
@@ -2,13 +2,13 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: put
5
- uri: http://admin:admin@localhost:7280/api/OrgDeactivation/88
5
+ uri: http://admin:admin@localhost:4280/api/OrgDeactivation/88
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{}'
9
9
  headers:
10
10
  User-Agent:
11
- - Faraday v0.8.9
11
+ - Faraday v0.9.0
12
12
  Content-Type:
13
13
  - application/json
14
14
  Accept-Encoding:
@@ -17,8 +17,8 @@ http_interactions:
17
17
  - '*/*'
18
18
  response:
19
19
  status:
20
- code: 201
21
- message: Created
20
+ code: 204
21
+ message: No Content
22
22
  headers:
23
23
  Cache-Control:
24
24
  - no-store
@@ -28,13 +28,11 @@ http_interactions:
28
28
  - http://localhost:4280/api/v1/OrgDeactivation/88
29
29
  Content-Type:
30
30
  - application/json
31
- Content-Length:
32
- - '0'
33
31
  Server:
34
32
  - Jetty(7.6.3.v20120416)
35
33
  body:
36
34
  encoding: UTF-8
37
35
  string: ''
38
- http_version:
39
- recorded_at: Mon, 28 Apr 2014 21:18:38 GMT
36
+ http_version:
37
+ recorded_at: Wed, 09 Jul 2014 15:34:44 GMT
40
38
  recorded_with: VCR 2.5.0