microslop_one_drive 4.1.0 → 5.0.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.
- checksums.yaml +4 -4
- data/README.md +32 -10
- data/lib/microslop_one_drive/deserializers/granted_to_deserializer.rb +17 -0
- data/lib/microslop_one_drive/deserializers/link_deserializer.rb +16 -0
- data/lib/microslop_one_drive/deserializers/permission_deserializer.rb +76 -0
- data/lib/microslop_one_drive/deserializers/user_deserializer.rb +2 -1
- data/lib/microslop_one_drive/endpoints/permissions.rb +1 -1
- data/lib/microslop_one_drive/list_responses/permission_list.rb +7 -7
- data/lib/microslop_one_drive/permissions/base_permission.rb +16 -0
- data/lib/microslop_one_drive/permissions/direct_permission.rb +13 -0
- data/lib/microslop_one_drive/permissions/link.rb +30 -0
- data/lib/microslop_one_drive/permissions/sharing_invitation.rb +12 -0
- data/lib/microslop_one_drive/permissions/sharing_link.rb +43 -0
- data/lib/microslop_one_drive/user.rb +10 -4
- data/lib/microslop_one_drive/version.rb +1 -1
- data/lib/microslop_one_drive.rb +8 -3
- metadata +9 -4
- data/lib/microslop_one_drive/audience.rb +0 -32
- data/lib/microslop_one_drive/permission.rb +0 -12
- data/lib/microslop_one_drive/permission_set.rb +0 -59
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c456959cfd4fbe8f15976c434467f540fce7a38187f26d4142227516fa71826e
|
|
4
|
+
data.tar.gz: e75f721e545a657b399840247c4a04721c8b407148edfb8ffc9feeeaf95c5408
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc8051606e48ce9e91b09108965645a87acb0c90d61a8eef0255858d060efd08b02dff8507ab6b91f8140fa20896ad445039d0b33c1848ca307175dbb2b87353
|
|
7
|
+
data.tar.gz: 557535418c4488950a39ef2b063010531b59888357aa0fae89bbf42c6c73f07667bb716588ace852a95d65bf245079d8e48616d8d82bcd6f932d200a5a88a0e9
|
data/README.md
CHANGED
|
@@ -131,18 +131,30 @@ shared_items = drive_item_list.items.select(&:shared?)
|
|
|
131
131
|
example_item = shared_items.first
|
|
132
132
|
|
|
133
133
|
permission_list = client.permissions(item_id: example_item.id)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
permission
|
|
138
|
-
|
|
139
|
-
permission.
|
|
140
|
-
|
|
134
|
+
# Or with a specific drive: client.permissions(item_id: example_item.id, drive_id: drive.id)
|
|
135
|
+
|
|
136
|
+
permissions = permission_list.permissions
|
|
137
|
+
# Each permission is a DirectPermission, SharingLink, or SharingInvitation.
|
|
138
|
+
|
|
139
|
+
# Example: direct permission (e.g. owner) — use granted_to (a User)
|
|
140
|
+
direct = permissions.find { |p| p.is_a?(MicroslopOneDrive::Permissions::DirectPermission) }
|
|
141
|
+
direct.roles # => ["owner"]
|
|
142
|
+
direct.granted_to.display_name # => "Example Person"
|
|
143
|
+
direct.granted_to.email_address # => "person@example.com"
|
|
144
|
+
direct.granted_to.id # => "4"
|
|
145
|
+
|
|
146
|
+
# Example: sharing link — use granted_to_list and link
|
|
147
|
+
link_perm = permissions.find { |p| p.is_a?(MicroslopOneDrive::Permissions::SharingLink) }
|
|
148
|
+
link_perm.roles # => ["write"]
|
|
149
|
+
link_perm.granted_to_list # => array of Users
|
|
150
|
+
link_perm.link.web_url # => "https://1drv.ms/f/c/..."
|
|
151
|
+
link_perm.edit_link? # => true
|
|
152
|
+
link_perm.anonymous_link? # => true
|
|
141
153
|
```
|
|
142
154
|
|
|
143
155
|
### Get Permissions for multiple Drive Items
|
|
144
156
|
|
|
145
|
-
Instead of calling `client.permissions(...)` for each item
|
|
157
|
+
Instead of calling `client.permissions(...)` for each item — which would make N API calls for N items — use
|
|
146
158
|
Microsoft Graph API [batch](https://learn.microsoft.com/en-us/graph/json-batching?tabs=http) feature.
|
|
147
159
|
|
|
148
160
|
```rb
|
|
@@ -150,8 +162,18 @@ drive_item_list = client.delta(drive_id: drive.id)
|
|
|
150
162
|
shared_items = drive_item_list.items.select(&:shared?)
|
|
151
163
|
|
|
152
164
|
permissions = client.batch_permissions(item_ids: shared_items.map(&:id))
|
|
153
|
-
#
|
|
154
|
-
|
|
165
|
+
# Or with a specific drive: client.batch_permissions(item_ids: shared_items.map(&:id), drive_id: drive.id)
|
|
166
|
+
# Returns a flat array of permission objects (DirectPermission, SharingLink, SharingInvitation).
|
|
167
|
+
# Batches of 20 are made under the hood.
|
|
168
|
+
|
|
169
|
+
permissions.each do |p|
|
|
170
|
+
case p
|
|
171
|
+
when MicroslopOneDrive::Permissions::DirectPermission
|
|
172
|
+
puts "#{p.granted_to.display_name}: #{p.roles.join(', ')}"
|
|
173
|
+
when MicroslopOneDrive::Permissions::SharingLink
|
|
174
|
+
puts "Link (#{p.link.type}): #{p.roles.join(', ')}"
|
|
175
|
+
end
|
|
176
|
+
end
|
|
155
177
|
```
|
|
156
178
|
|
|
157
179
|
### Checking if the user's accounts supports SharePoint Sites
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Deserializers
|
|
3
|
+
class GrantedToDeserializer
|
|
4
|
+
def self.create_from_hash(granted_to_hash)
|
|
5
|
+
granted_to_hash = Utils.deep_symbolize_keys(granted_to_hash)
|
|
6
|
+
|
|
7
|
+
if granted_to_hash.key?(:siteUser)
|
|
8
|
+
UserDeserializer.create_from_hash(granted_to_hash[:siteUser])
|
|
9
|
+
elsif granted_to_hash.key?(:group)
|
|
10
|
+
raise NotImplementedError, "Group permissions are not supported yet"
|
|
11
|
+
else
|
|
12
|
+
raise NotImplementedError, "Unknown granted to type for hash: #{granted_to_hash.inspect}"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Deserializers
|
|
3
|
+
class LinkDeserializer
|
|
4
|
+
def self.create_from_hash(link_hash)
|
|
5
|
+
link_hash = Utils.deep_symbolize_keys(link_hash)
|
|
6
|
+
|
|
7
|
+
MicroslopOneDrive::Permissions::Link.new(
|
|
8
|
+
web_url: link_hash.fetch(:webUrl, nil),
|
|
9
|
+
scope: link_hash.fetch(:scope, nil),
|
|
10
|
+
type: link_hash.fetch(:type, nil),
|
|
11
|
+
prevents_download: link_hash.fetch(:preventsDownload, false)
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Deserializers
|
|
3
|
+
class PermissionDeserializer
|
|
4
|
+
# Deserializes a hash into a Permission object. Permissions can be SharingLinks or SharingInvitations.
|
|
5
|
+
def self.create_from_hash(permission_hash)
|
|
6
|
+
permission_hash = Utils.deep_symbolize_keys(permission_hash)
|
|
7
|
+
|
|
8
|
+
if sharing_link?(permission_hash)
|
|
9
|
+
build_sharing_link(permission_hash)
|
|
10
|
+
elsif sharing_invitation?(permission_hash)
|
|
11
|
+
build_sharing_invitation(permission_hash)
|
|
12
|
+
elsif direct_permission?(permission_hash)
|
|
13
|
+
build_direct_permission(permission_hash)
|
|
14
|
+
else
|
|
15
|
+
raise NotImplementedError, "Unknown permission type for hash: #{permission_hash.inspect}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.build_common_parameters(permission_hash)
|
|
20
|
+
link_hash = permission_hash.fetch(:link, nil)
|
|
21
|
+
link = LinkDeserializer.create_from_hash(link_hash) if link_hash
|
|
22
|
+
|
|
23
|
+
{
|
|
24
|
+
id: permission_hash.fetch(:id, nil),
|
|
25
|
+
roles: permission_hash.fetch(:roles, []),
|
|
26
|
+
share_id: permission_hash.fetch(:shareId, nil),
|
|
27
|
+
link: link
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.sharing_link?(permission_hash)
|
|
32
|
+
link = permission_hash.fetch(:link, nil)
|
|
33
|
+
return false if link.nil?
|
|
34
|
+
|
|
35
|
+
link.key?(:scope) && link.key?(:type)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.sharing_invitation?(permission_hash)
|
|
39
|
+
permission_hash.key?(:invitation)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.direct_permission?(permission_hash)
|
|
43
|
+
permission_hash.key?(:grantedToV2)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.build_sharing_link(permission_hash)
|
|
47
|
+
common_parameters = build_common_parameters(permission_hash)
|
|
48
|
+
|
|
49
|
+
granted_to_hash_list = permission_hash.fetch(:grantedToIdentitiesV2, [])
|
|
50
|
+
granted_to_list = granted_to_hash_list.map { GrantedToDeserializer.create_from_hash(it) }
|
|
51
|
+
|
|
52
|
+
has_password = permission_hash.fetch(:hasPassword, false)
|
|
53
|
+
|
|
54
|
+
MicroslopOneDrive::Permissions::SharingLink.new(
|
|
55
|
+
**common_parameters,
|
|
56
|
+
granted_to_list: granted_to_list,
|
|
57
|
+
has_password: has_password
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.build_sharing_invitation(permission_hash)
|
|
62
|
+
common_parameters = build_common_parameters(permission_hash)
|
|
63
|
+
MicroslopOneDrive::Permissions::SharingInvitation.new(**common_parameters)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def self.build_direct_permission(permission_hash)
|
|
67
|
+
common_parameters = build_common_parameters(permission_hash)
|
|
68
|
+
|
|
69
|
+
granted_to_hash = permission_hash.fetch(:grantedToV2, nil)
|
|
70
|
+
granted_to = GrantedToDeserializer.create_from_hash(granted_to_hash)
|
|
71
|
+
|
|
72
|
+
MicroslopOneDrive::Permissions::DirectPermission.new(**common_parameters, granted_to: granted_to)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -21,7 +21,8 @@ module MicroslopOneDrive
|
|
|
21
21
|
mobile_phone: user_hash.fetch(:mobilePhone, nil),
|
|
22
22
|
job_title: user_hash.fetch(:jobTitle, nil),
|
|
23
23
|
office_location: user_hash.fetch(:officeLocation, nil),
|
|
24
|
-
business_phones: user_hash.fetch(:businessPhones, [])
|
|
24
|
+
business_phones: user_hash.fetch(:businessPhones, []),
|
|
25
|
+
login_name: user_hash.fetch(:loginName, nil)
|
|
25
26
|
)
|
|
26
27
|
end
|
|
27
28
|
end
|
|
@@ -12,15 +12,15 @@ module MicroslopOneDrive
|
|
|
12
12
|
private
|
|
13
13
|
|
|
14
14
|
def build_permissions(drive_item_id, parsed_response)
|
|
15
|
-
|
|
16
|
-
MicroslopOneDrive::
|
|
15
|
+
permissions = parsed_response.fetch("value", []).map do
|
|
16
|
+
MicroslopOneDrive::Deserializers::PermissionDeserializer.create_from_hash(it)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
permissions.each do
|
|
20
|
+
it.drive_item_id = drive_item_id
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
permissions
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Permissions
|
|
3
|
+
class BasePermission
|
|
4
|
+
attr_accessor :drive_item_id
|
|
5
|
+
attr_reader :id, :roles, :share_id, :link
|
|
6
|
+
|
|
7
|
+
def initialize(id:, roles:, share_id:, link:, drive_item_id: nil)
|
|
8
|
+
@id = id
|
|
9
|
+
@roles = roles
|
|
10
|
+
@share_id = share_id
|
|
11
|
+
@link = link
|
|
12
|
+
@drive_item_id = drive_item_id
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Permissions
|
|
3
|
+
class DirectPermission < MicroslopOneDrive::Permissions::BasePermission
|
|
4
|
+
# A direct permission is a permission that is granted to a specific user or group.
|
|
5
|
+
attr_reader :granted_to
|
|
6
|
+
|
|
7
|
+
def initialize(id:, roles:, share_id:, link:, granted_to:)
|
|
8
|
+
super(id: id, roles: roles, share_id: share_id, link: link)
|
|
9
|
+
@granted_to = granted_to
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Permissions
|
|
3
|
+
class Link
|
|
4
|
+
attr_reader :web_url, :scope, :type, :prevents_download
|
|
5
|
+
|
|
6
|
+
def initialize(web_url:, scope:, type:, prevents_download:)
|
|
7
|
+
@web_url = web_url
|
|
8
|
+
@scope = scope
|
|
9
|
+
@type = type
|
|
10
|
+
@prevents_download = prevents_download
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def view_link?
|
|
14
|
+
type == "view"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def edit_link?
|
|
18
|
+
type == "edit"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def specific_people_link?
|
|
22
|
+
scope == "users"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def anonymous_link?
|
|
26
|
+
scope == "anonymous"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Permissions
|
|
3
|
+
class SharingInvitation < MicroslopOneDrive::Permissions::BasePermission
|
|
4
|
+
# From https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/permission?view=odsp-graph-online#sharing-invitations:
|
|
5
|
+
#
|
|
6
|
+
# > Permissions sent by the invite API may have additional information in the invitation facet. If an invitation
|
|
7
|
+
# > was sent to an email address that doesn't match a known account, the grantedTo property may not be set until
|
|
8
|
+
# > the invitation is redeemed, which occurs the first time the user clicks the link and signs in.
|
|
9
|
+
#
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module MicroslopOneDrive
|
|
2
|
+
module Permissions
|
|
3
|
+
class SharingLink < MicroslopOneDrive::Permissions::BasePermission
|
|
4
|
+
# From https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/permission?view=odsp-graph-online#sharing-links:
|
|
5
|
+
#
|
|
6
|
+
# > Permissions with a link facet represent sharing links created on the item. These are the most common kinds of
|
|
7
|
+
# > permissions. Sharing links provide a unique URL that can be used to access a file or folder. They can be set
|
|
8
|
+
# > up to grant access in a variety of ways. For example, you can use the createLink API to create a link that
|
|
9
|
+
# > works for anyone signed into your organization, or you can create a link that works for anyone, without
|
|
10
|
+
# > needing to sign in. You can use the invite API to create a link that only works for specific people, whether
|
|
11
|
+
# > they're in your company or not.
|
|
12
|
+
#
|
|
13
|
+
# Concrete examples:
|
|
14
|
+
# 1. https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/permission?view=odsp-graph-online#view-link
|
|
15
|
+
# 2. https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/permission?view=odsp-graph-online#edit-link
|
|
16
|
+
# 3. https://learn.microsoft.com/en-us/onedrive/developer/rest-api/resources/permission?view=odsp-graph-online#specific-people-link
|
|
17
|
+
#
|
|
18
|
+
attr_reader :has_password, :granted_to_list
|
|
19
|
+
|
|
20
|
+
def initialize(id:, roles:, share_id:, link:, has_password:, granted_to_list:)
|
|
21
|
+
super(id: id, roles: roles, share_id: share_id, link: link)
|
|
22
|
+
@has_password = has_password
|
|
23
|
+
@granted_to_list = granted_to_list
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def view_link?
|
|
27
|
+
link.view_link?
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def edit_link?
|
|
31
|
+
link.edit_link?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def specific_people_link?
|
|
35
|
+
link.specific_people_link?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def anonymous_link?
|
|
39
|
+
link.anonymous_link?
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module MicroslopOneDrive
|
|
2
2
|
class User
|
|
3
3
|
attr_reader :principal_name, :id, :display_name, :surname, :given_name, :preferred_language, :mail, :mobile_phone,
|
|
4
|
-
:job_title, :office_location, :business_phones
|
|
4
|
+
:job_title, :office_location, :business_phones, :login_name
|
|
5
5
|
|
|
6
6
|
def initialize(
|
|
7
7
|
principal_name: nil,
|
|
@@ -14,7 +14,8 @@ module MicroslopOneDrive
|
|
|
14
14
|
mobile_phone: nil,
|
|
15
15
|
job_title: nil,
|
|
16
16
|
office_location: nil,
|
|
17
|
-
business_phones: []
|
|
17
|
+
business_phones: [],
|
|
18
|
+
login_name: nil
|
|
18
19
|
)
|
|
19
20
|
@principal_name = principal_name
|
|
20
21
|
@id = id
|
|
@@ -27,14 +28,19 @@ module MicroslopOneDrive
|
|
|
27
28
|
@job_title = job_title
|
|
28
29
|
@office_location = office_location
|
|
29
30
|
@business_phones = business_phones
|
|
31
|
+
@login_name = login_name
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def email
|
|
35
|
+
@mail
|
|
30
36
|
end
|
|
31
37
|
|
|
32
38
|
def email_address
|
|
33
|
-
mail
|
|
39
|
+
@mail
|
|
34
40
|
end
|
|
35
41
|
|
|
36
42
|
def last_name
|
|
37
|
-
surname
|
|
43
|
+
@surname
|
|
38
44
|
end
|
|
39
45
|
end
|
|
40
46
|
end
|
data/lib/microslop_one_drive.rb
CHANGED
|
@@ -11,6 +11,9 @@ require_relative "microslop_one_drive/deserializers/quota_deserializer"
|
|
|
11
11
|
require_relative "microslop_one_drive/deserializers/drive_item_deserializer"
|
|
12
12
|
require_relative "microslop_one_drive/deserializers/parent_reference_deserializer"
|
|
13
13
|
require_relative "microslop_one_drive/deserializers/shared_with_me_item_deserializer"
|
|
14
|
+
require_relative "microslop_one_drive/deserializers/permission_deserializer"
|
|
15
|
+
require_relative "microslop_one_drive/deserializers/link_deserializer"
|
|
16
|
+
require_relative "microslop_one_drive/deserializers/granted_to_deserializer"
|
|
14
17
|
|
|
15
18
|
# Drive items
|
|
16
19
|
require_relative "microslop_one_drive/file"
|
|
@@ -33,11 +36,13 @@ require_relative "microslop_one_drive/batch/response"
|
|
|
33
36
|
require_relative "microslop_one_drive/user"
|
|
34
37
|
require_relative "microslop_one_drive/parent_reference"
|
|
35
38
|
require_relative "microslop_one_drive/drive"
|
|
36
|
-
require_relative "microslop_one_drive/permission_set"
|
|
37
|
-
require_relative "microslop_one_drive/permission"
|
|
38
|
-
require_relative "microslop_one_drive/audience"
|
|
39
39
|
require_relative "microslop_one_drive/quota"
|
|
40
40
|
require_relative "microslop_one_drive/shared_with_me_item"
|
|
41
|
+
require_relative "microslop_one_drive/permissions/base_permission"
|
|
42
|
+
require_relative "microslop_one_drive/permissions/direct_permission"
|
|
43
|
+
require_relative "microslop_one_drive/permissions/sharing_link"
|
|
44
|
+
require_relative "microslop_one_drive/permissions/sharing_invitation"
|
|
45
|
+
require_relative "microslop_one_drive/permissions/link"
|
|
41
46
|
|
|
42
47
|
# Endpoints
|
|
43
48
|
require_relative "microslop_one_drive/endpoints/me"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: microslop_one_drive
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 5.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bradley Marques
|
|
@@ -33,13 +33,15 @@ extra_rdoc_files: []
|
|
|
33
33
|
files:
|
|
34
34
|
- README.md
|
|
35
35
|
- lib/microslop_one_drive.rb
|
|
36
|
-
- lib/microslop_one_drive/audience.rb
|
|
37
36
|
- lib/microslop_one_drive/batch/batch_response.rb
|
|
38
37
|
- lib/microslop_one_drive/batch/response.rb
|
|
39
38
|
- lib/microslop_one_drive/client.rb
|
|
40
39
|
- lib/microslop_one_drive/deserializers/drive_deserializer.rb
|
|
41
40
|
- lib/microslop_one_drive/deserializers/drive_item_deserializer.rb
|
|
41
|
+
- lib/microslop_one_drive/deserializers/granted_to_deserializer.rb
|
|
42
|
+
- lib/microslop_one_drive/deserializers/link_deserializer.rb
|
|
42
43
|
- lib/microslop_one_drive/deserializers/parent_reference_deserializer.rb
|
|
44
|
+
- lib/microslop_one_drive/deserializers/permission_deserializer.rb
|
|
43
45
|
- lib/microslop_one_drive/deserializers/quota_deserializer.rb
|
|
44
46
|
- lib/microslop_one_drive/deserializers/shared_with_me_item_deserializer.rb
|
|
45
47
|
- lib/microslop_one_drive/deserializers/user_deserializer.rb
|
|
@@ -66,8 +68,11 @@ files:
|
|
|
66
68
|
- lib/microslop_one_drive/list_responses/permission_list.rb
|
|
67
69
|
- lib/microslop_one_drive/list_responses/shared_with_me_list.rb
|
|
68
70
|
- lib/microslop_one_drive/parent_reference.rb
|
|
69
|
-
- lib/microslop_one_drive/
|
|
70
|
-
- lib/microslop_one_drive/
|
|
71
|
+
- lib/microslop_one_drive/permissions/base_permission.rb
|
|
72
|
+
- lib/microslop_one_drive/permissions/direct_permission.rb
|
|
73
|
+
- lib/microslop_one_drive/permissions/link.rb
|
|
74
|
+
- lib/microslop_one_drive/permissions/sharing_invitation.rb
|
|
75
|
+
- lib/microslop_one_drive/permissions/sharing_link.rb
|
|
71
76
|
- lib/microslop_one_drive/quota.rb
|
|
72
77
|
- lib/microslop_one_drive/root_folder.rb
|
|
73
78
|
- lib/microslop_one_drive/shared_with_me_item.rb
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
module MicroslopOneDrive
|
|
2
|
-
class Audience
|
|
3
|
-
attr_reader :type, :id, :display_name, :email_address
|
|
4
|
-
|
|
5
|
-
def initialize(type:, id:, display_name:, email_address: nil)
|
|
6
|
-
@type = type
|
|
7
|
-
@id = id
|
|
8
|
-
@display_name = display_name
|
|
9
|
-
@email_address = email_address
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# Converts a "siteUser" object into an OneDriveAudience object.
|
|
13
|
-
#
|
|
14
|
-
# A siteUser object looks like this:
|
|
15
|
-
#
|
|
16
|
-
# {
|
|
17
|
-
# "displayName" => "Bob Bentley",
|
|
18
|
-
# "email" => "bob@haikucode.dev",
|
|
19
|
-
# "id" => "12",
|
|
20
|
-
# "loginName" => "i:0#.f|membership|bob@haikucode.dev"
|
|
21
|
-
# }
|
|
22
|
-
#
|
|
23
|
-
def self.from_site_user(site_user)
|
|
24
|
-
new(
|
|
25
|
-
type: "user",
|
|
26
|
-
id: site_user.fetch("email"),
|
|
27
|
-
display_name: site_user.fetch("displayName"),
|
|
28
|
-
email_address: site_user.fetch("email")
|
|
29
|
-
)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
module MicroslopOneDrive
|
|
2
|
-
class PermissionSet
|
|
3
|
-
attr_reader :id, :role, :audiences
|
|
4
|
-
|
|
5
|
-
def initialize(drive_item_id:, parsed_response:)
|
|
6
|
-
@drive_item_id = drive_item_id
|
|
7
|
-
@id = parsed_response.fetch("id", nil)
|
|
8
|
-
@role = build_role(parsed_response)
|
|
9
|
-
@audiences = build_audiences(parsed_response)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def to_permissions
|
|
13
|
-
@audiences.map { Permission.new(id: @id, drive_item_id: @drive_item_id, role: @role, audience: it) }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def build_role(parsed_response)
|
|
19
|
-
roles = parsed_response.fetch("roles", [])
|
|
20
|
-
roles.is_a?(Array) ? roles.first : roles
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def build_audiences(parsed_response)
|
|
24
|
-
audiences = []
|
|
25
|
-
|
|
26
|
-
audiences += audiences_from_site_users(parsed_response)
|
|
27
|
-
audiences += audiences_from_anonymous_links(parsed_response)
|
|
28
|
-
|
|
29
|
-
audiences.compact
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def audiences_from_site_users(parsed_response)
|
|
33
|
-
site_users = []
|
|
34
|
-
site_users += parsed_response.fetch("grantedToIdentitiesV2", []).flat_map { it.fetch("siteUser", nil) }
|
|
35
|
-
site_users << parsed_response.dig("grantedToV2", "siteUser")
|
|
36
|
-
site_users.compact!
|
|
37
|
-
|
|
38
|
-
site_users.map { Audience.from_site_user(it) }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def audiences_from_anonymous_links(parsed_response)
|
|
42
|
-
link = parsed_response.fetch("link", nil)
|
|
43
|
-
return [] if link.nil? || (link.respond_to?(:empty?) && link.empty?)
|
|
44
|
-
|
|
45
|
-
link_scope = link.fetch("scope", nil)
|
|
46
|
-
|
|
47
|
-
return [] unless link_scope == "anonymous" # I.e. an "anyone with the link" audience
|
|
48
|
-
|
|
49
|
-
[
|
|
50
|
-
Audience.new(
|
|
51
|
-
type: "anyone",
|
|
52
|
-
id: "anyone_with_the_link",
|
|
53
|
-
display_name: "Anyone with the link",
|
|
54
|
-
email_address: nil
|
|
55
|
-
)
|
|
56
|
-
]
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|