sharepoint_api 1.0.3 → 2.2.1
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/CHANGELOG.md +10 -0
- data/Gemfile.lock +4 -4
- data/lib/sharepoint_api/file_info.rb +37 -1
- data/lib/sharepoint_api/file_system.rb +30 -24
- data/lib/sharepoint_api/version.rb +1 -1
- data/lib/sharepoint_api.rb +4 -4
- data/sharepoint_api.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c6b07883d80dbfaf3b87f352c8df343b61b8b7ae2a02825725429ed0c5a47915
|
|
4
|
+
data.tar.gz: 18fa74004691d59f173bc5c5e95718c51c1e1d237d5c14efe4e3b6c490e5b901
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a9e176e297670491aca1a556f4c019f498e409637ca17c144b6a76cfd183c02c1de2d5b0359d24d1659381e4b7a62b506b96d023db8d91453a1b4af8726f5274
|
|
7
|
+
data.tar.gz: eaf88cbd106de7ed5546861e55b74444d7db253e917b62fd317584048243c7db559bf9c6b6a05ddaabcfd822a98bd29542eadadda6866c9a7edfb50362dd6cba
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## [2.2.0] - 2021-07-06
|
|
2
|
+
* Use $select queries to vastly speed up FileInfo#version lookup.
|
|
3
|
+
|
|
4
|
+
## [2.1.0] - 2021-07-06
|
|
5
|
+
* Drop feature of add_file creating a folder if one didn't exist as it introduced a security issue where a folder could be created that didn't have access restricted to routing participants.
|
|
6
|
+
|
|
7
|
+
## [2.0.0] - 2021-06-28
|
|
8
|
+
* Update proof-sharepoint-ruby to escape apostrophes.
|
|
9
|
+
* Change usage of apostrophe escaping.
|
|
10
|
+
|
|
1
11
|
## [1.0.3] - 2021-01-12
|
|
2
12
|
* Handle edge case where FileInfo file#modified_by refers to a user that no longer exists.
|
|
3
13
|
|
data/Gemfile.lock
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
sharepoint_api (
|
|
4
|
+
sharepoint_api (2.2.1)
|
|
5
5
|
addressable (~> 2.7)
|
|
6
|
-
proof-sharepoint-ruby (~>
|
|
6
|
+
proof-sharepoint-ruby (~> 2.0)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
addressable (2.
|
|
11
|
+
addressable (2.8.0)
|
|
12
12
|
public_suffix (>= 2.0.2, < 5.0)
|
|
13
13
|
ast (2.4.1)
|
|
14
14
|
byebug (11.1.3)
|
|
@@ -49,7 +49,7 @@ GEM
|
|
|
49
49
|
parallel (1.20.1)
|
|
50
50
|
parser (2.7.2.0)
|
|
51
51
|
ast (~> 2.4.1)
|
|
52
|
-
proof-sharepoint-ruby (
|
|
52
|
+
proof-sharepoint-ruby (2.0.0)
|
|
53
53
|
curb (~> 0.8, <= 0.9.10)
|
|
54
54
|
pry (0.13.1)
|
|
55
55
|
coderay (~> 1.1)
|
|
@@ -4,6 +4,31 @@ class SharepointApi
|
|
|
4
4
|
class FileInfo
|
|
5
5
|
class FileInfoError < SharepointError; end
|
|
6
6
|
|
|
7
|
+
##
|
|
8
|
+
# Get all data required to build a FileInfo object without subsequent API calls.
|
|
9
|
+
FILE_SELECT_QUERY_WITH_VERSIONS = begin
|
|
10
|
+
sub_query = %w[
|
|
11
|
+
ModifiedBy/LoginName
|
|
12
|
+
ListItemAllFields/Id
|
|
13
|
+
Versions/Id
|
|
14
|
+
Versions/Created
|
|
15
|
+
Versions/IsCurrentVersion
|
|
16
|
+
Versions/CreatedBy/LoginName
|
|
17
|
+
Versions/Url
|
|
18
|
+
].join(',')
|
|
19
|
+
"$select=Name,UpdatedAt,MajorVersion,TimeLastModified,#{sub_query}&$expand=#{sub_query}"
|
|
20
|
+
end.freeze
|
|
21
|
+
|
|
22
|
+
##
|
|
23
|
+
# Get just enough data to build a FileInfo object that suports to_h
|
|
24
|
+
FILE_SELECT_QUERY = begin
|
|
25
|
+
sub_query = %w[
|
|
26
|
+
ModifiedBy/LoginName
|
|
27
|
+
ListItemAllFields/Id
|
|
28
|
+
].join(',')
|
|
29
|
+
"$select=Name,UpdatedAt,MajorVersion,TimeLastModified,Versions,#{sub_query}&$expand=#{sub_query}"
|
|
30
|
+
end.freeze
|
|
31
|
+
|
|
7
32
|
extend Forwardable
|
|
8
33
|
attr_reader :version, :version_id, :file, :updated_at
|
|
9
34
|
|
|
@@ -45,7 +70,7 @@ class SharepointApi
|
|
|
45
70
|
file_version.id,
|
|
46
71
|
created_at: Time.parse(file_version.created),
|
|
47
72
|
current: file_version.is_current_version,
|
|
48
|
-
creator_login: file_version
|
|
73
|
+
creator_login: safe_created_by(file_version)&.login_name
|
|
49
74
|
)
|
|
50
75
|
end
|
|
51
76
|
|
|
@@ -75,5 +100,16 @@ class SharepointApi
|
|
|
75
100
|
|
|
76
101
|
raise(FileInfoError, e.message)
|
|
77
102
|
end
|
|
103
|
+
|
|
104
|
+
def safe_created_by(file_version)
|
|
105
|
+
return file_version.creator if file_version.data['CreatedBy']['__deferred']
|
|
106
|
+
return file_version.created_by if file_version.data['CreatedBy']['__metadata']
|
|
107
|
+
|
|
108
|
+
nil
|
|
109
|
+
rescue Sharepoint::SPException => e
|
|
110
|
+
return nil if e.message =~ /User cannot be found/
|
|
111
|
+
|
|
112
|
+
raise(FileInfoError, e.message)
|
|
113
|
+
end
|
|
78
114
|
end
|
|
79
115
|
end
|
|
@@ -9,26 +9,19 @@ class SharepointApi
|
|
|
9
9
|
def add_file(path, content)
|
|
10
10
|
folder_path = File.dirname(path)
|
|
11
11
|
file_name = encode_path(File.basename(path))
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"/Add(overwrite=true,url='#{file_name}')",
|
|
19
|
-
content
|
|
20
|
-
)
|
|
12
|
+
FileInfo.wrap(
|
|
13
|
+
site.query(
|
|
14
|
+
:post,
|
|
15
|
+
"GetFolderByServerRelativeUrl('#{site_relative_path(folder_path)}')/Files" \
|
|
16
|
+
"/Add(overwrite=true,url='#{file_name}')?#{FileInfo::FILE_SELECT_QUERY}",
|
|
17
|
+
content
|
|
21
18
|
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
retry if (retries += 1) < 2
|
|
29
|
-
log_as(__method__, e, level: :warn)
|
|
30
|
-
nil
|
|
31
|
-
end
|
|
19
|
+
)
|
|
20
|
+
rescue Sharepoint::SPException => e
|
|
21
|
+
reraise_if_lock_error(e)
|
|
22
|
+
|
|
23
|
+
log_as(__method__, e)
|
|
24
|
+
nil
|
|
32
25
|
end
|
|
33
26
|
|
|
34
27
|
def file_exists?(path)
|
|
@@ -39,11 +32,18 @@ class SharepointApi
|
|
|
39
32
|
false
|
|
40
33
|
end
|
|
41
34
|
|
|
35
|
+
##
|
|
36
|
+
# Querying a non-existent file will raise a 500 error so we check for existence first.
|
|
42
37
|
def find_file(path)
|
|
38
|
+
return nil unless file_exists?(path)
|
|
39
|
+
|
|
43
40
|
server_path = server_relative_path(path)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
)
|
|
41
|
+
result = site.query(:get, "GetFileByServerRelativeUrl('#{server_path}')?#{FileInfo::FILE_SELECT_QUERY_WITH_VERSIONS}", nil, true)
|
|
42
|
+
result = JSON.parse(result)
|
|
43
|
+
result['d']['Versions'] = Sharepoint::Site.make_object_from_response(site, { 'd' => result['d']['Versions'] })
|
|
44
|
+
file = Sharepoint::Site.make_object_from_response(site, result)
|
|
45
|
+
|
|
46
|
+
FileInfo.wrap(file)
|
|
47
47
|
rescue Sharepoint::SPException => e
|
|
48
48
|
log_as(__method__, e)
|
|
49
49
|
nil
|
|
@@ -117,8 +117,14 @@ class SharepointApi
|
|
|
117
117
|
|
|
118
118
|
def files_in_folder(path)
|
|
119
119
|
server_path = server_relative_path(path)
|
|
120
|
-
site.query(:get, "GetFolderByServerRelativeUrl('#{server_path}')/Files")
|
|
121
|
-
|
|
120
|
+
result = site.query(:get, "GetFolderByServerRelativeUrl('#{server_path}')/Files?#{FileInfo::FILE_SELECT_QUERY_WITH_VERSIONS}", nil, true)
|
|
121
|
+
result = JSON.parse(result)
|
|
122
|
+
result.dig('d', 'results')&.map do |file_result|
|
|
123
|
+
file_result['Versions'] = Sharepoint::Site.make_object_from_response(site, { 'd' => file_result['Versions'] })
|
|
124
|
+
end
|
|
125
|
+
files = Sharepoint::Site.make_object_from_response(site, result)
|
|
126
|
+
|
|
127
|
+
files.map { |file| FileInfo.new(file) }
|
|
122
128
|
rescue Sharepoint::SPException => e
|
|
123
129
|
log_as(__method__, e)
|
|
124
130
|
nil
|
data/lib/sharepoint_api.rb
CHANGED
|
@@ -62,11 +62,11 @@ class SharepointApi
|
|
|
62
62
|
@site = build_connection
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
def site_relative_path(path,
|
|
65
|
+
def site_relative_path(path, safe_quote: true)
|
|
66
66
|
file_path = [
|
|
67
67
|
library_name, path
|
|
68
68
|
].reject { |p| p.nil? || p == '' }.join('/')
|
|
69
|
-
encode_path(file_path,
|
|
69
|
+
encode_path(file_path, safe_quote: safe_quote)
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def server_relative_path(path)
|
|
@@ -81,9 +81,9 @@ class SharepointApi
|
|
|
81
81
|
"#{protocol}://#{host}/#{site_path}"
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
-
def encode_path(path,
|
|
84
|
+
def encode_path(path, safe_quote: true)
|
|
85
85
|
path = Addressable::URI.encode(path)
|
|
86
|
-
path.gsub!(/'/, '%27%27')
|
|
86
|
+
path.gsub!(/'/, '%27%27') if safe_quote
|
|
87
87
|
path.gsub!('+', '%2B')
|
|
88
88
|
path
|
|
89
89
|
end
|
data/sharepoint_api.gemspec
CHANGED
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
|
17
17
|
spec.metadata['changelog_uri'] = 'https://github.com/proofgov/sharepoint_api/blob/master/CHANGELOG.md'
|
|
18
18
|
|
|
19
19
|
spec.add_runtime_dependency('addressable', '~> 2.7')
|
|
20
|
-
spec.add_runtime_dependency('proof-sharepoint-ruby', '~>
|
|
20
|
+
spec.add_runtime_dependency('proof-sharepoint-ruby', '~> 2.0')
|
|
21
21
|
|
|
22
22
|
# Specify which files should be added to the gem when it is released.
|
|
23
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sharepoint_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Kalek
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2021-
|
|
13
|
+
date: 2021-10-06 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: addressable
|
|
@@ -32,14 +32,14 @@ dependencies:
|
|
|
32
32
|
requirements:
|
|
33
33
|
- - "~>"
|
|
34
34
|
- !ruby/object:Gem::Version
|
|
35
|
-
version: '
|
|
35
|
+
version: '2.0'
|
|
36
36
|
type: :runtime
|
|
37
37
|
prerelease: false
|
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
39
39
|
requirements:
|
|
40
40
|
- - "~>"
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: '
|
|
42
|
+
version: '2.0'
|
|
43
43
|
description: A tool to make it easier to talk to sharepoint (via the proof-sharepoint-ruby
|
|
44
44
|
gem)
|
|
45
45
|
email:
|